2015-08-28 00:11:31 +00:00
|
|
|
#include "CInputGenerator.hpp"
|
2015-08-29 01:30:47 +00:00
|
|
|
#include "../CArchitectureMessage.hpp"
|
|
|
|
#include "../CArchitectureQueue.hpp"
|
2015-08-28 00:11:31 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-28 00:11:31 +00:00
|
|
|
{
|
|
|
|
|
2015-08-29 01:30:47 +00:00
|
|
|
void CInputGenerator::Update(float dt, CArchitectureQueue& queue)
|
|
|
|
{
|
2016-02-21 06:34:42 +00:00
|
|
|
if (m_firstFrame)
|
|
|
|
{
|
|
|
|
m_firstFrame = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-29 01:30:47 +00:00
|
|
|
/* Keyboard/Mouse first */
|
2016-02-20 06:45:36 +00:00
|
|
|
CFinalInput kbInput = getFinalInput(0, dt);
|
2015-08-29 01:30:47 +00:00
|
|
|
bool kbUsed = false;
|
|
|
|
|
|
|
|
/* Dolphin controllers next */
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
|
|
|
{
|
|
|
|
bool connected;
|
|
|
|
EStatusChange change = m_dolphinCb.getStatusChange(i, connected);
|
2015-11-21 01:16:07 +00:00
|
|
|
if (change != EStatusChange::NoChange)
|
|
|
|
queue.Push(std::move(MakeMsg::CreateControllerStatus(EArchMsgTarget::Game, i, connected)));
|
2015-08-29 01:30:47 +00:00
|
|
|
if (connected)
|
|
|
|
{
|
|
|
|
CFinalInput input = m_dolphinCb.getFinalInput(i, dt, m_leftDiv, m_rightDiv);
|
|
|
|
if (i == 0) /* Merge KB input with first controller */
|
|
|
|
{
|
|
|
|
input |= kbInput;
|
|
|
|
kbUsed = true;
|
|
|
|
}
|
2015-11-21 01:16:07 +00:00
|
|
|
queue.Push(std::move(MakeMsg::CreateUserInput(EArchMsgTarget::Game, input)));
|
2015-08-29 01:30:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-28 00:11:31 +00:00
|
|
|
|
2015-08-29 01:30:47 +00:00
|
|
|
/* Send straight keyboard input if no first controller present */
|
|
|
|
if (!kbUsed)
|
2015-11-21 01:16:07 +00:00
|
|
|
queue.Push(std::move(MakeMsg::CreateUserInput(EArchMsgTarget::Game, kbInput)));
|
2015-08-29 01:30:47 +00:00
|
|
|
}
|
2015-08-28 00:11:31 +00:00
|
|
|
|
|
|
|
}
|