From: ThorstenB Date: Sun, 3 Apr 2011 15:39:23 +0000 (+0200) Subject: Minor event manager clean-up/simplification. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3c0c51a9461f3c85642b0de18b5c9c65078816b6;p=simgear.git Minor event manager clean-up/simplification. (Mainly disliked the "delete this;" concept :) ). --- diff --git a/simgear/structure/event_mgr.cxx b/simgear/structure/event_mgr.cxx index 6753a38f..63e4672f 100644 --- a/simgear/structure/event_mgr.cxx +++ b/simgear/structure/event_mgr.cxx @@ -14,9 +14,7 @@ void SGEventMgr::add(const std::string& name, SGCallback* cb, SGTimer* t = new SGTimer; t->interval = interval; t->callback = cb; - t->mgr = this; t->repeat = repeat; - t->simtime = simtime; t->name = name; SGTimerQueue* q = simtime ? &_simQueue : &_rtQueue; @@ -24,17 +22,15 @@ void SGEventMgr::add(const std::string& name, SGCallback* cb, q->insert(t, delay); } +SGTimer::~SGTimer() +{ + delete callback; + callback = NULL; +} + void SGTimer::run() { (*callback)(); - - if(repeat) { - SGTimerQueue* q = simtime ? &mgr->_simQueue : &mgr->_rtQueue; - q->insert(this, interval); - } else { - delete callback; - delete this; - } } void SGEventMgr::update(double delta_time_sec) @@ -99,6 +95,11 @@ void SGTimerQueue::update(double deltaSecs) while(_numEntries && nextTime() <= _now) { SGTimer* t = remove(); t->run(); + if(t->repeat) { + insert(t, t->interval); + } else { + delete t; + } } } @@ -193,4 +194,3 @@ SGTimer* SGTimerQueue::findByName(const std::string& name) const return NULL; } - diff --git a/simgear/structure/event_mgr.hxx b/simgear/structure/event_mgr.hxx index 5b31c809..b68517ae 100644 --- a/simgear/structure/event_mgr.hxx +++ b/simgear/structure/event_mgr.hxx @@ -8,14 +8,15 @@ class SGEventMgr; -struct SGTimer { +class SGTimer { +public: + ~SGTimer(); + void run(); + std::string name; double interval; SGCallback* callback; - SGEventMgr* mgr; bool repeat; - bool simtime; - void run(); }; class SGTimerQueue { @@ -37,7 +38,7 @@ public: SGTimer* findByName(const std::string& name) const; private: // The "priority" is stored as a negative time. This allows the - // implemenetation to treat the "top" of the heap as the largest + // implementation to treat the "top" of the heap as the largest // value and avoids developer mindbugs. ;) struct HeapEntry { double pri; SGTimer* timer; };