From c1a90cdda1f1424cb9b6b2e91b82c47cf0913335 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 23 Apr 2014 21:01:48 -0400 Subject: MADS: Further synchronization implementation --- engines/mads/game.cpp | 1 + engines/mads/globals.cpp | 23 +++++++++++++++++++++-- engines/mads/globals.h | 10 ++++++++-- engines/mads/nebular/game_nebular.cpp | 8 ++++++++ engines/mads/nebular/game_nebular.h | 2 ++ engines/mads/nebular/globals_nebular.cpp | 2 +- engines/mads/scene.cpp | 1 + engines/mads/user_interface.cpp | 8 ++++++++ engines/mads/user_interface.h | 5 +++++ 9 files changed, 55 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 3b591d7a9e..462c6401a9 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -408,6 +408,7 @@ void Game::synchronize(Common::Serializer &s, bool phase1) { if (s.isLoading()) { _sectionNumber = _scene._nextSceneId / 100; _currentSectionNumber = _sectionNumber; + _scene._frameStartTime = _vm->_events->getFrameCounter(); } } else { s.syncAsByte(_difficulty); diff --git a/engines/mads/globals.cpp b/engines/mads/globals.cpp index 68a2cf1970..de15ba9595 100644 --- a/engines/mads/globals.cpp +++ b/engines/mads/globals.cpp @@ -26,8 +26,27 @@ namespace MADS { void Globals::reset() { - for (uint i = 0; i < _flags.size(); ++i) - _flags[i] = 0; + for (uint i = 0; i < _data.size(); ++i) + _data[i] = 0; +} + +void Globals::synchronize(Common::Serializer &s) { + int count = 0; + int16 v; + s.syncAsUint16LE(count); + + if (s.isSaving()) { + for (int idx = 0; idx < count; ++idx) { + v = _data[idx]; + s.syncAsSint16LE(v); + } + } else { + _data.clear(); + for (int idx = 0; idx < count; ++idx) { + s.syncAsSint16LE(v); + _data.push_back(v); + } + } } diff --git a/engines/mads/globals.h b/engines/mads/globals.h index ea327b0045..fa7a630f7f 100644 --- a/engines/mads/globals.h +++ b/engines/mads/globals.h @@ -25,24 +25,30 @@ #include "common/scummsys.h" #include "common/array.h" +#include "common/serializer.h" namespace MADS { class Globals { protected: - Common::Array _flags; + Common::Array _data; public: Globals() {} /** * Square brackets operator for accessing flags */ - int16 &operator[](int idx) { return _flags[idx]; } + int16 &operator[](int idx) { return _data[idx]; } /* * Resets all the globals to empty */ void reset(); + + /** + * Synchronize the globals data + */ + void synchronize(Common::Serializer &s); }; } // End of namespace MADS diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index 23c8b3cdd6..34eb6f140c 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -744,6 +744,14 @@ void GameNebular::step() { } } +void GameNebular::synchronize(Common::Serializer &s, bool phase1) { + Game::synchronize(s, phase1); + + if (!phase1) { + _globals.synchronize(s); + } +} + } // End of namespace Nebular } // End of namespace MADS diff --git a/engines/mads/nebular/game_nebular.h b/engines/mads/nebular/game_nebular.h index 7d64e3e49f..0e2d564236 100644 --- a/engines/mads/nebular/game_nebular.h +++ b/engines/mads/nebular/game_nebular.h @@ -73,6 +73,8 @@ public: virtual void unhandledAction(); virtual void step(); + + virtual void synchronize(Common::Serializer &s, bool phase1); }; diff --git a/engines/mads/nebular/globals_nebular.cpp b/engines/mads/nebular/globals_nebular.cpp index 3e9a9f7e2f..a8b7cdce72 100644 --- a/engines/mads/nebular/globals_nebular.cpp +++ b/engines/mads/nebular/globals_nebular.cpp @@ -30,7 +30,7 @@ namespace Nebular { NebularGlobals::NebularGlobals(): Globals() { // Initialize lists - _flags.resize(210); + _data.resize(210); _spriteIndexes.resize(30); _sequenceIndexes.resize(30); diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 239a91c585..24218479ce 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -684,6 +684,7 @@ void Scene::freeAnimation() { void Scene::synchronize(Common::Serializer &s) { _action._activeAction.synchronize(s); _rails.synchronize(s); + _userInterface.synchronize(s); } } // End of namespace MADS diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index 493804c923..9a63ac32ad 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -1079,4 +1079,12 @@ void UserInterface::scrollInventory() { _vm->_game->_screenObjects._v8332A = 0; } +void UserInterface::synchronize(Common::Serializer &s) { + InventoryObjects &invObjects = _vm->_game->_objects; + + if (s.isLoading()) { + _selectedInvIndex = invObjects._inventoryList.empty() ? -1 : 0; + } +} + } // End of namespace MADS diff --git a/engines/mads/user_interface.h b/engines/mads/user_interface.h index baae269c4f..1e07681a6f 100644 --- a/engines/mads/user_interface.h +++ b/engines/mads/user_interface.h @@ -293,6 +293,11 @@ public: * Add a msesage to the list of conversation items to select from */ void addConversationMessage(int vocabId, const Common::String &msg); + + /** + * Synchronize the data + */ + void synchronize(Common::Serializer &s); }; } // End of namespace MADS -- cgit v1.2.3