Hi!!
In my puzzle game I don't need to refresh the screen every frame, just when the user taps on the screen or changes something. So I disable the command SHOWSCREEN when the user is thinking and doesn't interact with the game. My goal is to save battery.
When I try this method on my PC the game runs fine, but on an iPad I sometimes get weird behavior. Is it possible that the SHOWSCREEN command does not only refresh the screen but also initialize variables and perform other actions? So, is it necessary to run it every frame?
Thanks!!
SHOWSCREEN is required, because its also does other task as well, example note the system the app is running. Otherway, the app might got killed by the system, if its hanging too much (which Android will do).
instead you could eventuelly lower the framerate with LIMITFPS, so its dont need to run 60 FPS.
Thank you Spacefractal for your replay. So I understand I can change the framerate with LIMITFPS wherever I want inside the code. I thought (I don't know why) LIMITFPS only worked at the very start of the app and after that it was ignored. :whistle: :zzz:
Also, you could look at your profiler and see what functions or parts of your program are consuming the most cycles and look to disable or skip them when a "pause" or "no activity" is detected.
If you want to get more battery run time just reduce the CPU load whilst you draw the screen contents only when there're changes. As I know you can choose if SHOWSCREEN does clear everything or not.
Try to wait until the player make an input, simple WHILE -WEND
Waiting for input without calling showscreen is not adviced :-)
Showscreen does not have to clear the screen though as S.O.P.M pointed out so just call SHOWSCREEN in your wait-loop.
Also, as iPhone users have found out, a lot of battery wastage is caused by the operating system...
CLEARSCREEN -1 and your SHOWSCREEN will not delete backbuffer, which means you can simply call SHOWSCREEN and dont need any drawcalls. Also SLEEP is a good way to give back CPU-Power and save battery (use either high SLEEP or low LIMITFPS). Actually you should always care about these issues, even on PC. I hate it when i run a game that does not do much, but when you start it uses 100% CPU power and CPU Fan runs full speed - always feels like I found a bad programmer.
Here a quick mock-up how you could design your game to handle your "waiting for input and save power"-scenario:
//prepare scene:
LIMITFPS 60
//mainloop:
WHILE TRUE
(game logic)
(drawing the scene)
SHOWSCREEN
idle_loop()
WEND
FUNCTION idle_loop%:
CLEARSCREEN -1
WHILE check_user_input()
SHOWSCREEN
SLEEP 100 // should give you about 9-10 fps - play with that value to see what is highest you can go, so your game is still responsive
WEND
CLEARSCREEN RGB(0,0,0)
ENDFUNCTION
FUNCTION check_user_input: // check and process user input here, be careful, reverse logic on output!
RETURN FALSE // user did input, touch screen etc...
RETURN TRUE // no user input, continue with idle loop
ENDFUNCTION
LIMITFPS 10
SLEEP 1
should give better perforcement. Personally im have not newer tried to save the battery really. Except the third game, im did tried a little bit if the game have idle a bit, which would set framerate to 20 and removed some details, until the game is active again.
ALso LIMITFPS works fine here anywhere you want to uses it, but of course you need to calculate the time by your self with your own frameskip system etc.
in Xcode, you can see the current framerate and cpu usage, if the device run iOS 7, while the device is connected to the mac. A nice thing to know.
There are several ways to reduce battery drain...
LIMITFPS might be an option, 20fps is a workable speed as long as speed and precision are not a key factor to your game.
KEYWAIT
MOUSEWAIT
EDIT: And dont forget SLEEP command....this will effectively alter your framerate too....its in milliseconds....SLEEP 250 will pause the program for 1/4 of a second.
Also...turn off GPS. Thats a BIGGIE
And....lower your screen "Brightness"
Quote from: Hemlos on 2014-Aug-12
...
And....lower your screen "Brightness"
Whaaaat?? Not even for free beer! :D
Just wondering, do GLB_ON_PAUSE & GLB_ON_RESUME sub routines get triggered with or without AUTOPAUSE? :zzz:
AUTOPAUSE TRUE
www.glbasic.com/xmlhelp.php?lang=en&id=220&action=view
kanonet, I mean, is there a difference in Alex_R program with AUTOPAUSE TRUE or FALSE. I figure when the iPad may go to sleep and GLB_PAUSE is activated tell the program to go in to back idle.
Thanks guys for your solutions!!.
When I set LIMITFPS 10 and SLEEP 1 it seems it save battery but I have a little problem. When user taps any button sometimes must do two or three touches with all finger in the screen till the game do something. I think due to SLEEP 1. If I remove the SLEEP command this problem is not solved but the behavior is aceptable (sometimes two taps is required to activate the game). So I need at least 30 FPS to check the user taps for a fine user experience. I'll try kanonet solution. I think it solves this problem.
Thank you again for your help!! This forum is awsome!! =D
Did you try HIBERNATE? That's a sort of an "intelligent SLEEP".
After some little testing with Apple developer tools I have the following results (perhaps can be useful to someone).
Special loop: When user is no tapping the screen the program goes to this special loop doing hibernate, sleep or other test as follows:
Procedure CPU usage GPU usage Touch response
30 fps always 29%-56% 7%-8% Very good: 10/10
Special loop
Hibernate
No showscreen 50%-51% 0% Good :8/10
Special loop
Hibernate
Sleep 50
No showscreen 46% 0% Good :8/10
Special loop
Hibernate
8 FPS reduction
No showscreen 50%-51% 0% Regular :7/10
Special loop
No hibernate
8 FPS reduction
No showscreen 20% 20-21% Bad: 4/10
Special loop
Screenshot
Sleep 50
Showscreen 28-29% 11% Bad: 4/10
Special loop
Screenshot
Hibernate
Showscreen 18% 25% Very Bad: 4/10
Special loop
Screenshot
8 FPS reduction
Showscreen 18%-21% 19%-25% Very bad: 3/4
Conclusion: unfortunately the best option is do nothing to save battery. You get the best user experience and the game runs fine.
Note: with this special loop the iPhone gets too warm after 5 minutes.
Note2: with hibernate after showscreen in the main loop I get almost the same CPU and GPU usage that without hibernate
more fps you have, why better control do you have. This is why some users want 60fps, even its a simple game. That is just more responsetive. So there is no reasons to try to save the battery state, except if the user is idle, example like 5 minuttes or such (which im did in Spot Race).