From 92cc2a7bc8f844a49b7e43840282ca6c57a7a80b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 28 Jun 2014 22:40:25 -0400 Subject: MADS: Create savegame thumbnail from scenes before opening in-game dialogs --- engines/mads/game.cpp | 36 +++++++++++++++++++++++++---------- engines/mads/game.h | 6 ++++++ engines/mads/nebular/game_nebular.cpp | 6 ++++++ engines/mads/scene.cpp | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 8639f59418..dde2b405ab 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -64,6 +64,7 @@ Game::Game(MADSEngine *vm) _loadGameSlot = -1; _lastSave = -1; _saveFile = nullptr; + _saveThumb = nullptr; _statusFlag = 0; _sectionHandler = nullptr; _sectionNumber = 1; @@ -93,6 +94,11 @@ Game::Game(MADSEngine *vm) } Game::~Game() { + if (_saveThumb) { + _saveThumb->free(); + delete _saveThumb; + } + delete _saveFile; delete _surface; delete _sectionHandler; @@ -548,16 +554,14 @@ void Game::writeSavegameHeader(Common::OutSaveFile *out, MADSSavegameHeader &hea out->write(header._saveName.c_str(), header._saveName.size()); out->writeByte('\0'); - // Get the active palette - uint8 thumbPalette[256 * 3]; - g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256); - - // Create a thumbnail and save it - Graphics::Surface *thumb = new Graphics::Surface(); - ::createThumbnail(thumb, _vm->_screen.getData(), MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT, thumbPalette); - Graphics::saveThumbnail(*out, *thumb); - thumb->free(); - delete thumb; + // Handle the thumbnail. If there's already one set by the game, create one + if (!_saveThumb) + createThumbnail(); + Graphics::saveThumbnail(*out, *_saveThumb); + + _saveThumb->free(); + delete _saveThumb; + _saveThumb = nullptr; // Write out the save date/time TimeDate td; @@ -570,4 +574,16 @@ void Game::writeSavegameHeader(Common::OutSaveFile *out, MADSSavegameHeader &hea out->writeUint32LE(_vm->_events->getFrameCounter()); } +void Game::createThumbnail() { + if (_saveThumb) { + _saveThumb->free(); + delete _saveThumb; + } + + uint8 thumbPalette[256 * 3]; + _vm->_palette->grabPalette(thumbPalette, 0, 256); + _saveThumb = new Graphics::Surface(); + ::createThumbnail(_saveThumb, _vm->_screen.getData(), MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT, thumbPalette); +} + } // End of namespace MADS diff --git a/engines/mads/game.h b/engines/mads/game.h index 08cd7e7843..1a61fc8ac8 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -82,6 +82,7 @@ protected: int _lastSave; Common::String _saveName; Common::InSaveFile *_saveFile; + Graphics::Surface *_saveThumb; /** * Constructor @@ -226,6 +227,11 @@ public: * Read in a savegame header */ static bool readSavegameHeader(Common::InSaveFile *in, MADSSavegameHeader &header); + + /** + * Creates a temporary thumbnail for use in saving games + */ + void createThumbnail(); }; } // End of namespace MADS diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index d6d7a07e52..8fddf8b9c4 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -22,6 +22,7 @@ #include "common/scummsys.h" #include "common/config-manager.h" +#include "graphics/scaler.h" #include "mads/mads.h" #include "mads/game.h" #include "mads/screen.h" @@ -310,6 +311,11 @@ void GameNebular::setSectionHandler() { void GameNebular::checkShowDialog() { if (_vm->_dialogs->_pendingDialog && _player._stepEnabled && !_globals[kCopyProtectFailed]) { _player.releasePlayerSprites(); + + // Make a thumbnail in case it's needed for making a savegame + _vm->_game->createThumbnail(); + + // Show the dialog _vm->_dialogs->showDialog(); _vm->_dialogs->_pendingDialog = DIALOG_NONE; } diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index ffeed6cda8..639f297f86 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -346,7 +346,7 @@ void Scene::loop() { // Handle drawing a game frame doFrame(); - // TODO: Verify correctness of frame wait + // Wait for the next frame _vm->_events->waitForNextFrame(); if (_vm->_dialogs->_pendingDialog != DIALOG_NONE && !_vm->_game->_trigger -- cgit v1.2.3