Btw, is there any need in the gamelogic to limit the framerate?
I just played a bit with SDL and SDL_Delay() and tested the average FPS
with a 800x600 OpenGL windows and 2 primitives.

I got the best CPU-Usage / FPS result with:

<<<
if ( frames % 5 == 0 )
        SDL_Delay(1);
<<<

Means, share after 5 frames some cpu time :)
With a "Sleep" command every frame the FPS drops to max ~500 FPS.
CPU usage ~1%

With a "Sleep" all 5 frames, i get ~2200 FPS.
CPU usage 2% ~ 4%

With a "Sleep" all 10 frames, i get 4000 ~ 5000 FPS
but around 50% CPU usage on each core :(
(Its the same like 'NoSleep')

- Kamaze

The Watermelon schrieb:
> 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
> [email protected]
> https://mail.gna.org/listinfo/warzone-dev

_______________________________________________
Warzone-dev mailing list
[email protected]
https://mail.gna.org/listinfo/warzone-dev

Reply via email to