ITimer doesn't start !!

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
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

ITimer doesn't start !!

Post by DaChief »

hey guys !

I got a problem with the Timer. I don't get this timer starting !
It is always at ZERO and if i use timer->isStopped() i always get TRUE.
And YES, i started the Timer with timer->start() and i heard that since 0.12 you don't need to write timer->tick() in the main-loop. (i never used a version below 0.12, so i dont start writing it anywhere :wink:)

i'm not sure, maybe there's a mistake in my code or something.
I don't have the Code here, but it looks something like this:

Code: Select all

device->createDevice(...);
ITimer* timer=device->getTimer();
ILogger* logger=device->getLogger();
timer->start();

while(device->run())
{
     if (timer->isStopped()) logger->log("Timer is Stopped !");
};
I hope someone can help me out. I didn't find the mistake.
And yes, timer->getRealTime() works ! it shows me the ms which passed since i started the app... but timer->getTimer() is always ZERO cause the Timer doesn't start.

If you need the hole Code around there, i can get it for you in some hours. I just had to cry my problems out here ^^
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

You aren't using the timer correctly, if you look at the examples, they show you how it should be used.
Guest

Post by Guest »

Are you sure ?
argh ^^

alright... could you post an example for me ?

thx anyway for the info :wink:
it looks like i'm not that "advanced" as i tought :D
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

ARGH... sry.. forgot to login :wink:
hybrid

Post by hybrid »

I'm not so sure that you're using Timer wrongly. Did you ever try to sue the timer without starting it? It should automatically start with deveice creation, so check the values of getTime(). start should be only used and needed if you want to stop later on. Should not break behaviour, though, so your code should be checked again, too.
bakkdoor
Posts: 49
Joined: Fri May 07, 2004 4:31 pm
Location: home

Post by bakkdoor »

i'm having problems with my timer too.
it doesnt seem to work, even with timer->start();

here is my code:

Code: Select all

    while(!g_GameApp->isQuitting() && g_GameApp->device->run())
    {
            if(timer->isStopped())
            {
            	timer->start();
            }                                
            fTime = timer->getTime();
          	if(fTime > 0)
          	{
          		fElapsedTime  = (1000.0f / (float)fTime);
          	}
          	
          	timer->tick();
          	
          	cout << fTime << " " << fElapsedTime << endl;
          	cout << timer->isStopped() << endl;
          	while(timer->isStopped())
          	{
                 timer->start();
                 cout << timer->getTime() << " <- TIME!!" << endl;
            }

          g_GameApp->OnRender(fTime, fElapsedTime);
    }

what i get displayed in my console window is this:
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
0 <- TIME!!
and the game doesnt do anything else anymore. it's really weird and my whole eventsystem is depending on it. any other way how to calculate the milliseconds that have passed since starting the game?
omaremad_

Post by omaremad_ »

hello

its seems that the variables might be an int so it rounds it or maybe the new irrlicht and its virtual timers and real timers are getting confused


(there are now 2 new timer types in ver .12)
omaremad_

Post by omaremad_ »

try the fnord timer
hybrid

Post by hybrid »

You should not start the timer too often. Every timer is reset each time it is started. Since there could be a problem with start/stop try to remove start/stop completely. And be sure that your device->run() does not call tick() itself. Will check it right now.
hybrid

Post by hybrid »

Ok, timer works in two ways. First, if you never touch start or stop it works out of the box. Second, if you want to start and stop it keep in mind that it is automatically started. So first call stop, then start.
Please note that first is a special case of second :wink:
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

doesn't device->run() call tick() ? I'm pretty sure it does... if that's the case, then every time you call tick, you are wiping out your result.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post by DaChief »

Cool... the timer is working now...
sure... if you want to start the timer, why should you call timer->start()
seriously, i don't know why ! :D

thx guys, i knew i can count on you ^^

whatever.. i got some other problems now, but the timer isn't the bad guy. it's simply my coding skills so don't worry :wink:

@bakkdoor
little info:
->getTime() <- virtual timer
->getRealTime() <- ms since app-start
AND you don't have to call ->tick() anymore. It is called by the device...
bakkdoor
Posts: 49
Joined: Fri May 07, 2004 4:31 pm
Location: home

Post by bakkdoor »

thanks for mentioning the getRealTime() function! that's what i needed and the event system now works perfectly :D
i'm so happy :D
omaremad_

Post by omaremad_ »

yay the event system is born time for some the fun programming
Post Reply