One Hour One Life Forums

a multiplayer game of parenting and civilization building

You are not logged in.

#1 2019-01-05 14:59:03

Léonard
Member
Registered: 2019-01-05
Posts: 205

Slow motion lag fix

First time posting here.


I recently bought the game on steam after hearing about it and absolutely loved it.
However I quickly began to notice a couple issues with it.

First, the VSync is always on no matter what you do even though there seems to be a "countingOnVSync" setting for it which also seems to show up in the menu.
sRxq.png

Second, sometimes when there is a lot going on in the screen, the game will go in a "slow motion" sort of lag where everything including the hud and the pause menu itself takes twice as long to move/update.
This makes it incredibly difficult to move or do anything really.

This to me strongly suggested that the game was dependent on the framerate for timing purposes.
So a couple days ago I decided to go digging around in the code since it was open source.
What I found was the explanation for everything and also a couple of odd things.
To start with, there indeed was code to handle VSync that could be turned off here (from ScreenGL_SDL.cpp, minorGems):
sRxS.png
Yet the VSync was still on regardless of the setting that controls mUseFrameSleep.
So I moved on to another idea and found this (from the same file):
sRxj.png
Admittedly I didn't bother to try and remove the flag to see if it would turn off the VSync but I suspect this is the reason as to why it is always on no matter what.

Next I checked LivingLifePage.cpp from OneLife and found out that the game was indeed dependent on the framerate for timing purposes.
The game code relies on a variable called frameRateFactor but never updates it as if it was made on the assumption that the framerate would always be absolutely constant no matter what.
So I fixed it and also changed the parts of the code that seemed to assume frameRateFactor would always be constant with 2 commits here and here.
Now whenever the framerate drops the game runs perfectly without slow motion.
On that note, this game does have framerate issues that hopefully could be addressed in the future.

All in all I was kind of confused by this, what was jason's intention while writing this code?
Is VSync intended to be always on no matter what, despite what the setting and some parts of the code seem to suggest?
I also found this function while looking through the code:
sRxy.png
which seems to indicate that the problem is known yet the function is called nowhere as far as I can tell and after trying to use it it turned out to be buggy as the animations would not loop properly.
If you ask me, I'm fine with VSync being on as a default but I think people should always have the choice to turn it off and let the game run as fast as it can on their machine or possibly set their own FPS cap.

Another thing I wanted to talk about was the structure of the game code itself.
I get that this is purely a multiplayer game and that it's not supposed to work without a server, but absolutely everything seems to be done at the same time.
Reading server messages, physics/logic code, rendering. All at once.
Particularly in LivingLifePage::step(). This method is an absolute monster, roughly 5k in lines.
Why not split/organize the code into multiple functions here? Possibly even like what most game engines do: network parsing, logic/physics followed by rendering.
I'm not trying to argue against anything here, I'm simply curious about all this as I'm only familiar with the usual way game engines are made.

Anyways, I'm not sure if it's alright to post binaries here, hopefully someone can inform me.
The fix works great, it's helped me a ton as I often do get FPS lag in big towns.
I'm not sure how common this issue is, I've heard other people ingame saying they experience it.
I should also mention that I have a 144hz screen, perhaps people who have 60hz monitors run into the issue much less often, I don't know.

Offline

#2 2019-01-05 15:53:43

lionon
Member
Registered: 2018-11-19
Posts: 532

Re: Slow motion lag fix

This is great, yes I experience slows as well, I know my computer pretty well and what sort of games it can run with what sort of performance. And OHOL is... well rather slow for it's perceived complexity. I suspected that performance can be improved, but didn't want to invest time into this as well.

Posting binaries? Not a fan of it. But could you post a patch please? The output of the "diff" command that compares the original directory with the modified. Or you could try posting a pull request to Jason on github, I don't know what his policies regarding these are.

Offline

#3 2019-01-05 17:31:03

Léonard
Member
Registered: 2019-01-05
Posts: 205

Re: Slow motion lag fix

Ah sorry, I did post the links to my changes, I guess the links are kinda drowned out in this wall of text I made.
I'm not particularly good at making long posts.
The 2 commits are here and here.

Offline

#4 2019-01-05 19:19:00

betame
Member
Registered: 2018-08-04
Posts: 202

