From bcdd8f43cd126253069a111ecb62c5137ec033ca Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 31 Mar 2013 12:56:12 -0400 Subject: HOPKINS: Refactored use of TEMP.SCR for screen backups to use a memory buffer --- engines/hopkins/anim.cpp | 17 +++++------------ engines/hopkins/graphics.cpp | 28 ++++++++++++++++++++++++++++ engines/hopkins/graphics.h | 3 +++ engines/hopkins/objects.cpp | 5 ++--- engines/hopkins/talk.cpp | 16 ++++------------ 5 files changed, 42 insertions(+), 27 deletions(-) (limited to 'engines') diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp index 1263f6281b..37eb4adc73 100644 --- a/engines/hopkins/anim.cpp +++ b/engines/hopkins/anim.cpp @@ -222,10 +222,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u while (!_vm->shouldQuit()) { memcpy(_vm->_graphicsManager->_oldPalette, _vm->_graphicsManager->_palette, 769); - if (_vm->_graphicsManager->_lineNbr == SCREEN_WIDTH) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 307200); - else if (_vm->_graphicsManager->_lineNbr == (SCREEN_WIDTH * 2)) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 614400); + _vm->_graphicsManager->backupScreen(); if (!_vm->_graphicsManager->_lineNbr) _vm->_graphicsManager->_scrollOffset = 0; @@ -344,8 +341,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u } _vm->_graphicsManager->_fadingFl = false; - _vm->_saveLoadManager->load("TEMP.SCR", _vm->_graphicsManager->_backBuffer); - g_system->getSavefileManager()->removeSavefile("TEMP.SCR"); + _vm->_graphicsManager->restoreScreen(); memcpy(_vm->_graphicsManager->_palette, _vm->_graphicsManager->_oldPalette, 769); _vm->_graphicsManager->clearPalette(); @@ -575,10 +571,8 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui if (!noColFl) { _vm->_eventsManager->refreshScreenAndEvents(); - if (_vm->_graphicsManager->_lineNbr == SCREEN_WIDTH) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 307200); - else if (_vm->_graphicsManager->_lineNbr == (SCREEN_WIDTH * 2)) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 614400); + _vm->_graphicsManager->backupScreen(); + if (!_vm->_graphicsManager->_lineNbr) _vm->_graphicsManager->_scrollOffset = 0; } @@ -691,8 +685,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui f.close(); if (!noColFl) { - _vm->_saveLoadManager->load("TEMP.SCR", _vm->_graphicsManager->_backBuffer); - g_system->getSavefileManager()->removeSavefile("TEMP.SCR"); + _vm->_graphicsManager->restoreScreen(); _vm->_eventsManager->_mouseFl = true; } diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp index ee2c75cf55..7eeb5e5b3e 100644 --- a/engines/hopkins/graphics.cpp +++ b/engines/hopkins/graphics.cpp @@ -52,6 +52,7 @@ GraphicsManager::GraphicsManager(HopkinsEngine *vm) { _backBuffer = NULL; _frontBuffer = NULL; _screenBuffer = g_PTRNUL; + _backupScreen = g_PTRNUL; _showDirtyRects = false; _lineNbr2 = 0; @@ -97,6 +98,7 @@ GraphicsManager::~GraphicsManager() { _vm->_globals->freeMemory(_backBuffer); _vm->_globals->freeMemory(_frontBuffer); _vm->_globals->freeMemory(_screenBuffer); + _vm->_globals->freeMemory(_backupScreen); } void GraphicsManager::setGraphicalMode(int width, int height) { @@ -1826,4 +1828,30 @@ void GraphicsManager::drawVerticalLine(byte *surface, int xp, int yp, int height } } +/** + * Backup the current screen + */ +void GraphicsManager::backupScreen() { + // Allocate a new data block for the screen, if necessary + if (_vm->_graphicsManager->_backupScreen == g_PTRNUL) + _vm->_graphicsManager->_backupScreen = _vm->_globals->allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT); + + // Backup the screen + Common::copy(_vm->_graphicsManager->_backBuffer, _vm->_graphicsManager->_backBuffer + + SCREEN_WIDTH * 2 * SCREEN_HEIGHT, _vm->_graphicsManager->_backupScreen); +} + +/** + * Restore a previously backed up screen + */ +void GraphicsManager::restoreScreen() { + assert(_vm->_graphicsManager->_backupScreen != g_PTRNUL); + + // Restore the screen and free the buffer + Common::copy(_vm->_graphicsManager->_backupScreen, _vm->_graphicsManager->_backupScreen + + SCREEN_WIDTH * 2 * SCREEN_HEIGHT, _vm->_graphicsManager->_backBuffer); + _vm->_globals->freeMemory(_vm->_graphicsManager->_backupScreen); + _backupScreen = g_PTRNUL; +} + } // End of namespace Hopkins diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h index 8009a366b9..bc8bb19c3f 100644 --- a/engines/hopkins/graphics.h +++ b/engines/hopkins/graphics.h @@ -90,6 +90,7 @@ public: byte *_backBuffer; byte *_frontBuffer; byte *_screenBuffer; + byte *_backupScreen; bool _largeScreenFl; bool _noFadingFl; bool _fadingFl; @@ -177,6 +178,8 @@ public: void m_scroll16(const byte *surface, int xs, int ys, int width, int height, int destX, int destY); void Trans_bloc2(byte *surface, byte *col, int size); void NB_SCREEN(bool initPalette); + void backupScreen(); + void restoreScreen(); }; } // End of namespace Hopkins diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp index 734d44da4c..7b0e57c9d7 100644 --- a/engines/hopkins/objects.cpp +++ b/engines/hopkins/objects.cpp @@ -2653,7 +2653,7 @@ void ObjectsManager::handleSpecialGames() { oldPalette = _vm->_globals->allocMemory(1000); memcpy(oldPalette, _vm->_graphicsManager->_palette, 769); - _vm->_saveLoadManager->saveFile("TEMP1.SCR", _vm->_graphicsManager->_backBuffer, 307200); + _vm->_graphicsManager->backupScreen(); if (!_vm->_graphicsManager->_lineNbr) _vm->_graphicsManager->_scrollOffset = 0; @@ -2665,8 +2665,7 @@ void ObjectsManager::handleSpecialGames() { _vm->_soundManager->_specialSoundNum = 0; _vm->_graphicsManager->NB_SCREEN(false); - _vm->_saveLoadManager->load("TEMP1.SCR", _vm->_graphicsManager->_backBuffer); - g_system->getSavefileManager()->removeSavefile("TEMP1.SCR"); + _vm->_graphicsManager->restoreScreen(); _charactersEnabledFl = false; memcpy(_vm->_graphicsManager->_palette, oldPalette, 769); diff --git a/engines/hopkins/talk.cpp b/engines/hopkins/talk.cpp index 455ead6b9b..a69ae59c94 100644 --- a/engines/hopkins/talk.cpp +++ b/engines/hopkins/talk.cpp @@ -83,10 +83,7 @@ void TalkManager::startAnimatedCharacterDialogue(const Common::String &filename) _characterSprite = _vm->_objectsManager->loadSprite("RES_SAN.RES"); } - if (_vm->_graphicsManager->_lineNbr == SCREEN_WIDTH) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 307200); - else if (_vm->_graphicsManager->_lineNbr == (SCREEN_WIDTH * 2)) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 614400); + _vm->_graphicsManager->backupScreen(); if (!_vm->_graphicsManager->_lineNbr) _vm->_graphicsManager->_scrollOffset = 0; @@ -126,8 +123,7 @@ void TalkManager::startAnimatedCharacterDialogue(const Common::String &filename) _characterSprite = _vm->_globals->freeMemory(_characterSprite); _vm->_graphicsManager->NB_SCREEN(false); - _vm->_saveLoadManager->load("TEMP.SCR", _vm->_graphicsManager->_backBuffer); - g_system->getSavefileManager()->removeSavefile("TEMP.SCR"); + _vm->_graphicsManager->restoreScreen(); _vm->_objectsManager->_charactersEnabledFl = false; _vm->_eventsManager->_mouseCursorId = oldMouseCursorId; @@ -997,10 +993,7 @@ void TalkManager::animateObject(const Common::String &filename) { else _characterSprite = _vm->_objectsManager->loadSprite("RES_SAN.RES"); - if (_vm->_graphicsManager->_lineNbr == SCREEN_WIDTH) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 307200); - else if (_vm->_graphicsManager->_lineNbr == (SCREEN_WIDTH * 2)) - _vm->_saveLoadManager->saveFile("TEMP.SCR", _vm->_graphicsManager->_backBuffer, 614400); + _vm->_graphicsManager->backupScreen(); if (!_vm->_graphicsManager->_lineNbr) _vm->_graphicsManager->_scrollOffset = 0; @@ -1060,8 +1053,7 @@ void TalkManager::animateObject(const Common::String &filename) { if (_vm->_globals->_exitId == 101) _vm->_globals->_exitId = 0; - _vm->_saveLoadManager->load("TEMP.SCR", _vm->_graphicsManager->_backBuffer); - g_system->getSavefileManager()->removeSavefile("TEMP.SCR"); + _vm->_graphicsManager->restoreScreen(); _vm->_objectsManager->_charactersEnabledFl = false; _vm->_eventsManager->_mouseCursorId = 4; -- cgit v1.2.3