Using the ITimer for Minutes/Seconds

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Using the ITimer for Minutes/Seconds

Post by DarkWhoppy »

I'm alittle lazy and not too good with things like this. But I need to use the ITimer to find the minutes and seconds thats passed since I last reset it. But, I get these outrages differences when I change on digit :?: . Like

if(Time >= 3000) //Millisecs
{
. . . .
}

If I change that to 4000 the time doesnt' change at all. . . :x . Could someone paste some code for a timer?
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

Code: Select all

//1000ms = 1 second
//60sec =  1 minute
//60000ms = 1 minute

void getTimeSince(u32 time, u32 & minutes, u32 & seconds) {
   u32 currTime = ITimer->getTime()

   u32 delta = currTime - time;  
   // delta =  minutes * 60000 + seconds * 1000 + ms

   //get num ms left that dont make up a minute   ( afterMinutes = seconds * 1000 + ms )
   u32 afterMinutes =  delta % 60000; 
   minutes = (delta-afterMinutes)/60000; 

   //get num ms left that dont make up a second ( afterseconds = ms )
   u32 afterSeconds = afterMinutes % 1000;    
   seconds = (delta - minutes*60000 - afterSeconds) / 1000;

}
modulus isnt the fastest thing to use-- i wonder if anyone knows a faster way?
a screen cap is worth 0x100000 DWORDS
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

i wrote a timer class to handle this for Fmorg...

Post by buhatkj »

here is a link to it:
http://buhatkj.dyndns.org:4242/tempfiles/fmorgTimer.h
i sent it in to niko, as a proposed addition to 0.05, but it is of course up to him if he decides to adapt it for that purpose.

oh, and it still uses ms, so i just multiply the seconds by 1000 when i pass it the time to set for. it wouldnt be too hard to just add another version of the set func that does that part for ya tho.
-Ted
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Thanks man, the FMORG timer works well :) .
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Post Reply