diff --git a/engines/asylum/actionlist.cpp b/engines/asylum/actionlist.cpp index d57adcbff6c..b6fc86dede9 100644 --- a/engines/asylum/actionlist.cpp +++ b/engines/asylum/actionlist.cpp @@ -303,7 +303,7 @@ int ActionList::process() { // XXX // gameFlag 183 is the same as the // processing flag, but is not being used - Shared.clearGameFlag(183); + _scene->vm()->clearGameFlag(183); } } @@ -359,7 +359,7 @@ int kSetGameFlag(ActionCommand *cmd, Scene *scn) { int flagNum = cmd->param1; if (flagNum >= 0) - Shared.setGameFlag(flagNum); + scn->vm()->setGameFlag(flagNum); return 0; } @@ -368,7 +368,7 @@ int kClearGameFlag(ActionCommand *cmd, Scene *scn) { int flagNum = cmd->param1; if (flagNum >= 0) - Shared.clearGameFlag(flagNum); + scn->vm()->clearGameFlag(flagNum); return 0; } @@ -377,7 +377,7 @@ int kToggleGameFlag(ActionCommand *cmd, Scene *scn) { int flagNum = cmd->param1; if (flagNum >= 0) - Shared.toggleGameFlag(flagNum); + scn->vm()->toggleGameFlag(flagNum); return 0; } @@ -386,9 +386,9 @@ int kJumpIfGameFlag(ActionCommand *cmd, Scene *scn) { int flagNum = cmd->param1; if (flagNum) { - bool doJump = Shared.isGameFlagSet(flagNum); + bool doJump = scn->vm()->isGameFlagSet(flagNum); if (cmd->param2) - doJump = Shared.isGameFlagNotSet(flagNum); + doJump = scn->vm()->isGameFlagNotSet(flagNum); if (doJump) scn->actions()->currentLine = cmd->param3; } diff --git a/engines/asylum/asylum.cpp b/engines/asylum/asylum.cpp index 1236651f386..fd31c2751d0 100644 --- a/engines/asylum/asylum.cpp +++ b/engines/asylum/asylum.cpp @@ -53,6 +53,8 @@ AsylumEngine::AsylumEngine(OSystem *system, Common::Language language) Common::File::addDefaultDirectory(_gameDataDir.getChild("Music")); g_eventRec.registerRandomSource(_rnd, "asylum"); + + memset(_gameFlags, 0, 1512); } AsylumEngine::~AsylumEngine() { @@ -65,6 +67,8 @@ AsylumEngine::~AsylumEngine() { delete _sound; delete _screen; delete _encounter; + + free(_gameFlags); } Common::Error AsylumEngine::run() { @@ -86,7 +90,6 @@ Common::Error AsylumEngine::init() { _mainMenu = 0; _scene = 0; - Shared.setOSystem(_system); Shared.setScreen(_screen); Shared.setSound(_sound); Shared.setVideo(_video); @@ -103,7 +106,7 @@ Common::Error AsylumEngine::go() { // TODO: if savegame exists on folder, than start NewGame() // Set up the game's main scene - _scene = new Scene(5); + _scene = new Scene(5, this); Shared.setScene(_scene); // XXX This is just here for testing purposes. It is also defined @@ -130,8 +133,8 @@ Common::Error AsylumEngine::go() { //playIntro(); // Enter first scene - Shared.setGameFlag(4); - Shared.setGameFlag(12); + setGameFlag(4); + setGameFlag(12); _scene->enterScene(); while (!shouldQuit()) { @@ -160,8 +163,8 @@ void AsylumEngine::playIntro() { _screen->clearScreen(); - Shared.setGameFlag(4); - Shared.setGameFlag(12); + setGameFlag(4); + setGameFlag(12); ResourcePack *introRes = new ResourcePack(18); @@ -282,7 +285,7 @@ void AsylumEngine::processDelayedEvents() { if (_scene) delete _scene; - _scene = new Scene(sceneIdx); + _scene = new Scene(sceneIdx, this); Shared.setScene(_scene); _scene->enterScene(); @@ -291,4 +294,25 @@ void AsylumEngine::processDelayedEvents() { } } +void AsylumEngine::setGameFlag(int flag) { + _gameFlags[flag / 32] |= 1 << flag % -32; +} + +void AsylumEngine::clearGameFlag(int flag) { + _gameFlags[flag / 32] &= ~(1 << flag % -32); +} + +void AsylumEngine::toggleGameFlag(int flag) { + _gameFlags[flag / 32] ^= 1 << flag % -32; +} + +bool AsylumEngine::isGameFlagSet(int flag) { + return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 != 0; +} + +bool AsylumEngine::isGameFlagNotSet(int flag) { + return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 == 0; +} + + } // namespace Asylum diff --git a/engines/asylum/asylum.h b/engines/asylum/asylum.h index fbac27601b4..3f49a6d0d41 100644 --- a/engines/asylum/asylum.h +++ b/engines/asylum/asylum.h @@ -72,6 +72,12 @@ public: virtual Common::Error run(); virtual bool hasFeature(EngineFeature f) const; + void setGameFlag(int flag); + void clearGameFlag(int flag); + void toggleGameFlag(int flag); + bool isGameFlagSet(int flag); + bool isGameFlagNotSet(int flag); + private: void checkForEvent(bool doUpdate); void waitForTimer(int msec_delay); @@ -92,6 +98,8 @@ private: Video *_video; Encounter *_encounter; + int _gameFlags[1512]; + friend class Console; }; diff --git a/engines/asylum/barrier.cpp b/engines/asylum/barrier.cpp index 867196f66d0..c697a6cf80e 100644 --- a/engines/asylum/barrier.cpp +++ b/engines/asylum/barrier.cpp @@ -44,9 +44,9 @@ bool Barrier::visible() { uint32 flag = gameFlags[f]; if (flag <= 0) - isSet = Shared.isGameFlagNotSet(flag); // -flag + isSet = Shared.getScene()->vm()->isGameFlagNotSet(flag); // -flag else - isSet = Shared.isGameFlagSet(flag); + isSet = Shared.getScene()->vm()->isGameFlagSet(flag); if(!isSet) return false; diff --git a/engines/asylum/console.cpp b/engines/asylum/console.cpp index 19244901c2e..4a2113e3740 100644 --- a/engines/asylum/console.cpp +++ b/engines/asylum/console.cpp @@ -93,7 +93,7 @@ void Console::printActionAreaStats(ActionArea *a) { bool Console::cmdShowFlags(int argc, const char **argv) { for (int i = 0; i < 1512; i++) { - if (Shared.isGameFlagSet(i)) { + if (_vm->isGameFlagSet(i)) { DebugPrintf("Game Flag %d is Active\n", i); } } @@ -106,8 +106,8 @@ bool Console::cmdToggleFlag(int argc, const char **argv) { DebugPrintf("Enter a value between 0 and 1512\n"); return true; } - Shared.toggleGameFlag(atoi(argv[1])); - DebugPrintf("Flag %d == %d\n", atoi(argv[1]), Shared.isGameFlagSet(atoi(argv[1]))); + _vm->toggleGameFlag(atoi(argv[1])); + DebugPrintf("Flag %d == %d\n", atoi(argv[1]), _vm->isGameFlagSet(atoi(argv[1]))); return true; } diff --git a/engines/asylum/scene.cpp b/engines/asylum/scene.cpp index 247572dfcfe..52aa0f07bb1 100644 --- a/engines/asylum/scene.cpp +++ b/engines/asylum/scene.cpp @@ -35,7 +35,7 @@ namespace Asylum { int g_debugPolygons; int g_debugBarriers; -Scene::Scene(uint8 sceneIdx) { +Scene::Scene(uint8 sceneIdx, AsylumEngine *vm): _vm(vm) { _sceneIdx = sceneIdx; char filename[10]; @@ -228,39 +228,39 @@ int Scene::updateScene() { WorldStats *worldStats = _ws; // Mouse - startTick = Shared.getMillis(); + startTick = _vm->_system->getMillis(); updateMouse(); - debugC(kDebugLevelScene, "UpdateMouse Time: %d", Shared.getMillis() - startTick); + debugC(kDebugLevelScene, "UpdateMouse Time: %d", _vm->_system->getMillis() - startTick); // Actors - startTick = Shared.getMillis(); + startTick = _vm->_system->getMillis(); for (uint32 a = 0; a < worldStats->numActors; a++) updateActor(a); - debugC(kDebugLevelScene, "UpdateActors Time: %d", Shared.getMillis() - startTick); + debugC(kDebugLevelScene, "UpdateActors Time: %d", _vm->_system->getMillis() - startTick); // Barriers - startTick = Shared.getMillis(); + startTick = _vm->_system->getMillis(); updateBarriers(worldStats); - debugC(kDebugLevelScene, "UpdateBarriers Time: %d", Shared.getMillis() - startTick); + debugC(kDebugLevelScene, "UpdateBarriers Time: %d", _vm->_system->getMillis() - startTick); // Ambient Sounds - startTick = Shared.getMillis(); + startTick = _vm->_system->getMillis(); updateAmbientSounds(); - debugC(kDebugLevelScene, "UpdateAmbientSounds Time: %d", Shared.getMillis() - startTick); + debugC(kDebugLevelScene, "UpdateAmbientSounds Time: %d", _vm->_system->getMillis() - startTick); // Music - startTick = Shared.getMillis(); + startTick = _vm->_system->getMillis(); updateMusic(); - debugC(kDebugLevelScene, "UpdateMusic Time: %d", Shared.getMillis() - startTick); + debugC(kDebugLevelScene, "UpdateMusic Time: %d", _vm->_system->getMillis() - startTick); // Adjust Screen - //startTick = Shared.getMillis(); + //startTick = _vm->_system->getMillis(); // FIXME // Commented out the (incomplete) update screen code because once the // actor's x1/y1 values are properly set, the temp code causes a crash // Have to finish implementing the method I guess :P //updateAdjustScreen(); - //debugC(kDebugLevelScene, "AdjustScreenStart Time: %d", Shared.getMillis() - startTick); + //debugC(kDebugLevelScene, "AdjustScreenStart Time: %d", _vm->_system->getMillis() - startTick); if(_actions->process()) return 1; @@ -447,11 +447,11 @@ void Scene::updateActor(uint32 actorIdx) { uint32 frameNum = actor->frameNum + 1; actor->frameNum = frameNum % actor->frameCount; - if (Shared.getMillis() - actor->tickValue1 > 300) { + if (_vm->_system->getMillis() - actor->tickValue1 > 300) { if (rand() % 100 < 50) { // TODO: check sound playing } - actor->tickValue1 = Shared.getMillis(); + actor->tickValue1 = _vm->_system->getMillis(); } } break; @@ -517,9 +517,9 @@ void Scene::updateBarriers(WorldStats *worldStats) { if (barrier->visible()) { uint32 flag = barrier->flags; if (flag & 0x20) { - if (barrier->field_B4 && (Shared.getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { + if (barrier->field_B4 && (_vm->_system->getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { barrier->frameIdx = (barrier->frameIdx + 1) % barrier->frameCount; - barrier->tickCount = Shared.getMillis(); + barrier->tickCount = _vm->_system->getMillis(); canPlaySound = true; } } else if (flag & 0x10) { @@ -527,7 +527,7 @@ void Scene::updateBarriers(WorldStats *worldStats) { char equalZero = frameIdx == 0; char lessZero = frameIdx < 0; if (!frameIdx) { - if (Shared.getMillis() - barrier->tickCount >= 1000 * barrier->tickCount2) { + if (_vm->_system->getMillis() - barrier->tickCount >= 1000 * barrier->tickCount2) { if (rand() % barrier->field_C0 == 1) { if (barrier->field_68C[0]) { // TODO: fix this, and find a better way to get frame count @@ -540,7 +540,7 @@ void Scene::updateBarriers(WorldStats *worldStats) { } barrier->frameIdx++; } - barrier->tickCount = Shared.getMillis(); + barrier->tickCount = _vm->_system->getMillis(); canPlaySound = true; } frameIdx = barrier->frameIdx; @@ -550,15 +550,15 @@ void Scene::updateBarriers(WorldStats *worldStats) { if (!(lessZero ^ 0 | equalZero)) { // FIXME: we shouldn't increment field_B4 (check why this value came zero sometimes) - if (barrier->field_B4 && (Shared.getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { + if (barrier->field_B4 && (_vm->_system->getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { barrier->frameIdx = (barrier->frameIdx + 1) % barrier->frameCount; - barrier->tickCount = Shared.getMillis(); + barrier->tickCount = _vm->_system->getMillis(); canPlaySound = true; } } } else if (flag & 8) { // FIXME: we shouldn't increment field_B4 (check why this value came zero sometimes) - if (barrier->field_B4 && (Shared.getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { + if (barrier->field_B4 && (_vm->_system->getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { uint32 frameIdx = barrier->frameIdx + 1; if (frameIdx < barrier->frameCount - 1) { if (barrier->field_688 == 1) { @@ -573,30 +573,30 @@ void Scene::updateBarriers(WorldStats *worldStats) { barrier->frameIdx = frameIdx; } } else if ((flag & 0xFF) & 8) { // check this - if (Shared.getMillis() - barrier->tickCount >= 1000 * barrier->tickCount2) { + if (_vm->_system->getMillis() - barrier->tickCount >= 1000 * barrier->tickCount2) { if (rand() % barrier->field_C0 == 1) { // TODO: THIS ISNT WORKING barrier->frameIdx = (barrier->frameIdx + 1) % barrier->frameCount; - barrier->tickCount = Shared.getMillis(); + barrier->tickCount = _vm->_system->getMillis(); canPlaySound = true; } } } else if (!((flag & 0xFFFF) & 6)) { // FIXME: we shouldn't increment field_B4 (check why this value came zero sometimes) - if (barrier->field_B4 && (Shared.getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4) && (flag & 0x10000)) { + if (barrier->field_B4 && (_vm->_system->getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4) && (flag & 0x10000)) { uint32 frameIdx = barrier->frameIdx - 1; if (frameIdx <= 0) { barrier->flags &= 0xFFFEFFFF; if (barrier->field_688 == 1) { // TODO: reset global x, y positions } - barrier->tickCount = Shared.getMillis(); + barrier->tickCount = _vm->_system->getMillis(); canPlaySound = true; } if (barrier->field_688 == 1) { // TODO: get global x, y positions } barrier->frameIdx = frameIdx; - } else if (barrier->field_B4 && (Shared.getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { + } else if (barrier->field_B4 && (_vm->_system->getMillis() - barrier->tickCount >= 0x3E8 / barrier->field_B4)) { if ((flag & 0xFF) & 2) { if (barrier->frameIdx == barrier->frameCount - 1) { barrier->frameIdx--; diff --git a/engines/asylum/scene.h b/engines/asylum/scene.h index 14baf713c22..63cd2d55dda 100644 --- a/engines/asylum/scene.h +++ b/engines/asylum/scene.h @@ -52,7 +52,7 @@ struct BarrierItem; class Scene { public: - Scene(uint8 sceneIdx); + Scene(uint8 sceneIdx, AsylumEngine *vm); ~Scene(); void handleEvent(Common::Event *event, bool doUpdate); @@ -75,15 +75,17 @@ public: void setBlowUpPuzzle(BlowUpPuzzle* puzzle) { _blowUp = puzzle; } void setScenePosition(int x, int y); - WorldStats* worldstats() { return _ws; } - Polygons* polygons() { return _polygons; } - ActionList* actions() { return _actions; } + AsylumEngine* vm() { return _vm; } + WorldStats* worldstats() { return _ws; } + Polygons* polygons() { return _polygons; } + ActionList* actions() { return _actions; } private: - uint8 _sceneIdx; - WorldStats *_ws; - Polygons *_polygons; - ActionList *_actions; + AsylumEngine *_vm; + uint8 _sceneIdx; + WorldStats *_ws; + Polygons *_polygons; + ActionList *_actions; Cursor *_cursor; ResourcePack *_resPack; diff --git a/engines/asylum/shared.cpp b/engines/asylum/shared.cpp index 10512d1e412..7761b2a85f9 100644 --- a/engines/asylum/shared.cpp +++ b/engines/asylum/shared.cpp @@ -37,7 +37,7 @@ SharedResources::SharedResources() { if (!g_initialized) { g_initialized = true; } - memset(_gameFlags, 0, 1512); + } SharedResources::~SharedResources() { @@ -130,24 +130,4 @@ int SharedResources::getAngle(int x1, int y1, int x2, int y2) { return result; } -void SharedResources::setGameFlag(int flag) { - _gameFlags[flag / 32] |= 1 << flag % -32; -} - -void SharedResources::clearGameFlag(int flag) { - _gameFlags[flag / 32] &= ~(1 << flag % -32); -} - -void SharedResources::toggleGameFlag(int flag) { - _gameFlags[flag / 32] ^= 1 << flag % -32; -} - -bool SharedResources::isGameFlagSet(int flag) { - return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 != 0; -} - -bool SharedResources::isGameFlagNotSet(int flag) { - return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 == 0; -} - } // end of namespace Asylum diff --git a/engines/asylum/shared.h b/engines/asylum/shared.h index f4dbf5f7024..d7f2dd02212 100644 --- a/engines/asylum/shared.h +++ b/engines/asylum/shared.h @@ -51,9 +51,6 @@ class Sound; class SharedResources: public Common::Singleton { public: - void setOSystem(OSystem* system) { _system = system; } - uint32 getMillis() { return _system->getMillis(); } - void setVideo(Video* video) { _video = video; } Video* getVideo() { return _video; } @@ -68,25 +65,16 @@ public: int getAngle(int x1, int y1, int x2, int y2); - void setGameFlag(int flag); - void clearGameFlag(int flag); - void toggleGameFlag(int flag); - bool isGameFlagSet(int flag); - bool isGameFlagNotSet(int flag); - private: friend class Common::Singleton; SharedResources(); ~SharedResources(); - OSystem *_system; Video *_video; Screen *_screen; Sound *_sound; Scene *_scene; - int _gameFlags[1512]; - }; // end of class SharedResources // Angle Tables used by getAngle()