diff options
-rw-r--r-- | engines/m4/console.cpp | 6 | ||||
-rw-r--r-- | engines/m4/globals.h | 6 | ||||
-rw-r--r-- | engines/m4/hotspot.cpp | 5 | ||||
-rw-r--r-- | engines/m4/mads_anim.cpp | 190 | ||||
-rw-r--r-- | engines/m4/scene.h | 22 |
5 files changed, 144 insertions, 85 deletions
diff --git a/engines/m4/console.cpp b/engines/m4/console.cpp index 7cf2120dc7..17fa20882a 100644 --- a/engines/m4/console.cpp +++ b/engines/m4/console.cpp @@ -310,7 +310,7 @@ bool Console::cmdObject(int argc, const char **argv) { DebugPrintf("%2d - ", objStart); for (uint objId = objStart; objId < MIN<uint>(_vm->_globals->getObjectsSize(), objStart + 5); ++objId) { if (objId != objStart) DebugPrintf(", "); - uint16 descId = _vm->_globals->getObject(objId)->descId - 1; + uint16 descId = _vm->_globals->getObject(objId)->descId; DebugPrintf("%s", _vm->_globals->getVocab(descId)); } @@ -327,13 +327,13 @@ bool Console::cmdObject(int argc, const char **argv) { else { const MadsObject *obj = _vm->_globals->getObject(id); - DebugPrintf("Object #%d (%s) room=%d vocabs=%d", id, _vm->_globals->getVocab(obj->descId - 1), + DebugPrintf("Object #%d (%s) room=%d vocabs=%d", id, _vm->_globals->getVocab(obj->descId), obj->roomNumber, obj->vocabCount); if (obj->vocabCount > 0) { DebugPrintf(" - "); for (int i = 0; i < obj->vocabCount; ++i) { if (i != 0) DebugPrintf(", "); - DebugPrintf("%s (%d)/%d", _vm->_globals->getVocab(obj->vocabList[i].vocabId - 1), + DebugPrintf("%s (%d)/%d", _vm->_globals->getVocab(obj->vocabList[i].vocabId), obj->vocabList[i].vocabId, obj->vocabList[i].unk); } } diff --git a/engines/m4/globals.h b/engines/m4/globals.h index 37348b1367..c77f0b2089 100644 --- a/engines/m4/globals.h +++ b/engines/m4/globals.h @@ -194,7 +194,11 @@ public: void loadMadsVocab(); uint32 getVocabSize() { return _madsVocab.size(); } - const char *getVocab(uint32 index) { return _madsVocab[index]; } + const char *getVocab(uint32 index) { + // Vocab list is 1-based, so always subtract one from index provided + assert((index > 0) && (index <= _madsVocab.size())); + return _madsVocab[index - 1]; + } void loadMadsQuotes(); uint32 getQuotesSize() { return _madsQuotes.size(); } diff --git a/engines/m4/hotspot.cpp b/engines/m4/hotspot.cpp index 7de66b375b..656d2300f4 100644 --- a/engines/m4/hotspot.cpp +++ b/engines/m4/hotspot.cpp @@ -51,6 +51,7 @@ HotSpot::HotSpot(int x1, int y1, int x2, int y2) : } HotSpot::~HotSpot() { + free(_vocab); } void HotSpot::setRect(int x1, int y1, int x2, int y2) { @@ -273,10 +274,10 @@ void HotSpotList::loadHotSpots(Common::SeekableReadStream* hotspotStream, int ho currentHotSpot->setVerb(""); if (currentHotSpot->getVocabID() > 0) - currentHotSpot->setVocab(_vm->_globals->getVocab(currentHotSpot->getVocabID() - 1)); + currentHotSpot->setVocab(_vm->_globals->getVocab(currentHotSpot->getVocabID())); if (currentHotSpot->getVerbID() > 0) - currentHotSpot->setVerb(_vm->_globals->getVocab(currentHotSpot->getVerbID() - 1)); + currentHotSpot->setVerb(_vm->_globals->getVocab(currentHotSpot->getVerbID())); } } } diff --git a/engines/m4/mads_anim.cpp b/engines/m4/mads_anim.cpp index ce956c4f75..0ada527875 100644 --- a/engines/m4/mads_anim.cpp +++ b/engines/m4/mads_anim.cpp @@ -25,6 +25,7 @@ #include "m4/mads_anim.h" #include "m4/m4.h" +#include "m4/compression.h" namespace M4 { @@ -491,8 +492,6 @@ void AnimviewView::setScript(const char *resourceName, AnimviewCallback callback strcat(_resourceName, ".res"); _script = _vm->res()->get(_resourceName); - - processLines(); } bool AnimviewView::onEvent(M4EventType eventType, int param, int x, int y, bool &captureEvents) { @@ -508,37 +507,97 @@ bool AnimviewView::onEvent(M4EventType eventType, int param, int x, int y, bool } void AnimviewView::updateState() { - char bgFile[10]; - int bgNumber = 0; + if (!_script) + return; // Only update state if wait period has expired if (_previousUpdate > 0) { - if (g_system->getMillis() - _previousUpdate < 3000) { + if (g_system->getMillis() - _previousUpdate < 100) return; - } else { - // time for an update - _previousUpdate = g_system->getMillis(); - } - } else { + _previousUpdate = g_system->getMillis(); - return; } - strncpy(bgFile, _currentFile, 5); - bgFile[0] = bgFile[2]; - bgFile[1] = bgFile[3]; - bgFile[2] = bgFile[4]; - bgFile[3] = '\0'; - bgNumber = atoi(bgFile); - sprintf(bgFile, "rm%i.art", bgNumber); + // Check if we're ready for the next command + bool animRunning = false; + if (!animRunning) { + if (_script->eos() || _script->err()) { + scriptDone(); + return; + } + + readNextCommand(); + + // FIXME: Replace flag with proper animation end check + animRunning = true; + } +} + +void AnimviewView::readNextCommand() { + while (!_script->eos() && !_script->err()) { + strncpy(_currentLine, _script->readLine().c_str(), 79); + + // Process any switches on the line + char *cStart = strchr(_currentLine, '-'); + while (cStart) { + // Loop for possible multiple commands on one line + char *cEnd = strchr(_currentLine, ' '); + if (!cEnd) + error("Unterminated command '%s' in response file", _currentLine); + + *cEnd = '\0'; + processCommand(); + + // Copy rest of line (if any) to start of buffer + // Don't use strcpy() here, because if the + // rest of the line is the longer of the two + // strings, the memory areas will overlap. + memmove(_currentLine, cEnd + 1, strlen(cEnd + 1) + 1); + + cStart = strchr(_currentLine, '-'); + } + + // If there's something left, presume it's a resource name to process + if (_currentLine[0]) + break; + } + + if (strchr(_currentLine, '.') == NULL) + strcat(_currentLine, ".aa"); + + AAFile aaFile(_currentLine, _vm); + + // Initial validation + if (aaFile.flags & AA_HAS_FONT) { + assert(_vm->_resourceManager->resourceExists(aaFile.fontResource.c_str())); + } + + for (int seriesCtr = 0; seriesCtr < aaFile.seriesCount; ++seriesCtr) + assert(_vm->_resourceManager->resourceExists(aaFile.filenames[seriesCtr].c_str())); + + // Start sound + if (aaFile.flags & AA_HAS_SOUND) + { + char buffer[100]; + strcpy(buffer, aaFile.soundName.c_str()); + buffer[0] = 'A'; // A for Adlib resource + + Common::SeekableReadStream *stream = _vm->_resourceManager->get(buffer); + + _vm->_resourceManager->toss(buffer); + } + + + char artFile[80]; + sprintf(artFile, "rm%d.art", aaFile.roomNumber); // Not all scenes have a background. If there is one, refresh it - if (_vm->_resourceManager->resourceExists(bgFile)) { + if (_vm->_resourceManager->resourceExists(artFile)) { if (_palData) { _vm->_palette->deleteRange(_palData); delete _palData; } - _bgSurface.loadBackground(bgNumber, &_palData); + _bgSurface.loadBackground(aaFile.roomNumber, &_palData); _vm->_palette->addRange(_palData); _bgSurface.translate(_palData); } @@ -581,10 +640,10 @@ void AnimviewView::updateState() { int yp = (height() - _bgSurface.height()) / 2; _bgSurface.copyTo(this, 0, yp); - // Read next line - processLines(); + _vm->_resourceManager->toss(_currentLine); } + void AnimviewView::scriptDone() { AnimviewCallback fn = _callback; M4Engine *vm = _vm; @@ -596,52 +655,6 @@ void AnimviewView::scriptDone() { fn(vm); } -void AnimviewView::processLines() { - strncpy(_currentLine, _script->readLine().c_str(), 79); - if (_script->eos() || _script->err()) { - // end of script, end animation - scriptDone(); - return; - } - - while (!_script->eos() && !_script->err()) { - // Process the line - char *cStart = strchr(_currentLine, '-'); - if (cStart) { - while (cStart) { - // Loop for possible multiple commands on one line - char *cEnd = strchr(_currentLine, ' '); - if (!cEnd) - error("Unterminated command '%s' in response file", _currentLine); - - *cEnd = '\0'; - processCommand(); - - // Copy rest of line (if any) to start of buffer - // Don't use strcpy() here, because if the - // rest of the line is the longer of the two - // strings, the memory areas will overlap. - memmove(_currentLine, cEnd + 1, strlen(cEnd + 1) + 1); - - cStart = strchr(_currentLine, '-'); - } - - if (_currentLine[0]) { - sprintf(_currentFile, "%s", _currentLine); - //printf("File: %s\n", _currentLine); - break; - } - - } else { - sprintf(_currentFile, "%s", _currentLine); - //printf("File: %s\n", _currentLine); - break; - } - - strncpy(_currentLine, _script->readLine().c_str(), 79); - } -} - /* Switches are: (taken from the help of the original executable) -b Toggle background load status off/on. @@ -705,4 +718,45 @@ void AnimviewView::processCommand() { } } +AAFile::AAFile(const char *resourceName, M4Engine* vm): MadsPack(resourceName, vm) { + Common::MemoryReadStream stream1(*getItemStream(1)); + Common::MemoryReadStream stream2(*getItemStream(2)); + + Common::MemoryReadStream stream(*getItemStream(0)); +printf("ss %d %d %d\n", stream.size(), stream1.size(), stream2.size()); + seriesCount = stream.readUint16LE(); + frameCount = stream.readUint16LE(); + frameEntryCount = stream.readUint16LE(); + stream.skip(3); + flags = stream.readByte(); + stream.skip(4); + roomNumber = stream.readUint16LE(); + stream.skip(10); + frameTicks = stream.readUint16LE(); + + stream.skip(21); + for (int i = 0; i < 10; ++i) { + char filename[13]; + stream.read(filename, 13); + filenames.push_back(Common::String(filename, 13)); + } + + stream.skip(81); + char name[100]; + stream.read(name, 13); + lbmFilename = Common::String(name, 13); + + stream.skip(365); + stream.read(name, 13); + spritesFilename = Common::String(name, 13); + + stream.skip(48); + stream.read(name, 13); + soundName = Common::String(name, 13); + + stream.skip(26); + stream.read(name, 14); + fontResource = Common::String(name, 14); +} + } diff --git a/engines/m4/scene.h b/engines/m4/scene.h index 4cf05ddddd..671821b438 100644 --- a/engines/m4/scene.h +++ b/engines/m4/scene.h @@ -44,17 +44,17 @@ namespace M4 { #define MADS_SURFACE_HEIGHT 156 enum MADSVerbs { - kVerbLook = 2, - kVerbTake = 3, - kVerbPush = 4, - kVerbOpen = 5, - kVerbPut = 6, - kVerbTalkTo = 7, - kVerbGive = 8, - kVerbPull = 9, - kVerbClose = 10, - kVerbThrow = 11, - kVerbWalkTo = 12 + kVerbLook = 3, + kVerbTake = 4, + kVerbPush = 5, + kVerbOpen = 6, + kVerbPut = 7, + kVerbTalkTo = 8, + kVerbGive = 9, + kVerbPull = 10, + kVerbClose = 11, + kVerbThrow = 12, + kVerbWalkTo = 13 }; struct SceneResources { |