From 384715da8448c303785072820329432461991deb Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 14 Aug 2019 20:29:56 +0300 Subject: STARTREK: Add a console This also fixes an uninitialized pointer crash (_mapFile) --- engines/startrek/console.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++ engines/startrek/console.h | 44 +++++++++++++++++++++++++++++++++++++ engines/startrek/events.cpp | 4 ++++ engines/startrek/graphics.cpp | 2 ++ engines/startrek/module.mk | 1 + engines/startrek/startrek.cpp | 5 +++++ engines/startrek/startrek.h | 2 ++ 7 files changed, 109 insertions(+) create mode 100644 engines/startrek/console.cpp create mode 100644 engines/startrek/console.h (limited to 'engines/startrek') diff --git a/engines/startrek/console.cpp b/engines/startrek/console.cpp new file mode 100644 index 0000000000..5e6108efa6 --- /dev/null +++ b/engines/startrek/console.cpp @@ -0,0 +1,51 @@ +/* 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 "startrek/console.h" +#include "gui/debugger.h" +#include "startrek/startrek.h" + +namespace StarTrek { + +Console::Console(StarTrekEngine *vm) : GUI::Debugger(), _vm(vm) { + registerCmd("room", WRAP_METHOD(Console, Cmd_Room)); +} + +Console::~Console() { +} + +bool Console::Cmd_Room(int argc, const char **argv) { + if (argc < 3) { + debugPrintf("Current room: %s%d\n", _vm->_missionToLoad.c_str(), _vm->_roomIndexToLoad); + debugPrintf("Use room to teleport\n"); + debugPrintf("Valid missions are: DEMON, TUG, LOVE, MUDD, FEATHER, TRIAL, SINS, VENG"); + return true; + } + + _vm->_missionToLoad = argv[1]; + _vm->_roomIndexToLoad = atoi(argv[2]); + _vm->runAwayMission(); + + return false; +} + +} // End of namespace StarTrek diff --git a/engines/startrek/console.h b/engines/startrek/console.h new file mode 100644 index 0000000000..1d1b6e72fc --- /dev/null +++ b/engines/startrek/console.h @@ -0,0 +1,44 @@ +/* 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 STARTREK_CONSOLE_H +#define STARTREK_CONSOLE_H + +#include "gui/debugger.h" + +namespace StarTrek { + +class StarTrekEngine; + +class Console : public GUI::Debugger { +public: + Console(StarTrekEngine *vm); + virtual ~Console(void); + +private: + StarTrekEngine *_vm; + + bool Cmd_Room(int argc, const char **argv); +}; + +} // End of namespace StarTrek +#endif diff --git a/engines/startrek/events.cpp b/engines/startrek/events.cpp index d8935bd432..c425b09050 100644 --- a/engines/startrek/events.cpp +++ b/engines/startrek/events.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "startrek/console.h" #include "startrek/startrek.h" namespace StarTrek { @@ -61,6 +62,9 @@ void StarTrekEngine::pollEvents(bool queueEvents) { break; case Common::EVENT_KEYDOWN: + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) + _console->attach(); + if (queueEvents) { trekEvent.type = TREKEVENT_KEYDOWN; addEventToQueue(trekEvent); diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp index 02e778c2dc..f56d7d3707 100644 --- a/engines/startrek/graphics.cpp +++ b/engines/startrek/graphics.cpp @@ -20,6 +20,7 @@ */ #include "startrek/common.h" +#include "startrek/console.h" #include "startrek/graphics.h" #include "common/algorithm.h" @@ -639,6 +640,7 @@ void Graphics::updateScreen() { _mouseWarpY = -1; } + _vm->_console->onFrame(); _vm->_system->updateScreen(); _vm->_system->delayMillis(10); } diff --git a/engines/startrek/module.mk b/engines/startrek/module.mk index e8012b572d..cc4b32a5fc 100644 --- a/engines/startrek/module.mk +++ b/engines/startrek/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS = \ awaymission.o \ bitmap.o \ common.o \ + console.o \ detection.o \ events.o \ font.o \ diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index b01749525e..123fc74cf5 100644 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -37,6 +37,7 @@ #include "engines/util.h" #include "video/qt_decoder.h" +#include "startrek/console.h" #include "startrek/iwfile.h" #include "startrek/lzss.h" #include "startrek/room.h" @@ -94,6 +95,7 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam _missionToLoad = "DEMON"; _roomIndexToLoad = 0; + _mapFile = nullptr; _showSubtitles = true; Common::fill(_r3List, _r3List + NUM_SPACE_OBJECTS, (R3 *)nullptr); @@ -106,6 +108,8 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam StarTrekEngine::~StarTrekEngine() { delete _activeMenu->nextMenu; delete _activeMenu; + + delete _console; delete _gfx; delete _sound; delete _macResFork; @@ -114,6 +118,7 @@ StarTrekEngine::~StarTrekEngine() { Common::Error StarTrekEngine::run() { _gfx = new Graphics(this); _sound = new Sound(this); + _console = new Console(this); if (getPlatform() == Common::kPlatformMacintosh) { _macResFork = new Common::MacResManager(); diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h index fadf295107..5f4dc61801 100644 --- a/engines/startrek/startrek.h +++ b/engines/startrek/startrek.h @@ -60,6 +60,7 @@ namespace StarTrek { class StarTrekEngine; class Room; +class Console; typedef String(StarTrekEngine::*TextGetterFunc)(int, uintptr, String *); // FIXME: Eventually get rid of Common::SharedPtr and dispose of file streams properly @@ -775,6 +776,7 @@ public: Graphics *_gfx; Sound *_sound; + Console *_console; SharedPtr _iwFile; private: -- cgit v1.2.3