Reduce emulated shaking frequency to 6hz. (something more humanly possible) (was ~13hz)

This commit is contained in:
Jordan Woyak 2018-12-15 10:26:51 -06:00
parent a8a6bdcdd2
commit 79eb065cf3
4 changed files with 26 additions and 23 deletions

View File

@ -23,7 +23,7 @@ enum class ClassicGroup;
enum class GuitarGroup; enum class GuitarGroup;
enum class DrumsGroup; enum class DrumsGroup;
enum class TurntableGroup; enum class TurntableGroup;
} } // namespace WiimoteEmu
enum enum
{ {
@ -55,6 +55,9 @@ enum class InitializeMode
DO_NOT_WAIT_FOR_WIIMOTES, DO_NOT_WAIT_FOR_WIIMOTES,
}; };
// The Real Wii Remote sends report every ~5ms (200 Hz).
constexpr int UPDATE_FREQ = 200;
void Shutdown(); void Shutdown();
void Initialize(InitializeMode init_mode); void Initialize(InitializeMode init_mode);
void Connect(unsigned int index, bool connect); void Connect(unsigned int index, bool connect);
@ -78,7 +81,7 @@ void InterruptChannel(int number, u16 channel_id, const void* data, u32 size);
bool ButtonPressed(int number); bool ButtonPressed(int number);
void Update(int number, bool connected); void Update(int number, bool connected);
bool NetPlay_GetButtonPress(int wiimote, bool pressed); bool NetPlay_GetButtonPress(int wiimote, bool pressed);
} } // namespace Wiimote
namespace WiimoteReal namespace WiimoteReal
{ {
@ -90,4 +93,4 @@ void Pause();
void Refresh(); void Refresh();
void LoadSettings(); void LoadSettings();
} } // namespace WiimoteReal

View File

@ -14,7 +14,7 @@ class Buttons;
class ControlGroup; class ControlGroup;
class Force; class Force;
class Tilt; class Tilt;
} } // namespace ControllerEmu
namespace WiimoteEmu namespace WiimoteEmu
{ {
@ -69,4 +69,4 @@ private:
std::array<u8, 3> m_shake_soft_step{}; std::array<u8, 3> m_shake_soft_step{};
std::array<u8, 3> m_shake_hard_step{}; std::array<u8, 3> m_shake_hard_step{};
}; };
} } // namespace WiimoteEmu

View File

@ -57,6 +57,11 @@ auto const PI = TAU / 2.0;
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr int SHAKE_FREQ = 6;
// Frame count of one up/down shake
// < 9 no shake detection in "Wario Land: Shake It"
constexpr int SHAKE_STEP_MAX = ::Wiimote::UPDATE_FREQ / SHAKE_FREQ;
// clang-format off // clang-format off
static const u8 eeprom_data_0[] = { static const u8 eeprom_data_0[] = {
// IR, maybe more // IR, maybe more
@ -114,10 +119,6 @@ void UpdateCalibrationDataChecksum(std::array<u8, 0x10>& data)
void EmulateShake(AccelData* const accel, ControllerEmu::Buttons* const buttons_group, void EmulateShake(AccelData* const accel, ControllerEmu::Buttons* const buttons_group,
const double intensity, u8* const shake_step) const double intensity, u8* const shake_step)
{ {
// frame count of one up/down shake
// < 9 no shake detection in "Wario Land: Shake It"
auto const shake_step_max = 15;
// shake is a bitfield of X,Y,Z shake button states // shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = {0x01, 0x02, 0x04}; static const unsigned int btns[] = {0x01, 0x02, 0x04};
unsigned int shake = 0; unsigned int shake = 0;
@ -127,8 +128,8 @@ void EmulateShake(AccelData* const accel, ControllerEmu::Buttons* const buttons_
{ {
if (shake & (1 << i)) if (shake & (1 << i))
{ {
(&(accel->x))[i] = std::sin(TAU * shake_step[i] / shake_step_max) * intensity; (&(accel->x))[i] = std::sin(TAU * shake_step[i] / SHAKE_STEP_MAX) * intensity;
shake_step[i] = (shake_step[i] + 1) % shake_step_max; shake_step[i] = (shake_step[i] + 1) % SHAKE_STEP_MAX;
} }
else else
shake_step[i] = 0; shake_step[i] = 0;
@ -139,10 +140,6 @@ void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data,
ControllerEmu::Buttons* const buttons_group, ControllerEmu::Buttons* const buttons_group,
const DynamicConfiguration& config, u8* const shake_step) const DynamicConfiguration& config, u8* const shake_step)
{ {
// frame count of one up/down shake
// < 9 no shake detection in "Wario Land: Shake It"
auto const shake_step_max = 15;
// shake is a bitfield of X,Y,Z shake button states // shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = {0x01, 0x02, 0x04}; static const unsigned int btns[] = {0x01, 0x02, 0x04};
unsigned int shake = 0; unsigned int shake = 0;
@ -156,8 +153,8 @@ void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data,
} }
else if (dynamic_data.executing_frames_left[i] > 0) else if (dynamic_data.executing_frames_left[i] > 0)
{ {
(&(accel->x))[i] = std::sin(TAU * shake_step[i] / shake_step_max) * dynamic_data.intensity[i]; (&(accel->x))[i] = std::sin(TAU * shake_step[i] / SHAKE_STEP_MAX) * dynamic_data.intensity[i];
shake_step[i] = (shake_step[i] + 1) % shake_step_max; shake_step[i] = (shake_step[i] + 1) % SHAKE_STEP_MAX;
dynamic_data.executing_frames_left[i]--; dynamic_data.executing_frames_left[i]--;
} }
else if (shake == 0 && dynamic_data.timing[i] > 0) else if (shake == 0 && dynamic_data.timing[i] > 0)
@ -1035,11 +1032,15 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
// Buttons // Buttons
#if defined HAVE_X11 && HAVE_X11 #if defined HAVE_X11 && HAVE_X11
m_buttons->SetControlExpression(0, "Click 1"); // A // A
m_buttons->SetControlExpression(1, "Click 3"); // B m_buttons->SetControlExpression(0, "Click 1");
// B
m_buttons->SetControlExpression(1, "Click 3");
#else #else
m_buttons->SetControlExpression(0, "Click 0"); // A // A
m_buttons->SetControlExpression(1, "Click 1"); // B m_buttons->SetControlExpression(0, "Click 0");
// B
m_buttons->SetControlExpression(1, "Click 1");
#endif #endif
m_buttons->SetControlExpression(2, "1"); // 1 m_buttons->SetControlExpression(2, "1"); // 1
m_buttons->SetControlExpression(3, "2"); // 2 m_buttons->SetControlExpression(3, "2"); // 2

View File

@ -356,8 +356,7 @@ void BluetoothEmu::Update()
} }
} }
// The Real Wii Remote sends report every ~5ms (200 Hz). const u64 interval = SystemTimers::GetTicksPerSecond() / Wiimote::UPDATE_FREQ;
const u64 interval = SystemTimers::GetTicksPerSecond() / 200;
const u64 now = CoreTiming::GetTicks(); const u64 now = CoreTiming::GetTicks();
if (now - m_last_ticks > interval) if (now - m_last_ticks > interval)