From: Mikko Rasa Date: Sun, 30 Oct 2016 15:15:40 +0000 (+0200) Subject: Add integration between EventDispatcher and Timer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7ca970e5db84020e4735afccf43ede4d52ac0bf0;p=libs%2Fcore.git Add integration between EventDispatcher and Timer --- diff --git a/source/io/eventdispatcher.cpp b/source/io/eventdispatcher.cpp index 144ad49..cf37c1e 100644 --- a/source/io/eventdispatcher.cpp +++ b/source/io/eventdispatcher.cpp @@ -1,3 +1,4 @@ +#include #include "base.h" #include "eventdispatcher.h" #include "eventobject.h" @@ -57,6 +58,15 @@ void EventDispatcher::tick(const Time::TimeDelta &dt) dispatch(); } +void EventDispatcher::tick(const Time::Timer &timer) +{ + const Time::TimeStamp &timeout = timer.get_next_timeout(); + if(timeout) + tick(timeout-Time::now()); + else + tick(); +} + void EventDispatcher::object_events_changed(PollEvent ev, EventObject *obj) { poller.set_object(*obj, ev); diff --git a/source/io/eventdispatcher.h b/source/io/eventdispatcher.h index 25455ab..b542d67 100644 --- a/source/io/eventdispatcher.h +++ b/source/io/eventdispatcher.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "poll.h" namespace Msp { @@ -45,6 +46,10 @@ public: waits at most the specified time before returning. */ void tick(const Time::TimeDelta &); + /** Checks for and dispatches events. If there are no events available, + waits until the timer's next timeout before returning. */ + void tick(const Time::Timer &); + private: void object_events_changed(PollEvent, EventObject *); void object_deleted(EventObject *);