diff --git a/common/events.cpp b/common/events.cpp index 242a00e8eac..5450b064236 100644 --- a/common/events.cpp +++ b/common/events.cpp @@ -71,6 +71,8 @@ void EventDispatcher::dispatch() { dispatchPoll(); for (List::iterator i = _sources.begin(); i != _sources.end(); ++i) { + if (i->ignore) + continue; while (i->source->pollEvent(event)) { // We only try to process the events via the setup event mapper, when // we have a setup mapper and when the event source allows mapping. @@ -102,6 +104,8 @@ void EventDispatcher::clearEvents() { Event event; for (List::iterator i = _sources.begin(); i != _sources.end(); ++i) { + if (i->ignore) + continue; while (i->source->pollEvent(event)) {} } } @@ -117,6 +121,7 @@ void EventDispatcher::registerSource(EventSource *source, bool autoFree) { newEntry.source = source; newEntry.autoFree = autoFree; + newEntry.ignore = false; _sources.push_back(newEntry); } @@ -133,6 +138,12 @@ void EventDispatcher::unregisterSource(EventSource *source) { } } +void EventDispatcher::ignoreSources(bool ignore) { + for (List::iterator i = _sources.begin(); i != _sources.end(); ++i) { + i->ignore = ignore; + } +} + void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool autoFree, bool notifyPoll) { ObserverEntry newEntry; diff --git a/common/events.h b/common/events.h index a392611e053..63388178592 100644 --- a/common/events.h +++ b/common/events.h @@ -402,6 +402,12 @@ public: */ void unregisterSource(EventSource *source); + /** + * Ignore some event sources and don't poll them. This is useful for e.g. the EventRecorder + * where you don't want the other EventSource instances to interfer with the serialized events. + */ + void ignoreSources(bool ignore); + /** * Register a new EventObserver with the Dispatcher. * @@ -421,6 +427,7 @@ private: struct Entry { bool autoFree; + bool ignore; }; struct SourceEntry : public Entry { diff --git a/gui/EventRecorder.cpp b/gui/EventRecorder.cpp index bc15a376524..6075c410bdf 100644 --- a/gui/EventRecorder.cpp +++ b/gui/EventRecorder.cpp @@ -107,7 +107,9 @@ void EventRecorder::deinit() { _controlPanel->close(); delete _controlPanel; debugC(1, kDebugLevelEventRec, "playback:action=stopplayback"); - g_system->getEventManager()->getEventDispatcher()->unregisterSource(this); + Common::EventDispatcher *eventDispater = g_system->getEventManager()->getEventDispatcher(); + eventDispater->unregisterSource(this); + eventDispater->ignoreSources(false); _recordMode = kPassthrough; _playbackFile->close(); delete _playbackFile; @@ -271,8 +273,11 @@ void EventRecorder::init(const Common::String &recordFileName, RecordMode mode) } if (_recordMode == kRecorderPlayback) { debugC(1, kDebugLevelEventRec, "playback:action=\"Load file\" filename=%s", recordFileName.c_str()); + Common::EventDispatcher *eventDispater = g_system->getEventManager()->getEventDispatcher(); + eventDispater->clearEvents(); + eventDispater->ignoreSources(true); + eventDispater->registerSource(this, false); } - g_system->getEventManager()->getEventDispatcher()->registerSource(this, false); _screenshotPeriod = ConfMan.getInt("screenshot_period"); if (_screenshotPeriod == 0) { _screenshotPeriod = kDefaultScreenshotPeriod; @@ -304,9 +309,8 @@ void EventRecorder::init(const Common::String &recordFileName, RecordMode mode) /** * Opens or creates file depend of recording mode. * - *@param id of recording or playing back game - *@return true in case of success, false in case of error - * + * @param id of recording or playing back game + * @return true in case of success, false in case of error */ bool EventRecorder::openRecordFile(const Common::String &fileName) { bool result;