mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-05 17:20:30 +00:00
ASYLUM: Moved the gameflags from SharedResources to the AsylumEngine. Also removed the OSystem member from the SharedResources (slowly phasing out the last singleton)
git-svn-id: http://asylumengine.googlecode.com/svn/trunk@351 0bfb4aae-4ea4-11de-8d8d-752d95cf3e3c
This commit is contained in:
parent
4c01ffb9e3
commit
badb49ed6d
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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--;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -51,9 +51,6 @@ class Sound;
|
||||
class SharedResources: public Common::Singleton<SharedResources> {
|
||||
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<SingletonBaseType>;
|
||||
SharedResources();
|
||||
~SharedResources();
|
||||
|
||||
OSystem *_system;
|
||||
Video *_video;
|
||||
Screen *_screen;
|
||||
Sound *_sound;
|
||||
Scene *_scene;
|
||||
|
||||
int _gameFlags[1512];
|
||||
|
||||
}; // end of class SharedResources
|
||||
|
||||
// Angle Tables used by getAngle()
|
||||
|
Loading…
Reference in New Issue
Block a user