aboutsummaryrefslogtreecommitdiff
path: root/engines/gob
diff options
context:
space:
mode:
authorSven Hesse2011-01-27 13:27:58 +0000
committerSven Hesse2011-01-27 13:27:58 +0000
commiteb3667d7c9efcefe3a9e4e57edc3aefa603d6416 (patch)
tree138802865180f9034aa174868781e276e5089296 /engines/gob
parent95ed10addee68cc91c2e2b8f2450b63022c61162 (diff)
downloadscummvm-rg350-eb3667d7c9efcefe3a9e4e57edc3aefa603d6416.tar.gz
scummvm-rg350-eb3667d7c9efcefe3a9e4e57edc3aefa603d6416.tar.bz2
scummvm-rg350-eb3667d7c9efcefe3a9e4e57edc3aefa603d6416.zip
GOB: Implement backuping of sprites, sounds, fonts in totSub
svn-id: r55565
Diffstat (limited to 'engines/gob')
-rw-r--r--engines/gob/game.cpp94
-rw-r--r--engines/gob/game.h13
2 files changed, 105 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();
}
diff --git a/engines/gob/game.h b/engines/gob/game.h
index 186afdee1a..7f8bf67153 100644
--- a/engines/gob/game.h
+++ b/engines/gob/game.h
@@ -27,6 +27,8 @@
#define GOB_GAME_H
#include "gob/util.h"
+#include "gob/video.h"
+#include "gob/sound/sounddesc.h"
namespace Gob {
@@ -53,6 +55,10 @@ public:
void clear();
+ bool setMedia(uint8 env);
+ bool getMedia(uint8 env);
+ bool clearMedia(uint8 env);
+
private:
struct Environment {
int32 cursorHotspotX;
@@ -63,9 +69,16 @@ private:
Resources *resources;
};
+ struct Media {
+ SurfacePtr sprites[10];
+ SoundDesc sounds[10];
+ Font *fonts[17];
+ };
+
GobEngine *_vm;
Environment _environments[kEnvironmentCount];
+ Media _media[kEnvironmentCount];
};
class Game {