Re: FPS counter
[email protected] ("Roman V. Nikolaev") Thu, 24 Feb 2011 13:34:44 +0300
| Newsgroups | perl.sdl.devel |
|---|---|
| Message-ID | <[email protected]> |
24.02.2011 12:51, [email protected] пишет: >> 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: [email protected] icq: 198-364-657 jabber: [email protected] site: http://www.rshadow.ru
signature.asc
(application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1mNEQACgkQ6hKpBt4OHBt5UQCfRy/Hr5riRsxLfk+IWVjFc7PP at0AoIe9ixMmEyqX5nRunZIX6MMWkY9E =1fJe -----END PGP SIGNATURE-----