diff options
Diffstat (limited to 'engines')
88 files changed, 1238 insertions, 585 deletions
diff --git a/engines/configure.engines b/engines/configure.engines index 3c2fc30dbb..1f2a31b382 100644 --- a/engines/configure.engines +++ b/engines/configure.engines @@ -42,7 +42,7 @@ add_engine sword25 "Broken Sword 2.5" no "" "" "png zlib 16bit" add_engine teenagent "Teen Agent" yes add_engine testbed "TestBed: the Testing framework" no add_engine tinsel "Tinsel" yes -add_engine toltecs "3 Skulls of the Toltecs" no +add_engine toltecs "3 Skulls of the Toltecs" yes add_engine toon "Toonstruck" yes add_engine touche "Touche: The Adventures of the Fifth Musketeer" yes add_engine tony "Tony Tough and the Night of Roasted Moths" yes "" "" "16bit" diff --git a/engines/kyra/detection_tables.h b/engines/kyra/detection_tables.h index 5b9d665a0e..d948f7d12d 100644 --- a/engines/kyra/detection_tables.h +++ b/engines/kyra/detection_tables.h @@ -53,7 +53,8 @@ namespace { #define LOL_FLOPPY_FLAGS FLAGS(false, false, false, false, false, false, false, false, Kyra::GI_LOL) #define LOL_FLOPPY_FAN_FLAGS(x, y) FLAGS_FAN(x, y, false, false, false, false, false, false, false, false, Kyra::GI_LOL) #define LOL_FLOPPY_CMP_FLAGS FLAGS(false, false, false, false, false, false, false, true, Kyra::GI_LOL) -#define LOL_PC98_SJIS_FLAGS FLAGS(false, false, false, false, true, true, false, false, Kyra::GI_LOL) +#define LOL_PC9801_FLAGS FLAGS(false, false, false, false, true, true, false, false, Kyra::GI_LOL) +#define LOL_FMTOWNS_FLAGS FLAGS(false, false, false, false, true, false, false, false, Kyra::GI_LOL) #define LOL_DEMO_FLAGS FLAGS(true, true, false, false, false, false, false, false, Kyra::GI_LOL) #define LOL_KYRA2_DEMO_FLAGS FLAGS(true, false, false, false, false, false, false, false, Kyra::GI_KYRA2) @@ -1462,7 +1463,24 @@ const KYRAGameDescription adGameDescs[] = { ADGF_NO_FLAGS, GUIO5(GUIO_NOSPEECH, GUIO_MIDIPC98, GUIO_RENDERPC9801, GAMEOPTION_LOL_SCROLLING, GAMEOPTION_LOL_CURSORS) }, - LOL_PC98_SJIS_FLAGS + LOL_PC9801_FLAGS + }, + + { + { + "lol", + 0, + { + { "GENERAL.PAK", 0, "2e4d4ce54bac9162e11fcba6907b576e", -1 }, + { "TMUS.PAK", 0, "5543dae575164e51856f5a49cfd6b368", -1 }, + { 0, 0, 0, 0 } + }, + Common::JA_JPN, + Common::kPlatformFMTowns, + ADGF_NO_FLAGS, + GUIO5(GUIO_NOSPEECH, GUIO_MIDITOWNS, GUIO_RENDERFMTOWNS, GAMEOPTION_LOL_SCROLLING, GAMEOPTION_LOL_CURSORS) + }, + LOL_FMTOWNS_FLAGS }, { diff --git a/engines/kyra/eobcommon.h b/engines/kyra/eobcommon.h index e42130cde0..70200d3049 100644 --- a/engines/kyra/eobcommon.h +++ b/engines/kyra/eobcommon.h @@ -722,21 +722,21 @@ protected: void gui_processWeaponSlotClickRight(int charIndex, int slotIndex); void gui_processInventorySlotClick(int slot); - static const int16 _buttonList1[]; + static const uint8 _buttonList1[]; int _buttonList1Size; - static const int16 _buttonList2[]; + static const uint8 _buttonList2[]; int _buttonList2Size; - static const int16 _buttonList3[]; + static const uint8 _buttonList3[]; int _buttonList3Size; - static const int16 _buttonList4[]; + static const uint8 _buttonList4[]; int _buttonList4Size; - static const int16 _buttonList5[]; + static const uint8 _buttonList5[]; int _buttonList5Size; - static const int16 _buttonList6[]; + static const uint8 _buttonList6[]; int _buttonList6Size; - static const int16 _buttonList7[]; + static const uint8 _buttonList7[]; int _buttonList7Size; - static const int16 _buttonList8[]; + static const uint8 _buttonList8[]; int _buttonList8Size; const EoBGuiButtonDef *_buttonDefs; diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp index 8b95230b88..f7a5386574 100644 --- a/engines/kyra/gui_lol.cpp +++ b/engines/kyra/gui_lol.cpp @@ -274,7 +274,7 @@ void LoLEngine::gui_printCharacterStats(int index, int redraw, int value) { if (offs) _screen->copyRegion(294, y, 182 + offs, y, 18, 8, 6, _screen->_curPage, Screen::CR_NO_P_CHECK); - Screen::FontId of = _flags.use16ColorMode ? _screen->setFont(Screen::FID_SJIS_FNT) : _screen->_currentFont; + Screen::FontId of = (_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? _screen->setFont(Screen::FID_SJIS_FNT) : _screen->_currentFont; _screen->fprintString("%d", 200 + offs, y, col, 0, _flags.use16ColorMode ? 2 : 6, value); _screen->setFont(of); } @@ -322,7 +322,7 @@ void LoLEngine::gui_changeCharacterStats(int charNum) { void LoLEngine::gui_drawCharInventoryItem(int itemIndex) { static const uint8 slotShapes[] = { 0x30, 0x34, 0x30, 0x34, 0x2E, 0x2F, 0x32, 0x33, 0x31, 0x35, 0x35 }; - + //2Eh, 32h, 2Eh, 32h, 2Ch, 2Dh, 30h, 31h, 2Fh, 33h, 33h const uint8 *coords = &_charInvDefs[_charInvIndex[_characters[_selectedCharacter].raceClassSex] * 22 + itemIndex * 2]; uint8 x = *coords++; uint8 y = *coords; diff --git a/engines/kyra/gui_rpg.cpp b/engines/kyra/gui_rpg.cpp index 71c1d1ddb5..ab25f95df8 100644 --- a/engines/kyra/gui_rpg.cpp +++ b/engines/kyra/gui_rpg.cpp @@ -76,8 +76,8 @@ void KyraRpgEngine::gui_drawHorizontalBarGraph(int x, int y, int w, int h, int32 screen()->fillRect(x + t, y, x + w - 1, y + h, col2); } -void KyraRpgEngine::gui_initButtonsFromList(const int16 *list) { - while (*list != -1) +void KyraRpgEngine::gui_initButtonsFromList(const uint8 *list) { + while (*list != 0xFF) gui_initButton(*list++); } diff --git a/engines/kyra/kyra_rpg.cpp b/engines/kyra/kyra_rpg.cpp index 13654111fa..f8eb7d00cd 100644 --- a/engines/kyra/kyra_rpg.cpp +++ b/engines/kyra/kyra_rpg.cpp @@ -204,18 +204,19 @@ bool KyraRpgEngine::posWithinRect(int posX, int posY, int x1, int y1, int x2, in void KyraRpgEngine::drawDialogueButtons() { int cp = screen()->setCurPage(0); - Screen::FontId of = screen()->setFont(gameFlags().use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); + Screen::FontId of = screen()->setFont(_flags.lang == Common::JA_JPN && _flags.use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); for (int i = 0; i < _dialogueNumButtons; i++) { int x = _dialogueButtonPosX[i]; - if (gameFlags().use16ColorMode) { + if (_flags.lang == Common::JA_JPN && _flags.use16ColorMode) { gui_drawBox(x, ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) & ~7) - 1, 74, 10, 0xEE, 0xCC, -1); screen()->printText(_dialogueButtonString[i], (x + 37 - (screen()->getTextWidth(_dialogueButtonString[i])) / 2) & ~3, ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) + 2) & ~7, _dialogueHighlightedButton == i ? 0xC1 : 0xE1, 0); } else { + int sjisYOffset = (_flags.lang == Common::JA_JPN && _dialogueButtonString[i][0] < 0) ? 2 : 0; gui_drawBox(x, (_dialogueButtonYoffs + _dialogueButtonPosY[i]), _dialogueButtonWidth, guiSettings()->buttons.height, guiSettings()->colors.frame1, guiSettings()->colors.frame2, guiSettings()->colors.fill); screen()->printText(_dialogueButtonString[i], x + (_dialogueButtonWidth >> 1) - (screen()->getTextWidth(_dialogueButtonString[i])) / 2, - (_dialogueButtonYoffs + _dialogueButtonPosY[i]) + 2, _dialogueHighlightedButton == i ? _dialogueButtonLabelColor1 : _dialogueButtonLabelColor2, 0); + (_dialogueButtonYoffs + _dialogueButtonPosY[i]) + 2 - sjisYOffset, _dialogueHighlightedButton == i ? _dialogueButtonLabelColor1 : _dialogueButtonLabelColor2, 0); } } screen()->setFont(of); @@ -228,7 +229,7 @@ uint16 KyraRpgEngine::processDialogue() { for (int i = 0; i < _dialogueNumButtons; i++) { int x = _dialogueButtonPosX[i]; - int y = (gameFlags().use16ColorMode ? ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) & ~7) - 1 : (_dialogueButtonYoffs + _dialogueButtonPosY[i])); + int y = ((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) & ~7) - 1 : (_dialogueButtonYoffs + _dialogueButtonPosY[i])); Common::Point p = getMousePos(); if (posWithinRect(p.x, p.y, x, y, x + _dialogueButtonWidth, y + guiSettings()->buttons.height)) { _dialogueHighlightedButton = i; diff --git a/engines/kyra/kyra_rpg.h b/engines/kyra/kyra_rpg.h index 2615875f4d..cd36d2a5cd 100644 --- a/engines/kyra/kyra_rpg.h +++ b/engines/kyra/kyra_rpg.h @@ -283,7 +283,7 @@ protected: void removeInputTop(); void gui_drawBox(int x, int y, int w, int h, int frameColor1, int frameColor2, int fillColor); virtual void gui_drawHorizontalBarGraph(int x, int y, int w, int h, int32 curVal, int32 maxVal, int col1, int col2); - void gui_initButtonsFromList(const int16 *list); + void gui_initButtonsFromList(const uint8 *list); virtual void gui_initButton(int index, int x = -1, int y = -1, int val = -1) = 0; void gui_resetButtonList(); void gui_notifyButtonListChanged(); diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp index f6fc4c3234..9194b64155 100644 --- a/engines/kyra/kyra_v1.cpp +++ b/engines/kyra/kyra_v1.cpp @@ -353,84 +353,88 @@ void KyraEngine_v1::setupKeyMap() { Common::KeyCode kcScummVM; int16 kcDOS; int16 kcPC98; + int16 kcFMTowns; }; +#define UNKNOWN_KEYCODE -1 #define KC(x) Common::KEYCODE_##x static const KeyCodeMapEntry keys[] = { - { KC(SPACE), 61, 53 }, - { KC(RETURN), 43, 29 }, - { KC(UP), 96, 68 }, - { KC(KP8), 96, 68 }, - { KC(RIGHT), 102, 73 }, - { KC(KP6), 102, 73 }, - { KC(DOWN), 98, 76 }, - { KC(KP2), 98, 76 }, - { KC(KP5), 97, 72 }, - { KC(LEFT), 92, 71 }, - { KC(KP4), 92, 71 }, - { KC(HOME), 91, 67 }, - { KC(KP7), 91, 67 }, - { KC(PAGEUP), 101, 69 }, - { KC(KP9), 101, 69 }, - { KC(END), 93, 0/*unknown*/ }, - { KC(KP1), 93, 0/*unknown*/ }, - { KC(PAGEDOWN), 103, 0/*unknown*/ }, - { KC(KP3), 103, 0/*unknown*/ }, - { KC(F1), 112, 99 }, - { KC(F2), 113, 100 }, - { KC(F3), 114, 101 }, - { KC(F4), 115, 102 }, - { KC(F5), 116, 103 }, - { KC(F6), 117, 104 }, - { KC(a), 31, 31 }, - { KC(b), 50, 50 }, - { KC(c), 48, 48 }, - { KC(d), 33, 33 }, - { KC(e), 19, 19 }, - { KC(f), 34, 34 }, - { KC(i), 24, 24 }, - { KC(k), 38, 38 }, - { KC(m), 52, 52 }, - { KC(n), 51, 51 }, - { KC(o), 25, 25 }, - { KC(p), 26, 26 }, - { KC(r), 20, 20 }, - { KC(s), 32, 32 }, - { KC(w), 18, 18 }, - { KC(y), 22, 22 }, - { KC(z), 46, 46 }, - { KC(1), 2, 0/*unknown*/ }, - { KC(2), 3, 0/*unknown*/ }, - { KC(3), 4, 0/*unknown*/ }, - { KC(4), 5, 0/*unknown*/ }, - { KC(5), 6, 0/*unknown*/ }, - { KC(6), 7, 0/*unknown*/ }, - { KC(7), 8, 0/*unknown*/ }, - { KC(SLASH), 55, 55 }, - { KC(ESCAPE), 110, 1 }, - { KC(MINUS), 12, 0/*unknown*/ }, - { KC(KP_MINUS), 105, 0/*unknown*/ }, - { KC(PLUS), 13, 0/*unknown*/ }, - { KC(KP_PLUS), 106, 0/*unknown*/ }, + { KC(SPACE), 61, 53, 32 }, + { KC(RETURN), 43, 29, 13 }, + { KC(UP), 96, 68, 30 }, + { KC(KP8), 96, 68, 30 }, + { KC(RIGHT), 102, 73, 28 }, + { KC(KP6), 102, 73, 28 }, + { KC(DOWN), 98, 76, 31 }, + { KC(KP2), 98, 76, 31 }, + { KC(KP5), 97, 72, UNKNOWN_KEYCODE }, + { KC(LEFT), 92, 71, 29 }, + { KC(KP4), 92, 71, 29 }, + { KC(HOME), 91, 67, 127 }, + { KC(KP7), 91, 67, 127 }, + { KC(PAGEUP), 101, 69, 18 }, + { KC(KP9), 101, 69, 18 }, + { KC(END), 93, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(KP1), 93, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(PAGEDOWN), 103, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(KP3), 103, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(F1), 112, 99, UNKNOWN_KEYCODE }, + { KC(F2), 113, 100, UNKNOWN_KEYCODE }, + { KC(F3), 114, 101, UNKNOWN_KEYCODE }, + { KC(F4), 115, 102, UNKNOWN_KEYCODE }, + { KC(F5), 116, 103, UNKNOWN_KEYCODE }, + { KC(F6), 117, 104, UNKNOWN_KEYCODE }, + { KC(a), 31, 31, UNKNOWN_KEYCODE }, + { KC(b), 50, 50, UNKNOWN_KEYCODE }, + { KC(c), 48, 48, 67 }, + { KC(d), 33, 33, UNKNOWN_KEYCODE }, + { KC(e), 19, 19, UNKNOWN_KEYCODE }, + { KC(f), 34, 34, UNKNOWN_KEYCODE }, + { KC(i), 24, 24, UNKNOWN_KEYCODE }, + { KC(k), 38, 38, UNKNOWN_KEYCODE }, + { KC(m), 52, 52, UNKNOWN_KEYCODE }, + { KC(n), 51, 51, UNKNOWN_KEYCODE }, + { KC(o), 25, 25, 79 }, + { KC(p), 26, 26, 80 }, + { KC(r), 20, 20, 82 }, + { KC(s), 32, 32, UNKNOWN_KEYCODE }, + { KC(w), 18, 18, UNKNOWN_KEYCODE }, + { KC(y), 22, 22, UNKNOWN_KEYCODE }, + { KC(z), 46, 46, UNKNOWN_KEYCODE }, + { KC(0), UNKNOWN_KEYCODE, UNKNOWN_KEYCODE, 48 }, + { KC(1), 2, UNKNOWN_KEYCODE, 49 }, + { KC(2), 3, UNKNOWN_KEYCODE, 50 }, + { KC(3), 4, UNKNOWN_KEYCODE, 51 }, + { KC(4), 5, UNKNOWN_KEYCODE, 52 }, + { KC(5), 6, UNKNOWN_KEYCODE, 53 }, + { KC(6), 7, UNKNOWN_KEYCODE, 54 }, + { KC(7), 8, UNKNOWN_KEYCODE, 55 }, + { KC(SLASH), 55, 55, 47 }, + { KC(ESCAPE), 110, 1, 27 }, + { KC(MINUS), 12, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(KP_MINUS), 105, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(PLUS), 13, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(KP_PLUS), 106, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, // Multiple mappings for the keys to the right of the 'M' key, // since these are different for QWERTZ, QWERTY and AZERTY keyboards. // QWERTZ - { KC(COMMA), 53, 0/*unknown*/ }, - { KC(PERIOD), 54, 0/*unknown*/ }, + { KC(COMMA), 53, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(PERIOD), 54, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, // AZERTY - { KC(SEMICOLON), 53, 0/*unknown*/ }, - { KC(COLON), 54, 0/*unknown*/ }, + { KC(SEMICOLON), 53, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(COLON), 54, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, // QWERTY - { KC(LESS), 53, 0/*unknown*/ }, - { KC(GREATER), 54, 0/*unknown*/ } + { KC(LESS), 53, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE }, + { KC(GREATER), 54, UNKNOWN_KEYCODE, UNKNOWN_KEYCODE } }; #undef KC +#undef UNKNOWN_KEYCODE _keyMap.clear(); for (int i = 0; i < ARRAYSIZE(keys); i++) - _keyMap[keys[i].kcScummVM] = (_flags.platform == Common::kPlatformPC98) ? keys[i].kcPC98 : keys[i].kcDOS; + _keyMap[keys[i].kcScummVM] = (_flags.platform == Common::kPlatformPC98) ? keys[i].kcPC98 : ((_flags.platform == Common::kPlatformFMTowns) ? keys[i].kcFMTowns : keys[i].kcDOS); } void KyraEngine_v1::updateInput() { diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index aa4e7a212a..f7696d45b5 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -524,7 +524,7 @@ Common::Error LoLEngine::go() { // the prologue code we need to setup them manually here. if (_gameToLoad != -1 && action != 3) { preInit(); - _screen->setFont(_flags.use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); + _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); } // We have three sound.dat files, one for the intro, one for the @@ -683,14 +683,14 @@ int LoLEngine::mainMenu() { bool hasSave = saveFileLoadable(0); MainMenu::StaticData data[] = { - // 256 color mode + // 256 color ASCII mode { { 0, 0, 0, 0, 0 }, { 0x01, 0x04, 0x0C, 0x04, 0x00, 0x3D, 0x9F }, { 0x2C, 0x19, 0x48, 0x2C }, Screen::FID_9_FNT, 1 }, - // 16 color mode + // 16 color SJIS mode { { 0, 0, 0, 0, 0 }, { 0x01, 0x04, 0x0C, 0x04, 0x00, 0xC1, 0xE1 }, @@ -933,7 +933,7 @@ void LoLEngine::writeSettings() { case 0: default: - if (_flags.platform == Common::kPlatformPC98) + if (_flags.platform == Common::kPlatformPC98 || _flags.platform == Common::kPlatformFMTowns) _flags.lang = Common::JA_JPN; else _flags.lang = Common::EN_ANY; @@ -3356,7 +3356,9 @@ int LoLEngine::battleHitSkillTest(int16 attacker, int16 target, int skill) { } if (target & 0x8000) { - evadeChanceModifier = (_monsterModifiers[9 + _monsterDifficulty] * _monsters[target & 0x7FFF].properties->fightingStats[3]) >> 8; + evadeChanceModifier = _monsters[target & 0x7FFF].properties->fightingStats[3]; + if (_monsterModifiers4) + evadeChanceModifier = (evadeChanceModifier * _monsterModifiers4[_monsterDifficulty]) >> 8; _monsters[target & 0x7FFF].flags |= 0x10; } else { evadeChanceModifier = _characters[target].defaultModifiers[3]; @@ -4062,7 +4064,7 @@ void LoLEngine::displayAutomap() { gui_notifyButtonListChanged(); } - if (f == 0x30) { + if (f == _keyMap[Common::KEYCODE_c]) { for (int i = 0; i < 1024; i++) _levelBlockProperties[i].flags |= 7; _mapUpdateNeeded = true; @@ -4189,7 +4191,7 @@ void LoLEngine::drawMapPage(int pageNum) { _screen->copyRegion(236, 16, 236 + xOffset, 16, -xOffset, 1, pageNum, pageNum, Screen::CR_NO_P_CHECK); int cp = _screen->setCurPage(pageNum); - Screen::FontId of = _screen->setFont(_flags.use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); + Screen::FontId of = _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); _screen->printText(getLangString(_autoMapStrings[_currentMapLevel]), 236 + xOffset, 8, 1, 0); uint16 blX = mapGetStartPosX(); uint16 bl = (mapGetStartPosY() << 5) + blX; @@ -4249,7 +4251,7 @@ void LoLEngine::drawMapPage(int pageNum) { _screen->setFont(of); _screen->setCurPage(cp); - of = _screen->setFont(_flags.use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); + of = _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); int tY = 0; sx = mapGetStartPosX(); diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index d8df6b6703..4002346d31 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -336,9 +336,9 @@ private: static const char *const _charPreviewNamesDefault[]; static const char *const _charPreviewNamesRussianFloppy[]; - // PC98 specific data + // PC98/FM-TOWNS specific data static const uint16 _charPosXPC98[]; - static const uint8 _charNamesPC98[][11]; + static const char *const _charNamesJapanese[]; WSAMovie_v2 *_chargenWSA; static const uint8 _chargenFrameTableTalkie[]; @@ -558,14 +558,14 @@ private: int clickedStatusIcon(Button *button); const LoLButtonDef *_buttonData; - const int16 *_buttonList1; - const int16 *_buttonList2; - const int16 *_buttonList3; - const int16 *_buttonList4; - const int16 *_buttonList5; - const int16 *_buttonList6; - const int16 *_buttonList7; - const int16 *_buttonList8; + const uint8 *_buttonList1; + const uint8 *_buttonList2; + const uint8 *_buttonList3; + const uint8 *_buttonList4; + const uint8 *_buttonList5; + const uint8 *_buttonList6; + const uint8 *_buttonList7; + const uint8 *_buttonList8; // text int characterSays(int track, int charId, bool redraw); @@ -1137,7 +1137,11 @@ private: uint16 _monsterCurBlock; int _objectLastDirection; - const uint16 *_monsterModifiers; + const uint16 *_monsterModifiers1; + const uint16 *_monsterModifiers2; + const uint16 *_monsterModifiers3; + const uint16 *_monsterModifiers4; + const int8 *_monsterShiftOffs; const uint8 *_monsterDirFlags; const uint8 *_monsterScaleX; diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h index 5364cce270..5c179a7864 100644 --- a/engines/kyra/resource.h +++ b/engines/kyra/resource.h @@ -679,7 +679,10 @@ enum KyraResources { kLoLCharDefsKieran, kLoLCharDefsAkshel, kLoLExpRequirements, - kLoLMonsterModifiers, + kLoLMonsterModifiers1, + kLoLMonsterModifiers2, + kLoLMonsterModifiers3, + kLoLMonsterModifiers4, kLoLMonsterShiftOffsets, kLoLMonsterDirFlags, kLoLMonsterScaleY, diff --git a/engines/kyra/saveload_lol.cpp b/engines/kyra/saveload_lol.cpp index 58e3d94c78..6c83ebd51b 100644 --- a/engines/kyra/saveload_lol.cpp +++ b/engines/kyra/saveload_lol.cpp @@ -547,7 +547,7 @@ void LoLEngine::restoreTempDataAdjustMonsterStrength(int index) { if (_lvlTempData[index]->monsterDifficulty == _monsterDifficulty) return; - uint16 d = (_monsterModifiers[_lvlTempData[index]->monsterDifficulty] << 8) / _monsterModifiers[_monsterDifficulty]; + uint16 d = (_monsterModifiers1[_lvlTempData[index]->monsterDifficulty] << 8) / _monsterModifiers1[_monsterDifficulty]; for (int i = 0; i < 30; i++) { if (_monsters[i].mode >= 14 || _monsters[i].block == 0 || _monsters[i].hitPoints <= 0) diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index 5dd7cfb25b..419b630714 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -56,6 +56,7 @@ Screen::Screen(KyraEngine_v1 *vm, OSystem *system, const ScreenDim *dimTable, co _pageMapping[i] = i & ~1; _renderMode = Common::kRenderDefault; + _sjisMixedFontMode = false; _currentFont = FID_8_FNT; _paletteChanged = true; @@ -124,6 +125,7 @@ bool Screen::init() { if (_useOverlays) { _useSJIS = (_vm->gameFlags().lang == Common::JA_JPN); _sjisInvisibleColor = (_vm->game() == GI_KYRA1) ? 0x80 : 0xF6; + _sjisMixedFontMode = !_use16ColorMode; for (int i = 0; i < SCREEN_OVLS_NUM; ++i) { if (!_sjisOverlayPtrs[i]) { @@ -139,7 +141,7 @@ bool Screen::init() { if (!font) error("Could not load any SJIS font, neither the original nor ScummVM's 'SJIS.FNT'"); - _fonts[FID_SJIS_FNT] = new SJISFont(font, _sjisInvisibleColor, _use16ColorMode, !_use16ColorMode); + _fonts[FID_SJIS_FNT] = new SJISFont(font, _sjisInvisibleColor, _use16ColorMode, !_use16ColorMode && _vm->game() != GI_LOL, _vm->game() == GI_LOL ? 1 : 0); } } @@ -1246,11 +1248,16 @@ int Screen::getCharWidth(uint16 c) const { return width + ((_currentFont != FID_SJIS_FNT) ? _charWidth : 0); } -int Screen::getTextWidth(const char *str) const { +int Screen::getTextWidth(const char *str) { int curLineLen = 0; int maxLineLen = 0; + FontId curFont = _currentFont; + while (1) { + if (_sjisMixedFontMode) + setFont(*str < 0 ? FID_SJIS_FNT : curFont); + uint c = fetchChar(str); if (c == 0) { @@ -1274,7 +1281,7 @@ void Screen::printText(const char *str, int x, int y, uint8 color1, uint8 color2 cmap[1] = color1; setTextColor(cmap, 0, 1); - const uint8 charHeightFnt = getFontHeight(); + FontId curFont = _currentFont; if (x < 0) x = 0; @@ -1288,6 +1295,11 @@ void Screen::printText(const char *str, int x, int y, uint8 color1, uint8 color2 return; while (1) { + if (_sjisMixedFontMode) + setFont(*str < 0 ? FID_SJIS_FNT : curFont); + + uint8 charHeightFnt = getFontHeight(); + uint c = fetchChar(str); if (c == 0) { @@ -3566,11 +3578,11 @@ void AMIGAFont::unload() { memset(_chars, 0, sizeof(_chars)); } -SJISFont::SJISFont(Graphics::FontSJIS *font, const uint8 invisColor, bool is16Color, bool outlineSize) - : _colorMap(0), _font(font), _invisColor(invisColor), _is16Color(is16Color) { +SJISFont::SJISFont(Graphics::FontSJIS *font, const uint8 invisColor, bool is16Color, bool drawOutline, int extraSpacing) + : _colorMap(0), _font(font), _invisColor(invisColor), _is16Color(is16Color), _drawOutline(drawOutline), _sjisWidthOffset(extraSpacing) { assert(_font); - _font->setDrawingMode(outlineSize ? Graphics::FontSJIS::kOutlineMode : Graphics::FontSJIS::kDefaultMode); + _font->setDrawingMode(_drawOutline ? Graphics::FontSJIS::kOutlineMode : Graphics::FontSJIS::kDefaultMode); _sjisWidth = _font->getMaxFontWidth() >> 1; _fontHeight = _font->getFontHeight() >> 1; @@ -3587,14 +3599,14 @@ int SJISFont::getHeight() const { } int SJISFont::getWidth() const { - return _sjisWidth; + return _sjisWidth + _sjisWidthOffset; } int SJISFont::getCharWidth(uint16 c) const { if (c <= 0x7F || (c >= 0xA1 && c <= 0xDF)) return _asciiWidth; else - return _sjisWidth; + return _sjisWidth + _sjisWidthOffset; } void SJISFont::setColorMap(const uint8 *src) { @@ -3604,7 +3616,7 @@ void SJISFont::setColorMap(const uint8 *src) { if (_colorMap[0] == _invisColor) _font->setDrawingMode(Graphics::FontSJIS::kDefaultMode); else - _font->setDrawingMode(Graphics::FontSJIS::kOutlineMode); + _font->setDrawingMode(_drawOutline ? Graphics::FontSJIS::kOutlineMode : Graphics::FontSJIS::kDefaultMode); } } diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index 7f3abf8b5f..156b5b9a7c 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -211,7 +211,7 @@ private: */ class SJISFont : public Font { public: - SJISFont(Graphics::FontSJIS *font, const uint8 invisColor, bool is16Color, bool outlineSize); + SJISFont(Graphics::FontSJIS *font, const uint8 invisColor, bool is16Color, bool drawOutline, int extraSpacing); ~SJISFont() { unload(); } bool usesOverlay() const { return true; } @@ -230,6 +230,12 @@ private: Graphics::FontSJIS *_font; const uint8 _invisColor; const bool _is16Color; + const bool _drawOutline; + // We use this for cases where the font width returned by getWidth() or getCharWidth() does not match the original. + // The original Japanese game versions use hard coded sjis font widths of 8 or 9. However, this does not necessarily + // depend on whether an outline is used or not (neither LOL/PC-9801 nor LOL/FM-TOWNS use an outline, but the first + // version uses a font width of 8 where the latter uses a font width of 9). + const int _sjisWidthOffset; int _sjisWidth, _asciiWidth; int _fontHeight; @@ -468,7 +474,7 @@ public: int getFontWidth() const; int getCharWidth(uint16 c) const; - int getTextWidth(const char *str) const; + int getTextWidth(const char *str); void printText(const char *str, int x, int y, uint8 color1, uint8 color2); @@ -581,6 +587,7 @@ protected: Common::RenderMode _renderMode; uint8 _sjisInvisibleColor; + bool _sjisMixedFontMode; Palette *_screenPalette; Common::Array<Palette *> _palettes; diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index e9fc1c7971..0bbe66f530 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -823,7 +823,7 @@ int LoLEngine::olol_initMonster(EMCState *script) { l->type = stackPos(4); l->properties = &_monsterProperties[l->type]; l->direction = l->facing << 1; - l->hitPoints = (l->properties->hitPoints * _monsterModifiers[_monsterDifficulty]) >> 8; + l->hitPoints = (l->properties->hitPoints * _monsterModifiers1[_monsterDifficulty]) >> 8; if (_currentLevel != 12 || l->type != 2) l->hitPoints = (l->hitPoints * (rollDice(1, 128) + 192)) >> 8; diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp index 82ec3dc658..ba0f62a2b4 100644 --- a/engines/kyra/script_tim.cpp +++ b/engines/kyra/script_tim.cpp @@ -297,20 +297,20 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) { memcpy(filename, text+1, end-1-text); } - const bool isPC98 = (_vm->gameFlags().platform == Common::kPlatformPC98); + const bool sjisMode = (_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode); if (filename[0] && (_vm->speechEnabled() || !_vm->gameFlags().isTalkie)) _vm->sound()->voicePlay(filename, 0, 255, 255, !_vm->gameFlags().isTalkie); if (text[0] == '$') text = strchr(text + 1, '$') + 1; - if (!isPC98) + if (!_vm->gameFlags().use16ColorMode) setupTextPalette((flags < 0) ? 1 : flags, 0); if (flags < 0) { static const uint8 colorMap[] = { 0x00, 0xF0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - _screen->setFont(isPC98 ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT); + _screen->setFont(sjisMode ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT); _screen->setTextColorMap(colorMap); _screen->_charWidth = -2; } @@ -335,7 +335,7 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) { int width = _screen->getTextWidth(str); if (flags >= 0) { - if (isPC98) { + if (_vm->gameFlags().use16ColorMode) { static const uint8 colorMap[] = { 0xE1, 0xE1, 0xC1, 0xA1, 0x81, 0x61 }; _screen->printText(str, (320 - width) >> 1, 160 + heightAdd, colorMap[flags], 0x00); } else { @@ -359,7 +359,7 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) { if (flags < 0) { static const uint8 colorMap[] = { 0x00, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00 }; - _screen->setFont(isPC98 ? Screen::FID_SJIS_FNT : Screen::FID_INTRO_FNT); + _screen->setFont(sjisMode ? Screen::FID_SJIS_FNT : Screen::FID_INTRO_FNT); _screen->setTextColorMap(colorMap); _screen->_charWidth = 0; } @@ -377,7 +377,7 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags, uint8 color) { if (flags == 255) return; - _screen->setFont(_vm->gameFlags().use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_INTRO_FNT); + _screen->setFont((_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_INTRO_FNT); static const uint8 colorMap[] = { 0x00, 0xA0, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; _screen->setTextColorMap(colorMap); diff --git a/engines/kyra/sequences_lol.cpp b/engines/kyra/sequences_lol.cpp index 3ff25d970c..c8f97eb770 100644 --- a/engines/kyra/sequences_lol.cpp +++ b/engines/kyra/sequences_lol.cpp @@ -72,7 +72,7 @@ int LoLEngine::processPrologue() { // Original version: (260|193) "V CD1.02 D" const int width = _screen->getTextWidth(versionString.c_str()); _screen->fprintString("%s", 320 - width, 193, 0x67, 0x00, 0x04, versionString.c_str()); - _screen->setFont(_flags.lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); + _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); _screen->fadePalette(_screen->getPalette(0), 0x1E); _screen->updateScreen(); @@ -145,7 +145,12 @@ void LoLEngine::setupPrologueData(bool load) { static const char *const fileListFloppy[] = { "INTRO.PAK", "INTROVOC.PAK", 0 }; - const char *const *fileList = _flags.isTalkie ? fileListCD : fileListFloppy; + + static const char *const fileListTowns[] = { + "INTRO.PAK", "TINTROVO.PAK", 0 + }; + + const char *const *fileList = _flags.isTalkie ? fileListCD : (_flags.platform == Common::kPlatformFMTowns ? fileListTowns : fileListFloppy); char filename[32]; for (uint i = 0; fileList[i]; ++i) { @@ -225,7 +230,7 @@ void LoLEngine::showIntro() { _screen->loadFont(Screen::FID_8_FNT, "NEW8P.FNT"); _screen->loadFont(Screen::FID_INTRO_FNT, "INTRO.FNT"); - _screen->setFont(_flags.lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT); + _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT); _tim->resetFinishedFlag(); _tim->setLangData("LOLINTRO.DIP"); @@ -295,10 +300,10 @@ int LoLEngine::chooseCharacter() { _chargenWSA->displayFrame(0, 2, 113, 0, 0, 0, 0); - _screen->setFont(_flags.lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); + _screen->setFont((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); _screen->_curPage = 2; - if (_flags.platform == Common::kPlatformPC98) { + if (_flags.platform == Common::kPlatformPC98 && _flags.use16ColorMode) { _screen->fillRect(17, 29, 94, 97, 17); _screen->fillRect(68, 167, 310, 199, 17); _screen->drawClippedLine(68, 166, 311, 166, 238); @@ -310,7 +315,7 @@ int LoLEngine::chooseCharacter() { _screen->_curPage = 2; for (int i = 0; i < 4; ++i) { - _screen->printText((const char *)_charNamesPC98[i], _charPosXPC98[i], 168, 0xC1, 0x00); + _screen->printText(_charNamesJapanese[i], _charPosXPC98[i], 168, 0xC1, 0x00); Screen::FontId old = _screen->setFont(Screen::FID_SJIS_FNT); for (int j = 0; j < 3; ++j) { @@ -324,7 +329,7 @@ int LoLEngine::chooseCharacter() { _screen->printText(_tim->getCTableEntry(53), 72, 184, 0x81, 0x00); _screen->printText(_tim->getCTableEntry(55), 72, 192, 0x81, 0x00); } else { - const char *const *previewNames = (_flags.lang == Common::RU_RUS && !_flags.isTalkie) ? _charPreviewNamesRussianFloppy : _charPreviewNamesDefault; + const char *const *previewNames = (_flags.lang == Common::RU_RUS && !_flags.isTalkie) ? _charPreviewNamesRussianFloppy : (_flags.lang == Common::JA_JPN ? _charNamesJapanese : _charPreviewNamesDefault); for (int i = 0; i < 4; ++i) { _screen->fprintStringIntro("%s", _charPreviews[i].x + 16, _charPreviews[i].y + 36, 0xC0, 0x00, 0x9C, 0x120, previewNames[i]); _screen->fprintStringIntro("%d", _charPreviews[i].x + 21, _charPreviews[i].y + 48, 0x98, 0x00, 0x9C, 0x220, _charPreviews[i].attrib[0]); @@ -1015,7 +1020,11 @@ void LoLEngine::setupEpilogueData(bool load) { "GENERAL.PAK", "INTRO.PAK", "FINALE1.PAK", "FINALE2.PAK", 0 }; - const char *const *fileList = _flags.isTalkie ? fileListCD : fileListFloppy; + static const char *const fileListTowns[] = { + "GENERAL.PAK", "INTRO.PAK", "FINALE1.PAK", "TFINALE2.PAK", 0 + }; + + const char *const *fileList = _flags.isTalkie ? fileListCD : (_flags.platform == Common::kPlatformFMTowns ? fileListTowns : fileListFloppy); assert(fileList); char filename[32]; diff --git a/engines/kyra/sound_lol.cpp b/engines/kyra/sound_lol.cpp index 02ea3f44a8..48230d025c 100644 --- a/engines/kyra/sound_lol.cpp +++ b/engines/kyra/sound_lol.cpp @@ -247,7 +247,7 @@ void LoLEngine::snd_playQueuedEffects() { void LoLEngine::snd_loadSoundFile(int track) { if (_sound->musicEnabled()) { - if (_flags.platform != Common::kPlatformPC98) { + if (_flags.platform == Common::kPlatformPC) { int t = (track - 250) * 3; if (_curMusicFileIndex != _musicTrackMap[t] || _curMusicFileExt != (char)_musicTrackMap[t + 1]) { snd_stopMusic(); @@ -269,12 +269,12 @@ int LoLEngine::snd_playTrack(int track) { _lastMusicTrack = track; if (_sound->musicEnabled()) { - if (_flags.platform == Common::kPlatformPC98) { - _sound->playTrack(track - 249); - } else { + if (_flags.platform == Common::kPlatformPC) { snd_loadSoundFile(track); int t = (track - 250) * 3; _sound->playTrack(_musicTrackMap[t + 2]); + } else { + _sound->playTrack(track - 249); } } diff --git a/engines/kyra/sound_towns.cpp b/engines/kyra/sound_towns.cpp index aff3e0f791..af741a1ebe 100644 --- a/engines/kyra/sound_towns.cpp +++ b/engines/kyra/sound_towns.cpp @@ -525,7 +525,9 @@ bool SoundTownsPC98_v2::init() { TownsPC98_AudioDriver::kType86 : TownsPC98_AudioDriver::kTypeTowns); if (_vm->gameFlags().platform == Common::kPlatformFMTowns) { - _vm->checkCD(); + if (_resInfo[_currentResourceSet]) + if (_resInfo[_currentResourceSet]->cdaTableSize) + _vm->checkCD(); // FIXME: While checking for 'track1.XXX(X)' looks like // a good idea, we should definitely not be doing this // here. Basically our filenaming scheme could change diff --git a/engines/kyra/sprites_lol.cpp b/engines/kyra/sprites_lol.cpp index 9b602d9dc4..88b24e1367 100644 --- a/engines/kyra/sprites_lol.cpp +++ b/engines/kyra/sprites_lol.cpp @@ -481,19 +481,8 @@ int LoLEngine::calcMonsterSkillLevel(int id, int a) { const uint16 *c = getCharacterOrMonsterStats(id); int r = (a << 8) / c[4]; - /* - if (!(id & 0x8000)) - r = (r * _monsterModifiers[3 + _monsterDifficulty]) >> 8; - - id &= 0x7FFF; - - if (_characters[id].skillLevels[1] <= 3) - return r; - else if (_characters[id].skillLevels[1] <= 7) - return (r- (r >> 2));*/ - if (id & 0x8000) { - r = (r * _monsterModifiers[3 + _monsterDifficulty]) >> 8; + r = (r * _monsterModifiers2[3 + _monsterDifficulty]) >> 8; } else { if (_characters[id].skillLevels[1] > 7) r = (r - (r >> 1)); @@ -708,7 +697,9 @@ int LoLEngine::getMonsterCurFrame(LoLMonster *m, uint16 dirFlags) { break; case 1: // monsters whose outward appearance reflects the damage they have taken - tmp = (m->properties->hitPoints * _monsterModifiers[_monsterDifficulty]) >> 8; + tmp = m->properties->hitPoints; + if (_flags.isTalkie) + tmp = (tmp * _monsterModifiers1[_monsterDifficulty]) >> 8; if (m->hitPoints > (tmp >> 1)) tmp = 0; else if (m->hitPoints > (tmp >> 2)) @@ -1127,7 +1118,7 @@ void LoLEngine::updateMonster(LoLMonster *monster) { // first recovery phase after delivering an attack if (++monster->fightCurTick > 2) { setMonsterMode(monster, 5); - monster->fightCurTick = (int8)((((8 << 8) / monster->properties->fightingStats[4]) * _monsterModifiers[6 + _monsterDifficulty]) >> 8); + monster->fightCurTick = (int8)((((8 << 8) / monster->properties->fightingStats[4]) * _monsterModifiers3[_monsterDifficulty]) >> 8); } checkSceneUpdateNeed(monster->block); break; diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 38481d9ac6..bac31f0a3e 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -39,7 +39,7 @@ namespace Kyra { -#define RESFILE_VERSION 83 +#define RESFILE_VERSION 84 namespace { bool checkKyraDat(Common::SeekableReadStream *file) { diff --git a/engines/kyra/staticres_eob.cpp b/engines/kyra/staticres_eob.cpp index 872ab40143..e0a2862dea 100644 --- a/engines/kyra/staticres_eob.cpp +++ b/engines/kyra/staticres_eob.cpp @@ -220,44 +220,44 @@ const uint8 EoBCoreEngine::_wallOfForceShapeDefs[] = { 0x0C, 0x00, 0x05, 0x10 }; -const int16 EoBCoreEngine::_buttonList1[] = { +const uint8 EoBCoreEngine::_buttonList1[] = { 58, 0, 1, 2, 3, 90, 91, 4, 5, 6, 7, 8, 9, 10, 11, 12, 78, 79, 13, 14, 15, 16, - 80, 81, 17, 18, 19, 20, 82, 83, 49, 50, 51, 52, 53, 54, 56, 57, -1 + 80, 81, 17, 18, 19, 20, 82, 83, 49, 50, 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList2[] = { +const uint8 EoBCoreEngine::_buttonList2[] = { 58, 61, 62, 63, 64, 65, 93, 94, 66, 67, 68, 69, 70, 71, 76, 77, 88, 0, 1, 2, 3, 90, 91, 4, 5, 6, 7, 8, 9, 10, 11, 12, 78, 79, 13, 14, 15, 16, 80, 81, 17, 18, - 19, 20, 82, 83, 49, 50, 51, 52, 53, 54, 56, 57, -1 + 19, 20, 82, 83, 49, 50, 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList3[] = { +const uint8 EoBCoreEngine::_buttonList3[] = { 58, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 84, 85, 46, 47, 48, 60, 59, 92, 4, 5, 6, 7, 8, 49, 50, - 51, 52, 53, 54, 56, 57, -1 + 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList4[] = { - 58, 47, 48, 60, 59, 92, 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, -1 +const uint8 EoBCoreEngine::_buttonList4[] = { + 58, 47, 48, 60, 59, 92, 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList5[] = { +const uint8 EoBCoreEngine::_buttonList5[] = { 58, 61, 62, 63, 64, 65, 93, 66, 67, 68, 69, 70, 71, 88, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 84, - 85, 46, 47, 48, 60, 59, 92, 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, -1 + 85, 46, 47, 48, 60, 59, 92, 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList6[] = { +const uint8 EoBCoreEngine::_buttonList6[] = { 58, 61, 62, 63, 64, 65, 93, 66, 67, 68, 69, 70, 71, 88, 46, 47, 48, 60, 59, 92, - 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, -1 + 4, 5, 6, 7, 8, 49, 50, 51, 52, 53, 54, 56, 57, 255 }; -const int16 EoBCoreEngine::_buttonList7[] = { - 17, 18, 19, 20, 82, 83, 55, -1 +const uint8 EoBCoreEngine::_buttonList7[] = { + 17, 18, 19, 20, 82, 83, 55, 255 }; -const int16 EoBCoreEngine::_buttonList8[] = { - 72, 73, 74, 75, 86, 87, 89, -1 +const uint8 EoBCoreEngine::_buttonList8[] = { + 72, 73, 74, 75, 86, 87, 89, 255 }; const uint8 EoBCoreEngine::_clock2Timers[] = { diff --git a/engines/kyra/staticres_lol.cpp b/engines/kyra/staticres_lol.cpp index 6b3064558c..a1c5ff340c 100644 --- a/engines/kyra/staticres_lol.cpp +++ b/engines/kyra/staticres_lol.cpp @@ -238,6 +238,15 @@ void LoLEngine::initStaticResource() { _sound->initAudioResourceInfo(kMusicIntro, &resInfoIntro); _sound->initAudioResourceInfo(kMusicIngame, &resInfoIngame); _sound->initAudioResourceInfo(kMusicFinale, &resInfoFinale); + } else if (_flags.platform == Common::kPlatformFMTowns) { + static const char *const fileListIntro[] = { 0, "lore84.twn", "lore82.twn", 0, 0, 0, "lore83.twn", "lore81.twn" }; + static const char *const fileListFinale[] = { 0, 0, "lore85.twn", "lore86.twn", "lore87.twn" }; + SoundResourceInfo_TownsPC98V2 resInfoIntro(fileListIntro, ARRAYSIZE(fileListIntro), 0, 0, 0); + SoundResourceInfo_TownsPC98V2 resInfoIngame(0, 0, "lore%02d.twn", 0, 0); + SoundResourceInfo_TownsPC98V2 resInfoFinale(fileListFinale, ARRAYSIZE(fileListFinale), 0, 0, 0); + _sound->initAudioResourceInfo(kMusicIntro, &resInfoIntro); + _sound->initAudioResourceInfo(kMusicIngame, &resInfoIngame); + _sound->initAudioResourceInfo(kMusicFinale, &resInfoFinale); } if (_flags.isDemo) @@ -261,7 +270,10 @@ void LoLEngine::initStaticResource() { _charDefsKieran = _staticres->loadRawDataBe16(kLoLCharDefsKieran, tempSize); _charDefsAkshel = _staticres->loadRawDataBe16(kLoLCharDefsAkshel, tempSize); _expRequirements = (const int32 *)_staticres->loadRawDataBe32(kLoLExpRequirements, tempSize); - _monsterModifiers = _staticres->loadRawDataBe16(kLoLMonsterModifiers, tempSize); + _monsterModifiers1 = _staticres->loadRawDataBe16(kLoLMonsterModifiers1, tempSize); + _monsterModifiers2 = _staticres->loadRawDataBe16(kLoLMonsterModifiers2, tempSize); + _monsterModifiers3 = _staticres->loadRawDataBe16(kLoLMonsterModifiers3, tempSize); + _monsterModifiers4 = _staticres->loadRawDataBe16(kLoLMonsterModifiers4, tempSize); _monsterShiftOffs = (const int8 *)_staticres->loadRawData(kLoLMonsterShiftOffsets, tempSize); _monsterDirFlags = _staticres->loadRawData(kLoLMonsterDirFlags, tempSize); _monsterScaleX = _staticres->loadRawData(kLoLMonsterScaleX, tempSize); @@ -304,14 +316,14 @@ void LoLEngine::initStaticResource() { } _buttonData = _staticres->loadButtonDefs(kLoLButtonDefs, tempSize); - _buttonList1 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList1, tempSize); - _buttonList2 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList2, tempSize); - _buttonList3 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList3, tempSize); - _buttonList4 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList4, tempSize); - _buttonList5 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList5, tempSize); - _buttonList6 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList6, tempSize); - _buttonList7 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList7, tempSize); - _buttonList8 = (const int16 *)_staticres->loadRawDataBe16(kLoLButtonList8, tempSize); + _buttonList1 = _staticres->loadRawData(kLoLButtonList1, tempSize); + _buttonList2 = _staticres->loadRawData(kLoLButtonList2, tempSize); + _buttonList3 = _staticres->loadRawData(kLoLButtonList3, tempSize); + _buttonList4 = _staticres->loadRawData(kLoLButtonList4, tempSize); + _buttonList5 = _staticres->loadRawData(kLoLButtonList5, tempSize); + _buttonList6 = _staticres->loadRawData(kLoLButtonList6, tempSize); + _buttonList7 = _staticres->loadRawData(kLoLButtonList7, tempSize); + _buttonList8 = _staticres->loadRawData(kLoLButtonList8, tempSize); _autoMapStrings = _staticres->loadRawDataBe16(kLoLMapStringId, tempSize); @@ -659,11 +671,11 @@ const uint16 LoLEngine::_charPosXPC98[] = { 92, 152, 212, 268 }; -const uint8 LoLEngine::_charNamesPC98[][11] = { - { 0x83, 0x41, 0x83, 0x4E, 0x83, 0x56, 0x83, 0x46, 0x83, 0x8B, 0x00 }, - { 0x83, 0x7D, 0x83, 0x43, 0x83, 0x50, 0x83, 0x8B, 0x00, 0x00, 0x00 }, - { 0x83, 0x4C, 0x81, 0x5B, 0x83, 0x89, 0x83, 0x93, 0x00, 0x00, 0x00 }, - { 0x83, 0x52, 0x83, 0x93, 0x83, 0x89, 0x83, 0x62, 0x83, 0x68, 0x00 } +const char *const LoLEngine::_charNamesJapanese[] = { + "\x83\x41\x83\x4E\x83\x56\x83\x46\x83\x8B\0", + "\x83\x7D\x83\x43\x83\x50\x83\x8B\x00\x00\0", + "\x83\x4C\x81\x5B\x83\x89\x83\x93\x00\x00\0", + "\x83\x52\x83\x93\x83\x89\x83\x62\x83\x68\0" }; const uint8 LoLEngine::_chargenFrameTableTalkie[] = { diff --git a/engines/kyra/text_lol.cpp b/engines/kyra/text_lol.cpp index eee3ea92f9..6e77db1f8a 100644 --- a/engines/kyra/text_lol.cpp +++ b/engines/kyra/text_lol.cpp @@ -136,18 +136,16 @@ void TextDisplayer_LoL::expandField() { void TextDisplayer_LoL::printDialogueText(int dim, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) { int oldDim = 0; - const bool isPc98 = (_vm->gameFlags().platform == Common::kPlatformPC98); - if (dim == 3) { if (_vm->_updateFlags & 2) { oldDim = clearDim(4); - _textDimData[4].color1 = isPc98 ? 0x33 : 254; + _textDimData[4].color1 = _vm->gameFlags().use16ColorMode ? 0x33 : 254; _textDimData[4].color2 = _screen->_curDim->unkA; } else { oldDim = clearDim(3); - _textDimData[3].color1 = isPc98 ? 0x33 : 192; + _textDimData[3].color1 = _vm->gameFlags().use16ColorMode ? 0x33 : 192; _textDimData[3].color2 = _screen->_curDim->unkA; - if (!isPc98) + if (!_vm->gameFlags().use16ColorMode) _screen->copyColor(192, 254); _vm->enableTimer(11); _vm->_textColorFlag = 0; @@ -157,12 +155,12 @@ void TextDisplayer_LoL::printDialogueText(int dim, char *str, EMCState *script, oldDim = _screen->curDimIndex(); _screen->setScreenDim(dim); _lineCount = 0; - _textDimData[dim].color1 = isPc98 ? 0x33 : 254; + _textDimData[dim].color1 = _vm->gameFlags().use16ColorMode ? 0x33 : 254; _textDimData[dim].color2 = _screen->_curDim->unkA; } int cp = _screen->setCurPage(0); - Screen::FontId of = _screen->setFont(_vm->gameFlags().use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); + Screen::FontId of = _screen->setFont((_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_9_FNT); preprocessString(str, script, paramList, paramIndex); _numCharsTotal = strlen(_dialogueBuffer); @@ -228,10 +226,9 @@ void TextDisplayer_LoL::printMessage(uint16 type, const char *str, ...) { void TextDisplayer_LoL::preprocessString(char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) { char *dst = _dialogueBuffer; - const bool isPc98 = (_vm->gameFlags().platform == Common::kPlatformPC98); for (char *s = str; *s;) { - if (isPc98) { + if (_vm->gameFlags().lang == Common::JA_JPN) { uint8 c = *s; if (c >= 0xE0 || (c > 0x80 && c < 0xA0)) { *dst++ = *s++; diff --git a/engines/kyra/text_rpg.cpp b/engines/kyra/text_rpg.cpp index 07f4fe0057..a19d678e35 100644 --- a/engines/kyra/text_rpg.cpp +++ b/engines/kyra/text_rpg.cpp @@ -36,7 +36,7 @@ enum { TextDisplayer_rpg::TextDisplayer_rpg(KyraRpgEngine *engine, Screen *scr) : _vm(engine), _screen(scr), _lineCount(0), _printFlag(false), _lineWidth(0), _numCharsTotal(0), _allowPageBreak(true), - _numCharsLeft(0), _numCharsPrinted(0), _sjisLineBreakFlag(false), _waitButtonMode(1) { + _numCharsLeft(0), _numCharsPrinted(0), _sjisTextModeLineBreak(false), _waitButtonMode(1) { _dialogueBuffer = new char[kEoBTextBufferSize]; memset(_dialogueBuffer, 0, kEoBTextBufferSize); @@ -88,8 +88,8 @@ void TextDisplayer_rpg::resetDimTextPositions(int dim) { } void TextDisplayer_rpg::resetPageBreakString() { - if (vm()->_moreStrings) - strcpy(_pageBreakString, vm()->_moreStrings[0]); + if (_vm->_moreStrings) + strcpy(_pageBreakString, _vm->_moreStrings[0]); } void TextDisplayer_rpg::setPageBreakFlag() { @@ -102,8 +102,6 @@ void TextDisplayer_rpg::removePageBreakFlag() { } void TextDisplayer_rpg::displayText(char *str, ...) { - const bool isPc98 = (_vm->gameFlags().platform == Common::kPlatformPC98); - _printFlag = false; _lineWidth = 0; @@ -125,7 +123,9 @@ void TextDisplayer_rpg::displayText(char *str, ...) { const ScreenDim *sd = _screen->_curDim; int sdx = _screen->curDimIndex(); - bool pc98PrintFlag = (isPc98 && (sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) ? true : false; + bool sjisTextMode = (_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode && (sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) ? true : false; + int sjisOffs = sjisTextMode ? 8 : 9; + uint16 charsPerLine = (sd->w << 3) / (_screen->getFontWidth() + _screen->_charWidth); while (c) { @@ -146,15 +146,25 @@ void TextDisplayer_rpg::displayText(char *str, ...) { c = parseCommand(); } - if (isPc98) { + if (_vm->gameFlags().lang == Common::JA_JPN) { uint8 cu = (uint8) c; if (cu >= 0xE0 || (cu > 0x80 && cu < 0xA0)) { - _currentLine[_numCharsLeft++] = c; - _currentLine[_numCharsLeft++] = parseCommand(); - _currentLine[_numCharsLeft] = '\0'; - _lineWidth += 8; - if ((_textDimData[sdx].column + _lineWidth) > (sd->w << 3)) + if (sjisTextMode) { + _currentLine[_numCharsLeft++] = c; + _currentLine[_numCharsLeft++] = parseCommand(); + _currentLine[_numCharsLeft] = '\0'; + } + + if ((_textDimData[sdx].column + _lineWidth + sjisOffs) > (sd->w << 3)) printLine(_currentLine); + + if (!sjisTextMode) { + _currentLine[_numCharsLeft++] = c; + _currentLine[_numCharsLeft++] = parseCommand(); + _currentLine[_numCharsLeft] = '\0'; + } + + _lineWidth += sjisOffs; c = parseCommand(); continue; } @@ -189,10 +199,10 @@ void TextDisplayer_rpg::displayText(char *str, ...) { break; case 12: - if (isPc98) - _sjisLineBreakFlag = true; + if (sjisTextMode) + _sjisTextModeLineBreak = true; printLine(_currentLine); - _sjisLineBreakFlag = false; + _sjisTextModeLineBreak = false; _lineCount++; _textDimData[sdx].column = 0; _textDimData[sdx].line++; @@ -208,7 +218,7 @@ void TextDisplayer_rpg::displayText(char *str, ...) { default: if (_vm->game() == GI_LOL || (unsigned char)c > 30) { - _lineWidth += (pc98PrintFlag ? 4 : _screen->getCharWidth((uint8)c)); + _lineWidth += (sjisTextMode ? 4 : (_screen->_currentFont == Screen::FID_SJIS_FNT ? 9 : _screen->getCharWidth((uint8)c))); _currentLine[_numCharsLeft++] = c; _currentLine[_numCharsLeft] = 0; @@ -280,10 +290,9 @@ void TextDisplayer_rpg::readNextPara() { } void TextDisplayer_rpg::printLine(char *str) { - const bool isPc98 = (_vm->gameFlags().platform == Common::kPlatformPC98); const ScreenDim *sd = _screen->_curDim; int sdx = _screen->curDimIndex(); - bool pc98PrintFlag = (isPc98 && (sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) ? true : false; + bool sjisTextMode = (_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode && (sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) ? true : false; int fh = (_screen->_currentFont == Screen::FID_SJIS_FNT) ? 9 : (_screen->getFontHeight() + _screen->_charOffset); int lines = (sd->h - _screen->_charOffset) / fh; @@ -307,25 +316,27 @@ void TextDisplayer_rpg::printLine(char *str) { } int x1 = (sd->sx << 3) + _textDimData[sdx].column; - int y = sd->sy + (pc98PrintFlag ? (_textDimData[sdx].line << 3) : (fh * _textDimData[sdx].line)); + int y = sd->sy + (sjisTextMode ? (_textDimData[sdx].line << 3) : (fh * _textDimData[sdx].line)); int w = sd->w << 3; int lw = _lineWidth; int s = _numCharsLeft; char c = 0; + uint8 twoByteCharOffs = 0; - if (pc98PrintFlag) { + + if (sjisTextMode) { bool ct = true; if ((lw + _textDimData[sdx].column) > w) { if ((lines - 1 - (_waitButtonSpace << 1)) <= _lineCount) // cut off line to leave space for "MORE" button - w -= vm()->guiSettings()->buttons.waitReserve; + w -= _vm->guiSettings()->buttons.waitReserve; } else { - if (!_sjisLineBreakFlag || (_lineCount + 1 < lines - 1)) + if (!_sjisTextModeLineBreak || (_lineCount + 1 < lines - 1)) ct = false; else // cut off line to leave space for "MORE" button - w -= vm()->guiSettings()->buttons.waitReserve; + w -= _vm->guiSettings()->buttons.waitReserve; } if (ct) { @@ -344,41 +355,88 @@ void TextDisplayer_rpg::printLine(char *str) { s = n2; } } else { - if ((lw + _textDimData[sdx].column) > w) { + if (_vm->gameFlags().lang == Common::JA_JPN) { + for (int i = 0; i < s; ++i) { + uint8 cu = (uint8) str[i]; + if (cu >= 0xE0 || (cu > 0x80 && cu < 0xA0)) + twoByteCharOffs = 8; + } + } + + if ((lw + _textDimData[sdx].column) >= w) { if ((lines - 1) <= _lineCount && _allowPageBreak) // cut off line to leave space for "MORE" button - w -= vm()->guiSettings()->buttons.waitReserve; + w -= _vm->guiSettings()->buttons.waitReserve; w -= _textDimData[sdx].column; - int n2 = 0; - int n1 = s - 1; + int lineLastCharPos = 0; + int strPos = s - 1; + + if (twoByteCharOffs) { + lw = 0; + int prevStrPos = 0; + c = str[0]; + + for (strPos = 0; strPos < s; ++strPos) { + uint8 cu = (uint8) str[strPos]; + if (cu >= 0xE0 || (cu > 0x80 && cu < 0xA0)) { + lw += 9; + strPos++; + } else { + lw += _screen->getCharWidth((uint8)c); + } + + if (!lineLastCharPos && w < lw + twoByteCharOffs) + lineLastCharPos = prevStrPos; + + if (lineLastCharPos && c == ' ') { + s = strPos; + _printFlag = false; + break; + } + prevStrPos = strPos; + c = (char) cu; + } + + if (!lineLastCharPos) { + lineLastCharPos = s - 1; + if (lineLastCharPos && str[lineLastCharPos] == ' ') { + s = strPos; + _printFlag = false; + } + } - while (n1 > 0) { - //cut off line after last space - c = str[n1]; + lw = _lineWidth; - lw -= _screen->getCharWidth((uint8)c); + } else { + while (strPos > 0) { + //cut off line after last space + c = str[strPos]; - if (!n2 && lw <= w) - n2 = n1; + lw -= _screen->getCharWidth((uint8)c); - if (n2 && c == ' ') { - s = n1; - _printFlag = false; - break; + if (!lineLastCharPos && lw <= w) + lineLastCharPos = strPos; + + if (lineLastCharPos && c == ' ') { + s = strPos; + _printFlag = false; + break; + } + strPos--; } - n1--; } - if (!n1) { + if (!strPos) { if (_textDimData[sdx].column && !_printFlag) { s = lw = 0; _printFlag = true; } else { - s = n2; + s = lineLastCharPos; } } + } } @@ -386,7 +444,7 @@ void TextDisplayer_rpg::printLine(char *str) { str[s] = 0; uint8 col = _textDimData[sdx].color1; - if (isPc98 && (sdx == 2 || sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) { + if (sjisTextMode && (sdx == 2 || sdx == 3 || sdx == 4 || sdx == 5 || sdx == 15)) { switch (_textDimData[sdx].color1) { case 0x88: col = 0x41; @@ -413,6 +471,7 @@ void TextDisplayer_rpg::printLine(char *str) { _screen->printText(str, x1 & ~3, (y + 8) & ~7, col, 0); } else { _screen->printText(str, x1, y, col, _textDimData[sdx].color2); + _screen->updateScreen(); } _textDimData[sdx].column += lw; @@ -432,9 +491,9 @@ void TextDisplayer_rpg::printLine(char *str) { str[len] = 0; _numCharsLeft = strlen(str); - _lineWidth = pc98PrintFlag ? (_numCharsLeft << 2) : _screen->getTextWidth(str); + _lineWidth = sjisTextMode ? (_numCharsLeft << 2) : (_screen->_currentFont == Screen::FID_SJIS_FNT ? _numCharsLeft * 9: _screen->getTextWidth(str)); - if (!_numCharsLeft && _textDimData[sdx].column < (sd->w << 3)) + if (!_numCharsLeft && (_textDimData[sdx].column + twoByteCharOffs) <= (sd->w << 3)) return; _textDimData[sdx].column = 0; @@ -483,7 +542,7 @@ void TextDisplayer_rpg::printMessage(const char *str, int textColor, ...) { displayText(_dialogueBuffer); - if (vm()->game() != GI_EOB1) + if (_vm->game() != GI_EOB1) _textDimData[_screen->curDimIndex()].color1 = tc; if (!_screen->_curPage) @@ -494,7 +553,7 @@ int TextDisplayer_rpg::clearDim(int dim) { int res = _screen->curDimIndex(); _screen->setScreenDim(dim); _textDimData[dim].color1 = _screen->_curDim->unk8; - _textDimData[dim].color2 = vm()->game() == GI_LOL ? _screen->_curDim->unkA : vm()->guiSettings()->colors.fill; + _textDimData[dim].color2 = _vm->game() == GI_LOL ? _screen->_curDim->unkA : _vm->guiSettings()->colors.fill; clearCurDim(); return res; } @@ -502,7 +561,7 @@ int TextDisplayer_rpg::clearDim(int dim) { void TextDisplayer_rpg::clearCurDim() { int d = _screen->curDimIndex(); const ScreenDim *tmp = _screen->getScreenDim(d); - if (vm()->gameFlags().use16ColorMode) { + if (_vm->gameFlags().use16ColorMode) { _screen->fillRect(tmp->sx << 3, tmp->sy, ((tmp->sx + tmp->w) << 3) - 2, (tmp->sy + tmp->h) - 2, _textDimData[d].color2); } else _screen->fillRect(tmp->sx << 3, tmp->sy, ((tmp->sx + tmp->w) << 3) - 1, (tmp->sy + tmp->h) - 1, _textDimData[d].color2); @@ -512,40 +571,40 @@ void TextDisplayer_rpg::clearCurDim() { } void TextDisplayer_rpg::textPageBreak() { - if (vm()->game() != GI_LOL) - SWAP(vm()->_dialogueButtonLabelColor1, vm()->_dialogueButtonLabelColor2); + if (_vm->game() != GI_LOL) + SWAP(_vm->_dialogueButtonLabelColor1, _vm->_dialogueButtonLabelColor2); int cp = _screen->setCurPage(0); - Screen::FontId cf = _screen->setFont(vm()->gameFlags().use16ColorMode ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); + Screen::FontId cf = _screen->setFont((_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().use16ColorMode) ? Screen::FID_SJIS_FNT : Screen::FID_6_FNT); - if (vm()->game() == GI_LOL) - vm()->_timer->pauseSingleTimer(11, true); + if (_vm->game() == GI_LOL) + _vm->_timer->pauseSingleTimer(11, true); - vm()->_fadeText = false; + _vm->_fadeText = false; int resetPortraitAfterSpeechAnim = 0; int updatePortraitSpeechAnimDuration = 0; - if (vm()->_updateCharNum != -1) { - resetPortraitAfterSpeechAnim = vm()->_resetPortraitAfterSpeechAnim; - vm()->_resetPortraitAfterSpeechAnim = 0; - updatePortraitSpeechAnimDuration = vm()->_updatePortraitSpeechAnimDuration; - if (vm()->_updatePortraitSpeechAnimDuration > 36) - vm()->_updatePortraitSpeechAnimDuration = 36; + if (_vm->_updateCharNum != -1) { + resetPortraitAfterSpeechAnim = _vm->_resetPortraitAfterSpeechAnim; + _vm->_resetPortraitAfterSpeechAnim = 0; + updatePortraitSpeechAnimDuration = _vm->_updatePortraitSpeechAnimDuration; + if (_vm->_updatePortraitSpeechAnimDuration > 36) + _vm->_updatePortraitSpeechAnimDuration = 36; } uint32 speechPartTime = 0; - if (vm()->speechEnabled() && vm()->_activeVoiceFileTotalTime && _numCharsTotal) - speechPartTime = vm()->_system->getMillis() + ((_numCharsPrinted * vm()->_activeVoiceFileTotalTime) / _numCharsTotal); + if (_vm->speechEnabled() && _vm->_activeVoiceFileTotalTime && _numCharsTotal) + speechPartTime = _vm->_system->getMillis() + ((_numCharsPrinted * _vm->_activeVoiceFileTotalTime) / _numCharsTotal); const ScreenDim *dim = _screen->getScreenDim(_screen->curDimIndex()); int x = ((dim->sx + dim->w) << 3) - (_vm->_dialogueButtonWidth + 3); int y = 0; - int w = vm()->_dialogueButtonWidth; + int w = _vm->_dialogueButtonWidth; - if (vm()->game() == GI_LOL) { - if (vm()->_needSceneRestore && (vm()->_updateFlags & 2)) { - if (vm()->_currentControlMode || !(vm()->_updateFlags & 2)) { + if (_vm->game() == GI_LOL) { + if (_vm->_needSceneRestore && (_vm->_updateFlags & 2)) { + if (_vm->_currentControlMode || !(_vm->_updateFlags & 2)) { y = dim->sy + dim->h - 5; } else { x += 6; @@ -555,49 +614,49 @@ void TextDisplayer_rpg::textPageBreak() { y = dim->sy + dim->h - 10; } } else { - y = vm()->guiSettings()->buttons.waitY[_waitButtonMode]; - x = vm()->guiSettings()->buttons.waitX[_waitButtonMode]; - w = vm()->guiSettings()->buttons.waitWidth[_waitButtonMode]; + y = _vm->guiSettings()->buttons.waitY[_waitButtonMode]; + x = _vm->guiSettings()->buttons.waitX[_waitButtonMode]; + w = _vm->guiSettings()->buttons.waitWidth[_waitButtonMode]; } - if (vm()->gameFlags().use16ColorMode) { - vm()->gui_drawBox(x + 8, (y & ~7) - 1, 66, 10, 0xEE, 0xCC, -1); + if (_vm->gameFlags().use16ColorMode) { + _vm->gui_drawBox(x + 8, (y & ~7) - 1, 66, 10, 0xEE, 0xCC, -1); _screen->printText(_pageBreakString, (x + 37 - (strlen(_pageBreakString) << 1) + 4) & ~3, (y + 2) & ~7, 0xC1, 0); } else { - vm()->gui_drawBox(x, y, w, vm()->guiSettings()->buttons.height, vm()->guiSettings()->colors.frame1, vm()->guiSettings()->colors.frame2, vm()->guiSettings()->colors.fill); - _screen->printText(_pageBreakString, x + (w >> 1) - (vm()->screen()->getTextWidth(_pageBreakString) >> 1), y + 2, vm()->_dialogueButtonLabelColor1, 0); + _vm->gui_drawBox(x, y, w, _vm->guiSettings()->buttons.height, _vm->guiSettings()->colors.frame1, _vm->guiSettings()->colors.frame2, _vm->guiSettings()->colors.fill); + _screen->printText(_pageBreakString, x + (w >> 1) - (_vm->screen()->getTextWidth(_pageBreakString) >> 1), y + 2, _vm->_dialogueButtonLabelColor1, 0); } - vm()->removeInputTop(); + _vm->removeInputTop(); bool loop = true; bool target = false; do { - int inputFlag = vm()->checkInput(0, false) & 0xFF; - vm()->removeInputTop(); + int inputFlag = _vm->checkInput(0, false) & 0xFF; + _vm->removeInputTop(); while (!inputFlag && !_vm->shouldQuit()) { - vm()->update(); + _vm->update(); - if (vm()->speechEnabled()) { - if (((vm()->_system->getMillis() > speechPartTime) || (vm()->snd_updateCharacterSpeech() != 2)) && speechPartTime) { + if (_vm->speechEnabled()) { + if (((_vm->_system->getMillis() > speechPartTime) || (_vm->snd_updateCharacterSpeech() != 2)) && speechPartTime) { loop = false; - inputFlag = vm()->_keyMap[Common::KEYCODE_RETURN]; + inputFlag = _vm->_keyMap[Common::KEYCODE_RETURN]; break; } } - inputFlag = vm()->checkInput(0, false) & 0xFF; - vm()->removeInputTop(); + inputFlag = _vm->checkInput(0, false) & 0xFF; + _vm->removeInputTop(); } - vm()->gui_notifyButtonListChanged(); + _vm->gui_notifyButtonListChanged(); - if (inputFlag == vm()->_keyMap[Common::KEYCODE_SPACE] || inputFlag == vm()->_keyMap[Common::KEYCODE_RETURN]) { + if (inputFlag == _vm->_keyMap[Common::KEYCODE_SPACE] || inputFlag == _vm->_keyMap[Common::KEYCODE_RETURN]) { loop = false; } else if (inputFlag == 199 || inputFlag == 201) { - if (vm()->posWithinRect(vm()->_mouseX, vm()->_mouseY, x, y, x + w, y + 9)) { + if (_vm->posWithinRect(_vm->_mouseX, _vm->_mouseY, x, y, x + w, y + 9)) { if (_vm->game() == GI_LOL) target = true; else @@ -609,7 +668,7 @@ void TextDisplayer_rpg::textPageBreak() { } } while (loop && !_vm->shouldQuit()); - if (vm()->gameFlags().use16ColorMode) + if (_vm->gameFlags().use16ColorMode) _screen->fillRect(x + 8, y, x + 57, y + 9, _textDimData[_screen->curDimIndex()].color2); else _screen->fillRect(x, y, x + w - 1, y + 8, _textDimData[_screen->curDimIndex()].color2); @@ -617,52 +676,52 @@ void TextDisplayer_rpg::textPageBreak() { clearCurDim(); _screen->updateScreen(); - if (vm()->game() == GI_LOL) - vm()->_timer->pauseSingleTimer(11, false); + if (_vm->game() == GI_LOL) + _vm->_timer->pauseSingleTimer(11, false); - if (vm()->_updateCharNum != -1) { - vm()->_resetPortraitAfterSpeechAnim = resetPortraitAfterSpeechAnim; + if (_vm->_updateCharNum != -1) { + _vm->_resetPortraitAfterSpeechAnim = resetPortraitAfterSpeechAnim; if (updatePortraitSpeechAnimDuration > 36) updatePortraitSpeechAnimDuration -= 36; else updatePortraitSpeechAnimDuration >>= 1; - vm()->_updatePortraitSpeechAnimDuration = updatePortraitSpeechAnimDuration; + _vm->_updatePortraitSpeechAnimDuration = updatePortraitSpeechAnimDuration; } _screen->setFont(cf); _screen->setCurPage(cp); - if (vm()->game() != GI_LOL) - SWAP(vm()->_dialogueButtonLabelColor1, vm()->_dialogueButtonLabelColor2); + if (_vm->game() != GI_LOL) + SWAP(_vm->_dialogueButtonLabelColor1, _vm->_dialogueButtonLabelColor2); - vm()->removeInputTop(); + _vm->removeInputTop(); } void TextDisplayer_rpg::displayWaitButton() { - vm()->_dialogueNumButtons = 1; - vm()->_dialogueButtonString[0] = _pageBreakString; - vm()->_dialogueButtonString[1] = 0; - vm()->_dialogueButtonString[2] = 0; - vm()->_dialogueHighlightedButton = 0; + _vm->_dialogueNumButtons = 1; + _vm->_dialogueButtonString[0] = _pageBreakString; + _vm->_dialogueButtonString[1] = 0; + _vm->_dialogueButtonString[2] = 0; + _vm->_dialogueHighlightedButton = 0; - vm()->_dialogueButtonPosX = &vm()->guiSettings()->buttons.waitX[_waitButtonMode]; - vm()->_dialogueButtonPosY = &vm()->guiSettings()->buttons.waitY[_waitButtonMode]; - vm()->_dialogueButtonWidth = vm()->guiSettings()->buttons.waitWidth[_waitButtonMode]; - vm()->_dialogueButtonYoffs = 0; + _vm->_dialogueButtonPosX = &_vm->guiSettings()->buttons.waitX[_waitButtonMode]; + _vm->_dialogueButtonPosY = &_vm->guiSettings()->buttons.waitY[_waitButtonMode]; + _vm->_dialogueButtonWidth = _vm->guiSettings()->buttons.waitWidth[_waitButtonMode]; + _vm->_dialogueButtonYoffs = 0; - SWAP(vm()->_dialogueButtonLabelColor1, vm()->_dialogueButtonLabelColor2); - vm()->drawDialogueButtons(); + SWAP(_vm->_dialogueButtonLabelColor1, _vm->_dialogueButtonLabelColor2); + _vm->drawDialogueButtons(); - if (!vm()->shouldQuit()) - vm()->removeInputTop(); + if (!_vm->shouldQuit()) + _vm->removeInputTop(); - while (!vm()->processDialogue() && !vm()->shouldQuit()) {} + while (!_vm->processDialogue() && !_vm->shouldQuit()) {} - _screen->fillRect(vm()->_dialogueButtonPosX[0], vm()->_dialogueButtonPosY[0], vm()->_dialogueButtonPosX[0] + vm()->_dialogueButtonWidth - 1, vm()->_dialogueButtonPosY[0] + vm()->guiSettings()->buttons.height - 1, vm()->guiSettings()->colors.fill); + _screen->fillRect(_vm->_dialogueButtonPosX[0], _vm->_dialogueButtonPosY[0], _vm->_dialogueButtonPosX[0] + _vm->_dialogueButtonWidth - 1, _vm->_dialogueButtonPosY[0] + _vm->guiSettings()->buttons.height - 1, _vm->guiSettings()->colors.fill); _screen->updateScreen(); - vm()->_dialogueButtonWidth = 95; - SWAP(vm()->_dialogueButtonLabelColor1, vm()->_dialogueButtonLabelColor2); + _vm->_dialogueButtonWidth = 95; + SWAP(_vm->_dialogueButtonLabelColor1, _vm->_dialogueButtonLabelColor2); clearCurDim(); } diff --git a/engines/kyra/text_rpg.h b/engines/kyra/text_rpg.h index 5ad8899484..eb8617a371 100644 --- a/engines/kyra/text_rpg.h +++ b/engines/kyra/text_rpg.h @@ -79,7 +79,7 @@ protected: uint32 _numCharsPrinted; bool _printFlag; - bool _sjisLineBreakFlag; + bool _sjisTextModeLineBreak; char _pageBreakString[20]; char _scriptParaString[11]; diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 5ae8245e5a..1bf3323a7b 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -3633,6 +3633,8 @@ bool Console::cmdAddresses(int argc, const char **argv) { DebugPrintf(" - ?obj -- Looks up an object with the specified name, uses its address. This will abort if\n"); DebugPrintf(" the object name is ambiguous; in that case, a list of addresses and indices is provided.\n"); DebugPrintf(" ?obj.idx may be used to disambiguate 'obj' by the index 'idx'.\n"); + DebugPrintf(" Underscores are used as substitute characters for spaces in object names.\n"); + DebugPrintf(" For example, an object named \"Glass Jar\" can be accessed as \"Glass_Jar\".\n"); return true; } @@ -3764,6 +3766,8 @@ static int parse_reg_t(EngineState *s, const char *str, reg_t *dest, bool mayBeV charsCountObject++; if ((*strLoop >= 'I') && (*strLoop <= 'Z')) charsCountObject++; + if (*strLoop == '_') // underscores are used as substitutes for spaces in object names + charsCountObject++; } strLoop++; } @@ -3836,10 +3840,16 @@ static int parse_reg_t(EngineState *s, const char *str, reg_t *dest, bool mayBeV index = strtol(tmp + 1, &endptr, 16); if (*endptr) return -1; - // Chop of the index + // Chop off the index str_objname = Common::String(str_objname.c_str(), tmp); } + // Replace all underscores in the name with spaces + for (uint i = 0; i < str_objname.size(); i++) { + if (str_objname[i] == '_') + str_objname.setChar(' ', i); + } + // Now all values are available; iterate over all objects. *dest = s->_segMan->findObjectByName(str_objname, index); if (dest->isNull()) diff --git a/engines/sci/detection_tables.h b/engines/sci/detection_tables.h index 736d0b7ddc..5640319e3f 100644 --- a/engines/sci/detection_tables.h +++ b/engines/sci/detection_tables.h @@ -3646,7 +3646,7 @@ static const struct ADGameDescription SciGameDescriptions[] = { {"resource.map", 0, "ed90a8e3ccc53af6633ff6ab58392bae", 7054}, {"resource.000", 0, "63247e3901ab8963d4eece73747832e0", 5157378}, AD_LISTEND}, - Common::EN_ANY, Common::kPlatformPC, ADGF_CD, GUIO5(GUIO_MIDIGM, GAMEOPTION_SQ4_SILVER_CURSORS, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_FB01_MIDI) }, + Common::EN_ANY, Common::kPlatformPC, ADGF_CD, GUIO4(GAMEOPTION_SQ4_SILVER_CURSORS, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_FB01_MIDI) }, // Space Quest 4 - English Windows CD (from the Space Quest Collection) // Executable scanning reports "1.001.064", VERSION file reports "1.0" diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index f985a69ebc..e3ebce80fb 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -427,18 +427,23 @@ reg_t kUpdatePlane(EngineState *s, int argc, reg_t *argv); reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv); reg_t kGetHighPlanePri(EngineState *s, int argc, reg_t *argv); reg_t kFrameOut(EngineState *s, int argc, reg_t *argv); + reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv); // kOnMe for SCI2, kIsOnMe for SCI2.1 +reg_t kInPolygon(EngineState *s, int argc, reg_t *argv); +reg_t kObjectIntersect(EngineState *s, int argc, reg_t *argv); + reg_t kListIndexOf(EngineState *s, int argc, reg_t *argv); reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv); reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv); reg_t kListAllTrue(EngineState *s, int argc, reg_t *argv); -reg_t kInPolygon(EngineState *s, int argc, reg_t *argv); -reg_t kObjectIntersect(EngineState *s, int argc, reg_t *argv); + reg_t kEditText(EngineState *s, int argc, reg_t *argv); reg_t kMakeSaveCatName(EngineState *s, int argc, reg_t *argv); reg_t kMakeSaveFileName(EngineState *s, int argc, reg_t *argv); reg_t kSetScroll(EngineState *s, int argc, reg_t *argv); reg_t kPalCycle(EngineState *s, int argc, reg_t *argv); +reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv); +reg_t kPalVaryUnknown2(EngineState *s, int argc, reg_t *argv); // SCI2.1 Kernel Functions reg_t kText(EngineState *s, int argc, reg_t *argv); @@ -513,7 +518,6 @@ reg_t kPalVaryDeinit(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryChangeTarget(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryChangeTicks(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryPauseResume(EngineState *s, int argc, reg_t *argv); -reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv); reg_t kPaletteSetFromResource(EngineState *s, int argc, reg_t *argv); reg_t kPaletteSetFlag(EngineState *s, int argc, reg_t *argv); diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h index d0c9b9b1cf..d7858180f1 100644 --- a/engines/sci/engine/kernel_tables.h +++ b/engines/sci/engine/kernel_tables.h @@ -156,7 +156,7 @@ static const SciKernelMapSubEntry kDoSound_subops[] = { // signature for SCI21 should be "o" { SIG_SOUNDSCI21, 9, MAP_CALL(DoSoundStop), NULL, NULL }, { SIG_SOUNDSCI21, 10, MAP_CALL(DoSoundPause), NULL, NULL }, - { SIG_SOUNDSCI21, 11, MAP_CALL(DoSoundFade), NULL, NULL }, + { SIG_SOUNDSCI21, 11, MAP_CALL(DoSoundFade), NULL, kDoSoundFade_workarounds }, { SIG_SOUNDSCI21, 12, MAP_CALL(DoSoundSetHold), NULL, NULL }, { SIG_SOUNDSCI21, 13, MAP_CALL(DoSoundDummy), NULL, NULL }, { SIG_SOUNDSCI21, 14, MAP_CALL(DoSoundSetVolume), NULL, NULL }, @@ -202,7 +202,10 @@ static const SciKernelMapSubEntry kPalVary_subops[] = { { SIG_SCIALL, 4, MAP_CALL(PalVaryChangeTarget), "i", NULL }, { SIG_SCIALL, 5, MAP_CALL(PalVaryChangeTicks), "i", NULL }, { SIG_SCIALL, 6, MAP_CALL(PalVaryPauseResume), "i", NULL }, +#ifdef ENABLE_SCI32 { SIG_SCI32, 8, MAP_CALL(PalVaryUnknown), "i", NULL }, + { SIG_SCI32, 9, MAP_CALL(PalVaryUnknown2), "i", NULL }, +#endif SCI_SUBOPENTRY_TERMINATOR }; diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index da377319c0..a65bcc215e 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -722,11 +722,6 @@ reg_t kPalVaryPauseResume(EngineState *s, int argc, reg_t *argv) { return NULL_REG; } -reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv) { - // Unknown (seems to be SCI32 exclusive) - return NULL_REG; -} - reg_t kAssertPalette(EngineState *s, int argc, reg_t *argv) { GuiResourceId paletteId = argv[0].toUint16(); diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp index 1d30f709dc..cd735d1233 100644 --- a/engines/sci/engine/kgraphics32.cpp +++ b/engines/sci/engine/kgraphics32.cpp @@ -683,6 +683,22 @@ reg_t kSetScroll(EngineState *s, int argc, reg_t *argv) { return kStub(s, argc, argv); } +reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv) { + // TODO: Unknown (seems to be SCI32 exclusive) + return kStub(s, argc, argv); +} + +reg_t kPalVaryUnknown2(EngineState *s, int argc, reg_t *argv) { + // TODO: Unknown (seems to be SCI32 exclusive) + // It seems to be related to the day/night palette effects in QFG4, and + // accepts a palette resource ID. It is triggered right when the night + // effect is initially applied (when exiting the caves). + // In QFG4, there are two scene palettes: 790 for night, and 791 for day. + // Initially, the game starts at night time, but this is called with the + // ID of the day time palette (i.e. 791). + return kStub(s, argc, argv); +} + reg_t kPalCycle(EngineState *s, int argc, reg_t *argv) { // Examples: GK1 room 480 (Bayou ritual), LSL6 room 100 (title screen) diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 4b8fadbb84..b2aaa01b45 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -77,18 +77,7 @@ reg_t kSqrt(EngineState *s, int argc, reg_t *argv) { return make_reg(0, (int16) sqrt((float) ABS(argv[0].toSint16()))); } -/** - * Returns the angle (in degrees) between the two points determined by (x1, y1) - * and (x2, y2). The angle ranges from 0 to 359 degrees. - * What this function does is pretty simple but apparently the original is not - * accurate. - */ -uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { - // SCI1 games (QFG2 and newer) use a simple atan implementation. SCI0 games - // use a somewhat less accurate calculation (below). - if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) - return (int16)(360 - atan2((double)(x1 - x2), (double)(y1 - y2)) * 57.2958) % 360; - +uint16 kGetAngle_SCI0(int16 x1, int16 y1, int16 x2, int16 y2) { int16 xRel = x2 - x1; int16 yRel = y1 - y2; // y-axis is mirrored. int16 angle; @@ -118,6 +107,75 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { return angle; } +// atan2 for first octant, x >= y >= 0. Returns [0,45] (inclusive) +int kGetAngle_SCI1_atan2_base(int y, int x) { + if (x == 0) + return 0; + + // fixed point tan(a) + int tan_fp = 10000 * y / x; + + if ( tan_fp >= 1000 ) { + // For tan(a) >= 0.1, interpolate between multiples of 5 degrees + + // 10000 * tan([5, 10, 15, 20, 25, 30, 35, 40, 45]) + const int tan_table[] = { 875, 1763, 2679, 3640, 4663, 5774, + 7002, 8391, 10000 }; + + // Look up tan(a) in our table + int i = 1; + while (tan_fp > tan_table[i]) ++i; + + // The angle a is between 5*i and 5*(i+1). We linearly interpolate. + int dist = tan_table[i] - tan_table[i-1]; + int interp = (5 * (tan_fp - tan_table[i-1]) + dist/2) / dist; + return 5*i + interp; + } else { + // for tan(a) < 0.1, tan(a) is approximately linear in a. + // tan'(0) = 1, so in degrees the slope of atan is 180/pi = 57.29... + return (57 * y + x/2) / x; + } +} + +int kGetAngle_SCI1_atan2(int y, int x) { + if (y < 0) { + int a = kGetAngle_SCI1_atan2(-y, -x); + if (a == 180) + return 0; + else + return 180 + a; + } + if (x < 0) + return 90 + kGetAngle_SCI1_atan2(-x, y); + if (y > x) + return 90 - kGetAngle_SCI1_atan2_base(x, y); + else + return kGetAngle_SCI1_atan2_base(y, x); + +} + +uint16 kGetAngle_SCI1(int16 x1, int16 y1, int16 x2, int16 y2) { + // We flip things around to get into the standard atan2 coordinate system + return kGetAngle_SCI1_atan2(x2 - x1, y1 - y2); + +} + +/** + * Returns the angle (in degrees) between the two points determined by (x1, y1) + * and (x2, y2). The angle ranges from 0 to 359 degrees. + * What this function does is pretty simple but apparently the original is not + * accurate. + */ + +uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { + if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) + return kGetAngle_SCI1(x1, y1, x2, y2); + else + return kGetAngle_SCI0(x1, y1, x2, y2); +} + + + reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) { // Based on behavior observed with a test program created with // SCI Studio. diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index c4db0b891c..65e139e1ee 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -155,30 +155,47 @@ reg_t kReadNumber(EngineState *s, int argc, reg_t *argv) { source++; /* Skip whitespace */ int16 result = 0; + int16 sign = 1; + if (*source == '-') { + sign = -1; + source++; + } if (*source == '$') { // Hexadecimal input - result = (int16)strtol(source + 1, NULL, 16); + source++; + char c; + while ((c = *source++) != 0) { + int16 x = 0; + if ((c >= '0') && (c <= '9')) + x = c - '0'; + else if ((c >= 'a') && (c <= 'f')) + x = c - 'a' + 10; + else if ((c >= 'A') && (c <= 'F')) + x = c - 'A' + 10; + else + // Stop if we encounter anything other than a digit (like atoi) + break; + result *= 16; + result += x; + } } else { // Decimal input. We can not use strtol/atoi in here, because while // Sierra used atoi, it was a non standard compliant atoi, that didn't // do clipping. In SQ4 we get the door code in here and that's even // larger than uint32! - if (*source == '-') { - // FIXME: Setting result to -1 does _not_ negate the output. - result = -1; - source++; - } - while (*source) { - if ((*source < '0') || (*source > '9')) + char c; + while ((c = *source++) != 0) { + if ((c < '0') || (c > '9')) // Stop if we encounter anything other than a digit (like atoi) break; result *= 10; - result += *source - 0x30; - source++; + result += c - '0'; } } + result *= sign; + return make_reg(0, result); } @@ -489,6 +506,7 @@ reg_t kGetMessage(EngineState *s, int argc, reg_t *argv) { reg_t kMessage(EngineState *s, int argc, reg_t *argv) { uint func = argv[0].toUint16(); + uint16 module = (argc >= 2) ? argv[1].toUint16() : 0; #ifdef ENABLE_SCI32 if (getSciVersion() >= SCI_VERSION_2) { @@ -518,19 +536,44 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (argc >= 6) tuple = MessageTuple(argv[2].toUint16(), argv[3].toUint16(), argv[4].toUint16(), argv[5].toUint16()); + // WORKAROUND for a script bug in Pepper. When using objects together, + // there is code inside script 894 that shows appropriate messages. + // In the case of the jar of cabbage (noun 26), the relevant message + // shown when using any object with it is missing. This leads to the + // script code being triggered, which modifies the jar's noun and + // message selectors, and renders it useless. Thus, when using any + // object with the jar of cabbage, it's effectively corrupted, and + // can't be used on the goat to empty it, therefore the game reaches + // an unsolvable state. It's almost impossible to patch the offending + // script, as it is used in many cases. But we can prevent the + // corruption of the jar here: if the message is found, the offending + // code is never reached and the jar is never corrupted. To do this, + // we substitute all verbs on the cabbage jar with the default verb, + // which shows the "Cannot use this object with the jar" message, and + // never triggers the offending script code that corrupts the object. + // This only affects the jar of cabbage - any other object, including + // the empty jar has a different noun, thus it's unaffected. + // Fixes bug #3601090. + // NOTE: To fix a corrupted jar object, type "send Glass_Jar message 52" + // in the debugger. + if (g_sci->getGameId() == GID_PEPPER && func == 0 && argc >= 6 && module == 894 && + tuple.noun == 26 && tuple.cond == 0 && tuple.seq == 1 && + !s->_msgState->getMessage(module, tuple, NULL_REG)) + tuple.verb = 0; + switch (func) { case K_MESSAGE_GET: - return make_reg(0, s->_msgState->getMessage(argv[1].toUint16(), tuple, (argc == 7 ? argv[6] : NULL_REG))); + return make_reg(0, s->_msgState->getMessage(module, tuple, (argc == 7 ? argv[6] : NULL_REG))); case K_MESSAGE_NEXT: return make_reg(0, s->_msgState->nextMessage((argc == 2 ? argv[1] : NULL_REG))); case K_MESSAGE_SIZE: - return make_reg(0, s->_msgState->messageSize(argv[1].toUint16(), tuple)); + return make_reg(0, s->_msgState->messageSize(module, tuple)); case K_MESSAGE_REFCOND: case K_MESSAGE_REFVERB: case K_MESSAGE_REFNOUN: { MessageTuple t; - if (s->_msgState->messageRef(argv[1].toUint16(), tuple, t)) { + if (s->_msgState->messageRef(module, tuple, t)) { switch (func) { case K_MESSAGE_REFCOND: return make_reg(0, t.cond); @@ -545,9 +588,9 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { } case K_MESSAGE_LASTMESSAGE: { MessageTuple msg; - int module; + int lastModule; - s->_msgState->lastQuery(module, msg); + s->_msgState->lastQuery(lastModule, msg); bool ok = false; @@ -556,7 +599,7 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (buffer) { ok = true; - WRITE_LE_UINT16(buffer, module); + WRITE_LE_UINT16(buffer, lastModule); WRITE_LE_UINT16(buffer + 2, msg.noun); WRITE_LE_UINT16(buffer + 4, msg.verb); WRITE_LE_UINT16(buffer + 6, msg.cond); @@ -567,7 +610,7 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (buffer) { ok = true; - buffer[0] = make_reg(0, module); + buffer[0] = make_reg(0, lastModule); buffer[1] = make_reg(0, msg.noun); buffer[2] = make_reg(0, msg.verb); buffer[3] = make_reg(0, msg.cond); diff --git a/engines/sci/engine/script_patches.cpp b/engines/sci/engine/script_patches.cpp index 8639b6ef71..c928cf3569 100644 --- a/engines/sci/engine/script_patches.cpp +++ b/engines/sci/engine/script_patches.cpp @@ -883,12 +883,38 @@ const uint16 qfg1vgaPatchDialogHeader[] = { PATCH_END }; +// When clicking on the crusher in room 331, Ego approaches him to talk to him, +// an action that is handled by moveToCrusher::changeState in script 331. The +// scripts set Ego to move close to the crusher, but when Ego is running instead +// of walking, the target coordinates specified by script 331 are never reached, +// as Ego is making larger steps, and never reaches the required spot. This is an +// edge case that can occur when Ego is set to run. Normally, when clicking on +// the crusher, ego is supposed to move close to position 79, 165. We change it +// to 85, 165, which is not an edge case thus the freeze is avoided. +// Fixes bug #3585189. +const byte qfg1vgaSignatureMoveToCrusher[] = { + 9, + 0x51, 0x1f, // class Motion + 0x36, // push + 0x39, 0x4f, // pushi 4f (79 - x) + 0x38, 0xa5, 0x00, // pushi 00a5 (165 - y) + 0x7c, // pushSelf + 0 +}; + +const uint16 qfg1vgaPatchMoveToCrusher[] = { + PATCH_ADDTOOFFSET | +3, + 0x39, 0x55, // pushi 55 (85 - x) + PATCH_END +}; + // script, description, magic DWORD, adjust const SciScriptSignature qfg1vgaSignatures[] = { { 215, "fight event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents }, { 216, "weapon master event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents }, { 814, "window text temp space", 1, PATCH_MAGICDWORD(0x3f, 0xba, 0x87, 0x00), 0, qfg1vgaSignatureTempSpace, qfg1vgaPatchTempSpace }, { 814, "dialog header offset", 3, PATCH_MAGICDWORD(0x5b, 0x04, 0x80, 0x36), 0, qfg1vgaSignatureDialogHeader, qfg1vgaPatchDialogHeader }, + { 331, "moving to crusher", 1, PATCH_MAGICDWORD(0x51, 0x1f, 0x36, 0x39), 0, qfg1vgaSignatureMoveToCrusher, qfg1vgaPatchMoveToCrusher }, SCI_SIGNATUREENTRY_TERMINATOR }; diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp index db510c2545..ff7e601fcb 100644 --- a/engines/sci/engine/workarounds.cpp +++ b/engines/sci/engine/workarounds.cpp @@ -140,7 +140,7 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_QFG2, 260, 260, 0, "jabbarS", "changeState",0x2d22, -1, { WORKAROUND_FAKE, 0 } }, // During the thief's first mission (in the house), just before Jabbar is about to enter the house (where you have to hide in the wardrobe), bug #3040469, temps 1 and 2 { GID_QFG2, 500, 500, 0, "lightNextCandleS", "changeState", -1, -1, { WORKAROUND_FAKE, 0 } }, // Inside the last room, while Ad Avis performs the ritual to summon the genie - bug #3148418 { GID_QFG2, -1, 700, 0, NULL, "showSign", -1, 10, { WORKAROUND_FAKE, 0 } }, // Occurs sometimes when reading a sign in Raseir, Shapeir et al - bugs #3272735, #3275413 - { GID_QFG3, 510, 510, 0, "awardPrize", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // Simbani warrior challenge, after throwing the spears and retrieving the ring - bug #3049435 + { GID_QFG3, 510, 510, 0, "awardPrize", "changeState", -1, 0, { WORKAROUND_FAKE, 1 } }, // Simbani warrior challenge, after throwing the spears and retrieving the ring - bug #3049435. Must be non-zero, otherwise the prize is awarded twice - bug #3575570. { GID_QFG3, 140, 140, 0, "rm140", "init", 0x1008, 0, { WORKAROUND_FAKE, 0 } }, // when importing a character and selecting the previous profession - bug #3040460 { GID_QFG3, 330, 330, -1, "Teller", "doChild", -1, -1, { WORKAROUND_FAKE, 0 } }, // when talking to King Rajah about "Rajah" (bug #3036390, temp 1) or "Tarna" (temp 0), or when clicking on yourself and saying "Greet" (bug #3039774, temp 1) { GID_QFG3, 700, 700, -1, "monsterIsDead", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // in the jungle, after winning any fight, bug #3040624 @@ -151,6 +151,8 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_QFG4, -1, 15, -1, "charInitScreen", "dispatchEvent", -1, 5, { WORKAROUND_FAKE, 0 } }, // floppy version, when viewing the character screen { GID_QFG4, -1, 64917, -1, "controlPlane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, when entering the game menu { GID_QFG4, -1, 64917, -1, "Plane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, happens sometimes in fight scenes + { GID_QFG4, 520, 64950, 0, "fLake2", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // CD version, at the lake, when meeting the Rusalka and attempting to leave + { GID_QFG4, 800, 64950, 0, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // CD version, in the room with the spider pillar, when climbing on the pillar { GID_RAMA, 12, 64950, -1, "InterfaceFeature", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts { GID_RAMA, 12, 64950, -1, "hiliteOptText", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts { GID_RAMA, 12, 64950, -1, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts @@ -246,6 +248,7 @@ const SciWorkaroundEntry kDoSoundFade_workarounds[] = { { GID_KQ5, 213, 989, 0, "globalSound3", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // english floppy: when bandits leave the secret temple, parameter 4 is an object - bug #3037594 { GID_KQ6, 105, 989, 0, "globalSound", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // floppy: during intro, parameter 4 is an object { GID_KQ6, 460, 989, 0, "globalSound2", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // after pulling the black widow's web on the isle of wonder, parameter 4 is an object - bug #3034567 + { GID_QFG4, -1, 64989, 0, "longSong", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // CD version: many places, parameter 4 is an object (longSong) SCI_WORKAROUNDENTRY_TERMINATOR }; diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp index 14443db1e2..7318fe2f68 100644 --- a/engines/sci/event.cpp +++ b/engines/sci/event.cpp @@ -160,9 +160,15 @@ SciEvent EventManager::getScummVMEvent() { noEvent.mousePos = input.mousePos = mousePos; - if (!found || ev.type == Common::EVENT_MOUSEMOVE) - return noEvent; + if (!found || ev.type == Common::EVENT_MOUSEMOVE) { + int modifiers = em->getModifierState(); + noEvent.modifiers = + ((modifiers & Common::KBD_ALT) ? SCI_KEYMOD_ALT : 0) | + ((modifiers & Common::KBD_CTRL) ? SCI_KEYMOD_CTRL : 0) | + ((modifiers & Common::KBD_SHIFT) ? SCI_KEYMOD_LSHIFT | SCI_KEYMOD_RSHIFT : 0); + return noEvent; + } if (ev.type == Common::EVENT_QUIT) { input.type = SCI_EVENT_QUIT; return input; diff --git a/engines/sci/graphics/animate.h b/engines/sci/graphics/animate.h index 5e2e39ea1a..52da7d6ec6 100644 --- a/engines/sci/graphics/animate.h +++ b/engines/sci/graphics/animate.h @@ -51,7 +51,6 @@ enum ViewScaleSignals { kScaleSignalDoScaling = 0x0001, // enables scaling when drawing that cel (involves scaleX and scaleY) kScaleSignalGlobalScaling = 0x0002, // means that global scaling shall get applied on that cel (sets scaleX/scaleY) kScaleSignalHoyle4SpecialHandling = 0x0004 // HOYLE4-exclusive: special handling inside kAnimate, is used when giving out cards - }; struct AnimateEntry { diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp index 8b7fa2c384..e251bd3dc0 100644 --- a/engines/sci/graphics/frameout.cpp +++ b/engines/sci/graphics/frameout.cpp @@ -349,6 +349,36 @@ void GfxFrameout::deletePlaneLine(reg_t object, reg_t hunkId) { } } +// Adapted from GfxAnimate::applyGlobalScaling() +void GfxFrameout::applyGlobalScaling(FrameoutEntry *itemEntry, Common::Rect planeRect, int16 celHeight) { + // Global scaling uses global var 2 and some other stuff to calculate scaleX/scaleY + int16 maxScale = readSelectorValue(_segMan, itemEntry->object, SELECTOR(maxScale)); + int16 maxCelHeight = (maxScale * celHeight) >> 7; + reg_t globalVar2 = g_sci->getEngineState()->variables[VAR_GLOBAL][2]; // current room object + int16 vanishingY = readSelectorValue(_segMan, globalVar2, SELECTOR(vanishingY)); + + int16 fixedPortY = planeRect.bottom - vanishingY; + int16 fixedEntryY = itemEntry->y - vanishingY; + if (!fixedEntryY) + fixedEntryY = 1; + + if ((celHeight == 0) || (fixedPortY == 0)) + error("global scaling panic"); + + itemEntry->scaleY = (maxCelHeight * fixedEntryY) / fixedPortY; + itemEntry->scaleY = (itemEntry->scaleY * maxScale) / celHeight; + + // Make sure that the calculated value is sane + if (itemEntry->scaleY < 1 /*|| itemEntry->scaleY > 128*/) + itemEntry->scaleY = 128; + + itemEntry->scaleX = itemEntry->scaleY; + + // and set objects scale selectors + //writeSelectorValue(_segMan, itemEntry->object, SELECTOR(scaleX), itemEntry->scaleX); + //writeSelectorValue(_segMan, itemEntry->object, SELECTOR(scaleY), itemEntry->scaleY); +} + void GfxFrameout::kernelAddScreenItem(reg_t object) { // Ignore invalid items if (!_segMan->isObject(object)) { @@ -390,8 +420,15 @@ void GfxFrameout::kernelUpdateScreenItem(reg_t object) { itemEntry->priority = itemEntry->y; itemEntry->signal = readSelectorValue(_segMan, object, SELECTOR(signal)); - itemEntry->scaleX = readSelectorValue(_segMan, object, SELECTOR(scaleX)); - itemEntry->scaleY = readSelectorValue(_segMan, object, SELECTOR(scaleY)); + itemEntry->scaleSignal = readSelectorValue(_segMan, object, SELECTOR(scaleSignal)); + + if (itemEntry->scaleSignal & kScaleSignalDoScaling32) { + itemEntry->scaleX = readSelectorValue(_segMan, object, SELECTOR(scaleX)); + itemEntry->scaleY = readSelectorValue(_segMan, object, SELECTOR(scaleY)); + } else { + itemEntry->scaleX = 128; + itemEntry->scaleY = 128; + } itemEntry->visible = true; // Check if the entry can be hidden @@ -650,7 +687,13 @@ void GfxFrameout::kernelFrameout() { _paint32->fillRect(it->planeRect, it->planeBack); _coordAdjuster->pictureSetDisplayArea(it->planeRect); - _palette->drewPicture(it->pictureId); + // Invoking drewPicture() with an invalid picture ID in SCI32 results in + // invalidating the palVary palette when a palVary effect is active. This + // is quite obvious in QFG4, where the day time palette is incorrectly + // shown when exiting the caves, and the correct night time palette + // flashes briefly each time that kPalVaryInit is called. + if (it->pictureId != 0xFFFF) + _palette->drewPicture(it->pictureId); FrameoutList itemList; @@ -699,6 +742,14 @@ void GfxFrameout::kernelFrameout() { // TODO: maybe we should clip the cels rect with this, i'm not sure // the only currently known usage is game menu of gk1 } else if (view) { + // Process global scaling, if needed. + // TODO: Seems like SCI32 always processes global scaling for scaled objects + // TODO: We can only process symmetrical scaling for now (i.e. same value for scaleX/scaleY) + if ((itemEntry->scaleSignal & kScaleSignalDoScaling32) && + !(itemEntry->scaleSignal & kScaleSignalDisableGlobalScaling32) && + (itemEntry->scaleX == itemEntry->scaleY)) + applyGlobalScaling(itemEntry, it->planeRect, view->getHeight(itemEntry->loopNo, itemEntry->celNo)); + if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128)) view->getCelRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->celRect); @@ -726,7 +777,12 @@ void GfxFrameout::kernelFrameout() { continue; } - g_sci->_gfxCompare->setNSRect(itemEntry->object, nsRect); + // FIXME: We should not update the object's NS rect here. + // This breaks the sliders in the control panel screen in + // QFG4, but disabling it does not change any functionality, + // as the object(s) will be drawn on screen with the + // calculated coordinates. + //g_sci->_gfxCompare->setNSRect(itemEntry->object, nsRect); } // Don't attempt to draw sprites that are outside the visible diff --git a/engines/sci/graphics/frameout.h b/engines/sci/graphics/frameout.h index 5fd2824224..5ef770486f 100644 --- a/engines/sci/graphics/frameout.h +++ b/engines/sci/graphics/frameout.h @@ -97,11 +97,18 @@ struct ScrollTextEntry { typedef Common::Array<ScrollTextEntry> ScrollTextList; +enum ViewScaleSignals32 { + kScaleSignalDoScaling32 = 0x0001, // enables scaling when drawing that cel (involves scaleX and scaleY) + kScaleSignalUnk1 = 0x0002, // unknown + kScaleSignalDisableGlobalScaling32 = 0x0004 +}; + class GfxCache; class GfxCoordAdjuster32; class GfxPaint32; class GfxPalette; class GfxScreen; + /** * Frameout class, kFrameout and relevant functions for SCI32 games */ @@ -113,6 +120,7 @@ public: void kernelAddPlane(reg_t object); void kernelUpdatePlane(reg_t object); void kernelDeletePlane(reg_t object); + void applyGlobalScaling(FrameoutEntry *itemEntry, Common::Rect planeRect, int16 celHeight); void kernelAddScreenItem(reg_t object); void kernelUpdateScreenItem(reg_t object); void kernelDeleteScreenItem(reg_t object); diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp index 52d44647e2..9b6eff6edc 100644 --- a/engines/sci/graphics/palette.cpp +++ b/engines/sci/graphics/palette.cpp @@ -722,11 +722,6 @@ void GfxPalette::kernelRestore(reg_t memoryHandle) { } void GfxPalette::kernelAssertPalette(GuiResourceId resourceId) { - // Sometimes invalid viewIds are asked for, ignore those (e.g. qfg1vga) - //if (!_resMan->testResource(ResourceId(kResourceTypeView, resourceId))) - // return; - // maybe we took the wrong parameter before, if this causes invalid view again, enable to commented out code again - GfxView *view = g_sci->_gfxCache->getView(resourceId); Palette *viewPalette = view->getPalette(); if (viewPalette) { diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp index f94b74ac45..1afb1b4074 100644 --- a/engines/scumm/he/sound_he.cpp +++ b/engines/scumm/he/sound_he.cpp @@ -804,7 +804,7 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { byte *snd1Ptr, *snd2Ptr; byte *sbng1Ptr, *sbng2Ptr; byte *sdat1Ptr, *sdat2Ptr; - byte *src, *dst, *tmp; + byte *src, *dst; int len, offs, size; int sdat1size, sdat2size; @@ -844,6 +844,7 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { if (sbng1Ptr != NULL && sbng2Ptr != NULL) { if (chan != -1 && ((SoundHE *)_sound)->_heChannel[chan].codeOffs > 0) { + // Copy any code left over to the beginning of the code block int curOffs = ((SoundHE *)_sound)->_heChannel[chan].codeOffs; src = snd1Ptr + curOffs; @@ -851,29 +852,33 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { size = READ_BE_UINT32(sbng1Ptr + 4); len = sbng1Ptr - snd1Ptr + size - curOffs; - byte *data = (byte *)malloc(len); - memcpy(data, src, len); - memcpy(dst, data, len); - free(data); + memmove(dst, src, len); + // Now seek to the end of this code block dst = sbng1Ptr + 8; while ((size = READ_LE_UINT16(dst)) != 0) dst += size; } else { + // We're going to overwrite the code block completely dst = sbng1Ptr + 8; } - ((SoundHE *)_sound)->_heChannel[chan].codeOffs = sbng1Ptr - snd1Ptr + 8; + // Reset the current code offset to the beginning of the code block + if (chan >= 0) + ((SoundHE *)_sound)->_heChannel[chan].codeOffs = sbng1Ptr - snd1Ptr + 8; - tmp = sbng2Ptr + 8; + // Seek to the end of the code block for sound 2 + byte *tmp = sbng2Ptr + 8; while ((offs = READ_LE_UINT16(tmp)) != 0) { tmp += offs; } + // Copy the code block for sound 2 to the code block for sound 1 src = sbng2Ptr + 8; len = tmp - sbng2Ptr - 6; memcpy(dst, src, len); + // Rewrite the time for this new code block to be after the sound 1 code block int32 time; while ((size = READ_LE_UINT16(dst)) != 0) { time = READ_LE_UINT32(dst + 2); @@ -883,6 +888,7 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { } } + // Find the data pointers and sizes if (findSoundTag(MKTAG('d','a','t','a'), snd1Ptr)) { sdat1Ptr = findSoundTag(MKTAG('d','a','t','a'), snd1Ptr); assert(sdat1Ptr); @@ -906,6 +912,8 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { sdat1size = _sndDataSize - _sndPtrOffs; if (sdat2size < sdat1size) { + // We have space leftover at the end of sound 1 + // -> Just append sound 2 src = sdat2Ptr + 8; dst = sdat1Ptr + 8 + _sndPtrOffs; len = sdat2size; @@ -915,6 +923,8 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { _sndPtrOffs += sdat2size; _sndTmrOffs += sdat2size; } else { + // We might not have enough space leftover at the end of sound 1 + // -> Append as much of possible of sound 2 to sound 1 src = sdat2Ptr + 8; dst = sdat1Ptr + 8 + _sndPtrOffs; len = sdat1size; @@ -922,6 +932,8 @@ void ScummEngine_v80he::createSound(int snd1id, int snd2id) { memcpy(dst, src, len); if (sdat2size != sdat1size) { + // We don't have enough space + // -> Start overwriting the beginning of the sound again src = sdat2Ptr + 8 + sdat1size; dst = sdat1Ptr + 8; len = sdat2size - sdat1size; diff --git a/engines/toltecs/movie.cpp b/engines/toltecs/movie.cpp index 45711ad983..8bc00511e9 100644 --- a/engines/toltecs/movie.cpp +++ b/engines/toltecs/movie.cpp @@ -52,7 +52,6 @@ MoviePlayer::~MoviePlayer() { } void MoviePlayer::playMovie(uint resIndex) { - const uint32 subtitleSlot = kMaxScriptSlots - 1; int16 savedSceneWidth = _vm->_sceneWidth; int16 savedSceneHeight = _vm->_sceneHeight; @@ -109,7 +108,7 @@ void MoviePlayer::playMovie(uint resIndex) { debug(0, "chunkType = %d; chunkSize = %d", chunkType, chunkSize); // Skip audio chunks - we've already queued them in - // fetchAudioChunks() above + // fetchAudioChunks() if (chunkType == kChunkAudio) { _vm->_arc->skip(chunkSize); } else { @@ -156,10 +155,11 @@ void MoviePlayer::playMovie(uint resIndex) { // Already processed break; case kChunkShowSubtitle: - if (_vm->_cfgText) { - memcpy(_vm->_script->getSlotData(subtitleSlot), chunkBuffer, chunkSize); - _vm->_screen->updateTalkText(subtitleSlot, 0); - } + memcpy(_vm->_script->getSlotData(subtitleSlot), chunkBuffer, chunkSize); + // The last character of the subtitle determines if it should + // always be displayed or not. If it's 0xFF, it should always be + // displayed, otherwise, if it's 0xFE, it can be toggled. + _vm->_screen->updateTalkText(subtitleSlot, 0, (chunkBuffer[chunkSize - 1] == 0xFF)); break; case kChunkShakeScreen: // start/stop shakescreen effect if (chunkBuffer[0] == 0xFF) @@ -207,7 +207,6 @@ void MoviePlayer::playMovie(uint resIndex) { } void MoviePlayer::fetchAudioChunks() { - uint32 startOfs = _vm->_arc->pos(); uint32 chunkCount = _chunkCount; uint prefetchChunkCount = 0; @@ -218,7 +217,7 @@ void MoviePlayer::fetchAudioChunks() { while (chunkCount-- && prefetchChunkCount < _framesPerSoundChunk / 2) { byte chunkType = _vm->_arc->readByte(); uint32 chunkSize = _vm->_arc->readUint32LE(); - if (chunkType == 4) { + if (chunkType == kChunkAudio) { byte *chunkBuffer = (byte *)malloc(chunkSize); _vm->_arc->read(chunkBuffer, chunkSize); _audioStream->queueBuffer(chunkBuffer, chunkSize, DisposeAfterUse::YES, Audio::FLAG_UNSIGNED); @@ -233,7 +232,6 @@ void MoviePlayer::fetchAudioChunks() { _lastPrefetchOfs = _vm->_arc->pos(); _vm->_arc->seek(startOfs, SEEK_SET); - } void MoviePlayer::unpackPalette(byte *source, byte *dest, int elemCount, int elemSize) { @@ -253,10 +251,12 @@ void MoviePlayer::unpackPalette(byte *source, byte *dest, int elemCount, int ele } void MoviePlayer::unpackRle(byte *source, byte *dest) { - int size = 256000; + int size = 256000; // 640x400 + //int packedSize = 0; while (size > 0) { byte a = *source++; byte b = *source++; + //packedSize += 2; if (a == 0) { dest += b; size -= b; @@ -266,6 +266,7 @@ void MoviePlayer::unpackRle(byte *source, byte *dest) { size -= a; } } + //debug("Packed RLE size: %d", packedSize); } bool MoviePlayer::handleInput() { diff --git a/engines/toltecs/resource.cpp b/engines/toltecs/resource.cpp index 437b4a963a..d66075004b 100644 --- a/engines/toltecs/resource.cpp +++ b/engines/toltecs/resource.cpp @@ -107,11 +107,13 @@ Resource *ResourceCache::load(uint resIndex) { } else { debug(1, "ResourceCache::load(%d) From disk", resIndex); + int32 curPos = _vm->_arc->pos(); Resource *resItem = new Resource(); resItem->size = _vm->_arc->openResource(resIndex); resItem->data = new byte[resItem->size]; _vm->_arc->read(resItem->data, resItem->size); _vm->_arc->closeResource(); + _vm->_arc->seek(curPos); _cache[resIndex] = resItem; diff --git a/engines/toltecs/screen.cpp b/engines/toltecs/screen.cpp index e970d9a6ed..be91130c0a 100644 --- a/engines/toltecs/screen.cpp +++ b/engines/toltecs/screen.cpp @@ -33,7 +33,6 @@ namespace Toltecs { Screen::Screen(ToltecsEngine *vm) : _vm(vm) { - _frontScreen = new byte[268800]; _backScreen = new byte[870400]; @@ -68,16 +67,13 @@ Screen::Screen(ToltecsEngine *vm) : _vm(vm) { _renderQueue = new RenderQueue(_vm); _fullRefresh = false; _guiRefresh = false; - } Screen::~Screen() { - delete[] _frontScreen; delete[] _backScreen; delete _renderQueue; - } void Screen::unpackRle(byte *source, byte *dest, uint16 width, uint16 height) { @@ -120,7 +116,6 @@ void Screen::loadMouseCursor(uint resIndex) { } void Screen::drawGuiImage(int16 x, int16 y, uint resIndex) { - byte *imageData = _vm->_res->load(resIndex)->data; int16 headerSize = READ_LE_UINT16(imageData); int16 width = imageData[2]; @@ -153,7 +148,6 @@ void Screen::drawGuiImage(int16 x, int16 y, uint resIndex) { } _guiRefresh = true; - } void Screen::startShakeScreen(int16 shakeCounter) { @@ -185,7 +179,6 @@ bool Screen::updateShakeScreen() { } void Screen::addStaticSprite(byte *spriteItem) { - DrawRequest drawRequest; memset(&drawRequest, 0, sizeof(drawRequest)); @@ -200,11 +193,9 @@ void Screen::addStaticSprite(byte *spriteItem) { debug(0, "Screen::addStaticSprite() x = %d; y = %d; baseColor = %d; resIndex = %d; flags = %04X", drawRequest.x, drawRequest.y, drawRequest.baseColor, drawRequest.resIndex, drawRequest.flags); addDrawRequest(drawRequest); - } void Screen::addAnimatedSprite(int16 x, int16 y, int16 fragmentId, byte *data, int16 *spriteArray, bool loop, int mode) { - //debug(0, "Screen::addAnimatedSprite(%d, %d, %d)", x, y, fragmentId); DrawRequest drawRequest; @@ -257,9 +248,7 @@ void Screen::addAnimatedSprite(int16 x, int16 y, int16 fragmentId, byte *data, i WRITE_LE_UINT16(spriteItem + 0, loopNum); WRITE_LE_UINT16(spriteItem + 4, frameNum); - } - } void Screen::clearSprites() { @@ -267,7 +256,6 @@ void Screen::clearSprites() { } void Screen::blastSprite(int16 x, int16 y, int16 fragmentId, int16 resIndex, uint16 flags) { - DrawRequest drawRequest; SpriteDrawItem sprite; @@ -283,7 +271,6 @@ void Screen::blastSprite(int16 x, int16 y, int16 fragmentId, int16 resIndex, uin sprite.y -= _vm->_cameraY; drawSprite(sprite); } - } void Screen::updateVerbLine(int16 slotIndex, int16 slotOffset) { @@ -356,11 +343,9 @@ void Screen::updateVerbLine(int16 slotIndex, int16 slotOffset) { drawGuiText(_verbLineX - 1 - (wrapState.width / 2), y - 1, 0xF9, 0xFF, _fontResIndexArray[0], wrapState); _guiRefresh = true; - } -void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { - +void Screen::updateTalkText(int16 slotIndex, int16 slotOffset, bool alwaysDisplayed) { int16 x, y, maxWidth, width, length; byte durationModifier = 1; byte *textData = _vm->_script->getSlotData(slotIndex) + slotOffset; @@ -369,6 +354,7 @@ void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { item->fontNum = 0; item->color = _talkTextFontColor; + item->alwaysDisplayed = alwaysDisplayed; x = CLIP<int16>(_talkTextX - _vm->_cameraX, 120, _talkTextMaxWidth); y = CLIP<int16>(_talkTextY - _vm->_cameraY, 4, _vm->_cameraHeight - 16); @@ -454,11 +440,9 @@ void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { textDurationMultiplier += 100; } item->duration = 4 * textDurationMultiplier * durationModifier; - } void Screen::addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 width, TalkTextItem *item) { - if (width > 0) { TextRect *textRect = &item->lines[item->lineCount]; width = width + 1 - font.getSpacing(); @@ -471,7 +455,6 @@ void Screen::addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 } y += font.getHeight() - 1; - } void Screen::addTalkTextItemsToRenderQueue() { @@ -487,7 +470,7 @@ void Screen::addTalkTextItemsToRenderQueue() { if (item->duration < 0) item->duration = 0; - if (!_vm->_cfgText) + if (!_vm->_cfgText && !item->alwaysDisplayed) return; for (byte j = 0; j < item->lineCount; j++) { @@ -498,6 +481,15 @@ void Screen::addTalkTextItemsToRenderQueue() { } } +bool Screen::isTalkTextActive(int16 slotIndex) { + for (int16 i = 0; i <= _talkTextItemNum; i++) { + if (_talkTextItems[i].slotIndex == slotIndex && _talkTextItems[i].duration > 0) + return true; + } + + return false; +} + int16 Screen::getTalkTextDuration() { return _talkTextItems[_talkTextItemNum].duration; } @@ -523,7 +515,6 @@ void Screen::registerFont(uint fontIndex, uint resIndex) { } void Screen::drawGuiTextMulti(byte *textData) { - int16 x = 0, y = 0; // Really strange stuff. @@ -558,7 +549,6 @@ void Screen::drawGuiTextMulti(byte *textData) { } while (*wrapState.sourceString != 0xFF); _guiRefresh = true; - } int16 Screen::wrapGuiText(uint fontResIndex, int maxWidth, GuiTextWrapState &wrapState) { @@ -581,7 +571,6 @@ int16 Screen::wrapGuiText(uint fontResIndex, int maxWidth, GuiTextWrapState &wra } return len; - } void Screen::drawGuiText(int16 x, int16 y, byte fontColor1, byte fontColor2, uint fontResIndex, GuiTextWrapState &wrapState) { @@ -595,7 +584,6 @@ void Screen::drawGuiText(int16 x, int16 y, byte fontColor1, byte fontColor2, uin } int16 Screen::drawString(int16 x, int16 y, byte color, uint fontResIndex, const byte *text, int len, int16 *ywobble, bool outline) { - //debug(0, "Screen::drawString(%d, %d, %d, %d)", x, y, color, fontResIndex); Font font(_vm->_res->load(fontResIndex)->data); @@ -622,11 +610,9 @@ int16 Screen::drawString(int16 x, int16 y, byte color, uint fontResIndex, const *ywobble = yadd; return x; - } void Screen::drawChar(const Font &font, byte *dest, int16 x, int16 y, byte ch, byte color, bool outline) { - int16 charWidth, charHeight; byte *charData; @@ -655,11 +641,9 @@ void Screen::drawChar(const Font &font, byte *dest, int16 x, int16 y, byte ch, b } dest += 640 - charWidth; } - } void Screen::drawSurface(int16 x, int16 y, Graphics::Surface *surface) { - int16 skipX = 0; int16 width = surface->w; int16 height = surface->h; @@ -704,11 +688,9 @@ void Screen::drawSurface(int16 x, int16 y, Graphics::Surface *surface) { frontScreen += 640 - width; surfacePixels += surface->w - width - skipX; } - } void Screen::saveState(Common::WriteStream *out) { - // Save verb line out->writeUint16LE(_verbLineNum); out->writeUint16LE(_verbLineX); @@ -755,11 +737,9 @@ void Screen::saveState(Common::WriteStream *out) { out->writeUint32LE(_fontResIndexArray[i]); out->writeByte(_fontColor1); out->writeByte(_fontColor2); - } void Screen::loadState(Common::ReadStream *in) { - // Load verb line _verbLineNum = in->readUint16LE(); _verbLineX = in->readUint16LE(); @@ -784,6 +764,7 @@ void Screen::loadState(Common::ReadStream *in) { _talkTextItems[i].fontNum = in->readUint16LE(); _talkTextItems[i].color = in->readByte(); _talkTextItems[i].lineCount = in->readByte(); + _talkTextItems[i].alwaysDisplayed = false; for (int j = 0; j < _talkTextItems[i].lineCount; j++) { _talkTextItems[i].lines[j].x = in->readUint16LE(); _talkTextItems[i].lines[j].y = in->readUint16LE(); @@ -807,7 +788,6 @@ void Screen::loadState(Common::ReadStream *in) { _fontResIndexArray[i] = in->readUint32LE(); _fontColor1 = in->readByte(); _fontColor2 = in->readByte(); - } } // End of namespace Toltecs diff --git a/engines/toltecs/screen.h b/engines/toltecs/screen.h index 788cde50c6..ee565e1882 100644 --- a/engines/toltecs/screen.h +++ b/engines/toltecs/screen.h @@ -136,6 +136,7 @@ struct TalkTextItem { byte color; byte lineCount; TextRect lines[15]; + bool alwaysDisplayed; }; struct GuiTextWrapState { @@ -177,10 +178,11 @@ public: void updateVerbLine(int16 slotIndex, int16 slotOffset); // Talk text - void updateTalkText(int16 slotIndex, int16 slotOffset); + void updateTalkText(int16 slotIndex, int16 slotOffset, bool alwaysDisplayed); void addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 width, TalkTextItem *item); void addTalkTextItemsToRenderQueue(); int16 getTalkTextDuration(); + bool isTalkTextActive(int16 slotIndex); void finishTalkTextItems(); void keepTalkTextItemsAlive(); diff --git a/engines/toltecs/sound.cpp b/engines/toltecs/sound.cpp index 4b281392e5..8afc0e7890 100644 --- a/engines/toltecs/sound.cpp +++ b/engines/toltecs/sound.cpp @@ -103,8 +103,7 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa } } } else { - - if (type == -3) { + if (type == kChannelTypeSpeech) { // Stop speech and play new sound stopSpeech(); } @@ -137,10 +136,8 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa _vm->_mixer->playStream(soundType, &channels[freeChannel].handle, stream, -1, volume, panning); - } - - } - + } // if (freeChannel >= 0) + } // resIndex } void Sound::updateSpeech() { diff --git a/engines/toltecs/toltecs.cpp b/engines/toltecs/toltecs.cpp index f6a2dfed9d..1a399dacc0 100644 --- a/engines/toltecs/toltecs.cpp +++ b/engines/toltecs/toltecs.cpp @@ -495,6 +495,11 @@ void ToltecsEngine::updateCamera() { void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) { byte *scanData = _script->getSlotData(slotIndex) + slotOffset; + // If there's another talk text at the requested slot and it's still + // active, don't overwrite it. Fixes bug #3600166. + if (_screen->isTalkTextActive(slotIndex)) + return; + while (*scanData < 0xF0) { if (*scanData == 0x19) { scanData++; @@ -514,13 +519,14 @@ void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) { debug(0, "ToltecsEngine::talk() playSound(resIndex: %d)", resIndex); _sound->playSpeech(resIndex); } + if (_doText) { - _screen->updateTalkText(slotIndex, slotOffset); + _screen->updateTalkText(slotIndex, slotOffset, false); } else { _screen->keepTalkTextItemsAlive(); } } else { - _screen->updateTalkText(slotIndex, slotOffset); + _screen->updateTalkText(slotIndex, slotOffset, true); } } diff --git a/engines/toon/toon.h b/engines/toon/toon.h index d40c489011..0ff351804f 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -316,12 +316,11 @@ public: } Common::Error saveGameState(int slot, const Common::String &desc) { - - return (saveGame(slot, desc) ? Common::kWritingFailed : Common::kNoError); + return (saveGame(slot, desc) ? Common::kNoError : Common::kWritingFailed); } Common::Error loadGameState(int slot) { - return (loadGame(slot) ? Common::kReadingFailed : Common::kNoError); + return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed); } bool hasFeature(EngineFeature f) const { diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index a985c517e2..526e0802cb 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -932,24 +932,34 @@ bool AdScene::traverseNodes(bool doUpdate) { if (_autoScroll) { // adjust horizontal scroll if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { + int timesMissed = (_gameRef->_timer - _lastTimeH) / _scrollTimeH; + // Cap the amount of catch-up to avoid jittery characters. + if (timesMissed > 2) { + timesMissed = 2; + } _lastTimeH = _gameRef->_timer; if (_offsetLeft < _targetOffsetLeft) { - _offsetLeft += _scrollPixelsH; + _offsetLeft += _scrollPixelsH * timesMissed; _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); } else if (_offsetLeft > _targetOffsetLeft) { - _offsetLeft -= _scrollPixelsH; + _offsetLeft -= _scrollPixelsH * timesMissed; _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); } } // adjust vertical scroll if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { + int timesMissed = (_gameRef->_timer - _lastTimeV) / _scrollTimeV; + // Cap the amount of catch-up to avoid jittery characters. + if (timesMissed > 2) { + timesMissed = 2; + } _lastTimeV = _gameRef->_timer; if (_offsetTop < _targetOffsetTop) { - _offsetTop += _scrollPixelsV; + _offsetTop += _scrollPixelsV * timesMissed; _offsetTop = MIN(_offsetTop, _targetOffsetTop); } else if (_offsetTop > _targetOffsetTop) { - _offsetTop -= _scrollPixelsV; + _offsetTop -= _scrollPixelsV * timesMissed; _offsetTop = MAX(_offsetTop, _targetOffsetTop); } } diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index cca4fdc2cb..937a4b333d 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -355,7 +355,7 @@ bool AdTalkHolder::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Item ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Item")==0){ + if (strcmp(name, "Item")==0) { SetItem(value->getString()); return STATUS_OK; } diff --git a/engines/wintermute/base/base_engine.h b/engines/wintermute/base/base_engine.h index 1ed0e3ab01..f04c594699 100644 --- a/engines/wintermute/base/base_engine.h +++ b/engines/wintermute/base/base_engine.h @@ -57,7 +57,7 @@ public: Common::RandomSource *getRandomSource() { return _rnd; } uint32 randInt(int from, int to); - SystemClassRegistry *getClassRegistry(){ return _classReg; } + SystemClassRegistry *getClassRegistry() { return _classReg; } BaseGame *getGameRef() { return _gameRef; } BaseFileManager *getFileManager() { return _fileManager; } static void LOG(bool res, const char *fmt, ...); diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp index 7402bc6f30..46acd8cd98 100644 --- a/engines/wintermute/base/base_game.cpp +++ b/engines/wintermute/base/base_game.cpp @@ -1258,7 +1258,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(2); const char *key = stack->pop()->getString(); const char *val = stack->pop()->getString(); - Common::String privKey = "priv_" + StringUtil::encodeSetting(key); + Common::String privKey = "wme_" + StringUtil::encodeSetting(key); Common::String privVal = StringUtil::encodeSetting(val); ConfMan.set(privKey, privVal); stack->pushNULL(); @@ -1272,7 +1272,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(2); const char *key = stack->pop()->getString(); const char *initVal = stack->pop()->getString(); - Common::String privKey = "priv_" + StringUtil::encodeSetting(key); + Common::String privKey = "wme_" + StringUtil::encodeSetting(key); Common::String result = initVal; if (ConfMan.hasKey(privKey)) { result = StringUtil::decodeSetting(ConfMan.get(key)); diff --git a/engines/wintermute/base/base_persistence_manager.cpp b/engines/wintermute/base/base_persistence_manager.cpp index bd53ed38e4..accb0a8fd3 100644 --- a/engines/wintermute/base/base_persistence_manager.cpp +++ b/engines/wintermute/base/base_persistence_manager.cpp @@ -71,6 +71,9 @@ BasePersistenceManager::BasePersistenceManager(const char *savePrefix, bool dele _richBuffer = NULL; _richBufferSize = 0; + _scummVMThumbnailData = NULL; + _scummVMThumbSize = 0; + _savedDescription = NULL; // _savedTimestamp = 0; _savedVerMajor = _savedVerMinor = _savedVerBuild = 0; @@ -123,6 +126,12 @@ void BasePersistenceManager::cleanup() { _thumbnailData = NULL; } + _scummVMThumbSize = 0; + if (_scummVMThumbnailData) { + delete[] _scummVMThumbnailData; + _scummVMThumbnailData = NULL; + } + delete _loadStream; delete _saveStream; _loadStream = NULL; @@ -131,7 +140,7 @@ void BasePersistenceManager::cleanup() { Common::String BasePersistenceManager::getFilenameForSlot(int slot) const { // 3 Digits, to allow for one save-slot for autosave + slot 1 - 100 (which will be numbered 0-99 filename-wise) - return Common::String::format("%s-save%03d.wsv", _savePrefix.c_str(), slot); + return Common::String::format("%s.%03d", _savePrefix.c_str(), slot); } void BasePersistenceManager::getSaveStateDesc(int slot, SaveStateDescriptor &desc) { @@ -146,17 +155,28 @@ void BasePersistenceManager::getSaveStateDesc(int slot, SaveStateDescriptor &des desc.setDeletableFlag(true); desc.setWriteProtectedFlag(false); - if (_thumbnailDataSize > 0) { - Common::MemoryReadStream thumbStream(_thumbnailData, _thumbnailDataSize); + int thumbSize = 0; + byte *thumbData = NULL; + if (_scummVMThumbSize > 0) { + thumbSize = _scummVMThumbSize; + thumbData = _scummVMThumbnailData; + } else if (_thumbnailDataSize > 0) { + thumbSize = _thumbnailDataSize; + thumbData = _thumbnailData; + } + + if (thumbSize > 0) { + Common::MemoryReadStream thumbStream(thumbData, thumbSize, DisposeAfterUse::NO); Graphics::BitmapDecoder bmpDecoder; if (bmpDecoder.loadStream(thumbStream)) { - Graphics::Surface *surf = NULL; - surf = bmpDecoder.getSurface()->convertTo(g_system->getOverlayFormat()); - TransparentSurface *scaleableSurface = new TransparentSurface(*surf, false); + const Graphics::Surface *bmpSurface = bmpDecoder.getSurface(); + TransparentSurface *scaleableSurface = new TransparentSurface(*bmpSurface, false); Graphics::Surface *scaled = scaleableSurface->scale(kThumbnailWidth, kThumbnailHeight2); - desc.setThumbnail(scaled); + Graphics::Surface *thumb = scaled->convertTo(g_system->getOverlayFormat()); + desc.setThumbnail(thumb); delete scaleableSurface; - delete surf; + scaled->free(); + delete scaled; } } @@ -171,13 +191,13 @@ void BasePersistenceManager::deleteSaveSlot(int slot) { } uint32 BasePersistenceManager::getMaxUsedSlot() { - Common::String saveMask = Common::String::format("%s-save???.wsv", _savePrefix.c_str()); + Common::String saveMask = Common::String::format("%s.???", _savePrefix.c_str()); Common::StringArray saves = g_system->getSavefileManager()->listSavefiles(saveMask); Common::StringArray::iterator it = saves.begin(); int ret = -1; for (; it != saves.end(); ++it) { int num = -1; - sscanf(it->c_str(), "save%d", &num); + sscanf(it->c_str(), ".%d", &num); ret = MAX(ret, num); } return ret; @@ -249,6 +269,25 @@ bool BasePersistenceManager::initSave(const char *desc) { if (!thumbnailOK) { putDWORD(0); } + thumbnailOK = false; + // Again for the ScummVM-thumb: + if (_gameRef->_cachedThumbnail) { + if (_gameRef->_cachedThumbnail->_scummVMThumb) { + Common::MemoryWriteStreamDynamic scummVMthumbStream(DisposeAfterUse::YES); + if (_gameRef->_cachedThumbnail->_scummVMThumb->writeBMPToStream(&scummVMthumbStream)) { + _saveStream->writeUint32LE(scummVMthumbStream.size()); + _saveStream->write(scummVMthumbStream.getData(), scummVMthumbStream.size()); + } else { + _saveStream->writeUint32LE(0); + } + + thumbnailOK = true; + } + } + if (!thumbnailOK) { + putDWORD(0); + } + // in any case, destroy the cached thumbnail once used delete _gameRef->_cachedThumbnail; @@ -308,6 +347,15 @@ bool BasePersistenceManager::readHeader(const Common::String &filename) { _thumbnailDataSize = 0; } } + if (_savedVerMajor >= 1 && _savedVerMinor >= 2) { + _scummVMThumbSize = getDWORD(); + _scummVMThumbnailData = new byte[_scummVMThumbSize]; + if (_scummVMThumbnailData) { + getBytes(_scummVMThumbnailData, _scummVMThumbSize); + } else { + _scummVMThumbSize = 0; + } + } } else { _savedVerBuild = 35; // last build with ver1 savegames } diff --git a/engines/wintermute/base/base_persistence_manager.h b/engines/wintermute/base/base_persistence_manager.h index a262c92a0b..114f6e066f 100644 --- a/engines/wintermute/base/base_persistence_manager.h +++ b/engines/wintermute/base/base_persistence_manager.h @@ -93,6 +93,8 @@ public: uint32 _thumbnailDataSize; byte *_thumbnailData; + uint32 _scummVMThumbSize; + byte *_scummVMThumbnailData; Common::String getFilenameForSlot(int slot) const; private: bool _deleteSingleton; diff --git a/engines/wintermute/base/base_save_thumb_helper.cpp b/engines/wintermute/base/base_save_thumb_helper.cpp index b4205c21c4..3899ece59b 100644 --- a/engines/wintermute/base/base_save_thumb_helper.cpp +++ b/engines/wintermute/base/base_save_thumb_helper.cpp @@ -30,51 +30,80 @@ #include "engines/wintermute/base/gfx/base_image.h" #include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/base_game.h" +#include "graphics/scaler.h" namespace Wintermute { ////////////////////////////////////////////////////////////////////////// BaseSaveThumbHelper::BaseSaveThumbHelper(BaseGame *inGame) : BaseClass(inGame) { _thumbnail = NULL; + _scummVMThumb = NULL; } ////////////////////////////////////////////////////////////////////////// BaseSaveThumbHelper::~BaseSaveThumbHelper(void) { delete _thumbnail; _thumbnail = NULL; + delete _scummVMThumb; + _scummVMThumb = NULL; } -////////////////////////////////////////////////////////////////////////// -bool BaseSaveThumbHelper::storeThumbnail(bool doFlip) { - delete _thumbnail; - _thumbnail = NULL; - +BaseImage *BaseSaveThumbHelper::storeThumb(bool doFlip, int width, int height) { + BaseImage *thumbnail = NULL; if (_gameRef->_thumbnailWidth > 0 && _gameRef->_thumbnailHeight > 0) { if (doFlip) { // when using opengl on windows it seems to be necessary to do this twice // works normally for direct3d _gameRef->displayContent(false); _gameRef->_renderer->flip(); - + _gameRef->displayContent(false); _gameRef->_renderer->flip(); } - + BaseImage *screenshot = _gameRef->_renderer->takeScreenshot(); if (!screenshot) { - return STATUS_FAILED; + return NULL; } - + // normal thumbnail if (_gameRef->_thumbnailWidth > 0 && _gameRef->_thumbnailHeight > 0) { - _thumbnail = new BaseImage(); - _thumbnail->copyFrom(screenshot, _gameRef->_thumbnailWidth, _gameRef->_thumbnailHeight); + thumbnail = new BaseImage(); + thumbnail->copyFrom(screenshot, width, height); } - - + + delete screenshot; screenshot = NULL; } + return thumbnail; +} + +////////////////////////////////////////////////////////////////////////// +bool BaseSaveThumbHelper::storeThumbnail(bool doFlip) { + delete _thumbnail; + _thumbnail = NULL; + + if (_gameRef->_thumbnailWidth > 0 && _gameRef->_thumbnailHeight > 0) { + + _thumbnail = storeThumb(doFlip, _gameRef->_thumbnailWidth, _gameRef->_thumbnailHeight); + if (!_thumbnail) { + return STATUS_FAILED; + } + } + storeScummVMThumbNail(); + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool BaseSaveThumbHelper::storeScummVMThumbNail(bool doFlip) { + delete _scummVMThumb; + _scummVMThumb = NULL; + + _scummVMThumb = storeThumb(doFlip, kThumbnailWidth, kThumbnailHeight2); + if (!_scummVMThumb) { + return STATUS_FAILED; + } return STATUS_OK; } diff --git a/engines/wintermute/base/base_save_thumb_helper.h b/engines/wintermute/base/base_save_thumb_helper.h index 8863508ac9..8e8a7183c2 100644 --- a/engines/wintermute/base/base_save_thumb_helper.h +++ b/engines/wintermute/base/base_save_thumb_helper.h @@ -40,9 +40,12 @@ public: BaseSaveThumbHelper(BaseGame *inGame); virtual ~BaseSaveThumbHelper(void); bool storeThumbnail(bool doFlip = false); + bool storeScummVMThumbNail(bool doFlip = false); BaseImage *_thumbnail; + BaseImage *_scummVMThumb; private: + BaseImage *storeThumb(bool doFlip, int width, int height); BaseImage *_richThumbnail; }; diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp index 47506089b4..83f0a35f53 100644 --- a/engines/wintermute/base/font/base_font_truetype.cpp +++ b/engines/wintermute/base/font/base_font_truetype.cpp @@ -38,6 +38,7 @@ #include "engines/wintermute/wintermute.h" #include "graphics/fonts/ttf.h" #include "graphics/fontman.h" +#include "common/unzip.h" #include <limits.h> namespace Wintermute { @@ -162,7 +163,7 @@ void BaseFontTT::drawText(const byte *text, int x, int y, int width, TTextAlign // HACK: J.U.L.I.A. uses CP1252, we need to fix that, // And we still don't have any UTF8-support. if (_gameRef->_textEncoding != TEXT_UTF8) { - textStr = StringUtil::ansiToWide((char *)text); + textStr = StringUtil::ansiToWide((const char *)text); } if (maxLength >= 0 && textStr.size() > (uint32)maxLength) { @@ -546,26 +547,52 @@ bool BaseFontTT::initFont() { if (!_fontFile) { return STATUS_FAILED; } - +#ifdef USE_FREETYPE2 Common::SeekableReadStream *file = BaseFileManager::getEngineInstance()->openFile(_fontFile); if (!file) { - //TODO: Try to fallback from Arial to FreeSans - /* - // the requested font file is not in wme file space; try loading a system font - AnsiString fontFileName = PathUtil::combine(BasePlatform::getSystemFontPath(), PathUtil::getFileName(_fontFile)); - file = BaseFileManager::getEngineInstance()->openFile(fontFileName.c_str(), false); - if (!file) { - _gameRef->LOG(0, "Error loading TrueType font '%s'", _fontFile); - //return STATUS_FAILED; - }*/ + if (Common::String(_fontFile) != "arial.ttf") { + warning("%s has no replacement font yet, using FreeSans for now (if available)", _fontFile); + } + // Fallback1: Try to find FreeSans.ttf + file = SearchMan.createReadStreamForMember("FreeSans.ttf"); } if (file) { -#ifdef USE_FREETYPE2 _deletableFont = Graphics::loadTTFFont(*file, 96, _fontHeight); // Use the same dpi as WME (96 vs 72). _font = _deletableFont; -#endif + BaseFileManager::getEngineInstance()->closeFile(file); + file = NULL; + } + + // Fallback2: Try to find ScummModern.zip, and get the font from there: + if (!_font) { + Common::SeekableReadStream *themeFile = SearchMan.createReadStreamForMember("scummmodern.zip"); + if (themeFile) { + Common::Archive *themeArchive = Common::makeZipArchive(themeFile); + if (themeArchive->hasFile("FreeSans.ttf")) { + file = NULL; + file = themeArchive->createReadStreamForMember("FreeSans.ttf"); + _deletableFont = Graphics::loadTTFFont(*file, 96, _fontHeight); // Use the same dpi as WME (96 vs 72). + _font = _deletableFont; + } + // We're not using BaseFileManager, so clean up after ourselves: + delete file; + file = NULL; + delete themeArchive; + themeArchive = NULL; + } } + + // Fallback3: Try to ask FontMan for the FreeSans.ttf ScummModern.zip uses: + if (!_font) { + // Really not desireable, as we will get a font with dpi-72 then + Common::String fontName = Common::String::format("%s-%s@%d", "FreeSans.ttf", "ASCII", _fontHeight); + warning("Looking for %s", fontName.c_str()); + _font = FontMan.getFontByName(fontName); + } +#endif // USE_FREETYPE2 + + // Fallback4: Just use the Big GUI-font. (REALLY undesireable) if (!_font) { _font = _fallbackFont = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); warning("BaseFontTT::InitFont - Couldn't load font: %s", _fontFile); diff --git a/engines/wintermute/base/gfx/base_renderer.h b/engines/wintermute/base/gfx/base_renderer.h index 9027c66a14..796dee8cd1 100644 --- a/engines/wintermute/base/gfx/base_renderer.h +++ b/engines/wintermute/base/gfx/base_renderer.h @@ -84,8 +84,9 @@ public: * @param rect the portion of the screen to fade (if NULL, the entire screen will be faded). */ virtual void fadeToColor(byte r, byte g, byte b, byte a, Common::Rect *rect = NULL) = 0; - virtual bool drawLine(int x1, int y1, int x2, int y2, uint32 color); - virtual bool drawRect(int x1, int y1, int x2, int y2, uint32 color, int width = 1); + + virtual bool drawLine(int x1, int y1, int x2, int y2, uint32 color); // Unused outside indicator-display + virtual bool drawRect(int x1, int y1, int x2, int y2, uint32 color, int width = 1); // Unused outside indicator-display BaseRenderer(BaseGame *inGame = NULL); virtual ~BaseRenderer(); virtual bool setProjection() { diff --git a/engines/wintermute/base/gfx/base_surface.h b/engines/wintermute/base/gfx/base_surface.h index ee53c03e77..012be95aac 100644 --- a/engines/wintermute/base/gfx/base_surface.h +++ b/engines/wintermute/base/gfx/base_surface.h @@ -55,6 +55,7 @@ public: virtual bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTransform(int x, int y, int hotX, int hotY, Rect32 rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; + virtual bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) = 0; virtual bool restore(); virtual bool create(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime = -1, bool keepLoaded = false) = 0; virtual bool create(int width, int height); @@ -79,7 +80,7 @@ public: } Common::String getFileNameStr() { return _filename; } const char* getFileName() { return _filename.c_str(); } - //void SetWidth(int Width){ _width = Width; } + //void SetWidth(int Width) { _width = Width; } //void SetHeight(int Height){ _height = Height; } protected: bool _ckDefault; diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 097ea7fa42..a5b251cea6 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -53,6 +53,8 @@ BaseRenderOSystem::BaseRenderOSystem(BaseGame *inGame) : BaseRenderer(inGame) { _needsFlip = true; _spriteBatch = false; _batchNum = 0; + _skipThisFrame = false; + _previousTicket = NULL; _borderLeft = _borderRight = _borderTop = _borderBottom = 0; _ratioX = _ratioY = 1.0f; @@ -67,6 +69,15 @@ BaseRenderOSystem::BaseRenderOSystem(BaseGame *inGame) : BaseRenderer(inGame) { ////////////////////////////////////////////////////////////////////////// BaseRenderOSystem::~BaseRenderOSystem() { + RenderQueueIterator it = _renderQueue.begin(); + while (it != _renderQueue.end()) { + RenderTicket *ticket = *it; + it = _renderQueue.erase(it); + delete ticket; + } + + delete _dirtyRect; + _renderSurface->free(); delete _renderSurface; _blankSurface->free(); @@ -155,6 +166,14 @@ bool BaseRenderOSystem::indicatorFlip() { } bool BaseRenderOSystem::flip() { + if (_skipThisFrame) { + _skipThisFrame = false; + delete _dirtyRect; + _dirtyRect = NULL; + g_system->updateScreen(); + _needsFlip = false; + return true; + } if (!_disableDirtyRects) { drawTickets(); } else { @@ -256,21 +275,23 @@ Graphics::PixelFormat BaseRenderOSystem::getPixelFormat() const { } void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha) { - // Skip rects that are completely outside the screen: - if ((dstRect->left < 0 && dstRect->right < 0) || (dstRect->top < 0 && dstRect->bottom < 0)) { - return; - } // Start searching from the beginning for the first and second items (since it's empty the first time around // then keep incrementing the start-position, to avoid comparing against already used tickets. if (_drawNum == 0 || _drawNum == 1) { _lastAddedTicket = _renderQueue.begin(); } + // Skip rects that are completely outside the screen: + if ((dstRect->left < 0 && dstRect->right < 0) || (dstRect->top < 0 && dstRect->bottom < 0)) { + return; + } + if (owner) { // Fade-tickets are owner-less RenderTicket compare(owner, NULL, srcRect, dstRect, mirrorX, mirrorY, disableAlpha); compare._batchNum = _batchNum; - if (_spriteBatch) + if (_spriteBatch) { _batchNum++; + } compare._colorMod = _colorMod; RenderQueueIterator it; // Avoid calling end() and operator* every time, when potentially going through @@ -285,7 +306,7 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S drawFromSurface(compareTicket); } else { drawFromTicket(compareTicket); - _lastAddedTicket++; + _previousTicket = compareTicket; } return; } @@ -295,14 +316,53 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S ticket->_colorMod = _colorMod; if (!_disableDirtyRects) { drawFromTicket(ticket); - drawFromSurface(ticket); - _lastAddedTicket++; + _previousTicket = ticket; } else { ticket->_wantsDraw = true; _renderQueue.push_back(ticket); } } +void BaseRenderOSystem::repeatLastDraw(int offsetX, int offsetY, int numTimesX, int numTimesY) { + if (_previousTicket && _lastAddedTicket != _renderQueue.end()) { + RenderTicket *origTicket = _previousTicket; + + // Make sure drawSurface WILL start from the correct _lastAddedTicket + if (*_lastAddedTicket != origTicket) { + RenderQueueIterator it; + RenderQueueIterator endIterator = _renderQueue.end(); + for (it = _renderQueue.begin(); it != endIterator; ++it) { + if ((*it) == _previousTicket) { + _lastAddedTicket = it; + break; + } + } + } + Common::Rect srcRect(0, 0, 0, 0); + srcRect.setWidth(origTicket->getSrcRect()->width()); + srcRect.setHeight(origTicket->getSrcRect()->height()); + + Common::Rect dstRect = origTicket->_dstRect; + int initLeft = dstRect.left; + int initRight = dstRect.right; + + for (int i = 0; i < numTimesY; i++) { + if (i == 0) { + dstRect.translate(offsetX, 0); + } + for (int j = (i == 0 ? 1 : 0); j < numTimesX; j++) { + drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, false, false); + dstRect.translate(offsetX, 0); + } + dstRect.left = initLeft; + dstRect.right = initRight; + dstRect.translate(0, offsetY); + } + } else { + error("Repeat-draw failed (did you forget to draw something before this?)"); + } +} + void BaseRenderOSystem::invalidateTicket(RenderTicket *renderTicket) { addDirtyRect(renderTicket->_dstRect); renderTicket->_isValid = false; @@ -327,28 +387,31 @@ void BaseRenderOSystem::drawFromTicket(RenderTicket *renderTicket) { renderTicket->_drawNum = _drawNum++; _renderQueue.push_back(renderTicket); addDirtyRect(renderTicket->_dstRect); + ++_lastAddedTicket; } else { // Before something - Common::List<RenderTicket *>::iterator pos; + RenderQueueIterator pos; for (pos = _renderQueue.begin(); pos != _renderQueue.end(); pos++) { if ((*pos)->_drawNum >= _drawNum) { break; } } _renderQueue.insert(pos, renderTicket); - Common::List<RenderTicket *>::iterator it; renderTicket->_drawNum = _drawNum++; // Increment the following tickets, so they still are in line + RenderQueueIterator it; for (it = pos; it != _renderQueue.end(); ++it) { (*it)->_drawNum++; (*it)->_wantsDraw = false; } addDirtyRect(renderTicket->_dstRect); + _lastAddedTicket = pos; } } else { // Was drawn last round, still in the same order if (_drawNum == renderTicket->_drawNum) { _drawNum++; + ++_lastAddedTicket; } else { // Remove the ticket from the list RenderQueueIterator it = _renderQueue.begin(); @@ -473,10 +536,10 @@ void BaseRenderOSystem::drawFromSurface(RenderTicket *ticket, Common::Rect *dstR ////////////////////////////////////////////////////////////////////////// bool BaseRenderOSystem::drawLine(int x1, int y1, int x2, int y2, uint32 color) { - static bool hasWarned = false; // TODO: Fix this, this only avoids spamming warnings for now. - if (!_disableDirtyRects && !hasWarned) { - warning("BaseRenderOSystem::DrawLine - doesn't work for dirty rects yet"); - hasWarned = true; + // This function isn't used outside of indicator-displaying, and thus quite unused in + // BaseRenderOSystem when dirty-rects are enabled. + if (!_disableDirtyRects && !_indicatorDisplay) { + error("BaseRenderOSystem::DrawLine - doesn't work for dirty rects yet"); } byte r = RGBCOLGetR(color); @@ -583,6 +646,9 @@ void BaseRenderOSystem::endSaveLoad() { it = _renderQueue.erase(it); delete ticket; } + // HACK: After a save the buffer will be drawn before the scripts get to update it, + // so just skip this single frame. + _skipThisFrame = true; _drawNum = 1; } diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.h b/engines/wintermute/base/gfx/osystem/base_render_osystem.h index e79a0cee46..2c89037183 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.h @@ -81,6 +81,7 @@ public: virtual bool endSpriteBatch(); void endSaveLoad(); void drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha = false); + void repeatLastDraw(int offsetX, int offsetY, int numTimesX, int numTimesY); BaseSurface *createSurface(); private: void addDirtyRect(const Common::Rect &rect); @@ -93,6 +94,7 @@ private: Common::Rect *_dirtyRect; Common::List<RenderTicket *> _renderQueue; RenderQueueIterator _lastAddedTicket; + RenderTicket *_previousTicket; bool _needsFlip; uint32 _drawNum; @@ -112,6 +114,8 @@ private: float _ratioY; uint32 _colorMod; uint32 _clearColor; + + bool _skipThisFrame; }; } // end of namespace Wintermute diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index bee876bb65..e2bc3967e2 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -414,6 +414,12 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo return STATUS_OK; } +bool BaseSurfaceOSystem::repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) { + BaseRenderOSystem *renderer = static_cast<BaseRenderOSystem *>(_gameRef->_renderer); + renderer->repeatLastDraw(offsetX, offsetY, numTimesX, numTimesY); + return STATUS_OK; +} + bool BaseSurfaceOSystem::putSurface(const Graphics::Surface &surface, bool hasAlpha) { _loaded = true; _surface->free(); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index 43422ef4e7..5bbfa27179 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -57,6 +57,7 @@ public: bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false); bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false); bool displayTransform(int x, int y, int hotX, int hotY, Rect32 Rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false); + bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY); virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false); /* static unsigned DLL_CALLCONV ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle); static int DLL_CALLCONV SeekProc(fi_handle handle, long offset, int origin); diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.h b/engines/wintermute/base/gfx/osystem/render_ticket.h index 19637a23d0..968b42b5e1 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.h +++ b/engines/wintermute/base/gfx/osystem/render_ticket.h @@ -56,6 +56,7 @@ public: BaseSurfaceOSystem *_owner; bool operator==(RenderTicket &a); + const Common::Rect *getSrcRect() { return &_srcRect; } private: Graphics::Surface *_surface; Common::Rect _srcRect; diff --git a/engines/wintermute/base/scriptables/script.cpp b/engines/wintermute/base/scriptables/script.cpp index 54d0a9cdc7..9bb7fedf38 100644 --- a/engines/wintermute/base/scriptables/script.cpp +++ b/engines/wintermute/base/scriptables/script.cpp @@ -622,11 +622,11 @@ bool ScScript::executeInstruction() { } /* ScValue* val = var->getProp(MethodName); - if (val){ + if (val) { dw = GetFuncPos(val->getString()); - if (dw==0){ + if (dw==0) { TExternalFunction* f = GetExternal(val->getString()); - if (f){ + if (f) { ExternalCall(_stack, _thisStack, f); } else{ @@ -955,13 +955,13 @@ bool ScScript::executeInstruction() { /* if ((op1->isNULL() && !op2->isNULL()) || (!op1->isNULL() && op2->isNULL())) _operand->setBool(false); - else if (op1->isNative() && op2->isNative()){ + else if (op1->isNative() && op2->isNative()) { _operand->setBool(op1->getNative() == op2->getNative()); } - else if (op1->getType()==VAL_STRING || op2->getType()==VAL_STRING){ + else if (op1->getType()==VAL_STRING || op2->getType()==VAL_STRING) { _operand->setBool(scumm_stricmp(op1->getString(), op2->getString())==0); } - else if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + else if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() == op2->getFloat()); } else{ @@ -979,13 +979,13 @@ bool ScScript::executeInstruction() { /* if ((op1->isNULL() && !op2->isNULL()) || (!op1->isNULL() && op2->isNULL())) _operand->setBool(true); - else if (op1->isNative() && op2->isNative()){ + else if (op1->isNative() && op2->isNative()) { _operand->setBool(op1->getNative() != op2->getNative()); } - else if (op1->getType()==VAL_STRING || op2->getType()==VAL_STRING){ + else if (op1->getType()==VAL_STRING || op2->getType()==VAL_STRING) { _operand->setBool(scumm_stricmp(op1->getString(), op2->getString())!=0); } - else if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + else if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() != op2->getFloat()); } else{ @@ -1002,7 +1002,7 @@ bool ScScript::executeInstruction() { op1 = _stack->pop(); /* - if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() < op2->getFloat()); } else _operand->setBool(op1->getInt() < op2->getInt()); @@ -1017,7 +1017,7 @@ bool ScScript::executeInstruction() { op1 = _stack->pop(); /* - if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() > op2->getFloat()); } else _operand->setBool(op1->getInt() > op2->getInt()); @@ -1032,7 +1032,7 @@ bool ScScript::executeInstruction() { op1 = _stack->pop(); /* - if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() <= op2->getFloat()); } else _operand->setBool(op1->getInt() <= op2->getInt()); @@ -1047,7 +1047,7 @@ bool ScScript::executeInstruction() { op1 = _stack->pop(); /* - if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT){ + if (op1->getType()==VAL_FLOAT && op2->getType()==VAL_FLOAT) { _operand->setBool(op1->getFloat() >= op2->getFloat()); } else _operand->setBool(op1->getInt() >= op2->getInt()); diff --git a/engines/wintermute/base/scriptables/script_ext_date.cpp b/engines/wintermute/base/scriptables/script_ext_date.cpp index 5aa069d0b2..53a1d36b81 100644 --- a/engines/wintermute/base/scriptables/script_ext_date.cpp +++ b/engines/wintermute/base/scriptables/script_ext_date.cpp @@ -224,7 +224,7 @@ bool SXDate::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// - if (name == "Name")==0){ + if (name == "Name")==0) { setName(value->getString()); return STATUS_OK; } diff --git a/engines/wintermute/base/scriptables/script_ext_file.cpp b/engines/wintermute/base/scriptables/script_ext_file.cpp index a1d39c5d0a..08ecc8d7db 100644 --- a/engines/wintermute/base/scriptables/script_ext_file.cpp +++ b/engines/wintermute/base/scriptables/script_ext_file.cpp @@ -701,13 +701,13 @@ bool SXFile::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Length ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Length")==0){ + if (strcmp(name, "Length")==0) { int origLength = _length; _length = max(value->getInt(0), 0); char propName[20]; - if (_length < OrigLength){ - for(int i=_length; i<OrigLength; i++){ + if (_length < OrigLength) { + for(int i=_length; i<OrigLength; i++) { sprintf(PropName, "%d", i); _values->DeleteProp(PropName); } diff --git a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp index 8f05b7bff6..42c5cfb20e 100644 --- a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp +++ b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp @@ -476,15 +476,15 @@ bool SXMemBuffer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Length ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Length")==0){ + if (strcmp(name, "Length")==0) { int origLength = _length; _length = max(value->getInt(0), 0); char propName[20]; - if (_length < OrigLength){ - for(int i=_length; i<OrigLength; i++){ - sprintf(PropName, "%d", i); - _values->DeleteProp(PropName); + if (_length < origLength) { + for(int i=_length; i < origLength; i++) { + sprintf(propName, "%d", i); + _values->DeleteProp(propName); } } return STATUS_OK; diff --git a/engines/wintermute/base/scriptables/script_stack.cpp b/engines/wintermute/base/scriptables/script_stack.cpp index 77367045c2..194c5f4f35 100644 --- a/engines/wintermute/base/scriptables/script_stack.cpp +++ b/engines/wintermute/base/scriptables/script_stack.cpp @@ -147,73 +147,36 @@ void ScStack::correctParams(uint32 expectedParams) { ////////////////////////////////////////////////////////////////////////// void ScStack::pushNULL() { - /* - ScValue* val = new ScValue(_gameRef); - val->setNULL(); - Push(val); - delete val; - */ getPushValue()->setNULL(); } ////////////////////////////////////////////////////////////////////////// void ScStack::pushInt(int val) { - /* - ScValue* val = new ScValue(_gameRef); - val->setInt(Val); - Push(val); - delete val; - */ getPushValue()->setInt(val); } ////////////////////////////////////////////////////////////////////////// void ScStack::pushFloat(double val) { - /* - ScValue* val = new ScValue(_gameRef); - val->setFloat(Val); - Push(val); - delete val; - */ getPushValue()->setFloat(val); } ////////////////////////////////////////////////////////////////////////// void ScStack::pushBool(bool val) { - /* - ScValue* val = new ScValue(_gameRef); - val->setBool(Val); - Push(val); - delete val; - */ getPushValue()->setBool(val); } ////////////////////////////////////////////////////////////////////////// void ScStack::pushString(const char *val) { - /* - ScValue* val = new ScValue(_gameRef); - val->setString(Val); - Push(val); - delete val; - */ getPushValue()->setString(val); } ////////////////////////////////////////////////////////////////////////// void ScStack::pushNative(BaseScriptable *val, bool persistent) { - /* - ScValue* val = new ScValue(_gameRef); - val->setNative(Val, Persistent); - Push(val); - delete val; - */ - getPushValue()->setNative(val, persistent); } diff --git a/engines/wintermute/base/scriptables/script_value.cpp b/engines/wintermute/base/scriptables/script_value.cpp index 0bc7ab5807..ad8ab26e09 100644 --- a/engines/wintermute/base/scriptables/script_value.cpp +++ b/engines/wintermute/base/scriptables/script_value.cpp @@ -242,7 +242,7 @@ bool ScValue::setProp(const char *name, ScValue *val, bool copyWhole, bool setAs /* _valIter = _valObject.find(Name); - if (_valIter != _valObject.end()){ + if (_valIter != _valObject.end()) { delete _valIter->_value; _valIter->_value = NULL; } diff --git a/engines/wintermute/base/sound/base_sound_buffer.cpp b/engines/wintermute/base/sound/base_sound_buffer.cpp index 250570f2b8..d2b265a254 100644 --- a/engines/wintermute/base/sound/base_sound_buffer.cpp +++ b/engines/wintermute/base/sound/base_sound_buffer.cpp @@ -111,7 +111,7 @@ bool BaseSoundBuffer::loadFromFile(const Common::String &filename, bool forceRel if (Audio::loadWAVFromStream(*_file, waveSize, waveRate, waveFlags, &waveType)) { if (waveType == 1) { // We need to wrap the file in a substream to make sure the size is right. - _file = new Common::SeekableSubReadStream(_file, 0, waveSize); + _file = new Common::SeekableSubReadStream(_file, _file->pos(), waveSize + _file->pos(), DisposeAfterUse::YES); _stream = Audio::makeRawStream(_file, waveRate, waveFlags, DisposeAfterUse::YES); } else { error("BSoundBuffer::LoadFromFile - WAVE not supported yet for %s with type %d", filename.c_str(), waveType); diff --git a/engines/wintermute/base/sound/base_sound_manager.cpp b/engines/wintermute/base/sound/base_sound_manager.cpp index 441793144d..7e4a70afb2 100644 --- a/engines/wintermute/base/sound/base_sound_manager.cpp +++ b/engines/wintermute/base/sound/base_sound_manager.cpp @@ -50,6 +50,7 @@ namespace Wintermute { BaseSoundMgr::BaseSoundMgr(BaseGame *inGame) : BaseClass(inGame) { _soundAvailable = false; _volumeMaster = 255; + _volumeMasterPercent = 100; } @@ -72,7 +73,7 @@ bool BaseSoundMgr::cleanup() { ////////////////////////////////////////////////////////////////////////// void BaseSoundMgr::saveSettings() { if (_soundAvailable) { - ConfMan.setInt("master_volume", _volumeMaster); + ConfMan.setInt("master_volume_percent", _volumeMasterPercent); } } @@ -83,7 +84,8 @@ bool BaseSoundMgr::initialize() { if (!g_system->getMixer()->isReady()) { return STATUS_FAILED; } - _volumeMaster = (ConfMan.hasKey("master_volume") ? ConfMan.getInt("master_volume") : 255); + byte volumeMasterPercent = (ConfMan.hasKey("master_volume_percent") ? ConfMan.getInt("master_volume_percent") : 100); + setMasterVolumePercent(volumeMasterPercent); _soundAvailable = true; return STATUS_OK; @@ -217,6 +219,11 @@ byte BaseSoundMgr::getVolumePercent(Audio::Mixer::SoundType type) { ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::setMasterVolume(byte value) { + // This function intentionally doesn't touch _volumeMasterPercent, + // as that variable keeps track of what the game actually wanted, + // and this gives a close approximation, while letting the game + // be none the wiser about round-off-errors. This function should thus + // ONLY be called by setMasterVolumePercent. _volumeMaster = value; for (uint32 i = 0; i < _sounds.size(); i++) { _sounds[i]->updateVolume(); @@ -226,14 +233,15 @@ bool BaseSoundMgr::setMasterVolume(byte value) { ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::setMasterVolumePercent(byte percent) { - setMasterVolume(percent * 255 / 100); + _volumeMasterPercent = percent; + setMasterVolume((int)ceil(percent * 255.0 / 100.0)); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// byte BaseSoundMgr::getMasterVolumePercent() { - return getMasterVolume() * 100 / 255; + return _volumeMasterPercent; } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/sound/base_sound_manager.h b/engines/wintermute/base/sound/base_sound_manager.h index 36a729b5ae..1ee3c13fdb 100644 --- a/engines/wintermute/base/sound/base_sound_manager.h +++ b/engines/wintermute/base/sound/base_sound_manager.h @@ -45,7 +45,6 @@ public: //DECLARE_PERSISTENT(BaseSoundMgr, BaseClass); byte getMasterVolumePercent(); byte getMasterVolume(); - bool setMasterVolume(byte percent); bool setMasterVolumePercent(byte percent); byte getVolumePercent(Audio::Mixer::SoundType type); bool setVolumePercent(Audio::Mixer::SoundType type, byte percent); @@ -61,6 +60,9 @@ public: virtual ~BaseSoundMgr(); Common::Array<BaseSoundBuffer *> _sounds; void saveSettings(); +private: + int _volumeMasterPercent; // Necessary to avoid round-offs. + bool setMasterVolume(byte percent); }; } // end of namespace Wintermute diff --git a/engines/wintermute/dcgf.h b/engines/wintermute/dcgf.h index fc4174094b..0fbb1c6b29 100644 --- a/engines/wintermute/dcgf.h +++ b/engines/wintermute/dcgf.h @@ -32,7 +32,7 @@ ////////////////////////////////////////////////////////////////////////// #define DCGF_VER_MAJOR 1 -#define DCGF_VER_MINOR 1 +#define DCGF_VER_MINOR 2 #define DCGF_VER_BUILD 1 #define DCGF_VER_SUFFIX "beta" #define DCGF_VER_BETA true diff --git a/engines/wintermute/debugger.cpp b/engines/wintermute/debugger.cpp new file mode 100644 index 0000000000..1160a16d37 --- /dev/null +++ b/engines/wintermute/debugger.cpp @@ -0,0 +1,48 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "engines/wintermute/debugger.h" +#include "engines/wintermute/wintermute.h" +#include "engines/wintermute/base/base_game.h" + +namespace Wintermute { + +Console::Console(WintermuteEngine *vm) : GUI::Debugger(), _engineRef(vm) { + DCmd_Register("show_fps", WRAP_METHOD(Console, Cmd_ShowFps)); +} + +Console::~Console(void) { + +} + +bool Console::Cmd_ShowFps(int argc, const char **argv) { + if (argc > 1) { + if (Common::String(argv[1]) == "true") { + _engineRef->_game->_debugShowFPS = true; + } else if (Common::String(argv[1]) == "false") { + _engineRef->_game->_debugShowFPS = false; + } + } + return true; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/debugger.h b/engines/wintermute/debugger.h new file mode 100644 index 0000000000..069980385e --- /dev/null +++ b/engines/wintermute/debugger.h @@ -0,0 +1,43 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef WINTERMUTE_DEBUGGER_H +#define WINTERMUTE_DEBUGGER_H + +#include "gui/debugger.h" + +namespace Wintermute { + +class WintermuteEngine; +class Console : public GUI::Debugger { +public: + Console(WintermuteEngine *vm); + virtual ~Console(); + + bool Cmd_ShowFps(int argc, const char **argv); +private: + WintermuteEngine *_engineRef; +}; + +} + +#endif // WINTERMUTE_DEBUGGER_H diff --git a/engines/wintermute/detection.cpp b/engines/wintermute/detection.cpp index 04f7f3b112..1bf2c76a50 100644 --- a/engines/wintermute/detection.cpp +++ b/engines/wintermute/detection.cpp @@ -28,6 +28,7 @@ #include "common/error.h" #include "common/fs.h" #include "common/util.h" +#include "common/translation.h" #include "engines/metaengine.h" @@ -49,6 +50,20 @@ static ADGameDescription s_fallbackDesc = { ADGF_UNSTABLE, GUIO0() }; + +static const ADExtraGuiOptionsMap gameGuiOptions[] = { + { + GAMEOPTION_SHOW_FPS, + { + _s("Show FPS-counter"), + _s("Show the current number of frames per second in the upper left corner"), + "show_fps", + false + } + }, + AD_EXTRA_GUI_OPTIONS_TERMINATOR +}; + static char s_fallbackGameIdBuf[256]; static const char *directoryGlobs[] = { @@ -58,8 +73,9 @@ static const char *directoryGlobs[] = { class WintermuteMetaEngine : public AdvancedMetaEngine { public: - WintermuteMetaEngine() : AdvancedMetaEngine(Wintermute::gameDescriptions, sizeof(ADGameDescription), Wintermute::wintermuteGames) { + WintermuteMetaEngine() : AdvancedMetaEngine(Wintermute::gameDescriptions, sizeof(ADGameDescription), Wintermute::wintermuteGames, gameGuiOptions) { _singleid = "wintermute"; + _guioptions = GUIO2(GUIO_NOMIDI, GAMEOPTION_SHOW_FPS); _maxScanDepth = 2; _directoryGlobs = directoryGlobs; } diff --git a/engines/wintermute/detection_tables.h b/engines/wintermute/detection_tables.h index 0c843108ac..6b6dec635d 100644 --- a/engines/wintermute/detection_tables.h +++ b/engines/wintermute/detection_tables.h @@ -22,6 +22,8 @@ namespace Wintermute { +#define GAMEOPTION_SHOW_FPS GUIO_GAMEOPTIONS1 + static const PlainGameDescriptor wintermuteGames[] = { {"5ld", "Five Lethal Demons"}, {"5ma", "Five Magical Amulets"}, diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 9319899495..0f2279c40e 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -32,7 +32,7 @@ namespace Wintermute { byte *TransparentSurface::_lookup = NULL; void TransparentSurface::destroyLookup() { - delete _lookup; + delete[] _lookup; _lookup = NULL; } @@ -394,6 +394,8 @@ TransparentSurface *TransparentSurface::scale(const Common::Rect &srcRect, const // dstRect(x, y) = srcRect(x * srcW / dstW, y * srcH / dstH); TransparentSurface *target = new TransparentSurface(); + assert(format.bytesPerPixel == 4); + int srcW = srcRect.width(); int srcH = srcRect.height(); int dstW = dstRect.width(); diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk index 2bd71f1b6b..f61e61f6db 100644 --- a/engines/wintermute/module.mk +++ b/engines/wintermute/module.mk @@ -110,6 +110,7 @@ MODULE_OBJS := \ utils/utils.o \ video/video_player.o \ video/video_theora_player.o \ + debugger.o \ wintermute.o \ persistent.o diff --git a/engines/wintermute/persistent.h b/engines/wintermute/persistent.h index c862df5d6b..ca9281f798 100644 --- a/engines/wintermute/persistent.h +++ b/engines/wintermute/persistent.h @@ -36,53 +36,53 @@ class BasePersistenceManager; // persistence support typedef void *(*PERSISTBUILD)(void); typedef bool(*PERSISTLOAD)(void *, BasePersistenceManager *); -typedef void (*SYS_INSTANCE_CALLBACK)(void *Instance, void *Data); +typedef void(*SYS_INSTANCE_CALLBACK)(void *instance, void *data); } // end of namespace Wintermute #include "engines/wintermute/system/sys_class_registry.h" namespace Wintermute { -#define DECLARE_PERSISTENT(class_name, parent_class)\ +#define DECLARE_PERSISTENT(className, parentClass)\ static const char _className[];\ - static void* persistBuild(void);\ - virtual const char* getClassName();\ + static void *persistBuild(void);\ + virtual const char *getClassName();\ static bool persistLoad(void* Instance, BasePersistenceManager* PersistMgr);\ - class_name(TDynamicConstructor p1, TDynamicConstructor p2) :parent_class(p1, p2){ /*memset(this, 0, sizeof(class_name));*/ };\ - virtual bool persist(BasePersistenceManager* PersistMgr);\ + className(TDynamicConstructor p1, TDynamicConstructor p2) : parentClass(p1, p2) { /*memset(this, 0, sizeof(class_name));*/ };\ + virtual bool persist(BasePersistenceManager *persistMgr);\ void* operator new (size_t size);\ void operator delete(void* p);\ -#define IMPLEMENT_PERSISTENT(class_name, persistent_class)\ - const char class_name::_className[] = #class_name;\ - void* class_name::persistBuild(){\ - return ::new class_name(DYNAMIC_CONSTRUCTOR, DYNAMIC_CONSTRUCTOR);\ +#define IMPLEMENT_PERSISTENT(className, persistentClass)\ + const char className::_className[] = #className;\ + void* className::persistBuild() {\ + return ::new className(DYNAMIC_CONSTRUCTOR, DYNAMIC_CONSTRUCTOR);\ }\ \ - bool class_name::persistLoad(void* Instance, BasePersistenceManager* PersistMgr){\ - return ((class_name*)Instance)->persist(PersistMgr);\ + bool className::persistLoad(void *instance, BasePersistenceManager *persistMgr) {\ + return ((className*)instance)->persist(persistMgr);\ }\ \ - const char* class_name::getClassName(){\ - return #class_name;\ + const char *className::getClassName() {\ + return #className;\ }\ \ /*SystemClass Register##class_name(class_name::_className, class_name::PersistBuild, class_name::PersistLoad, persistent_class);*/\ \ - void* class_name::operator new (size_t size){\ + void* className::operator new(size_t size) {\ void* ret = ::operator new(size);\ - SystemClassRegistry::getInstance()->registerInstance(#class_name, ret);\ + SystemClassRegistry::getInstance()->registerInstance(#className, ret);\ return ret;\ }\ \ - void class_name::operator delete (void* p){\ - SystemClassRegistry::getInstance()->unregisterInstance(#class_name, p);\ + void className::operator delete(void *p) {\ + SystemClassRegistry::getInstance()->unregisterInstance(#className, p);\ ::operator delete(p);\ }\ -#define TMEMBER(member_name) #member_name, &member_name -#define TMEMBER_INT(member_name) #member_name, (int*)&member_name +#define TMEMBER(memberName) #memberName, &memberName +#define TMEMBER_INT(memberName) #memberName, (int*)&memberName } // end of namespace Wintermute diff --git a/engines/wintermute/platform_osystem.cpp b/engines/wintermute/platform_osystem.cpp index 0bd99b11cd..f13bdd2a3c 100644 --- a/engines/wintermute/platform_osystem.cpp +++ b/engines/wintermute/platform_osystem.cpp @@ -26,6 +26,7 @@ * Copyright (c) 2011 Jan Nedoma */ +#include "engines/wintermute/wintermute.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/gfx/osystem/base_render_osystem.h" #include "engines/wintermute/platform_osystem.h" @@ -36,13 +37,20 @@ namespace Wintermute { BaseGame *BasePlatform::_gameRef = NULL; +WintermuteEngine *BasePlatform::_engineRef = NULL; #define CLASS_NAME "GF_FRAME" -int BasePlatform::initialize(BaseGame *inGame, int argc, char *argv[]) { +int BasePlatform::initialize(WintermuteEngine *engineRef, BaseGame *inGame, int argc, char *argv[]) { _gameRef = inGame; + _engineRef = engineRef; return true; } +void BasePlatform::deinit() { + _gameRef = NULL; + _engineRef = NULL; +} + ////////////////////////////////////////////////////////////////////////// void BasePlatform::handleEvent(Common::Event *event) { switch (event->type) { @@ -86,6 +94,11 @@ void BasePlatform::handleEvent(Common::Event *event) { } break; case Common::EVENT_KEYDOWN: + if (event->kbd.flags & Common::KBD_CTRL) { + if (event->kbd.keycode == Common::KEYCODE_d) { + _engineRef->trigDebugger(); + } + } if (_gameRef) { _gameRef->handleKeypress(event); } diff --git a/engines/wintermute/platform_osystem.h b/engines/wintermute/platform_osystem.h index 21a77e0a0e..8c39b29ea9 100644 --- a/engines/wintermute/platform_osystem.h +++ b/engines/wintermute/platform_osystem.h @@ -36,11 +36,12 @@ namespace Wintermute { class BaseGame; - +class WintermuteEngine; ////////////////////////////////////////////////////////////////////////// class BasePlatform { public: - static int initialize(BaseGame *inGame, int argc, char *argv[]); + static int initialize(WintermuteEngine *engineRef, BaseGame *inGame, int argc, char *argv[]); + static void deinit(); static void handleEvent(Common::Event *event); static AnsiString getPlatformName(); @@ -66,6 +67,7 @@ public: private: // Set by initialize on game-startup, the object referred to is also deleted by deinit in WintermuteEngine static BaseGame *_gameRef; + static WintermuteEngine *_engineRef; }; } // end of namespace Wintermute diff --git a/engines/wintermute/ui/ui_tiled_image.cpp b/engines/wintermute/ui/ui_tiled_image.cpp index 2b337330c7..03fef5ca05 100644 --- a/engines/wintermute/ui/ui_tiled_image.cpp +++ b/engines/wintermute/ui/ui_tiled_image.cpp @@ -104,14 +104,11 @@ bool UITiledImage::display(int x, int y, int width, int height) { } // tiles - yyy = y + (_upMiddle.bottom - _upMiddle.top); - for (row = 0; row < nuRows; row++) { + if (nuRows > 0 && nuColumns > 0) { + yyy = y + (_upMiddle.bottom - _upMiddle.top); xxx = x + (_upLeft.right - _upLeft.left); - for (col = 0; col < nuColumns; col++) { - _image->_surface->displayTrans(xxx, yyy, _middleMiddle); - xxx += tileWidth; - } - yyy += tileWidth; + _image->_surface->displayTrans(xxx, yyy, _middleMiddle); + _image->_surface->repeatLastDisplayOp(tileWidth, tileWidth, nuColumns, nuRows); } _gameRef->_renderer->endSpriteBatch(); diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp index 7b3b0e1297..a1053bbef6 100644 --- a/engines/wintermute/utils/string_util.cpp +++ b/engines/wintermute/utils/string_util.cpp @@ -213,8 +213,10 @@ int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t } Common::String StringUtil::encodeSetting(const Common::String &str) { - if (str.contains('=')) { - error("Setting contains '='"); + for (uint32 i = 0; i < str.size(); i++) { + if ((str[i] < 33) || (str[i] == '=') || (str[i] > 126)) { + error("Setting contains illegal characters: %s", str.c_str()); + } } return str; } diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp index d2b761afd7..4d3adc95b2 100644 --- a/engines/wintermute/wintermute.cpp +++ b/engines/wintermute/wintermute.cpp @@ -34,6 +34,7 @@ #include "engines/util.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/wintermute.h" +#include "engines/wintermute/debugger.h" #include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/base/base_engine.h" @@ -48,6 +49,8 @@ namespace Wintermute { // This might not be the prettiest solution WintermuteEngine::WintermuteEngine() : Engine(g_system) { _game = new AdGame(""); + _debugger = NULL; + _trigDebug = false; } WintermuteEngine::WintermuteEngine(OSystem *syst, const ADGameDescription *desc) @@ -55,6 +58,7 @@ WintermuteEngine::WintermuteEngine(OSystem *syst, const ADGameDescription *desc) // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you // need to do such things, do them from init(). + ConfMan.registerDefault("show_fps","false"); // Do not initialize graphics here @@ -71,13 +75,15 @@ WintermuteEngine::WintermuteEngine(OSystem *syst, const ADGameDescription *desc) DebugMan.addDebugChannel(kWintermuteDebugGeneral, "general", "various issues not covered by any of the above"); _game = NULL; + _debugger = NULL; + _trigDebug = false; } WintermuteEngine::~WintermuteEngine() { // Dispose your resources here deinit(); delete _game; - delete _console; + delete _debugger; // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); @@ -106,7 +112,7 @@ Common::Error WintermuteEngine::run() { } // Create debugger console. It requires GFX to be initialized - _console = new Console(this); + _debugger = new Console(this); // DebugMan.enableDebugChannel("enginelog"); debugC(1, kWintermuteDebugLog, "Engine Debug-LOG enabled"); @@ -133,7 +139,7 @@ int WintermuteEngine::init() { return 1; } BaseEngine::instance().setGameRef(_game); - BasePlatform::initialize(_game, 0, NULL); + BasePlatform::initialize(this, _game, 0, NULL); bool windowedMode = !ConfMan.getBool("fullscreen"); @@ -232,11 +238,18 @@ int WintermuteEngine::messageLoop() { const uint32 maxFPS = 60; const uint32 frameTime = 2 * (uint32)((1.0 / maxFPS) * 1000); while (!done) { + _debugger->onFrame(); + Common::Event event; while (_system->getEventManager()->pollEvent(event)) { BasePlatform::handleEvent(&event); } + if (_trigDebug) { + _debugger->attach(); + _trigDebug = false; + } + if (_game && _game->_renderer->_active && _game->_renderer->_ready) { _game->displayContent(); _game->displayQuickMsg(); @@ -272,6 +285,7 @@ int WintermuteEngine::messageLoop() { void WintermuteEngine::deinit() { BaseEngine::destroy(); + BasePlatform::deinit(); } Common::Error WintermuteEngine::loadGameState(int slot) { diff --git a/engines/wintermute/wintermute.h b/engines/wintermute/wintermute.h index d24b120658..fcaa2840a9 100644 --- a/engines/wintermute/wintermute.h +++ b/engines/wintermute/wintermute.h @@ -48,6 +48,9 @@ public: WintermuteEngine(); ~WintermuteEngine(); + virtual GUI::Debugger *getDebugger() { return _debugger; } + void trigDebugger() { _trigDebug = true; } + virtual Common::Error run(); virtual bool hasFeature(EngineFeature f) const; Common::SaveFileManager *getSaveFileMan() { return _saveFileMan; } @@ -58,19 +61,15 @@ public: // For detection-purposes: static bool getGameInfo(const Common::FSList &fslist, Common::String &name, Common::String &caption); private: + bool _trigDebug; int init(); void deinit(); int messageLoop(); - Console *_console; + GUI::Debugger *_debugger; BaseGame *_game; const ADGameDescription *_gameDescription; -}; -// Example console class -class Console : public GUI::Debugger { -public: - Console(WintermuteEngine *vm) {} - virtual ~Console(void) {} + friend class Console; }; } // End of namespace Wintermute |