Refactoring

This commit is contained in:
elasota
2020-01-05 16:41:04 -05:00
parent 1fba6f9e85
commit 645a997c7a
18 changed files with 174 additions and 186 deletions

View File

@@ -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)

View File

@@ -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<int>(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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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:

View File

@@ -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);

View File

@@ -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

View File

@@ -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);