From b541e3507e2012eb674fbadf6322b335d0823053 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 3 Sep 2011 17:33:14 +0200 Subject: [PATCH] MYST3: Added a simple debugging console --- engines/myst3/console.cpp | 89 +++++++++++++++++++++++++++++ engines/myst3/console.h | 47 +++++++++++++++ engines/myst3/directorysubentry.cpp | 5 +- engines/myst3/module.mk | 1 + engines/myst3/myst3.cpp | 2 +- engines/myst3/myst3.h | 9 ++- engines/myst3/scene.cpp | 13 ++++- engines/myst3/scene.h | 4 ++ engines/myst3/script.cpp | 4 ++ 9 files changed, 164 insertions(+), 10 deletions(-) create mode 100644 engines/myst3/console.cpp create mode 100644 engines/myst3/console.h diff --git a/engines/myst3/console.cpp b/engines/myst3/console.cpp new file mode 100644 index 00000000000..f5885a2fec2 --- /dev/null +++ b/engines/myst3/console.cpp @@ -0,0 +1,89 @@ +/* Residual - A 3D game interpreter + * + * Residual is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#include "engines/myst3/console.h" + +namespace Myst3 { + +Console::Console(Myst3Engine *vm) : GUI::Debugger(), _vm(vm) { + DCmd_Register("infos", WRAP_METHOD(Console, Cmd_Infos)); + DCmd_Register("lookAt", WRAP_METHOD(Console, Cmd_LookAt)); +} + +Console::~Console() { +} + +bool Console::Cmd_Infos(int argc, const char **argv) { + + uint16 nodeId = _vm->_node.getId(); + NodePtr nodeData = _vm->_db->getNodeData(nodeId); + + char roomName[8]; + _vm->_db->getRoomName(roomName); + + Common::Point lookAt = _vm->_scene.getMousePos(); + + DebugPrintf("current node: %s%d ", roomName, nodeId); + DebugPrintf("pitch: %d heading: %d", lookAt.x, lookAt.y); + + for (uint i = 0; i < nodeData->hotspots.size(); i++) { + DebugPrintf("\nhotspot %d > condition: %d\n", + i, nodeData->hotspots[i].condition); + + for(uint j = 0; j < nodeData->hotspots[i].rects.size(); j++) { + PolarRect &rect = nodeData->hotspots[i].rects[j]; + + DebugPrintf(" rect > pitch: %d heading: %d height: %d width: %d\n", + rect.centerPitch, rect.centerHeading, rect.width, rect.height); + } + + for(uint j = 0; j < nodeData->hotspots[i].script.size(); j++) { + Opcode &opcode = nodeData->hotspots[i].script[j]; + + DebugPrintf(" op %d ( ", + opcode.op); + + for(uint k = 0; k < opcode.args.size(); k++) { + DebugPrintf("%d ", opcode.args[k]); + } + + DebugPrintf(")\n"); + } + } + + return true; +} + +bool Console::Cmd_LookAt(int argc, const char **argv) { + + if (argc != 3) { + DebugPrintf("Usage :\n"); + DebugPrintf("lookAt pitch heading\n"); + return true; + } + + _vm->_scene.lookAt(atof(argv[1]), atof(argv[2])); + + return false; +} + +} /* namespace Myst3 */ diff --git a/engines/myst3/console.h b/engines/myst3/console.h new file mode 100644 index 00000000000..206ab9c7f0f --- /dev/null +++ b/engines/myst3/console.h @@ -0,0 +1,47 @@ +/* Residual - A 3D game interpreter + * + * Residual is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#ifndef CONSOLE_H_ +#define CONSOLE_H_ + +#include "gui/debugger.h" + +#include "engines/myst3/myst3.h" + +namespace Myst3 { + +class Myst3Engine; + +class Console : public GUI::Debugger { +public: + Console(Myst3Engine *vm); + virtual ~Console(); + +private: + Myst3Engine *_vm; + + bool Cmd_Infos(int argc, const char **argv); + bool Cmd_LookAt(int argc, const char **argv); +}; + +} /* namespace Myst3 */ +#endif /* CONSOLE_H_ */ diff --git a/engines/myst3/directorysubentry.cpp b/engines/myst3/directorysubentry.cpp index f21c784c245..dc6dcd2e24c 100755 --- a/engines/myst3/directorysubentry.cpp +++ b/engines/myst3/directorysubentry.cpp @@ -18,9 +18,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - * $URL$ - * $Id$ - * */ #include "engines/myst3/directorysubentry.h" @@ -38,7 +35,7 @@ void DirectorySubEntry::readFromStream(Common::SeekableReadStream &inStream) { _face = inStream.readByte(); _type = inStream.readByte(); - dump(); + // dump(); if (_padding == 2) { uint32 _padding2 = inStream.readUint32LE(); diff --git a/engines/myst3/module.mk b/engines/myst3/module.mk index e7ed2c2ffb8..2b3bf9a016f 100755 --- a/engines/myst3/module.mk +++ b/engines/myst3/module.mk @@ -2,6 +2,7 @@ MODULE := engines/myst3 MODULE_OBJS := \ archive.o \ + console.o \ database.o \ detection.o \ directoryentry.o \ diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp index c5b3e3cabed..425282d7b59 100644 --- a/engines/myst3/myst3.cpp +++ b/engines/myst3/myst3.cpp @@ -49,7 +49,7 @@ namespace Myst3 { Myst3Engine::Myst3Engine(OSystem *syst, int gameFlags) : Engine(syst), _system(syst), _scriptEngine(this), _db(0) { - _console = new GUI::Debugger(); + _console = new Console(this); } Myst3Engine::~Myst3Engine() { diff --git a/engines/myst3/myst3.h b/engines/myst3/myst3.h index af091ca1879..a71cb48db96 100644 --- a/engines/myst3/myst3.h +++ b/engines/myst3/myst3.h @@ -28,6 +28,7 @@ #include "common/system.h" #include "engines/myst3/archive.h" +#include "engines/myst3/console.h" #include "engines/myst3/database.h" #include "engines/myst3/node.h" #include "engines/myst3/scene.h" @@ -35,12 +36,14 @@ namespace Myst3 { +class Console; + class Myst3Engine : public Engine { protected: // Engine APIs virtual Common::Error run(); - virtual GUI::Debugger *getDebugger() { return _console; } + virtual GUI::Debugger *getDebugger() { return (GUI::Debugger *)_console; } public: Myst3Engine(OSystem *syst, int gameFlags); @@ -50,13 +53,15 @@ public: private: OSystem *_system; - GUI::Debugger *_console; + Console *_console; Node _node; Scene _scene; Archive _archive; Script _scriptEngine; Database *_db; + + friend class Console; }; } // end of namespace Myst3 diff --git a/engines/myst3/scene.cpp b/engines/myst3/scene.cpp index e29569369c5..690310c33db 100644 --- a/engines/myst3/scene.cpp +++ b/engines/myst3/scene.cpp @@ -27,6 +27,11 @@ namespace Myst3 { +Scene::Scene(): + _cameraPitch(0.0f), _cameraHeading(0.0f) +{ +} + void Scene::init(int width, int height) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -38,9 +43,6 @@ void Scene::init(int width, int height) { glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); - - _cameraPitch = 0.0f; - _cameraHeading = 0.0f; } void Scene::clear() { @@ -69,4 +71,9 @@ void Scene::updateCamera(Common::Point &mouse) { _cameraPitch = CLIP(_cameraPitch, -60.0f, 80.0f); } +void Scene::lookAt(float pitch, float heading) { + _cameraPitch = pitch; + _cameraHeading = heading; +} + } // end of namespace Myst3 diff --git a/engines/myst3/scene.h b/engines/myst3/scene.h index ea3ef970bad..0587c763973 100644 --- a/engines/myst3/scene.h +++ b/engines/myst3/scene.h @@ -44,11 +44,15 @@ class Scene { Common::Point _mouseOld; public: + Scene(); + void init(int width, int height); void clear(); void setupCamera(); void updateCamera(Common::Point &mouse); Common::Point getMousePos() { return Common::Point(_cameraHeading, _cameraPitch); } + + void lookAt(float pitch, float heading); }; } // end of namespace Myst3 diff --git a/engines/myst3/script.cpp b/engines/myst3/script.cpp index bec4db70499..89f9660f3ed 100644 --- a/engines/myst3/script.cpp +++ b/engines/myst3/script.cpp @@ -35,9 +35,13 @@ Script::~Script() { } void Script::run(Common::Array *script) { + debug("Script start %p", (void *) script); + for (uint i = 0; i < script->size(); i++) { runOp(&script->operator[](i)); } + + debug("Script stop %p ", (void *) script); } void Script::runOp(Opcode *op) {