diff options
Diffstat (limited to 'engines/gob/game.cpp')
-rw-r--r-- | engines/gob/game.cpp | 94 |
1 files changed, 92 insertions, 2 deletions
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp index 81ff66f100..2ee25b008d 100644 --- a/engines/gob/game.cpp +++ b/engines/gob/game.cpp @@ -46,6 +46,7 @@ namespace Gob { Environments::Environments(GobEngine *vm) : _vm(vm) { for (uint i = 0; i < kEnvironmentCount; i++) { Environment &e = _environments[i]; + Media &m = _media[i]; e.cursorHotspotX = 0; e.cursorHotspotY = 0; @@ -53,6 +54,9 @@ Environments::Environments(GobEngine *vm) : _vm(vm) { e.script = 0; e.resources = 0; e.curTotFile[0] = '\0'; + + for (int j = 0; j < 17; j++) + m.fonts[j] = 0; } } @@ -86,6 +90,9 @@ void Environments::clear() { if (!has(_environments[i].resources, i + 1)) delete _environments[i].resources; } + + for (uint i = 0; i < kEnvironmentCount; i++) + clearMedia(i); } void Environments::set(uint8 env) { @@ -165,6 +172,82 @@ bool Environments::has(Resources *resources, uint8 startEnv, int16 except) const return false; } +bool Environments::clearMedia(uint8 env) { + if (env >= kEnvironmentCount) + return false; + + Media &m = _media[env]; + + for (int i = 0; i < 10; i++) + m.sprites[i].reset(); + + for (int i = 0; i < 10; i++) + m.sounds[i].free(); + + for (int i = 0; i < 17; i++) { + delete m.fonts[i]; + m.fonts[i] = 0; + } + + return true; +} + +bool Environments::setMedia(uint8 env) { + if (env >= kEnvironmentCount) + return false; + + clearMedia(env); + + Media &m = _media[env]; + + for (int i = 0; i < 10; i++) { + m.sprites[i] = _vm->_draw->_spritesArray[i]; + _vm->_draw->_spritesArray[i].reset(); + } + + for (int i = 0; i < 10; i++) { + SoundDesc *sound = _vm->_sound->sampleGetBySlot(i); + if (sound) + m.sounds[i].swap(*sound); + } + + int n = MIN(Draw::kFontCount, 17); + for (int i = 0; i < n; i++) { + m.fonts[i] = _vm->_draw->_fonts[i]; + _vm->_draw->_fonts[i] = 0; + } + + return true; +} + +bool Environments::getMedia(uint8 env) { + if (env >= kEnvironmentCount) + return false; + + Media &m = _media[env]; + + for (int i = 0; i < 10; i++) { + _vm->_draw->_spritesArray[i] = m.sprites[i]; + m.sprites[i].reset(); + } + + for (int i = 0; i < 10; i++) { + SoundDesc *sound = _vm->_sound->sampleGetBySlot(i); + if (sound) + m.sounds[i].swap(*sound); + m.sounds[i].free(); + } + + int n = MIN(Draw::kFontCount, 17); + for (int i = 0; i < n; i++) { + delete _vm->_draw->_fonts[i]; + _vm->_draw->_fonts[i] = m.fonts[i]; + m.fonts[i]= 0; + } + + return true; +} + Game::Game(GobEngine *vm) : _vm(vm) { _captureCount = 0; @@ -572,8 +655,10 @@ void Game::totSub(int8 flags, const char *newTotFile) { _environments->set(_numEnvironments); - if (flags == 18) - warning("Game::totSub(): Backup media"); + if (flags == 18) { + warning("Backuping media to %d", _numEnvironments); + _environments->setMedia(_numEnvironments); + } curBackupPos = _curEnvironment; _numEnvironments++; @@ -621,6 +706,11 @@ void Game::totSub(int8 flags, const char *newTotFile) { _curEnvironment = curBackupPos; _environments->get(_numEnvironments); + if (flags == 18) { + warning("Restoring media from %d", _numEnvironments); + _environments->getMedia(_numEnvironments); + } + _vm->_global->_inter_animDataSize = _script->getAnimDataSize(); } |