(Mainly disliked the "delete this;" concept :) ).
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;
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)
while(_numEntries && nextTime() <= _now) {
SGTimer* t = remove();
t->run();
+ if(t->repeat) {
+ insert(t, t->interval);
+ } else {
+ delete t;
+ }
}
}
return NULL;
}
-
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 {
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; };