[Scummvm-cvs-logs] SF.net SVN: scummvm: [28968] scummvm/trunk
sev at users.sourceforge.net
sev at users.sourceforge.net
Wed Sep 19 15:55:05 CEST 2007
Revision: 28968
http://scummvm.svn.sourceforge.net/scummvm/?rev=28968&view=rev
Author: sev
Date: 2007-09-19 06:55:05 -0700 (Wed, 19 Sep 2007)
Log Message:
-----------
Modified patch #1738058: "Action recorder".
Modified Paths:
--------------
scummvm/trunk/backends/events/default/default-events.cpp
scummvm/trunk/backends/events/default/default-events.h
scummvm/trunk/backends/platform/sdl/sdl.cpp
scummvm/trunk/base/commandLine.cpp
scummvm/trunk/common/events.h
scummvm/trunk/common/util.h
scummvm/trunk/engines/agi/agi.cpp
scummvm/trunk/engines/agos/agos.cpp
scummvm/trunk/engines/cine/cine.cpp
scummvm/trunk/engines/cine/cine.h
scummvm/trunk/engines/cine/script.cpp
scummvm/trunk/engines/cine/various.cpp
scummvm/trunk/engines/cruise/cruise.cpp
scummvm/trunk/engines/cruise/cruise.h
scummvm/trunk/engines/cruise/function.cpp
scummvm/trunk/engines/drascula/drascula.cpp
scummvm/trunk/engines/gob/gob.cpp
scummvm/trunk/engines/kyra/kyra.cpp
scummvm/trunk/engines/kyra/sprites.cpp
scummvm/trunk/engines/lure/hotspots.cpp
scummvm/trunk/engines/lure/res.cpp
scummvm/trunk/engines/lure/scripts.cpp
scummvm/trunk/engines/parallaction/objects.cpp
scummvm/trunk/engines/parallaction/parallaction.cpp
scummvm/trunk/engines/parallaction/parallaction.h
scummvm/trunk/engines/queen/display.cpp
scummvm/trunk/engines/queen/music.cpp
scummvm/trunk/engines/queen/queen.cpp
scummvm/trunk/engines/saga/saga.cpp
scummvm/trunk/engines/scumm/scumm.cpp
scummvm/trunk/engines/sky/logic.cpp
scummvm/trunk/engines/sword1/logic.cpp
scummvm/trunk/engines/sword1/sound.cpp
scummvm/trunk/engines/sword2/sword2.cpp
scummvm/trunk/engines/touche/touche.cpp
Modified: scummvm/trunk/backends/events/default/default-events.cpp
===================================================================
--- scummvm/trunk/backends/events/default/default-events.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/backends/events/default/default-events.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -27,11 +27,69 @@
#include "common/config-manager.h"
#include "common/system.h"
+#include "common/config-manager.h"
#include "backends/events/default/default-events.h"
#include "engines/engine.h"
#include "gui/message.h"
+#define RECORD_SIGNATURE 0x54455354
+#define RECORD_VERSION 1
+
+void readRecord(Common::InSaveFile *inFile, uint32 &diff, Common::Event &event) {
+ diff = inFile->readUint32LE();
+
+ event.type = (Common::EventType)inFile->readUint32LE();
+
+ switch(event.type) {
+ case Common::EVENT_KEYDOWN:
+ case Common::EVENT_KEYUP:
+ event.kbd.keycode = (Common::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:
+ event.mouse.x = inFile->readSint16LE();
+ event.mouse.y = inFile->readSint16LE();
+ break;
+ default:
+ break;
+ }
+}
+
+void writeRecord(Common::OutSaveFile *outFile, uint32 diff, Common::Event &event) {
+ outFile->writeUint32LE(diff);
+
+ outFile->writeUint32LE((uint32)event.type);
+
+ switch(event.type) {
+ case Common::EVENT_KEYDOWN:
+ case Common::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:
+ outFile->writeSint16LE(event.mouse.x);
+ outFile->writeSint16LE(event.mouse.y);
+ break;
+ default:
+ break;
+ }
+}
+
DefaultEventManager::DefaultEventManager(OSystem *boss) :
_boss(boss),
_buttonState(0),
@@ -40,16 +98,279 @@
assert(_boss);
+ _recordFile = NULL;
+ _recordTimeFile = NULL;
+ _playbackFile = NULL;
+ _playbackTimeFile = NULL;
+ _timeMutex = _boss->createMutex();
+ _recorderMutex = _boss->createMutex();
+
+ _eventCount = 0;
+ _lastEventCount = 0;
+ _lastMillis = 0;
+
+ Common::String recordModeString = ConfMan.get("record_mode");
+ if (recordModeString.compareToIgnoreCase("record") == 0) {
+ _recordMode = kRecorderRecord;
+ } else {
+ if (recordModeString.compareToIgnoreCase("playback") == 0) {
+ _recordMode = kRecorderPlayback;
+ } else {
+ _recordMode = kPassthrough;
+ }
+ }
+
+ _recordFileName = ConfMan.get("record_file_name");
+ if (_recordFileName.empty()) {
+ _recordFileName = "record.bin";
+ }
+ _recordTempFileName = ConfMan.get("record_temp_file_name");
+ if (_recordTempFileName.empty()) {
+ _recordTempFileName = "record.tmp";
+ }
+ _recordTimeFileName = ConfMan.get("record_time_file_name");
+ if (_recordTimeFileName.empty()) {
+ _recordTimeFileName = "record.time";
+ }
+
// Reset key repeat
_currentKeyDown.keycode = 0;
+
+ // recorder stuff
+ if (_recordMode == kRecorderRecord) {
+ _recordCount = 0;
+ _recordTimeCount = 0;
+ _recordFile = _boss->getSavefileManager()->openForSaving(_recordTempFileName.c_str());
+ _recordTimeFile = _boss->getSavefileManager()->openForSaving(_recordTimeFileName.c_str());
+ _recordSubtitles = ConfMan.getBool("subtitles");
+ }
+
+ uint32 sign;
+ uint32 version;
+ uint32 randomSourceCount;
+ if (_recordMode == kRecorderPlayback) {
+ _playbackCount = 0;
+ _playbackTimeCount = 0;
+ _playbackFile = _boss->getSavefileManager()->openForLoading(_recordFileName.c_str());
+ _playbackTimeFile = _boss->getSavefileManager()->openForLoading(_recordTimeFileName.c_str());
+
+ if (!_playbackFile) {
+ warning("Cannot open playback file %s. Playback was switched off", _recordFileName.c_str());
+ _recordMode = kPassthrough;
+ }
+
+ if (!_playbackTimeFile) {
+ warning("Cannot open playback time file %s. Playback was switched off", _recordTimeFileName.c_str());
+ _recordMode = kPassthrough;
+ }
+ }
+
+ if (_recordMode == kRecorderPlayback) {
+ sign = _playbackFile->readUint32LE();
+ if (sign != RECORD_SIGNATURE) {
+ error("Unknown record file signature");
+ }
+ version = _playbackFile->readUint32LE();
+
+ // conf vars
+ ConfMan.setBool("subtitles", _playbackFile->readByte() != 0);
+
+ _recordCount = _playbackFile->readUint32LE();
+ _recordTimeCount = _playbackFile->readUint32LE();
+ randomSourceCount = _playbackFile->readUint32LE();
+ for (uint i = 0; i < randomSourceCount; ++i) {
+ RandomSourceRecord rec;
+ rec.name = "";
+ uint32 sLen = _playbackFile->readUint32LE();
+ for (uint j = 0; j < sLen; ++j) {
+ char c = _playbackFile->readSByte();
+ rec.name += c;
+ }
+ rec.seed = _playbackFile->readUint32LE();
+ _randomSourceRecords.push_back(rec);
+ }
+
+ _hasPlaybackEvent = false;
+ }
}
+DefaultEventManager::~DefaultEventManager() {
+ _boss->lockMutex(_timeMutex);
+ _boss->lockMutex(_recorderMutex);
+ _recordMode = kPassthrough;
+ _boss->unlockMutex(_timeMutex);
+ _boss->unlockMutex(_recorderMutex);
+
+ if (_playbackFile != NULL) {
+ delete _playbackFile;
+ }
+ if (_playbackTimeFile != NULL) {
+ delete _playbackTimeFile;
+ }
+
+ if (_recordFile != NULL) {
+ _recordFile->finalize();
+ delete _recordFile;
+ _recordTimeFile->finalize();
+ delete _recordTimeFile;
+
+ _playbackFile = _boss->getSavefileManager()->openForLoading(_recordTempFileName.c_str());
+
+ _recordFile = _boss->getSavefileManager()->openForSaving(_recordFileName.c_str());
+ _recordFile->writeUint32LE(RECORD_SIGNATURE);
+ _recordFile->writeUint32LE(RECORD_VERSION);
+
+ // conf vars
+ _recordFile->writeByte(_recordSubtitles ? 1 : 0);
+
+ _recordFile->writeUint32LE(_recordCount);
+ _recordFile->writeUint32LE(_recordTimeCount);
+
+ _recordFile->writeUint32LE(_randomSourceRecords.size());
+ for (uint i = 0; i < _randomSourceRecords.size(); ++i) {
+ _recordFile->writeUint32LE(_randomSourceRecords[i].name.size());
+ _recordFile->writeString(_randomSourceRecords[i].name);
+ _recordFile->writeUint32LE(_randomSourceRecords[i].seed);
+ }
+
+ for (uint i = 0; i < _recordCount; ++i) {
+ uint32 tempDiff;
+ Common::Event tempEvent;
+ readRecord(_playbackFile, tempDiff, tempEvent);
+ writeRecord(_recordFile, tempDiff, tempEvent);
+ }
+
+ _recordFile->finalize();
+ delete _recordFile;
+ delete _playbackFile;
+
+ //TODO: remove recordTempFileName'ed file
+ }
+ _boss->deleteMutex(_timeMutex);
+ _boss->deleteMutex(_recorderMutex);
+}
+
+bool DefaultEventManager::playback(Common::Event &event) {
+
+ if (!_hasPlaybackEvent) {
+ if (_recordCount > _playbackCount) {
+ readRecord(_playbackFile, (uint32&)_playbackDiff, _playbackEvent);
+ _playbackCount++;
+ _hasPlaybackEvent = true;
+ }
+ }
+
+ 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:
+ _boss->warpMouse(_playbackEvent.mouse.x, _playbackEvent.mouse.y);
+ break;
+ default:
+ break;
+ }
+ event = _playbackEvent;
+ _hasPlaybackEvent = false;
+ _lastEventCount = _eventCount;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void DefaultEventManager::record(Common::Event &event) {
+ writeRecord(_recordFile, _eventCount - _lastEventCount, event);
+
+ _recordCount++;
+ _lastEventCount = _eventCount;
+}
+
+void DefaultEventManager::registerRandomSource(Common::RandomSource &rnd, const char *name) {
+
+ if (_recordMode == kRecorderRecord) {
+ RandomSourceRecord rec;
+ rec.name = name;
+ rec.seed = rnd.getSeed();
+ _randomSourceRecords.push_back(rec);
+ }
+
+ if (_recordMode == kRecorderPlayback) {
+ for (uint i = 0; i < _randomSourceRecords.size(); ++i) {
+ if (_randomSourceRecords[i].name == name) {
+ rnd.setSeed(_randomSourceRecords[i].seed);
+ _randomSourceRecords.remove_at(i);
+ break;
+ }
+ }
+ }
+}
+
+void DefaultEventManager::processMillis(uint32 &millis) {
+ uint32 d;
+ if (_recordMode == kPassthrough) {
+ return;
+ }
+
+ _boss->lockMutex(_timeMutex);
+ if (_recordMode == kRecorderRecord) {
+ //Simple RLE compression
+ d = millis - _lastMillis;
+ if (d >= 0xff) {
+ _recordTimeFile->writeByte(0xff);
+ _recordTimeFile->writeUint32LE(d);
+ } else {
+ _recordTimeFile->writeByte(d);
+ }
+ _recordTimeCount++;
+ }
+
+ if (_recordMode == kRecorderPlayback) {
+ if (_recordTimeCount > _playbackTimeCount) {
+ d = _playbackTimeFile->readByte();
+ if (d == 0xff) {
+ d = _playbackTimeFile->readUint32LE();
+ }
+ millis = _lastMillis + d;
+ _playbackTimeCount++;
+ }
+ }
+
+ _lastMillis = millis;
+ _boss->unlockMutex(_timeMutex);
+}
+
bool DefaultEventManager::pollEvent(Common::Event &event) {
uint32 time = _boss->getMillis();
bool result;
result = _boss->pollEvent(event);
+ if (_recordMode != kPassthrough) {
+
+ _boss->lockMutex(_recorderMutex);
+ _eventCount++;
+
+ if (_recordMode == kRecorderPlayback) {
+ if (event.type != Common::EVENT_QUIT) {
+ result = playback(event);
+ }
+ } else {
+ if (_recordMode == kRecorderRecord) {
+ if (result) {
+ record(event);
+ }
+ }
+ }
+ _boss->unlockMutex(_recorderMutex);
+ }
+
if (result) {
event.synthetic = false;
switch (event.type) {
Modified: scummvm/trunk/backends/events/default/default-events.h
===================================================================
--- scummvm/trunk/backends/events/default/default-events.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/backends/events/default/default-events.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -27,6 +27,7 @@
#define BACKEND_EVENTS_DEFAULT_H
#include "common/events.h"
+#include "common/savefile.h"
/*
At some point we will remove pollEvent from OSystem and change
@@ -47,7 +48,45 @@
int _buttonState;
int _modifierState;
bool _shouldQuit;
+
+ class RandomSourceRecord {
+ public:
+ Common::String name;
+ uint32 seed;
+ };
+ Common::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;
+ volatile uint32 _lastMillis;
+
+ volatile uint32 _playbackCount;
+ volatile uint32 _playbackDiff;
+ volatile bool _hasPlaybackEvent;
+ volatile uint32 _playbackTimeCount;
+ Common::Event _playbackEvent;
+ Common::InSaveFile *_playbackFile;
+ Common::InSaveFile *_playbackTimeFile;
+
+ volatile uint32 _eventCount;
+ volatile uint32 _lastEventCount;
+
+ enum RecordMode {
+ kPassthrough = 0,
+ kRecorderRecord = 1,
+ kRecorderPlayback = 2
+ };
+ volatile RecordMode _recordMode;
+ Common::String _recordFileName;
+ Common::String _recordTempFileName;
+ Common::String _recordTimeFileName;
+
// for continuous events (keyDown)
enum {
kKeyRepeatInitialDelay = 400,
@@ -61,10 +100,15 @@
} _currentKeyDown;
uint32 _keyRepeatTime;
+ void record(Common::Event &event);
+ bool playback(Common::Event &event);
public:
DefaultEventManager(OSystem *boss);
+ ~DefaultEventManager();
virtual bool pollEvent(Common::Event &event);
+ virtual void registerRandomSource(Common::RandomSource &rnd, const char *name);
+ virtual void processMillis(uint32 &millis);
virtual Common::Point getMousePos() const { return _mousePos; }
virtual int getButtonState() const { return _buttonState; }
Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -25,6 +25,7 @@
#include "backends/platform/sdl/sdl.h"
#include "common/config-manager.h"
+#include "common/events.h"
#include "common/util.h"
#include "backends/saves/default/default-saves.h"
@@ -187,7 +188,9 @@
}
uint32 OSystem_SDL::getMillis() {
- return SDL_GetTicks();
+ uint32 millis = SDL_GetTicks();
+ getEventManager()->processMillis(millis);
+ return millis;
}
void OSystem_SDL::delayMillis(uint msecs) {
@@ -268,6 +271,7 @@
SDL_ShowCursor(SDL_ENABLE);
SDL_Quit();
+ delete getEventManager();
exit(0);
}
Modified: scummvm/trunk/base/commandLine.cpp
===================================================================
--- scummvm/trunk/base/commandLine.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/base/commandLine.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -225,6 +225,11 @@
ConfMan.registerDefault("savepath", savePath);
#endif
#endif // #ifdef DEFAULT_SAVE_PATH
+
+ ConfMan.registerDefault("record_mode", "none");
+ ConfMan.registerDefault("record_file_name", "record.bin");
+ ConfMan.registerDefault("record_temp_file_name", "record.tmp");
+ ConfMan.registerDefault("record_time_file_name", "record.time");
}
//
@@ -500,6 +505,19 @@
END_OPTION
#endif
+ DO_LONG_OPTION("record-mode")
+ END_OPTION
+
+ DO_LONG_OPTION("record-file-name")
+ END_OPTION
+
+ DO_LONG_OPTION("record-temp-file-name")
+ END_OPTION
+
+ DO_LONG_OPTION("record-time-file-name")
+ END_OPTION
+
+
unknownOption:
// If we get till here, the option is unhandled and hence unknown.
usage("Unrecognized option '%s'", argv[i]);
Modified: scummvm/trunk/common/events.h
===================================================================
--- scummvm/trunk/common/events.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/common/events.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -140,7 +140,11 @@
*/
virtual bool pollEvent(Common::Event &event) = 0;
-
+ /** Register random source so it can be serialized in game test purposes **/
+ virtual void registerRandomSource(Common::RandomSource &rnd, const char *name) = 0;
+
+ virtual void processMillis(uint32 &millis) = 0;
+
/** Return the current key state */
virtual Common::Point getMousePos() const = 0;
Modified: scummvm/trunk/common/util.h
===================================================================
--- scummvm/trunk/common/util.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/common/util.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -72,6 +72,10 @@
public:
RandomSource();
void setSeed(uint32 seed);
+
+ uint32 getSeed() {
+ return _randSeed;
+ }
/**
* Generates a random unsigned integer in the interval [0, max].
Modified: scummvm/trunk/engines/agi/agi.cpp
===================================================================
--- scummvm/trunk/engines/agi/agi.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/agi/agi.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -623,6 +623,7 @@
_gameId = g->id;
_rnd = new Common::RandomSource();
+ syst->getEventManager()->registerRandomSource(*_rnd, "agi");
Common::addSpecialDebugLevel(kDebugLevelMain, "Main", "Generic debug level");
Common::addSpecialDebugLevel(kDebugLevelResources, "Resources", "Resources debugging");
Modified: scummvm/trunk/engines/agos/agos.cpp
===================================================================
--- scummvm/trunk/engines/agos/agos.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/agos/agos.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -28,6 +28,7 @@
#include "common/config-manager.h"
#include "common/file.h"
#include "common/system.h"
+#include "common/events.h"
#include "agos/debugger.h"
#include "agos/intern.h"
@@ -519,6 +520,8 @@
File::addDefaultDirectory(_gameDataPath + "SFX");
File::addDefaultDirectory(_gameDataPath + "speech");
File::addDefaultDirectory(_gameDataPath + "SPEECH");
+
+ syst->getEventManager()->registerRandomSource(_rnd, "agos");
}
int AGOSEngine::init() {
Modified: scummvm/trunk/engines/cine/cine.cpp
===================================================================
--- scummvm/trunk/engines/cine/cine.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cine/cine.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -23,7 +23,7 @@
*
*/
-
+#include "common/events.h"
#include "common/file.h"
#include "common/savefile.h"
#include "common/config-manager.h"
@@ -62,6 +62,8 @@
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
g_cine = this;
+
+ syst->getEventManager()->registerRandomSource(_rnd, "cine");
}
CineEngine::~CineEngine() {
Modified: scummvm/trunk/engines/cine/cine.h
===================================================================
--- scummvm/trunk/engines/cine/cine.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cine/cine.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -85,6 +85,8 @@
const CINEGameDescription *_gameDescription;
Common::File _partFileHandle;
+ Common::RandomSource _rnd;
+
private:
void initialize(void);
bool makeLoad(char *saveName);
Modified: scummvm/trunk/engines/cine/script.cpp
===================================================================
--- scummvm/trunk/engines/cine/script.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cine/script.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -909,7 +909,7 @@
break;
case 5:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = rand mod %d", _currentLine, varIdx, dataIdx);
- _currentScriptElement->localVars[varIdx] = rand() % dataIdx;
+ _currentScriptElement->localVars[varIdx] = g_cine->_rnd.getRandomNumber(dataIdx - 1);
break;
case 8:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = file[%d].packedSize", _currentLine, varIdx, dataIdx);
Modified: scummvm/trunk/engines/cine/various.cpp
===================================================================
--- scummvm/trunk/engines/cine/various.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cine/various.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -2355,7 +2355,7 @@
int16 localY;
int16 localWidth;
- byte msgIdx = cmd * 4 + rand() % 4;
+ byte msgIdx = cmd * 4 + g_cine->_rnd.getRandomNumber(3);
const char *messagePtr = failureMessages[msgIdx];
int len = strlen(messagePtr);
Modified: scummvm/trunk/engines/cruise/cruise.cpp
===================================================================
--- scummvm/trunk/engines/cruise/cruise.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cruise/cruise.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -23,7 +23,7 @@
*
*/
-
+#include "common/events.h"
#include "common/file.h"
#include "common/savefile.h"
#include "common/config-manager.h"
@@ -64,6 +64,8 @@
ConfMan.getInt("music_volume"));
g_cruise = this;
+
+ syst->getEventManager()->registerRandomSource(_rnd, "cruise");
}
CruiseEngine::~CruiseEngine() {
@@ -75,8 +77,7 @@
int CruiseEngine::init() {
// Detect game
if (!initGame()) {
- GUIErrorMessage
- ("No valid games were found in the specified directory.");
+ GUIErrorMessage ("No valid games were found in the specified directory.");
return -1;
}
// Initialize backend
Modified: scummvm/trunk/engines/cruise/cruise.h
===================================================================
--- scummvm/trunk/engines/cruise/cruise.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cruise/cruise.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -43,28 +43,30 @@
class CruiseEngine:public Engine {
- protected:
+protected:
int init();
int go();
void shutdown();
bool initGame();
- public:
- CruiseEngine(OSystem * syst);
- virtual ~ CruiseEngine();
+public:
+ CruiseEngine(OSystem * syst);
+ virtual ~ CruiseEngine();
int getGameType() const;
uint32 getFeatures() const;
- Common::Language getLanguage() const;
- Common::Platform getPlatform() const;
+ Common::Language getLanguage() const;
+ Common::Platform getPlatform() const;
bool loadSaveDirectory(void);
void makeSystemMenu(void);
const CRUISEGameDescription *_gameDescription;
- private:
+ Common::RandomSource _rnd;
+
+private:
void initialize(void);
bool makeLoad(char *saveName);
void mainLoop(int bootScriptIdx);
Modified: scummvm/trunk/engines/cruise/function.cpp
===================================================================
--- scummvm/trunk/engines/cruise/function.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/cruise/function.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -23,6 +23,7 @@
*
*/
+#include "cruise/cruise.h"
#include "cruise/cruise_main.h"
#include "cruise/cell.h"
#include "common/util.h"
@@ -193,7 +194,7 @@
return (0);
}
- return (rand() % var);
+ return (g_cruise->_rnd.getRandomNumber(var - 1));
}
int16 Op_PlayFX(void) { // TODO: implement
Modified: scummvm/trunk/engines/drascula/drascula.cpp
===================================================================
--- scummvm/trunk/engines/drascula/drascula.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/drascula/drascula.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -71,6 +71,7 @@
_gameId = g->id;
_rnd = new Common::RandomSource();
+ syst->getEventManager()->registerRandomSource(*_rnd, "drascula");
int cd_num = ConfMan.getInt("cdrom");
if (cd_num >= 0)
Modified: scummvm/trunk/engines/gob/gob.cpp
===================================================================
--- scummvm/trunk/engines/gob/gob.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/gob/gob.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -25,6 +25,7 @@
#include "common/endian.h"
+#include "common/events.h"
#include "base/plugins.h"
#include "common/config-manager.h"
@@ -98,6 +99,8 @@
Common::addSpecialDebugLevel(kDebugFileIO, "FileIO", "File Input/Output debug level");
Common::addSpecialDebugLevel(kDebugGraphics, "Graphics", "Graphics debug level");
Common::addSpecialDebugLevel(kDebugCollisions, "Collisions", "Collisions debug level");
+
+ syst->getEventManager()->registerRandomSource(_rnd, "gob");
}
GobEngine::~GobEngine() {
Modified: scummvm/trunk/engines/kyra/kyra.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/kyra/kyra.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -71,6 +71,8 @@
Common::addSpecialDebugLevel(kDebugLevelSequence, "Sequence", "Sequence debug level");
Common::addSpecialDebugLevel(kDebugLevelMovie, "Movie", "Movie debug level");
Common::addSpecialDebugLevel(kDebugLevelTimer, "Timer", "Timer debug level");
+
+ system->getEventManager()->registerRandomSource(_rnd, "kyra");
}
int KyraEngine::init() {
Modified: scummvm/trunk/engines/kyra/sprites.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sprites.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/kyra/sprites.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -28,6 +28,7 @@
#include "common/stream.h"
#include "common/util.h"
#include "common/system.h"
+#include "common/events.h"
#include "kyra/screen.h"
#include "kyra/kyra_v1.h"
#include "kyra/sprites.h"
@@ -47,6 +48,7 @@
_spriteDefStart = 0;
memset(_drawLayerTable, 0, sizeof(_drawLayerTable));
_sceneAnimatorBeaconFlag = 0;
+ system->getEventManager()->registerRandomSource(_rnd, "kyraSprites");
}
Sprites::~Sprites() {
Modified: scummvm/trunk/engines/lure/hotspots.cpp
===================================================================
--- scummvm/trunk/engines/lure/hotspots.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/lure/hotspots.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -588,6 +588,8 @@
Common::RandomSource rnd;
int16 xp, yp;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureHotspots");
+
if (_currentActions.isEmpty())
_currentActions.addFront(START_WALKING, roomNumber());
else
@@ -2925,6 +2927,8 @@
Common::RandomSource rnd;
RandomActionType actionType;
uint16 scheduleId;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureHotspots");
+
int actionIndex = rnd.getRandomNumber(set->numActions() - 1);
set->getEntry(actionIndex, actionType, scheduleId);
@@ -3113,6 +3117,8 @@
ValueTableData &fields = Resources::getReference().fieldList();
Common::RandomSource rnd;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureHotspots");
+
h.handleTalkDialog();
if (h.frameCtr() > 0) {
h.setFrameCtr(h.frameCtr() - 1);
@@ -3153,6 +3159,8 @@
if (h.executeScript()) {
// Script is done - set new script to one of two alternates randomly
Common::RandomSource rnd;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureHotspots");
+
h.setHotspotScript(rnd.getRandomNumber(100) >= 50 ? 0x54 : 0);
h.setFrameCtr(20 + rnd.getRandomNumber(63));
}
@@ -3417,6 +3425,8 @@
Common::RandomSource rnd;
static bool ewanXOffset = false;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureHotspots");
+
h.handleTalkDialog();
if (h.delayCtr() > 0) {
h.setDelayCtr(h.delayCtr() - 1);
Modified: scummvm/trunk/engines/lure/res.cpp
===================================================================
--- scummvm/trunk/engines/lure/res.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/lure/res.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -28,6 +28,7 @@
#include "lure/scripts.h"
#include "lure/screen.h"
#include "common/endian.h"
+#include "common/events.h"
namespace Lure {
@@ -40,6 +41,7 @@
}
Resources::Resources() {
+ g_system->getEventManager()->registerRandomSource(_rnd, "lureResources");
int_resources = this;
reloadData();
Modified: scummvm/trunk/engines/lure/scripts.cpp
===================================================================
--- scummvm/trunk/engines/lure/scripts.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/lure/scripts.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -704,6 +704,7 @@
void Script::randomToGeneral(uint16 maxVal, uint16 minVal, uint16 v3) {
Common::RandomSource rnd;
+ g_system->getEventManager()->registerRandomSource(rnd, "lureScripts");
uint16 v = minVal + rnd.getRandomNumber(maxVal - minVal);
Resources::getReference().fieldList().setField(GENERAL, v);
}
Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/parallaction/objects.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -23,6 +23,7 @@
*
*/
+#include "parallaction/parallaction.h"
#include "parallaction/objects.h"
#include "parallaction/parser.h"
@@ -287,7 +288,7 @@
}
if (_flags & kParaRandom) {
- return (rand() * _value) / 32767;
+ return (_vm->_rnd.getRandomNumber(65536) * _value) / 32767;
}
error("Parameter is not an r-value");
Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -111,6 +111,8 @@
Common::addSpecialDebugLevel(kDebugInput, "input", "Input debug level");
Common::addSpecialDebugLevel(kDebugAudio, "audio", "Audio debug level");
Common::addSpecialDebugLevel(kDebugMenu, "menu", "Menu debug level");
+
+ syst->getEventManager()->registerRandomSource(_rnd, "parallaction");
}
Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/parallaction/parallaction.h 2007-09-19 13:55:05 UTC (rev 28968)
@@ -492,6 +492,7 @@
Font *_menuFont;
Font *_dialogueFont;
+ Common::RandomSource _rnd;
protected: // data
Modified: scummvm/trunk/engines/queen/display.cpp
===================================================================
--- scummvm/trunk/engines/queen/display.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/queen/display.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -25,6 +25,7 @@
#include "common/system.h"
+#include "common/events.h"
#include "graphics/cursorman.h"
@@ -73,6 +74,7 @@
memset(&_dynalum, 0, sizeof(_dynalum));
setupInkColors();
+ system->getEventManager()->registerRandomSource(_rnd, "queenDisplay");
}
Display::~Display() {
Modified: scummvm/trunk/engines/queen/music.cpp
===================================================================
--- scummvm/trunk/engines/queen/music.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/queen/music.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -23,6 +23,7 @@
*
*/
+#include "common/events.h"
#include "queen/music.h"
#include "queen/queen.h"
@@ -48,6 +49,7 @@
this->open();
_tune = vm->resource()->isDemo() ? Sound::_tuneDemo : Sound::_tune;
+ vm->_system->getEventManager()->registerRandomSource(_rnd, "queenMusic");
}
MidiMusic::~MidiMusic() {
Modified: scummvm/trunk/engines/queen/queen.cpp
===================================================================
--- scummvm/trunk/engines/queen/queen.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/queen/queen.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -32,6 +32,7 @@
#include "common/fs.h"
#include "common/savefile.h"
#include "common/system.h"
+#include "common/events.h"
#include "queen/queen.h"
#include "queen/bankman.h"
@@ -110,6 +111,7 @@
QueenEngine::QueenEngine(OSystem *syst)
: Engine(syst), _debugger(0) {
+ syst->getEventManager()->registerRandomSource(randomizer, "queen");
}
QueenEngine::~QueenEngine() {
Modified: scummvm/trunk/engines/saga/saga.cpp
===================================================================
--- scummvm/trunk/engines/saga/saga.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/saga/saga.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -28,6 +28,7 @@
#include "common/file.h"
#include "common/config-manager.h"
#include "common/system.h"
+#include "common/events.h"
#include "sound/mixer.h"
@@ -113,6 +114,7 @@
}
_displayClip.left = _displayClip.top = 0;
+ syst->getEventManager()->registerRandomSource(_rnd, "saga");
}
SagaEngine::~SagaEngine() {
Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/scumm/scumm.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -536,6 +536,8 @@
// Add debug levels
for (int i = 0; i < ARRAYSIZE(debugChannels); ++i)
Common::addSpecialDebugLevel(debugChannels[i].flag, debugChannels[i].channel, debugChannels[i].desc);
+
+ syst->getEventManager()->registerRandomSource(_rnd, "scumm");
}
Modified: scummvm/trunk/engines/sky/logic.cpp
===================================================================
--- scummvm/trunk/engines/sky/logic.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/sky/logic.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -26,6 +26,7 @@
#include "common/endian.h"
#include "common/rect.h"
+#include "common/events.h"
#include "sky/autoroute.h"
#include "sky/compact.h"
@@ -71,6 +72,8 @@
}
Logic::Logic(SkyCompact *skyCompact, Screen *skyScreen, Disk *skyDisk, Text *skyText, MusicBase *skyMusic, Mouse *skyMouse, Sound *skySound) {
+ g_system->getEventManager()->registerRandomSource(_rnd, "sky");
+
_skyCompact = skyCompact;
_skyScreen = skyScreen;
_skyDisk = skyDisk;
Modified: scummvm/trunk/engines/sword1/logic.cpp
===================================================================
--- scummvm/trunk/engines/sword1/logic.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/sword1/logic.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -26,6 +26,8 @@
#include "common/endian.h"
#include "common/util.h"
+#include "common/system.h"
+#include "common/events.h"
#include "sword1/logic.h"
#include "sword1/text.h"
@@ -54,6 +56,8 @@
uint32 Logic::_scriptVars[NUM_SCRIPT_VARS];
Logic::Logic(ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Music *pMusic, Menu *pMenu, OSystem *system, Audio::Mixer *mixer) {
+ g_system->getEventManager()->registerRandomSource(_rnd, "sword1");
+
_objMan = pObjMan;
_resMan = resMan;
_screen = pScreen;
Modified: scummvm/trunk/engines/sword1/sound.cpp
===================================================================
--- scummvm/trunk/engines/sword1/sound.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/sword1/sound.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -27,6 +27,7 @@
#include "common/endian.h"
#include "common/util.h"
+#include "common/events.h"
#include "sword1/sound.h"
#include "sword1/resman.h"
@@ -44,6 +45,7 @@
#define SPEECH_FLAGS (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_LITTLE_ENDIAN)
Sound::Sound(const char *searchPath, Audio::Mixer *mixer, ResMan *pResMan) {
+ g_system->getEventManager()->registerRandomSource(_rnd, "sword1sound");
strcpy(_filePath, searchPath);
_mixer = mixer;
_resMan = pResMan;
Modified: scummvm/trunk/engines/sword2/sword2.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sword2.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/sword2/sword2.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -209,6 +209,7 @@
_gameSpeed = 1;
_quit = false;
+ syst->getEventManager()->registerRandomSource(_rnd, "sword2");
}
Sword2Engine::~Sword2Engine() {
Modified: scummvm/trunk/engines/touche/touche.cpp
===================================================================
--- scummvm/trunk/engines/touche/touche.cpp 2007-09-19 09:54:42 UTC (rev 28967)
+++ scummvm/trunk/engines/touche/touche.cpp 2007-09-19 13:55:05 UTC (rev 28968)
@@ -73,6 +73,8 @@
Common::addSpecialDebugLevel(kDebugResource, "Resource", "Resource debug level");
Common::addSpecialDebugLevel(kDebugOpcodes, "Opcodes", "Opcodes debug level");
Common::addSpecialDebugLevel(kDebugUserIntf, "UserIntf", "UserInterface debug level");
+
+ system->getEventManager()->registerRandomSource(_rnd, "touche");
}
ToucheEngine::~ToucheEngine() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list