24.02.2011 12:51, em...@froggs.de пишет:
>> Hello again =)
>>
>> I have anover small question: how I can get current FPS rate?
>>
>> I can limit it like:
>> $self->app->min_t(1/FPS);
>> But if my computer too slow i want to see real FPS rate. And it`s need
>> to control myself because if I do something wrong then FPS drops down.
>>
> 
> Hmmm, I think I would do something like this:
> 
> Add vars:
> $frames = 0;
> $before = Time::HiRes::time;
> 
> Add a show_handler:
> if($frames >= 20) {
>   $now    = Time::HiRes::time;
>   $fps    = $frames / ($now - $before);
>   $frames = 0;
>   $before = $now;
>   # blit fps to screen
> }
> $frames++;
> 
> Didnt tested it, but I think it should work this way...
> 
> -- 
> Cheers, FROGGS

Yes. I do something like this when I use SDL_perl 2.2*.
I think maybe this code already has in SDLx::FPS or SDL::GFX::Framerate
=) There is many FPS control functions but none get current FPS rate =(.

I do:

$frames = 0;
$time = $app->ticks;
$fps = undef;

In show_handler:

$frames++;
if($app->ticks - $time >= 1000)
{
  $fps = $frame;
  $frame = 0;
  $time = $app->ticks;
}

draw $fps...


-- 

         Roman V. Nikolaev

mail:        rsha...@rambler.ru
icq:         198-364-657
jabber:      rsha...@jabber.org
site:        http://www.rshadow.ru

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to