mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Refactoring
This commit is contained in:
@@ -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)
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
||||
|
57
PortabilityLayer/PLKeyEncoding.cpp
Normal file
57
PortabilityLayer/PLKeyEncoding.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "PLKeyEncoding.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@@ -60,4 +60,6 @@ struct KeyDownStates
|
||||
GpBitfield<GpNumPadSpecials::kCount> m_numPadSpecial;
|
||||
GpBitfield<GpFKeyMaximumInclusive> m_fKey;
|
||||
GpBitfield<GpGamepadButtons::kCount> m_gamepadButtons[PL_INPUT_MAX_PLAYERS];
|
||||
|
||||
bool IsSet(intptr_t packedVOSCode) const;
|
||||
};
|
||||
|
@@ -319,6 +319,7 @@
|
||||
<ClCompile Include="PLIconWidget.cpp" />
|
||||
<ClCompile Include="PLImageWidget.cpp" />
|
||||
<ClCompile Include="PLInvisibleWidget.cpp" />
|
||||
<ClCompile Include="PLKeyEncoding.cpp" />
|
||||
<ClCompile Include="PLLabelWidget.cpp" />
|
||||
<ClCompile Include="PLMenus.cpp" />
|
||||
<ClCompile Include="PLMovies.cpp" />
|
||||
|
@@ -692,5 +692,8 @@
|
||||
<ClCompile Include="PLRadioButtonWidget.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PLKeyEncoding.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user