Re: Slow motion lag fix

Curious could this also cause playback issues?


Morality is the interpretation of what is best for the well-being of humankind.
List of Guides | Resources per Food | Yum? | Temperature | Crafting Info: https://onetech.info

Offline

#5 2019-01-05 19:46:35

lionon
Member
Registered: 2018-11-19
Posts: 532

Re: Slow motion lag fix

Just tried it, it also applied cleanly to the mod, yes it's much better. It gets jerky in a full city, but it's already much better.

Offline

#6 2019-01-06 09:09:47

lionon
Member
Registered: 2018-11-19
Posts: 532

Re: Slow motion lag fix

BTW: Could you please submit a pull request to Awbz mod?
https://github.com/Awbz/OneLife

Offline

#7 2019-01-06 11:53:09

Léonard
Member
Registered: 2019-01-05
Posts: 205

Re: Slow motion lag fix

betame wrote:

Curious could this also cause playback issues?

That's a good question, I'm not completely sure.
I know from reading the code that apparently there are binds that allow you to slow/speed up the passage of time that worked by directly changing the variable so those are definitely broken though it could be made compatible.

lionon wrote:

Just tried it, it also applied cleanly to the mod, yes it's much better. It gets jerky in a full city, but it's already much better.

Yes as I said, this only fixes the slow motion issue but the underlying lag that was there before is still present.
It's just that now whenever the game lags it will no longer go in slow motion mode making everything that much easier to do.

lionon wrote:

BTW: Could you please submit a pull request to Awbz mod?

Right now there are changes both in OneLife and minorGems and Awbz only has a fork of OneLife.
I guess I could make this work with changes only to OneLife if I measure frame time in the game code instead but first I'd like to see what Jason thinks of this so perhaps it could actually be fixed in the main game.

Offline

#8 2019-01-09 01:27:55

Mr.XIX
Member
From: The Netherlands
Registered: 2018-03-12
Posts: 175

Re: Slow motion lag fix

I'd love to see an update on this matter.

Offline

#9 2019-01-23 22:19:13

jasonrohrer
Administrator
Registered: 2017-02-13
Posts: 4,801

Re: Slow motion lag fix

Good stuff here.

Popping by to answer questions.


GL_SWAP_CONTROL is only a request.  Yes, I want VSYNC if available.  No, I can't force it to turn on.  But yes, I always request it, no matter what.  Your graphics card control panel usually controls this, ultimately, but it sometimes depends on the card.

mUseFrameSleep is enabled as a backup, if its determined that VSYNC isn't really on.  That just sleeps the extra time away to ensure close to 60fps.  But this results in ugly tearing (because the sleep time is out of sync with the screen refresh).


The bottom line is that without vsync, some visual tearing is unavoidable, because the screen graphics will get updated during the middle of the scan.



I hate the way variable framerate looks.  It means that during smooth motion, the object will move a different distance on the screen each frame.  You measure the time each frame, and then use that to decide how far to move it.  This results in jerky motion.

Your fix does this, essentially, updating frameRateFactor every frame.  But even with vsync on, you won't get the same time measurement each frame, which means that the motion will be jerky.  (The screen is actually updating at a fixed frequency, but this is impossible to measure with OS timing calls).

Most people won't notice this, but I've tried it (long ago), saw the subtle jerkiness, and decided that fixed frame rates are for me.  It also makes a lot of other things much cleaner, like recording and playback of events.

Now, what about adjustAllFrameCounts?

This was a bit of code that I tried that would periodically adjust frameRateFactor based on current measurements.  Not every frame (to avoid constant jerkiness), but if slowdown was detected over 100 frames or so.  I also didn't like the way this looked.  During a slowdown, the reduced fps would eventually be noticed and compensated for, and you'd start waking normal speed again.  But then later, when the slowdown ended, the character would walk fast briefly, until the end of the slowdown was measured and noticed.  No micro jerkiness, but macro jerkiness....

So I disabled it.


In general, why are you playing this 2D game on a computer/GPU that can't run it at 60 fps?

I mean, my expectation is that your computer will be fast enough for it.

If you can't, I'd rather have you run it at 30fps all the time, or even 15fps.  Pick a fixed frame rate, and stick with that.  There's no in-game way to adjust this.... maybe I should add one.  Not sure how many people would benefit from it, though.

