[Scummvm-cvs-logs] scummvm master -> 9b2ef340dceebc3db36519051e45af0fd9477850

fingolfin max at quendi.de
Tue May 17 13:05:07 CEST 2011


This automated email contains information about 15 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4cbe4ede66 COMMON: Registers RandomSources in constructor with the event recorder
05a7b160b3 TEEN: Use only one RandomSource and give that one a name.
f04d6c6ee5 TUCKER: Give name to RandomSource, to register it with event recorder
44b798d107 AGI: Unify RandomSource instantiation
9ac184bfba MOHAWK: Name the RandomSource used for myst
99a6ac46e1 TSAGE: Name the RandomSource
fb31fa2d6a SWORD25: Name the random source
fc9b8d2a71 COMMON: Remove auxillary RandomSource constructor
d165292234 COMMON: Remove unused RandomSource destructor, clarify comments, cleanup
a3fe84cfe6 GUI: For a list entry in edit mode, move caret to end
29851abaea GUI: Text editing tweaks
a3c3264561 TOON: Use RandomSource instead of rand()
64bcb731bf LURE: Rename method random() -> getRandom()
a03ed0a3f7 AUDIO: Fix typo
9b2ef340dc COMMON: Forbid use of some more symbols


Commit: 4cbe4ede66e65ec9289811eca2f5f62285174c8d
    https://github.com/scummvm/scummvm/commit/4cbe4ede66e65ec9289811eca2f5f62285174c8d
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:26-07:00

Commit Message:
COMMON: Registers RandomSources in constructor with the event recorder

This also removes the dependency of engines on the event recorder header
and API, and will make it easier to RandomSources that are not properly
registered.

Changed paths:
    common/EventRecorder.cpp
    common/EventRecorder.h
    common/random.cpp
    common/random.h
    engines/agi/agi.cpp
    engines/agos/agos.cpp
    engines/cine/cine.cpp
    engines/cruise/cruise.cpp
    engines/draci/draci.cpp
    engines/drascula/drascula.cpp
    engines/gob/gob.cpp
    engines/gob/sound/bgatmosphere.cpp
    engines/groovie/script.cpp
    engines/hugo/hugo.cpp
    engines/kyra/kyra_v1.cpp
    engines/kyra/sprites.cpp
    engines/lastexpress/lastexpress.cpp
    engines/lure/lure.cpp
    engines/lure/scripts.cpp
    engines/m4/m4.cpp
    engines/made/made.cpp
    engines/mohawk/cstime.cpp
    engines/mohawk/livingbooks.cpp
    engines/mohawk/riven.cpp
    engines/parallaction/parallaction.cpp
    engines/queen/display.cpp
    engines/queen/music.cpp
    engines/queen/queen.cpp
    engines/saga/saga.cpp
    engines/sci/sci.cpp
    engines/scumm/scumm.cpp
    engines/sky/logic.cpp
    engines/sword1/logic.cpp
    engines/sword1/logic.h
    engines/sword1/sound.cpp
    engines/sword2/sword2.cpp
    engines/tinsel/tinsel.cpp
    engines/toon/toon.cpp
    engines/touche/touche.cpp



diff --git a/common/EventRecorder.cpp b/common/EventRecorder.cpp
index 20dbde1..eb22e1e 100644
--- a/common/EventRecorder.cpp
+++ b/common/EventRecorder.cpp
@@ -251,7 +251,7 @@ void EventRecorder::deinit() {
 	g_system->deleteMutex(_recorderMutex);
 }
 
