diff --git a/GpApp/Environ.cpp b/GpApp/Environ.cpp index 554f7a3..8cc8965 100644 --- a/GpApp/Environ.cpp +++ b/GpApp/Environ.cpp @@ -11,6 +11,7 @@ #include "Externs.h" #include "Environ.h" #include "HostDisplayDriver.h" +#include "HostSystemServices.h" #define kSwitchDepthAlert 130 @@ -393,7 +394,7 @@ void CheckMemorySize (void) { #define kBaseBytesNeeded 614400L // 600K Base memory #define kPaddingBytes 204800L // 200K Padding - long bytesNeeded, bytesAvail; + long bytesNeeded; long soundBytes, musicBytes; dontLoadMusic = false; @@ -484,7 +485,7 @@ void CheckMemorySize (void) bytesNeeded += sizeof(objDataType) * kMaxMasterObjects; bytesNeeded += kDemoLength; SpinCursor(1); - bytesAvail = FreeMem(); SpinCursor(1); + SpinCursor(1); } void GetDeviceRect(Rect *rect) diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index 7b4ebb9..d4ae019 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -14,6 +14,7 @@ #include "Externs.h" #include "Environ.h" #include "House.h" +#include "InputManager.h" #include "ObjectEdit.h" @@ -162,9 +163,9 @@ void HandleMouseEvent (const GpMouseInputEvent &theEvent, uint32_t tick) void HandleKeyEvent (const KeyDownStates &keyStates, const GpKeyboardInputEvent &theEvent) { const intptr_t theChar = PackVOSKeyCode(theEvent); - const bool shiftDown = BitTst(keyStates, PL_KEY_EITHER_SPECIAL(kShift)); - const bool commandDown = BitTst(keyStates, PL_KEY_EITHER_SPECIAL(kControl)); - const bool optionDown = BitTst(keyStates, PL_KEY_EITHER_SPECIAL(kAlt)); + const bool shiftDown = keyStates.IsSet(PL_KEY_EITHER_SPECIAL(kShift)); + const bool commandDown = keyStates.IsSet(PL_KEY_EITHER_SPECIAL(kControl)); + const bool optionDown = keyStates.IsSet(PL_KEY_EITHER_SPECIAL(kAlt)); if ((commandDown) && (!optionDown)) DoMenuChoice(MenuKey(static_cast(theChar))); @@ -458,18 +459,17 @@ void HandleIdleTask (void) void HandleEvent (void) { - KeyDownStates eventKeys; TimeTaggedVOSEvent theEvent; uint32_t sleep = 2; bool itHappened = true; - - GetKeys(eventKeys); - if ((BitTst(eventKeys, PL_KEY_EITHER_SPECIAL(kControl))) && - (BitTst(eventKeys, PL_KEY_EITHER_SPECIAL(kAlt)))) + + const KeyDownStates *eventKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + if ((eventKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) && + (eventKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt)))) { HiliteAllObjects(); } - else if ((BitTst(eventKeys, PL_KEY_EITHER_SPECIAL(kAlt))) && (theMode == kEditMode) && + else if ((eventKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt))) && (theMode == kEditMode) && (houseUnlocked)) { EraseSelectedTool(); @@ -497,7 +497,7 @@ void HandleEvent (void) { case GpKeyboardInputEventTypes::kDown: case GpKeyboardInputEventTypes::kAuto: - HandleKeyEvent(eventKeys, theEvent.m_vosEvent.m_event.m_keyboardInputEvent); + HandleKeyEvent(*eventKeys, theEvent.m_vosEvent.m_event.m_keyboardInputEvent); break; default: break; diff --git a/GpApp/GameOver.cpp b/GpApp/GameOver.cpp index 093d726..38c6676 100644 --- a/GpApp/GameOver.cpp +++ b/GpApp/GameOver.cpp @@ -14,6 +14,7 @@ #include "Environ.h" #include "FontManager.h" #include "FontFamily.h" +#include "InputManager.h" #include "MainWindow.h" #include "Objects.h" #include "RectUtils.h" @@ -141,7 +142,6 @@ void DoGameOverStarAnimation (void) { #define kStarFalls 8 TimeTaggedVOSEvent theEvent; - KeyDownStates theKeys; Rect angelDest; long nextLoop; short which, i, count, pass; @@ -212,8 +212,9 @@ void DoGameOverStarAnimation (void) do { - GetKeys(theKeys); - if ((BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl))) || (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kAlt))) || (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kShift)))) + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if ((theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) || (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt))) || (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift)))) noInteruption = false; if (PortabilityLayer::EventQueue::GetInstance()->Dequeue(&theEvent)) @@ -442,7 +443,6 @@ void DrawPages (void) void DoDiedGameOver (void) { TimeTaggedVOSEvent theEvent; - KeyDownStates theKeys; long nextLoop; Boolean userAborted; @@ -459,8 +459,9 @@ void DoDiedGameOver (void) DrawPages(); do { - GetKeys(theKeys); - if ((BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kAlt))) || (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl))) || (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kShift)))) + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if ((theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt))) || (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) || (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift)))) { pagesStuck = 8; userAborted = true; diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 705a42a..85bccc4 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -89,7 +89,7 @@ void OpenHouseMovie (void) if (theErr != PLErrors::kNone) return; - theErr = OpenMovieFile(theSpec, &movieRefNum, fsCurPerm); + theErr = OpenMovieFile(theSpec, &movieRefNum, 0); if (theErr != PLErrors::kNone) { YellowAlert(kYellowQTMovieNotLoaded, theErr); diff --git a/GpApp/Input.cpp b/GpApp/Input.cpp index 81b05a3..9fb117e 100644 --- a/GpApp/Input.cpp +++ b/GpApp/Input.cpp @@ -31,7 +31,6 @@ Boolean QuerySaveGame (void); demoPtr demoData; -KeyDownStates theKeys; Dialog *saveDial; short demoIndex, batteryFrame; Boolean isEscPauseKey, paused, batteryWasEngaged; @@ -54,8 +53,10 @@ void LogDemoKey (char keyIs) //-------------------------------------------------------------- DoCommandKey void DoCommandKey (void) -{ - if (BitTst(theKeys, PL_KEY_ASCII('Q'))) +{ + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (theKeys->IsSet(PL_KEY_ASCII('Q'))) { playing = false; paused = false; @@ -65,7 +66,7 @@ void DoCommandKey (void) SaveGame2(); // New save game. } } - else if ((BitTst(theKeys, PL_KEY_ASCII('S'))) && (!twoPlayerGame)) + else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) { RefreshScoreboard(kSavingTitleMode); SaveGame2(); // New save game. @@ -89,23 +90,27 @@ void DoPause (void) LoadScaledGraphic(surface, kEscPausePictID, &bounds); else LoadScaledGraphic(surface, kTabPausePictID, &bounds); - + + const KeyDownStates *theKeys = nullptr; + do { - GetKeys(theKeys); + theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + Delay(1, nullptr); } - while ((isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kEscape))) || - (!isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kTab)))); + while ((isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kEscape))) || + (!isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kTab)))); paused = true; while (paused) { - GetKeys(theKeys); - if ((isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kEscape))) || - (!isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kTab)))) + theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if ((isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kEscape))) || + (!isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kTab)))) paused = false; - else if (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl))) + else if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) DoCommandKey(); Delay(1, nullptr); @@ -117,11 +122,11 @@ void DoPause (void) do { - GetKeys(theKeys); + theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); Delay(1, nullptr); } - while ((isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kEscape))) || - (!isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kTab)))); + while ((isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kEscape))) || + (!isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kTab)))); } //-------------------------------------------------------------- DoBatteryEngaged @@ -193,20 +198,21 @@ void DoHeliumEngaged (gliderPtr thisGlider) void GetDemoInput (gliderPtr thisGlider) { + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + if (thisGlider->which == kPlayer1) { - GetKeys(theKeys); #if BUILD_ARCADE_VERSION - if ((BitTst(theKeys, thisGlider->leftKey)) || - (BitTst(theKeys, thisGlider->gamepadLeftKey)) || - (BitTst(theKeys, thisGlider->rightKey)) || - (BitTst(theKeys, thisGlider->gamepadRightKey)) || - (BitTst(theKeys, thisGlider->battKey)) || - (BitTst(theKeys, thisGlider->gamepadBattKey)) || - (BitTst(theKeys, thisGlider->bandKey)) || - (BitTst(theKeys, thisGlider->gamepadBandKey))) + if ((theKeys->IsSet(thisGlider->leftKey)) || + (theKeys->IsSet(thisGlider->gamepadLeftKey)) || + (theKeys->IsSet(thisGlider->rightKey)) || + (theKeys->IsSet(thisGlider->gamepadRightKey)) || + (theKeys->IsSet(thisGlider->battKey)) || + (theKeys->IsSet(thisGlider->gamepadBattKey)) || + (theKeys->IsSet(thisGlider->bandKey)) || + (theKeys->IsSet(thisGlider->gamepadBandKey))) { playing = false; paused = false; @@ -214,7 +220,7 @@ void DoHeliumEngaged (gliderPtr thisGlider) #else - if (BitTst(&theKeys, kCommandKeyMap)) + if (theKeys->IsSet(kCommandKeyMap)) DoCommandKey(); #endif @@ -280,8 +286,8 @@ void DoHeliumEngaged (gliderPtr thisGlider) else thisGlider->fireHeld = false; - if ((isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kEscape))) || - (!isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kTab)))) + if ((isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kEscape))) || + (!isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kTab)))) { DoPause(); } @@ -294,8 +300,9 @@ void GetInput (gliderPtr thisGlider) { if (thisGlider->which == kPlayer1) { - GetKeys(theKeys); - if (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl))) + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) DoCommandKey(); } @@ -313,33 +320,35 @@ void GetInput (gliderPtr thisGlider) bool leftState = false; bool rightState = false; - if (BitTst(theKeys, thisGlider->rightKey) || BitTst(theKeys, thisGlider->gamepadRightKey)) // right key + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (theKeys->IsSet(thisGlider->rightKey) || theKeys->IsSet(thisGlider->gamepadRightKey)) // right key { PL_NotYetImplemented_TODO("FixDemo"); // Flips aren't recorded in the demo properly - if (BitTst(theKeys, thisGlider->leftKey) || BitTst(theKeys, thisGlider->gamepadLeftKey)) + if (theKeys->IsSet(thisGlider->leftKey) || theKeys->IsSet(thisGlider->gamepadLeftKey)) continuousFlipState = true; else rightState = true; } - else if (BitTst(theKeys, thisGlider->leftKey) || BitTst(theKeys, thisGlider->gamepadLeftKey)) // left key + else if (theKeys->IsSet(thisGlider->leftKey) || theKeys->IsSet(thisGlider->gamepadLeftKey)) // left key leftState = true; else thisGlider->tipped = false; - if (BitTst(theKeys, thisGlider->gamepadRightKey)) + if (theKeys->IsSet(thisGlider->gamepadRightKey)) rightState = true; - if (BitTst(theKeys, thisGlider->gamepadLeftKey)) + if (theKeys->IsSet(thisGlider->gamepadLeftKey)) leftState = true; - if (BitTst(theKeys, thisGlider->gamepadFaceLeftKey) && thisGlider->facing == kFaceRight) + if (theKeys->IsSet(thisGlider->gamepadFaceLeftKey) && thisGlider->facing == kFaceRight) continuousFlipState = true; - if (BitTst(theKeys, thisGlider->gamepadFaceRightKey) && thisGlider->facing == kFaceLeft) + if (theKeys->IsSet(thisGlider->gamepadFaceRightKey) && thisGlider->facing == kFaceLeft) continuousFlipState = true; - if (BitTst(theKeys, thisGlider->gamepadFlipKey)) + if (theKeys->IsSet(thisGlider->gamepadFlipKey)) holdFlipState = true; if (thisGlider->which == kPlayer1 || thisGlider->which == kPlayer2) @@ -397,7 +406,7 @@ void GetInput (gliderPtr thisGlider) if (!leftState && !rightState) thisGlider->tipped = false; - if ((BitTst(theKeys, thisGlider->battKey) || BitTst(theKeys, thisGlider->gamepadBattKey)) && (batteryTotal != 0) && + if ((theKeys->IsSet(thisGlider->battKey) || theKeys->IsSet(thisGlider->gamepadBattKey)) && (batteryTotal != 0) && (thisGlider->mode == kGliderNormal)) { #ifdef CREATEDEMODATA @@ -411,7 +420,7 @@ void GetInput (gliderPtr thisGlider) else batteryWasEngaged = false; - if ((BitTst(theKeys, thisGlider->bandKey) || BitTst(theKeys, thisGlider->gamepadBandKey)) && (bandsTotal > 0) && + if ((theKeys->IsSet(thisGlider->bandKey) || theKeys->IsSet(thisGlider->gamepadBandKey)) && (bandsTotal > 0) && (thisGlider->mode == kGliderNormal)) { #ifdef CREATEDEMODATA @@ -434,14 +443,14 @@ void GetInput (gliderPtr thisGlider) thisGlider->fireHeld = false; if ((otherPlayerEscaped != kNoOneEscaped) && - (BitTst(theKeys, PL_KEY_SPECIAL(kDelete))) && + (theKeys->IsSet(PL_KEY_SPECIAL(kDelete))) && (thisGlider->which) && (!onePlayerLeft)) { ForceKillGlider(); } - if ((isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kEscape))) || - (!isEscPauseKey && BitTst(theKeys, PL_KEY_SPECIAL(kTab)))) + if ((isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kEscape))) || + (!isEscPauseKey && theKeys->IsSet(PL_KEY_SPECIAL(kTab)))) { DoPause(); } diff --git a/GpApp/MainWindow.cpp b/GpApp/MainWindow.cpp index 5ac8a41..a18fdaa 100644 --- a/GpApp/MainWindow.cpp +++ b/GpApp/MainWindow.cpp @@ -12,6 +12,7 @@ #include "Environ.h" #include "FontFamily.h" #include "House.h" +#include "InputManager.h" #include "MenuManager.h" #include "RectUtils.h" #include "PLKeyEncoding.h" @@ -378,7 +379,6 @@ void UpdateEditWindowTitle (void) void HandleMainClick (Point wherePt, Boolean isDoubleClick) { - KeyDownStates theseKeys; if ((theMode != kEditMode) || (mainWindow == nil) || (!houseUnlocked)) @@ -393,9 +393,10 @@ void HandleMainClick (Point wherePt, Boolean isDoubleClick) DoSelectionClick(mainWindowSurface, wherePt, isDoubleClick); else DoNewObjectClick(wherePt); - - GetKeys(theseKeys); - if (!BitTst(theseKeys, PL_KEY_EITHER_SPECIAL(kShift))) + + const KeyDownStates *theseKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (!theseKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift))) { EraseSelectedTool(); SelectTool(kSelectTool); diff --git a/GpApp/ObjectAdd.cpp b/GpApp/ObjectAdd.cpp index 62788e8..a859ae9 100644 --- a/GpApp/ObjectAdd.cpp +++ b/GpApp/ObjectAdd.cpp @@ -9,6 +9,7 @@ #include "PLToolUtils.h" #include "PLKeyEncoding.h" #include "Externs.h" +#include "InputManager.h" #include "ObjectEdit.h" #include "RectUtils.h" @@ -48,7 +49,6 @@ short wasFlower; Boolean AddNewObject (Point where, short what, Boolean showItNow) { - KeyDownStates theseKeys; Rect srcRect, newRect; short direction, dist; Boolean handled, drawWholeRoom; @@ -738,13 +738,16 @@ Boolean AddNewObject (Point where, short what, Boolean showItNow) break; case kFlower: - GetKeys(theseKeys); - if (!BitTst(theseKeys, PL_KEY_EITHER_SPECIAL(kShift))) - wasFlower = RandomInt(kNumFlowers); - newRect = flowerSrc[wasFlower]; - CenterRectOnPoint(&newRect, where); - thisRoom->objects[objActive].data.i.bounds = newRect; - thisRoom->objects[objActive].data.i.pict = wasFlower; + { + const KeyDownStates *theseKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (!theseKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift))) + wasFlower = RandomInt(kNumFlowers); + newRect = flowerSrc[wasFlower]; + CenterRectOnPoint(&newRect, where); + thisRoom->objects[objActive].data.i.bounds = newRect; + thisRoom->objects[objActive].data.i.pict = wasFlower; + } break; case kOzma: diff --git a/GpApp/ObjectEdit.cpp b/GpApp/ObjectEdit.cpp index 2ee61a5..27e0130 100644 --- a/GpApp/ObjectEdit.cpp +++ b/GpApp/ObjectEdit.cpp @@ -10,6 +10,7 @@ #include "PLPasStr.h" #include "Externs.h" #include "House.h" +#include "InputManager.h" #include "MainWindow.h" #include "Marquee.h" #include "ObjectEdit.h" @@ -2683,7 +2684,7 @@ void DrawThisRoomsObjects (void) void HiliteAllObjects (void) { #ifndef COMPILEDEMO - KeyDownStates theseKeys; + const KeyDownStates *theseKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); short i; Pattern dummyPattern; @@ -2701,10 +2702,10 @@ void HiliteAllObjects (void) do { - GetKeys(theseKeys); + Delay(1, nullptr); } - while ((BitTst(theseKeys, PL_KEY_EITHER_SPECIAL(kControl))) && - (BitTst(theseKeys, PL_KEY_EITHER_SPECIAL(kAlt)))); + while ((theseKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl))) && + (theseKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt)))); for (i = 0; i < kMaxRoomObs; i++) surface->InvertFrameRect(roomObjectRects[i], dummyPattern); diff --git a/GpApp/Room.cpp b/GpApp/Room.cpp index 92aed83..7d59c16 100644 --- a/GpApp/Room.cpp +++ b/GpApp/Room.cpp @@ -12,6 +12,7 @@ #include "Externs.h" #include "FontFamily.h" #include "House.h" +#include "InputManager.h" #include "MainWindow.h" #include "RectUtils.h" @@ -161,7 +162,6 @@ void SetInitialTiles (short background, Boolean doRoom) #ifndef COMPILEDEMO Boolean CreateNewRoom (short h, short v) { - KeyDownStates theKeys; long howMuch; PLError_t theErr; short i, availableRoom; @@ -221,9 +221,10 @@ Boolean CreateNewRoom (short h, short v) noRoomAtAll = false; fileDirty = true; UpdateMenus(false); - - GetKeys(theKeys); - if (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kShift))) + + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift))) newRoomNow = false; else newRoomNow = autoRoomEdit; // Flag to bring up RoomInfo diff --git a/GpApp/Utilities.cpp b/GpApp/Utilities.cpp index abb2350..a761b25 100644 --- a/GpApp/Utilities.cpp +++ b/GpApp/Utilities.cpp @@ -379,7 +379,6 @@ long LongSquareRoot (long theNumber) Boolean WaitForInputEvent (short seconds) { TimeTaggedVOSEvent theEvent; - KeyDownStates theKeys; long timeToBail; Boolean waiting, didResume; @@ -387,11 +386,13 @@ Boolean WaitForInputEvent (short seconds) FlushEvents(everyEvent, 0); waiting = true; didResume = false; + while (waiting) { - GetKeys(theKeys); - if (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl)) || BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kAlt)) || BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kShift))) + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl)) || theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt)) || theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kShift))) waiting = false; if (PortabilityLayer::EventQueue::GetInstance()->Dequeue(&theEvent)) @@ -414,15 +415,15 @@ Boolean WaitForInputEvent (short seconds) void WaitCommandQReleased (void) { - KeyDownStates theKeys; Boolean waiting; waiting = true; while (waiting) { - GetKeys(theKeys); - if (!BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kControl)) || !BitTst(theKeys, PL_KEY_ASCII('Q'))) + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); + + if (!theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kControl)) || !theKeys->IsSet(PL_KEY_ASCII('Q'))) waiting = false; Delay(1, nullptr); @@ -464,10 +465,9 @@ void GetKeyName (intptr_t message, StringPtr theName) Boolean OptionKeyDown (void) { - KeyDownStates theKeys; + const KeyDownStates *theKeys = PortabilityLayer::InputManager::GetInstance()->GetKeys(); - GetKeys(theKeys); - if (BitTst(theKeys, PL_KEY_EITHER_SPECIAL(kAlt))) + if (theKeys->IsSet(PL_KEY_EITHER_SPECIAL(kAlt))) return (true); else return (false); diff --git a/PortabilityLayer/InputManager.cpp b/PortabilityLayer/InputManager.cpp index be199b5..fef420d 100644 --- a/PortabilityLayer/InputManager.cpp +++ b/PortabilityLayer/InputManager.cpp @@ -12,7 +12,7 @@ namespace PortabilityLayer public: InputManagerImpl(); - void GetKeys(KeyDownStates &keyMap) const override; + const KeyDownStates *GetKeys() const override; void ApplyKeyboardEvent(const GpKeyboardInputEvent &vosEvent) override; void ApplyGamepadEvent(const GpGamepadInputEvent &vosEvent) override; int16_t GetGamepadAxis(unsigned int playerNum, GpGamepadAxis_t gamepadAxis) override; @@ -30,9 +30,9 @@ namespace PortabilityLayer static InputManagerImpl ms_instance; }; - void InputManagerImpl::GetKeys(KeyDownStates &keyMap) const + const KeyDownStates *InputManagerImpl::GetKeys() const { - keyMap = m_keyMap; + return &m_keyMap; } void InputManagerImpl::ApplyKeyboardEvent(const GpKeyboardInputEvent &vosEvent) diff --git a/PortabilityLayer/InputManager.h b/PortabilityLayer/InputManager.h index 698db48..611c6b8 100644 --- a/PortabilityLayer/InputManager.h +++ b/PortabilityLayer/InputManager.h @@ -11,7 +11,7 @@ namespace PortabilityLayer class InputManager { public: - virtual void GetKeys(KeyDownStates &keys16) const = 0; + virtual const KeyDownStates *GetKeys() const = 0; virtual void ApplyKeyboardEvent(const GpKeyboardInputEvent &vosEvent) = 0; virtual void ApplyGamepadEvent(const GpGamepadInputEvent &vosEvent) = 0; virtual int16_t GetGamepadAxis(unsigned int playerNum, GpGamepadAxis_t gamepadAxis) = 0; diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index 4e0d0fd..9f9350e 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -274,11 +274,6 @@ long TickCount() return PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount(); } -void GetKeys(KeyDownStates &keyMap) -{ - PortabilityLayer::InputManager::GetInstance()->GetKeys(keyMap); -} - short LoWord(Int32 v) { return ((v ^ 0x8000) & 0xffff) - 0x8000; @@ -289,60 +284,6 @@ short HiWord(Int32 v) return (((v >> 16) ^ 0x8000) & 0xffff) - 0x8000; } -static bool BitTestEitherSpecial(const KeyDownStates &keyMap, int eitherSpecial) -{ - switch (eitherSpecial) - { - case KeyEventEitherSpecialCategories::kAlt: - return keyMap.m_special.Get(GpKeySpecials::kLeftAlt) || keyMap.m_special.Get(GpKeySpecials::kRightAlt); - case KeyEventEitherSpecialCategories::kShift: - return keyMap.m_special.Get(GpKeySpecials::kLeftShift) || keyMap.m_special.Get(GpKeySpecials::kRightShift); - case KeyEventEitherSpecialCategories::kControl: - return keyMap.m_special.Get(GpKeySpecials::kLeftCtrl) || keyMap.m_special.Get(GpKeySpecials::kRightCtrl); - default: - assert(false); - return false; - } -} - -bool BitTst(const KeyDownStates &keyMap, int encodedKey) -{ - const KeyEventType evtType = PL_KEY_GET_EVENT_TYPE(encodedKey); - const int evtValue = PL_KEY_GET_VALUE(encodedKey); - - switch (evtType) - { - case KeyEventType_Special: - return keyMap.m_special.Get(evtValue); - case KeyEventType_ASCII: - return keyMap.m_ascii.Get(evtValue); - case KeyEventType_MacRoman: - assert(evtValue >= 128 && evtValue < 256); - return keyMap.m_macRoman.Get(evtValue - 128); - case KeyEventType_NumPadNumber: - return keyMap.m_numPadNumber.Get(evtValue); - case KeyEventType_NumPadSpecial: - return keyMap.m_numPadSpecial.Get(evtValue); - case KeyEventType_FKey: - assert(evtValue >= 1 && evtValue <= GpFKeyMaximumInclusive); - return keyMap.m_fKey.Get(evtValue - 1); - case KeyEventType_EitherSpecial: - return BitTestEitherSpecial(keyMap, evtValue); - case KeyEventType_GamepadButton: - { - unsigned int playerNum = evtValue & ((1 << PL_INPUT_PLAYER_INDEX_BITS) - 1); - assert(playerNum < PL_INPUT_MAX_PLAYERS); - unsigned int button = evtValue >> PL_INPUT_PLAYER_INDEX_BITS; - - return keyMap.m_gamepadButtons[playerNum].Get(button); - } - break; - default: - assert(false); - return false; - } -} - void NumToString(long number, unsigned char *str) { unsigned char *firstChar = str + 1; @@ -408,13 +349,6 @@ void ParamText(const PLPasStr &title, const PLPasStr &a, const PLPasStr &b, cons PL_NotYetImplemented(); } - -UInt32 FreeMem() -{ - PL_NotYetImplemented_Minor(); - return 256 * 1024 * 1024; -} - PLError_t AEProcessAppleEvent(EventRecord *evt) { PL_NotYetImplemented(); @@ -446,13 +380,6 @@ void GetIndString(unsigned char *str, int stringsID, int fnameIndex) } } -PLError_t PBDirCreate(HFileParam *fileParam, bool asynchronous) -{ - PL_NotYetImplemented(); - return PLErrors::kNone; -} - - VFileSpec MakeVFileSpec(PortabilityLayer::VirtualDirectory_t dir, const PLPasStr &fileName) { VFileSpec spec; diff --git a/PortabilityLayer/PLCore.h b/PortabilityLayer/PLCore.h index 19e0a48..493c3c8 100644 --- a/PortabilityLayer/PLCore.h +++ b/PortabilityLayer/PLCore.h @@ -232,18 +232,6 @@ static const int everyEvent = -1; static const int iBeamCursor = 1; static const int watchCursor = 4; -static const int shiftKey = 0x1; -static const int cmdKey = 0x2; // Ctrl -static const int optionKey = 0x4; // Alt - -static const bool kCreateFolder = true; -static const bool kDontCreateFolder = false; - -static const int fsRdPerm = 1; -static const int fsWrPerm = 2; -static const int fsRdWrPerm = (fsRdPerm | fsWrPerm); -static const int fsCurPerm = 4; // Any allowed permission - static const Boolean TRUE = 1; static const Boolean FALSE = 0; @@ -290,28 +278,21 @@ long MenuSelect(Point point); // Breaks into menu select routine (in practice we long MenuKey(int charCode); long TickCount(); -void GetKeys(KeyDownStates &keyMap); short LoWord(Int32 v); short HiWord(Int32 v); -bool BitTst(const KeyDownStates &keyMap, int bit); void NumToString(long number, unsigned char *str); void ParamText(const PLPasStr &title, const PLPasStr &a, const PLPasStr &b, const PLPasStr &c); -UInt32 FreeMem(); - PLError_t AEProcessAppleEvent(EventRecord *evt); void GetIndString(unsigned char *str, int stringsID, int fnameIndex); // Fetches a string resource of some sort -PLError_t PBDirCreate(HFileParam *fileParam, bool asynchronous); VFileSpec MakeVFileSpec(PortabilityLayer::VirtualDirectory_t dir, const PLPasStr &fileName); PLError_t FSpGetFInfo(const VFileSpec &spec, VFileInfo &finfoOut); -PLError_t PBGetCatInfo(CInfoPBPtr paramBlock, Boolean async); - DirectoryFileListEntry *GetDirectoryFiles(PortabilityLayer::VirtualDirectory_t dirID); void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL); diff --git a/PortabilityLayer/PLKeyEncoding.cpp b/PortabilityLayer/PLKeyEncoding.cpp new file mode 100644 index 0000000..f9199d9 --- /dev/null +++ b/PortabilityLayer/PLKeyEncoding.cpp @@ -0,0 +1,57 @@ +#include "PLKeyEncoding.h" + +#include + +static bool BitTestEitherSpecial(const KeyDownStates &keyMap, int eitherSpecial) +{ + switch (eitherSpecial) + { + case KeyEventEitherSpecialCategories::kAlt: + return keyMap.m_special.Get(GpKeySpecials::kLeftAlt) || keyMap.m_special.Get(GpKeySpecials::kRightAlt); + case KeyEventEitherSpecialCategories::kShift: + return keyMap.m_special.Get(GpKeySpecials::kLeftShift) || keyMap.m_special.Get(GpKeySpecials::kRightShift); + case KeyEventEitherSpecialCategories::kControl: + return keyMap.m_special.Get(GpKeySpecials::kLeftCtrl) || keyMap.m_special.Get(GpKeySpecials::kRightCtrl); + default: + assert(false); + return false; + } +} + +bool KeyDownStates::IsSet(intptr_t encodedKey) const +{ + const KeyEventType evtType = PL_KEY_GET_EVENT_TYPE(encodedKey); + const int evtValue = PL_KEY_GET_VALUE(encodedKey); + + switch (evtType) + { + case KeyEventType_Special: + return m_special.Get(evtValue); + case KeyEventType_ASCII: + return m_ascii.Get(evtValue); + case KeyEventType_MacRoman: + assert(evtValue >= 128 && evtValue < 256); + return m_macRoman.Get(evtValue - 128); + case KeyEventType_NumPadNumber: + return m_numPadNumber.Get(evtValue); + case KeyEventType_NumPadSpecial: + return m_numPadSpecial.Get(evtValue); + case KeyEventType_FKey: + assert(evtValue >= 1 && evtValue <= GpFKeyMaximumInclusive); + return m_fKey.Get(evtValue - 1); + case KeyEventType_EitherSpecial: + return BitTestEitherSpecial(*this, evtValue); + case KeyEventType_GamepadButton: + { + unsigned int playerNum = evtValue & ((1 << PL_INPUT_PLAYER_INDEX_BITS) - 1); + assert(playerNum < PL_INPUT_MAX_PLAYERS); + unsigned int button = evtValue >> PL_INPUT_PLAYER_INDEX_BITS; + + return m_gamepadButtons[playerNum].Get(button); + } + break; + default: + assert(false); + return false; + } +} diff --git a/PortabilityLayer/PLKeyEncoding.h b/PortabilityLayer/PLKeyEncoding.h index 2640e46..9effe47 100644 --- a/PortabilityLayer/PLKeyEncoding.h +++ b/PortabilityLayer/PLKeyEncoding.h @@ -60,4 +60,6 @@ struct KeyDownStates GpBitfield m_numPadSpecial; GpBitfield m_fKey; GpBitfield m_gamepadButtons[PL_INPUT_MAX_PLAYERS]; + + bool IsSet(intptr_t packedVOSCode) const; }; diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj index 4c2435a..8c679a1 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj +++ b/PortabilityLayer/PortabilityLayer.vcxproj @@ -319,6 +319,7 @@ + diff --git a/PortabilityLayer/PortabilityLayer.vcxproj.filters b/PortabilityLayer/PortabilityLayer.vcxproj.filters index 4c51111..2ebd8ab 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj.filters +++ b/PortabilityLayer/PortabilityLayer.vcxproj.filters @@ -692,5 +692,8 @@ Source Files + + Source Files + \ No newline at end of file