[Scummvm-cvs-logs] SF.net SVN: scummvm:[43715] scummvm/trunk/engines/lure

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Aug 25 01:04:25 CEST 2009


Revision: 43715
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43715&view=rev
Author:   lordhoto
Date:     2009-08-24 23:04:25 +0000 (Mon, 24 Aug 2009)

Log Message:
-----------
Switched LURE to use a single central RandomSource instance, instead of (sometimes) creating a new RandomSource every function call.

Modified Paths:
--------------
    scummvm/trunk/engines/lure/fights.cpp
    scummvm/trunk/engines/lure/fights.h
    scummvm/trunk/engines/lure/hotspots.cpp
    scummvm/trunk/engines/lure/lure.cpp
    scummvm/trunk/engines/lure/lure.h
    scummvm/trunk/engines/lure/res.cpp
    scummvm/trunk/engines/lure/res.h
    scummvm/trunk/engines/lure/scripts.cpp
    scummvm/trunk/engines/lure/surface.cpp
    scummvm/trunk/engines/lure/surface.h

Modified: scummvm/trunk/engines/lure/fights.cpp
===================================================================
--- scummvm/trunk/engines/lure/fights.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/fights.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -40,7 +40,7 @@
 
 FightsManager *int_fights = NULL;
 
-FightsManager::FightsManager() {
+FightsManager::FightsManager() : _rnd(LureEngine::getReference().rnd()) {
 	int_fights = this;
 	_fightData = NULL;
 	_mouseFlags = 0;

Modified: scummvm/trunk/engines/lure/fights.h
===================================================================
--- scummvm/trunk/engines/lure/fights.h	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/fights.h	2009-08-24 23:04:25 UTC (rev 43715)
@@ -66,7 +66,7 @@
 class FightsManager {
 private:
 	MemoryBlock *_fightData;
-	Common::RandomSource _rnd;
+	Common::RandomSource &_rnd;
 	uint8 _mouseFlags;
 	KeyStatus _keyDown;
 	FighterRecord _fighterList[3];

Modified: scummvm/trunk/engines/lure/hotspots.cpp
===================================================================
--- scummvm/trunk/engines/lure/hotspots.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/hotspots.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -38,7 +38,6 @@
 #include "lure/sound.h"
 #include "lure/lure.h"
 #include "common/endian.h"
-#include "common/EventRecorder.h"
 
 namespace Lure {
 
@@ -598,11 +597,9 @@
 	Resources &res = Resources::getReference();
 	RoomData *roomData = res.getRoom(roomNumber());
 	Common::Rect &rect = roomData->walkBounds;
-	Common::RandomSource rnd;
+	Common::RandomSource &rnd = LureEngine::getReference().rnd();
 	int16 xp, yp;
 
-	g_eventRec.registerRandomSource(rnd, "lureHotspots");
-
 	if (currentActions().isEmpty())
 		currentActions().addFront(START_WALKING, roomNumber());
 	else
@@ -3145,10 +3142,9 @@
 		return;
 	}
 
-	Common::RandomSource rnd;
+	Common::RandomSource &rnd = LureEngine::getReference().rnd();
 	RandomActionType actionType;
 	uint16 scheduleId;
-	g_eventRec.registerRandomSource(rnd, "lureHotspots");
 
 	int actionIndex = rnd.getRandomNumber(set->numActions() - 1);
 	set->getEntry(actionIndex, actionType, scheduleId);
@@ -3336,10 +3332,8 @@
 
 void HotspotTickHandlers::prisonerAnimHandler(Hotspot &h) {
 	ValueTableData &fields = Resources::getReference().fieldList();
-	Common::RandomSource rnd;
+	Common::RandomSource &rnd = LureEngine::getReference().rnd();
 
-	g_eventRec.registerRandomSource(rnd, "lureHotspots");
-
 	h.handleTalkDialog();
 	if (h.frameCtr() > 0) {
 		h.setFrameCtr(h.frameCtr() - 1);
@@ -3380,8 +3374,7 @@
 
 	if (h.executeScript()) {
 		// Script is done - set new script to one of two alternates randomly
-		Common::RandomSource rnd;
-		g_eventRec.registerRandomSource(rnd, "lureHotspots");
+		Common::RandomSource &rnd = LureEngine::getReference().rnd();
 
 		h.setHotspotScript(rnd.getRandomNumber(100) >= 50 ? 0x54 : 0);
 		h.setFrameCtr(20 + rnd.getRandomNumber(63));
@@ -3678,11 +3671,9 @@
 	Resources &res = Resources::getReference();
 	Room &room = Room::getReference();
 	BarEntry &barEntry = res.barmanLists().getDetails(h.roomNumber());
-	Common::RandomSource rnd;
+	Common::RandomSource &rnd = LureEngine::getReference().rnd();
 	static bool ewanXOffset = false;
 
-	g_eventRec.registerRandomSource(rnd, "lureHotspots");
-
 	h.handleTalkDialog();
 	if (h.delayCtr() > 0) {
 		h.setDelayCtr(h.delayCtr() - 1);

Modified: scummvm/trunk/engines/lure/lure.cpp
===================================================================
--- scummvm/trunk/engines/lure/lure.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/lure.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -26,6 +26,7 @@
 #include "common/config-manager.h"
 #include "common/system.h"
 #include "common/savefile.h"
+#include "common/EventRecorder.h"
 
 #include "lure/luredefs.h"
 #include "lure/surface.h"
@@ -39,6 +40,7 @@
 static LureEngine *int_engine = NULL;
 
 LureEngine::LureEngine(OSystem *system, const LureGameDescription *gameDesc): Engine(system), _gameDescription(gameDesc) {
+	g_eventRec.registerRandomSource(_rnd, "lure");
 
 	Common::addDebugChannel(kLureDebugScripts, "scripts", "Scripts debugging");
 	Common::addDebugChannel(kLureDebugAnimations, "animations", "Animations debugging");

Modified: scummvm/trunk/engines/lure/lure.h
===================================================================
--- scummvm/trunk/engines/lure/lure.h	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/lure.h	2009-08-24 23:04:25 UTC (rev 43715)
@@ -31,6 +31,7 @@
 #include "sound/mixer.h"
 #include "common/file.h"
 #include "common/savefile.h"
+#include "common/util.h"
 
 #include "lure/disk.h"
 #include "lure/res.h"
@@ -43,6 +44,8 @@
 
 namespace Lure {
 
+#define RandomNumberGen LureEngine::getReference().rnd()
+
 struct LureGameDescription;
 
 class LureEngine : public Engine {
@@ -59,6 +62,7 @@
 	StringData *_strings;
 	Room *_room;
 	FightsManager *_fights;
+	Common::RandomSource _rnd;
 
 	const char *generateSaveName(int slotNumber);
 
@@ -86,6 +90,7 @@
 
 	Disk &disk() { return *_disk; }
 
+	Common::RandomSource &rnd() { return _rnd; }
 	int gameToLoad() { return _gameToLoad; }
 	bool loadGame(uint8 slotNumber);
 	bool saveGame(uint8 slotNumber, Common::String &caption);

Modified: scummvm/trunk/engines/lure/res.cpp
===================================================================
--- scummvm/trunk/engines/lure/res.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/res.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -30,7 +30,6 @@
 #include "lure/lure.h"
 #include "common/endian.h"
 #include "common/events.h"
-#include "common/EventRecorder.h"
 
 namespace Lure {
 
@@ -42,8 +41,7 @@
 	return *int_resources;
 }
 
-Resources::Resources() {
-	g_eventRec.registerRandomSource(_rnd, "lureResources");
+Resources::Resources() : _rnd(LureEngine::getReference().rnd()) {
 	int_resources = this;
 	reloadData();
 

Modified: scummvm/trunk/engines/lure/res.h
===================================================================
--- scummvm/trunk/engines/lure/res.h	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/res.h	2009-08-24 23:04:25 UTC (rev 43715)
@@ -51,7 +51,7 @@
 
 class Resources {
 private:
-	Common::RandomSource _rnd;
+	Common::RandomSource &_rnd;
 	Palette *_paletteSubset;
 	MemoryBlock *_cursors;
 	RoomDataList _roomData;

Modified: scummvm/trunk/engines/lure/scripts.cpp
===================================================================
--- scummvm/trunk/engines/lure/scripts.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/scripts.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -739,9 +739,7 @@
 // Generates a random number and stores it in the general field
 
 void Script::randomToGeneral(uint16 maxVal, uint16 minVal, uint16 v3) {
-	Common::RandomSource rnd;
-	g_eventRec.registerRandomSource(rnd, "lureScripts");
-	uint16 v = minVal + rnd.getRandomNumber(maxVal - minVal);
+	uint16 v = minVal + LureEngine::getReference().rnd().getRandomNumber(maxVal - minVal);
 	Resources::getReference().fieldList().setField(GENERAL, v);
 }
 

Modified: scummvm/trunk/engines/lure/surface.cpp
===================================================================
--- scummvm/trunk/engines/lure/surface.cpp	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/surface.cpp	2009-08-24 23:04:25 UTC (rev 43715)
@@ -1299,7 +1299,6 @@
 bool CopyProtectionDialog::show() {
 	Screen &screen = Screen::getReference();
 	Events &events = Events::getReference();
-	Common::RandomSource rnd;
 	LureEngine &engine = LureEngine::getReference();
 
 	screen.setPaletteEmpty();
@@ -1403,8 +1402,9 @@
 
 void CopyProtectionDialog::chooseCharacters() {
 	Screen &screen = Screen::getReference();
-	int char1 = _rnd.getRandomNumber(19);
-	int char2 = _rnd.getRandomNumber(19);
+	Common::RandomSource &rnd = LureEngine::getReference().rnd();
+	int char1 = rnd.getRandomNumber(19);
+	int char2 = rnd.getRandomNumber(19);
 
 	HotspotsList::iterator curHotspot = _hotspots.begin();
 	(curHotspot->get())->setFrameNumber(char1);

Modified: scummvm/trunk/engines/lure/surface.h
===================================================================
--- scummvm/trunk/engines/lure/surface.h	2009-08-24 22:41:56 UTC (rev 43714)
+++ scummvm/trunk/engines/lure/surface.h	2009-08-24 23:04:25 UTC (rev 43715)
@@ -140,7 +140,6 @@
 
 class CopyProtectionDialog {
 private:
-	Common::RandomSource _rnd;
 	typedef Common::List<Common::SharedPtr<Hotspot> > HotspotsList;
 	HotspotsList _hotspots;
 	int _charIndex;


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