diff options
author | Gregory Montoir | 2003-12-26 12:58:27 +0000 |
---|---|---|
committer | Gregory Montoir | 2003-12-26 12:58:27 +0000 |
commit | ffbfe8922a3cfa2d2750fca3a2cb2d953fd1e4ca (patch) | |
tree | e75942537560cbf1939534597c120258ceba69cb /queen | |
parent | a45e92efed3715b3bb0b1191b718207b191ab1ae (diff) | |
download | scummvm-rg350-ffbfe8922a3cfa2d2750fca3a2cb2d953fd1e4ca.tar.gz scummvm-rg350-ffbfe8922a3cfa2d2750fca3a2cb2d953fd1e4ca.tar.bz2 scummvm-rg350-ffbfe8922a3cfa2d2750fca3a2cb2d953fd1e4ca.zip |
new debugging code, using Common::Debugger
svn-id: r11940
Diffstat (limited to 'queen')
-rw-r--r-- | queen/debug.cpp | 243 | ||||
-rw-r--r-- | queen/debug.h | 49 | ||||
-rw-r--r-- | queen/input.cpp | 52 | ||||
-rw-r--r-- | queen/input.h | 14 | ||||
-rw-r--r-- | queen/logic.cpp | 38 | ||||
-rw-r--r-- | queen/logic.h | 3 | ||||
-rw-r--r-- | queen/queen.cpp | 3 | ||||
-rw-r--r-- | queen/queen.h | 3 |
8 files changed, 165 insertions, 240 deletions
diff --git a/queen/debug.cpp b/queen/debug.cpp index 6b03eb06ff..233c51aecb 100644 --- a/queen/debug.cpp +++ b/queen/debug.cpp @@ -30,195 +30,148 @@ #include "queen/resource.h" #include "queen/structs.h" -namespace Queen { - -Debug::Debug(QueenEngine *vm) - : _passwordCharCount(0), _stubCount(0), _vm(vm) { - - memset(_password, 0, sizeof(_password)); - - registerStub("zeroxpark", &Debug::jumpToRoom); - registerStub("grimley", &Debug::printInfo); - registerStub("kowamori", &Debug::toggleFastMode); -} +#include "common/debugger.cpp" +namespace Queen { -void Debug::registerStub(const char *password, DebugFunc debugFunc) { - assert(_stubCount < MAX_STUB); - _stub[_stubCount].password = password; - _stub[_stubCount].function = debugFunc; - ++_stubCount; +Debugger::Debugger(QueenEngine *vm) + : _drawAreas(false), _vm(vm) { + + DCmd_Register("exit", &Debugger::Cmd_Exit); + DCmd_Register("help", &Debugger::Cmd_Help); + DCmd_Register("areas", &Debugger::Cmd_Areas); + DCmd_Register("asm", &Debugger::Cmd_Asm); + DCmd_Register("gs", &Debugger::Cmd_GameState); + DCmd_Register("info", &Debugger::Cmd_Info); + DCmd_Register("items", &Debugger::Cmd_Items); + DCmd_Register("room", &Debugger::Cmd_Room); } -void Debug::update(int c) { - - if (c >= 'a' && c <= 'z') { - _password[_passwordCharCount] = (char)c; - ++_passwordCharCount; - _passwordCharCount &= 15; - - uint k; - for (k = 0; k < _stubCount; ++k) { - const char *pass = _stub[k].password; - int i = strlen(pass) - 1; - int j = _passwordCharCount - 1; - bool match = true; - for (; i >= 0; --i, --j) { - if (_password[j & 15] != pass[i]) { - match = false; - break; - } - } - if (match) { - (this->*(_stub[k].function))(); - break; - } - } - } +void Debugger::preEnter() { + + // XXX mute all sounds } -void Debug::jumpToRoom() { - - debug(9, "Debug::jumpToRoom()"); - - _vm->graphics()->textCurrentColor(INK_JOE); - _vm->graphics()->textSet(0, 142, "Enter new room"); - _vm->logic()->update(); - - int room; - _digitTextCount = 0; - if (_vm->input()->waitForNumber(room, digitKeyPressed, this)) { - _vm->logic()->joeX(0); - _vm->logic()->joeY(0); - _vm->logic()->newRoom(room); - _vm->logic()->entryObj(_vm->logic()->roomData(room) + 1); - _vm->graphics()->textClear(0, 199); - } +void Debugger::postEnter() { + + // XXX un-mute all sounds + _vm->graphics()->bobSetupControl(); // re-init mouse cursor } -void Debug::toggleFastMode() { - - debug(9, "Debug::toggleFastMode()"); - _vm->input()->fastMode(!_vm->input()->fastMode()); +bool Debugger::Cmd_Exit(int argc, const char **argv) { + + _detach_now = true; + return false; } -void Debug::printInfo() { +bool Debugger::Cmd_Help(int argc, const char **argv) { + // console normally has 39 line width + // wrap around nicely + int width = 0, size, i; - debug(9, "Debug::printInfo()"); + DebugPrintf("Commands are:\n"); + for (i = 0 ; i < _dcmd_count ; i++) { + size = strlen(_dcmds[i].name) + 1; - _vm->graphics()->textClear(0, 199); - _vm->graphics()->textCurrentColor(INK_JOE); + if ((width + size) >= 39) { + DebugPrintf("\n"); + width = size; + } else + width += size; - char buf[100]; - - snprintf(buf, sizeof(buf), "Version : %s", _vm->resource()->JASVersion()); - _vm->graphics()->textSet(110, 20, buf); - - snprintf(buf, sizeof(buf), "Room number : %d", _vm->logic()->currentRoom()); - _vm->graphics()->textSet(110, 40, buf); - - snprintf(buf, sizeof(buf), "Room name : %s", _vm->logic()->roomName(_vm->logic()->currentRoom())); - _vm->graphics()->textSet(110, 60, buf); + DebugPrintf("%s ", _dcmds[i].name); + } + DebugPrintf("\n"); + return true; +} - _vm->logic()->update(); - char c; - if (_vm->input()->waitForCharacter(c)) { - switch (c) { - case 'a': - toggleAreasDrawing(); - break; - case 's' : - changeGameState(); - break; - case 'x' : - printGameState(); - break; - case 'i' : - giveAllItems(); - break; - } +bool Debugger::Cmd_Asm(int argc, const char **argv) { + + if (argc == 2) { + uint16 sm = atoi(argv[1]); + DebugPrintf("Executing special move %d\n", sm); + _vm->logic()->executeSpecialMove(sm); + } else { + DebugPrintf("Usage: %s smnum\n", argv[0]); } - _vm->graphics()->textClear(0, 199); + return true; } -void Debug::toggleAreasDrawing() { +bool Debugger::Cmd_Areas(int argc, const char **argv) { - debug(9, "Debug::toggleAreasDrawing()"); - warning("Debug::toggleAreasDrawing() unimplemented"); + _drawAreas = !_drawAreas; + DebugPrintf("Room areas display %s\n", _drawAreas ? "on" : "off"); + return true; } -void Debug::changeGameState() { - - debug(9, "Debug::changeGameState()"); - _vm->graphics()->textSet(0, 142, "Set GAMESTATE"); - _vm->logic()->update(); - int slot, value; - _digitTextCount = 0; - if (_vm->input()->waitForNumber(slot, digitKeyPressed, this)) { - _vm->graphics()->textClear(0, 199); - _vm->graphics()->textSet(0, 142, "to"); - _vm->logic()->update(); - _digitTextCount = 0; - if (_vm->input()->waitForNumber(value, digitKeyPressed, this)) { - _vm->logic()->gameState(slot, value); - } - } +bool Debugger::Cmd_GameState(int argc, const char **argv) { + + uint16 slot; + switch (argc) { + case 2: + slot = atoi(argv[1]); + DebugPrintf("GAMESTATE[%d] ", slot); + DebugPrintf("is %d\n", _vm->logic()->gameState(slot)); + break; + case 3: + slot = atoi(argv[1]); + DebugPrintf("GAMESTATE[%d] ", slot); + DebugPrintf("was %d ", _vm->logic()->gameState(slot)); + _vm->logic()->gameState(slot, atoi(argv[2])); + DebugPrintf("now %d\n", _vm->logic()->gameState(slot)); + break; + default: + DebugPrintf("Usage: %s slotnum value\n", argv[0]); + break; + } + return true; } -void Debug::printGameState() { - - debug(9, "Debug::printGameState()"); - _vm->graphics()->textSet(0, 142, "Show GAMESTATE"); - _vm->logic()->update(); - int slot; - _digitTextCount = 0; - if (_vm->input()->waitForNumber(slot, digitKeyPressed, this)) { - _vm->graphics()->textClear(0, 199); - char buf[50]; - snprintf(buf, sizeof(buf), "Currently - %d", _vm->logic()->gameState(slot)); - _vm->graphics()->textSet(0, 142, buf); - _vm->logic()->update(); - char c; - _vm->input()->waitForCharacter(c); - } +bool Debugger::Cmd_Info(int argc, const char **argv) { + + DebugPrintf("Version: %s\n", _vm->resource()->JASVersion()); + DebugPrintf("Room number: %d\n", _vm->logic()->currentRoom()); + DebugPrintf("Room name: %s\n", _vm->logic()->roomName(_vm->logic()->currentRoom())); + return true; } -void Debug::giveAllItems() { - - debug(9, "Debug::giveAllItems()"); +bool Debugger::Cmd_Items(int argc, const char **argv) { + int n = _vm->logic()->itemDataCount(); ItemData *item = _vm->logic()->itemData(1); while (n--) { item->name = ABS(item->name); ++item; } + DebugPrintf("Enabled all inventory items\n"); + return true; } -void Debug::digitKeyPressed(void *refCon, int key) { - - Debug *debug = (Debug *)refCon; - if(key != -1 && debug->_digitTextCount < sizeof(debug->_digitText) - 1) { - debug->_digitText[debug->_digitTextCount] = (char)key; - ++debug->_digitTextCount; - } - else if (debug->_digitTextCount > 0) { - --debug->_digitTextCount; +bool Debugger::Cmd_Room(int argc, const char **argv) { + + if (argc == 2) { + uint16 roomNum = atoi(argv[1]); + _vm->logic()->joeX(0); + _vm->logic()->joeY(0); + _vm->logic()->newRoom(roomNum); + _vm->logic()->entryObj(_vm->logic()->roomData(roomNum) + 1); + DebugPrintf("Changing from room %d to %d\n", _vm->logic()->currentRoom(), roomNum); + } else { + DebugPrintf("Usage: %s roomnum\n", argv[0]); } - debug->_digitText[debug->_digitTextCount] = '\0'; - debug->_vm->graphics()->textSet(0, 151, debug->_digitText); - debug->_vm->logic()->update(); + return true; } -} +} // End of namespace Queen diff --git a/queen/debug.h b/queen/debug.h index 25cf02529d..6dd0f71cbb 100644 --- a/queen/debug.h +++ b/queen/debug.h @@ -22,57 +22,38 @@ #ifndef QUEENDEBUG_H #define QUEENDEBUG_H -#include "common/util.h" +#include "common/debugger.h" namespace Queen { class QueenEngine; -class Debug { +class Debugger : public Common::Debugger<Debugger> { public: - typedef void (Debug::*DebugFunc)(); - Debug(QueenEngine *vm); + Debugger(QueenEngine *vm); - void registerStub(const char *password, DebugFunc debugFunc); + bool _drawAreas; - void update(int c); +protected: - void jumpToRoom(); - void toggleFastMode(); - void printInfo(); - void toggleAreasDrawing(); - void changeGameState(); - void printGameState(); - void giveAllItems(); - - static void digitKeyPressed(void *refCon, int key); - - struct DebugStub { - const char *password; - DebugFunc function; - }; - - enum { - MAX_STUB = 5 - }; + virtual void preEnter(); + virtual void postEnter(); + bool Cmd_Exit(int argc, const char **argv); + bool Cmd_Help(int argc, const char **argv); + bool Cmd_Areas(int argc, const char **argv); + bool Cmd_Asm(int argc, const char **argv); + bool Cmd_GameState(int argc, const char **argv); + bool Cmd_Info(int argc, const char **argv); + bool Cmd_Items(int argc, const char **argv); + bool Cmd_Room(int argc, const char **argv); private: - char _password[16]; - uint _passwordCharCount; - - char _digitText[50]; - uint _digitTextCount; - - DebugStub _stub[MAX_STUB]; - uint _stubCount; - QueenEngine *_vm; }; - } // End of namespace Queen #endif diff --git a/queen/input.cpp b/queen/input.cpp index d8b35e37af..cf964dd3ad 100644 --- a/queen/input.cpp +++ b/queen/input.cpp @@ -36,7 +36,7 @@ const char* Input::_commandKeys[LANGUAGE_COUNT] = { Input::Input(Language language, OSystem *system) : _system(system), _fastMode(false), _keyVerb(VERB_NONE), _cutawayRunning(false), _cutawayQuit(false), _talkQuit(false), - _quickSave(false), _quickLoad(false), + _quickSave(false), _quickLoad(false), _debugger(false), _inKey(0), _mouse_x(0), _mouse_y(0), _mouseButton(0) { switch (language) { @@ -83,7 +83,17 @@ void Input::delay(uint amount) { event.kbd.keycode, isprint(event.kbd.keycode) ? event.kbd.keycode : '.'); - _inKey = event.kbd.keycode; + if (event.kbd.flags == OSystem::KBD_CTRL) { + if (event.kbd.keycode == 'd') { + _debugger = true; + } + else if (event.kbd.keycode == 'f') { + _fastMode = !_fastMode; + } + } + else { + _inKey = event.kbd.keycode; + } break; case OSystem::EVENT_MOUSEMOVE: @@ -219,43 +229,5 @@ int Input::checkKeys() { } -bool Input::waitForNumber(int &i, keyPressedCallback callback, void *refCon) { - - i = 0; - int key = 0; - do { - delay(DELAY_SHORT); - key = _inKey; - _inKey = 0; - if (key >= '0' && key <= '9') { - i = i * 10 + key - '0'; - (*callback)(refCon, key); - } - else if (key == KEY_BACKSPACE) { - i /= 10; - (*callback)(refCon, -1); - } - } while (key != KEY_ESCAPE && key != KEY_RETURN); - return key != KEY_ESCAPE; -} - - -bool Input::waitForCharacter(char &c) { - - int key = 0; - do { - delay(DELAY_SHORT); - if (_inKey >= 'a' && _inKey <= 'z' || _inKey == KEY_ESCAPE) { - key = _inKey; - if (_inKey != KEY_ESCAPE) { - c = (char)_inKey; - } - } - _inKey = 0; - } while (key == 0); - return key != KEY_ESCAPE; -} - - } // End of namespace Queen diff --git a/queen/input.h b/queen/input.h index 439ca10a37..5936efd11c 100644 --- a/queen/input.h +++ b/queen/input.h @@ -31,8 +31,6 @@ class Input { public: - typedef void (*keyPressedCallback)(void *refCon, int key); - //! Adjust here to change delays! enum { DELAY_SHORT = 10, @@ -75,6 +73,8 @@ class Input { void quickSaveReset() { _quickSave = false; } bool quickLoad() const { return _quickLoad; } void quickLoadReset() { _quickLoad = false; } + bool debugger() const { return _debugger; } + void debuggerReset() { _debugger = false; } bool fastMode() const { return _fastMode; } void fastMode(bool fm) { _fastMode = fm; } @@ -87,9 +87,6 @@ class Input { int mouseButton() const { return _mouseButton; } void clearMouseButton() { _mouseButton = 0; } - bool waitForNumber(int &i, keyPressedCallback callback, void *refCon); - bool waitForCharacter(char &c); - private: enum KeyCode { @@ -146,6 +143,9 @@ class Input { //! Set if quickload requested bool _quickLoad; + //! Set if debugger requested + bool _debugger; + //! Set by delay(); int _inKey; @@ -156,10 +156,10 @@ class Input { int _mouseButton; //! Command keys for current language - const char* _currentCommandKeys; + const char *_currentCommandKeys; //! Command keys for all languages - static const char* _commandKeys[LANGUAGE_COUNT]; + static const char *_commandKeys[LANGUAGE_COUNT]; }; } // End of namespace Queen diff --git a/queen/logic.cpp b/queen/logic.cpp index 12352a08cf..9fa31bc03d 100644 --- a/queen/logic.cpp +++ b/queen/logic.cpp @@ -25,8 +25,8 @@ #include "common/config-manager.h" #include "queen/command.h" #include "queen/cutaway.h" -#include "queen/defs.h" #include "queen/debug.h" +#include "queen/defs.h" #include "queen/display.h" #include "queen/graphics.h" #include "queen/input.h" @@ -45,15 +45,11 @@ Logic::Logic(QueenEngine *vm) : _vm(vm) { _joe.x = _joe.y = 0; _joe.scale = 100; - _dbg = new Debug(vm); memset(_gameState, 0, sizeof(_gameState)); memset(_talkSelected, 0, sizeof(_talkSelected)); initialise(); } -Logic::~Logic() { - delete _dbg; -} void Logic::initialise() { @@ -2226,23 +2222,43 @@ void Logic::handlePinnacleRoom() { void Logic::update() { + + if (_vm->debugger()->isAttached()) { + _vm->debugger()->onFrame(); + } + _vm->graphics()->update(_currentRoom); + _vm->input()->delay(); + _vm->display()->palCustomScroll(_currentRoom); + if (_vm->debugger()->_drawAreas) { + for(int i = 1; i < MAX_ZONES_NUMBER; ++i) { + const ZoneSlot *pzs = &_zones[ZONE_ROOM][i]; + if (pzs->valid) { + const Box *b = &pzs->box; + _vm->display()->drawBox(b->x1, b->y1, b->x2, b->y2, 3); + } + } + } BobSlot *joe = _vm->graphics()->bob(0); _vm->display()->update(joe->active, joe->x, joe->y); - _dbg->update(_vm->input()->checkKeys()); - - if (_vm->input()->quickSave()) - if (!_vm->input()->cutawayRunning()) { + + _vm->input()->checkKeys(); + if (_vm->input()->debugger()) { + _vm->input()->debuggerReset(); + _vm->debugger()->attach(); + } + if (!_vm->input()->cutawayRunning()) { + if (_vm->input()->quickSave()) { _vm->input()->quickSaveReset(); gameSave(0, "Quicksave"); } - if (_vm->input()->quickLoad()) - if (!_vm->input()->cutawayRunning()) { + if (_vm->input()->quickLoad()) { _vm->input()->quickLoadReset(); gameLoad(0); } + } } bool Logic::gameSave(uint16 slot, const char *desc) { diff --git a/queen/logic.h b/queen/logic.h index 5a1926ae22..d82881aba1 100644 --- a/queen/logic.h +++ b/queen/logic.h @@ -52,14 +52,12 @@ struct ZoneSlot { Box box; }; -class Debug; class QueenEngine; class Logic { public: Logic(QueenEngine *vm); - ~Logic(); uint16 currentRoom() const { return _currentRoom; } void currentRoom(uint16 room) { @@ -425,7 +423,6 @@ protected: bool _subtitles; - Debug *_dbg; QueenEngine *_vm; }; diff --git a/queen/queen.cpp b/queen/queen.cpp index 160b7fd92b..07675f4795 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -33,6 +33,7 @@ #include "queen/queen.h" #include "queen/command.h" #include "queen/cutaway.h" +#include "queen/debug.h" #include "queen/display.h" #include "queen/graphics.h" #include "queen/input.h" @@ -105,6 +106,7 @@ QueenEngine::~QueenEngine() { delete _bam; delete _resource; delete _command; + delete _debugger; delete _display; delete _graphics; delete _input; @@ -163,6 +165,7 @@ void QueenEngine::initialise(void) { _bam = new BamScene(this); _resource = new Resource(_gameDataPath, _system->get_savefile_manager(), getSavePath()); _command = new Command(this); + _debugger = new Debugger(this); _display = new Display(this, _resource->getLanguage(), _system); _graphics = new Graphics(this); _input = new Input(_resource->getLanguage(), _system); diff --git a/queen/queen.h b/queen/queen.h index 4cc9cb3fde..3aae2482c2 100644 --- a/queen/queen.h +++ b/queen/queen.h @@ -30,6 +30,7 @@ namespace Queen { class BamScene; class Command; +class Debugger; class Display; class Graphics; class Input; @@ -47,6 +48,7 @@ public: BamScene *bam() const { return _bam; } Command *command() const { return _command; } + Debugger *debugger() const { return _debugger; } Display *display() const { return _display; } Graphics *graphics() const { return _graphics; } Input *input() const { return _input; } @@ -71,6 +73,7 @@ protected: BamScene *_bam; Command *_command; + Debugger *_debugger; Display *_display; Graphics *_graphics; Input *_input; |