PEGASUS: Make InputDevice into a Singleton

Removes a global construction
This commit is contained in:
Matthew Hoops 2011-12-20 18:35:33 -05:00
parent a600dcb56a
commit 331da45ae3
7 changed files with 31 additions and 28 deletions

View File

@ -265,7 +265,7 @@ bool AIArea::playAIMovie(const LowerAreaSignature area, const Common::String &mo
lockAIOut();
InputHandler::getCurrentInputDevice()->waitInput(interruptFilter);
InputDevice.waitInput(interruptFilter);
if (_AIMovie.isMovieValid())
_AIMovie.releaseMovie();
@ -295,7 +295,7 @@ bool AIArea::playAIMovie(const LowerAreaSignature area, const Common::String &mo
while (_AIMovie.isRunning()) {
Input input;
InputHandler::getCurrentInputDevice()->getInput(input, interruptFilter);
InputDevice.getInput(input, interruptFilter);
if (input.anyInput() || vm->shouldQuit()) {
result = false;

View File

@ -30,16 +30,17 @@
#include "pegasus/input.h"
#include "pegasus/pegasus.h"
namespace Common {
DECLARE_SINGLETON(Pegasus::InputDeviceManager);
}
namespace Pegasus {
InputDevice::InputDevice() {
InputDeviceManager::InputDeviceManager() {
_lastRawBits = kAllUpBits;
}
InputDevice::~InputDevice() {
}
void InputDevice::getInput(Input &input, const InputBits filter) {
void InputDeviceManager::getInput(Input &input, const InputBits filter) {
// TODO: Save/Load keys
InputBits currentBits = 0;
@ -140,7 +141,7 @@ void InputDevice::getInput(Input &input, const InputBits filter) {
}
// Wait until the input device stops returning input allowed by filter...
void InputDevice::waitInput(const InputBits filter) {
void InputDeviceManager::waitInput(const InputBits filter) {
if (filter != 0) {
for (;;) {
Input input;
@ -160,7 +161,6 @@ int operator!=(const Input &arg1, const Input &arg2) {
}
InputHandler *InputHandler::_inputHandler = 0;
InputDevice InputHandler::_inputDevice;
bool InputHandler::_invalHotspots = false;
InputBits InputHandler::_lastFilter = kFilterNoInput;
@ -198,7 +198,7 @@ void InputHandler::getInput(Input &input, Hotspot *&cursorSpot) {
else
_lastFilter = kFilterAllInput;
_inputDevice.getInput(input, _lastFilter);
InputDevice.getInput(input, _lastFilter);
if (_inputHandler && _inputHandler->wantsCursor() && (_lastFilter & _inputHandler->getClickFilter()) != 0) {
if (cursor->isVisible()) {
@ -220,7 +220,7 @@ void InputHandler::getInput(Input &input, Hotspot *&cursorSpot) {
}
void InputHandler::readInputDevice(Input &input) {
_inputDevice.getInput(input, kFilterAllInput);
InputDevice.getInput(input, kFilterAllInput);
}
InputHandler::InputHandler(InputHandler *nextHandler) {

View File

@ -27,6 +27,7 @@
#define PEGASUS_INPUT_H
#include "common/rect.h"
#include "common/singleton.h"
#include "pegasus/constants.h"
#include "pegasus/types.h"
@ -36,16 +37,18 @@ namespace Pegasus {
class Hotspot;
class Input;
class InputDevice {
class InputDeviceManager : public Common::Singleton<InputDeviceManager> {
public:
InputDevice();
~InputDevice();
InputDeviceManager();
~InputDeviceManager() {}
void getInput(Input &, const InputBits);
void waitInput(const InputBits);
protected:
friend class Common::Singleton<SingletonBaseType>;
InputBits _lastRawBits;
};
@ -292,7 +295,7 @@ static const InputBits kOpticalInterruption = kFilterAllInputNoAuto;
class Input {
friend int operator==(const Input &, const Input &);
friend int operator!=(const Input &, const Input &);
friend class InputDevice;
friend class InputDeviceManager;
public:
Input() { clearInput(); }
@ -385,7 +388,6 @@ class InputHandler {
public:
static InputHandler *setInputHandler(InputHandler*);
static InputHandler *getCurrentHandler() { return _inputHandler; }
static InputDevice *getCurrentInputDevice() { return &_inputDevice; }
static void pollForInput();
static void getInput(Input&, Hotspot*&);
static void readInputDevice(Input&);
@ -419,7 +421,6 @@ public:
protected:
static InputHandler *_inputHandler;
static InputDevice _inputDevice; // TODO: Remove global constructor
static bool _invalHotspots;
static InputBits _lastFilter;
@ -487,4 +488,6 @@ public:
} // End of namespace Pegasus
#define InputDevice (::Pegasus::InputDeviceManager::instance())
#endif

View File

@ -222,7 +222,7 @@ void Caldoria::start() {
}
}
InputHandler::getCurrentInputDevice()->getInput(input, kPullbackInterruptFilter);
InputDevice.getInput(input, kPullbackInterruptFilter);
if (input.anyInput()) { // TODO: Save/Quit requests
skipped = true;
break;

View File

@ -882,7 +882,7 @@ void Neighborhood::startExtraSequence(const ExtraID extraID, const NotificationF
}
bool Neighborhood::startExtraSequenceSync(const ExtraID extraID, const InputBits interruptionFilter) {
InputHandler::getCurrentInputDevice()->waitInput(interruptionFilter);
InputDevice.waitInput(interruptionFilter);
return prepareExtraSync(extraID) && waitMovieFinish(&_navMovie, interruptionFilter);
}
@ -1315,7 +1315,7 @@ bool Neighborhood::waitMovieFinish(Movie *movie, const InputBits interruptionFil
bool openAllowed = _vm->swapLoadAllowed(false);
while (movie->isRunning()) {
InputHandler::getCurrentInputDevice()->getInput(input, interruptionFilter);
InputDevice.getInput(input, interruptionFilter);
if (input.anyInput() || _vm->shouldQuit()) {
result = false;
@ -1590,7 +1590,7 @@ void Neighborhood::playCroppedMovieOnce(const Common::String &movieName, CoordTy
Input input;
while (_croppedMovie.isRunning() && !_vm->shouldQuit()) {
_vm->processShell();
InputHandler::getCurrentInputDevice()->getInput(input, interruptionFilter);
InputDevice.getInput(input, interruptionFilter);
if (input.anyInput() || _vm->shouldQuit()) // TODO: Save/Load request
break;
_vm->_system->delayMillis(10);

View File

@ -1619,7 +1619,7 @@ void FullTSA::showMainJumpMenu() {
}
void FullTSA::playTBPMonitor() {
InputHandler::getCurrentInputDevice()->waitInput(kFilterAllButtons);
InputDevice.waitInput(kFilterAllButtons);
if ((GameState.getT0BMonitorMode() & kPlayingTBPMask) == 0) {
ExtraID extra;
@ -1770,7 +1770,7 @@ void FullTSA::initializeComparisonMonitor(const int newMode, const ExtraID compa
}
void FullTSA::playLeftComparison() {
InputHandler::getCurrentInputDevice()->waitInput(kFilterAllButtons);
InputDevice.waitInput(kFilterAllButtons);
if ((GameState.getT0BMonitorMode() & kPlayingLeftComparisonMask) == 0) {
ExtraID extra;
@ -1820,7 +1820,7 @@ void FullTSA::playLeftComparison() {
}
void FullTSA::playRightComparison() {
InputHandler::getCurrentInputDevice()->waitInput(kFilterAllButtons);
InputDevice.waitInput(kFilterAllButtons);
if ((GameState.getT0BMonitorMode() & kPlayingRightComparisonMask) == 0) {
ExtraID extra;

View File

@ -281,7 +281,7 @@ void PegasusEngine::runIntro() {
}
Input input;
InputHandler::getCurrentInputDevice()->getInput(input, kFilterAllInput);
InputDevice.getInput(input, kFilterAllInput);
if (input.anyInput())
skipped = true;
@ -892,7 +892,7 @@ void PegasusEngine::doInterfaceOverview() {
highlight.setHighlightCornerDiameter(8);
Input input;
InputHandler::getCurrentInputDevice()->getInput(input, kFilterAllInput);
InputDevice.getInput(input, kFilterAllInput);
Common::Point cursorLoc;
input.getInputLocation(cursorLoc);
@ -934,7 +934,7 @@ void PegasusEngine::doInterfaceOverview() {
_gfx->doFadeInSync();
for (;;) {
InputHandler::getCurrentInputDevice()->getInput(input, kFilterAllInput);
InputDevice.getInput(input, kFilterAllInput);
if (input.anyInput() || shouldQuit()) // TODO: Check for save/load requests too
break;
@ -1150,7 +1150,7 @@ bool PegasusEngine::playMovieScaled(Video::SeekableVideoDecoder *video, uint16 x
}
Input input;
InputHandler::getCurrentInputDevice()->getInput(input, kFilterAllInput);
InputDevice.getInput(input, kFilterAllInput);
if (input.anyInput())
skipped = true;