2015-10-30 22:39:21 -04:00
|
|
|
#include <cassert>
|
2016-07-26 00:52:31 +01:00
|
|
|
#include <cstring>
|
2015-10-31 20:38:27 -04:00
|
|
|
#include "PH_Generic.h"
|
2015-05-06 02:00:14 -04:00
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
CPH_Generic::CPH_Generic()
|
2015-05-06 02:00:14 -04:00
|
|
|
{
|
2015-05-16 23:07:24 -04:00
|
|
|
memset(&m_buttonStates, 0, sizeof(m_buttonStates));
|
2015-06-30 05:26:01 -04:00
|
|
|
memset(&m_axisStates, 0, sizeof(m_axisStates));
|
2015-05-06 02:00:14 -04:00
|
|
|
}
|
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
CPH_Generic::~CPH_Generic()
|
2015-05-06 02:00:14 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
CPadHandler::FactoryFunction CPH_Generic::GetFactoryFunction()
|
2015-05-06 02:00:14 -04:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
return []() { return new CPH_Generic(); };
|
2015-05-06 02:00:14 -04:00
|
|
|
}
|
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
void CPH_Generic::Update(uint8* ram)
|
2015-05-06 02:00:14 -04:00
|
|
|
{
|
|
|
|
for(auto& listener : m_listeners)
|
|
|
|
{
|
2015-05-16 23:07:24 -04:00
|
|
|
for(unsigned int i = 0; i < PS2::CControllerInfo::MAX_BUTTONS; i++)
|
|
|
|
{
|
|
|
|
auto button = static_cast<PS2::CControllerInfo::BUTTON>(i);
|
2015-06-30 05:26:01 -04:00
|
|
|
if(PS2::CControllerInfo::IsAxis(button))
|
|
|
|
{
|
|
|
|
float buttonValue = ((m_axisStates[i] + 1.0f) / 2.0f) * 255.f;
|
|
|
|
listener->SetAxisState(0, button, static_cast<uint8>(buttonValue), ram);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
listener->SetButtonState(0, button, m_buttonStates[i], ram);
|
|
|
|
}
|
2015-05-16 23:07:24 -04:00
|
|
|
}
|
2015-05-06 02:00:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
void CPH_Generic::SetButtonState(uint32 buttonId, bool pressed)
|
2015-05-06 02:00:14 -04:00
|
|
|
{
|
2015-10-30 22:39:21 -04:00
|
|
|
assert(buttonId < PS2::CControllerInfo::MAX_BUTTONS);
|
|
|
|
m_buttonStates[buttonId] = pressed;
|
2015-05-06 02:00:14 -04:00
|
|
|
}
|
2015-06-30 05:26:01 -04:00
|
|
|
|
2015-10-31 20:38:27 -04:00
|
|
|
void CPH_Generic::SetAxisState(uint32 buttonId, float value)
|
2015-06-30 05:26:01 -04:00
|
|
|
{
|
2015-10-30 22:39:21 -04:00
|
|
|
assert(buttonId < PS2::CControllerInfo::MAX_BUTTONS);
|
|
|
|
m_axisStates[buttonId] = value;
|
2015-06-30 05:26:01 -04:00
|
|
|
}
|