// 计时器运行time毫秒 void RanaTimerBank::routine(RanaTIME _expiretime) { m_curTime = _expiretime; std::multiset<RanaTimer*,CompRanaTimerPoint>::iterator timerIt; for (timerIt=m_activeTimer.begin(); timerIt!=m_activeTimer.end(); timerIt=m_activeTimer.begin() ) { RanaTimer* timer = *timerIt; if(timer->getExpireTime() > _expiretime) { break; } m_activeTimer.erase(timerIt); bool bStop = true; if( timer->getRepeat() ) { int periodTime = (int)timer->getPeriodTime(); if( periodTime > 0) { bStop = false; timer->setExpireTime( timer->getExpireTime() + timer->getPeriodTime() ); m_timerMap[timer->getSpaceHandle().handle][timer->getHandle()].activeIt = m_activeTimer.insert(timer); } } if(bStop) { timer->setOnOff(false); timer->setRestTime(0); m_timerMap[timer->getSpaceHandle().handle][timer->getHandle()].pausedIt = m_pausedTimer.insert(m_pausedTimer.end(),timer); m_timerMap[timer->getSpaceHandle().handle][timer->getHandle()].itType = ListIterator::E_PAUSED; } RanaSpace* pRanaSpace = RanaSpaceBank::getInstance()->getLuaSpace( timer->getSpaceHandle() ); if(!pRanaSpace) { RANA_ASSERT(0); delTimer( timer->getSpaceHandle() ); continue; } RanaTimeMessage msg; // msg.setSpaceName( ); msg.setTimerHandle(timer->getHandle()); pRanaSpace->onMessage(&msg); } }
int Doodle::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: createSmoke1(); break; case 1: createSmoke2(); break; case 2: createSmoke3(); break; case 3: delTimer(); break; case 4: endAnimation(); break; case 5: switchScreen(); break; default: ; } _id -= 6; } return _id; }
/** @brief (one liner) * * (documentation goes here) */ int CEvent::addTimer(int iTimerId,uint32_t dwExpire, const HandlerEvent &onEvent, void* pClientData) { MAP_TIME_INDEX::iterator it = m_mapTimeEventIndexs.find(iTimerId); if(it != m_mapTimeEventIndexs.end()) { delTimer(iTimerId); } STimeEvent stTimeEvent; stTimeEvent.ddwMillSecs = CEvent::getMillSecsNow()+dwExpire; stTimeEvent.iTimerId=iTimerId; stTimeEvent.pClientData=pClientData; stTimeEvent.onTimer=onEvent; m_mapTimeEventIndexs[iTimerId] = stTimeEvent.ddwMillSecs; m_setSTimeEvents.insert(stTimeEvent); return 0; }
void Timer_test() { size_t i; const struct timespec* rTime; Timer* t = newTimer(1, 0); if(!t) { printf("Error occurred allocating memory for the timer.\n"); return; } Timer_begin(t); rTime = Timer_get_run_time(t); usleep(NANOS_TO_MICROS(rTime->tv_nsec) + SECONDS_TO_MICROS(rTime->tv_sec)); for(i = 0; !Timer_check(t); ++i); printf("Timer check %lu times.\n", i); Timer_begin(t); for(i = 0; !Timer_check(t); ++i) usleep((NANOS_TO_MICROS(rTime->tv_nsec) + SECONDS_TO_MICROS(rTime->tv_sec)) / 10); printf("Timer check %lu times.\n", i); delTimer(&t); }