EVENTRECORDER: ignore other event sources when playing back a record

This commit is contained in:
Martin Gerhardy 2021-06-23 19:52:44 +02:00 committed by Eugene Sandulenko
parent 5ae72dc190
commit f35cc92aaf
3 changed files with 27 additions and 5 deletions

View File

@ -71,6 +71,8 @@ void EventDispatcher::dispatch() {
dispatchPoll();
for (List<SourceEntry>::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<SourceEntry>::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<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
i->ignore = ignore;
}
}
void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool autoFree, bool notifyPoll) {
ObserverEntry newEntry;

View File

@ -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 {

View File

@ -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;