[Scummvm-cvs-logs] CVS: scummvm/queen debug.cpp,1.3,1.4 debug.h,1.3,1.4 input.cpp,1.15,1.16 input.h,1.12,1.13 logic.cpp,1.137,1.138 logic.h,1.91,1.92 queen.cpp,1.59,1.60 queen.h,1.21,1.22

Gregory Montoir cyx at users.sourceforge.net
Fri Dec 26 04:59:01 CET 2003


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv12484/queen

Modified Files:
	debug.cpp debug.h input.cpp input.h logic.cpp logic.h 
	queen.cpp queen.h 
Log Message:
new debugging code, using Common::Debugger

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/debug.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- debug.cpp	11 Dec 2003 22:16:34 -0000	1.3
+++ debug.cpp	26 Dec 2003 12:58:27 -0000	1.4
@@ -30,195 +30,148 @@
 #include "queen/resource.h"
 #include "queen/structs.h"
 
-namespace Queen {
+#include "common/debugger.cpp"
 
-Debug::Debug(QueenEngine *vm)
-	: _passwordCharCount(0), _stubCount(0), _vm(vm) {
+namespace Queen {
 
-	memset(_password, 0, sizeof(_password));
 
-	registerStub("zeroxpark", &Debug::jumpToRoom);
-	registerStub("grimley",   &Debug::printInfo);
-	registerStub("kowamori",  &Debug::toggleFastMode);
+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::registerStub(const char *password, DebugFunc debugFunc) {
-
-	assert(_stubCount < MAX_STUB);
-	_stub[_stubCount].password = password;
-	_stub[_stubCount].function = debugFunc;
-	++_stubCount;
+void Debugger::preEnter() {
+	
+	// XXX mute all sounds
 }
 
 
-void Debug::update(int c) {
+void Debugger::postEnter() {
+	
+	// XXX un-mute all sounds
+	_vm->graphics()->bobSetupControl(); // re-init mouse cursor
+}
 
-	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;
-			}
-		}
-	}
+bool Debugger::Cmd_Exit(int argc, const char **argv) {
+	
+	_detach_now = true;
+	return false;	
 }
 
 
-void Debug::jumpToRoom() {
+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::jumpToRoom()");
+	DebugPrintf("Commands are:\n");
+	for (i = 0 ; i < _dcmd_count ; i++) {
+		size = strlen(_dcmds[i].name) + 1;
 
-	_vm->graphics()->textCurrentColor(INK_JOE);
-	_vm->graphics()->textSet(0, 142, "Enter new room");
-	_vm->logic()->update();
+		if ((width + size) >= 39) {
+			DebugPrintf("\n");
+			width = size;
+		} else
+			width += size;
 
-	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);
+		DebugPrintf("%s ", _dcmds[i].name);
 	}
+	DebugPrintf("\n");
+	return true;
 }
 
 
-void Debug::toggleFastMode() {
-
-	debug(9, "Debug::toggleFastMode()");
-	_vm->input()->fastMode(!_vm->input()->fastMode());
-}
-
-
-void Debug::printInfo() {
-
-	debug(9, "Debug::printInfo()");
-
-	_vm->graphics()->textClear(0, 199);
-	_vm->graphics()->textCurrentColor(INK_JOE);
-
-	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);
-
-	_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

Index: debug.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/debug.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- debug.h	11 Dec 2003 22:16:34 -0000	1.3
+++ debug.h	26 Dec 2003 12:58:27 -0000	1.4
@@ -22,56 +22,37 @@
 #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);
 
-	void registerStub(const char *password, DebugFunc debugFunc);
-
-	void update(int c);
-
-	void jumpToRoom();
-	void toggleFastMode();
-	void printInfo();
-	void toggleAreasDrawing();
-	void changeGameState();
-	void printGameState();
-	void giveAllItems();
+	Debugger(QueenEngine *vm);
 
-	static void digitKeyPressed(void *refCon, int key); 
+	bool _drawAreas;
 
-	struct DebugStub {
-		const char *password;
-		DebugFunc function;
-	};
+protected:
 
-	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
 

Index: input.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/input.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- input.cpp	12 Dec 2003 20:26:20 -0000	1.15
+++ input.cpp	26 Dec 2003 12:58:27 -0000	1.16
@@ -36,7 +36,7 @@
 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 @@
 							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:
@@ -216,44 +226,6 @@
 	int inKey = _inKey;
 	_inKey = 0;	//reset
 	return inKey;
-}
-
-
-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;
 }
 
 

Index: input.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/input.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- input.h	12 Dec 2003 10:33:34 -0000	1.12
+++ input.h	26 Dec 2003 12:58:27 -0000	1.13
@@ -31,8 +31,6 @@
 
 	public:
 
-		typedef void (*keyPressedCallback)(void *refCon, int key);
-
 		//! Adjust here to change delays!
 		enum {
 			DELAY_SHORT  =  10,
@@ -75,6 +73,8 @@
 		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 @@
 		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 @@
 		//! Set if quickload requested
 		bool _quickLoad;
 
+		//! Set if debugger requested
+		bool _debugger;
+
 		//! Set by delay();
 		int _inKey;
 
@@ -156,10 +156,10 @@
 		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

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.137
retrieving revision 1.138
diff -u -d -r1.137 -r1.138
--- logic.cpp	20 Dec 2003 16:54:46 -0000	1.137
+++ logic.cpp	26 Dec 2003 12:58:27 -0000	1.138
@@ -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 @@
 	: _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::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) {

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.h,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- logic.h	20 Dec 2003 16:54:46 -0000	1.91
+++ logic.h	26 Dec 2003 12:58:27 -0000	1.92
@@ -52,14 +52,12 @@
 	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 @@
 
 	bool _subtitles;
 
-	Debug *_dbg;
 	QueenEngine *_vm;
 };
 

Index: queen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- queen.cpp	24 Dec 2003 17:42:19 -0000	1.59
+++ queen.cpp	26 Dec 2003 12:58:27 -0000	1.60
@@ -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 @@
 	delete _bam;
 	delete _resource;
 	delete _command;
+	delete _debugger;
 	delete _display;
 	delete _graphics;
 	delete _input;
@@ -163,6 +165,7 @@
 	_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);

Index: queen.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- queen.h	19 Dec 2003 09:22:20 -0000	1.21
+++ queen.h	26 Dec 2003 12:58:27 -0000	1.22
@@ -30,6 +30,7 @@
 
 class BamScene;
 class Command;
+class Debugger;
 class Display;
 class Graphics;
 class Input;
@@ -47,6 +48,7 @@
 
 	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 @@
 
 	BamScene *_bam;
 	Command *_command;
+	Debugger *_debugger;
 	Display *_display;
 	Graphics *_graphics;
 	Input *_input;





More information about the Scummvm-git-logs mailing list