diff --git a/engines/asylum/actor.cpp b/engines/asylum/actor.cpp index 38517a89de1..11af7556753 100644 --- a/engines/asylum/actor.cpp +++ b/engines/asylum/actor.cpp @@ -27,7 +27,7 @@ #include "asylum/actor.h" #include "asylum/screen.h" -#include "asylum/utilities.h" +#include "asylum/shared.h" namespace Asylum { @@ -39,10 +39,12 @@ MainActor::MainActor(uint8 *data) { dataPtr += 4; } - _resPack = 0; - _graphic = 0; - _actorX = _actorY = 0; - _currentAction = 0; + _resPack = 0; + _graphic = 0; + _actorX = 0; + _actorY = 0; + _currentAction = 0; + _currentWalkArea = 0; } MainActor::~MainActor() { @@ -103,10 +105,10 @@ GraphicFrame *MainActor::getFrame() { return frame; } -void MainActor::drawActorAt(Screen *screen, uint16 x, uint16 y) { +void MainActor::drawActorAt(uint16 x, uint16 y) { GraphicFrame *frame = getFrame(); - screen->copyRectToScreenWithTransparency( + Shared.getScreen()->copyRectToScreenWithTransparency( ((byte *)frame->surface.pixels), frame->surface.w, x, @@ -118,10 +120,10 @@ void MainActor::drawActorAt(Screen *screen, uint16 x, uint16 y) { _actorY = y; } -void MainActor::drawActor(Screen *screen) { +void MainActor::drawActor() { GraphicFrame *frame = getFrame(); - screen->copyToBackBufferWithTransparency( + Shared.getScreen()->copyToBackBufferWithTransparency( ((byte *)frame->surface.pixels), frame->surface.w, _actorX, @@ -130,7 +132,14 @@ void MainActor::drawActor(Screen *screen) { frame->surface.h ); } -void MainActor::walkTo(Screen *screen, uint16 x, uint16 y, PolyDefinitions *region) { +void MainActor::setWalkArea(ActionItem *target) { + if (_currentWalkArea != target) { + ScriptMan.setScriptIndex(target->actionListIdx1); + _currentWalkArea = target; + } +} + +void MainActor::walkTo(uint16 x, uint16 y) { // TODO: pathfinding! The character can walk literally anywhere int newAction = _currentAction; @@ -195,18 +204,47 @@ void MainActor::walkTo(Screen *screen, uint16 x, uint16 y, PolyDefinitions *regi rect.bottom = newY + 4; surface.frameRect(rect, 0x33); - screen->copyRectToScreen((byte*)surface.pixels, 5, newX, newY, 5, 5); + Shared.getScreen()->copyRectToScreen((byte*)surface.pixels, 5, newX, newY, 5, 5); surface.free(); + int availableAreas[5]; + int areaPtr = 0; + ActionItem *area; - if (Utils.pointInPoly(region, newX, newY)) { - _actorX = newX; - _actorY = newY; + // Check what valid walk region(s) is/are currently available + for (uint32 a = 0; a < Shared.getScene()->getResources()->getWorldStats()->numActions; a++) { + if (Shared.getScene()->getResources()->getWorldStats()->actions[a].actionType == 0) { + area = &Shared.getScene()->getResources()->getWorldStats()->actions[a]; + PolyDefinitions poly = Shared.getScene()->getResources()->getGamePolygons()->polygons[area->polyIdx]; + if (Shared.pointInPoly(&poly, _actorX, _actorY)) { + availableAreas[areaPtr] = a; + areaPtr++; + + if (areaPtr > 5) + error("More than 5 overlapping walk regions found. Increase buffer"); + } + } + } + + // Set the current walk region to the first available action area + // in the collection + setWalkArea(&Shared.getScene()->getResources()->getWorldStats()->actions[availableAreas[0]]); + + // Check that we can walk in the current direction within any of the available + // walkable regions + for (int i = 0; i < areaPtr; i++) { + area = &Shared.getScene()->getResources()->getWorldStats()->actions[availableAreas[i]]; + PolyDefinitions *region = &Shared.getScene()->getResources()->getGamePolygons()->polygons[area->polyIdx]; + if (Shared.pointInPoly(region, newX, newY)) { + _actorX = newX; + _actorY = newY; + break; + } } setAction(newAction); - drawActor(screen); + drawActor(); } } // end of namespace Asylum diff --git a/engines/asylum/actor.h b/engines/asylum/actor.h index cfb4e89ccf6..41b36f8dfc8 100644 --- a/engines/asylum/actor.h +++ b/engines/asylum/actor.h @@ -32,7 +32,7 @@ namespace Asylum { class Screen; -struct PolyDefinitions; +struct ActionItem; // TODO properly use this enum as opposed to just // using it for visual reference :P @@ -134,21 +134,24 @@ public: virtual ~MainActor(); void setResourcePack(ResourcePack *resPack) { _resPack = resPack; } + void setWalkArea(ActionItem *target); // depreciate void setAction(int action); void setActionByIndex(int index); - void drawActorAt(Screen *screen, uint16 x, uint16 y); - void drawActor(Screen *screen); - void walkTo(Screen *screen, uint16 x, uint16 y, PolyDefinitions *region); + void drawActorAt(uint16 x, uint16 y); + void drawActor(); + void walkTo(uint16 x, uint16 y); int getCurrentAction() { return _currentAction; } uint16 _actorX, _actorY; private: GraphicResource *_graphic; - ResourcePack *_resPack; - uint32 _resources[61]; - uint8 _currentFrame; - int _currentAction; + ResourcePack *_resPack; + uint32 _resources[61]; + uint8 _currentFrame; + int _currentAction; + + ActionItem *_currentWalkArea; GraphicFrame *getFrame(); diff --git a/engines/asylum/asylum.cpp b/engines/asylum/asylum.cpp index b42369e45cc..0e5e0badc96 100644 --- a/engines/asylum/asylum.cpp +++ b/engines/asylum/asylum.cpp @@ -31,6 +31,7 @@ #include "asylum/asylum.h" #include "asylum/respack.h" +#include "asylum/shared.h" namespace Asylum { @@ -84,6 +85,10 @@ Common::Error AsylumEngine::init() { _mainMenu = 0; _scene = 0; + Shared.setScreen(_screen); + Shared.setSound(_sound); + Shared.setVideo(_video); + return Common::kNoError; } @@ -102,19 +107,17 @@ Common::Error AsylumEngine::go() { //_video->playVideo(1, kSubtitlesOn); // Set up the game's main scene - _scene = new Scene(_screen, _sound, _video, 5); - _scene->setBlowUpPuzzle(new BlowUpPuzzleVCR(_scene)); // this will be done by a Script command + _scene = new Scene(5); + Shared.setScene(_scene); - // TODO Since the ScriptMan is a singleton, setScene assignments could - // probably be rolled into the Scene constructor :D - ScriptMan.setScene(_scene); + _scene->setBlowUpPuzzle(new BlowUpPuzzleVCR()); // this will be done by a Script command // TODO This can probably also be rolled into the scene constructor. // Investigate if this will fuck up the execution sequence though :P ScriptMan.setScript(_scene->getDefaultActionList()); // Set up main menu - _mainMenu = new MainMenu(_screen, _sound, _scene); + _mainMenu = new MainMenu(); // XXX Testing @@ -228,11 +231,9 @@ void AsylumEngine::processDelayedEvents() { if (_scene) delete _scene; - _scene = new Scene(_screen, _sound, _video, sceneIdx); - - ScriptMan.setScene(_scene); - + _scene = new Scene(sceneIdx); _scene->enterScene(); + ScriptMan.setDelayedSceneIndex(-1); ScriptMan.setScript(_scene->getDefaultActionList()); } diff --git a/engines/asylum/blowuppuzzle.cpp b/engines/asylum/blowuppuzzle.cpp index d9b9a6f35b3..c9211587209 100644 --- a/engines/asylum/blowuppuzzle.cpp +++ b/engines/asylum/blowuppuzzle.cpp @@ -26,11 +26,11 @@ #include "asylum/blowuppuzzle.h" #include "asylum/respack.h" #include "asylum/graphics.h" +#include "asylum/shared.h" namespace Asylum { -BlowUpPuzzle::BlowUpPuzzle(Scene *scene) : - _scene(scene), _screen(scene->getScreen()), _sound(scene->getSound()), _video(scene->getVideo()) { +BlowUpPuzzle::BlowUpPuzzle() { } BlowUpPuzzle::~BlowUpPuzzle() { @@ -43,7 +43,7 @@ void BlowUpPuzzle::updateCursor() { if (_curMouseCursor == _cursorResource->getFrameCount() - 1) _cursorStep = -1; - _screen->setCursor(_cursorResource, _curMouseCursor); + Shared.getScreen()->setCursor(_cursorResource, _curMouseCursor); } void BlowUpPuzzle::addGraphicToQueue(uint32 redId, uint32 x, uint32 y, uint32 frameIdx, uint32 flags, uint32 priority) { @@ -66,9 +66,9 @@ void BlowUpPuzzle::updateGraphicsInQueue() { // sort by priority first graphicsSelectionSort(); for(uint i = 0; i < _queueItems.size(); i++) { - GraphicResource *jack = _scene->getGraphicResource(_queueItems[i].resId); + GraphicResource *jack = Shared.getScene()->getGraphicResource(_queueItems[i].resId); GraphicFrame *fra = jack->getFrame(_queueItems[i].frameIdx); - _screen->copyRectToScreenWithTransparency((byte *)fra->surface.pixels, fra->surface.w, _queueItems[i].x, _queueItems[i].y, fra->surface.w, fra->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)fra->surface.pixels, fra->surface.w, _queueItems[i].x, _queueItems[i].y, fra->surface.w, fra->surface.h); } } @@ -97,7 +97,7 @@ void BlowUpPuzzle::swapGraphicItem(int item1, int item2) { // BlowUp Puzzle VCR --------------------------------------------------------------------------------------------- -BlowUpPuzzleVCR::BlowUpPuzzleVCR(Scene *scene) : BlowUpPuzzle(scene) { +BlowUpPuzzleVCR::BlowUpPuzzleVCR() { _mouseX = 0; _mouseY = 0; _leftClickUp = false; @@ -106,8 +106,8 @@ BlowUpPuzzleVCR::BlowUpPuzzleVCR(Scene *scene) : BlowUpPuzzle(scene) { _curMouseCursor = 0; _cursorStep = 1; _active = false; - _cursorResource = _scene->getGraphicResource(_scene->getResources()->getWorldStats()->grResId[28]); - _bgResource = _scene->getGraphicResource(_scene->getResources()->getWorldStats()->grResId[0]); + _cursorResource = Shared.getScene()->getGraphicResource(Shared.getScene()->getResources()->getWorldStats()->grResId[28]); + _bgResource = Shared.getScene()->getGraphicResource(Shared.getScene()->getResources()->getWorldStats()->grResId[0]); _tvScreenAnimIdx = 0; _isAccomplished = false; @@ -124,20 +124,20 @@ BlowUpPuzzleVCR::~BlowUpPuzzleVCR() { void BlowUpPuzzleVCR::openBlowUp() { _active = true; - _scene->deactivate(); + Shared.getScene()->deactivate(); // FIXME: decomment this line when stopSfx works properly (it nows stop together SFX and Music - //_sound->stopSfx(); + //Shared.getSound()->stopSfx(); // Load the graphics palette - _screen->setPalette(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[29]); + Shared.getScreen()->setPalette(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[29]); // show blow up puzzle BG GraphicFrame *bg = _bgResource->getFrame(0); - _screen->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); + Shared.getScreen()->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); // Set mouse cursor - _screen->setCursor(_cursorResource, 0); - _screen->showCursor(); + Shared.getScreen()->setCursor(_cursorResource, 0); + Shared.getScreen()->showCursor(); _leftClickUp = false; _leftClickDown = false; @@ -147,7 +147,7 @@ void BlowUpPuzzleVCR::openBlowUp() { void BlowUpPuzzleVCR::closeBlowUp() { _active = false; - _scene->activate(); + Shared.getScene()->activate(); } void BlowUpPuzzleVCR::handleEvent(Common::Event *event, bool doUpdate) { @@ -187,7 +187,7 @@ void BlowUpPuzzleVCR::update() { _rightClickDown = false; closeBlowUp(); // TODO: stop sound fx grResId[47] (TV On sfx) - _scene->enterScene(); + Shared.getScene()->enterScene(); } if (_leftClickDown) { @@ -212,8 +212,8 @@ void BlowUpPuzzleVCR::update() { updateStopButton(); if(_buttonsState[kPower] == kON) { - addGraphicToQueue(_scene->getResources()->getWorldStats()->grResId[22], 0, 37, _tvScreenAnimIdx, 0, 1); - addGraphicToQueue(_scene->getResources()->getWorldStats()->grResId[23], 238, 22, _tvScreenAnimIdx++, 0, 1); + addGraphicToQueue(Shared.getScene()->getResources()->getWorldStats()->grResId[22], 0, 37, _tvScreenAnimIdx, 0, 1); + addGraphicToQueue(Shared.getScene()->getResources()->getWorldStats()->grResId[23], 238, 22, _tvScreenAnimIdx++, 0, 1); _tvScreenAnimIdx %= 6; } @@ -224,17 +224,17 @@ void BlowUpPuzzleVCR::update() { int barSize = 0; do { - _screen->drawWideScreen(barSize); + Shared.getScreen()->drawWideScreen(barSize); barSize += 4; } while(barSize < 84); // TODO: fade palette to grey - _video->playVideo(2, kSubtitlesOn); + Shared.getVideo()->playVideo(2, kSubtitlesOn); _isAccomplished = false; _active = false; - _scene->enterScene(); + Shared.getScene()->enterScene(); } else { updateGraphicsInQueue(); } @@ -248,7 +248,7 @@ GraphicQueueItem BlowUpPuzzleVCR::getGraphicJackItem(int resId) { jackY = 356; } - jackItemOnHand.resId = _scene->getResources()->getWorldStats()->grResId[resId]; + jackItemOnHand.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[resId]; jackItemOnHand.frameIdx = 0; jackItemOnHand.x = _mouseX - 114; jackItemOnHand.y = jackY - 14; @@ -264,7 +264,7 @@ GraphicQueueItem BlowUpPuzzleVCR::getGraphicShadowItem() { if(_mouseY < 356) { shadowY = 0; } - shadowItem.resId = _scene->getResources()->getWorldStats()->grResId[30]; + shadowItem.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[30]; shadowItem.frameIdx = 0; shadowItem.x = _mouseX - shadowY; shadowItem.y = 450; @@ -278,28 +278,28 @@ void BlowUpPuzzleVCR::updateJack(Jack jack, VCRDrawInfo onTable, VCRDrawInfo plu switch(_jacksState[jack]){ case kOnTable: - item.resId = _scene->getResources()->getWorldStats()->grResId[onTable.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[onTable.resId]; item.frameIdx = 0; item.x = onTable.x; item.y = onTable.y; item.priority = 3; break; case kPluggedOnRed: - item.resId = _scene->getResources()->getWorldStats()->grResId[pluggedOnRed.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[pluggedOnRed.resId]; item.frameIdx = 0; item.x = 329; item.y = 407; item.priority = 3; break; case kPluggedOnYellow: - item.resId = _scene->getResources()->getWorldStats()->grResId[pluggedOnYellow.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[pluggedOnYellow.resId]; item.frameIdx = 0; item.x = 402; item.y = 413; item.priority = 3; break; case kPluggedOnBlack: - item.resId = _scene->getResources()->getWorldStats()->grResId[pluggedOnBlack.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[pluggedOnBlack.resId]; item.frameIdx = 0; item.x = 477; item.y = 418; @@ -384,13 +384,13 @@ int BlowUpPuzzleVCR::setJackOnHole(int jackType, JackState plugged) { if(_jacksState[jackType-1] == kOnHand) { _jacksState[jackType-1] = plugged; _holesState[plugged-1] = jackType; // set jack on red - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[44]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[44]); } } else if(jackType == 0) { jackType = _holesState[plugged-1]; _jacksState[jackType-1] = kOnHand; _holesState[plugged-1] = 0; - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[43]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[43]); return 0; } return 1; @@ -401,7 +401,7 @@ void BlowUpPuzzleVCR::updateButton(Button button, VCRDrawInfo btON, VCRDrawInfo switch(_buttonsState[button]){ case kON: - item.resId = _scene->getResources()->getWorldStats()->grResId[btON.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[btON.resId]; item.frameIdx = 0; item.x = btON.x; item.y = btON.y; @@ -409,7 +409,7 @@ void BlowUpPuzzleVCR::updateButton(Button button, VCRDrawInfo btON, VCRDrawInfo break; case kDownON: case kDownOFF: - item.resId = _scene->getResources()->getWorldStats()->grResId[btDown.resId]; + item.resId = Shared.getScene()->getResources()->getWorldStats()->grResId[btDown.resId]; item.frameIdx = 0; item.x = btDown.x; item.y = btDown.y; @@ -508,14 +508,14 @@ void BlowUpPuzzleVCR::updateCursorInPolyRegion() { || inPolyRegion(_mouseX, _mouseY, kYellowHole) && _holesState[kPluggedOnYellow-1] || inPolyRegion(_mouseX, _mouseY, kBlackHole) && _holesState[kPluggedOnBlack-1]) { if(_curMouseCursor != 2) { // reset cursor - _screen->showCursor(); + Shared.getScreen()->showCursor(); _curMouseCursor = 2; _cursorStep = 1; updateCursor(); } } else { if(_curMouseCursor != 0) { // reset cursor - _screen->showCursor(); + Shared.getScreen()->showCursor(); _curMouseCursor = 0; _cursorStep = 1; updateCursor(); @@ -523,7 +523,7 @@ void BlowUpPuzzleVCR::updateCursorInPolyRegion() { } } } else { - _screen->hideCursor(); + Shared.getScreen()->hideCursor(); } } @@ -569,8 +569,8 @@ void BlowUpPuzzleVCR::handleMouseDown() { if (_mouseX >= (uint32)BlowUpPuzzleVCRPolies[kBlackJack].left && _mouseX <= (uint32)BlowUpPuzzleVCRPolies[kYellowJack].right && _mouseY >= (uint32)BlowUpPuzzleVCRPolies[kBlackJack].top && _mouseY <= (uint32)BlowUpPuzzleVCRPolies[kYellowJack].bottom) { _jacksState[jackType-1] = kOnTable; - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[50]); - _screen->showCursor(); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[50]); + Shared.getScreen()->showCursor(); } return; } @@ -586,7 +586,7 @@ void BlowUpPuzzleVCR::handleMouseDown() { // TODO: VCR button regions if (inPolyRegion(_mouseX, _mouseY, kRewindButton)) { - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[39]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[39]); if(!_buttonsState[kRewind]) { _buttonsState[kRewind] = kDownON; return; @@ -596,7 +596,7 @@ void BlowUpPuzzleVCR::handleMouseDown() { return; } } else if (inPolyRegion(_mouseX, _mouseY, kPlayButton)) { - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[39]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[39]); if(!_buttonsState[kPlay]) { _buttonsState[kPlay] = kDownON; return; @@ -606,7 +606,7 @@ void BlowUpPuzzleVCR::handleMouseDown() { return; } } else if (inPolyRegion(_mouseX, _mouseY, kStopButton)) { - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[39]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[39]); if(_buttonsState[kStop]) { if(_buttonsState[kStop] == kON) { _buttonsState[kStop] = kDownOFF; @@ -617,7 +617,7 @@ void BlowUpPuzzleVCR::handleMouseDown() { return; } } else if (inPolyRegion(_mouseX, _mouseY, kPowerButton)) { - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[39]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[39]); if(!_buttonsState[kPower] && _holesState[kPluggedOnBlack-1] == kBlack+1 && _holesState[kPluggedOnRed-1] && _holesState[kPluggedOnYellow-1]) { _buttonsState[kPower] = kDownON; @@ -633,7 +633,7 @@ void BlowUpPuzzleVCR::handleMouseUp() { if(_buttonsState[kPower] == kDownON) { // TODO: check if next sound is already playing - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[47]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[47]); _buttonsState[kPower] = kON; _buttonsState[kStop] = kON; _buttonsState[kPlay] = kON; @@ -648,7 +648,7 @@ void BlowUpPuzzleVCR::handleMouseUp() { if(_buttonsState[kRewind] == kDownOFF) { _buttonsState[kRewind] = kON; - _sound->playSfx(_scene->getResourcePack(), _scene->getResources()->getWorldStats()->grResId[46]); + Shared.getSound()->playSfx(Shared.getScene()->getResourcePack(), Shared.getScene()->getResources()->getWorldStats()->grResId[46]); } else if(_buttonsState[kRewind] == kDownON) { _buttonsState[kRewind] = kOFF; } diff --git a/engines/asylum/blowuppuzzle.h b/engines/asylum/blowuppuzzle.h index f0c288c5bcb..eca09cd6eea 100644 --- a/engines/asylum/blowuppuzzle.h +++ b/engines/asylum/blowuppuzzle.h @@ -53,7 +53,7 @@ typedef struct GraphicQueueItem { class BlowUpPuzzle { public: - BlowUpPuzzle(Scene *scene); + BlowUpPuzzle(); virtual ~BlowUpPuzzle(); virtual void handleEvent(Common::Event *event, bool doUpdate){}; @@ -64,11 +64,6 @@ public: protected: Common::Event *_ev; - Screen *_screen; - Sound *_sound; - Scene *_scene; - Video *_video; - uint32 _mouseX; uint32 _mouseY; uint32 _curMouseCursor; @@ -119,7 +114,7 @@ const Common::Rect BlowUpPuzzleVCRPolies[10] = { class BlowUpPuzzleVCR : public BlowUpPuzzle { public: - BlowUpPuzzleVCR(Scene *scene); + BlowUpPuzzleVCR(); ~BlowUpPuzzleVCR(); void handleEvent(Common::Event *event, bool doUpdate); diff --git a/engines/asylum/menu.cpp b/engines/asylum/menu.cpp index 5d7872a576e..1018c7f9841 100644 --- a/engines/asylum/menu.cpp +++ b/engines/asylum/menu.cpp @@ -26,14 +26,14 @@ #include "asylum/menu.h" #include "asylum/respack.h" #include "asylum/graphics.h" +#include "asylum/shared.h" namespace Asylum { /** This fixes the menu icons text x position on screen */ const int MenuIconFixedXpos[12] = { 28, 128, 225, 320, 410, 528, 16, 115, 237, 310, 508, 419 }; -MainMenu::MainMenu(Screen *screen, Sound *sound, Scene *scene) : - _screen(screen), _sound(sound), _scene(scene) { +MainMenu::MainMenu() { _mouseX = 0; _mouseY = 0; _leftClick = false; @@ -58,7 +58,7 @@ MainMenu::MainMenu(Screen *screen, Sound *sound, Scene *scene) : _creditsResource = 0; _creditsFadeResource = 0; - _text = new Text(_screen); + _text = new Text(Shared.getScreen()); _text->loadFont(_resPack, 16); // 0x80010010, yellow font } @@ -75,27 +75,27 @@ MainMenu::~MainMenu() { void MainMenu::openMenu() { _active = true; - _scene->deactivate(); + Shared.getScene()->deactivate(); // yellow font _text->loadFont(_resPack, 0x80010010); // Load the graphics palette - _screen->setPalette(_resPack, 17); + Shared.getScreen()->setPalette(_resPack, 17); // Copy the bright background to the back buffer GraphicFrame *bg = _bgResource->getFrame(1); - _screen->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); + Shared.getScreen()->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); // Set mouse cursor - _screen->setCursor(_cursorResource, 0); - _screen->showCursor(); + Shared.getScreen()->setCursor(_cursorResource, 0); + Shared.getScreen()->showCursor(); // Stop all sounds - _sound->stopMusic(); - _sound->stopSfx(); + Shared.getSound()->stopMusic(); + Shared.getSound()->stopSfx(); // Start playing music - _sound->playMusic(_resPack, 39); + Shared.getSound()->playMusic(_resPack, 39); _previousActiveIcon = _activeIcon = -1; _leftClick = false; @@ -105,11 +105,11 @@ void MainMenu::openMenu() { void MainMenu::closeMenu() { _active = false; - _scene->activate(); + Shared.getScene()->activate(); // Stop menu sounds and menu music - _sound->stopSfx(); - _sound->stopMusic(); + Shared.getSound()->stopSfx(); + Shared.getSound()->stopMusic(); } void MainMenu::handleEvent(Common::Event *event, bool doUpdate) { @@ -147,13 +147,13 @@ void MainMenu::update() { if (_activeIcon != -1) { // Copy the dark background to the back buffer GraphicFrame *bg = _bgResource->getFrame(0); - _screen->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); + Shared.getScreen()->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); _activeMenuScreen = (MenuScreen) _activeIcon; // Set the cursor delete _cursorResource; _cursorResource = new GraphicResource(_resPack, 3); - _screen->setCursor(_cursorResource, 0); + Shared.getScreen()->setCursor(_cursorResource, 0); } switch (_activeIcon) { @@ -195,15 +195,15 @@ void MainMenu::update() { _creditsFadeResource = new GraphicResource(_resPack, 23); _creditsTextScroll = 0x1E0 - 30; // Set credits palette - _screen->setPalette(_resPack, 26); + Shared.getScreen()->setPalette(_resPack, 26); // Stop all sounds - _sound->stopMusic(); + Shared.getSound()->stopMusic(); // Start playing music - _sound->playMusic(_resPack, 38); + Shared.getSound()->playMusic(_resPack, 38); break; case kReturnToGame: closeMenu(); - _scene->enterScene(); + Shared.getScene()->enterScene(); break; } } @@ -216,7 +216,7 @@ void MainMenu::updateCursor() { if (_curMouseCursor == _cursorResource->getFrameCount() - 1) _cursorStep = -1; - _screen->setCursor(_cursorResource, _curMouseCursor); + Shared.getScreen()->setCursor(_cursorResource, _curMouseCursor); } void MainMenu::updateEyesAnimation() { @@ -249,7 +249,7 @@ void MainMenu::updateEyesAnimation() { // TODO: kEyesCrossed state GraphicFrame *eyeFrame = _eyeResource->getFrame(eyeFrameNum); - _screen->copyRectToScreenWithTransparency((byte *)eyeFrame->surface.pixels, eyeFrame->surface.w, eyeFrame->x, eyeFrame->y, eyeFrame->surface.w, eyeFrame->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)eyeFrame->surface.pixels, eyeFrame->surface.w, eyeFrame->x, eyeFrame->y, eyeFrame->surface.w, eyeFrame->surface.h); } void MainMenu::updateMainMenu() { @@ -289,7 +289,7 @@ void MainMenu::updateMainMenu() { } GraphicFrame *iconFrame = _iconResource->getFrame(MIN(_iconResource->getFrameCount() - 1, _curIconFrame)); - _screen->copyRectToScreenWithTransparency((byte *)iconFrame->surface.pixels, iconFrame->surface.w, iconFrame->x, iconFrame->y, iconFrame->surface.w, iconFrame->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)iconFrame->surface.pixels, iconFrame->surface.w, iconFrame->x, iconFrame->y, iconFrame->surface.w, iconFrame->surface.h); // Cycle icon frame _curIconFrame++; @@ -300,8 +300,8 @@ void MainMenu::updateMainMenu() { _text->drawResTextCentered(MenuIconFixedXpos[iconNum], iconFrame->y + 50, _text->getResTextWidth(iconNum + 1309), iconNum + 1309); // Play creepy voice - if (!_sound->isSfxActive() && _activeIcon != _previousActiveIcon) { - _sound->playSfx(_resPack, iconNum + 44); + if (!Shared.getSound()->isSfxActive() && _activeIcon != _previousActiveIcon) { + Shared.getSound()->playSfx(_resPack, iconNum + 44); _previousActiveIcon = _activeIcon; } @@ -312,7 +312,7 @@ void MainMenu::updateMainMenu() { void MainMenu::updateSubMenu() { GraphicFrame *iconFrame = _iconResource->getFrame(MIN(_iconResource->getFrameCount() - 1, _curIconFrame)); - _screen->copyRectToScreenWithTransparency((byte *)iconFrame->surface.pixels, iconFrame->surface.w, iconFrame->x, iconFrame->y, iconFrame->surface.w, iconFrame->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)iconFrame->surface.pixels, iconFrame->surface.w, iconFrame->x, iconFrame->y, iconFrame->surface.w, iconFrame->surface.h); // Cycle icon frame _curIconFrame++; @@ -580,10 +580,10 @@ void MainMenu::updateSubMenuShowCredits() { int maxBound = 0; GraphicFrame *creditsFadeFrame = _creditsFadeResource->getFrame(0); - _screen->copyRectToScreenWithTransparency((byte *)creditsFadeFrame->surface.pixels, creditsFadeFrame->surface.w, creditsFadeFrame->x, creditsFadeFrame->y, creditsFadeFrame->surface.w, creditsFadeFrame->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)creditsFadeFrame->surface.pixels, creditsFadeFrame->surface.w, creditsFadeFrame->x, creditsFadeFrame->y, creditsFadeFrame->surface.w, creditsFadeFrame->surface.h); GraphicFrame *creditsFrame = _creditsResource->getFrame(MIN(_creditsResource->getFrameCount() - 1, _creditsBgFrame)); - _screen->copyRectToScreenWithTransparency((byte *)creditsFrame->surface.pixels, creditsFrame->surface.w, creditsFrame->x, creditsFrame->y, creditsFrame->surface.w, creditsFrame->surface.h); + Shared.getScreen()->copyRectToScreenWithTransparency((byte *)creditsFrame->surface.pixels, creditsFrame->surface.w, creditsFrame->x, creditsFrame->y, creditsFrame->surface.w, creditsFrame->surface.h); _creditsBgFrame++; if (_creditsBgFrame >= _creditsResource->getFrameCount()) @@ -624,11 +624,11 @@ void MainMenu::updateSubMenuShowCredits() { if (_leftClick) { // Restore palette - _screen->setPalette(_resPack, 17); + Shared.getScreen()->setPalette(_resPack, 17); // Stop all sounds - _sound->stopMusic(); + Shared.getSound()->stopMusic(); // Start playing music - _sound->playMusic(_resPack, 39); + Shared.getSound()->playMusic(_resPack, 39); exitSubMenu(); } } @@ -639,12 +639,12 @@ void MainMenu::exitSubMenu() { // Copy the bright background to the back buffer GraphicFrame *bg = _bgResource->getFrame(1); - _screen->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); + Shared.getScreen()->copyToBackBuffer((byte *)bg->surface.pixels, bg->surface.w, 0, 0, bg->surface.w, bg->surface.h); // Set the cursor delete _cursorResource; _cursorResource = new GraphicResource(_resPack, 2); - _screen->setCursor(_cursorResource, 0); + Shared.getScreen()->setCursor(_cursorResource, 0); } } // end of namespace Asylum diff --git a/engines/asylum/menu.h b/engines/asylum/menu.h index e35de1d85a6..8e7d9478cc0 100644 --- a/engines/asylum/menu.h +++ b/engines/asylum/menu.h @@ -36,14 +36,11 @@ namespace Asylum { -class Scene; -class Screen; -class Sound; class Text; class MainMenu { public: - MainMenu(Screen *screen, Sound *sound, Scene *scene); + MainMenu(); ~MainMenu(); void handleEvent(Common::Event *event, bool doUpdate); @@ -84,10 +81,6 @@ private: Common::Event *_ev; - Screen *_screen; - Sound *_sound; - Scene *_scene; - uint32 _mouseX; uint32 _mouseY; int32 _activeIcon; diff --git a/engines/asylum/module.mk b/engines/asylum/module.mk index 06c57d541a3..296ccb57ea3 100644 --- a/engines/asylum/module.mk +++ b/engines/asylum/module.mk @@ -17,7 +17,7 @@ MODULE_OBJS := \ encounters.o \ scriptman.o \ blowuppuzzle.o \ - utilities.o + shared.o # This module can be built as a plugin ifeq ($(ENABLE_ASYLUM), DYNAMIC_PLUGIN) diff --git a/engines/asylum/scene.cpp b/engines/asylum/scene.cpp index 87b217cba20..65f08298385 100644 --- a/engines/asylum/scene.cpp +++ b/engines/asylum/scene.cpp @@ -25,7 +25,7 @@ #include "asylum/scene.h" #include "asylum/sceneres.h" -#include "asylum/utilities.h" +#include "asylum/shared.h" namespace Asylum { @@ -35,12 +35,12 @@ namespace Asylum { int g_debugPolygons; int g_debugBarriers; -Scene::Scene(Screen *screen, Sound *sound, Video *video, uint8 sceneIdx): _screen(screen), _sound(sound), _video(video) { +Scene::Scene(uint8 sceneIdx) { _sceneIdx = sceneIdx; _sceneResource = new SceneResource; if (_sceneResource->load(_sceneIdx)) { - _text = new Text(_screen); + _text = new Text(Shared.getScreen()); _resPack = new ResourcePack(sceneIdx); _speechPack = new ResourcePack(3); @@ -84,19 +84,19 @@ Scene::~Scene() { } void Scene::enterScene() { - _screen->setPalette(_resPack, _sceneResource->getWorldStats()->commonRes.palette); + Shared.getScreen()->setPalette(_resPack, _sceneResource->getWorldStats()->commonRes.palette); _background = _bgResource->getFrame(0); - _screen->copyToBackBuffer( + Shared.getScreen()->copyToBackBuffer( ((byte *)_background->surface.pixels) + _startY * _background->surface.w + _startX, _background->surface.w, 0, 0, 640, 480); _cursorStep = 1; _curMouseCursor = 0; - _screen->setCursor(_cursorResource, 0); - _screen->showCursor(); + Shared.getScreen()->setCursor(_cursorResource, 0); + Shared.getScreen()->showCursor(); // Music testing: play the first music track - _sound->playMusic(_musPack, 0); + Shared.getSound()->playMusic(_musPack, 0); _isActive = true; _walking = false; @@ -267,7 +267,7 @@ void Scene::animateCursor() { if (_curMouseCursor == _cursorResource->getFrameCount() - 1) _cursorStep = -1; - _screen->setCursor(_cursorResource, _curMouseCursor); + Shared.getScreen()->setCursor(_cursorResource, _curMouseCursor); } void Scene::update() { @@ -283,7 +283,7 @@ void Scene::update() { // debugScreenScrolling(bg); // Copy the background to the back buffer before updating the scene animations - _screen->copyToBackBuffer(((byte *)bg->surface.pixels) + _startY * bg->surface.w + _startX, + Shared.getScreen()->copyToBackBuffer(((byte *)bg->surface.pixels) + _startY * bg->surface.w + _startX, bg->surface.w, 0, 0, @@ -294,24 +294,23 @@ void Scene::update() { // This is a hack for scene 1. This really shouldn't be hardcoded, as the // activation of this barrier should be interpreted by the script manager, // but at the moment, we're not sure where it is in the script. - updateBarrier(_screen, _resPack, 1); // inside the middle room + updateBarrier(Shared.getScreen(), _resPack, 1); // inside the middle room for(uint b=0; b < _sceneResource->getWorldStats()->barriers.size(); b++) { if ((_sceneResource->getWorldStats()->barriers[b].flags & 0x20) != 0) // TODO - enums for flags (0x20 is visible/playing?) - updateBarrier(_screen, _resPack, b); + updateBarrier(Shared.getScreen(), _resPack, b); } // DEBUGGING // Check current walk region - PolyDefinitions currentWalkRegion; - for (uint32 a = 0; a < worldStats->numActions; a++) { if (worldStats->actions[a].actionType == 0) { - PolyDefinitions poly = _sceneResource->getGamePolygons()->polygons[worldStats->actions[a].polyIdx]; - if (Utils.pointInPoly(&poly, mainActor->_actorX, mainActor->_actorY)) { + ActionItem *area = &worldStats->actions[a]; + PolyDefinitions poly = _sceneResource->getGamePolygons()->polygons[area->polyIdx]; + if (Shared.pointInPoly(&poly, mainActor->_actorX, mainActor->_actorY)) { debugShowWalkRegion(&poly); - currentWalkRegion = poly; - break; + mainActor->setWalkArea(area); + //break; } } } @@ -330,12 +329,12 @@ void Scene::update() { mainActor->setAction(currentAction + 5); _walking = false; } - mainActor->drawActor(_screen); + mainActor->drawActor(); } } else { _walking = true; - mainActor->walkTo(_screen, _mouseX, _mouseY, ¤tWalkRegion); + mainActor->walkTo(_mouseX, _mouseY); updateCursor(); } @@ -369,7 +368,7 @@ void Scene::update() { for (uint32 p = 0; p < _sceneResource->getGamePolygons()->numEntries; p++) { PolyDefinitions poly = _sceneResource->getGamePolygons()->polygons[p]; if (poly.boundingRect.contains(_mouseX + _startX, _mouseY + _startY)) { - if (Utils.pointInPoly(&poly, _mouseX + _startX, _mouseY + _startY)) { + if (Shared.pointInPoly(&poly, _mouseX + _startX, _mouseY + _startY)) { curHotspot = (int32)p; animateCursor(); break; @@ -440,7 +439,7 @@ void Scene::copyToBackBufferClipped(Graphics::Surface *surface, int x, int y) { if (surface->h > 480) startY = _startY; - _screen->copyToBackBufferWithTransparency( + Shared.getScreen()->copyToBackBufferWithTransparency( ((byte*)surface->pixels) + startY * surface->pitch + startX * surface->bytesPerPixel, diff --git a/engines/asylum/scene.h b/engines/asylum/scene.h index eba2a422bf0..98c6b16cc3c 100644 --- a/engines/asylum/scene.h +++ b/engines/asylum/scene.h @@ -47,7 +47,7 @@ struct PolyDefinitions; class Scene { public: - Scene(Screen *screen, Sound *sound, Video *video, uint8 sceneIdx); + Scene(uint8 sceneIdx); ~Scene(); void handleEvent(Common::Event *event, bool doUpdate); @@ -76,10 +76,6 @@ public: BlowUpPuzzle* getBlowUpPuzzle() { return _blowUp; } void setBlowUpPuzzle(BlowUpPuzzle* puzzle) { _blowUp = puzzle; } - Screen* getScreen() { return _screen; } - Sound* getSound() { return _sound; } - Video* getVideo() { return _video; } - private: #if 0 void copyToSceneBackground(GraphicFrame *frame, int x, int y); @@ -91,13 +87,8 @@ private: ResourcePack *_resPack; ResourcePack *_speechPack; ResourcePack *_musPack; - - Screen *_screen; - Sound *_sound; - Video *_video; - BlowUpPuzzle *_blowUp; - Common::Event *_ev; - + BlowUpPuzzle *_blowUp; + Common::Event *_ev; Text *_text; GraphicResource *_bgResource; GraphicResource *_cursorResource; diff --git a/engines/asylum/scriptman.cpp b/engines/asylum/scriptman.cpp index b862bd1affb..0f273bfc9dc 100644 --- a/engines/asylum/scriptman.cpp +++ b/engines/asylum/scriptman.cpp @@ -22,10 +22,11 @@ * $Id$ */ -#include "asylum/scriptman.h" - #include "common/system.h" +#include "asylum/scriptman.h" +#include "asylum/shared.h" + DECLARE_SINGLETON(Asylum::ScriptManager); namespace Asylum { @@ -69,14 +70,10 @@ void ScriptManager::setScript(ActionDefinitions *action) { } } -void ScriptManager::setScene(Scene* scene) { - _scene = scene; -} - void ScriptManager::setScriptIndex(uint32 index) { _currentScript = 0; _currentLine = 0; - setScript(_scene->getActionList(index)); + setScript(Shared.getScene()->getActionList(index)); } void ScriptManager::setGameFlag(int flag) { @@ -157,25 +154,25 @@ void ScriptManager::processActionList() { break; /* 0x05 */ case kHideCursor: - _scene->_screen->hideCursor(); + Shared.getScreen()->hideCursor(); _allowInput = false; break; /* 0x06 */ case kShowCursor: - _scene->_screen->showCursor(); + Shared.getScreen()->showCursor(); _allowInput = true; // TODO: clear_flag_01() break; /* 0x07 */ case kPlayAnimation: { - int barrierIndex = _scene->_sceneResource->getBarrierIndexById(currentCommand->param1); + int barrierIndex = Shared.getScene()->_sceneResource->getBarrierIndexById(currentCommand->param1); if (barrierIndex >= 0) - _scene->_sceneResource->getWorldStats()->barriers[barrierIndex].flags |= 0x20; // TODO - enums for flags (0x20 is visible/playing?) + Shared.getScene()->_sceneResource->getWorldStats()->barriers[barrierIndex].flags |= 0x20; // TODO - enums for flags (0x20 is visible/playing?) else debugC(kDebugLevelScripts, "Requested invalid object ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -184,17 +181,17 @@ void ScriptManager::processActionList() { /* 0x09 */ case kHideActor: { uint32 actorIndex = 0; if (currentCommand->param1 == -1) - ;//actorIndex = _scene->getWorldStats()->playerActor; + ;//actorIndex = Shared.getScene()->getWorldStats()->playerActor; else actorIndex = currentCommand->param1; - if ((actorIndex >= 0) && (actorIndex < _scene->_sceneResource->getWorldStats()->numActors)) - _scene->actorVisible(actorIndex, false); + if ((actorIndex >= 0) && (actorIndex < Shared.getScene()->_sceneResource->getWorldStats()->numActors)) + Shared.getScene()->actorVisible(actorIndex, false); else debugC(kDebugLevelScripts, "Requested invalid actor ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -202,17 +199,17 @@ void ScriptManager::processActionList() { /* 0x0A */ case kShowActor: { uint32 actorIndex = 0; if (currentCommand->param1 == -1) - ;//actorIndex = _scene->getWorldStats()->playerActor; + ;//actorIndex = Shared.getScene()->getWorldStats()->playerActor; else actorIndex = currentCommand->param1; - if ((actorIndex >= 0) && (actorIndex < _scene->_sceneResource->getWorldStats()->numActors)) - _scene->actorVisible(actorIndex, true); + if ((actorIndex >= 0) && (actorIndex < Shared.getScene()->_sceneResource->getWorldStats()->numActors)) + Shared.getScene()->actorVisible(actorIndex, true); else debugC(kDebugLevelScripts, "Requested invalid actor ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -220,19 +217,19 @@ void ScriptManager::processActionList() { /* 0x0B */ case kSetActorStats: { uint32 actorIndex = 0; if (currentCommand->param1 == -1) - ;//actorIndex = _scene->getWorldStats()->playerActor; + ;//actorIndex = Shared.getScene()->getWorldStats()->playerActor; else actorIndex = currentCommand->param1; - if ((actorIndex >= 0) && (actorIndex < _scene->_sceneResource->getWorldStats()->numActors)) { - _scene->setActorPosition(actorIndex, currentCommand->param2, currentCommand->param3); - _scene->setActorAction(actorIndex, currentCommand->param4); + if ((actorIndex >= 0) && (actorIndex < Shared.getScene()->_sceneResource->getWorldStats()->numActors)) { + Shared.getScene()->setActorPosition(actorIndex, currentCommand->param2, currentCommand->param3); + Shared.getScene()->setActorAction(actorIndex, currentCommand->param4); } else debugC(kDebugLevelScripts, "Requested invalid actor ID:0x%02X in Scene %d Script %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -242,33 +239,33 @@ void ScriptManager::processActionList() { /* 0x0E */ case kEnableActor: { int actorIndex = 0; if (currentCommand->param1 == -1) - ;//actorIndex = _scene->getWorldStats()->playerActor; + ;//actorIndex = Shared.getScene()->getWorldStats()->playerActor; else actorIndex = currentCommand->param1; - if (_scene->_sceneResource->getWorldStats()->actors[actorIndex].field_40 == 5) { + if (Shared.getScene()->_sceneResource->getWorldStats()->actors[actorIndex].field_40 == 5) { enableActorSub(actorIndex, 4); } } break; /* 0x0F */ case kEnableBarriers: { - int barIdx = _scene->_sceneResource->getBarrierIndexById(currentCommand->param1); + int barIdx = Shared.getScene()->_sceneResource->getBarrierIndexById(currentCommand->param1); uint32 sndIdx = currentCommand->param3; uint32 v59 = currentCommand->param2; - if (!_currentScript->counter && _scene->getSceneIndex() != 13 && sndIdx != 0) { + if (!_currentScript->counter && Shared.getScene()->getSceneIndex() != 13 && sndIdx != 0) { // TODO // Find a script that actually has a valid param3 // to see if this code is accurate :P ResourcePack *tmpRes = new ResourcePack(12); - _scene->_sound->playSfx(tmpRes, ((int)(sndIdx != 0) & 5) + 0x80120001); + Shared.getSound()->playSfx(tmpRes, ((int)(sndIdx != 0) & 5) + 0x80120001); delete tmpRes; } if (_currentScript->counter >= 3 * v59 - 1) { _currentScript->counter = 0; - _scene->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = 0; + Shared.getScene()->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = 0; processActionListSub02(_currentScript, currentCommand, 2); _currentLoops = 1; // v4 = 1; } else { @@ -278,10 +275,10 @@ void ScriptManager::processActionList() { if (sndIdx) { v64 = 1; int v170 = 3 - v62 / v59; - _scene->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = v170; + Shared.getScene()->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = v170; } else { v64 = 0; - _scene->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = v62 / v59 + 1; + Shared.getScene()->_sceneResource->getWorldStats()->barriers[barIdx].field_67C = v62 / v59 + 1; } processActionListSub02(_currentScript, currentCommand, v64); @@ -296,14 +293,14 @@ void ScriptManager::processActionList() { break; /* 0x11 */ case kDestroyObject: { - int barrierIndex = _scene->_sceneResource->getBarrierIndexById(currentCommand->param1); + int barrierIndex = Shared.getScene()->_sceneResource->getBarrierIndexById(currentCommand->param1); if (barrierIndex >= 0) - _scene->_sceneResource->getWorldStats()->barriers[barrierIndex].flags &= 0xFFFFDF; // TODO - enums for flags (0x20 is visible/playing?) + Shared.getScene()->_sceneResource->getWorldStats()->barriers[barrierIndex].flags &= 0xFFFFDF; // TODO - enums for flags (0x20 is visible/playing?) else debugC(kDebugLevelScripts, "Requested invalid object ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -347,7 +344,7 @@ void ScriptManager::processActionList() { /* 0x2E */ case kStopAllBarriersSounds: // TODO: do this for all barriers that have sfx playing - _scene->_sound->stopSfx(); + Shared.getSound()->stopSfx(); break; /* 0x2F */ //case kSetActionFlag01: @@ -355,7 +352,7 @@ void ScriptManager::processActionList() { /* 0x31 */ //case kResetSceneRect: /* 0x32 */ //case kChangeMusicById: /* 0x33 */ case kStopMusic: - _scene->_sound->stopMusic(); + Shared.getSound()->stopMusic(); break; /* 0x34 */ //case k_unk34_Status: @@ -363,8 +360,8 @@ void ScriptManager::processActionList() { /* 0x36 */ //case k_unk36: /* 0x37 */ case kRunBlowUpPuzzle: { int blowUpPuzzleIdx = currentCommand->param1; - _scene->setBlowUpPuzzle(new BlowUpPuzzleVCR(_scene)); - _scene->getBlowUpPuzzle()->openBlowUp(); + Shared.getScene()->setBlowUpPuzzle(new BlowUpPuzzleVCR()); + Shared.getScene()->getBlowUpPuzzle()->openBlowUp(); } break; @@ -374,15 +371,15 @@ void ScriptManager::processActionList() { /* 0x3B */ //case k_unk3B_PALETTE_MOD: /* 0x3C */ //case k_unk3C_CMP_VAL: /* 0x3D */ case kWaitUntilFramePlayed: { - int barrierIndex = _scene->_sceneResource->getBarrierIndexById(currentCommand->param1); + int barrierIndex = Shared.getScene()->_sceneResource->getBarrierIndexById(currentCommand->param1); if (barrierIndex >= 0) { uint32 frameNum = 0; if (currentCommand->param2 == -1) - frameNum = _scene->_sceneResource->getWorldStats()->barriers[barrierIndex].frameCount - 1; + frameNum = Shared.getScene()->_sceneResource->getWorldStats()->barriers[barrierIndex].frameCount - 1; else frameNum = currentCommand->param2; - if (_scene->_sceneResource->getWorldStats()->barriers[barrierIndex].tickCount < frameNum) { + if (Shared.getScene()->_sceneResource->getWorldStats()->barriers[barrierIndex].tickCount < frameNum) { lineIncrement = 0; waitCycle = true; } @@ -390,7 +387,7 @@ void ScriptManager::processActionList() { debugC(kDebugLevelScripts, "Requested invalid object ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -400,7 +397,7 @@ void ScriptManager::processActionList() { if(barSize >= 22) { currentCommand->param1 = 0; } else { - _scene->_screen->drawWideScreen(4 * barSize); + Shared.getScreen()->drawWideScreen(4 * barSize); currentCommand->param1++; } } @@ -414,16 +411,16 @@ void ScriptManager::processActionList() { if ((int)sndIdx >= 0) { if (sndIdx >= 259) { sndIdx -= 9; - _scene->_sound->playSfx(_scene->_speechPack, sndIdx - 0x7FFD0000); + Shared.getSound()->playSfx(Shared.getScene()->_speechPack, sndIdx - 0x7FFD0000); } else { - _scene->_sound->playSfx(_scene->_speechPack, sndIdx); + Shared.getSound()->playSfx(Shared.getScene()->_speechPack, sndIdx); } } else debugC(kDebugLevelScripts, "Requested invalid sound ID:0x%02X in Scene %d Line %d.", currentCommand->param1, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); } break; @@ -442,11 +439,11 @@ void ScriptManager::processActionList() { int actorIdx = currentCommand->param1; int fieldType = currentCommand->param2; if(fieldType) { - if(_scene->getResources()->getWorldStats()->actors[actorIdx].field_40 < 11) { - _scene->getResources()->getWorldStats()->actors[actorIdx].field_40 = 14; + if(Shared.getScene()->getResources()->getWorldStats()->actors[actorIdx].field_40 < 11) { + Shared.getScene()->getResources()->getWorldStats()->actors[actorIdx].field_40 = 14; } } else { - _scene->getResources()->getWorldStats()->actors[actorIdx].field_40 = 4; + Shared.getScene()->getResources()->getWorldStats()->actors[actorIdx].field_40 = 4; } } break; @@ -454,7 +451,7 @@ void ScriptManager::processActionList() { /* 0x4E */ //case k_unk4E_RANDOM_COMMAND: /* 0x4F */ case kClearScreen: if(currentCommand->param1) { - _scene->_screen->clearScreen(); + Shared.getScreen()->clearScreen(); } break; @@ -482,7 +479,7 @@ void ScriptManager::processActionList() { debugC(kDebugLevelScripts, "Unhandled opcode 0x%02X in Scene %d Line %d.", currentCommand->opcode, - _scene->getSceneIndex(), + Shared.getScene()->getSceneIndex(), _currentLine); break; @@ -516,14 +513,14 @@ void ScriptManager::processActionListSub02(ActionDefinitions* script, ActionComm int v8 = command->param4; for (int i = 7; i > 0; i--) { - barrierIdx = _scene->getResources()->getBarrierIndexById(v8); - if (barrierIdx) - _scene->getResources()->getWorldStats()->barriers[barrierIdx].field_67C = 0; + barrierIdx = Shared.getScene()->getResources()->getBarrierIndexById(v8); + if (barrierIdx >= 0) + Shared.getScene()->getResources()->getWorldStats()->barriers[barrierIdx].field_67C = 0; v8 += 4; } } // TODO - switch (_scene->getSceneIndex()) { + switch (Shared.getScene()->getSceneIndex()) { case 7: warning("Scene 7 / v4 != 0 Not Implemented"); break; @@ -546,13 +543,13 @@ void ScriptManager::processActionListSub02(ActionDefinitions* script, ActionComm int v13 = command->param4; int v4 = script->counter / command->param2 + 4; for (int i = 7; i > 0; i--) { - barrierIdx = _scene->getResources()->getBarrierIndexById(v13); + barrierIdx = Shared.getScene()->getResources()->getBarrierIndexById(v13); if (barrierIdx >= 0) - _scene->getResources()->getWorldStats()->barriers[barrierIdx].field_67C = v4; + Shared.getScene()->getResources()->getWorldStats()->barriers[barrierIdx].field_67C = v4; v13 += 4; } // TODO - switch (_scene->getSceneIndex()) { + switch (Shared.getScene()->getSceneIndex()) { case 7: warning("Scene 7 / v4 = 0 Not Implemented"); break; diff --git a/engines/asylum/scriptman.h b/engines/asylum/scriptman.h index 1f46a0ae9e1..64d06f8784b 100644 --- a/engines/asylum/scriptman.h +++ b/engines/asylum/scriptman.h @@ -39,7 +39,6 @@ public: void processActionList(); - void setScene(Scene *scene); void setScript(ActionDefinitions *action); void setScriptIndex(uint32 index); @@ -70,7 +69,6 @@ private: int _delayedVideoIndex; bool _allowInput; - Scene *_scene; ActionDefinitions *_currentScript; // NOTE diff --git a/engines/asylum/utilities.cpp b/engines/asylum/shared.cpp similarity index 88% rename from engines/asylum/utilities.cpp rename to engines/asylum/shared.cpp index 5afdf84d058..c17943646b7 100644 --- a/engines/asylum/utilities.cpp +++ b/engines/asylum/shared.cpp @@ -23,28 +23,28 @@ * */ -#include "asylum/utilities.h" +#include "asylum/shared.h" #include "common/system.h" -DECLARE_SINGLETON(Asylum::Utilities); +DECLARE_SINGLETON(Asylum::SharedResources); namespace Asylum { static bool g_initialized = false; -Utilities::Utilities() { +SharedResources::SharedResources() { if (!g_initialized) { g_initialized = true; } } -Utilities::~Utilities() { +SharedResources::~SharedResources() { g_initialized = false; } -bool Utilities::pointInPoly(PolyDefinitions *poly, int x, int y) { +bool SharedResources::pointInPoly(PolyDefinitions *poly, int x, int y) { // Copied from backends/vkeybd/polygon.cpp int yflag0; int yflag1; diff --git a/engines/asylum/shared.h b/engines/asylum/shared.h new file mode 100644 index 00000000000..3902f51ac0b --- /dev/null +++ b/engines/asylum/shared.h @@ -0,0 +1,80 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef ASYLUM_SHARED_H +#define ASYLUM_SHARED_H_ + +#include "common/singleton.h" + +#include "asylum/sceneres.h" + +namespace Asylum { + +/** + * Shared Resources are classes that are instantiated at the engine level. + * Binding them to this singleton simplifies implementation of new classes + * that will require access to common interfaces and tools. + * + * A candidate for a shared resource would be any class that will be utilized + * by one-to-many instances of another class, but will never need more than + * one instance itself. + * + * Each component herin could technically be a singleton unto itself, but + * by using this method, destruction can be handled by the engine. + */ +class SharedResources: public Common::Singleton { +public: + + void setVideo(Video* video) { _video = video; } + Video* getVideo() { return _video; } + + void setScreen(Screen* screen) { _screen = screen; } + Screen* getScreen() { return _screen; } + + void setSound(Sound* sound) { _sound = sound; } + Sound* getSound() { return _sound; } + + void setScene(Scene* scene) { _scene = scene; } + Scene* getScene() { return _scene; } + + bool pointInPoly(PolyDefinitions *poly, int x, int y); + +private: + friend class Common::Singleton; + SharedResources(); + ~SharedResources(); + + Video *_video; + Screen *_screen; + Sound *_sound; + Scene *_scene; + +}; // end of class SharedResources + +#define Shared (::Asylum::SharedResources::instance()) + +} // end of namespace Asylum + +#endif diff --git a/engines/asylum/utilities.h b/engines/asylum/utilities.h deleted file mode 100644 index 2c7d5b39a1c..00000000000 --- a/engines/asylum/utilities.h +++ /dev/null @@ -1,49 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef ASYLUM_UTILITIES_H_ -#define ASYLUM_UTILITIES_H_ - -#include "common/singleton.h" - -#include "asylum/sceneres.h" - -namespace Asylum { - -class Utilities: public Common::Singleton { -public: - bool pointInPoly(PolyDefinitions *poly, int x, int y); - -private: - friend class Common::Singleton; - Utilities(); - ~Utilities(); -}; // end of class Utilities - -#define Utils (::Asylum::Utilities::instance()) - -} // end of namespace Asylum - -#endif