diff options
author | Martin Kiewitz | 2016-02-13 20:42:30 +0100 |
---|---|---|
committer | Martin Kiewitz | 2016-02-13 20:42:30 +0100 |
commit | 9f59b5ed7c3130bd7b0060e770a9ec915a91a891 (patch) | |
tree | a25c0a9be25596fa1c236fb2a49879253a27e0e2 /engines/agi | |
parent | 94e5804b84e3e165055fd210f002279d0deb1bb0 (diff) | |
download | scummvm-rg350-9f59b5ed7c3130bd7b0060e770a9ec915a91a891.tar.gz scummvm-rg350-9f59b5ed7c3130bd7b0060e770a9ec915a91a891.tar.bz2 scummvm-rg350-9f59b5ed7c3130bd7b0060e770a9ec915a91a891.zip |
AGI: Fix priority band handling
- Fix saving/loading priority bands table. Now saving the actual raw
data
- Now also saving the flag, that defines if the priority table got
modified by scripts
- For older saved games it will try to figure out the state of that
flag
- Blocking set.pri.base for AGI below 2.936
- set.pri.base was actually introduced in 2.936 and not AGI3
- The set.pri.base bug was present in 2.936 as well
- Saved games created between the graphics rewrite and this
commit may have priority issues for games, that used AGI2.936+
Diffstat (limited to 'engines/agi')
-rw-r--r-- | engines/agi/graphics.cpp | 35 | ||||
-rw-r--r-- | engines/agi/graphics.h | 8 | ||||
-rw-r--r-- | engines/agi/op_cmd.cpp | 6 | ||||
-rw-r--r-- | engines/agi/opcodes.cpp | 4 | ||||
-rw-r--r-- | engines/agi/saveload.cpp | 55 |
5 files changed, 83 insertions, 25 deletions
diff --git a/engines/agi/graphics.cpp b/engines/agi/graphics.cpp index b0165154c8..abe3dc707e 100644 --- a/engines/agi/graphics.cpp +++ b/engines/agi/graphics.cpp @@ -750,10 +750,15 @@ void GfxMgr::updateScreen() { } void GfxMgr::initPriorityTable() { + _priorityTableSet = false; + + createDefaultPriorityTable(_priorityTable); +} + +void GfxMgr::createDefaultPriorityTable(uint8 *priorityTable) { int16 priority, step; int16 yPos = 0; - _priorityTableSet = false; for (priority = 1; priority < 15; priority++) { for (step = 0; step < 12; step++) { _priorityTable[yPos++] = priority < 4 ? 4 : priority; @@ -775,11 +780,35 @@ void GfxMgr::setPriorityTable(int16 priorityBase) { } } +// used for saving +int16 GfxMgr::saveLoadGetPriority(int16 yPos) { + assert(yPos < SCRIPT_HEIGHT); + return _priorityTable[yPos]; +} +bool GfxMgr::saveLoadWasPriorityTableModified() { + return _priorityTableSet; +} + // used for restoring -void GfxMgr::setPriority(int16 yPos, int16 priority) { +void GfxMgr::saveLoadSetPriority(int16 yPos, int16 priority) { assert(yPos < SCRIPT_HEIGHT); _priorityTable[yPos] = priority; } +void GfxMgr::saveLoadSetPriorityTableModifiedBool(bool wasModified) { + _priorityTableSet = wasModified; +} +void GfxMgr::saveLoadFigureOutPriorityTableModifiedBool() { + uint8 defaultPriorityTable[SCRIPT_HEIGHT]; /**< priority table */ + + createDefaultPriorityTable(defaultPriorityTable); + + if (memcmp(defaultPriorityTable, _priorityTable, sizeof(_priorityTable)) == 0) { + // Match, it is the default table, so reset the flag + _priorityTableSet = false; + } else { + _priorityTableSet = true; + } +} /** * Convert sprite priority to y value. @@ -792,7 +821,7 @@ int16 GfxMgr::priorityToY(int16 priority) { return (priority - 5) * 12 + 48; } - // dynamic priority bands were introduced in 3.002.086 (effectively AGI3) + // dynamic priority bands were introduced in 2.936 (effectively last version of AGI2) // It seems there was a glitch, that caused priority bands to not get calculated properly. // It was caused by this function starting with Y = 168 instead of 167, which meant it always // returned with 168 as result. diff --git a/engines/agi/graphics.h b/engines/agi/graphics.h index 6f6a1656f4..3f94b3e950 100644 --- a/engines/agi/graphics.h +++ b/engines/agi/graphics.h @@ -140,8 +140,14 @@ public: void updateScreen(); void initPriorityTable(); + void createDefaultPriorityTable(uint8 *priorityTable); void setPriorityTable(int16 priorityBase); - void setPriority(int16 yPos, int16 priority); + bool saveLoadWasPriorityTableModified(); + int16 saveLoadGetPriority(int16 yPos); + void saveLoadSetPriorityTableModifiedBool(bool wasModified); + void saveLoadSetPriority(int16 yPos, int16 priority); + void saveLoadFigureOutPriorityTableModifiedBool(); + int16 priorityToY(int16 priority); int16 priorityFromY(int16 yPos); }; diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp index 4339bf2712..8b24d250b1 100644 --- a/engines/agi/op_cmd.cpp +++ b/engines/agi/op_cmd.cpp @@ -2180,6 +2180,12 @@ void cmdPushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdSetPriBase(AgiGame *state, AgiEngine *vm, uint8 *parameter) { + if (getVersion() < 0x2936) { + // was not available before 2.936 (last AGI2 version) + warning("set.pri.base called, although not available for current AGI version"); + return; + } + uint16 priorityBase = parameter[0]; debug(0, "Priority base set to %d", priorityBase); diff --git a/engines/agi/opcodes.cpp b/engines/agi/opcodes.cpp index 359d79ee4a..78beb475ee 100644 --- a/engines/agi/opcodes.cpp +++ b/engines/agi/opcodes.cpp @@ -347,9 +347,9 @@ AgiInstruction insV2[] = { { "push.script", "", &cmdPushScript }, // BB { "pop.script", "", &cmdPopScript }, // BC { "hold.key", "", &cmdHoldKey }, // BD - { "set.pri.base", "n", &cmdSetPriBase }, // BE + { "set.pri.base", "n", &cmdSetPriBase }, // BE // AGI2.936+ { "discard.sound", "n", &cmdDiscardSound }, // BF - { "hide.mouse", "", &cmdHideMouse }, // 1 arg for AGI version 3.002.086 + { "hide.mouse", "", &cmdHideMouse }, // 1 arg for AGI version 3.002.086 AGI3+ only starts here { "allow.menu", "n", &cmdAllowMenu }, // C1 { "show.mouse", "", &cmdShowMouse }, // C2 { "fence.mouse", "nnnn", &cmdFenceMouse }, // C3 diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index e22b127021..5f1c5112cd 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -45,24 +45,25 @@ #include "agi/systemui.h" #include "agi/words.h" -#define SAVEGAME_CURRENT_VERSION 9 +#define SAVEGAME_CURRENT_VERSION 10 // -// Version 0 (Sarien): view table has 64 entries -// Version 1 (Sarien): view table has 256 entries (needed in KQ3) -// Version 2 (ScummVM): first ScummVM version -// Version 3 (ScummVM): added AGIPAL save/load support -// Version 4 (ScummVM): added thumbnails and save creation date/time -// Version 5 (ScummVM): Added game md5 -// Version 6 (ScummVM): Added game played time -// Version 7 (ScummVM): Added controller key mappings -// required for some games for quick-loading from ScummVM main menu -// for games, that do not set all key mappings right at the start -// Added automatic save data (for command SetSimple) -// Version 8 (ScummVM): Added Hold-Key-Mode boolean -// required for at least Mixed Up Mother Goose -// gets set at the start of the game only -// Version 9 (ScummVM): Added seconds to saved game time stamp +// Version 0 (Sarien): view table has 64 entries +// Version 1 (Sarien): view table has 256 entries (needed in KQ3) +// Version 2 (ScummVM): first ScummVM version +// Version 3 (ScummVM): added AGIPAL save/load support +// Version 4 (ScummVM): added thumbnails and save creation date/time +// Version 5 (ScummVM): Added game md5 +// Version 6 (ScummVM): Added game played time +// Version 7 (ScummVM): Added controller key mappings +// required for some games for quick-loading from ScummVM main menu +// for games, that do not set all key mappings right at the start +// Added automatic save data (for command SetSimple) +// Version 8 (ScummVM): Added Hold-Key-Mode boolean +// required for at least Mixed Up Mother Goose +// gets set at the start of the game only +// Version 9 (ScummVM): Added seconds to saved game time stamp +// Version 10 (ScummVM): Added priorityTableSet boolean namespace Agi { @@ -174,9 +175,11 @@ int AgiEngine::saveGame(const Common::String &fileName, const Common::String &de out->writeSint16BE(0); } - // TODO: save if priority table was modified for (i = 0; i < SCRIPT_HEIGHT; i++) - out->writeByte(_gfx->priorityFromY(i)); + out->writeByte(_gfx->saveLoadGetPriority(i)); + + // Version 10+: Save, if priority table got modified (set.pri.base opcode) + out->writeSint16BE((int16)_gfx->saveLoadWasPriorityTableModified()); out->writeSint16BE((int16)_game.gfxMode); out->writeByte(_text->inputGetCursorChar()); @@ -500,7 +503,21 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) { } for (i = 0; i < SCRIPT_HEIGHT; i++) - _gfx->setPriority(i, in->readByte()); + _gfx->saveLoadSetPriority(i, in->readByte()); + + if (saveVersion >= 10) { + // Version 10+: priority table was modified by scripts + int16 priorityTableWasModified = in->readSint16BE(); + + if (priorityTableWasModified) { + _gfx->saveLoadSetPriorityTableModifiedBool(true); + } else { + _gfx->saveLoadSetPriorityTableModifiedBool(false); + } + } else { + // Try to figure it out by ourselves + _gfx->saveLoadFigureOutPriorityTableModifiedBool(); + } _text->closeWindow(); |