CHEWY: Added events manager class

This commit is contained in:
Paul Gilbert
2022-03-03 18:34:58 -08:00
parent 81d2f77d63
commit fba13ed0f7
5 changed files with 161 additions and 6 deletions
+4 -6
View File
@@ -24,6 +24,7 @@
#include "common/system.h"
#include "engines/util.h"
#include "chewy/chewy.h"
#include "chewy/events.h"
#include "chewy/main.h"
#include "chewy/resource.h"
#include "chewy/sound.h"
@@ -36,6 +37,7 @@ ChewyEngine::ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc)
: Engine(syst),
_gameDescription(gameDesc),
_rnd("chewy"),
_events(nullptr),
_screen(nullptr),
_sound(nullptr) {
@@ -52,12 +54,14 @@ ChewyEngine::ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc)
}
ChewyEngine::~ChewyEngine() {
delete _events;
delete _screen;
delete _sound;
g_engine = nullptr;
}
void ChewyEngine::initialize() {
_events = new EventsManager();
_screen = new Graphics::Screen();
_sound = new Sound(_mixer);
}
@@ -71,12 +75,6 @@ Common::Error ChewyEngine::run() {
game_main();
// Run a dummy loop
while (!shouldQuit()) {
g_system->updateScreen();
g_system->delayMillis(10);
}
return Common::kNoError;
}
+2
View File
@@ -38,6 +38,7 @@ namespace Chewy {
#define SCREEN_HEIGHT 200
struct ChewyGameDescription;
class EventsManager;
class Sound;
class ChewyEngine : public Engine {
@@ -50,6 +51,7 @@ protected:
void shutdown();
public:
EventsManager *_events;
Sound *_sound;
Graphics::Screen *_screen;
public:
+74
View File
@@ -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.
*
*/
#include "common/system.h"
#include "chewy/events.h"
namespace Chewy {
EventsManager *g_events;
EventsManager::EventsManager() {
g_events = this;
}
EventsManager::~EventsManager() {
g_events = nullptr;
}
void EventsManager::pollEvents() {
Common::Event e;
while (g_system->getEventManager()->pollEvent(e)) {
switch (e.type) {
case Common::EVENT_QUIT:
case Common::EVENT_RETURN_TO_LAUNCHER:
return;
case Common::EVENT_KEYDOWN:
_keyEvents.push(e);
break;
default:
// Add other event types to the pending events queue. If the event is a
// mouse move and the prior one was also, then discard the prior one.
// This'll help prevent too many mouse move events accumulating
if (e.type == Common::EVENT_MOUSEMOVE && !_pendingEvents.empty() &&
_pendingEvents.back().type == Common::EVENT_MOUSEMOVE)
_pendingEvents.back() = e;
else
_pendingEvents.push(e);
break;
}
}
}
Common::Event EventsManager::readEvent() {
pollEvents();
return _pendingEvents.empty() ? Common::Event() : _pendingEvents.pop();
}
void EventsManager::warpMouse(const Common::Point &newPos) {
g_system->warpMouse(newPos.x, newPos.y);
}
} // namespace Chewy
+80
View File
@@ -0,0 +1,80 @@
/* 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 CHEWY_EVENTS_H
#define CHEWY_EVENTS_H
#include "common/array.h"
#include "common/queue.h"
#include "common/events.h"
namespace Chewy {
class EventsManager {
private:
Common::Queue<Common::Event> _pendingEvents;
Common::Queue<Common::Event> _keyEvents;
public:
EventsManager();
~EventsManager();
/**
* Poll any pending events
*/
void pollEvents();
/**
* Returns true if any unprocessed keyboard events are pending
*/
bool keyEventPending() const {
return !_keyEvents.empty();
}
/**
* Returns the next pending unprocessed keyboard event
*/
Common::Event getPendingKeyEvent() {
return _keyEvents.pop();
}
/**
* Returns the next event, if any
*/
Common::Event readEvent();
/**
* Sets the mouse position
*/
void warpMouse(const Common::Point &newPos);
void clearEvents() {
_pendingEvents.clear();
_keyEvents.clear();
}
};
extern EventsManager *g_events;
} // namespace Chewy
#endif
+1
View File
@@ -15,6 +15,7 @@ MODULE_OBJS = \
episode2.o \
episode3.o \
episode4.o \
events.o \
fehler.o \
file.o \
flic.o \