I was browsing through the game loop/frame related source to find out why
the game uses so much cpu time,then I suddenly found out that this function
is borked:

void SDL_framerateDelay(FPSmanager * manager)
{
   Uint32 current_ticks;
   Uint32 target_ticks;
   Uint32 the_delay;

   /*
    * Next frame
    */
   manager->framecount++;

   /*
    * Get/calc ticks
    */
   current_ticks = SDL_GetTicks();
   target_ticks = manager->lastticks + (Uint32) ((float)
manager->framecount * manager->rateticks);
   if (current_ticks <= target_ticks) {
the_delay = target_ticks - current_ticks;
SDL_Delay(the_delay); // <- it will never get there
   } else {
manager->framecount = 0;
manager->lastticks = SDL_GetTicks();
   }
}

it will never get to the line SDL_Delay(the_delay); because SDL_GetTicks()
gets the time in ms since SDL lib is firstly initialized.

a wz game frame would probably take quite a few ms so current_ticks is
always greater than target_ticks(lastticks + 1000/framelimits * 1(always one
because it gets reseted every time)),this bug will end up as a busy cpu
loop,that explains why wz uses so much cpu time.

basically the SDL tick caculations are pointless,since the framerateDelay is
called per game cycle.

so it should be:

void SDL_framerateDelay(FPSmanager * manager)
{

manager->framecount++;
SDL_Delay((Uint32)manager->rateticks);
manager->lastticks = SDL_GetTicks();
}
with this change my old pc(1.4Ghz) can run a debug build with limited
optimization flags with 200 gamefps(capped by SDL) with 80%-90% cpu
usage,while it ran with a optimized-to-death release build with the
default(60gamefps actually the limits got ignored due to this bug) with 100%
cpu without this change

at least we have one less problem now :)
_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to