-void EventRecorder::registerRandomSource(RandomSource &rnd, const char *name) {
+void EventRecorder::registerRandomSource(RandomSource &rnd, const String &name) {
 	if (_recordMode == kRecorderRecord) {
 		RandomSourceRecord rec;
 		rec.name = name;
diff --git a/common/EventRecorder.h b/common/EventRecorder.h
index 29bcf8e..8377d9e 100644
--- a/common/EventRecorder.h
+++ b/common/EventRecorder.h
@@ -51,7 +51,7 @@ public:
 	void deinit();
 
 	/** Register random source so it can be serialized in game test purposes */
-	void registerRandomSource(RandomSource &rnd, const char *name);
+	void registerRandomSource(RandomSource &rnd, const String &name);
 
 	/** TODO: Add documentation, this is only used by the backend */
 	void processMillis(uint32 &millis);
diff --git a/common/random.cpp b/common/random.cpp
index 5a00d48..be69d39 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -21,10 +21,23 @@
 
 #include "common/random.h"
 #include "common/system.h"
+#include "common/EventRecorder.h"
 
 
 namespace Common {
 
+RandomSource::RandomSource(const String &name) {
+	// Use system time as RNG seed. Normally not a good idea, if you are using
+	// a RNG for security purposes, but good enough for our purposes.
+	assert(g_system);
+	uint32 seed = g_system->getMillis();
+	setSeed(seed);
+
+	// Register this random source with the event recorder. This might
+	// reset the seed, so call it *after* the initial seed has been set.
+	g_eventRec.registerRandomSource(*this, name);
+}
+
 RandomSource::RandomSource() {
 	// Use system time as RNG seed. Normally not a good idea, if you are using
 	// a RNG for security purposes, but good enough for our purposes.
@@ -33,6 +46,10 @@ RandomSource::RandomSource() {
 	setSeed(seed);
 }
 
+RandomSource::~RandomSource() {
+	// TODO: Unregister with g_eventRec
+}
+
 void RandomSource::setSeed(uint32 seed) {
 	_randSeed = seed;
 }
diff --git a/common/random.h b/common/random.h
index 437675a..308d8a6 100644
--- a/common/random.h
+++ b/common/random.h
@@ -26,6 +26,8 @@
 
 namespace Common {
 
+class String;
+
 /**
  * Simple random number generator. Although it is definitely not suitable for
  * cryptographic purposes, it serves our purposes just fine.
@@ -35,7 +37,21 @@ private:
 	uint32 _randSeed;
 
 public:
+	/**
+	 * Construct a new randomness source with the specific name.
+	 * The name used name must be globally unique, and is used to
+	 * register the randomness source with the active event recorder,
+	 * if any.
+	 */
+	RandomSource(const String &name);
+
+	// FIXME: This constructor for a nameless randomness source should be removed.
+	// I am only adding this temporarily to ease transition to the new
+	// system which enforces names for randomness sources.
 	RandomSource();
+
+	~RandomSource();
+
 	void setSeed(uint32 seed);
 
 	uint32 getSeed() {
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 3efb017..101c149 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -22,7 +22,6 @@
 
 #include "common/md5.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/file.h"
 #include "common/memstream.h"
 #include "common/savefile.h"
@@ -496,8 +495,7 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
 
 	parseFeatures();
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "agi");
+	_rnd = new Common::RandomSource("agi");
 
 	DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
 	DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp
index b6dba06..7e4c564 100644
--- a/engines/agos/agos.cpp
+++ b/engines/agos/agos.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/config-manager.h"
-#include "common/EventRecorder.h"
 #include "common/file.h"
 #include "common/fs.h"
 #include "common/textconsole.h"
@@ -110,7 +109,7 @@ AGOSEngine_Elvira1::AGOSEngine_Elvira1(OSystem *system)
 }
 
 AGOSEngine::AGOSEngine(OSystem *syst)
-	: Engine(syst) {
+	: Engine(syst), _rnd("agos") {
 
 	_vcPtr = 0;
 	_vcGetOutOfCode = 0;
@@ -526,8 +525,6 @@ AGOSEngine::AGOSEngine(OSystem *syst)
 	SearchMan.addSubDirectoryMatching(gameDataDir, "movies");
 	SearchMan.addSubDirectoryMatching(gameDataDir, "sfx");
 	SearchMan.addSubDirectoryMatching(gameDataDir, "speech");
-
-	g_eventRec.registerRandomSource(_rnd, "agos");
 }
 
 Common::Error AGOSEngine::init() {
diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp
index 1692662..6f34b0f 100644
--- a/engines/cine/cine.cpp
+++ b/engines/cine/cine.cpp
@@ -20,7 +20,6 @@
  *
  */
 
-#include "common/EventRecorder.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
 
@@ -42,7 +41,10 @@ Sound *g_sound = 0;
 
 CineEngine *g_cine = 0;
 
-CineEngine::CineEngine(OSystem *syst, const CINEGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
+CineEngine::CineEngine(OSystem *syst, const CINEGameDescription *gameDesc)
+	: Engine(syst),
+	_gameDescription(gameDesc),
+	_rnd("cine") {
 	// Setup mixer
 	syncSoundSettings();
 
@@ -53,8 +55,6 @@ CineEngine::CineEngine(OSystem *syst, const CINEGameDescription *gameDesc) : Eng
 	_console = new CineConsole(this);
 
 	g_cine = this;
-
-	g_eventRec.registerRandomSource(_rnd, "cine");
 }
 
 CineEngine::~CineEngine() {
diff --git a/engines/cruise/cruise.cpp b/engines/cruise/cruise.cpp
index 0766ce3f..1e0b7b1 100644
--- a/engines/cruise/cruise.cpp
+++ b/engines/cruise/cruise.cpp
@@ -20,7 +20,6 @@
  *
  */
 
-#include "common/EventRecorder.h"
 #include "common/file.h"
 #include "common/debug-channels.h"
 #include "common/textconsole.h"
@@ -41,7 +40,8 @@ namespace Cruise {
 
 CruiseEngine *_vm;
 
-CruiseEngine::CruiseEngine(OSystem * syst, const CRUISEGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
+CruiseEngine::CruiseEngine(OSystem * syst, const CRUISEGameDescription *gameDesc)
+	: Engine(syst), _gameDescription(gameDesc), _rnd("cruise") {
 
 	DebugMan.addDebugChannel(kCruiseDebugScript, "scripts", "Scripts debug level");
 	DebugMan.addDebugChannel(kCruiseDebugSound, "sound", "Sound debug level");
@@ -52,8 +52,6 @@ CruiseEngine::CruiseEngine(OSystem * syst, const CRUISEGameDescription *gameDesc
 
 	// Setup mixer
 	syncSoundSettings();
-
-	g_eventRec.registerRandomSource(_rnd, "cruise");
 }
 
 extern void listMemory();
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index 41950ac..cdc91e8 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -27,7 +27,6 @@
 #include "common/events.h"
 #include "common/file.h"
 #include "common/keyboard.h"
-#include "common/EventRecorder.h"
 
 #include "engines/util.h"
 
@@ -71,7 +70,8 @@ const uint kSoundsFrequency = 13000;
 const uint kDubbingFrequency = 22050;
 
 DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
- : Engine(syst) {
+ : Engine(syst), _rnd("draci") {
+
 	// Put your engine in a sane state, but do nothing big yet;
 	// in particular, do not load data from files; rather, if you
 	// need to do such things, do them from init().
@@ -92,9 +92,6 @@ DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
 	DebugMan.addDebugChannel(kDraciWalkingDebugLevel, "walking", "Walking debug info");
 
 	_console = new DraciConsole(this);
-
-	// Don't forget to register your random source
-	g_eventRec.registerRandomSource(_rnd, "draci");
 }
 
 bool DraciEngine::hasFeature(EngineFeature f) const {
diff --git a/engines/drascula/drascula.cpp b/engines/drascula/drascula.cpp
index f165116..cac7f93 100644
--- a/engines/drascula/drascula.cpp
+++ b/engines/drascula/drascula.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/keyboard.h"
 #include "common/file.h"
 #include "common/savefile.h"
@@ -97,8 +96,7 @@ DrasculaEngine::DrasculaEngine(OSystem *syst, const DrasculaGameDescription *gam
 	rightMouseButton = 0;
 	*textName = 0;
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "drascula");
+	_rnd = new Common::RandomSource("drascula");
 
 	_console = 0;
 
diff --git a/engines/gob/gob.cpp b/engines/gob/gob.cpp
index 7e8f77f..ea7e329 100644
--- a/engines/gob/gob.cpp
+++ b/engines/gob/gob.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
 
 #include "backends/audiocd/audiocd.h"
 #include "base/plugins.h"
@@ -110,7 +109,7 @@ void PauseDialog::handleKeyDown(Common::KeyState state) {
 }
 
 
-GobEngine::GobEngine(OSystem *syst) : Engine(syst) {
+GobEngine::GobEngine(OSystem *syst) : Engine(syst), _rnd("gob") {
 	_sound     = 0; _mult     = 0; _game    = 0;
 	_global    = 0; _dataIO   = 0; _goblin  = 0;
 	_vidPlayer = 0; _init     = 0; _inter   = 0;
@@ -145,8 +144,6 @@ GobEngine::GobEngine(OSystem *syst) : Engine(syst) {
 	DebugMan.addDebugChannel(kDebugVideo, "Video", "IMD/VMD video debug level");
 	DebugMan.addDebugChannel(kDebugHotspots, "Hotspots", "Hotspots debug level");
 	DebugMan.addDebugChannel(kDebugDemo, "Demo", "Demo script debug level");
-
-	g_eventRec.registerRandomSource(_rnd, "gob");
 }
 
 GobEngine::~GobEngine() {
diff --git a/engines/gob/sound/bgatmosphere.cpp b/engines/gob/sound/bgatmosphere.cpp
index e249824..daba72b 100644
--- a/engines/gob/sound/bgatmosphere.cpp
+++ b/engines/gob/sound/bgatmosphere.cpp
@@ -20,7 +20,7 @@
  *
  */
 
-#include "common/EventRecorder.h"
+#include "common/array.h"
 
 #include "gob/sound/bgatmosphere.h"
 #include "gob/sound/sounddesc.h"
@@ -28,14 +28,12 @@
 namespace Gob {
 
 BackgroundAtmosphere::BackgroundAtmosphere(Audio::Mixer &mixer) :
-	SoundMixer(mixer, Audio::Mixer::kMusicSoundType) {
+	SoundMixer(mixer, Audio::Mixer::kMusicSoundType), _rnd("gobBA") {
 
 	_playMode = kPlayModeLinear;
 	_queuePos = -1;
 	_shaded = false;
 	_shadable = true;
-
-	g_eventRec.registerRandomSource(_rnd, "gobBA");
 }
 
 BackgroundAtmosphere::~BackgroundAtmosphere() {
diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp
index 080e025..3bd90a0 100644
--- a/engines/groovie/script.cpp
+++ b/engines/groovie/script.cpp
@@ -33,7 +33,7 @@
 #include "common/archive.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
+#include "common/events.h"
 #include "common/file.h"
 #include "common/macresman.h"
 
@@ -65,7 +65,8 @@ static void debugScript(int level, bool nl, const char *s, ...) {
 
 Script::Script(GroovieEngine *vm, EngineVersion version) :
 	_code(NULL), _savedCode(NULL), _stacktop(0), _debugger(NULL), _vm(vm),
-	_videoFile(NULL), _videoRef(0), _staufsMove(NULL) {
+	_videoFile(NULL), _videoRef(0), _staufsMove(NULL),
+	_random("GroovieScripts") {
 	// Initialize the opcode set depending on the engine version
 	switch (version) {
 	case kGroovieT7G:
@@ -76,9 +77,6 @@ Script::Script(GroovieEngine *vm, EngineVersion version) :
 		break;
 	}
 
-	// Initialize the random source
-	g_eventRec.registerRandomSource(_random, "GroovieScripts");
-
 	// Prepare the variables
 	_bitflags = 0;
 	for (int i = 0; i < 0x400; i++) {
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index 2485213..7d35aec 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -24,7 +24,6 @@
 #include "common/random.h"
 #include "common/error.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/debug-channels.h"
 #include "common/config-manager.h"
 #include "common/textconsole.h"
@@ -596,8 +595,7 @@ void HugoEngine::initialize() {
 	_file->openDatabaseFiles();                     // Open database files
 	calcMaxScore();                                 // Initialise maxscore
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "hugo");
+	_rnd = new Common::RandomSource("hugo");
 	_rnd->setSeed(42);                              // Kick random number generator
 
 	switch (_gameVariant) {
diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp
index 5081435..7f4f1ec 100644
--- a/engines/kyra/kyra_v1.cpp
+++ b/engines/kyra/kyra_v1.cpp
@@ -29,12 +29,11 @@
 #include "common/error.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
 
 namespace Kyra {
 
 KyraEngine_v1::KyraEngine_v1(OSystem *system, const GameFlags &flags)
-	: Engine(system), _flags(flags) {
+	: Engine(system), _flags(flags), _rnd("kyra") {
 	_res = 0;
 	_sound = 0;
 	_text = 0;
@@ -78,8 +77,6 @@ KyraEngine_v1::KyraEngine_v1(OSystem *system, const GameFlags &flags)
 	DebugMan.addDebugChannel(kDebugLevelSequence, "Sequence", "Sequence debug level");
 	DebugMan.addDebugChannel(kDebugLevelMovie, "Movie", "Movie debug level");
 	DebugMan.addDebugChannel(kDebugLevelTimer, "Timer", "Timer debug level");
-
-	g_eventRec.registerRandomSource(_rnd, "kyra");
 }
 
 ::GUI::Debugger *KyraEngine_v1::getDebugger() {
diff --git a/engines/kyra/sprites.cpp b/engines/kyra/sprites.cpp
index bcf1675..e0d1142 100644
--- a/engines/kyra/sprites.cpp
+++ b/engines/kyra/sprites.cpp
@@ -25,11 +25,10 @@
 #include "kyra/animator_lok.h"
 
 #include "common/system.h"
-#include "common/EventRecorder.h"
 
 namespace Kyra {
 
-Sprites::Sprites(KyraEngine_LoK *vm, OSystem *system) {
+Sprites::Sprites(KyraEngine_LoK *vm, OSystem *system) : _rnd("kyraSprites") {
 	_vm = vm;
 	_res = vm->resource();
 	_screen = vm->screen();
@@ -40,7 +39,6 @@ Sprites::Sprites(KyraEngine_LoK *vm, OSystem *system) {
 	_spriteDefStart = 0;
 	memset(_drawLayerTable, 0, sizeof(_drawLayerTable));
 	_sceneAnimatorBeaconFlag = 0;
-	g_eventRec.registerRandomSource(_rnd, "kyraSprites");
 }
 
 Sprites::~Sprites() {
diff --git a/engines/lastexpress/lastexpress.cpp b/engines/lastexpress/lastexpress.cpp
index ad6acff..d195fcf 100644
--- a/engines/lastexpress/lastexpress.cpp
+++ b/engines/lastexpress/lastexpress.cpp
@@ -37,7 +37,6 @@
 
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
 
 #include "engines/util.h"
 
@@ -49,10 +48,16 @@ const char *g_entityNames[] = { "Player", "Anna", "August", "Mertens", "Coudert"
 namespace LastExpress {
 
 LastExpressEngine::LastExpressEngine(OSystem *syst, const ADGameDescription *gd) :
-    Engine(syst), _gameDescription(gd), _debugger(NULL), _cursor(NULL),
-    _font(NULL), _logic(NULL), _menu(NULL), _frameCounter(0), _lastFrameCount(0),
-	_graphicsMan(NULL), _resMan(NULL), _sceneMan(NULL), _soundMan(NULL),
-	_eventMouse(NULL), _eventTick(NULL), _eventMouseBackup(NULL), _eventTickBackup(NULL) {
+    Engine(syst), _gameDescription(gd),
+    _debugger(NULL), _cursor(NULL),
+    _font(NULL), _logic(NULL), _menu(NULL),
+    _frameCounter(0), _lastFrameCount(0),
+	_graphicsMan(NULL), _resMan(NULL),
+	_sceneMan(NULL), _soundMan(NULL),
+	_eventMouse(NULL), _eventTick(NULL),
+	_eventMouseBackup(NULL), _eventTickBackup(NULL),
+	_random("lastexpress")
+	{
 	// Setup mixer
 	syncSoundSettings();
 
@@ -71,8 +76,6 @@ LastExpressEngine::LastExpressEngine(OSystem *syst, const ADGameDescription *gd)
 	DebugMan.addDebugChannel(kLastExpressDebugLogic, "Logic", "Debug logic");
 	DebugMan.addDebugChannel(kLastExpressDebugScenes, "Scenes", "Debug scenes & hotspots");
 	DebugMan.addDebugChannel(kLastExpressDebugUnknown, "Unknown", "Debug unknown data");
-
-	g_eventRec.registerRandomSource(_random, "lastexpress");
 }
 
 LastExpressEngine::~LastExpressEngine() {
diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp
index cec845a..c6be5c4 100644
--- a/engines/lure/lure.cpp
+++ b/engines/lure/lure.cpp
@@ -24,7 +24,6 @@
 #include "common/debug-channels.h"
 #include "common/system.h"
 #include "common/savefile.h"
-#include "common/EventRecorder.h"
 
 #include "engines/util.h"
 
@@ -39,8 +38,8 @@ namespace Lure {
 
 static LureEngine *int_engine = NULL;
 
-LureEngine::LureEngine(OSystem *system, const LureGameDescription *gameDesc): Engine(system), _gameDescription(gameDesc) {
-	g_eventRec.registerRandomSource(_rnd, "lure");
+LureEngine::LureEngine(OSystem *system, const LureGameDescription *gameDesc)
+	: Engine(system), _gameDescription(gameDesc), _rnd("lure") {
 
 	DebugMan.addDebugChannel(kLureDebugScripts, "scripts", "Scripts debugging");
 	DebugMan.addDebugChannel(kLureDebugAnimations, "animations", "Animations debugging");
diff --git a/engines/lure/scripts.cpp b/engines/lure/scripts.cpp
index 5a5a311..7cd8be4 100644
--- a/engines/lure/scripts.cpp
+++ b/engines/lure/scripts.cpp
@@ -31,7 +31,6 @@
 #include "lure/sound.h"
 #include "common/stack.h"
 #include "common/endian.h"
-#include "common/EventRecorder.h"
 
 namespace Lure {
 
diff --git a/engines/m4/m4.cpp b/engines/m4/m4.cpp
index 5b1e4e9..881a523 100644
--- a/engines/m4/m4.cpp
+++ b/engines/m4/m4.cpp
@@ -49,7 +49,6 @@
 #include "common/error.h"
 #include "common/file.h"
 #include "common/fs.h"
-#include "common/EventRecorder.h"
 #include "common/system.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
@@ -177,8 +176,7 @@ Common::Error MadsM4Engine::run() {
 	_script = new ScriptInterpreter(this);
 	_ws = new WoodScript(this);
 	//_callbacks = new Callbacks(this);
-	_random = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_random, "m4");
+	_random = new Common::RandomSource("m4");
 
 	return Common::kNoError;
 }
diff --git a/engines/made/made.cpp b/engines/made/made.cpp
index c4e0198..a9c4587 100644
--- a/engines/made/made.cpp
+++ b/engines/made/made.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/keyboard.h"
 #include "common/config-manager.h"
 #include "common/stream.h"
@@ -72,8 +71,7 @@ MadeEngine::MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc) : Eng
 		if (!scumm_stricmp(g->gameid, gameid))
 			_gameId = g->id;
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "made");
+	_rnd = new Common::RandomSource("made");
 
 	_console = new MadeConsole(this);
 
diff --git a/engines/mohawk/cstime.cpp b/engines/mohawk/cstime.cpp
index 0bc480e..59bc5ad 100644
--- a/engines/mohawk/cstime.cpp
+++ b/engines/mohawk/cstime.cpp
@@ -32,15 +32,14 @@
 #include "common/config-manager.h"
 #include "common/error.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/fs.h"
 #include "common/textconsole.h"
+#include "common/system.h"
 
 namespace Mohawk {
 
 MohawkEngine_CSTime::MohawkEngine_CSTime(OSystem *syst, const MohawkGameDescription *gamedesc) : MohawkEngine(syst, gamedesc) {
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "cstime");
+	_rnd = new Common::RandomSource("cstime");
 
 	// If the user just copied the CD contents, the fonts are in a subdirectory.
 	const Common::FSNode gameDataDir(ConfMan.get("path"));
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index 36d86fb..a4e7f03 100644
--- a/engines/mohawk/livingbooks.cpp
+++ b/engines/mohawk/livingbooks.cpp
@@ -28,10 +28,10 @@
 #include "common/config-manager.h"
 #include "common/error.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/fs.h"
 #include "common/archive.h"
 #include "common/textconsole.h"
+#include "common/system.h"
 
 #include "graphics/palette.h"
 
@@ -125,8 +125,7 @@ MohawkEngine_LivingBooks::MohawkEngine_LivingBooks(OSystem *syst, const MohawkGa
 
 	_alreadyShowedIntro = false;
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "livingbooks");
+	_rnd = new Common::RandomSource("livingbooks");
 
 	_page = NULL;
 
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index 417a5b5..f407e65 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -22,9 +22,9 @@
 
 #include "common/config-manager.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/keyboard.h"
 #include "common/translation.h"
+#include "common/system.h"
 
 #include "mohawk/cursors.h"
 #include "mohawk/graphics.h"
@@ -118,8 +118,7 @@ Common::Error MohawkEngine_Riven::run() {
 	_optionsDialog = new RivenOptionsDialog(this);
 	_scriptMan = new RivenScriptManager(this);
 
-	_rnd = new Common::RandomSource();
-	g_eventRec.registerRandomSource(*_rnd, "riven");
+	_rnd = new Common::RandomSource("riven");
 
 	// Create the cursor manager
 	if (Common::File::exists("rivendmo.exe"))
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 61709b7..9bbc7d0 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
 #include "common/system.h"
 #include "common/textconsole.h"
 
@@ -45,7 +44,7 @@ uint32		_globalFlags = 0;
 
 Parallaction::Parallaction(OSystem *syst, const PARALLACTIONGameDescription *gameDesc) :
 	Engine(syst), _gameDescription(gameDesc), _location(getGameType()),
-	_dialogueMan(0) {
+	_dialogueMan(0), _rnd("parallaction") {
 	// Setup mixer
 	syncSoundSettings();
 
@@ -60,8 +59,6 @@ Parallaction::Parallaction(OSystem *syst, const PARALLACTIONGameDescription *gam
 	DebugMan.addDebugChannel(kDebugAudio, "audio", "Audio debug level");
 	DebugMan.addDebugChannel(kDebugMenu, "menu", "Menu debug level");
 	DebugMan.addDebugChannel(kDebugInventory, "inventory", "Inventory debug level");
-
-	g_eventRec.registerRandomSource(_rnd, "parallaction");
 }
 
 Parallaction::~Parallaction() {
diff --git a/engines/queen/display.cpp b/engines/queen/display.cpp
index 56f1026..83dc1a9 100644
--- a/engines/queen/display.cpp
+++ b/engines/queen/display.cpp
@@ -22,7 +22,6 @@
 
 
 #include "common/system.h"
-#include "common/EventRecorder.h"
 #include "common/events.h"
 
 #include "graphics/cursorman.h"
@@ -38,7 +37,7 @@ namespace Queen {
 
 Display::Display(QueenEngine *vm, OSystem *system)
 	: _fullscreen(true), _horizontalScroll(0), _bdWidth(0), _bdHeight(0),
-	_system(system), _vm(vm) {
+	_system(system), _vm(vm), _rnd("queenDisplay") {
 
 	initFont();
 
@@ -73,7 +72,6 @@ Display::Display(QueenEngine *vm, OSystem *system)
 	memset(&_dynalum, 0, sizeof(_dynalum));
 
 	setupInkColors();
-	g_eventRec.registerRandomSource(_rnd, "queenDisplay");
 }
 
 Display::~Display() {
diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp
index 5d20e48..8586927 100644
--- a/engines/queen/music.cpp
+++ b/engines/queen/music.cpp
@@ -22,7 +22,6 @@
 
 #include "common/config-manager.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 
 #include "queen/music.h"
 #include "queen/queen.h"
@@ -37,7 +36,9 @@ namespace Queen {
 extern MidiDriver *C_Player_CreateAdLibMidiDriver(Audio::Mixer *);
 
 MidiMusic::MidiMusic(QueenEngine *vm)
-	: _isPlaying(false), _isLooping(false), _randomLoop(false), _masterVolume(192), _buf(0) {
+	: _isPlaying(false), _isLooping(false),
+	_randomLoop(false), _masterVolume(192),
+	_buf(0), _rnd("queenMusic") {
 
 	memset(_channelsTable, 0, sizeof(_channelsTable));
 	_queuePos = _lastSong = _currentSong = 0;
@@ -89,8 +90,6 @@ MidiMusic::MidiMusic(QueenEngine *vm)
 	_parser = MidiParser::createParser_SMF();
 	_parser->setMidiDriver(this);
 	_parser->setTimerRate(_driver->getBaseTempo());
-
-	g_eventRec.registerRandomSource(_rnd, "queenMusic");
 }
 
 MidiMusic::~MidiMusic() {
diff --git a/engines/queen/queen.cpp b/engines/queen/queen.cpp
index 1e34ba2..97f757c 100644
--- a/engines/queen/queen.cpp
+++ b/engines/queen/queen.cpp
@@ -28,7 +28,6 @@
 #include "common/savefile.h"
 #include "common/system.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/textconsole.h"
 
 #include "engines/util.h"
@@ -193,8 +192,7 @@ Common::Error QueenMetaEngine::createInstance(OSystem *syst, Engine **engine) co
 namespace Queen {
 
 QueenEngine::QueenEngine(OSystem *syst)
-	: Engine(syst), _debugger(0) {
-	g_eventRec.registerRandomSource(randomizer, "queen");
+	: Engine(syst), _debugger(0), randomizer("queen") {
 }
 
 QueenEngine::~QueenEngine() {
diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp
index f2b70d2..15bd2af 100644
--- a/engines/saga/saga.cpp
+++ b/engines/saga/saga.cpp
@@ -25,7 +25,6 @@
 #include "common/config-manager.h"
 #include "common/system.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 
 #include "audio/mixer.h"
 
@@ -56,7 +55,7 @@ namespace Saga {
 #define MAX_TIME_DELTA 100
 
 SagaEngine::SagaEngine(OSystem *syst, const SAGAGameDescription *gameDesc)
-	: Engine(syst), _gameDescription(gameDesc) {
+	: Engine(syst), _gameDescription(gameDesc), _rnd("saga") {
 
 	_framesEsc = 0;
 
@@ -133,7 +132,6 @@ SagaEngine::SagaEngine(OSystem *syst, const SAGAGameDescription *gameDesc)
 	SearchMan.addSubDirectoryMatching(gameDataDir, "video");
 
 	_displayClip.left = _displayClip.top = 0;
-	g_eventRec.registerRandomSource(_rnd, "saga");
 }
 
 SagaEngine::~SagaEngine() {
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 43cda13..cf46d41 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -23,8 +23,6 @@
 #include "common/system.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
-#include "common/EventRecorder.h"
-#include "common/file.h"	// for Common::File::exists()
 
 #include "engines/advancedDetector.h"
 #include "engines/util.h"
@@ -75,7 +73,7 @@ SciEngine *g_sci = 0;
 class GfxDriver;
 
 SciEngine::SciEngine(OSystem *syst, const ADGameDescription *desc, SciGameId gameId)
-		: Engine(syst), _gameDescription(desc), _gameId(gameId) {
+		: Engine(syst), _gameDescription(desc), _gameId(gameId), _rng("sci") {
 
 	assert(g_sci == 0);
 	g_sci = this;
@@ -183,8 +181,6 @@ SciEngine::~SciEngine() {
 extern void showScummVMDialog(const Common::String &message);
 
 Common::Error SciEngine::run() {
-	g_eventRec.registerRandomSource(_rng, "sci");
-
 	// Assign default values to the config manager, in case settings are missing
 	ConfMan.registerDefault("sci_originalsaveload", "false");
 	ConfMan.registerDefault("native_fb01", "false");
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 6e95846..1b7f16b 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -24,7 +24,6 @@
 #include "common/debug-channels.h"
 #include "common/md5.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/system.h"
 #include "common/translation.h"
 
@@ -111,7 +110,9 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
 	  _language(dr.language),
 	  _debugger(0),
 	  _currentScript(0xFF), // Let debug() work on init stage
-	  _messageDialog(0), _pauseDialog(0), _versionDialog(0) {
+	  _messageDialog(0), _pauseDialog(0), _versionDialog(0),
+	  _rnd("scumm")
+	  {
 
 	if (_game.heversion > 0) {
 		_gdi = new GdiHE(this);
@@ -574,8 +575,6 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
 	assert(!_mainMenuDialog);
 	_mainMenuDialog = new ScummMenuDialog(this);
 #endif
-
-	g_eventRec.registerRandomSource(_rnd, "scumm");
 }
 
 
diff --git a/engines/sky/logic.cpp b/engines/sky/logic.cpp
index ab3f114..de081bb 100644
--- a/engines/sky/logic.cpp
+++ b/engines/sky/logic.cpp
@@ -22,7 +22,6 @@
 
 #include "common/endian.h"
 #include "common/rect.h"
-#include "common/EventRecorder.h"
 #include "common/textconsole.h"
 
 #include "sky/autoroute.h"
@@ -68,8 +67,8 @@ void Logic::setupLogicTable() {
 	_logicTable = logicTable;
 }
 
-Logic::Logic(SkyCompact *skyCompact, Screen *skyScreen, Disk *skyDisk, Text *skyText, MusicBase *skyMusic, Mouse *skyMouse, Sound *skySound) {
-	g_eventRec.registerRandomSource(_rnd, "sky");
+Logic::Logic(SkyCompact *skyCompact, Screen *skyScreen, Disk *skyDisk, Text *skyText, MusicBase *skyMusic, Mouse *skyMouse, Sound *skySound)
+	: _rnd("sky") {
 
 	_skyCompact = skyCompact;
 	_skyScreen = skyScreen;
diff --git a/engines/sword1/logic.cpp b/engines/sword1/logic.cpp
index b334294..00f7112 100644
--- a/engines/sword1/logic.cpp
+++ b/engines/sword1/logic.cpp
@@ -22,7 +22,6 @@
 
 #include "common/endian.h"
 #include "common/util.h"
-#include "common/EventRecorder.h"
 #include "common/textconsole.h"
 
 #include "sword1/logic.h"
@@ -50,8 +49,8 @@ namespace Sword1 {
 
 uint32 Logic::_scriptVars[NUM_SCRIPT_VARS];
 
-Logic::Logic(SwordEngine *vm, ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Music *pMusic, Menu *pMenu, OSystem *system, Audio::Mixer *mixer) {
-	g_eventRec.registerRandomSource(_rnd, "sword1");
+Logic::Logic(SwordEngine *vm, ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Music *pMusic, Menu *pMenu, OSystem *system, Audio::Mixer *mixer)
+	: _rnd("sword1") {
 
 	_vm = vm;
 	_objMan = pObjMan;
diff --git a/engines/sword1/logic.h b/engines/sword1/logic.h
index 461355a..13ddbc9 100644
--- a/engines/sword1/logic.h
+++ b/engines/sword1/logic.h
@@ -30,6 +30,8 @@
 #include "common/random.h"
 #include "audio/mixer.h"
 
+class OSystem;
+
 namespace Sword1 {
 
 #define NON_ZERO_SCRIPT_VARS 95
diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index a5a3634..f7ab9ca 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -24,7 +24,6 @@
 #include "common/endian.h"
 
 #include "common/util.h"
-#include "common/EventRecorder.h"
 #include "common/memstream.h"
 #include "common/textconsole.h"
 
@@ -46,8 +45,8 @@ namespace Sword1 {
 #define SOUND_SPEECH_ID 1
 #define SPEECH_FLAGS (Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN)
 
-Sound::Sound(const char *searchPath, Audio::Mixer *mixer, ResMan *pResMan) {
-	g_eventRec.registerRandomSource(_rnd, "sword1sound");
+Sound::Sound(const char *searchPath, Audio::Mixer *mixer, ResMan *pResMan)
+	: _rnd("sword1sound") {
 	strcpy(_filePath, searchPath);
 	_mixer = mixer;
 	_resMan = pResMan;
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp
index cb58398..47c9b16 100644
--- a/engines/sword2/sword2.cpp
+++ b/engines/sword2/sword2.cpp
@@ -28,7 +28,6 @@
 #include "common/file.h"
 #include "common/fs.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/savefile.h"
 #include "common/system.h"
 #include "common/textconsole.h"
@@ -252,7 +251,7 @@ Common::Error Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) c
 
 namespace Sword2 {
 
-Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
+Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst), _rnd("sword2") {
 	// Add default file directories
 	const Common::FSNode gameDataDir(ConfMan.get("path"));
 	SearchMan.addSubDirectoryMatching(gameDataDir, "clusters");
@@ -292,8 +291,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
 	_gameSpeed = 1;
 
 	_gmmLoadSlot = -1; // Used to manage GMM Loading
-
-	g_eventRec.registerRandomSource(_rnd, "sword2");
 }
 
 Sword2Engine::~Sword2Engine() {
diff --git a/engines/tinsel/tinsel.cpp b/engines/tinsel/tinsel.cpp
index 9fc2ecf..84a8ea8 100644
--- a/engines/tinsel/tinsel.cpp
+++ b/engines/tinsel/tinsel.cpp
@@ -24,7 +24,6 @@
 #include "common/endian.h"
 #include "common/error.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/keyboard.h"
 #include "common/fs.h"
 #include "common/config-manager.h"
@@ -815,7 +814,7 @@ const char *TinselEngine::_textFiles[][3] = {
 
 
 TinselEngine::TinselEngine(OSystem *syst, const TinselGameDescription *gameDesc) :
-		Engine(syst), _gameDescription(gameDesc) {
+		Engine(syst), _gameDescription(gameDesc), _random("tinsel") {
 	_vm = this;
 
 	_config = new Config(this);
@@ -906,8 +905,6 @@ Common::Error TinselEngine::run() {
 		_screenSurface.create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
 	}
 
-	g_eventRec.registerRandomSource(_random, "tinsel");
-
 	_console = new Console();
 
 	_scheduler = new Scheduler();
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 471c7c2..d441e59 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -25,7 +25,6 @@
 #include "common/debug-channels.h"
 #include "common/archive.h"
 #include "common/config-manager.h"
-#include "common/EventRecorder.h"
 #include "common/savefile.h"
 #include "common/memstream.h"
 
@@ -780,8 +779,6 @@ Common::Error ToonEngine::run() {
 	if (!loadToonDat())
 		return Common::kUnknownError;
 
-	g_eventRec.registerRandomSource(_rnd, "toon");
-
 	initGraphics(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT, true);
 	init();
 
@@ -815,7 +812,8 @@ Common::Error ToonEngine::run() {
 }
 
 ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription)
-	: Engine(syst), _gameDescription(gameDescription), _language(gameDescription->language) {
+	: Engine(syst), _gameDescription(gameDescription),
+	_language(gameDescription->language), _rnd("toon") {
 	_system = syst;
 	_tickLength = 16;
 	_currentPicture = NULL;
diff --git a/engines/touche/touche.cpp b/engines/touche/touche.cpp
index 018e5b0..81d6adf 100644
--- a/engines/touche/touche.cpp
+++ b/engines/touche/touche.cpp
@@ -24,7 +24,6 @@
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 #include "common/fs.h"
 #include "common/system.h"
 #include "common/archive.h"
@@ -45,7 +44,7 @@
 namespace Touche {
 
 ToucheEngine::ToucheEngine(OSystem *system, Common::Language language)
-	: Engine(system), _midiPlayer(0), _language(language) {
+	: Engine(system), _midiPlayer(0), _language(language), _rnd("touche") {
 	_saveLoadCurrentPage = 0;
 	_saveLoadCurrentSlot = 0;
 	_hideInventoryTexts = false;
@@ -84,8 +83,6 @@ ToucheEngine::ToucheEngine(OSystem *system, Common::Language language)
 	DebugMan.addDebugChannel(kDebugMenu,     "Menu",     "Menu debug level");
 
 	_console = new ToucheConsole(this);
-
-	g_eventRec.registerRandomSource(_rnd, "touche");
 }
 
 ToucheEngine::~ToucheEngine() {


Commit: 05a7b160b396f0ffec50d597f5c980be235cbe7e
    https://github.com/scummvm/scummvm/commit/05a7b160b396f0ffec50d597f5c980be235cbe7e
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:26-07:00

Commit Message:
TEEN: Use only one RandomSource and give that one a name.

This change ensures that only RandomSource is used which also is
registered with the event recorder. Moreover, it gets rid of a static
RandomSource instance inside Actor::renderIdle.

Changed paths:
    engines/teenagent/actor.cpp
    engines/teenagent/actor.h
    engines/teenagent/callbacks.cpp
    engines/teenagent/scene.cpp
    engines/teenagent/teenagent.cpp
    engines/teenagent/teenagent.h



diff --git a/engines/teenagent/actor.cpp b/engines/teenagent/actor.cpp
index 870410b..717c022 100644
--- a/engines/teenagent/actor.cpp
+++ b/engines/teenagent/actor.cpp
@@ -31,10 +31,9 @@ namespace TeenAgent {
 Actor::Actor() : head_index(0), idle_type(0) {}
 
 //idle animation lists at dseg: 0x6540
-Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom) {
-	static Common::RandomSource random;
+Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom, Common::RandomSource &rnd) {
 	if (index == 0) {
-		idle_type = random.getRandomNumber(2);
+		idle_type = rnd.getRandomNumber(2);
 		debug(0, "switched to idle animation %u", idle_type);
 	}
 
@@ -44,7 +43,7 @@ Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &
 		frames_idle = res->dseg.ptr(res->dseg.get_word(0x6540 + idle_type * 2)) + index;
 		index += delta_frame;
 		if (*frames_idle == 0) {
-			idle_type = random.getRandomNumber(2);
+			idle_type = rnd.getRandomNumber(2);
 			debug(0, "switched to idle animation %u[loop]", idle_type);
 			index = 3; //put 4th frame (base 1) if idle animation loops
 		}
diff --git a/engines/teenagent/actor.h b/engines/teenagent/actor.h
index 5e13af1..9a7d395 100644
--- a/engines/teenagent/actor.h
+++ b/engines/teenagent/actor.h
@@ -22,6 +22,10 @@
 #include "teenagent/animation.h"
 #include "common/rect.h"
 
+namespace Common {
+class RandomSource;
+}
+
 namespace TeenAgent {
 
 class Actor : public Animation {
@@ -30,7 +34,7 @@ class Actor : public Animation {
 public:
 	Actor();
 	Common::Rect render(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, bool head, uint zoom);
-	Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom);
+	Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom, Common::RandomSource &rnd);
 };
 
 } // End of namespace TeenAgent
diff --git a/engines/teenagent/callbacks.cpp b/engines/teenagent/callbacks.cpp
index 8c8519e..ae49847 100644
--- a/engines/teenagent/callbacks.cpp
+++ b/engines/teenagent/callbacks.cpp
@@ -36,7 +36,7 @@ namespace TeenAgent {
 void TeenAgentEngine::rejectMessage() {
 	Resources * res = Resources::instance();
 	//random reject message:
-	uint i = random.getRandomNumber(3);
+	uint i = _rnd.getRandomNumber(3);
 	//debug(0, "reject message: %s", (const char *)res->dseg.ptr(res->dseg.get_word(0x339e + 2 * i)));
 	displayMessage(res->dseg.get_word(0x339e + 2 * i));
 }
@@ -3004,7 +3004,7 @@ bool TeenAgentEngine::processCallback(uint16 addr) {
 		moveTo(153, 163, 4);
 		playActorAnimation(973);
 		if (CHECK_FLAG(0xDBC1, 0)) {
-			SET_FLAG(0xDBC1, random.getRandomNumber(5) + 1);
+			SET_FLAG(0xDBC1, _rnd.getRandomNumber(5) + 1);
 		}
 		loadScene(30, 18, 159, 2);
 		return true;
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index 54c3ce9..ef18b95 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -804,7 +804,7 @@ bool Scene::render(bool tick_game, bool tick_mark, uint32 delta) {
 				if (_idle_timer < 50)
 					actor_animation_position = teenagent.render(surface, position, orientation, 0, actor_talking, zoom);
 				else
-					actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, mark_delta, zoom);
+					actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, mark_delta, zoom, _engine->_rnd);
 			}
 		}
 
diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp
index d8cbae9..f076dbc 100644
--- a/engines/teenagent/teenagent.cpp
+++ b/engines/teenagent/teenagent.cpp
@@ -47,7 +47,9 @@
 
 namespace TeenAgent {
 
-TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd) : Engine(system), action(kActionNone), _gameDescription(gd) {
+TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd)
+	: Engine(system), action(kActionNone), _gameDescription(gd),
+	_rnd("teenagent") {
 	music = new MusicPlayer();
 
 	console = 0;
@@ -396,8 +398,8 @@ bool TeenAgentEngine::showMetropolis() {
 			//generate colors matrix
 			memmove(colors + 320, colors + 480, 8480);
 			for(uint c = 0; c < 17; ++c) {
-				byte x = (random.getRandomNumber(184) + 5) & 0xff;
-				uint offset = 8800 + random.getRandomNumber(158);
+				byte x = (_rnd.getRandomNumber(184) + 5) & 0xff;
+				uint offset = 8800 + _rnd.getRandomNumber(158);
 				colors[offset++] = x;
 				colors[offset++] = x;
 			}
diff --git a/engines/teenagent/teenagent.h b/engines/teenagent/teenagent.h
index a376b37..bc802da 100644
--- a/engines/teenagent/teenagent.h
+++ b/engines/teenagent/teenagent.h
@@ -47,7 +47,7 @@ class Scene;
 class MusicPlayer;
 class Console;
 
-class TeenAgentEngine: public Engine {
+class TeenAgentEngine : public Engine {
 public:
 	enum Action { kActionNone, kActionExamine, kActionUse };
 
@@ -117,7 +117,7 @@ public:
 	void fadeOut();
 	void wait(uint16 frames);
 
-	Common::RandomSource random;
+	Common::RandomSource _rnd;
 
 	Scene *scene;
 	Inventory *inventory;


Commit: f04d6c6ee5872e5d82ddf7376778259b4428673a
    https://github.com/scummvm/scummvm/commit/f04d6c6ee5872e5d82ddf7376778259b4428673a
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:27-07:00

Commit Message:
TUCKER: Give name to RandomSource, to register it with event recorder

Changed paths:
    engines/tucker/tucker.cpp



diff --git a/engines/tucker/tucker.cpp b/engines/tucker/tucker.cpp
index f28afe7..2bd7c47 100644
--- a/engines/tucker/tucker.cpp
+++ b/engines/tucker/tucker.cpp
@@ -41,7 +41,7 @@
 namespace Tucker {
 
 TuckerEngine::TuckerEngine(OSystem *system, Common::Language language, uint32 flags)
-	: Engine(system), _gameLang(language), _gameFlags(flags) {
+	: Engine(system), _gameLang(language), _gameFlags(flags), _rnd("tucker") {
 	_console = new TuckerConsole(this);
 }
 


Commit: 44b798d1072a32ee2142e8041fe3007e0b6b8e95
    https://github.com/scummvm/scummvm/commit/44b798d1072a32ee2142e8041fe3007e0b6b8e95
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:27-07:00

Commit Message:
AGI: Unify RandomSource instantiation

This fixes a leak in PreAGI games (which never deleted their
RandomSource), ensures that PreAGI's RandomSource has a name (and hence
is registered with the event recorder) and even slightly simplifies the
AgiEngine destructor.

Changed paths:
    engines/agi/agi.cpp
    engines/agi/agi.h
    engines/agi/preagi.cpp



diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 101c149..7831658 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -484,10 +484,16 @@ static const GameSettings agiSettings[] = {
 AgiBase::AgiBase(OSystem *syst, const AGIGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
 	_noSaveLoadAllowed = false;
 
+	_rnd = new Common::RandomSource("agi");
+
 	initFeatures();
 	initVersion();
 }
 
+AgiBase::~AgiBase() {
+	delete _rnd;
+}
+
 AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBase(syst, gameDesc) {
 
 	// Setup mixer
@@ -495,8 +501,6 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
 
 	parseFeatures();
 
-	_rnd = new Common::RandomSource("agi");
-
 	DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
 	DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
 	DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");
@@ -647,10 +651,11 @@ void AgiEngine::initialize() {
 }
 
 AgiEngine::~AgiEngine() {
-	// If the engine hasn't been initialized yet via AgiEngine::initialize(), don't attempt to free any resources,
-	// as they haven't been allocated. Fixes bug #1742432 - AGI: Engine crashes if no game is detected
+	// If the engine hasn't been initialized yet via
+	// AgiEngine::initialize(), don't attempt to free any resources, as
+	// they haven't been allocated. Fixes bug #1742432 - AGI: Engine
+	// crashes if no game is detected
 	if (_game.state == STATE_INIT) {
-		delete _rnd;	// delete _rnd, as it is allocated in the constructor, not in initialize()
 		return;
 	}
 
@@ -664,7 +669,6 @@ AgiEngine::~AgiEngine() {
 	free(_game.sbufOrig);
 	_gfx->deinitMachine();
 	delete _gfx;
-	delete _rnd;
 	delete _console;
 
 	free(_predictiveDictLine);
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 0b941e4..1934387 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -755,6 +755,7 @@ public:
 	virtual void clearKeyQueue() = 0;
 
 	AgiBase(OSystem *syst, const AGIGameDescription *gameDesc);
+	~AgiBase();
 
 	virtual void clearImageStack() = 0;
 	virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
diff --git a/engines/agi/preagi.cpp b/engines/agi/preagi.cpp
index 8eb2e7d..c1a6cd3 100644
--- a/engines/agi/preagi.cpp
+++ b/engines/agi/preagi.cpp
@@ -42,8 +42,6 @@ PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) :
 	// Setup mixer
 	syncSoundSettings();
 
-	_rnd = new Common::RandomSource();
-
 	DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
 	DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
 	DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");


Commit: 9ac184bfba36ff35191abb39fa0481f528ae7edb
    https://github.com/scummvm/scummvm/commit/9ac184bfba36ff35191abb39fa0481f528ae7edb
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:27-07:00

Commit Message:
MOHAWK: Name the RandomSource used for myst

Changed paths:
    engines/mohawk/myst.cpp



diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index 432d111..4f9c3a8 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -256,7 +256,7 @@ Common::Error MohawkEngine_Myst::run() {
 	_loadDialog->setSaveMode(false);
 	_optionsDialog = new MystOptionsDialog(this);
 	_cursor = new MystCursorManager(this);
-	_rnd = new Common::RandomSource();
+	_rnd = new Common::RandomSource("myst");
 
 	// Cursor is visible by default
 	_cursor->showCursor();


Commit: 99a6ac46e1c24ad4b08b0056f1bbbe12229d86c8
    https://github.com/scummvm/scummvm/commit/99a6ac46e1c24ad4b08b0056f1bbbe12229d86c8
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:27-07:00

Commit Message:
TSAGE: Name the RandomSource

Changed paths:
    engines/tsage/globals.cpp



diff --git a/engines/tsage/globals.cpp b/engines/tsage/globals.cpp
index e51e9d2..e38fb21 100644
--- a/engines/tsage/globals.cpp
+++ b/engines/tsage/globals.cpp
@@ -51,8 +51,9 @@ static SavedObject *classFactoryProc(const Common::String &className) {
 /*--------------------------------------------------------------------------*/
 
 Globals::Globals() :
-		_dialogCenter(160, 140),
-		_gfxManagerInstance(_screenSurface) {
+	_dialogCenter(160, 140),
+	_gfxManagerInstance(_screenSurface),
+	_randomSource("tsage") {
 	reset();
 	_stripNum = 0;
 


Commit: fb31fa2d6af4d68688ea996e329772b11999dc1a
    https://github.com/scummvm/scummvm/commit/fb31fa2d6af4d68688ea996e329772b11999dc1a
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:28-07:00

Commit Message:
SWORD25: Name the random source

Changed paths:
    engines/sword25/kernel/kernel.cpp



diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp
index 3ef4446..f45137c 100644
--- a/engines/sword25/kernel/kernel.cpp
+++ b/engines/sword25/kernel/kernel.cpp
@@ -54,7 +54,8 @@ Kernel::Kernel() :
 	_input(0),
 	_package(0),
 	_script(0),
-	_fmv(0)
+	_fmv(0),
+	_rnd("sword25")
 	{
 
 	_instance = this;


Commit: fc9b8d2a71cee8ad27aa8e390b378c0e46307bd2
    https://github.com/scummvm/scummvm/commit/fc9b8d2a71cee8ad27aa8e390b378c0e46307bd2
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:17:28-07:00

Commit Message:
COMMON: Remove auxillary RandomSource constructor

Changed paths:
    common/random.cpp
    common/random.h



diff --git a/common/random.cpp b/common/random.cpp
index be69d39..9ecd5d0 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -38,14 +38,6 @@ RandomSource::RandomSource(const String &name) {
 	g_eventRec.registerRandomSource(*this, name);
 }
 
-RandomSource::RandomSource() {
-	// Use system time as RNG seed. Normally not a good idea, if you are using
-	// a RNG for security purposes, but good enough for our purposes.
-	assert(g_system);
-	uint32 seed = g_system->getMillis();
-	setSeed(seed);
-}
-
 RandomSource::~RandomSource() {
 	// TODO: Unregister with g_eventRec
 }
diff --git a/common/random.h b/common/random.h
index 308d8a6..ea590f4 100644
--- a/common/random.h
+++ b/common/random.h
@@ -45,11 +45,6 @@ public:
 	 */
 	RandomSource(const String &name);
 
-	// FIXME: This constructor for a nameless randomness source should be removed.
-	// I am only adding this temporarily to ease transition to the new
-	// system which enforces names for randomness sources.
-	RandomSource();
-
 	~RandomSource();
 
 	void setSeed(uint32 seed);


Commit: d1652922340abbc852ab1c52125cf1a4c559a231
    https://github.com/scummvm/scummvm/commit/d1652922340abbc852ab1c52125cf1a4c559a231
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:23:41-07:00

Commit Message:
COMMON: Remove unused RandomSource destructor, clarify comments, cleanup

Changed paths:
    common/random.cpp
    common/random.h



diff --git a/common/random.cpp b/common/random.cpp
index 9ecd5d0..55fa3cb 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -33,15 +33,12 @@ RandomSource::RandomSource(const String &name) {
 	uint32 seed = g_system->getMillis();
 	setSeed(seed);
 
-	// Register this random source with the event recorder. This might
-	// reset the seed, so call it *after* the initial seed has been set.
+	// Register this random source with the event recorder. This may end
+	// up querying or resetting the current seed, so we must call it
+	// *after* the initial seed has been set.
 	g_eventRec.registerRandomSource(*this, name);
 }
 
-RandomSource::~RandomSource() {
-	// TODO: Unregister with g_eventRec
-}
-
 void RandomSource::setSeed(uint32 seed) {
 	_randSeed = seed;
 }
diff --git a/common/random.h b/common/random.h
index ea590f4..90f2ed5 100644
--- a/common/random.h
+++ b/common/random.h
@@ -45,11 +45,9 @@ public:
 	 */
 	RandomSource(const String &name);
 
-	~RandomSource();
-
 	void setSeed(uint32 seed);
 
-	uint32 getSeed() {
+	uint32 getSeed() const {
 		return _randSeed;
 	}
 
@@ -59,12 +57,14 @@ public:
 	 * @return	a random number in the interval [0, max]
 	 */
 	uint getRandomNumber(uint max);
+
 	/**
 	 * Generates a random bit, i.e. either 0 or 1.
-	 * Identical to getRandomNumber(1), but faster, hopefully.
+	 * Identical to getRandomNumber(1), but potentially faster.
 	 * @return	a random bit, either 0 or 1
 	 */
 	uint getRandomBit();
+
 	/**
 	 * Generates a random unsigned integer in the interval [min, max].
 	 * @param min	the lower bound


Commit: a3fe84cfe67a3eb4ae4750923f712bc9216a2f3f
    https://github.com/scummvm/scummvm/commit/a3fe84cfe67a3eb4ae4750923f712bc9216a2f3f
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:23:55-07:00

Commit Message:
GUI: For a list entry in edit mode, move caret to end

Changed paths:
    gui/widgets/list.cpp



diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index 7e72758..065b240 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -587,6 +587,7 @@ void ListWidget::startEditMode() {
 	if (_editable && !_editMode && _selectedItem >= 0) {
 		_editMode = true;
 		setEditString(_list[_selectedItem]);
+		_caretPos = _editString.size();	// Force caret to the *end* of the selection.
 		if (_listColors.empty()) {
 			_editColor = ThemeEngine::kFontColorNormal;
 		} else {


Commit: 29851abaea1a693f170f726aaa73d50af24b4761
    https://github.com/scummvm/scummvm/commit/29851abaea1a693f170f726aaa73d50af24b4761
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:23:55-07:00

Commit Message:
GUI: Text editing tweaks

- Streamline keypad handling
- Allow up/down to act like home/end
- On Mac OS X, allow ctrl-a and ctrl-e to act like home/end

Changed paths:
    gui/widgets/editable.cpp



diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp
index 35e85ca..de331d9 100644
--- a/gui/widgets/editable.cpp
+++ b/gui/widgets/editable.cpp
@@ -93,6 +93,28 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
 	if (_caretVisible)
 		drawCaret(true);
 
+	// Remap numeric keypad if NUM lock is *not* active.
+	// This code relies on the fact that the various KEYCODE_KP* values are
+	// consecutive.
+	if (0 == (state.flags & Common::KBD_NUM)
+		&& Common::KEYCODE_KP0 <= state.keycode
+		&& state.keycode <= Common::KEYCODE_KP_PERIOD) {
+		const Common::KeyCode remap[11] = {
+			Common::KEYCODE_INSERT, 	// KEYCODE_KP0
+			Common::KEYCODE_END,	 	// KEYCODE_KP1
+			Common::KEYCODE_DOWN, 		// KEYCODE_KP2
+			Common::KEYCODE_PAGEDOWN, 	// KEYCODE_KP3
+			Common::KEYCODE_LEFT, 		// KEYCODE_KP4
+			Common::KEYCODE_INVALID, 	// KEYCODE_KP5
+			Common::KEYCODE_RIGHT,	 	// KEYCODE_KP6
+			Common::KEYCODE_HOME,	 	// KEYCODE_KP7
+			Common::KEYCODE_UP, 		// KEYCODE_KP8
+			Common::KEYCODE_PAGEUP, 	// KEYCODE_KP9
+			Common::KEYCODE_DELETE,	 	// KEYCODE_KP_PERIOD
+		};
+		state.keycode = remap[state.keycode - Common::KEYCODE_KP0];
+	}
+
 	switch (state.keycode) {
 	case Common::KEYCODE_RETURN:
 	case Common::KEYCODE_KP_ENTER:
@@ -117,27 +139,6 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
 		forcecaret = true;
 		break;
 
-	// Keypad & special keys
-	//   - if num lock is set, we always go to the default case
-	//   - if num lock is not set, we either fall down to the special key case
-	//     or ignore the key press in case of 0 (INSERT), 2 (DOWN), 3 (PGDWN)
-	//     5, 8 (UP) and 9 (PGUP)
-
-	case Common::KEYCODE_KP0:
-	case Common::KEYCODE_KP2:
-	case Common::KEYCODE_KP3:
-	case Common::KEYCODE_KP5:
-	case Common::KEYCODE_KP8:
-	case Common::KEYCODE_KP9:
-		if (state.flags & Common::KBD_NUM)
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-		break;
-
-	case Common::KEYCODE_KP_PERIOD:
-		if (state.flags & Common::KBD_NUM) {
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-			break;
-		}
 	case Common::KEYCODE_DELETE:
 		if (_caretPos < (int)_editString.size()) {
 			_editString.deleteChar(_caretPos);
@@ -148,22 +149,15 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
 		forcecaret = true;
 		break;
 
-	case Common::KEYCODE_KP1:
-		if (state.flags & Common::KBD_NUM) {
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-			break;
-		}
+	case Common::KEYCODE_DOWN:
 	case Common::KEYCODE_END:
+		// Move caret to end
 		dirty = setCaretPos(_editString.size());
 		forcecaret = true;
 		break;
 
-	case Common::KEYCODE_KP4:
-		if (state.flags & Common::KBD_NUM) {
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-			break;
-		}
 	case Common::KEYCODE_LEFT:
+		// Move caret one left (if possible)
 		if (_caretPos > 0) {
 			dirty = setCaretPos(_caretPos - 1);
 		}
@@ -171,12 +165,8 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
 		dirty = true;
 		break;
 
-	case Common::KEYCODE_KP6:
-		if (state.flags & Common::KBD_NUM) {
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-			break;
-		}
 	case Common::KEYCODE_RIGHT:
+		// Move caret one right (if possible)
 		if (_caretPos < (int)_editString.size()) {
 			dirty = setCaretPos(_caretPos + 1);
 		}
@@ -184,16 +174,33 @@ bool EditableWidget::handleKeyDown(Common::KeyState state) {
 		dirty = true;
 		break;
 
-	case Common::KEYCODE_KP7:
-		if (state.flags & Common::KBD_NUM) {
-			defaultKeyDownHandler(state, dirty, forcecaret, handled);
-			break;
-		}
+	case Common::KEYCODE_UP:
 	case Common::KEYCODE_HOME:
+		// Move caret to start
 		dirty = setCaretPos(0);
 		forcecaret = true;
 		break;
 
+#ifdef MACOSX
+	// Mac OS X GUI style shortcuts: Ctrl-A goes to start of line, Ctrl-e to end of line.
+	// TODO: Should we disable these on Windows? There, Ctrl-A usually means
+	// "select all".
+	case Common::KEYCODE_a:
+	case Common::KEYCODE_e:
+		if (state.flags & Common::KBD_CTRL) {
+			if (state.keycode == Common::KEYCODE_a) {
+				// Move caret to start
+				dirty = setCaretPos(0);
+				forcecaret = true;
+			} else if (state.keycode == Common::KEYCODE_e) {
+				// Move caret to end
+				dirty = setCaretPos(_editString.size());
+				forcecaret = true;
+			}
+			break;
+		}
+#endif
+
 	default:
 		defaultKeyDownHandler(state, dirty, forcecaret, handled);
 	}


Commit: a3c326456110f9f5b71ff3a91bbad15b5232c5d7
    https://github.com/scummvm/scummvm/commit/a3c326456110f9f5b71ff3a91bbad15b5232c5d7
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:28:39-07:00

Commit Message:
TOON: Use RandomSource instead of rand()

Changed paths:
    engines/toon/toon.cpp



diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index d441e59..44c747c 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -2855,7 +2855,7 @@ void ToonEngine::playSFX(int32 id, int32 volume) {
 }
 
 void ToonEngine::playSoundWrong() {
-	_audioManager->playSFX(rand() & 7, 128, true);
+	_audioManager->playSFX(randRange(0,7), 128, true);
 }
 
 void ToonEngine::getTextPosition(int32 characterId, int32 *retX, int32 *retY) {


Commit: 64bcb731bf0b28d9bf1391ac265ea47ba0a2f374
    https://github.com/scummvm/scummvm/commit/64bcb731bf0b28d9bf1391ac265ea47ba0a2f374
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:31:21-07:00

Commit Message:
LURE: Rename method random() -> getRandom()

Also get rid of a slight bias for 0 in the random numbers (it was
selected twice as often as any other number).

Changed paths:
    engines/lure/res.h
    engines/lure/scripts.cpp



diff --git a/engines/lure/res.h b/engines/lure/res.h
index f5c8711..a0a908f 100644
--- a/engines/lure/res.h
+++ b/engines/lure/res.h
@@ -114,7 +114,7 @@ public:
 	MemoryBlock *messagesData() { return _messagesData; }
 	uint16 getHotspotScript(uint16 index);
 	HotspotList &activeHotspots() { return _activeHotspots; }
-	uint16 random() { return _rnd.getRandomNumber(65536) & 0xffff; }
+	uint16 getRandom() { return _rnd.getRandomNumber(0xffff); }
 	HotspotData *getHotspot(uint16 hotspotId);
 	Hotspot *getActiveHotspot(uint16 hotspotId);
 	HotspotOverrideData *getHotspotOverride(uint16 hotspotId);
diff --git a/engines/lure/scripts.cpp b/engines/lure/scripts.cpp
index 7cd8be4..22656dd 100644
--- a/engines/lure/scripts.cpp
+++ b/engines/lure/scripts.cpp
@@ -1127,7 +1127,7 @@ uint16 Script::execute(uint16 startOffset) {
 			break;
 
 		case S_OPCODE_RANDOM:
-			param = r.random() >> 8; // make number between 0 to 255
+			param = r.getRandom() >> 8; // make number between 0 to 255
 			break;
 
 		case S_OPCODE_END:


Commit: a03ed0a3f7643417bbc169301a4fdd23043f3134
    https://github.com/scummvm/scummvm/commit/a03ed0a3f7643417bbc169301a4fdd23043f3134
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:57:46-07:00

Commit Message:
AUDIO: Fix typo

Changed paths:
    audio/softsynth/mt32/partial.cpp
    audio/softsynth/mt32/synth.cpp
    audio/softsynth/mt32/tables.cpp



diff --git a/audio/softsynth/mt32/partial.cpp b/audio/softsynth/mt32/partial.cpp
index 5ba9ef6..d06634d 100644
--- a/audio/softsynth/mt32/partial.cpp
+++ b/audio/softsynth/mt32/partial.cpp
@@ -28,7 +28,7 @@
 #if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
 // Older versions of Mac OS X didn't supply a powf function, so using it
 // will cause a binary incompatibility when trying to run a binary built
-// on a newer OS X release on an olderr one. And Solaris 8 doesn't provide
+// on a newer OS X release on an older one. And Solaris 8 doesn't provide
 // powf, floorf, fabsf etc. at all.
 // Cross-compiled MinGW32 toolchains suffer from a cross-compile bug in
 // libstdc++. math/stubs.o should be empty, but it comes with a symbol for
diff --git a/audio/softsynth/mt32/synth.cpp b/audio/softsynth/mt32/synth.cpp
index 112527c..5e74b26 100644
--- a/audio/softsynth/mt32/synth.cpp
+++ b/audio/softsynth/mt32/synth.cpp
@@ -34,7 +34,7 @@
 #if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
 // Older versions of Mac OS X didn't supply a powf function, so using it
 // will cause a binary incompatibility when trying to run a binary built
-// on a newer OS X release on an olderr one. And Solaris 8 doesn't provide
+// on a newer OS X release on an older one. And Solaris 8 doesn't provide
 // powf, floorf, fabsf etc. at all.
 // Cross-compiled MinGW32 toolchains suffer from a cross-compile bug in
 // libstdc++. math/stubs.o should be empty, but it comes with a symbol for
diff --git a/audio/softsynth/mt32/tables.cpp b/audio/softsynth/mt32/tables.cpp
index eba4d2a..4bb6a06 100644
--- a/audio/softsynth/mt32/tables.cpp
+++ b/audio/softsynth/mt32/tables.cpp
@@ -28,7 +28,7 @@
 #if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
 // Older versions of Mac OS X didn't supply a powf function, so using it
 // will cause a binary incompatibility when trying to run a binary built
-// on a newer OS X release on an olderr one. And Solaris 8 doesn't provide
+// on a newer OS X release on an older one. And Solaris 8 doesn't provide
 // powf, floorf, fabsf etc. at all.
 // Cross-compiled MinGW32 toolchains suffer from a cross-compile bug in
 // libstdc++. math/stubs.o should be empty, but it comes with a symbol for


Commit: 9b2ef340dceebc3db36519051e45af0fd9477850
    https://github.com/scummvm/scummvm/commit/9b2ef340dceebc3db36519051e45af0fd9477850
Author: Max Horn (max at quendi.de)
Date: 2011-05-17T03:58:34-07:00

Commit Message:
COMMON: Forbid use of some more symbols

Changed paths:
    audio/softsynth/mt32/tables.cpp
    common/forbidden.h



diff --git a/audio/softsynth/mt32/tables.cpp b/audio/softsynth/mt32/tables.cpp
index 4bb6a06..25ee043 100644
--- a/audio/softsynth/mt32/tables.cpp
+++ b/audio/softsynth/mt32/tables.cpp
@@ -19,6 +19,10 @@
  * IN THE SOFTWARE.
  */
 
+
+// FIXME: Avoid using rand
+#define FORBIDDEN_SYMBOL_EXCEPTION_rand
+
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
diff --git a/common/forbidden.h b/common/forbidden.h
index 95ecb7c..d769ff3 100644
--- a/common/forbidden.h
+++ b/common/forbidden.h
@@ -244,6 +244,43 @@
 #define setvbuf(a,b,c,d)	FORBIDDEN_SYMBOL_REPLACEMENT
 #endif
 
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_tmpfile
+#undef tmpfile
+#define tmpfile()	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_tmpnam
+#undef tmpnam
+#define tmpnam(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_tempnam
+#undef tempnam
+#define tempnam(a,b)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_rand
+#undef rand
+#define rand()	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_srand
+#undef srand
+#define srand(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_random
+#undef random
+#define random()	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_srandom
+#undef srandom
+#define srandom(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
 /*
  * We also would like to disable the following symbols;
  * however, these are also frequently used in regular code,






More information about the Scummvm-git-logs mailing list