getRealTime question

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
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

getRealTime question

Post by kendric »

Here is a tiny snippet of code:

Code: Select all

timeNow=myGameDevice->getTimer()->getRealTime();
game->mainLoop(timeNow-timeLastMainUpdate);
timeLastMainUpdate=myGameDevice->getTimer()->getRealTime();
in mainLoop im doing:
totalMilliPassed+=millisecondsPassed;

I print the value out every so often to watch time pass. I am seeing the time passing slower then it should as measured by calls to this every so often:

Code: Select all

time_t rawtime;
time ( &rawtime );
printf ( "The current local time is: %s", ctime (&rawtime) );
Should these numbers not be changing at the same rate?
I am seeing a 8 second time block in ctime and a 5 second time block in the other one.

Am I missing something?
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

I tried changing my timing loop to look like this:

Code: Select all

	myGameDevice->getTimer()->start();
	myGameDevice->getTimer()->tick();
	u32 lastTime=myGameDevice->getTimer()->getTime();
	u32 timeDiff=0;
	u32 nextTime=0;
	while(game->running&&myGameDevice->run())
	{
		myGameDevice->getTimer()->tick();//This is probably not needed since I believe it happens in the irr render function
		u32 nextTime=myGameDevice->getTimer()->getTime();
		timeDiff=nextTime-lastTime;
		lastTime=nextTime;
		game->mainLoop(timeDiff);
		game->render();
	}
	myGameDevice->getTimer()->stop();
But i must really not get this cause the time is always comming back as 0. Does anyone know how to use this correctly?
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

getRealTime worked for me. Not sure why the other one didnt work
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Don't call startTimer() unless you've called stopTimer(). It has a bug that causes it to stop the timer if it is already running. You should be able to write this...

Code: Select all

   u32 lastTime = myGameDevice->getTimer()->getTime(); 

   while(game->running && myGameDevice->run()) 
   { 
      u32 nextTime = myGameDevice->getTimer()->getTime(); 
      u32 timeDiff = nextTime-lastTime; 
      lastTime = nextTime; 

      game->mainLoop(timeDiff); 
      game->render(); 
   } 
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

Ahh Thanks.
Post Reply