How can I sync the game Logic at 30 times per sec? +details

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
CuecaX
Posts: 13
Joined: Mon Mar 05, 2007 8:54 pm
Location: Brazil

How can I sync the game Logic at 30 times per sec? +details

Post by CuecaX »

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 :P



*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...
Baiame
Posts: 41
Joined: Sun Oct 15, 2006 11:33 am

Post by Baiame »

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?
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Try using doubles to store the values you get off the irrlicht timers, other data types didnt work for me :?
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Post by Strong99 »

30 ticks is 1000 miliseconds / 30 =tick

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))
} 

but with the sleep some bit better :P
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

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
CuecaX
Posts: 13
Joined: Mon Mar 05, 2007 8:54 pm
Location: Brazil

subject

Post by CuecaX »

thanks for help, I will try this sleep() way...

rogerborg: thanks, but I want a portable code :)
Baiame 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?
i dont want my game running well using all processing power at 200fps :P
and i think that using fixed values is simple and easier.
loading singature...
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

if you want portable code so why dont you write some? :?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

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.
Baiame
Posts: 41
Joined: Sun Oct 15, 2006 11:33 am

Re: subject

Post by Baiame »

CuecaX wrote:i dont want my game running well using all processing power at 200fps :P
and i think that using fixed values is simple and easier.
Oh, sorry, I misunderstood your first post. Yeah, that's a good idea.
CuecaX
Posts: 13
Joined: Mon Mar 05, 2007 8:54 pm
Location: Brazil

Post by CuecaX »

roxaz wrote:if you want portable code so why dont you write some? :?
because i´m entering in a competition and dont have much time... i need to finish the game until the end of the month :(
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.
if i did something helpful of course i will release the code ^^
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...
Post Reply