Hi all,
I just recently rebuilt a simple game I wrote for desktop linux (SDL) to android,
and it’s the first time I deal with Android.
I got in trouble with the pause/resume.
The game works fine, I added touch input using SDL Finger events.
But when the application goes to the background, and then comes back again,
the game slows down considerably. Everything works, but there is a major slowdown (like 90fps to 30fps or so).
I thought this was about having to destroy and recreate all textures, so I did just that,
handling WINDOW events of type FOCUS_LOST (destroy all textures) and FOCUS_GAINED (recreate all textures), but even though it works, I still see this major slowdown.
Btw is what I am doing something useful at all? There seems to be NO difference in behavior with or without texture recreation. Should I recreate the SDL_Renderer too?
Any ideas what it could be?
I am using SDL-2.0.15, and I am keeping SDL_Surface objects around (which I presume are not lost on pause/resume?), and creating SDL_Textures out of them, which I destroy on FOCUS_LOST (and pause), and recreate on FOCUS_GAINED.
Maybe the problem is that the frequency of the high performance counter changes?
Here is my frame capping code (g.fps is 90, g.frequency is set at start time to be = SDL_GetPerformanceFrequency()):
Uint64 game_counter_to_msec(Uint64 counter)
{
return counter * 1000 / g.frequency;
}
void game_wait_next_frame(Uint64 counter_delta)
{
Uint32 elapsed_ms, sleep_ms;
Uint32 one_frame_ms = 1000 / g.fps;
elapsed_ms = game_counter_to_msec(counter_delta);
if (elapsed_ms < one_frame_ms) {
/* if less than one wallclock frame has passed */
sleep_ms = one_frame_ms - elapsed_ms;
//SDL_Log("c: %llu ms: %u sl: %u", counter_delta, elapsed_ms, sleep_ms);
SDL_Delay(sleep_ms);
}
}
Thanks for any hints…
C