diff options
author | Paul Gilbert | 2015-03-15 18:42:24 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-03-15 18:42:24 -0400 |
commit | 1452c18ffb21da0d97725c7c982b25992bd75fe8 (patch) | |
tree | b4fdedcb4601acd01b588523295495e7aa2b2820 | |
parent | a6db2fb281fb5842be2d8fc0621922e70ad9668c (diff) | |
download | scummvm-rg350-1452c18ffb21da0d97725c7c982b25992bd75fe8.tar.gz scummvm-rg350-1452c18ffb21da0d97725c7c982b25992bd75fe8.tar.bz2 scummvm-rg350-1452c18ffb21da0d97725c7c982b25992bd75fe8.zip |
SHERLOCK: Added events manager and debugger classes
-rw-r--r-- | engines/sherlock/debugger.cpp | 59 | ||||
-rw-r--r-- | engines/sherlock/debugger.h | 45 | ||||
-rw-r--r-- | engines/sherlock/events.cpp | 167 | ||||
-rw-r--r-- | engines/sherlock/events.h | 82 | ||||
-rw-r--r-- | engines/sherlock/graphics.cpp | 4 | ||||
-rw-r--r-- | engines/sherlock/graphics.h | 1 | ||||
-rw-r--r-- | engines/sherlock/module.mk | 2 | ||||
-rw-r--r-- | engines/sherlock/scalpel/scalpel.cpp | 9 | ||||
-rw-r--r-- | engines/sherlock/scalpel/scalpel.h | 2 | ||||
-rw-r--r-- | engines/sherlock/sherlock.cpp | 7 | ||||
-rw-r--r-- | engines/sherlock/sherlock.h | 4 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo.cpp | 4 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo.h | 2 |
13 files changed, 386 insertions, 2 deletions
diff --git a/engines/sherlock/debugger.cpp b/engines/sherlock/debugger.cpp new file mode 100644 index 0000000000..50300322ef --- /dev/null +++ b/engines/sherlock/debugger.cpp @@ -0,0 +1,59 @@ +/* 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 "sherlock/debugger.h" +#include "sherlock/sherlock.h" + +namespace Sherlock { + +Debugger::Debugger(SherlockEngine *vm) : GUI::Debugger(), _vm(vm) { + registerCmd("continue", WRAP_METHOD(Debugger, cmdExit)); + registerCmd("scene", WRAP_METHOD(Debugger, cmd_scene)); +} + +static int strToInt(const char *s) { + if (!*s) + // No string at all + return 0; + else if (toupper(s[strlen(s) - 1]) != 'H') + // Standard decimal string + return atoi(s); + + // Hexadecimal string + uint tmp = 0; + int read = sscanf(s, "%xh", &tmp); + if (read < 1) + error("strToInt failed on string \"%s\"", s); + return (int)tmp; +} + +bool Debugger::cmd_scene(int argc, const char **argv) { + if (argc != 2) { + debugPrintf("Format: scene <room>\n"); + return true; + } else { + _vm->_rooms->_goToRoom = strToInt(argv[1]); + return false; + } +} + +} // End of namespace Sherlock diff --git a/engines/sherlock/debugger.h b/engines/sherlock/debugger.h new file mode 100644 index 0000000000..8c7291c9e6 --- /dev/null +++ b/engines/sherlock/debugger.h @@ -0,0 +1,45 @@ +/* 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 SHERLOCK_DEBUGGER_H +#define SHERLOCK_DEBUGGER_H + +#include "common/scummsys.h" +#include "gui/debugger.h" + +namespace Sherlock { + +class SherlockEngine; + +class Debugger : public GUI::Debugger { +private: + SherlockEngine *_vm; +protected: + bool cmd_scene(int argc, const char **argv); +public: + Debugger(SherlockEngine *vm); + virtual ~Debugger() {} +}; + +} // End of namespace Sherlock + +#endif /* SHERLOCK_DEBUGGER_H */ diff --git a/engines/sherlock/events.cpp b/engines/sherlock/events.cpp new file mode 100644 index 0000000000..7e62dc075b --- /dev/null +++ b/engines/sherlock/events.cpp @@ -0,0 +1,167 @@ +/* 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 "common/scummsys.h" +#include "common/events.h" +#include "common/system.h" +#include "engines/util.h" +#include "graphics/cursorman.h" +#include "sherlock/sherlock.h" +#include "sherlock/events.h" + +namespace Sherlock { + +EventsManager::EventsManager(SherlockEngine *vm) { + _vm = vm; + _cursorId = CURSOR_NONE; + _frameCounter = 1; + _priorFrameTime = 0; + _mouseClicked = false; + _mouseButtons = 0; +} + +EventsManager::~EventsManager() { +} + +/** + * Set the cursor to show + */ +void EventsManager::setCursor(CursorType cursorId) { + _cursorId = cursorId; + + // TODO: Cursor handling +} + +/** + * Show the mouse cursor + */ +void EventsManager::showCursor() { + CursorMan.showMouse(true); +} + +/** + * Hide the mouse cursor + */ +void EventsManager::hideCursor() { + CursorMan.showMouse(false); +} + +/** + * Returns true if the mouse cursor is visible + */ +bool EventsManager::isCursorVisible() { + return CursorMan.isVisible(); +} + +void EventsManager::pollEvents() { + checkForNextFrameCounter(); + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) { + // Handle keypress + switch (event.type) { + case Common::EVENT_QUIT: + case Common::EVENT_RTL: + return; + + case Common::EVENT_KEYDOWN: + // Check for debugger + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) { + // Attach to the debugger + _vm->_debugger->attach(); + _vm->_debugger->onFrame(); + } else { + _pendingKeys.push(event.kbd); + } + return; + case Common::EVENT_KEYUP: + return; + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_RBUTTONDOWN: + _mouseClicked = true; + return; + case Common::EVENT_LBUTTONUP: + case Common::EVENT_RBUTTONUP: + _mouseClicked = false; + return; + case Common::EVENT_MOUSEMOVE: + _mousePos = event.mouse; + break; + default: + break; + } + } +} + +bool EventsManager::checkForNextFrameCounter() { + // Check for next game frame + uint32 milli = g_system->getMillis(); + if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) { + ++_frameCounter; + _priorFrameTime = milli; + + // Give time to the debugger + _vm->_debugger->onFrame(); + + // Display the frame + _vm->_screen->update(); + + // Signal the ScummVM debugger + _vm->_debugger->onFrame(); + + return true; + } + + return false; +} + +void EventsManager::delay(int cycles) { + uint32 totalMilli = cycles * 1000 / GAME_FRAME_RATE; + uint32 delayEnd = g_system->getMillis() + totalMilli; + + while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) { + g_system->delayMillis(10); + + pollEvents(); + } +} + +void EventsManager::waitForNextFrame() { + _mouseClicked = false; + _mouseButtons = 0; + + bool mouseClicked = false; + int mouseButtons = 0; + + uint32 frameCtr = getFrameCounter(); + while (!_vm->shouldQuit() && frameCtr == _frameCounter) { + delay(1); + + mouseClicked |= _mouseClicked; + mouseButtons |= _mouseButtons; + } + + _mouseClicked = mouseClicked; + _mouseButtons = mouseButtons; +} + +} // End of namespace MADS diff --git a/engines/sherlock/events.h b/engines/sherlock/events.h new file mode 100644 index 0000000000..4ba30e0bdf --- /dev/null +++ b/engines/sherlock/events.h @@ -0,0 +1,82 @@ +/* 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 SHERLOCK_EVENTS_H +#define SHERLOCK_EVENTS_H + +#include "common/scummsys.h" +#include "common/events.h" +#include "common/stack.h" + +namespace Sherlock { + +enum CursorType { CURSOR_NONE = 0 }; + +#define GAME_FRAME_RATE 50 +#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE) + +class SherlockEngine; + +class EventsManager { +private: + SherlockEngine *_vm; + uint32 _frameCounter; + uint32 _priorFrameTime; + Common::Point _mousePos; + + bool checkForNextFrameCounter(); +public: + CursorType _cursorId; + byte _mouseButtons; + bool _mouseClicked; + Common::Stack<Common::KeyState> _pendingKeys; +public: + EventsManager(SherlockEngine *vm); + ~EventsManager(); + + void setCursor(CursorType cursorId); + + void showCursor(); + + void hideCursor(); + + bool isCursorVisible(); + + void pollEvents(); + + Common::Point mousePos() const { return _mousePos; } + + uint32 getFrameCounter() const { return _frameCounter; } + + bool isKeyPressed() const { return !_pendingKeys.empty(); } + + Common::KeyState getKey() { return _pendingKeys.pop(); } + + void delay(int amount); + + void waitForNextFrame(); + +}; + +} // End of namespace Sherlock + +#endif /* SHERLOCK_EVENTS_H */ diff --git a/engines/sherlock/graphics.cpp b/engines/sherlock/graphics.cpp index 695635d2ca..5c6c94606e 100644 --- a/engines/sherlock/graphics.cpp +++ b/engines/sherlock/graphics.cpp @@ -45,7 +45,9 @@ void Surface::drawSprite(int x, int y, SpriteFrame *spriteFrame, bool flipped, b /*----------------------------------------------------------------*/ -Screen::Screen(SherlockEngine *vm) : Surface(SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT), _vm(vm) { +Screen::Screen(SherlockEngine *vm) : Surface(SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT), _vm(vm), + _backBuffer1(SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT), + _backBuffer2(SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT) { setFont(1); } diff --git a/engines/sherlock/graphics.h b/engines/sherlock/graphics.h index fe03e7155d..801b1747ee 100644 --- a/engines/sherlock/graphics.h +++ b/engines/sherlock/graphics.h @@ -44,6 +44,7 @@ class Screen : public Surface { private: SherlockEngine *_vm; int _fontNumber; + Surface _backBuffer1, _backBuffer2; public: Screen(SherlockEngine *vm); diff --git a/engines/sherlock/module.mk b/engines/sherlock/module.mk index 1dfcb3a5af..19ad039262 100644 --- a/engines/sherlock/module.mk +++ b/engines/sherlock/module.mk @@ -4,7 +4,9 @@ MODULE_OBJS = \ scalpel/scalpel.o \ tattoo/tattoo.o \ decompress.o \ + debugger.o \ detection.o \ + events.o \ graphics.o \ journal.o \ resources.o \ diff --git a/engines/sherlock/scalpel/scalpel.cpp b/engines/sherlock/scalpel/scalpel.cpp index bd8c96f253..1eaf7c91ee 100644 --- a/engines/sherlock/scalpel/scalpel.cpp +++ b/engines/sherlock/scalpel/scalpel.cpp @@ -30,6 +30,8 @@ namespace Scalpel { * Game initialization */ void ScalpelEngine::initialize() { + SherlockEngine::initialize(); + _flags.resize(100 * 8); _flags[3] = true; // Turn on Alley _flags[39] = true; // Turn on Baker Street @@ -38,6 +40,13 @@ void ScalpelEngine::initialize() { _rooms->_goToRoom = 4; } +/** + * Show the opening sequence + */ +void ScalpelEngine::showOpening() { + // TODO +} + } // End of namespace Scalpel diff --git a/engines/sherlock/scalpel/scalpel.h b/engines/sherlock/scalpel/scalpel.h index 9001c20456..6016984e45 100644 --- a/engines/sherlock/scalpel/scalpel.h +++ b/engines/sherlock/scalpel/scalpel.h @@ -32,6 +32,8 @@ namespace Scalpel { class ScalpelEngine : public SherlockEngine { protected: virtual void initialize(); + + virtual void showOpening(); public: ScalpelEngine(OSystem *syst, const SherlockGameDescription *gameDesc) : SherlockEngine(syst, gameDesc) {} diff --git a/engines/sherlock/sherlock.cpp b/engines/sherlock/sherlock.cpp index 13731e2fd8..cfbbacccf7 100644 --- a/engines/sherlock/sherlock.cpp +++ b/engines/sherlock/sherlock.cpp @@ -30,6 +30,7 @@ namespace Sherlock { SherlockEngine::SherlockEngine(OSystem *syst, const SherlockGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { + _debugger = nullptr; _journal = nullptr; _res = nullptr; _rooms = nullptr; @@ -39,6 +40,7 @@ SherlockEngine::SherlockEngine(OSystem *syst, const SherlockGameDescription *gam SherlockEngine::~SherlockEngine() { + delete _debugger; delete _journal; delete _res; delete _rooms; @@ -64,6 +66,7 @@ void SherlockEngine::initialize() { _midi->setNativeMT32(native_mt32); */ + _debugger = new Debugger(this); _journal = new Journal(); _res = new Resources(); _rooms = new Rooms(); @@ -74,7 +77,9 @@ void SherlockEngine::initialize() { Common::Error SherlockEngine::run() { initialize(); - // TODO: The rest of the game + showOpening(); + + // TODO: Rest of game return Common::kNoError; } diff --git a/engines/sherlock/sherlock.h b/engines/sherlock/sherlock.h index 172c940c34..781851db71 100644 --- a/engines/sherlock/sherlock.h +++ b/engines/sherlock/sherlock.h @@ -30,6 +30,7 @@ #include "common/savefile.h" #include "common/hash-str.h" #include "engines/engine.h" +#include "sherlock/debugger.h" #include "sherlock/graphics.h" #include "sherlock/journal.h" #include "sherlock/resources.h" @@ -62,8 +63,11 @@ class SherlockEngine : public Engine { private: protected: virtual void initialize(); + + virtual void showOpening() = 0; public: const SherlockGameDescription *_gameDescription; + Debugger *_debugger; Journal *_journal; Resources *_res; Rooms *_rooms; diff --git a/engines/sherlock/tattoo/tattoo.cpp b/engines/sherlock/tattoo/tattoo.cpp index 57ca5c6e29..b2b45bc310 100644 --- a/engines/sherlock/tattoo/tattoo.cpp +++ b/engines/sherlock/tattoo/tattoo.cpp @@ -26,6 +26,10 @@ namespace Sherlock { namespace Tattoo { +void TattooEngine::showOpening() { + // TODO +} + } // End of namespace Tattoo } // End of namespace Scalpel diff --git a/engines/sherlock/tattoo/tattoo.h b/engines/sherlock/tattoo/tattoo.h index f06fa1532d..6d3ec33967 100644 --- a/engines/sherlock/tattoo/tattoo.h +++ b/engines/sherlock/tattoo/tattoo.h @@ -30,6 +30,8 @@ namespace Sherlock { namespace Tattoo { class TattooEngine : public SherlockEngine { +protected: + virtual void showOpening(); public: TattooEngine(OSystem *syst, const SherlockGameDescription *gameDesc) : SherlockEngine(syst, gameDesc) {} |