From 25bd55b7aae4aedac60d60a2890172f329e8e2c4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 6 Jul 2015 13:34:11 -0400 Subject: [PATCH] Core: Use clamps for nunchuk and wiimote x,y,z values --- .../Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp | 16 ++++------------ Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp index 3af7359897..2796e473f3 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/MathUtil.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h" @@ -93,18 +94,9 @@ void Nunchuk::GetState(u8* const data) s16 accel_y = (s16)(4 * (accel.y * ACCEL_RANGE + ACCEL_ZERO_G)); s16 accel_z = (s16)(4 * (accel.z * ACCEL_RANGE + ACCEL_ZERO_G)); - if (accel_x > 1024) - accel_x = 1024; - else if (accel_x < 0) - accel_x = 0; - if (accel_y > 1024) - accel_y = 1024; - else if (accel_y < 0) - accel_y = 0; - if (accel_z > 1024) - accel_z = 1024; - else if (accel_z < 0) - accel_z = 0; + accel_x = MathUtil::Clamp(accel_x, 0, 1024); + accel_y = MathUtil::Clamp(accel_y, 0, 1024); + accel_z = MathUtil::Clamp(accel_z, 0, 1024); ncdata->ax = (accel_x >> 2) & 0xFF; ncdata->ay = (accel_y >> 2) & 0xFF; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 1d54096bc0..3f79f5363f 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -6,6 +6,7 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" +#include "Common/MathUtil.h" #include "Common/Timer.h" #include "Core/ConfigManager.h" #include "Core/Host.h" @@ -403,18 +404,9 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf) s16 y = (s16)(4 * (m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G)); s16 z = (s16)(4 * (m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G)); - if (x > 1024) - x = 1024; - else if (x < 0) - x = 0; - if (y > 1024) - y = 1024; - else if (y < 0) - y = 0; - if (z > 1024) - z = 1024; - else if (z < 0) - z = 0; + x = MathUtil::Clamp(x, 0, 1024); + y = MathUtil::Clamp(y, 0, 1024); + z = MathUtil::Clamp(z, 0, 1024); accel.x = (x >> 2) & 0xFF; accel.y = (y >> 2) & 0xFF;