EVENTRECORDER: added new event for OSystem::getTimeAndDate

This commit is contained in:
Martin Gerhardy 2021-07-08 19:31:13 +02:00
parent 674094016a
commit a0c237f7b9
28 changed files with 112 additions and 27 deletions

View file

@ -169,7 +169,7 @@ void OSystem_3DS::delayMillis(uint msecs) {
svcSleepThread(msecs * 1000000);
}
void OSystem_3DS::getTimeAndDate(TimeDate& td) const {
void OSystem_3DS::getTimeAndDate(TimeDate& td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -115,7 +115,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
virtual MutexRef createMutex();
virtual void lockMutex(MutexRef mutex);

View file

@ -575,7 +575,7 @@ Audio::Mixer *OSystem_Android::getMixer() {
return _mixer;
}
void OSystem_Android::getTimeAndDate(TimeDate &td) const {
void OSystem_Android::getTimeAndDate(TimeDate &td, bool skipRecord) const {
struct tm tm;
const time_t curTime = time(0);

View file

@ -135,7 +135,7 @@ public:
virtual void setWindowCaption(const Common::U32String &caption) override;
virtual Audio::Mixer *getMixer() override;
virtual void getTimeAndDate(TimeDate &t) const override;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
virtual void logMessage(LogMessageType::Type type, const char *message) override;
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
virtual bool openUrl(const Common::String &url) override;

View file

@ -505,7 +505,7 @@ Audio::Mixer *OSystem_Android::getMixer() {
return _mixer;
}
void OSystem_Android::getTimeAndDate(TimeDate &td) const {
void OSystem_Android::getTimeAndDate(TimeDate &td, bool skipRecord) const {
struct tm tm;
const time_t curTime = time(0);

View file

@ -179,7 +179,7 @@ public:
virtual void showVirtualKeyboard(bool enable);
virtual Audio::Mixer *getMixer();
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
virtual void logMessage(LogMessageType::Type type, const char *message);
virtual void addSysArchivesToSearchSet(Common::SearchSet &s,
int priority = 0);

View file

@ -142,7 +142,7 @@ public:
void delayMillis(uint msecs);
// Get the current time and date. Correspond to time()+localtime().
void getTimeAndDate(TimeDate &t) const;
void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
// Get the next event.
// Returns true if an event was retrieved.

View file

@ -218,7 +218,7 @@ bool OSystem_Dreamcast::getFeatureState(Feature f)
}
}
void OSystem_Dreamcast::getTimeAndDate(TimeDate &td) const {
void OSystem_Dreamcast::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime;
time(&curTime);
struct tm t = *localtime(&curTime);

View file

@ -117,7 +117,7 @@ void OSystem_DS::doTimerCallback(int interval) {
}
}
void OSystem_DS::getTimeAndDate(TimeDate &td) const {
void OSystem_DS::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -125,7 +125,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
void doTimerCallback(int interval = 10);
virtual Common::EventSource *getDefaultEventSource() { return _eventSource; }

View file

@ -314,7 +314,7 @@ void OSystem_iOS7::setTimerCallback(TimerProc callback, int interval) {
void OSystem_iOS7::quit() {
}
void OSystem_iOS7::getTimeAndDate(TimeDate &td) const {
void OSystem_iOS7::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -185,7 +185,7 @@ public:
virtual void quit() override;
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
virtual void getTimeAndDate(TimeDate &t) const override;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
virtual Audio::Mixer *getMixer() override;

View file

@ -198,7 +198,7 @@ void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) {
void OSystem_IPHONE::quit() {
}
void OSystem_IPHONE::getTimeAndDate(TimeDate &td) const {
void OSystem_IPHONE::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -173,7 +173,7 @@ public:
virtual void quit();
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
virtual Audio::Mixer *getMixer();

View file

@ -195,7 +195,7 @@ public:
virtual void quit();
virtual Audio::Mixer *getMixer();
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &t, bool skipRecord = false) const;
virtual void setTimerCallback(TimerProc callback, int interval);
virtual void logMessage(LogMessageType::Type type, const char *message);

View file

@ -838,7 +838,7 @@ Audio::Mixer *OSystem_N64::getMixer() {
return _mixer;
}
void OSystem_N64::getTimeAndDate(TimeDate &t) const {
void OSystem_N64::getTimeAndDate(TimeDate &t, bool skipRecord) const {
// No RTC inside the N64, read mips timer to simulate
// passing of time, not a perfect solution, but can't think
// of anything better.

View file

@ -87,7 +87,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &t) const;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
virtual void quit();
@ -208,7 +208,7 @@ void OSystem_NULL::delayMillis(uint msecs) {
#endif
}
void OSystem_NULL::getTimeAndDate(TimeDate &td) const {
void OSystem_NULL::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -429,7 +429,7 @@ void OSystem_PSP::logMessage(LogMessageType::Type type, const char *message) {
PspDebugTrace(false, "%s", message); // write to file
}
void OSystem_PSP::getTimeAndDate(TimeDate &td) const {
void OSystem_PSP::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -138,7 +138,7 @@ public:
// Misc
FilesystemFactory *getFilesystemFactory() { return &PSPFilesystemFactory::instance(); }
void getTimeAndDate(TimeDate &t) const;
void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
virtual void engineDone();
void quit();

View file

@ -638,7 +638,7 @@ void OSystem_SDL::delayMillis(uint msecs) {
SDL_Delay(msecs);
}
void OSystem_SDL::getTimeAndDate(TimeDate &td) const {
void OSystem_SDL::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;
@ -648,6 +648,10 @@ void OSystem_SDL::getTimeAndDate(TimeDate &td) const {
td.tm_mon = t.tm_mon;
td.tm_year = t.tm_year;
td.tm_wday = t.tm_wday;
#ifdef ENABLE_EVENTRECORDER
g_eventRec.processTimeAndDate(td, skipRecord);
#endif
}
MixerManager *OSystem_SDL::getMixerManager() {

View file

@ -83,7 +83,7 @@ public:
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
virtual void getTimeAndDate(TimeDate &td) const override;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
virtual MixerManager *getMixerManager() override;
virtual Common::TimerManager *getTimerManager() override;
virtual Common::SaveFileManager *getSavefileManager() override;

View file

@ -266,7 +266,7 @@ FilesystemFactory *OSystem_Wii::getFilesystemFactory() {
return &WiiFilesystemFactory::instance();
}
void OSystem_Wii::getTimeAndDate(TimeDate &td) const {
void OSystem_Wii::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;

View file

@ -208,7 +208,7 @@ public:
virtual Audio::Mixer *getMixer() override;
virtual FilesystemFactory *getFilesystemFactory() override;
virtual void getTimeAndDate(TimeDate &t) const override;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
virtual void logMessage(LogMessageType::Type type, const char *message) override;

View file

@ -373,6 +373,15 @@ void PlaybackFile::readEvent(RecorderEvent& event) {
case kRecorderEventTypeTimer:
event.time = _tmpPlaybackFile.readUint32LE();
break;
case kRecorderEventTypeTimeDate:
event.timeDate.tm_sec = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_min = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_hour = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_mday = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_mon = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_year = _tmpPlaybackFile.readSint32LE();
event.timeDate.tm_wday = _tmpPlaybackFile.readSint32LE();
break;
default:
// fallthrough intended
case kRecorderEventTypeNormal:
@ -549,6 +558,15 @@ void PlaybackFile::writeEvent(const RecorderEvent &event) {
case kRecorderEventTypeTimer:
_tmpRecordFile.writeUint32LE(event.time);
break;
case kRecorderEventTypeTimeDate:
_tmpRecordFile.writeSint32LE(event.timeDate.tm_sec);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_min);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_hour);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_mday);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_mon);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_year);
_tmpRecordFile.writeSint32LE(event.timeDate.tm_wday);
break;
default:
// fallthrough intended
case kRecorderEventTypeNormal:

View file

@ -38,21 +38,39 @@ namespace Common {
enum RecorderEventType {
kRecorderEventTypeNormal = 0,
kRecorderEventTypeTimer = 1
kRecorderEventTypeTimer = 1,
kRecorderEventTypeTimeDate = 2
};
struct RecorderEvent : Event {
RecorderEventType recordedtype;
uint32 time;
union {
uint32 time;
TimeDate timeDate;
};
RecorderEvent() {
recordedtype = kRecorderEventTypeNormal;
time = 0;
timeDate.tm_sec = 0;
timeDate.tm_min = 0;
timeDate.tm_hour = 0;
timeDate.tm_mday = 0;
timeDate.tm_mon = 0;
timeDate.tm_year = 0;
timeDate.tm_wday = 0;
}
RecorderEvent(const Event &e) : Event(e) {
recordedtype = kRecorderEventTypeNormal;
time = 0;
timeDate.tm_sec = 0;
timeDate.tm_min = 0;
timeDate.tm_hour = 0;
timeDate.tm_mday = 0;
timeDate.tm_mon = 0;
timeDate.tm_year = 0;
timeDate.tm_wday = 0;
}
};

View file

@ -1368,7 +1368,7 @@ public:
* On many systems, this corresponds to the combination of time()
* and localtime().
*/
virtual void getTimeAndDate(TimeDate &t) const = 0;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const = 0;
/**
* Return the timer manager singleton.

View file

@ -77,6 +77,13 @@ EventRecorder::EventRecorder() {
_needRedraw = false;
_processingMillis = false;
_fastPlayback = false;
_lastTimeDate.tm_sec = 0;
_lastTimeDate.tm_min = 0;
_lastTimeDate.tm_hour = 0;
_lastTimeDate.tm_mday = 0;
_lastTimeDate.tm_mon = 0;
_lastTimeDate.tm_year = 0;
_lastTimeDate.tm_wday = 0;
_fakeTimer = 0;
_savedState = false;
@ -119,6 +126,42 @@ void EventRecorder::deinit() {
DebugMan.disableDebugChannel("EventRec");
}
void EventRecorder::processTimeAndDate(TimeDate &td, bool skipRecord) {
if (!_initialized) {
return;
}
if (skipRecord) {
td = _lastTimeDate;
return;
}
Common::RecorderEvent timeDateEvent;
switch (_recordMode) {
case kRecorderRecord:
timeDateEvent.recordedtype = Common::kRecorderEventTypeTimeDate;
timeDateEvent.timeDate = td;
_lastTimeDate = td;
_playbackFile->writeEvent(timeDateEvent);
break;
case kRecorderPlayback:
if (_nextEvent.recordedtype != Common::kRecorderEventTypeTimeDate) {
// just re-use any previous date time value
td = _lastTimeDate;
return;
}
_lastTimeDate = _nextEvent.timeDate;
td = _lastTimeDate;
debug(3, "timedate event");
_nextEvent = _playbackFile->getNextEvent();
break;
case kRecorderPlaybackPause:
td = _lastTimeDate;
break;
default:
break;
}
}
void EventRecorder::processMillis(uint32 &millis, bool skipRecord) {
if (!_initialized) {
return;

View file

@ -81,6 +81,7 @@ public:
void deinit();
bool processDelayMillis();
uint32 getRandomSeed(const Common::String &name);
void processTimeAndDate(TimeDate &td, bool skipRecord);
void processMillis(uint32 &millis, bool skipRecord);
void processGameDescription(const ADGameDescription *desc);
Common::SeekableReadStream *processSaveStream(const Common::String & fileName);
@ -178,6 +179,7 @@ private:
bool notifyEvent(const Common::Event &event) override;
bool _initialized;
volatile uint32 _fakeTimer;
TimeDate _lastTimeDate;
bool _savedState;
bool _needcontinueGame;
int _temporarySlot;