Change targetFrameRate to 30fps.  Change countingOnVsync to 0.

You will get some tearing, of course, when you do this.



Now, as for why the event loop in LivingLifePage is a monster, as opposed to being broken up into functions.... well, what for?  The event loop is complicated.  There are lots of steps.  I added the steps, one by one, as the game grew.  I could break this up now, in retrospect, into functions, but these would be "dummy" functions that would only be called once (like "processPlayerUpdateMessage").  My coding philosophy suggests that this is actually a bad idea (functions are meant to encapsulate behavior that is repeated).  Complicated things can not be made simpler through redirection.  Sticking different parts of the complex monster into different files doesn't change the complexity.  It just makes finding and understanding the monster even harder.

Every sufficiently complex piece of software is a monster.  There's no way around that.  Have you ever tried to understand someone else's code when they were trying to be clever with the structure?  It's a nightmare of rabbit holes that lead to other rabbit holes.  Functions that call other functions that call other functions.  Where is the actual work being done here?  The actual imperative steps are often hidden away.

It's a nightmare to understand complicated code no matter what, but at least it's all on one page here...  just walk through and see what happens, step by step.

As far as "game engines" go, who knows?  I mean, there they are making a piecemeal thing meant to be called by other programmers, so breaking it up into atomic blocks (that can each be called in isolation) makes sense.

Offline

#10 2019-01-24 06:37:58

lionon
Member
Registered: 2018-11-19
Posts: 532

Re: Slow motion lag fix

jasonrohrer wrote:

In general, why are you playing this 2D game on a computer/GPU that can't run it at 60 fps?

Because for me it's an arcane setting I didn't care about. If I don't specifically override this setting, I expect the game to chose something sensible for itself if it wants to go fixed.

And if there is the rare occasion it cannot meet that target, I'd rather have one jerky animation than "virtual lag".

Offline

#11 2019-01-24 06:55:46

pein
Member
Registered: 2018-03-31
Posts: 4,335

Re: Slow motion lag fix

changing target to 30 didn't really helped on a slower pc, but skip half of frames had some benefit
the speedup was funny, when you left the game for long periods like 10 hours on death screen, you born and run on horse speed
now this is deadly most cases, and i don't really know how is for other players, maybe run normally ? but they can never pick you up?

once i managed to live like 32 years, if i stopped to compensate for the extra speed, yeah, working also had some extra speed, but i bumped to items often
with 20 food bars, the bumping was survivable, and after a while i knew when i got to stop and chill
but still killed me at 30 as i was bumping into a bush for way too long

the fixed frame rate results in bad pvp experiences tho
while i got the skills and habits to dodge most of attacks coming from 2 tile away and never stand directly to anyone having weapon
sometimes i die due to this speed difference, as on my screen they appear further
this is very annoying sometimes, i don't blame it every time on lag, but certainly more than half of the time i got killed, im moving on my screen and im dead anyway
worst was when someone run in off screen and i was dead, and played the whole animation like 5 sec later

i would prefer to have options regarding this

Last edited by pein (2019-01-24 06:56:14)


https://onehouronelife.com/forums/viewtopic.php?id=7986 livestock pens 4.0
https://onehouronelife.com/forums/viewtopic.php?id=4411 maxi guide

Playing OHOL optimally is like cosplaying a cactus: stand still and don't waste the water.

Offline

#12 2019-01-26 21:41:37

Gederian
Member
Registered: 2018-03-28
Posts: 164

Re: Slow motion lag fix

Took me about 2 hours to get this game working because my (very popular) Surface Book does not have the dGpu enabled by default. It was a bad first experience. I'm sure lots of people have similar experiences for various reasons.

Seems like a simple addition.

Options and user friendly are better. Show them an annoying in game message instead.

Also, when I click the Family Tree link or move the window (non full screen) in the menu the FPS alert triggers.

Offline

#13 2020-01-12 01:00:33

Pastah
Member
Registered: 2018-11-28
Posts: 15

Re: Slow motion lag fix

The slow motion lag needs to get fixed. Big towns are a lag fest.

Offline

#14 2020-01-12 01:07:30

