SHERLOCK: Added events manager and debugger classes
This commit is contained in:
parent
a6db2fb281
commit
1452c18ffb
13 changed files with 386 additions and 2 deletions
59
engines/sherlock/debugger.cpp
Normal file
59
engines/sherlock/debugger.cpp
Normal file
|
@ -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
|
45
engines/sherlock/debugger.h
Normal file
45
engines/sherlock/debugger.h
Normal file
|
@ -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 */
|
167
engines/sherlock/events.cpp
Normal file
167
engines/sherlock/events.cpp
Normal file
|
@ -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
|
82
engines/sherlock/events.h
Normal file
82
engines/sherlock/events.h
Normal file
|
@ -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 */
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ class Screen : public Surface {
|
|||
private:
|
||||
SherlockEngine *_vm;
|
||||
int _fontNumber;
|
||||
Surface _backBuffer1, _backBuffer2;
|
||||
public:
|
||||
Screen(SherlockEngine *vm);
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -26,6 +26,10 @@ namespace Sherlock {
|
|||
|
||||
namespace Tattoo {
|
||||
|
||||
void TattooEngine::showOpening() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
} // End of namespace Tattoo
|
||||
|
||||
} // End of namespace Scalpel
|
||||
|
|
|
@ -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) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue