aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2010-11-19 00:38:17 +0000
committerMax Horn2010-11-19 00:38:17 +0000
commita72de47d5dba28b635bea0127fbb7d1a71aef8ed (patch)
treec05409cf14ea252f176235e561a3e5004303b9b6 /common
parentaef1ca4c4b43c56962dff25b4c02e24ed7238936 (diff)
downloadscummvm-rg350-a72de47d5dba28b635bea0127fbb7d1a71aef8ed.tar.gz
scummvm-rg350-a72de47d5dba28b635bea0127fbb7d1a71aef8ed.tar.bz2
scummvm-rg350-a72de47d5dba28b635bea0127fbb7d1a71aef8ed.zip
COMMON: Cleanup EventRecorder
svn-id: r54355
Diffstat (limited to 'common')
-rw-r--r--common/EventRecorder.cpp73
-rw-r--r--common/EventRecorder.h35
2 files changed, 55 insertions, 53 deletions
diff --git a/common/EventRecorder.cpp b/common/EventRecorder.cpp
index 2ce57b8502..07a651be65 100644
--- a/common/EventRecorder.cpp
+++ b/common/EventRecorder.cpp
@@ -27,6 +27,7 @@
#include "common/config-manager.h"
#include "common/random.h"
+#include "common/savefile.h"
DECLARE_SINGLETON(Common::EventRecorder);
@@ -35,25 +36,25 @@ namespace Common {
#define RECORD_SIGNATURE 0x54455354
#define RECORD_VERSION 1
-void readRecord(Common::InSaveFile *inFile, uint32 &diff, Common::Event &event) {
+void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event) {
diff = inFile->readUint32LE();
- event.type = (Common::EventType)inFile->readUint32LE();
+ event.type = (EventType)inFile->readUint32LE();
switch (event.type) {
- case Common::EVENT_KEYDOWN:
- case Common::EVENT_KEYUP:
- event.kbd.keycode = (Common::KeyCode)inFile->readSint32LE();
+ case EVENT_KEYDOWN:
+ case EVENT_KEYUP:
+ event.kbd.keycode = (KeyCode)inFile->readSint32LE();
event.kbd.ascii = inFile->readUint16LE();
event.kbd.flags = inFile->readByte();
break;
- case Common::EVENT_MOUSEMOVE:
- case Common::EVENT_LBUTTONDOWN:
- case Common::EVENT_LBUTTONUP:
- case Common::EVENT_RBUTTONDOWN:
- case Common::EVENT_RBUTTONUP:
- case Common::EVENT_WHEELUP:
- case Common::EVENT_WHEELDOWN:
+ case EVENT_MOUSEMOVE:
+ case EVENT_LBUTTONDOWN:
+ case EVENT_LBUTTONUP:
+ case EVENT_RBUTTONDOWN:
+ case EVENT_RBUTTONUP:
+ case EVENT_WHEELUP:
+ case EVENT_WHEELDOWN:
event.mouse.x = inFile->readSint16LE();
event.mouse.y = inFile->readSint16LE();
break;
@@ -62,25 +63,25 @@ void readRecord(Common::InSaveFile *inFile, uint32 &diff, Common::Event &event)
}
}
-void writeRecord(Common::OutSaveFile *outFile, uint32 diff, const Common::Event &event) {
+void writeRecord(WriteStream *outFile, uint32 diff, const Event &event) {
outFile->writeUint32LE(diff);
outFile->writeUint32LE((uint32)event.type);
switch (event.type) {
- case Common::EVENT_KEYDOWN:
- case Common::EVENT_KEYUP:
+ case EVENT_KEYDOWN:
+ case EVENT_KEYUP:
outFile->writeSint32LE(event.kbd.keycode);
outFile->writeUint16LE(event.kbd.ascii);
outFile->writeByte(event.kbd.flags);
break;
- case Common::EVENT_MOUSEMOVE:
- case Common::EVENT_LBUTTONDOWN:
- case Common::EVENT_LBUTTONUP:
- case Common::EVENT_RBUTTONDOWN:
- case Common::EVENT_RBUTTONUP:
- case Common::EVENT_WHEELUP:
- case Common::EVENT_WHEELDOWN:
+ case EVENT_MOUSEMOVE:
+ case EVENT_LBUTTONDOWN:
+ case EVENT_LBUTTONUP:
+ case EVENT_RBUTTONDOWN:
+ case EVENT_RBUTTONUP:
+ case EVENT_WHEELUP:
+ case EVENT_WHEELDOWN:
outFile->writeSint16LE(event.mouse.x);
outFile->writeSint16LE(event.mouse.y);
break;
@@ -109,7 +110,7 @@ EventRecorder::~EventRecorder() {
}
void EventRecorder::init() {
- Common::String recordModeString = ConfMan.get("record_mode");
+ String recordModeString = ConfMan.get("record_mode");
if (recordModeString.compareToIgnoreCase("record") == 0) {
_recordMode = kRecorderRecord;
} else {
@@ -236,7 +237,7 @@ void EventRecorder::deinit() {
for (uint i = 0; i < _recordCount; ++i) {
uint32 tempDiff;
- Common::Event tempEvent;
+ Event tempEvent;
readRecord(_playbackFile, tempDiff, tempEvent);
writeRecord(_recordFile, tempDiff, tempEvent);
}
@@ -252,7 +253,7 @@ void EventRecorder::deinit() {
g_system->deleteMutex(_recorderMutex);
}
-void EventRecorder::registerRandomSource(Common::RandomSource &rnd, const char *name) {
+void EventRecorder::registerRandomSource(RandomSource &rnd, const char *name) {
if (_recordMode == kRecorderRecord) {
RandomSourceRecord rec;
rec.name = name;
@@ -305,11 +306,11 @@ void EventRecorder::processMillis(uint32 &millis) {
g_system->unlockMutex(_timeMutex);
}
-bool EventRecorder::notifyEvent(const Common::Event &ev) {
+bool EventRecorder::notifyEvent(const Event &ev) {
if (_recordMode != kRecorderRecord)
return false;
- Common::StackLock lock(_recorderMutex);
+ StackLock lock(_recorderMutex);
++_eventCount;
writeRecord(_recordFile, _eventCount - _lastEventCount, ev);
@@ -320,11 +321,11 @@ bool EventRecorder::notifyEvent(const Common::Event &ev) {
return false;
}
-bool EventRecorder::pollEvent(Common::Event &ev) {
+bool EventRecorder::pollEvent(Event &ev) {
if (_recordMode != kRecorderPlayback)
return false;
- Common::StackLock lock(_recorderMutex);
+ StackLock lock(_recorderMutex);
++_eventCount;
if (!_hasPlaybackEvent) {
@@ -338,13 +339,13 @@ bool EventRecorder::pollEvent(Common::Event &ev) {
if (_hasPlaybackEvent) {
if (_playbackDiff <= (_eventCount - _lastEventCount)) {
switch (_playbackEvent.type) {
- case Common::EVENT_MOUSEMOVE:
- case Common::EVENT_LBUTTONDOWN:
- case Common::EVENT_LBUTTONUP:
- case Common::EVENT_RBUTTONDOWN:
- case Common::EVENT_RBUTTONUP:
- case Common::EVENT_WHEELUP:
- case Common::EVENT_WHEELDOWN:
+ case EVENT_MOUSEMOVE:
+ case EVENT_LBUTTONDOWN:
+ case EVENT_LBUTTONUP:
+ case EVENT_RBUTTONDOWN:
+ case EVENT_RBUTTONUP:
+ case EVENT_WHEELUP:
+ case EVENT_WHEELDOWN:
g_system->warpMouse(_playbackEvent.mouse.x, _playbackEvent.mouse.y);
break;
default:
diff --git a/common/EventRecorder.h b/common/EventRecorder.h
index 257d6f5ca0..19272c4e29 100644
--- a/common/EventRecorder.h
+++ b/common/EventRecorder.h
@@ -29,7 +29,6 @@
#include "common/scummsys.h"
#include "common/events.h"
#include "common/singleton.h"
-#include "common/savefile.h"
#include "common/mutex.h"
#include "common/array.h"
@@ -38,6 +37,8 @@
namespace Common {
class RandomSource;
+class SeekableReadStream;
+class WriteStream;
/**
* Our generic event recorder.
@@ -45,7 +46,7 @@ class RandomSource;
* TODO: Add more documentation.
*/
class EventRecorder : private EventSource, private EventObserver, public Singleton<EventRecorder> {
- friend class Common::Singleton<SingletonBaseType>;
+ friend class Singleton<SingletonBaseType>;
EventRecorder();
~EventRecorder();
public:
@@ -53,40 +54,40 @@ public:
void deinit();
/** Register random source so it can be serialized in game test purposes */
- void registerRandomSource(Common::RandomSource &rnd, const char *name);
+ void registerRandomSource(RandomSource &rnd, const char *name);
/** TODO: Add documentation, this is only used by the backend */
void processMillis(uint32 &millis);
private:
- bool notifyEvent(const Common::Event &ev);
- bool pollEvent(Common::Event &ev);
+ bool notifyEvent(const Event &ev);
+ bool pollEvent(Event &ev);
bool allowMapping() const { return false; }
class RandomSourceRecord {
public:
- Common::String name;
+ String name;
uint32 seed;
};
- Common::Array<RandomSourceRecord> _randomSourceRecords;
+ Array<RandomSourceRecord> _randomSourceRecords;
bool _recordSubtitles;
volatile uint32 _recordCount;
volatile uint32 _lastRecordEvent;
volatile uint32 _recordTimeCount;
- Common::OutSaveFile *_recordFile;
- Common::OutSaveFile *_recordTimeFile;
- Common::MutexRef _timeMutex;
- Common::MutexRef _recorderMutex;
+ WriteStream *_recordFile;
+ WriteStream *_recordTimeFile;
+ MutexRef _timeMutex;
+ MutexRef _recorderMutex;
volatile uint32 _lastMillis;
volatile uint32 _playbackCount;
volatile uint32 _playbackDiff;
volatile bool _hasPlaybackEvent;
volatile uint32 _playbackTimeCount;
- Common::Event _playbackEvent;
- Common::InSaveFile *_playbackFile;
- Common::InSaveFile *_playbackTimeFile;
+ Event _playbackEvent;
+ SeekableReadStream *_playbackFile;
+ SeekableReadStream *_playbackTimeFile;
volatile uint32 _eventCount;
volatile uint32 _lastEventCount;
@@ -97,9 +98,9 @@ private:
kRecorderPlayback = 2
};
volatile RecordMode _recordMode;
- Common::String _recordFileName;
- Common::String _recordTempFileName;
- Common::String _recordTimeFileName;
+ String _recordFileName;
+ String _recordTempFileName;
+ String _recordTimeFileName;
};
} // End of namespace Common