From e45a9d42e26c70d9eeb3bfa11408bc0d33c7b69b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 4 May 2008 15:56:28 +0000 Subject: - Shared checkInput code between kyra2 and kyra3 - Debugger related cleanup svn-id: r31868 --- engines/kyra/debugger.cpp | 120 +++++----------------------------------------- engines/kyra/debugger.h | 23 ++++----- engines/kyra/kyra_hof.cpp | 66 +------------------------ engines/kyra/kyra_hof.h | 6 +-- engines/kyra/kyra_mr.cpp | 67 +------------------------- engines/kyra/kyra_mr.h | 9 +--- engines/kyra/kyra_v2.cpp | 67 ++++++++++++++++++++++++++ engines/kyra/kyra_v2.h | 9 +++- 8 files changed, 100 insertions(+), 267 deletions(-) diff --git a/engines/kyra/debugger.cpp b/engines/kyra/debugger.cpp index 82f6dd30fb..51e4d17487 100644 --- a/engines/kyra/debugger.cpp +++ b/engines/kyra/debugger.cpp @@ -28,8 +28,8 @@ #include "common/system.h" #include "kyra/debugger.h" #include "kyra/kyra_v1.h" +#include "kyra/kyra_v2.h" #include "kyra/kyra_hof.h" -#include "kyra/kyra_mr.h" #include "kyra/screen.h" #include "kyra/timer.h" #include "kyra/resource.h" @@ -283,7 +283,7 @@ bool Debugger_v1::cmd_listBirthstones(int argc, const char **argv) { #pragma mark - -Debugger_v2::Debugger_v2(KyraEngine_HoF *vm) : Debugger(vm), _vm(vm) { +Debugger_v2::Debugger_v2(KyraEngine_v2 *vm) : Debugger(vm), _vm(vm) { DCmd_Register("character_info", WRAP_METHOD(Debugger_v2, cmd_characterInfo)); DCmd_Register("enter", WRAP_METHOD(Debugger_v2, cmd_enterScene)); DCmd_Register("rooms", WRAP_METHOD(Debugger_v2, cmd_listScenes)); // for consistency with kyra_v1 @@ -291,7 +291,6 @@ Debugger_v2::Debugger_v2(KyraEngine_HoF *vm) : Debugger(vm), _vm(vm) { DCmd_Register("scene_info", WRAP_METHOD(Debugger_v2, cmd_sceneInfo)); DCmd_Register("scene_to_facing", WRAP_METHOD(Debugger_v2, cmd_sceneToFacing)); DCmd_Register("give", WRAP_METHOD(Debugger_v2, cmd_giveItem)); - DCmd_Register("pass_codes", WRAP_METHOD(Debugger_v2, cmd_passcodes)); } bool Debugger_v2::cmd_enterScene(int argc, const char **argv) { @@ -322,8 +321,8 @@ bool Debugger_v2::cmd_enterScene(int argc, const char **argv) { _vm->_mainCharacter.facing = direction; _vm->enterNewScene(scene, _vm->_mainCharacter.facing, 0, 0, 1); - while (!_vm->_screen->isMouseVisible()) - _vm->_screen->showMouse(); + while (!_vm->screen_v2()->isMouseVisible()) + _vm->screen_v2()->showMouse(); _detach_now = true; return false; @@ -436,7 +435,13 @@ bool Debugger_v2::cmd_giveItem(int argc, const char **argv) { return true; } -bool Debugger_v2::cmd_passcodes(int argc, const char **argv) { +#pragma mark - + +Debugger_HoF::Debugger_HoF(KyraEngine_HoF *vm) : Debugger_v2(vm), _vm(vm) { + DCmd_Register("pass_codes", WRAP_METHOD(Debugger_HoF, cmd_passcodes)); +} + +bool Debugger_HoF::cmd_passcodes(int argc, const char **argv) { if (argc == 2) { int val = atoi(argv[1]); @@ -453,108 +458,5 @@ bool Debugger_v2::cmd_passcodes(int argc, const char **argv) { return true; } -Debugger_v3::Debugger_v3(KyraEngine_MR *vm) : Debugger(vm), _vm(vm) { - DCmd_Register("give", WRAP_METHOD(Debugger_v3, cmd_giveItem)); - DCmd_Register("enter", WRAP_METHOD(Debugger_v3, cmd_enterScene)); - DCmd_Register("rooms", WRAP_METHOD(Debugger_v3, cmd_listScenes)); // for consistency with kyra_v1 - DCmd_Register("scenes", WRAP_METHOD(Debugger_v3, cmd_listScenes)); - DCmd_Register("scene_info", WRAP_METHOD(Debugger_v3, cmd_sceneInfo)); -} - -bool Debugger_v3::cmd_giveItem(int argc, const char **argv) { - if (argc == 2) { - int item = atoi(argv[1]); - - // Kyrandia 3 has only 73 items (-1 to 71), otherwise it will crash - if (item < -1 || item > 71) { - DebugPrintf("itemid must be any value between (including) -1 and 71\n"); - return true; - } - - _vm->setHandItem(item); - } else { - DebugPrintf("Syntax: give \n"); - } - - return true; -} - -bool Debugger_v3::cmd_enterScene(int argc, const char **argv) { - uint direction = 0; - if (argc > 1) { - int scene = atoi(argv[1]); - - // game will crash if entering a non-existent scene - if (scene >= _vm->_sceneListSize) { - DebugPrintf("scene number must be any value between (including) 0 and %d\n", _vm->_sceneListSize-1); - return true; - } - - if (argc > 2) { - direction = atoi(argv[2]); - } else { - if (_vm->_sceneList[scene].exit1 != 0xFFFF) - direction = 4; - else if (_vm->_sceneList[scene].exit2 != 0xFFFF) - direction = 6; - else if (_vm->_sceneList[scene].exit3 != 0xFFFF) - direction = 0; - else if (_vm->_sceneList[scene].exit4 != 0xFFFF) - direction = 2; - } - - _vm->_system->hideOverlay(); - _vm->_mainCharacter.facing = direction; - - _vm->enterNewScene(scene, _vm->_mainCharacter.facing, 0, 0, 1); - while (!_vm->_screen->isMouseVisible()) - _vm->_screen->showMouse(); - - _detach_now = true; - return false; - } - - DebugPrintf("Syntax: %d \n", argv[0]); - return true; -} - -bool Debugger_v3::cmd_listScenes(int argc, const char **argv) { - int shown = 1; - for (int i = 0; i < _vm->_sceneListSize; ++i) { - if (_vm->_sceneList[i].filename1[0]) { - DebugPrintf("%-2i: %-10s", i, _vm->_sceneList[i].filename1); - if (!(shown % 5)) - DebugPrintf("\n"); - ++shown; - } - } - DebugPrintf("\n"); - DebugPrintf("Current scene: %i\n", _vm->_mainCharacter.sceneId); - return true; -} - -bool Debugger_v3::cmd_sceneInfo(int argc, const char **argv) { - DebugPrintf("Current scene: %d '%s'\n", _vm->_mainCharacter.sceneId, _vm->_sceneList[_vm->_mainCharacter.sceneId].filename1); - DebugPrintf("\n"); - DebugPrintf("Exit information:\n"); - DebugPrintf("Exit1: leads to %d, position %dx%d\n", int16(_vm->_sceneExit1), _vm->_sceneEnterX1, _vm->_sceneEnterY1); - DebugPrintf("Exit2: leads to %d, position %dx%d\n", int16(_vm->_sceneExit2), _vm->_sceneEnterX2, _vm->_sceneEnterY2); - DebugPrintf("Exit3: leads to %d, position %dx%d\n", int16(_vm->_sceneExit3), _vm->_sceneEnterX3, _vm->_sceneEnterY3); - DebugPrintf("Exit4: leads to %d, position %dx%d\n", int16(_vm->_sceneExit4), _vm->_sceneEnterX4, _vm->_sceneEnterY4); - DebugPrintf("Special exit information:\n"); - if (!_vm->_specialExitCount) { - DebugPrintf("No special exits.\n"); - } else { - DebugPrintf("This scene has %d special exits.\n", _vm->_specialExitCount); - for (int i = 0; i < _vm->_specialExitCount; ++i) { - DebugPrintf("SpecialExit%d: facing %d, position (x1/y1/x2/y2): %d/%d/%d/%d\n", i, - _vm->_specialExitTable[20+i], _vm->_specialExitTable[0+i], _vm->_specialExitTable[5+i], - _vm->_specialExitTable[10+i], _vm->_specialExitTable[15+i]); - } - } - - return true; -} - } // End of namespace Kyra diff --git a/engines/kyra/debugger.h b/engines/kyra/debugger.h index be6725de89..ab5657bbde 100644 --- a/engines/kyra/debugger.h +++ b/engines/kyra/debugger.h @@ -32,8 +32,8 @@ namespace Kyra { class KyraEngine; class KyraEngine_v1; +class KyraEngine_v2; class KyraEngine_HoF; -class KyraEngine_MR; class Debugger : public ::GUI::Debugger { public: @@ -73,11 +73,11 @@ protected: class Debugger_v2 : public Debugger { public: - Debugger_v2(KyraEngine_HoF *vm); + Debugger_v2(KyraEngine_v2 *vm); virtual ~Debugger_v2() {} protected: - KyraEngine_HoF *_vm; + KyraEngine_v2 *_vm; bool cmd_enterScene(int argc, const char **argv); bool cmd_listScenes(int argc, const char **argv); @@ -85,24 +85,17 @@ protected: bool cmd_characterInfo(int argc, const char **argv); bool cmd_sceneToFacing(int argc, const char **argv); bool cmd_giveItem(int argc, const char **argv); - bool cmd_passcodes(int argc, const char **argv); }; -class Debugger_v3 : public Debugger { +class Debugger_HoF : public Debugger_v2 { public: - Debugger_v3(KyraEngine_MR *vm); - virtual ~Debugger_v3() {} + Debugger_HoF(KyraEngine_HoF *vm); protected: - KyraEngine_MR *_vm; - - bool cmd_giveItem(int argc, const char **argv); - bool cmd_enterScene(int argc, const char **argv); - bool cmd_listScenes(int argc, const char **argv); - bool cmd_sceneInfo(int argc, const char **argv); - bool cmd_sceneToFacing(int argc, const char **argv); -}; + KyraEngine_HoF *_vm; + bool cmd_passcodes(int argc, const char **argv); +}; } // End of namespace Kyra diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp index d7052c9332..64ec7e2905 100644 --- a/engines/kyra/kyra_hof.cpp +++ b/engines/kyra/kyra_hof.cpp @@ -54,7 +54,6 @@ const KyraEngine_v2::EngineDesc KyraEngine_HoF::_hofEngineDesc = { KyraEngine_HoF::KyraEngine_HoF(OSystem *system, const GameFlags &flags) : KyraEngine_v2(system, flags, _hofEngineDesc), _updateFunctor(this, &KyraEngine_HoF::update) { _mouseSHPBuf = 0; - _debugger = 0; _screen = 0; _text = 0; @@ -154,7 +153,6 @@ KyraEngine_HoF::~KyraEngine_HoF() { delete _gui; delete _tim; _text = 0; - delete _debugger; delete _invWsa.wsa; if (_sequenceSoundList) { @@ -185,7 +183,7 @@ int KyraEngine_HoF::init() { KyraEngine::init(); initStaticResource(); - _debugger = new Debugger_v2(this); + _debugger = new Debugger_HoF(this); assert(_debugger); _text = new TextDisplayer_HoF(this, _screen); assert(_text); @@ -744,68 +742,6 @@ void KyraEngine_HoF::updateMouse() { } } -int KyraEngine_HoF::checkInput(Button *buttonList, bool mainLoop) { - updateInput(); - - int keys = 0; - - while (_eventList.size()) { - Common::Event event = *_eventList.begin(); - bool breakLoop = false; - - switch (event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && - (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && mainLoop) { - const char *saveLoadSlot = getSavegameFilename(9 - (event.kbd.keycode - '0') + 990); - - if (event.kbd.flags == Common::KBD_CTRL) { - loadGame(saveLoadSlot); - _eventList.clear(); - breakLoop = true; - } else { - char savegameName[14]; - sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); - saveGame(saveLoadSlot, savegameName); - } - } else if (event.kbd.flags == Common::KBD_CTRL) { - if (event.kbd.keycode == 'd') - _debugger->attach(); - } - break; - - case Common::EVENT_MOUSEMOVE: { - Common::Point pos = getMousePos(); - _mouseX = pos.x; - _mouseY = pos.y; - _screen->updateScreen(); - } break; - - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_LBUTTONUP: { - Common::Point pos = getMousePos(); - _mouseX = pos.x; - _mouseY = pos.y; - keys = event.type == Common::EVENT_LBUTTONDOWN ? 199 : (200 | 0x800); - breakLoop = true; - } break; - - default: - break; - } - - if (_debugger->isAttached()) - _debugger->onFrame(); - - if (breakLoop) - break; - - _eventList.erase(_eventList.begin()); - } - - return _gui->processButtonList(buttonList, keys | 0x8000); -} - void KyraEngine_HoF::delay(uint32 amount, bool updateGame, bool isMainLoop) { uint32 start = _system->getMillis(); do { diff --git a/engines/kyra/kyra_hof.h b/engines/kyra/kyra_hof.h index 42cdd57ae7..b24ea02262 100644 --- a/engines/kyra/kyra_hof.h +++ b/engines/kyra/kyra_hof.h @@ -100,7 +100,6 @@ enum kNestedSequencesDemo { class WSAMovieV2; class KyraEngine_HoF; class TextDisplayer_HoF; -class Debugger_v2; struct TIM; @@ -192,7 +191,7 @@ struct ActiveItemAnim { }; class KyraEngine_HoF : public KyraEngine_v2 { -friend class Debugger_v2; +friend class Debugger_HoF; friend class TextDisplayer_HoF; friend class GUI_HoF; public: @@ -201,6 +200,7 @@ public: Screen *screen() { return _screen; } Screen_v2 *screen_v2() const { return _screen; } + GUI_v2 *gui_v2() const { return _gui; } virtual TextDisplayer *text() { return _text; } int language() const { return _lang; } protected: @@ -289,7 +289,6 @@ protected: Screen_HoF *_screen; TextDisplayer_HoF *_text; - Debugger_v2 *_debugger; TIMInterpreter *_tim; uint8 *_mouseSHPBuf; @@ -332,7 +331,6 @@ protected: int _mouseState; - int checkInput(Button *buttonList, bool mainLoop = false); void handleInput(int x, int y); bool handleInputUnkSub(int x, int y); diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp index 2545f6ffc3..fbd5ed5492 100644 --- a/engines/kyra/kyra_mr.cpp +++ b/engines/kyra/kyra_mr.cpp @@ -130,7 +130,6 @@ KyraEngine_MR::KyraEngine_MR(OSystem *system, const GameFlags &flags) : KyraEngi _invWsaFrame = -1; _score = 0; memset(_scoreFlagTable, 0, sizeof(_scoreFlagTable)); - _debugger = 0; _mainButtonData = 0; _mainButtonList = 0; _mainButtonListInitialized = false; @@ -182,7 +181,6 @@ KyraEngine_MR::~KyraEngine_MR() { delete _dlgBuffer; delete [] _stringBuffer; delete _invWsa; - delete _debugger; delete [] _mainButtonData; delete _gui; } @@ -194,7 +192,7 @@ int KyraEngine_MR::init() { KyraEngine::init(); - _debugger = new Debugger_v3(this); + _debugger = new Debugger_v2(this); assert(_debugger); _soundDigital = new SoundDigital(this, _mixer); @@ -1250,69 +1248,6 @@ void KyraEngine_MR::delay(uint32 millis, bool doUpdate, bool isMainLoop) { #pragma mark - -int KyraEngine_MR::checkInput(Button *buttonList, bool mainLoop) { - debugC(9, kDebugLevelMain, "KyraEngine_MR::checkInput(%p, %d)", (const void*)buttonList, mainLoop); - updateInput(); - - int keys = 0; - - while (_eventList.size()) { - Common::Event event = *_eventList.begin(); - bool breakLoop = false; - - switch (event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && - (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && mainLoop) { - const char *saveLoadSlot = getSavegameFilename(9 - (event.kbd.keycode - '0') + 990); - - if (event.kbd.flags == Common::KBD_CTRL) { - loadGame(saveLoadSlot); - _eventList.clear(); - breakLoop = true; - } else { - char savegameName[14]; - sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); - saveGame(saveLoadSlot, savegameName); - } - } else if (event.kbd.flags == Common::KBD_CTRL) { - if (event.kbd.keycode == 'd') - _debugger->attach(); - } - break; - - case Common::EVENT_MOUSEMOVE: { - Common::Point pos = getMousePos(); - _mouseX = pos.x; - _mouseY = pos.y; - _screen->updateScreen(); - } break; - - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_LBUTTONUP: { - Common::Point pos = getMousePos(); - _mouseX = pos.x; - _mouseY = pos.y; - keys = event.type == Common::EVENT_LBUTTONDOWN ? 199 : (200 | 0x800); - breakLoop = true; - } break; - - default: - break; - } - - if (_debugger->isAttached()) - _debugger->onFrame(); - - if (breakLoop) - break; - - _eventList.erase(_eventList.begin()); - } - - return _gui->processButtonList(buttonList, keys | 0x8000); -} - void KyraEngine_MR::makeCharFacingMouse() { debugC(9, kDebugLevelAnimator, "KyraEngine_MR::makeCharFacingMouse()"); if (_mainCharacter.x1 > _mouseX) diff --git a/engines/kyra/kyra_mr.h b/engines/kyra/kyra_mr.h index 33e2415b48..4d83eee7bb 100644 --- a/engines/kyra/kyra_mr.h +++ b/engines/kyra/kyra_mr.h @@ -29,6 +29,7 @@ #include "kyra/kyra_v2.h" #include "kyra/screen_mr.h" #include "kyra/script.h" +#include "kyra/gui_mr.h" #include "common/hashmap.h" #include "common/list.h" @@ -40,12 +41,9 @@ class Screen_MR; class MainMenu; class WSAMovieV2; class TextDisplayer_MR; -class Debugger_v3; -class GUI_MR; struct Button; class KyraEngine_MR : public KyraEngine_v2 { -friend class Debugger_v3; friend class TextDisplayer_MR; friend class GUI_MR; public: @@ -54,6 +52,7 @@ public: Screen *screen() { return _screen; } Screen_v2 *screen_v2() const { return _screen; } + GUI_v2 *gui_v2() const { return _gui; } SoundDigital *soundDigital() { return _soundDigital; } int language() const { return _lang; } @@ -87,9 +86,6 @@ protected: void delay(uint32 millis, bool update = false, bool isMainLoop = false); - // - Input - int checkInput(Button *buttonList, bool mainLoop = false); - // sound specific private: void playMenuAudioFile(); @@ -567,7 +563,6 @@ private: // misc TextDisplayer_MR *_text; - Debugger_v3 *_debugger; bool _wsaPlayingVQA; // resource specific diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 8070f86eb3..6e58d8592a 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -25,6 +25,7 @@ #include "kyra/kyra_v2.h" #include "kyra/screen_v2.h" +#include "kyra/debugger.h" namespace Kyra { @@ -62,6 +63,8 @@ KyraEngine_v2::KyraEngine_v2(OSystem *system, const GameFlags &flags, const Engi _chatObject = -1; memset(_hiddenItems, -1, sizeof(_hiddenItems)); + + _debugger = 0; } KyraEngine_v2::~KyraEngine_v2() { @@ -81,6 +84,70 @@ KyraEngine_v2::~KyraEngine_v2() { delete *i; _opcodesAnimation.clear(); + delete _debugger; +} + +int KyraEngine_v2::checkInput(Button *buttonList, bool mainLoop) { + debugC(9, kDebugLevelMain, "KyraEngine_v2::checkInput(%p, %d)", (const void*)buttonList, mainLoop); + updateInput(); + + int keys = 0; + + while (_eventList.size()) { + Common::Event event = *_eventList.begin(); + bool breakLoop = false; + + switch (event.type) { + case Common::EVENT_KEYDOWN: + if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && + (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && mainLoop) { + const char *saveLoadSlot = getSavegameFilename(9 - (event.kbd.keycode - '0') + 990); + + if (event.kbd.flags == Common::KBD_CTRL) { + loadGame(saveLoadSlot); + _eventList.clear(); + breakLoop = true; + } else { + char savegameName[14]; + sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); + saveGame(saveLoadSlot, savegameName); + } + } else if (event.kbd.flags == Common::KBD_CTRL) { + if (event.kbd.keycode == 'd') + _debugger->attach(); + } + break; + + case Common::EVENT_MOUSEMOVE: { + Common::Point pos = getMousePos(); + _mouseX = pos.x; + _mouseY = pos.y; + screen()->updateScreen(); + } break; + + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_LBUTTONUP: { + Common::Point pos = getMousePos(); + _mouseX = pos.x; + _mouseY = pos.y; + keys = event.type == Common::EVENT_LBUTTONDOWN ? 199 : (200 | 0x800); + breakLoop = true; + } break; + + default: + break; + } + + if (_debugger->isAttached()) + _debugger->onFrame(); + + if (breakLoop) + break; + + _eventList.erase(_eventList.begin()); + } + + return gui_v2()->processButtonList(buttonList, keys | 0x8000); } void KyraEngine_v2::updateInput() { diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index 0dda0d9fc6..7134d62872 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -36,6 +36,7 @@ namespace Kyra { class Screen_v2; +class Debugger_v2; class KyraEngine_v2 : public KyraEngine { friend class Debugger_v2; @@ -57,10 +58,12 @@ public: ~KyraEngine_v2(); virtual Screen_v2 *screen_v2() const = 0; + virtual GUI *gui_v2() const = 0; const EngineDesc &engineDesc() const { return _desc; } protected: EngineDesc _desc; + Debugger_v2 *_debugger; // run bool _runFlag; @@ -74,10 +77,10 @@ protected: MainMenu *_menu; // Input - virtual int checkInput(Button *buttonList, bool mainLoop = false) = 0; virtual int inputSceneChange(int x, int y, int unk1, int unk2) = 0; void updateInput(); + int checkInput(Button *buttonList, bool mainLoop = false); void removeInputTop(); int _mouseX, _mouseY; @@ -403,6 +406,10 @@ protected: int o2_setTimerCountdown(EMCState *script); int o2_setVocHigh(EMCState *script); int o2_getVocHigh(EMCState *script); + + // save/load specific + virtual void saveGame(const char *fileName, const char *saveName) = 0; + virtual void loadGame(const char *fileName) = 0; }; } // end of namespace Kyra -- cgit v1.2.3