Jump to content
  • Advertisement
Sign in to follow this  
dgi

SDL2 android game loop

This topic is 849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all ,

I have a question about the game loop on android.The way SDL2 works is that it opens a thread from the activity and calls SDL_main() , 

so now the game loop is this :

 

update()

draw()

sleep()

 

So I was wondering what is the best way to do it when it comes to performance and battery consumption.

Should I continue to do it like that , or get a callback from view :: onDraw and then do : update() draw()

 

When I install the app on a real device I get some kind of lag spikes . I control the fps so I don't think the problem is there.

Is that because the device is shit or there is some sort of syncing going on  ?

 

btw the app is very basic and not cpu heavy

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Looks like you put two concerns into one post.

 

> I was wondering what is the best way to do it when it comes to performance and battery consumption.

 

To not consume battery, do as little as you need as infrequently as you can.

 

Sadly in this era many mobile games do not care about battery life.  Playing games, even simple form-style games, often generates an unexpected power draw.  A feature bullet point of "low power consumption" is unlikely to generate more sales or attract more ad revenue.

 

If your game must draw the screen at regular intervals then do so.  It doesn't really matter if you do it from one update method or another update method. If you need to update 30 times per second but are concerned about battery life, ask yourself what would happen if you updated 15 times per second. Would the improvement to battery life be better than the change to visual quality?

 

If your game does not need to draw the screen at regular intervals, but could update after an event followed by a brief animation and then return to idle, do that instead.

 

>  I install the app on a real device I get some kind of lag spikes . I control the fps so I don't think the problem is there.

 

Could be many reasons.  

 

Instead of tracking just frames per second, track the minimum, average, and maximum time for frames over a window, perhaps one second.  Times that look like (4.034 ms / 4.902 ms/ 5.352 ms) mean you've got quite a lot of room to grow and a steady rate.  Times that look like (1.932 ms / 4.902 ms / 19.241 ms) tells you you've got some very long spikes and some very fast frames, even though you've got the same average framerate as the measurements before.

 

Beyond that, you'll want to use a good profiler. Measure what is actually causing the time spikes. Only once you have measured it and identified it can you make the changes and then measure again to verify you've fixed the problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!