From 99939109d75816e434f51479bafdc48a987fb008 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 3 Jul 2010 11:50:42 +0000 Subject: Adding the beginnings of a player control class, as well as various changes to the other classes to support it svn-id: r50620 --- engines/m4/mads_scene.cpp | 123 ++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 47 deletions(-) (limited to 'engines/m4/mads_scene.cpp') diff --git a/engines/m4/mads_scene.cpp b/engines/m4/mads_scene.cpp index f4581ed629..c34216aa34 100644 --- a/engines/m4/mads_scene.cpp +++ b/engines/m4/mads_scene.cpp @@ -67,8 +67,10 @@ MadsScene::~MadsScene() { /** * Secondary scene loading code */ -void MadsScene::loadScene2(const char *aaName) { +void MadsScene::loadScene2(const char *aaName, int sceneNumber) { // TODO: Completely finish + _madsVm->globals()->previousScene = _madsVm->globals()->sceneNumber; + _madsVm->globals()->sceneNumber = sceneNumber; _spriteSlots.clear(); _sequenceList.clear(); @@ -115,27 +117,41 @@ void MadsScene::loadScene(int sceneNumber) { // Handle common scene setting Scene::loadScene(sceneNumber); - - _madsVm->globals()->previousScene = _madsVm->globals()->sceneNumber; - _madsVm->globals()->sceneNumber = sceneNumber; + _madsVm->globals()->_nextSceneId = sceneNumber; // Existing ScummVM code that needs to be eventually replaced with MADS code loadSceneTemporary(); + _madsVm->_player._spritesChanged = true; + _madsVm->globals()->clearQuotes(); + _dynamicHotspots.reset(); + // Signal the script engine what scene is to be active _sceneLogic.selectScene(sceneNumber); - _sceneLogic.setupScene(); // Add the scene if necessary to the list of scenes that have been visited _vm->globals()->addVisitedScene(sceneNumber); - if (_vm->getGameType() == GType_RexNebular) { + if (_vm->getGameType() == GType_RexNebular) + _sceneLogic.setupScene(); + + // TODO: Unknown code + + // Secondary scene load routine + if (_vm->getGameType() == GType_RexNebular) // Secondary scene load routine - loadScene2("*I0.AA"); + loadScene2("*I0.AA", sceneNumber); - // Do any scene specific setup + _madsVm->_player.loadSprites(NULL); + + // Do any scene specific setup + if (_vm->getGameType() == GType_RexNebular) _sceneLogic.enterScene(); - } + + // Miscellaneous player setup + _madsVm->_player._destPos = _madsVm->_player._destPos; + _madsVm->_player._direction2 = _madsVm->_player._direction; + _madsVm->_player.idle(); // Purge resources _vm->res()->purge(); @@ -300,6 +316,8 @@ void MadsScene::update() { } void MadsScene::updateState() { + _madsVm->_player.update(); + _sceneLogic.sceneStep(); if ((_activeAnimation) && !_abortTimers) { @@ -311,8 +329,36 @@ void MadsScene::updateState() { } MadsView::update(); + + // Remove the animation if it's been completed + if ((_activeAnimation) && ((MadsAnimation *)_activeAnimation)->freeFlag()) + freeAnimation(); +} + +/** + * Does extra work at cleaning up the animation, and then deletes it + */ +void MadsScene::freeAnimation() { + if (!_activeAnimation) + return; + + MadsAnimation *anim = (MadsAnimation *)_activeAnimation; + if (anim->freeFlag()) { + _madsVm->scene()->_spriteSlots.clear(); + _madsVm->scene()->_spriteSlots.fullRefresh(); + _madsVm->scene()->_sequenceList.scan(); + } + + if (_madsVm->_player._visible) { + _madsVm->_player._forceRefresh = true; + _madsVm->_player.update(); + } + + delete _activeAnimation; + _activeAnimation = NULL; } + int MadsScene::loadSceneSpriteSet(const char *setName) { char resName[100]; strcpy(resName, setName); @@ -324,28 +370,6 @@ int MadsScene::loadSceneSpriteSet(const char *setName) { return _spriteSlots.addSprites(resName); } -void MadsScene::loadPlayerSprites(const char *prefix) { - const char suffixList[8] = { '8', '9', '6', '3', '2', '7', '4', '1' }; - char setName[80]; - - strcpy(setName, "*"); - strcat(setName, prefix); - strcat(setName, "_0.SS"); - char *digitP = strchr(setName, '_') + 1; - - for (int idx = 0; idx < 8; ++idx) { - *digitP = suffixList[idx]; - - if (_vm->res()->resourceExists(setName)) { - loadSceneSpriteSet(setName); - return; - } - } - - // Phantom/Dragon - warning("Couldn't find player sprites"); -} - enum boxSprites { topLeft = 0, topRight = 1, @@ -665,22 +689,27 @@ void MadsSceneResources::load(int sceneNumber, const char *resName, int v0, M4Su } // TODO: The following is wrong for Phantom/Dragon - artFileNum = stream->readUint16LE(); - depthStyle = stream->readUint16LE(); - width = stream->readUint16LE(); - height = stream->readUint16LE(); + _artFileNum = stream->readUint16LE(); + _depthStyle = stream->readUint16LE(); + _width = stream->readUint16LE(); + _height = stream->readUint16LE(); stream->skip(24); int objectCount = stream->readUint16LE(); - - stream->skip(40); + _yBandsEnd = stream->readUint16LE(); + _yBandsStart = stream->readUint16LE(); + _maxScale = stream->readSint16LE(); + _minScale = stream->readSint16LE(); + for (int i = 0; i < DEPTH_BANDS_SIZE; ++i) + _depthBands[i] = stream->readUint16LE(); + stream->skip(2); // Load in any scene objects for (int i = 0; i < objectCount; ++i) { MadsObject rec; rec.load(stream); - objects.push_back(rec); + _objects.push_back(rec); } for (int i = 0; i < 20 - objectCount; ++i) stream->skip(48); @@ -690,7 +719,7 @@ void MadsSceneResources::load(int sceneNumber, const char *resName, int v0, M4Su for (int i = 0; i < setCount; ++i) { char buffer2[64]; Common::String s(buffer2, 64); - setNames.push_back(s); + _setNames.push_back(s); } delete stream; @@ -698,16 +727,16 @@ void MadsSceneResources::load(int sceneNumber, const char *resName, int v0, M4Su // Initialise a copy of the surfaces if they weren't provided bool dsFlag = false, ssFlag = false; if (!surface) { - surface = new M4Surface(width, height); + surface = new M4Surface(_width, _height); ssFlag = true; - } else if ((width != surface->width()) || (height != surface->height())) - surface->setSize(width, height); + } else if ((_width != surface->width()) || (_height != surface->height())) + surface->setSize(_width, _height); if (!depthSurface) { - depthSurface = new M4Surface(width, height); + depthSurface = new M4Surface(_width, _height); dsFlag = true; - } else if ((width != depthSurface->width()) || (height != depthSurface->height())) - depthSurface->setSize(width, height); + } else if ((_width != depthSurface->width()) || (_height != depthSurface->height())) + depthSurface->setSize(_width, _height); // For Rex Nebular, read in the scene's compressed walk surface information @@ -724,7 +753,7 @@ void MadsSceneResources::load(int sceneNumber, const char *resName, int v0, M4Su // Run length encoded depth data while ((runLength = *srcP++) != 0) { - if (depthStyle == 2) { + if (_depthStyle == 2) { // 2-bit depth pixels byte byteVal = *srcP++; for (int byteCtr = 0; byteCtr < runLength; ++byteCtr) { @@ -746,7 +775,7 @@ void MadsSceneResources::load(int sceneNumber, const char *resName, int v0, M4Su _vm->_resourceManager->toss(sceneName); // Load the surface artwork - surface->loadBackground(artFileNum); + surface->loadBackground(_artFileNum); // Final cleanup if (ssFlag) -- cgit v1.2.3