Saving battery

Previous topic - Next topic

Alex_R

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!!


spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Alex_R

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:

MrPlow

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.

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

S.O.P.M.

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.
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

Schranz0r

Try to wait until the player make an input, simple WHILE -WEND
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Moru

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.

MrTAToad

Also, as iPhone users have found out, a lot of battery wastage is caused by the operating system...

kanonet

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:
Code (glbasic) Select
//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
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

spacefractal

#9
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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Hemlos

#10
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"
Bing ChatGpt is pretty smart :O

erico

Quote from: Hemlos on 2014-Aug-12
...
And....lower your screen "Brightness"

Whaaaat?? Not even for free beer! :D

matchy

#12
Just wondering, do GLB_ON_PAUSE & GLB_ON_RESUME sub routines get triggered with or without AUTOPAUSE?  :zzz:


kanonet

AUTOPAUSE TRUE
www.glbasic.com/xmlhelp.php?lang=en&id=220&action=view
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

matchy

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.