diff options
| author | Paul Gilbert | 2016-03-18 20:04:54 -0400 |
|---|---|---|
| committer | Paul Gilbert | 2016-03-18 20:04:54 -0400 |
| commit | 61947ef56b77ab4778adafde93388fb526911eb7 (patch) | |
| tree | dde8c61d4ad301a20da46622c6238ee32a3291b8 | |
| parent | 8b9f3dc0b8929d920cb101a06cef8ba14fee59f0 (diff) | |
| download | scummvm-rg350-61947ef56b77ab4778adafde93388fb526911eb7.tar.gz scummvm-rg350-61947ef56b77ab4778adafde93388fb526911eb7.tar.bz2 scummvm-rg350-61947ef56b77ab4778adafde93388fb526911eb7.zip | |
TITANIC: Create Event manager class
| -rw-r--r-- | engines/titanic/events.cpp | 88 | ||||
| -rw-r--r-- | engines/titanic/events.h | 74 | ||||
| -rw-r--r-- | engines/titanic/game/bomb.cpp | 2 | ||||
| -rw-r--r-- | engines/titanic/module.mk | 1 | ||||
| -rw-r--r-- | engines/titanic/string.cpp | 2 | ||||
| -rw-r--r-- | engines/titanic/titanic.cpp | 30 | ||||
| -rw-r--r-- | engines/titanic/titanic.h | 9 |
7 files changed, 172 insertions, 34 deletions
diff --git a/engines/titanic/events.cpp b/engines/titanic/events.cpp new file mode 100644 index 0000000000..c9e4e5dc98 --- /dev/null +++ b/engines/titanic/events.cpp @@ -0,0 +1,88 @@ +/* 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 "titanic/events.h" +#include "titanic/titanic.h" + +namespace Titanic { + +Events::Events(TitanicEngine *vm): _vm(vm), + _frameCounter(1), _priorFrameTime(0) { +} + +void Events::pollEvents() { + checkForNextFrameCounter(); + + Common::Event event; + g_system->getEventManager()->pollEvent(event); + + // Give time to the debugger + _vm->_debugger->onFrame(); + + switch (event.type) { + case Common::EVENT_KEYDOWN: + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) { + // Attach to the debugger + _vm->_debugger->attach(); + _vm->_debugger->onFrame(); + } + break; + + default: + break; + } +} + +void Events::pollEventsAndWait() { + pollEvents(); + g_system->delayMillis(10); +} + +bool Events::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(); + + return true; + } + + return false; +} + +uint32 Events::getTicksCount() const { + return g_system->getMillis(); +} + + +} // End of namespace Titanic diff --git a/engines/titanic/events.h b/engines/titanic/events.h new file mode 100644 index 0000000000..2de04d44b1 --- /dev/null +++ b/engines/titanic/events.h @@ -0,0 +1,74 @@ +/* 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 TITANIC_EVENTS_H +#define TITANIC_EVENTS_H + +#include "common/scummsys.h" +#include "common/events.h" + +namespace Titanic { + +#define GAME_FRAME_RATE 30 +#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE) + +class TitanicEngine; + +class Events { +private: + TitanicEngine *_vm; + uint32 _frameCounter; + uint32 _priorFrameTime; + + /** + * Check whether it's time to display the next screen frame + */ + bool checkForNextFrameCounter(); +public: + Events(TitanicEngine *vm); + ~Events() {} + + /** + * Check for any pending events + */ + void pollEvents(); + + /** + * Poll for events and introduce a small delay, to allow the system to + * yield to other running programs + */ + void pollEventsAndWait(); + + /** + * Return the current game frame number + */ + uint32 getFrameCounter() const { return _frameCounter; } + + /** + * Get the elapsed playtime + */ + uint32 getTicksCount() const; +}; + +} // End of namespace Titanic + +#endif /* TITANIC_EVENTS_H */ diff --git a/engines/titanic/game/bomb.cpp b/engines/titanic/game/bomb.cpp index 429f254d66..e4cf1b3830 100644 --- a/engines/titanic/game/bomb.cpp +++ b/engines/titanic/game/bomb.cpp @@ -74,7 +74,7 @@ bool CBomb::handleEvent(const CEnterRoomMsg &msg) { _fieldE8 = 12; _fieldEC = 9; _fieldF0 = 0; - _startingTicks = g_vm->_ticksCount; + _startingTicks = g_vm->_events->getTicksCount(); return true; } diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index 0fc6d3b7dd..da194bf00e 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ debugger.o \ detection.o \ direct_draw.o \ + events.o \ files_manager.o \ font.o \ game_location.o \ diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp index ed5379be65..5831b7dc3a 100644 --- a/engines/titanic/string.cpp +++ b/engines/titanic/string.cpp @@ -30,7 +30,7 @@ CString CString::left(uint count) const { } CString CString::right(uint count) const { - int strSize = size(); + uint strSize = size(); return (count > strSize) ? CString() : CString(c_str() + strSize - count, c_str() + strSize); } diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp index e5417c1e7d..f29e776791 100644 --- a/engines/titanic/titanic.cpp +++ b/engines/titanic/titanic.cpp @@ -45,16 +45,17 @@ namespace Titanic { TitanicEngine *g_vm; TitanicEngine::TitanicEngine(OSystem *syst, const TitanicGameDescription *gameDesc) - : _gameDescription(gameDesc), Engine(syst), _randomSource("Titanic"), - _ticksCount(0), _frameCounter(0) { + : _gameDescription(gameDesc), Engine(syst), _randomSource("Titanic") { g_vm = this; _debugger = nullptr; + _events = nullptr; _window = nullptr; _screenManager = nullptr; } TitanicEngine::~TitanicEngine() { delete _debugger; + delete _events; delete _window; delete _screenManager; CSaveableObject::freeClassList(); @@ -83,6 +84,7 @@ void TitanicEngine::initialize() { CEnterExitSecClassMiniLift::init(); _debugger = new Debugger(this); + _events = new Events(this); _screenManager = new OSScreenManager(this); _window = new CMainGameWindow(this); _window->applicationStarting(); @@ -103,33 +105,11 @@ Common::Error TitanicEngine::run() { // Main event loop while (!shouldQuit()) { - processEvents(); - g_system->delayMillis(5); + _events->pollEventsAndWait(); } deinitialize(); return Common::kNoError; } -void TitanicEngine::processEvents() { - Common::Event event; - g_system->getEventManager()->pollEvent(event); - - // Give time to the debugger - _debugger->onFrame(); - - switch (event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) { - // Attach to the debugger - _debugger->attach(); - _debugger->onFrame(); - } - break; - - default: - break; - } -} - } // End of namespace Titanic diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index c2a66fbc03..8ed353f413 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -30,6 +30,7 @@ #include "engines/advancedDetector.h" #include "engines/engine.h" #include "titanic/debugger.h" +#include "titanic/events.h" #include "titanic/files_manager.h" #include "titanic/screen_manager.h" #include "titanic/main_game_window.h" @@ -83,11 +84,6 @@ private: * Handles game deinitialization */ void deinitialize(); - - /** - * Processes pending events - */ - void processEvents(); protected: const TitanicGameDescription *_gameDescription; int _loadSaveSlot; @@ -99,11 +95,10 @@ protected: public: CFilesManager _filesManager; Debugger *_debugger; + Events *_events; OSScreenManager *_screenManager; CMainGameWindow *_window; Common::RandomSource _randomSource; - uint _frameCounter; - uint _ticksCount; public: TitanicEngine(OSystem *syst, const TitanicGameDescription *gameDesc); virtual ~TitanicEngine(); |
