• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - IDE What is Sleep Margin? Can it be changed on the fly?

D

Dani

Guest
Hello!

In any of my GMS2 projects, if I change the Sleep Margin config parameter for Windows, I get the following results:

Code:
Sleep Margin = 1 ===> Game runs very slow. Crappy scrolling parallax. Almost no CPU usage.
Sleep Margin = 10 ===> Game runs ok. No smooth scrolling parallax. Low CPU usage.
Sleep Margin = 15 ===> Game runs good. Smooth scrolling parallax. Medium CPU usage.
Sleep Margin = 20 ===> Game runs very good. Super smooth scrolling parallax. High CPU usage.
Obviously, people own different computers, so it would be a good idea to let them set the Sleep Margin they want from within the game, so these are my questions:

1. What is the sleep margin for?
2. Why there is no sleep margin on Mac and Linux?
3. Is there any way to change the sleep margin on the fly, via code?

Thanks in advance.
 

Jeremy

Member
The documentation has this to say about the sleep margin:
This option is related to reducing stuttering when running your game on specific systems. Basically, if your game is running faster than your room speed GameMaker Studio 2 will "sleep" for the remaining time, but this sleep can be quite inaccurate and you can often end of* sleeping for longer than necessary, causing your frame to take longer which causes stuttering. To get around this we can sleep for less time, then sit in a tight loop for the remainder of the time to make it more accurate - although the problem with sitting in a loop is that it causes CPU usage to increase, which in turn can cause your CPU temperatures to rise and your fan to run faster. By default, this value is set to 10, and in 99.99% of the cases you'll be fine with this, but for low end machines or for machines with a lot of background processes running this may not be an ideal solution (or for very high end machines too) and a value of 1 or 15 or something may be required. Note though that this is very much a system specific configuration and what works on your build machine may not be appropriate for another user, and as such if in doubt leave it set to 10.
*Typo in the documentation :p?

I don't think you can control it via code.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
The entire documentation and GMS1.4 IDE is flooded with vague wording and spelling/punctuation mistakes.
As the sole person responsible for all the GMS (1.4 and 2) documentation it's my job to make sure that things are as well written and clear as possible. If you find typos (like the one shown above... :( ) then please file a bug, and you can also file bugs if you feel that the documentation glosses over important details or fails to provide sufficient information about a subject. I take great pains to try and ensure that the docs are as comprehensive as possible and strive to correct these issues when they are brought to my attention.
 
D

Dani

Guest
Please, save your complaints for other topics. One reason why I use GameMaker is the documentation. Yes, there may be typos, but almost anything you need is documented. Maybe more examples and use cases would make it even better.

But this topis is about Sleep Margin, so I'm still interested in an "official" reply from YoYo developers about that subject.

Thanks.
 

2drealms

Member
So, if setting the sleep margin will "fix" stuttering for the development machine yet, it's very system dependant, what is the point? If it runs good on my system yet runs like crap on a customer's machine, what have I accomplished? It's of my opinion that the timing issue needs to be rethought. There are better ways of doing it. I've made suggestions over the years (many have). The response to me was get community feedback. People have complained and complained about the timing, yet these issues still remain. The sleep margin is not a real fix. In my opinion that there should be two step events, one that is variable and one that is fixed. The fixed one can be used for physics and the variable one can be used for everything else. You can then use the delta to update per unit of time vs per frame. But, all of this has been discussed before. Timing is important and other engines have taking the approach that I've mention above. I don't understand why this can not just be fixed once and for all. Sigh!

At the very least use the higher precision timer if available and fall back to less precise one otherwise (maybe this is already being done). The tight loop is killing CPUs. Maybe call win32 sleep(1) in the tight loop, this will allow background tasks to run and reduce the cpu load. I have used this in the timing code of my custom engine before. I check for the high res timer and use that if avail or fall back to less accurate timing otherwise. In the later case, I call timeBeginPeriod(1) to increase the resolution. But, like I've said, I offered this suggestion years ago, it just falls on deaf ears.

Sorry for the rant, but this timing issue needs to be fixed. Either fix what is there or replace it.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
The sleep margin is not a "new" issue nor is it a "fix" for an existing issue... It's always been there, only before it was hidden and not accessible to the user. It was (by default) set to 10, but some users were complaining about issues and so it was exposed to the public and left for each person to decide how best to set it. If you are in doubt about how it works or what to do then just leave it at 10 since this was what it was before it was exposed. Note that performance issues on certain machines because of the sleep margin are not something that YYG can magically fix since the very nature of PC gaming means that no matter what you do, if your player base is wide enough, you'll find that some people will have issues because no two PC's are the same (an infinite number of hardware/software configurations).
 

gnysek

Member
It should be possible to change it when game is running then, so we can add this in game options for users to choose (setting 1 and 20 for example).
 
Top