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

svn-id: r43715
This commit is contained in:
Johannes Schickel 2009-08-24 23:04:25 +00:00
parent e98c791106
commit ac5a6552ca
10 changed files with 20 additions and 27 deletions

View file

@ -40,7 +40,7 @@ const FighterRecord initialFighterList[3] = {
FightsManager *int_fights = NULL; FightsManager *int_fights = NULL;
FightsManager::FightsManager() { FightsManager::FightsManager() : _rnd(LureEngine::getReference().rnd()) {
int_fights = this; int_fights = this;
_fightData = NULL; _fightData = NULL;
_mouseFlags = 0; _mouseFlags = 0;

View file

@ -66,7 +66,7 @@ enum KeyStatus {KS_UP, KS_KEYDOWN_1, KS_KEYDOWN_2};
class FightsManager { class FightsManager {
private: private:
MemoryBlock *_fightData; MemoryBlock *_fightData;
Common::RandomSource _rnd; Common::RandomSource &_rnd;
uint8 _mouseFlags; uint8 _mouseFlags;
KeyStatus _keyDown; KeyStatus _keyDown;
FighterRecord _fighterList[3]; FighterRecord _fighterList[3];

View file

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

View file

@ -26,6 +26,7 @@
#include "common/config-manager.h" #include "common/config-manager.h"
#include "common/system.h" #include "common/system.h"
#include "common/savefile.h" #include "common/savefile.h"
#include "common/EventRecorder.h"
#include "lure/luredefs.h" #include "lure/luredefs.h"
#include "lure/surface.h" #include "lure/surface.h"
@ -39,6 +40,7 @@ namespace Lure {
static LureEngine *int_engine = NULL; static LureEngine *int_engine = NULL;
LureEngine::LureEngine(OSystem *system, const LureGameDescription *gameDesc): Engine(system), _gameDescription(gameDesc) { LureEngine::LureEngine(OSystem *system, const LureGameDescription *gameDesc): Engine(system), _gameDescription(gameDesc) {
g_eventRec.registerRandomSource(_rnd, "lure");
Common::addDebugChannel(kLureDebugScripts, "scripts", "Scripts debugging"); Common::addDebugChannel(kLureDebugScripts, "scripts", "Scripts debugging");
Common::addDebugChannel(kLureDebugAnimations, "animations", "Animations debugging"); Common::addDebugChannel(kLureDebugAnimations, "animations", "Animations debugging");

View file

@ -31,6 +31,7 @@
#include "sound/mixer.h" #include "sound/mixer.h"
#include "common/file.h" #include "common/file.h"
#include "common/savefile.h" #include "common/savefile.h"
#include "common/util.h"
#include "lure/disk.h" #include "lure/disk.h"
#include "lure/res.h" #include "lure/res.h"
@ -43,6 +44,8 @@
namespace Lure { namespace Lure {
#define RandomNumberGen LureEngine::getReference().rnd()
struct LureGameDescription; struct LureGameDescription;
class LureEngine : public Engine { class LureEngine : public Engine {
@ -59,6 +62,7 @@ private:
StringData *_strings; StringData *_strings;
Room *_room; Room *_room;
FightsManager *_fights; FightsManager *_fights;
Common::RandomSource _rnd;
const char *generateSaveName(int slotNumber); const char *generateSaveName(int slotNumber);
@ -86,6 +90,7 @@ public:
Disk &disk() { return *_disk; } Disk &disk() { return *_disk; }
Common::RandomSource &rnd() { return _rnd; }
int gameToLoad() { return _gameToLoad; } int gameToLoad() { return _gameToLoad; }
bool loadGame(uint8 slotNumber); bool loadGame(uint8 slotNumber);
bool saveGame(uint8 slotNumber, Common::String &caption); bool saveGame(uint8 slotNumber, Common::String &caption);

View file

@ -30,7 +30,6 @@
#include "lure/lure.h" #include "lure/lure.h"
#include "common/endian.h" #include "common/endian.h"
#include "common/events.h" #include "common/events.h"
#include "common/EventRecorder.h"
namespace Lure { namespace Lure {
@ -42,8 +41,7 @@ Resources &Resources::getReference() {
return *int_resources; return *int_resources;
} }
Resources::Resources() { Resources::Resources() : _rnd(LureEngine::getReference().rnd()) {
g_eventRec.registerRandomSource(_rnd, "lureResources");
int_resources = this; int_resources = this;
reloadData(); reloadData();

View file

@ -51,7 +51,7 @@ struct TalkDialogDetails {
class Resources { class Resources {
private: private:
Common::RandomSource _rnd; Common::RandomSource &_rnd;
Palette *_paletteSubset; Palette *_paletteSubset;
MemoryBlock *_cursors; MemoryBlock *_cursors;
RoomDataList _roomData; RoomDataList _roomData;

View file

@ -739,9 +739,7 @@ void Script::addActions(uint16 hotspotId, uint16 actions, uint16 v3) {
// Generates a random number and stores it in the general field // Generates a random number and stores it in the general field
void Script::randomToGeneral(uint16 maxVal, uint16 minVal, uint16 v3) { void Script::randomToGeneral(uint16 maxVal, uint16 minVal, uint16 v3) {
Common::RandomSource rnd; uint16 v = minVal + LureEngine::getReference().rnd().getRandomNumber(maxVal - minVal);
g_eventRec.registerRandomSource(rnd, "lureScripts");
uint16 v = minVal + rnd.getRandomNumber(maxVal - minVal);
Resources::getReference().fieldList().setField(GENERAL, v); Resources::getReference().fieldList().setField(GENERAL, v);
} }

View file

@ -1299,7 +1299,6 @@ CopyProtectionDialog::CopyProtectionDialog() {
bool CopyProtectionDialog::show() { bool CopyProtectionDialog::show() {
Screen &screen = Screen::getReference(); Screen &screen = Screen::getReference();
Events &events = Events::getReference(); Events &events = Events::getReference();
Common::RandomSource rnd;
LureEngine &engine = LureEngine::getReference(); LureEngine &engine = LureEngine::getReference();
screen.setPaletteEmpty(); screen.setPaletteEmpty();
@ -1403,8 +1402,9 @@ bool CopyProtectionDialog::show() {
void CopyProtectionDialog::chooseCharacters() { void CopyProtectionDialog::chooseCharacters() {
Screen &screen = Screen::getReference(); Screen &screen = Screen::getReference();
int char1 = _rnd.getRandomNumber(19); Common::RandomSource &rnd = LureEngine::getReference().rnd();
int char2 = _rnd.getRandomNumber(19); int char1 = rnd.getRandomNumber(19);
int char2 = rnd.getRandomNumber(19);
HotspotsList::iterator curHotspot = _hotspots.begin(); HotspotsList::iterator curHotspot = _hotspots.begin();
(curHotspot->get())->setFrameNumber(char1); (curHotspot->get())->setFrameNumber(char1);

View file

@ -140,7 +140,6 @@ public:
class CopyProtectionDialog { class CopyProtectionDialog {
private: private:
Common::RandomSource _rnd;
typedef Common::List<Common::SharedPtr<Hotspot> > HotspotsList; typedef Common::List<Common::SharedPtr<Hotspot> > HotspotsList;
HotspotsList _hotspots; HotspotsList _hotspots;
int _charIndex; int _charIndex;