Code: Select all
irrDevice->getTimer()->start();
cout<<irrDevice->getTimer()->getTime()<<" "<<irrDevice->getTimer()->isStopped()<<endl;
Code: Select all
0 1
0 1
0 1
How can i start this timer?
Code: Select all
irrDevice->getTimer()->start();
cout<<irrDevice->getTimer()->getTime()<<" "<<irrDevice->getTimer()->isStopped()<<endl;
Code: Select all
0 1
0 1
0 1
Code: Select all
IrrTime* time = irrDevice->getTimer();
time->strart();
Code: Select all
while (device->run()) {
timer->start();
printf(time);
}Code: Select all
mtimer->stop();
cout<<"stop. stopped? "<<mtimer->isStopped()<<endl;
mtimer->start();
cout<<"start. stopped? "<<mtimer->isStopped()<<endl;
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
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 }
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.floppyfreak wrote:To me personally it makes no sense to have a counter here. What's the perpose of that?
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.the documentation sais, you can start and stop the timer with start() and stop().
Yes, you can work around the problem, but that doesn't change the fact that it is a bug.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().
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;
}