//------------------------------------------------------------------------ void CItemScheduler::Update(float frameTime) { if (frameTime > 0.2f) frameTime = 0.2f; if (!m_schedule.empty()) { while(!m_schedule.empty() && !m_busy) { SScheduledAction &action = *m_schedule.begin(); ISchedulerAction *pAction= action.action; m_schedule.erase(m_schedule.begin()); pAction->execute(m_pItem); pAction->destroy(); } } if (!m_timers.empty()) { uint32 count=0; m_actives.swap(m_timers); for (TTimerActionVector::iterator it = m_actives.begin(); it != m_actives.end(); it++) { STimerAction &action = *it; action.time -= frameTime; if (action.time <= 0.0f) { action.action->execute(m_pItem); action.action->destroy(); ++count; } } if (count) m_actives.erase(m_actives.begin(), m_actives.begin()+count); if (!m_timers.empty()) { for (TTimerActionVector::iterator it=m_timers.begin(); it!=m_timers.end(); ++it) m_actives.push_back(*it); std::sort(m_actives.begin(), m_actives.end(), compare_timers()); } m_actives.swap(m_timers); m_actives.resize(0); } if (m_timers.empty() && m_schedule.empty()) m_pItem->EnableUpdate(false, eIUS_Scheduler); }
//------------------------------------------------------------------------ void CItemScheduler::TimerAction(uint32 time, ISchedulerAction *action, bool persistent) { if (m_locked) return; STimerAction timerAction; timerAction.action = action; timerAction.time = (float)time/1000.0f; timerAction.persist = persistent; m_timers.push_back(timerAction); std::sort(m_timers.begin(), m_timers.end(), compare_timers()); m_pItem->EnableUpdate(true, eIUS_Scheduler); }
//------------------------------------------------------------------------ void CItemScheduler::TimerAction(float fTimeSeconds, ISchedulerAction *action, bool persistent/*=false*/) { if (m_locked) return; STimerAction timerAction; timerAction.action = action; timerAction.time = fTimeSeconds; timerAction.persist = persistent; m_timers.push_back(timerAction); std::sort(m_timers.begin(), m_timers.end(), compare_timers()); m_pItem->EnableUpdate(true, eIUS_Scheduler); }