Restructure event handling

This commit is contained in:
Phillip Stephens 2016-02-19 22:45:36 -08:00
parent 4bfe4026f2
commit 5229f95fb7
4 changed files with 112 additions and 63 deletions

View File

@ -12,7 +12,9 @@ class CIOWin;
enum class EArchMsgTarget
{
IOWinManager = 0,
Game = 1
Game = 1,
/* PathShagged targets, we start at 255 */
ArchitectureSupport = 255,
};
enum class EArchMsgType
@ -28,6 +30,8 @@ enum class EArchMsgType
QuitGameplay = 8,
UpdateBegin = 10,
FrameBegin = 11,
/* PathShagged messages, we start at 255 */
ApplicationExit = 255,
};
struct IArchMsgParm
@ -143,6 +147,11 @@ public:
{
return *msg.GetParm<CArchMsgParmVoidPtr>();
}
/* PathShagged Messages */
static CArchitectureMessage CreateApplicationExit(EArchMsgTarget target)
{
return CArchitectureMessage(target, EArchMsgType::ApplicationExit, new CArchMsgParmNull());
}
};
}

View File

@ -8,7 +8,7 @@ namespace pshag
void CInputGenerator::Update(float dt, CArchitectureQueue& queue)
{
/* Keyboard/Mouse first */
CFinalInput kbInput = m_windowCb.getFinalInput(0, dt);
CFinalInput kbInput = getFinalInput(0, dt);
bool kbUsed = false;
/* Dolphin controllers next */

View File

@ -24,6 +24,7 @@ class CInputGenerator : public boo::DeviceFinder
* the logical state */
float m_leftDiv;
float m_rightDiv;
CKeyboardMouseControllerData m_data;
public:
CInputGenerator(float leftDiv, float rightDiv)
: boo::DeviceFinder({typeid(boo::DolphinSmashAdapter)}),
@ -35,70 +36,66 @@ public:
* for buffering events in its own way, then boo flushes the buffer
* at the start of each frame, invoking these methods. No atomic locking
* is necessary, only absolute state tracking. */
struct WindowCallback : boo::IWindowCallback
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey)
{
CKeyboardMouseControllerData m_data;
m_data.m_mouseButtons[int(button)] = true;
}
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey)
{
m_data.m_mouseButtons[int(button)] = false;
}
void mouseMove(const boo::SWindowCoord& coord)
{
m_data.m_mouseCoord = coord;
}
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta& scroll)
{
m_data.m_accumScroll += scroll;
}
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey)
{
m_data.m_mouseButtons[int(button)] = true;
}
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton button, boo::EModifierKey)
{
m_data.m_mouseButtons[int(button)] = false;
}
void mouseMove(const boo::SWindowCoord& coord)
{
m_data.m_mouseCoord = coord;
}
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta& scroll)
{
m_data.m_accumScroll += scroll;
}
void charKeyDown(unsigned long charCode, boo::EModifierKey, bool)
{
charCode = tolower(charCode);
if (charCode > 255)
return;
m_data.m_charKeys[charCode] = true;
}
void charKeyUp(unsigned long charCode, boo::EModifierKey mods)
{
charCode = tolower(charCode);
if (charCode > 255)
return;
m_data.m_charKeys[charCode] = false;
}
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey, bool)
{
m_data.m_specialKeys[int(key)] = true;
}
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey)
{
m_data.m_specialKeys[int(key)] = false;
}
void modKeyDown(boo::EModifierKey mod, bool)
{
m_data.m_modMask = m_data.m_modMask | mod;
}
void modKeyUp(boo::EModifierKey mod)
{
m_data.m_modMask = m_data.m_modMask & ~mod;
}
void charKeyDown(unsigned long charCode, boo::EModifierKey, bool)
{
charCode = tolower(charCode);
if (charCode > 255)
return;
m_data.m_charKeys[charCode] = true;
}
void charKeyUp(unsigned long charCode, boo::EModifierKey mods)
{
charCode = tolower(charCode);
if (charCode > 255)
return;
m_data.m_charKeys[charCode] = false;
}
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey, bool)
{
m_data.m_specialKeys[int(key)] = true;
}
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey)
{
m_data.m_specialKeys[int(key)] = false;
}
void modKeyDown(boo::EModifierKey mod, bool)
{
m_data.m_modMask = m_data.m_modMask | mod;
}
void modKeyUp(boo::EModifierKey mod)
{
m_data.m_modMask = m_data.m_modMask & ~mod;
}
void reset()
{
m_data.m_accumScroll.zeroOut();
}
void reset()
{
m_data.m_accumScroll.zeroOut();
}
CFinalInput m_lastUpdate;
const CFinalInput& getFinalInput(unsigned idx, float dt)
{
m_lastUpdate = CFinalInput(idx, dt, m_data, m_lastUpdate);
return m_lastUpdate;
}
} m_windowCb;
CFinalInput m_lastUpdate;
const CFinalInput& getFinalInput(unsigned idx, float dt)
{
m_lastUpdate = CFinalInput(idx, dt, m_data, m_lastUpdate);
return m_lastUpdate;
}
/* Input via the smash adapter is received asynchronously on a USB
* report thread. This class atomically exchanges that data to the

View File

@ -98,7 +98,7 @@ public:
}
};
class CGameArchitectureSupport
class CGameArchitectureSupport : public boo::IWindowCallback
{
CArchitectureQueue m_archQueue;
CAudioSys m_audioSys;
@ -109,6 +109,30 @@ class CGameArchitectureSupport
CMainFlow m_mainFlow;
CConsoleOutputWindow m_consoleWindow;
CAudioStateWin m_audioStateWin;
void mouseDown(const boo::SWindowCoord &coord, boo::EMouseButton button, boo::EModifierKey mods)
{ m_inputGenerator.mouseDown(coord, button, mods); }
void mouseUp(const boo::SWindowCoord &coord, boo::EMouseButton button, boo::EModifierKey mods)
{ m_inputGenerator.mouseUp(coord, button, mods); }
void mouseMove(const boo::SWindowCoord &coord)
{ m_inputGenerator.mouseMove(coord); }
void scroll(const boo::SWindowCoord &coord, const boo::SScrollDelta &scroll)
{ m_inputGenerator.scroll(coord, scroll); }
void charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat)
{ m_inputGenerator.charKeyDown(charCode, mods, isRepeat); }
void charKeyUp(unsigned long charCode, boo::EModifierKey mods)
{ m_inputGenerator.charKeyUp(charCode, mods); }
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat)
{ m_inputGenerator.specialKeyDown(key, mods, isRepeat); }
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods)
{ m_inputGenerator.specialKeyUp(key, mods); }
void modKeyDown(boo::EModifierKey mod, bool isRepeat)
{ m_inputGenerator.modKeyDown(mod, isRepeat);}
void modKeyUp(boo::EModifierKey mod)
{ m_inputGenerator.modKeyUp(mod); }
void destroyed() { m_archQueue.Push(std::move(MakeMsg::CreateApplicationExit(EArchMsgTarget::ArchitectureSupport))); }
public:
CGameArchitectureSupport()
: m_audioSys(0,0,0,0,0),
@ -120,6 +144,24 @@ public:
bool Update()
{
bool finished = false;
m_inputGenerator.Update(1.0 / 60.0, m_archQueue);
while(m_archQueue)
{
CArchitectureMessage msg = m_archQueue.Pop();
if (msg.GetTarget() == EArchMsgTarget::ArchitectureSupport)
{
if (msg.GetType() == EArchMsgType::ApplicationExit)
finished = true;
}
if (msg.GetTarget() == EArchMsgTarget::Game && msg.GetType() == EArchMsgType::UserInput)
{
const CArchMsgParmUserInput* input = msg.GetParm<CArchMsgParmUserInput>();
if (input->x4_parm.DStart())
m_archQueue.Push(std::move(MakeMsg::CreateApplicationExit(EArchMsgTarget::ArchitectureSupport)));
}
}
return finished;
}
};
@ -177,6 +219,7 @@ int CMain::appMain(boo::IApplication* app)
g_TweakManager->ReadFromMemoryCard("AudioTweaks");
FillInAssetIDs();
TOneStatic<CGameArchitectureSupport> archSupport;
mainWindow->setCallback(archSupport.GetAllocSpace());
boo::IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
float rgba[4] = { 0.2f, 0.2f, 0.2f, 1.0f};