Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Sleep command

Author
Message
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 24th Dec 2016 01:18 Edited at: 16th Nov 2017 18:23
Hi guys,

I was wondering whether I should use the SLEEP command or not.
I'm currently developing a retro 2D game for Android, and I have plenty of frames left.

Is it advisable to use this command?
Should I use it on Android only, or on all platforms?

Please enlighten me


PSY


PSY LABS Games
Coders don't die, they just gosub without return
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 24th Dec 2016 03:08
Rather than using sleep i would;
1. have a sleepmode flag
2. set setsyncrate() to some low number
3. count the frames until the sleep time has expired

Note: Doco says you shouldn't use the sleep() command to sleep for more than 17ms
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 24th Dec 2016 03:23 Edited at: 16th Nov 2017 18:23
Thanks for your answer!

The sync rate is already at 30, I can't go lower because it would look laggy.

If the sync rate is set to 30 fps, but the main loop eats about 10 fps, there are 20 fps left, which are 'controlled' by SYNC().

My question is, does SYNC() automatically allocate the remaining processing time to other processes ( outside the application ), or do I have to use SLEEP() ?


PSY LABS Games
Coders don't die, they just gosub without return
damothegreat
User Banned
Posted: 24th Dec 2016 21:26
I believe all Sync really does is.

Rendering and updating

Renders whats on the back buffer (what we code to in the main loop) and updates it to the front buffer (what we see on screen)

Not sure about any other mechanics or secrets behind the command

Others may know or be able to answer better

My advise, I would not use Sleep() - cause this will cause lags.

Instead I would use the timer() and set a variable and when a certain frame is passed - do something so that when the sync() comes along, it knows what to draw to the front buffer (screen)
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 25th Dec 2016 01:18 Edited at: 16th Nov 2017 18:23
I guess Sync does some other stuff, too, like handling mouse clicks and other global events.

I can use Sleep ( 10 ) and it doesn't lag at all.

Everything runs just fine...with and without Sleep.

I'm simply not sure if it's advisable to use Sleep at all in order to give other background applications processing time, or if that's not necessary.


My guess is that you should use it when you do some intense calculations without using SYNC, so the system doesn't hang...


PSY LABS Games
Coders don't die, they just gosub without return
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 25th Dec 2016 20:26
I guess it really depends on if it is a 'nice' sleep or a blocking sleep.

If it is the former, in addition to giving processing time to other processes, it also uses less power as the cpu is allowed to rest. Conserving battery and running cooler can be big pluses.

If it is the latter, it will just add a busy delay in the app and not really give anything back to the system.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
http://games.joshkirklin.com/sulium
NGP
AGK Developer
8
Years of Service
User Offline
Joined: 29th Dec 2015
Location: In the studio
Posted: 25th Dec 2016 20:45
+1's to all the good advice above!

Base things on a timer if at all possible! When I first arrived at AppGameKit, it was easy to use the sleep command in place of a "pause" function (link to prime example in signature) but that can cause problems down the road. Some devices get confused and think the app has hung when using longer sleep times (remember the sheer variety of possible machines your app will be running on). Different systems will try and cope in different ways, not all pretty. Best to avoid that kind of confusion by writing your own functions now, not using the sleep command! Exactly what I'm working on at the moment!

Best of luck!
AGK Linux user.
Tessellatus - a game of chance for Android.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 25th Dec 2016 21:38 Edited at: 16th Nov 2017 18:23
Thanks for all the good info guys !!!


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-11-24 13:21:23
Your offset time is: 2024-11-24 13:21:23