I have no time :]

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
floppyfreak
Posts: 117
Joined: Sat Apr 19, 2008 10:14 am

I have no time :]

Post by floppyfreak »

When i write in the device->run() loop

Code: Select all

            irrDevice->getTimer()->start();
            cout<<irrDevice->getTimer()->getTime()<<" "<<irrDevice->getTimer()->isStopped()<<endl;
I get

Code: Select all

0 1
0 1
0 1
on the console. (the line with the start() is here only for testing perposes.
How can i start this timer?
pelonzudo
Posts: 20
Joined: Wed May 07, 2008 11:14 am

Post by pelonzudo »

I think...

Code: Select all

IrrTime* time = irrDevice->getTimer();
time->strart();
That is (if I'm rigth) every time you call getTimer, you got a pointer to an irrTime object, so you need a pointer to get it and work with it.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to use the usual render loop to advance the timer, or do it manually in your own handler. Should be documented in the API and some example.
floppyfreak
Posts: 117
Joined: Sat Apr 19, 2008 10:14 am

Post by floppyfreak »

oh, thanks a lot. Without testing I am sure, I'll get it now :oops:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Surely it's the user of timer->start() that's bad?

I'm assuming floppyfreak's code is like this:

Code: Select all

while (device->run()) {
  timer->start();
  printf(time);
}
you shouldn't need to call start should you? though of course that doesn't really explain why isStopped is returning true...

floppyfreak, as hybrid said, you do need to have device->run() or timer->tick() called each frame.
Image Image Image
floppyfreak
Posts: 117
Joined: Sat Apr 19, 2008 10:14 am

Post by floppyfreak »

total confusion here now :P
little test prog:

Code: Select all

    mtimer->stop();
    cout<<"stop. stopped? "<<mtimer->isStopped()<<endl;
    mtimer->start();
    cout<<"start. stopped? "<<mtimer->isStopped()<<endl;

now I can make funny things like producing output (by repeated starts and stops) like

Code: Select all

stop. stopped? 1
start. stopped? 0
start. stopped? 1
stop. stopped? 1
stop. stopped? 1
start. stopped? 1
start. stopped? 1
start. stopped? 0
start. stopped? 1
stop. stopped? 0
start. stopped? 1
so I can stop the timer by saying start and start him by saying stop.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Looks like a bug to me...

Code: Select all

  248 	//! stops the virtual timer
  249 	void Timer::stopTimer()
  250 	{
  251 		if (!isStopped())
  252 		{
  253 			// stop the virtual timer
  254 			LastVirtualTime = getTime();
  255 		}
  256 
  257 		--VirtualTimerStopCounter;
  258 	}
  259 
  260 	//! starts the virtual timer
  261 	void Timer::startTimer()
  262 	{
  263 		++VirtualTimerStopCounter;
  264 
  265 		if (!isStopped())
  266 		{
  267 			// restart virtual timer
  268 			setTime(LastVirtualTime);
  269 		}
  270 	}

  288 	//! returns if the timer currently is stopped
  289 	bool Timer::isStopped()
  290 	{
  291 		return VirtualTimerStopCounter != 0;
  292 	}
I think that the timer is 'stopped' if VirtualTimerStopCounter < 0. Multiple calls to stopTimer() should decrement the counter, and the timer shouldn't be started until the appropriate number of startTimer() calls have been made.

If this is how it should work, then the startTimer() and stopTimer() methods need to be updated to only modify the virtual time if the current value of VirtualTimerStopCounter == 0 [i.e. the clock is switching states].

Travis
floppyfreak
Posts: 117
Joined: Sat Apr 19, 2008 10:14 am

Post by floppyfreak »

To me personally it makes no sense to have a counter here. What's the perpose of that? the documentation sais, you can start and stop the timer with start() and stop(). If it works, it should be enough for most tasks. If you need a counter, write it.
In my case the reason for the confusion was, that i started the timer while it was started, which stopped him. So I just will add something like
if isStopped() start().
By the way, this can't affect me. irrlicht is just great. :)
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

floppyfreak wrote:To me personally it makes no sense to have a counter here. What's the perpose of that?
The purpose is so that you can require every call to stop() be matched with a call to start() to get the timer started again.

Say you have different blocks of code that use the timer. Two of these blocks call stop() then the timer should be stopped, right? Then, if one of them calls start() the timer should remain stopped until the other block of code calls start(), right? That is what the counter does.

The problem with the way that it is currently setup is that the isStopped() function returns true when the timer is not really stopped at all.
the documentation sais, you can start and stop the timer with start() and stop().
No, I'm afraid it does not. The documentation says... The timer is reference counted, which means everything which calls stop() will also have to call start(), otherwise the timer may not start/stop correctly again.
floppyfreak wrote:In my case the reason for the confusion was, that i started the timer while it was started, which stopped him. So I just will add something like
if isStopped() start().
Yes, you can work around the problem, but that doesn't change the fact that it is a bug.

I believe the correct implementation is...

Code: Select all

//! stops the virtual timer 
void Timer::stopTimer() 
{
   if (VirtualTimerStopCounter == 0) 
      LastVirtualTime = getTime(); 

   --VirtualTimerStopCounter; 
} 

//! starts the virtual timer 
void Timer::startTimer() 
{ 
   ++VirtualTimerStopCounter; 

   if (VirtualTimerStopCounter == 0) 
      setTime(LastVirtualTime); 
} 

//! returns if the timer currently is stopped 
bool Timer::isStopped() 
{ 
  return VirtualTimerStopCounter < 0; 
}
This way isStopped() only returns true if there have been more calls to stop() than calls to start().

Travis
Post Reply