X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fevent_mgr.cxx;h=63e4672faaeb0a95212cb39760af5925dc050619;hb=f3c131ffaf04d8e04595c1271f8a70c8a9d89f5f;hp=6753a38f41de7cf5b22e0b3160911cefb9441f6e;hpb=b48c0e968fcba4c063419e12674a7f2b24954b43;p=simgear.git 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; } -