How can I sync the game Logic at 30 times per sec? +details
How can I sync the game Logic at 30 times per sec? +details
I saw this "howto" yesterday:
http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=723
but it s not what i want
i dont want to multiply anything, i prefer use fixed values
> i want with something like a timer locked at 30 or 60 ticks per second (I cant get the irrlicht timer working correctly )
> or a allegro´s* like wait vsync() function to sync with the screen´s refresh rate.
> or at least a non irrlicht related timer
*I tested the allegro´s vsync() with irrlicht and it works, but I can´t use allegro beacause i want to port my game for PSP
thanks in advance
http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=723
but it s not what i want
i dont want to multiply anything, i prefer use fixed values
> i want with something like a timer locked at 30 or 60 ticks per second (I cant get the irrlicht timer working correctly )
> or a allegro´s* like wait vsync() function to sync with the screen´s refresh rate.
> or at least a non irrlicht related timer
*I tested the allegro´s vsync() with irrlicht and it works, but I can´t use allegro beacause i want to port my game for PSP
thanks in advance
loading singature...
30 ticks is 1000 miliseconds / 30 =tick
so you get something like this
but with the sleep some bit better
so you get something like this
Code: Select all
time = Device->getTimer()->getRealTimer()
if (time - lasttime >= tick)
{
// do something
lasttime = time;
}else{
Sleep ( (1000 /30 )(time - lasttime - 1))
}
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Indeed, Irrlicht could do with a ITimer::sleep() method. The following code is Windows specific, and is perhaps a little more paranoid about timer granularity than you probably need. Note that it skips rendering if the frame rate lags behind the required frequency, and there's no check for the pathological case where it can't catch up. You'll need to include winbase.h (just include windows.h) and link against winmm.lib for timeGetDevCaps().
Code: Select all
ITimer * timer = device->getTimer();
u32 lastFrame = timer->getTime();
enum { FRAME_TIME = 1000 / 30 };
u32 nextFrameTime = lastFrame + FRAME_TIME;
TIMECAPS timeCaps;
(void)timeGetDevCaps(&timeCaps, sizeof(timeCaps));
while(device->run())
{
u32 now = timer->getTime();
if(now >= nextFrameTime)
{
doGameLogic(); // always do your game logic
nextFrameTime += FRAME_TIME;
if(now < nextFrameTime)
doRendering(); // Only render if we're not lagging
}
else
{
if(nextFrameTime - now > timeCaps.wPeriodMin)
Sleep(nextFrameTime - now);
else
Sleep(0);
}
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
subject
thanks for help, I will try this sleep() way...
rogerborg: thanks, but I want a portable code :)
and i think that using fixed values is simple and easier.
rogerborg: thanks, but I want a portable code :)
i dont want my game running well using all processing power at 200fps :PBaiame wrote:But with what you want to do, you can never, ever guarantee a time-consistent simulation. What exactly is it about delta time systems that bothers you?
and i think that using fixed values is simple and easier.
loading singature...
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Indeed. If you do write portable code (i.e. a cross platform sleep() method) then could you consider adding it to I/CTimer and submitting a patch please.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Re: subject
Oh, sorry, I misunderstood your first post. Yeah, that's a good idea.CuecaX wrote:i dont want my game running well using all processing power at 200fps
and i think that using fixed values is simple and easier.
because i´m entering in a competition and dont have much time... i need to finish the game until the end of the monthroxaz wrote:if you want portable code so why dont you write some?
if i did something helpful of course i will release the code ^^rogerborg wrote:Indeed. If you do write portable code (i.e. a cross platform sleep() method) then could you consider adding it to I/CTimer and submitting a patch please.
hybrid wrote:We already have a cross-platform sleep method in the upcoming next release of Irrlicht You have the option to halt the timers as well.
loading singature...