diff options
author | Matthew Hoops | 2011-09-06 20:59:06 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-09-06 20:59:06 -0400 |
commit | e56546a83d3dd3c9bf0d301b547d499e4b06b636 (patch) | |
tree | c6e704b2a6ef4d295260fe030a64993b8502cd1c | |
parent | cbcae58caf674198bf19f4b8bb3bf07c0a30055b (diff) | |
download | scummvm-rg350-e56546a83d3dd3c9bf0d301b547d499e4b06b636.tar.gz scummvm-rg350-e56546a83d3dd3c9bf0d301b547d499e4b06b636.tar.bz2 scummvm-rg350-e56546a83d3dd3c9bf0d301b547d499e4b06b636.zip |
PEGASUS: Implement two of the base input classes
-rwxr-xr-x | engines/pegasus/constants.h | 220 | ||||
-rwxr-xr-x | engines/pegasus/input.cpp | 138 | ||||
-rwxr-xr-x | engines/pegasus/input.h | 373 | ||||
-rw-r--r-- | engines/pegasus/module.mk | 1 | ||||
-rw-r--r-- | engines/pegasus/neighborhood/neighborhood.cpp | 1 |
5 files changed, 513 insertions, 220 deletions
diff --git a/engines/pegasus/constants.h b/engines/pegasus/constants.h index 509c9f3892..dd12727baf 100755 --- a/engines/pegasus/constants.h +++ b/engines/pegasus/constants.h @@ -187,8 +187,6 @@ const TimeValue kFiveMinutesPerSixtyTicks = kFiveMinutes * kSixtyTicksPerSecond; const TimeValue kTenMinutesPerSixtyTicks = kTenMinutes * kSixtyTicksPerSecond; // Time in seconds you can hang around Caldoria without going to work... -//const TimeValue kCaldoriaUncreatedTimeLimit = kFifteenMinutes; -//const TimeValue kCaldoriaUncreatedTimeLimit = kTwentyMinutes; const TimeValue kLateWarning2TimeLimit = kFiveMinutes; const TimeValue kLateWarning3TimeLimit = kTenMinutes; @@ -221,224 +219,6 @@ const TimeValue kPlasmaImpactTime = kTwoSeconds; const TimeValue kNoradAirMaskTimeLimit = kOneMinute + kFifteenSeconds; -enum { - kButtonDownBit = 0, - kAutoButtonBit = 1, - kBitsPerButton = 2, - - kButtonDownMask = 1 << kButtonDownBit, - kAutoButtonMask = 1 << kAutoButtonBit, - - kButtonStateBits = kButtonDownMask | kAutoButtonMask, - - kRawButtonUp = 0, - kRawButtonDown = kButtonDownMask | kAutoButtonMask, - - kButtonUp = 0, - kButtonDown = kButtonDownMask, - kButtonAutoUp = kAutoButtonMask, - kButtonAutoDown = kButtonDownMask | kAutoButtonMask -}; - -enum { - kUpButtonNum = 0, - kLeftButtonNum = 1, - kDownButtonNum = 2, - kRightButtonNum = 3, - kLeftFireButtonNum = 4, - kRightFireButtonNum = 5, - kOneButtonNum = 6, - kTwoButtonNum = 7, - kThreeButtonNum = 8, - kFourButtonNum = 9, - kMod1ButtonNum = 10, - kMod2ButtonNum = 11, - kMod3ButtonNum = 12 -}; - -enum { - kUpButtonShift = kUpButtonNum * kBitsPerButton, - kLeftButtonShift = kLeftButtonNum * kBitsPerButton, - kDownButtonShift = kDownButtonNum * kBitsPerButton, - kRightButtonShift = kRightButtonNum * kBitsPerButton, - kLeftFireButtonShift = kLeftFireButtonNum * kBitsPerButton, - kRightFireButtonShift = kRightFireButtonNum * kBitsPerButton, - kOneButtonShift = kOneButtonNum * kBitsPerButton, - kTwoButtonShift = kTwoButtonNum * kBitsPerButton, - kThreeButtonShift = kThreeButtonNum * kBitsPerButton, - kFourButtonShift = kFourButtonNum * kBitsPerButton, - kMod1ButtonShift = kMod1ButtonNum * kBitsPerButton, - kMod2ButtonShift = kMod2ButtonNum * kBitsPerButton, - kMod3ButtonShift = kMod3ButtonNum * kBitsPerButton -}; - -enum { - kAllUpBits = (kButtonUp << kUpButtonShift) | - (kButtonUp << kLeftButtonShift) | - (kButtonUp << kDownButtonShift) | - (kButtonUp << kRightButtonShift) | - (kButtonUp << kLeftFireButtonShift) | - (kButtonUp << kRightFireButtonShift) | - (kButtonUp << kOneButtonShift) | - (kButtonUp << kTwoButtonShift) | - (kButtonUp << kThreeButtonShift) | - (kButtonUp << kFourButtonShift) | - (kButtonUp << kMod1ButtonShift) | - (kButtonUp << kMod2ButtonShift) | - (kButtonUp << kMod3ButtonShift), - kDirectionBits = (kButtonDownMask << kUpButtonShift) | - (kButtonDownMask << kLeftButtonShift) | - (kButtonDownMask << kDownButtonShift) | - (kButtonDownMask << kRightButtonShift), - kButtonBits = (kButtonDownMask << kLeftFireButtonShift) | - (kButtonDownMask << kRightFireButtonShift) | - (kButtonDownMask << kOneButtonShift) | - (kButtonDownMask << kTwoButtonShift) | - (kButtonDownMask << kThreeButtonShift) | - (kButtonDownMask << kFourButtonShift) | - (kButtonDownMask << kMod1ButtonShift) | - (kButtonDownMask << kMod2ButtonShift) | - (kButtonDownMask << kMod3ButtonShift), - kAllButtonDownBits = kDirectionBits | kButtonBits, - kAllAutoBits = (kAutoButtonMask << kUpButtonShift) | - (kAutoButtonMask << kLeftButtonShift) | - (kAutoButtonMask << kDownButtonShift) | - (kAutoButtonMask << kRightButtonShift) | - (kAutoButtonMask << kLeftFireButtonShift) | - (kAutoButtonMask << kRightFireButtonShift) | - (kAutoButtonMask << kOneButtonShift) | - (kAutoButtonMask << kTwoButtonShift) | - (kAutoButtonMask << kThreeButtonShift) | - (kAutoButtonMask << kFourButtonShift) | - (kAutoButtonMask << kMod1ButtonShift) | - (kAutoButtonMask << kMod2ButtonShift) | - (kAutoButtonMask << kMod3ButtonShift), - - kFilterUpButton = kButtonDownMask << kUpButtonShift, - kFilterUpAuto = kAutoButtonMask << kUpButtonShift, - kFilterUpButtonAny = kFilterUpButton | kFilterUpAuto, - kFilterLeftButton = kButtonDownMask << kLeftButtonShift, - kFilterLeftAuto = kAutoButtonMask << kLeftButtonShift, - kFilterLeftButtonAny = kFilterLeftButton | kFilterLeftAuto, - kFilterDownButton = kButtonDownMask << kDownButtonShift, - kFilterDownAuto = kAutoButtonMask << kDownButtonShift, - kFilterDownButtonAny = kFilterDownButton | kFilterDownAuto, - kFilterRightButton = kButtonDownMask << kRightButtonShift, - kFilterRightAuto = kAutoButtonMask << kRightButtonShift, - kFilterRightButtonAny = kFilterRightButton | kFilterRightAuto, - kFilterLeftFireButton = kButtonDownMask << kLeftFireButtonShift, - kFilterLeftFireAuto = kAutoButtonMask << kLeftFireButtonShift, - kFilterLeftFireButtonAny = kFilterLeftFireButton | kFilterLeftFireAuto, - kFilterRightFireButton = kButtonDownMask << kRightFireButtonShift, - kFilterRightFireAuto = kAutoButtonMask << kRightFireButtonShift, - kFilterRightFireButtonAny = kFilterRightFireButton | kFilterRightFireAuto, - kFilterOneButton = kButtonDownMask << kOneButtonShift, - kFilterOneAuto = kAutoButtonMask << kOneButtonShift, - kFilterOneButtonAny = kFilterOneButton | kFilterOneAuto, - kFilterTwoButton = kButtonDownMask << kTwoButtonShift, - kFilterTwoAuto = kAutoButtonMask << kTwoButtonShift, - kFilterTwoButtonAny = kFilterTwoButton | kFilterTwoAuto, - kFilterThreeButton = kButtonDownMask << kThreeButtonShift, - kFilterThreeAuto = kAutoButtonMask << kThreeButtonShift, - kFilterThreeButtonAny = kFilterThreeButton | kFilterThreeAuto, - kFilterFourButton = kButtonDownMask << kFourButtonShift, - kFilterFourAuto = kAutoButtonMask << kFourButtonShift, - kFilterFourButtonAny = kFilterFourButton | kFilterFourAuto, - kFilterMod1Button = kButtonDownMask << kMod1ButtonShift, - kFilterMod1Auto = kAutoButtonMask << kMod1ButtonShift, - kFilterMod1ButtonAny = kFilterMod1Button | kFilterMod1Auto, - kFilterMod2Button = kButtonDownMask << kMod2ButtonShift, - kFilterMod2Auto = kAutoButtonMask << kMod2ButtonShift, - kFilterMod2ButtonAny = kFilterMod2Button | kFilterMod2Auto, - kFilterMod3Button = kButtonDownMask << kMod3ButtonShift, - kFilterMod3Auto = kAutoButtonMask << kMod3ButtonShift, - kFilterMod3ButtonAny = kFilterMod3Button | kFilterMod3Auto, - - kFilterNoInput = 0, - kFilterAllInput = kFilterUpButton | - kFilterUpAuto | - kFilterLeftButton | - kFilterLeftAuto | - kFilterDownButton | - kFilterDownAuto | - kFilterRightButton | - kFilterRightAuto | - kFilterLeftFireButton | - kFilterLeftFireAuto | - kFilterRightFireButton | - kFilterRightFireAuto | - kFilterOneButton | - kFilterOneAuto | - kFilterTwoButton | - kFilterTwoAuto | - kFilterThreeButton | - kFilterThreeAuto | - kFilterFourButton | - kFilterFourAuto | - kFilterMod1Button | - kFilterMod1Auto | - kFilterMod2Button | - kFilterMod2Auto | - kFilterMod3Button | - kFilterMod3Auto, - - kFilterAllDirections = kFilterUpButton | - kFilterUpAuto | - kFilterLeftButton | - kFilterLeftAuto | - kFilterDownButton | - kFilterDownAuto | - kFilterRightButton | - kFilterRightAuto, - - kFilterButtons = kFilterOneButton | - kFilterOneAuto | - kFilterTwoButton | - kFilterTwoAuto | - kFilterThreeButton | - kFilterThreeAuto | - kFilterFourButton | - kFilterFourAuto, - - kFilterFireButtons = kFilterLeftFireButton | - kFilterLeftFireAuto | - kFilterRightFireButton | - kFilterRightFireAuto, - - kFilterAllButtons = kFilterLeftFireButton | - kFilterLeftFireAuto | - kFilterRightFireButton | - kFilterRightFireAuto | - kFilterOneButton | - kFilterOneAuto | - kFilterTwoButton | - kFilterTwoAuto | - kFilterThreeButton | - kFilterThreeAuto | - kFilterFourButton | - kFilterFourAuto | - kFilterMod1Button | - kFilterMod1Auto | - kFilterMod2Button | - kFilterMod2Auto | - kFilterMod3Button | - kFilterMod3Auto, - - kFilterAllInputNoAuto = kFilterUpButton | - kFilterLeftButton | - kFilterDownButton | - kFilterRightButton | - kFilterLeftFireButton | - kFilterRightFireButton | - kFilterOneButton | - kFilterTwoButton | - kFilterThreeButton | - kFilterFourButton | - kFilterMod1Button | - kFilterMod2Button | - kFilterMod3Button -}; - const tNotificationID kNeighborhoodNotificationID = 1; const tNotificationID kLastNeighborhoodNotificationID = kNeighborhoodNotificationID; diff --git a/engines/pegasus/input.cpp b/engines/pegasus/input.cpp new file mode 100755 index 0000000000..bb147fb716 --- /dev/null +++ b/engines/pegasus/input.cpp @@ -0,0 +1,138 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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/events.h" +#include "common/system.h" + +#include "pegasus/input.h" + +namespace Pegasus { + +InputDevice::InputDevice() { + _lastRawBits = kAllUpBits; +} + +InputDevice::~InputDevice() { +} + +void InputDevice::getInput(Input &input, const tInputBits filter) { + // TODO: Save/Load keys + + tInputBits currentBits = 0; + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) { + // We only care about two events here + // We're mapping from ScummVM events to pegasus events, which + // are based on pippin events. + if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP) { + switch (event.kbd.keycode) { + case Common::KEYCODE_UP: + case Common::KEYCODE_KP8: + currentBits |= (kRawButtonDown << kUpButtonShift); + break; + case Common::KEYCODE_LEFT: + case Common::KEYCODE_KP4: + currentBits |= (kRawButtonDown << kLeftButtonShift); + break; + case Common::KEYCODE_DOWN: + case Common::KEYCODE_KP5: + currentBits |= (kRawButtonDown << kDownButtonShift); + break; + case Common::KEYCODE_RIGHT: + case Common::KEYCODE_KP6: + currentBits |= (kRawButtonDown << kRightButtonShift); + break; + case Common::KEYCODE_RETURN: + case Common::KEYCODE_SPACE: + currentBits |= (kRawButtonDown << kTwoButtonShift); + break; + case Common::KEYCODE_t: + case Common::KEYCODE_KP_EQUALS: + currentBits |= (kRawButtonDown << kThreeButtonShift); + break; + case Common::KEYCODE_i: + case Common::KEYCODE_KP_DIVIDE: + currentBits |= (kRawButtonDown << kFourButtonShift); + break; + case Common::KEYCODE_q: + currentBits |= (kRawButtonDown << kMod1ButtonShift); + break; + case Common::KEYCODE_ESCAPE: + case Common::KEYCODE_p: + currentBits |= (kRawButtonDown << kMod3ButtonShift); + break; + case Common::KEYCODE_TILDE: + case Common::KEYCODE_NUMLOCK: // Yes, the original uses Num Lock/Clear on the Mac... + currentBits |= (kRawButtonDown << kLeftFireButtonShift); + break; + case Common::KEYCODE_DELETE: + currentBits |= (kRawButtonDown << kRightFireButtonShift); + break; + default: + break; + } + + if (event.kbd.flags & Common::KBD_ALT) // Alt, option, same thing! + currentBits |= (kRawButtonDown << kMod2ButtonShift); + } + } + + // Update mouse button state + // Note that we don't use EVENT_LBUTTONUP/EVENT_LBUTTONDOWN because + // they do not show if the button is being held down. We're treating + // both mouse buttons as the same for ease of use. + if (g_system->getEventManager()->getButtonState() != 0) + currentBits |= (kRawButtonDown << kTwoButtonShift); + + // Update the mouse position too + input.setInputLocation(g_system->getEventManager()->getMousePos()); + _lastRawBits = currentBits; + + tInputBits filteredBits = currentBits & filter; + input.setInputBits((filteredBits & kAllButtonDownBits) | (filteredBits & _lastRawBits & kAllAutoBits)); +} + +// Wait until the input device stops returning input allowed by filter... +void InputDevice::waitInput(const tInputBits filter) { + if (filter != 0) { + for (;;) { + Input input; + getInput(input, filter); + if (!input.anyInput()) + break; + } + } +} + +int operator==(const Input &arg1, const Input &arg2) { + return arg1._inputState == arg2._inputState; +} + +int operator!=(const Input &arg1, const Input &arg2) { + return !operator==(arg1, arg2); +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/input.h b/engines/pegasus/input.h new file mode 100755 index 0000000000..463e3d024b --- /dev/null +++ b/engines/pegasus/input.h @@ -0,0 +1,373 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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 PEGASUS_INPUT_H +#define PEGASUS_INPUT_H + +#include "common/rect.h" + +#include "pegasus/constants.h" +#include "pegasus/types.h" + +namespace Pegasus { + +class Hotspot; +class Input; + +class InputDevice { +public: + InputDevice(); + ~InputDevice(); + + void getInput(Input&, const tInputBits); + + void waitInput(const tInputBits); + +protected: + tInputBits _lastRawBits; +}; + +enum { + kButtonDownBit = 0, + kAutoButtonBit = 1, + kBitsPerButton = 2, + + kButtonDownMask = 1 << kButtonDownBit, + kAutoButtonMask = 1 << kAutoButtonBit, + + kButtonStateBits = kButtonDownMask | kAutoButtonMask, + + kRawButtonUp = 0, + kRawButtonDown = kButtonDownMask | kAutoButtonMask, + + kButtonUp = 0, + kButtonDown = kButtonDownMask, + kButtonAutoUp = kAutoButtonMask, + kButtonAutoDown = kButtonDownMask | kAutoButtonMask +}; + +enum { + kUpButtonNum = 0, + kLeftButtonNum = 1, + kDownButtonNum = 2, + kRightButtonNum = 3, + kLeftFireButtonNum = 4, + kRightFireButtonNum = 5, + kOneButtonNum = 6, + kTwoButtonNum = 7, + kThreeButtonNum = 8, + kFourButtonNum = 9, + kMod1ButtonNum = 10, + kMod2ButtonNum = 11, + kMod3ButtonNum = 12 +}; + +enum { + kUpButtonShift = kUpButtonNum * kBitsPerButton, + kLeftButtonShift = kLeftButtonNum * kBitsPerButton, + kDownButtonShift = kDownButtonNum * kBitsPerButton, + kRightButtonShift = kRightButtonNum * kBitsPerButton, + kLeftFireButtonShift = kLeftFireButtonNum * kBitsPerButton, + kRightFireButtonShift = kRightFireButtonNum * kBitsPerButton, + kOneButtonShift = kOneButtonNum * kBitsPerButton, + kTwoButtonShift = kTwoButtonNum * kBitsPerButton, + kThreeButtonShift = kThreeButtonNum * kBitsPerButton, + kFourButtonShift = kFourButtonNum * kBitsPerButton, + kMod1ButtonShift = kMod1ButtonNum * kBitsPerButton, + kMod2ButtonShift = kMod2ButtonNum * kBitsPerButton, + kMod3ButtonShift = kMod3ButtonNum * kBitsPerButton +}; + +enum { + kAllUpBits = (kButtonUp << kUpButtonShift) | + (kButtonUp << kLeftButtonShift) | + (kButtonUp << kDownButtonShift) | + (kButtonUp << kRightButtonShift) | + (kButtonUp << kLeftFireButtonShift) | + (kButtonUp << kRightFireButtonShift) | + (kButtonUp << kOneButtonShift) | + (kButtonUp << kTwoButtonShift) | + (kButtonUp << kThreeButtonShift) | + (kButtonUp << kFourButtonShift) | + (kButtonUp << kMod1ButtonShift) | + (kButtonUp << kMod2ButtonShift) | + (kButtonUp << kMod3ButtonShift), + kDirectionBits = (kButtonDownMask << kUpButtonShift) | + (kButtonDownMask << kLeftButtonShift) | + (kButtonDownMask << kDownButtonShift) | + (kButtonDownMask << kRightButtonShift), + kButtonBits = (kButtonDownMask << kLeftFireButtonShift) | + (kButtonDownMask << kRightFireButtonShift) | + (kButtonDownMask << kOneButtonShift) | + (kButtonDownMask << kTwoButtonShift) | + (kButtonDownMask << kThreeButtonShift) | + (kButtonDownMask << kFourButtonShift) | + (kButtonDownMask << kMod1ButtonShift) | + (kButtonDownMask << kMod2ButtonShift) | + (kButtonDownMask << kMod3ButtonShift), + kAllButtonDownBits = kDirectionBits | kButtonBits, + kAllAutoBits = (kAutoButtonMask << kUpButtonShift) | + (kAutoButtonMask << kLeftButtonShift) | + (kAutoButtonMask << kDownButtonShift) | + (kAutoButtonMask << kRightButtonShift) | + (kAutoButtonMask << kLeftFireButtonShift) | + (kAutoButtonMask << kRightFireButtonShift) | + (kAutoButtonMask << kOneButtonShift) | + (kAutoButtonMask << kTwoButtonShift) | + (kAutoButtonMask << kThreeButtonShift) | + (kAutoButtonMask << kFourButtonShift) | + (kAutoButtonMask << kMod1ButtonShift) | + (kAutoButtonMask << kMod2ButtonShift) | + (kAutoButtonMask << kMod3ButtonShift), + + kFilterUpButton = kButtonDownMask << kUpButtonShift, + kFilterUpAuto = kAutoButtonMask << kUpButtonShift, + kFilterUpButtonAny = kFilterUpButton | kFilterUpAuto, + kFilterLeftButton = kButtonDownMask << kLeftButtonShift, + kFilterLeftAuto = kAutoButtonMask << kLeftButtonShift, + kFilterLeftButtonAny = kFilterLeftButton | kFilterLeftAuto, + kFilterDownButton = kButtonDownMask << kDownButtonShift, + kFilterDownAuto = kAutoButtonMask << kDownButtonShift, + kFilterDownButtonAny = kFilterDownButton | kFilterDownAuto, + kFilterRightButton = kButtonDownMask << kRightButtonShift, + kFilterRightAuto = kAutoButtonMask << kRightButtonShift, + kFilterRightButtonAny = kFilterRightButton | kFilterRightAuto, + kFilterLeftFireButton = kButtonDownMask << kLeftFireButtonShift, + kFilterLeftFireAuto = kAutoButtonMask << kLeftFireButtonShift, + kFilterLeftFireButtonAny = kFilterLeftFireButton | kFilterLeftFireAuto, + kFilterRightFireButton = kButtonDownMask << kRightFireButtonShift, + kFilterRightFireAuto = kAutoButtonMask << kRightFireButtonShift, + kFilterRightFireButtonAny = kFilterRightFireButton | kFilterRightFireAuto, + kFilterOneButton = kButtonDownMask << kOneButtonShift, + kFilterOneAuto = kAutoButtonMask << kOneButtonShift, + kFilterOneButtonAny = kFilterOneButton | kFilterOneAuto, + kFilterTwoButton = kButtonDownMask << kTwoButtonShift, + kFilterTwoAuto = kAutoButtonMask << kTwoButtonShift, + kFilterTwoButtonAny = kFilterTwoButton | kFilterTwoAuto, + kFilterThreeButton = kButtonDownMask << kThreeButtonShift, + kFilterThreeAuto = kAutoButtonMask << kThreeButtonShift, + kFilterThreeButtonAny = kFilterThreeButton | kFilterThreeAuto, + kFilterFourButton = kButtonDownMask << kFourButtonShift, + kFilterFourAuto = kAutoButtonMask << kFourButtonShift, + kFilterFourButtonAny = kFilterFourButton | kFilterFourAuto, + kFilterMod1Button = kButtonDownMask << kMod1ButtonShift, + kFilterMod1Auto = kAutoButtonMask << kMod1ButtonShift, + kFilterMod1ButtonAny = kFilterMod1Button | kFilterMod1Auto, + kFilterMod2Button = kButtonDownMask << kMod2ButtonShift, + kFilterMod2Auto = kAutoButtonMask << kMod2ButtonShift, + kFilterMod2ButtonAny = kFilterMod2Button | kFilterMod2Auto, + kFilterMod3Button = kButtonDownMask << kMod3ButtonShift, + kFilterMod3Auto = kAutoButtonMask << kMod3ButtonShift, + kFilterMod3ButtonAny = kFilterMod3Button | kFilterMod3Auto, + + kFilterNoInput = 0, + kFilterAllInput = kFilterUpButton | + kFilterUpAuto | + kFilterLeftButton | + kFilterLeftAuto | + kFilterDownButton | + kFilterDownAuto | + kFilterRightButton | + kFilterRightAuto | + kFilterLeftFireButton | + kFilterLeftFireAuto | + kFilterRightFireButton | + kFilterRightFireAuto | + kFilterOneButton | + kFilterOneAuto | + kFilterTwoButton | + kFilterTwoAuto | + kFilterThreeButton | + kFilterThreeAuto | + kFilterFourButton | + kFilterFourAuto | + kFilterMod1Button | + kFilterMod1Auto | + kFilterMod2Button | + kFilterMod2Auto | + kFilterMod3Button | + kFilterMod3Auto, + + kFilterAllDirections = kFilterUpButton | + kFilterUpAuto | + kFilterLeftButton | + kFilterLeftAuto | + kFilterDownButton | + kFilterDownAuto | + kFilterRightButton | + kFilterRightAuto, + + kFilterButtons = kFilterOneButton | + kFilterOneAuto | + kFilterTwoButton | + kFilterTwoAuto | + kFilterThreeButton | + kFilterThreeAuto | + kFilterFourButton | + kFilterFourAuto, + + kFilterFireButtons = kFilterLeftFireButton | + kFilterLeftFireAuto | + kFilterRightFireButton | + kFilterRightFireAuto, + + kFilterAllButtons = kFilterLeftFireButton | + kFilterLeftFireAuto | + kFilterRightFireButton | + kFilterRightFireAuto | + kFilterOneButton | + kFilterOneAuto | + kFilterTwoButton | + kFilterTwoAuto | + kFilterThreeButton | + kFilterThreeAuto | + kFilterFourButton | + kFilterFourAuto | + kFilterMod1Button | + kFilterMod1Auto | + kFilterMod2Button | + kFilterMod2Auto | + kFilterMod3Button | + kFilterMod3Auto, + + kFilterAllInputNoAuto = kFilterUpButton | + kFilterLeftButton | + kFilterDownButton | + kFilterRightButton | + kFilterLeftFireButton | + kFilterRightFireButton | + kFilterOneButton | + kFilterTwoButton | + kFilterThreeButton | + kFilterFourButton | + kFilterMod1Button | + kFilterMod2Button | + kFilterMod3Button +}; + +/* + + Buttons are defined as: + up, left, down, right direction buttons. + fireLeft, fireRight: fire buttons. + mod1, mod2, mod3: modifier buttons, similar to shift, control, etc. + a, b, c, d: general purpose buttons. + + button state is held as bits in a long word, two bits per button. + + Filter bits: + for each button, two bits are assigned for filtering. If bit 0 is set, the + corresponding button is available for "button down" input. If bit 1 is set, + the corresponding button is available for "auto down" input. Note that bit + 1 is meaningful only if bit 0 is set. + +*/ + +class Input { +friend int operator==(const Input &, const Input &); +friend int operator!=(const Input &, const Input &); +friend class InputDevice; + +public: + Input() { clearInput(); } + + bool upButtonDown() const { return (_inputState & (kButtonStateBits << kUpButtonShift)) == (kButtonDown << kUpButtonShift); } + bool upButtonAutoDown() const { return (_inputState & (kButtonStateBits << kUpButtonShift)) == (kButtonAutoDown << kUpButtonShift); } + bool upButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kUpButtonShift)) != 0; } + + bool leftButtonDown() const { return (_inputState & (kButtonStateBits << kLeftButtonShift)) == (kButtonDown << kLeftButtonShift); } + bool leftButtonAutoDown() const { return (_inputState & (kButtonStateBits << kLeftButtonShift)) == (kButtonAutoDown << kLeftButtonShift); } + bool leftButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kLeftButtonShift)) != 0; } + + bool downButtonDown() const { return (_inputState & (kButtonStateBits << kDownButtonShift)) == (kButtonDown << kDownButtonShift); } + bool downButtonAutoDown() const { return (_inputState & (kButtonStateBits << kDownButtonShift)) == (kButtonAutoDown << kDownButtonShift); } + bool downButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kDownButtonShift)) != 0; } + + bool rightButtonDown() const { return (_inputState & (kButtonStateBits << kRightButtonShift)) == (kButtonDown << kRightButtonShift); } + bool rightButtonAutoDown() const { return (_inputState & (kButtonStateBits << kRightButtonShift)) == (kButtonAutoDown << kRightButtonShift); } + bool rightButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kRightButtonShift)) != 0; } + + bool leftFireButtonDown() const { return (_inputState & (kButtonStateBits << kLeftFireButtonShift)) == (kButtonDown << kLeftFireButtonShift); } + bool leftFireButtonAutoDown() const { return (_inputState & (kButtonStateBits << kLeftFireButtonShift)) == (kButtonAutoDown << kLeftFireButtonShift); } + bool leftFireButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kLeftFireButtonShift)) != 0; } + + bool rightFireButtonDown() const { return (_inputState & (kButtonStateBits << kRightFireButtonShift)) == (kButtonDown << kRightFireButtonShift); } + bool rightFireButtonAutoDown() const { return (_inputState & (kButtonStateBits << kRightFireButtonShift)) == (kButtonAutoDown << kRightFireButtonShift); } + bool rightFireButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kRightFireButtonShift)) != 0; } + + bool oneButtonDown() const { return (_inputState & (kButtonStateBits << kOneButtonShift)) == (kButtonDown << kOneButtonShift); } + bool oneButtonAutoDown() const { return (_inputState & (kButtonStateBits << kOneButtonShift)) == (kButtonAutoDown << kOneButtonShift); } + bool oneButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kOneButtonShift)) != 0; } + + bool twoButtonDown() const { return (_inputState & (kButtonStateBits << kTwoButtonShift)) == (kButtonDown << kTwoButtonShift); } + bool twoButtonAutoDown() const { return (_inputState & (kButtonStateBits << kTwoButtonShift)) == (kButtonAutoDown << kTwoButtonShift); } + bool twoButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kTwoButtonShift)) != 0; } + + bool threeButtonDown() const { return (_inputState & (kButtonStateBits << kThreeButtonShift)) == (kButtonDown << kThreeButtonShift); } + bool threeButtonAutoDown() const { return (_inputState & (kButtonStateBits << kThreeButtonShift)) == (kButtonAutoDown << kThreeButtonShift); } + bool threeButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kThreeButtonShift)) != 0; } + + bool fourButtonDown() const { return (_inputState & (kButtonStateBits << kFourButtonShift)) == (kButtonDown << kFourButtonShift); } + bool fourButtonAutoDown() const { return (_inputState & (kButtonStateBits << kFourButtonShift)) == (kButtonAutoDown << kFourButtonShift); } + bool fourButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kFourButtonShift)) != 0; } + + bool mod1ButtonDown() const { return (_inputState & (kButtonStateBits << kMod1ButtonShift)) == (kButtonDown << kMod1ButtonShift); } + bool mod1ButtonAutoDown() const { return (_inputState & (kButtonStateBits << kMod1ButtonShift)) == (kButtonAutoDown << kMod1ButtonShift); } + bool mod1ButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kMod1ButtonShift)) != 0; } + + bool mod2ButtonDown() const { return (_inputState & (kButtonStateBits << kMod2ButtonShift)) == (kButtonDown << kMod2ButtonShift); } + bool mod2ButtonAutoDown() const { return (_inputState & (kButtonStateBits << kMod2ButtonShift)) == (kButtonAutoDown << kMod2ButtonShift); } + bool mod2ButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kMod2ButtonShift)) != 0; } + + bool mod3ButtonDown() const { return (_inputState & (kButtonStateBits << kMod3ButtonShift)) == (kButtonDown << kMod3ButtonShift); } + bool mod3ButtonAutoDown() const { return (_inputState & (kButtonStateBits << kMod3ButtonShift)) == (kButtonAutoDown << kMod3ButtonShift); } + bool mod3ButtonAnyDown() const { return (_inputState & (kButtonAutoDown << kMod3ButtonShift)) != 0; } + + bool allAutoInput() const { return (_inputState & kAllAutoBits) != 0; } + bool anyDirectionInput() const { return (_inputState & kDirectionBits) != 0; } + bool anyButtonInput() const { return (_inputState & kButtonBits) != 0; } + bool anyInput() const { return _inputState != 0; } + + void getInputLocation(Common::Point &where) const { where = _inputLocation; } + + bool anyInputBitSet(const tInputBits bits) const { return (_inputState & bits) != 0; } + + void clearInput() { + _inputState = kAllUpBits; + _inputLocation.x = 0; + _inputLocation.y = 0; + } + +protected: + void setInputBits(const tInputBits state) { _inputState = state; } + void setInputLocation(const Common::Point &where) { _inputLocation = where; } + + tInputBits _inputState; + Common::Point _inputLocation; +}; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/module.mk b/engines/pegasus/module.mk index 5b8898ff85..8d3ee52304 100644 --- a/engines/pegasus/module.mk +++ b/engines/pegasus/module.mk @@ -7,6 +7,7 @@ MODULE_OBJS = \ gamestate.o \ graphics.o \ hotspot.o \ + input.o \ menu.o \ notification.o \ overview.o \ diff --git a/engines/pegasus/neighborhood/neighborhood.cpp b/engines/pegasus/neighborhood/neighborhood.cpp index 8381188764..461f4b0149 100644 --- a/engines/pegasus/neighborhood/neighborhood.cpp +++ b/engines/pegasus/neighborhood/neighborhood.cpp @@ -27,6 +27,7 @@ #include "common/stream.h" #include "pegasus/gamestate.h" +#include "pegasus/input.h" #include "pegasus/pegasus.h" #include "pegasus/neighborhood/neighborhood.h" |