2016-02-21 06:34:42 +00:00
|
|
|
#include "CRumbleGenerator.hpp"
|
2018-01-26 09:48:42 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
2016-02-21 06:34:42 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-21 06:34:42 +00:00
|
|
|
{
|
2017-01-13 00:16:26 +00:00
|
|
|
|
2016-02-21 06:34:42 +00:00
|
|
|
CRumbleGenerator::CRumbleGenerator()
|
|
|
|
{
|
2018-01-26 09:48:42 +00:00
|
|
|
xf0_24_disabled = false;
|
|
|
|
HardStopAll();
|
2016-02-21 06:34:42 +00:00
|
|
|
}
|
2017-01-13 00:16:26 +00:00
|
|
|
|
2018-01-26 09:48:42 +00:00
|
|
|
CRumbleGenerator::~CRumbleGenerator()
|
2017-01-13 00:16:26 +00:00
|
|
|
{
|
2018-01-26 09:48:42 +00:00
|
|
|
HardStopAll();
|
|
|
|
}
|
2017-01-13 00:16:26 +00:00
|
|
|
|
2018-01-26 09:48:42 +00:00
|
|
|
void CRumbleGenerator::Update(float dt)
|
|
|
|
{
|
|
|
|
if (!xf0_24_disabled)
|
|
|
|
{
|
|
|
|
bool updated = false;
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
|
|
|
{
|
|
|
|
float intensity = x0_voices[i].GetIntensity();
|
|
|
|
if (!x0_voices[i].Update(dt) || intensity <= 0.f)
|
|
|
|
{
|
|
|
|
xc0_periodTime[i] = 0.f;
|
|
|
|
xd0_onTime[i] = 0.f;
|
|
|
|
if (xe0_commandArray[i] != EMotorState::Stop)
|
|
|
|
{
|
|
|
|
xe0_commandArray[i] = EMotorState::Stop;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xc0_periodTime[i] += dt;
|
|
|
|
if (xc0_periodTime[i] >= 1.f / (30.f * intensity))
|
|
|
|
{
|
|
|
|
xc0_periodTime[i] = 0.f;
|
|
|
|
if (xe0_commandArray[i] != EMotorState::Rumble)
|
|
|
|
{
|
|
|
|
xe0_commandArray[i] = EMotorState::Rumble;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xd0_onTime[i] += dt;
|
|
|
|
if (xd0_onTime[i] >= (1.f / 30.f))
|
|
|
|
{
|
|
|
|
xd0_onTime[i] = 0.f;
|
|
|
|
if (xe0_commandArray[i] != EMotorState::Stop)
|
|
|
|
{
|
|
|
|
xe0_commandArray[i] = EMotorState::Stop;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated)
|
|
|
|
g_InputGenerator->ControlAllMotors(xe0_commandArray);
|
|
|
|
}
|
2017-01-13 00:16:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 09:48:42 +00:00
|
|
|
static const EMotorState HardStopCommands[] = { EMotorState::StopHard,
|
|
|
|
EMotorState::StopHard,
|
|
|
|
EMotorState::StopHard,
|
|
|
|
EMotorState::StopHard };
|
|
|
|
|
2017-01-13 00:16:26 +00:00
|
|
|
void CRumbleGenerator::HardStopAll()
|
|
|
|
{
|
2018-01-26 09:48:42 +00:00
|
|
|
for (int i=0 ; i<4 ; ++i)
|
|
|
|
{
|
|
|
|
xc0_periodTime[i] = 0.f;
|
|
|
|
xd0_onTime[i] = 0.f;
|
|
|
|
xe0_commandArray[i] = EMotorState::Stop;
|
|
|
|
x0_voices[i].HardReset();
|
|
|
|
}
|
|
|
|
g_InputGenerator->ControlAllMotors(HardStopCommands);
|
2017-01-13 00:16:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 09:48:42 +00:00
|
|
|
s16 CRumbleGenerator::Rumble(const SAdsrData& adsr, float gain, ERumblePriority prio, EIOPort port)
|
2017-01-13 00:16:26 +00:00
|
|
|
{
|
2018-01-26 09:48:42 +00:00
|
|
|
CRumbleVoice& vox = x0_voices[int(port)];
|
|
|
|
s16 freeChan = vox.GetFreeChannel();
|
|
|
|
if (prio >= vox.GetPriority(freeChan))
|
|
|
|
{
|
|
|
|
xc0_periodTime[int(port)] = 0.f;
|
|
|
|
return vox.Activate(adsr, freeChan, gain, prio);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-01-13 00:16:26 +00:00
|
|
|
|
2018-01-26 09:48:42 +00:00
|
|
|
void CRumbleGenerator::Stop(s16 id, EIOPort port)
|
|
|
|
{
|
|
|
|
CRumbleVoice& vox = x0_voices[int(port)];
|
|
|
|
vox.Deactivate(id, false);
|
2017-01-13 00:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 06:34:42 +00:00
|
|
|
}
|