DestinyCall
Member
Registered: 2018-12-08
Posts: 4,563

Re: Slow motion lag fix

One year later ...

Offline

#15 2020-01-12 11:00:04

sigmen4020
Member
Registered: 2019-01-05
Posts: 850

Re: Slow motion lag fix

A good ol’ necro.


For the time being, I think we have enough content.

Offline

#16 2020-01-12 23:33:56

Léonard
Member
Registered: 2019-01-05
Posts: 205

Re: Slow motion lag fix

Not all necros are automatically bad.

This is still an issue a year later and if you think it's a problem what better place to post about it than in the thread made by literally the only person who tried to fix it.


My changes are still available on github and I expect anyone could merge them with the current onelife+/onelife head without much difficulty.
Awbz himself was interested in merging the changes to his client but didn't go through with it as far as I remember.

Anyways, don't expect anything from me, I don't play this game anymore so I have no interest in working on this.

Offline

#17 2020-10-20 01:32:08

OdinCockeril
Member
Registered: 2020-10-07
Posts: 18

Re: Slow motion lag fix

My character always feels slow when walking around, I play this game with my gf who sits next to me and her game looks fine. Still don't know how to fix this..


Haven't said my last words yet

Offline

#18 2020-10-20 01:38:08

NoTruePunk
Member
Registered: 2019-01-25
Posts: 321

Re: Slow motion lag fix

NECRO

Offline

#19 2020-10-20 01:41:58

Coconut Fruit
Member
Registered: 2019-08-16
Posts: 831

Re: Slow motion lag fix

OdinCockeril wrote:

My character always feels slow when walking around, I play this game with my gf who sits next to me and her game looks fine. Still don't know how to fix this..

Try this https://onehouronelife.com/forums/viewtopic.php?id=8044


Making own private server (Very easy! You can play on it even if you haven't bought the game)
Zoom mod
Mini guide for beginners
website with all recipies

Offline

#20 2020-10-20 23:01:48

Cogito
Member
Registered: 2020-03-09
Posts: 192

Re: Slow motion lag fix

I still struggle with this, even after trying a lot of different options.

Unfortunately, there is not one clear and obvious idea to investigate - as Jason says there shouldn't be any problem running on a good graphics card!

I have a Sapphire AMD Radeon RX 5700 XT, which should be powerful enough (ha!) but it is running in an external GPU enclosure over thunderbolt 3, so perhaps that causes issues?

I have an i7-8550U processor with 16GB of ram, which again should be enough, but I have a filesystem monitoring job that I can't stop that spikes the CPU usage every half an hour or so, so perhaps that causes issues?

My suspicion is that the sprite drawing is hitting some edge case that makes the pixel copying slow for some reason, and that becomes extremely laggy when there are a lot of sprites to be drawn (in a town, or zoomed out).

Offline

#21 2020-10-20 23:41:15

DiscardedSlinky
DubiousSlinker
From: Discord
Registered: 2019-05-06
Posts: 687

Re: Slow motion lag fix

So no idea if this would help anyone, but I fixed this problem for a girl a few months back. Maybe it will help some of you guys too


http://onehouronelife.com/forums/viewto … 79#p100279


I'm Slinky and I hate it here.
I also /blush.

Offline

#22 2020-10-21 00:03:16

Cogito
Member
Registered: 2020-03-09
Posts: 192

Re: Slow motion lag fix

DiscardedSlinky wrote:

So no idea if this would help anyone, but I fixed this problem for a girl a few months back. Maybe it will help some of you guys too


http://onehouronelife.com/forums/viewto … 79#p100279

Thanks, I saw that when you posted it.

There have been times when my dedicated GPU was not being used, but that just makes the game unplayable, rather than laggy.

It's playable with GPU in use, but the lagginess is super frustrating.

Last edited by Cogito (2020-10-21 00:03:31)

Offline

#23 2020-10-21 01:27:06

Coconut Fruit
Member
Registered: 2019-08-16
Posts: 831

Re: Slow motion lag fix

Clearly Jason's fault. Many people have fps issues even with strong PCs.


Making own private server (Very easy! You can play on it even if you haven't bought the game)
Zoom mod
Mini guide for beginners
website with all recipies

Offline

Board footer

Powered by FluxBB