Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8982 from lioncash/wii-const
WiimoteEmu: Mark several getters as const
  • Loading branch information
JosJuice committed Jul 24, 2020
2 parents 520af03 + f9b856a commit b996dcf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
44 changes: 21 additions & 23 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -287,7 +287,7 @@ std::string Wiimote::GetName() const
return fmt::format("Wiimote{}", 1 + m_index);
}

ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group)
ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const
{
switch (group)
{
Expand Down Expand Up @@ -323,52 +323,52 @@ ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group)
}
}

ControllerEmu::ControlGroup* Wiimote::GetNunchukGroup(NunchukGroup group)
ControllerEmu::ControlGroup* Wiimote::GetNunchukGroup(NunchukGroup group) const
{
return static_cast<Nunchuk*>(m_attachments->GetAttachmentList()[ExtensionNumber::NUNCHUK].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetClassicGroup(ClassicGroup group)
ControllerEmu::ControlGroup* Wiimote::GetClassicGroup(ClassicGroup group) const
{
return static_cast<Classic*>(m_attachments->GetAttachmentList()[ExtensionNumber::CLASSIC].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetGuitarGroup(GuitarGroup group)
ControllerEmu::ControlGroup* Wiimote::GetGuitarGroup(GuitarGroup group) const
{
return static_cast<Guitar*>(m_attachments->GetAttachmentList()[ExtensionNumber::GUITAR].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetDrumsGroup(DrumsGroup group)
ControllerEmu::ControlGroup* Wiimote::GetDrumsGroup(DrumsGroup group) const
{
return static_cast<Drums*>(m_attachments->GetAttachmentList()[ExtensionNumber::DRUMS].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group)
ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group) const
{
return static_cast<Turntable*>(
m_attachments->GetAttachmentList()[ExtensionNumber::TURNTABLE].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetUDrawTabletGroup(UDrawTabletGroup group)
ControllerEmu::ControlGroup* Wiimote::GetUDrawTabletGroup(UDrawTabletGroup group) const
{
return static_cast<UDrawTablet*>(
m_attachments->GetAttachmentList()[ExtensionNumber::UDRAW_TABLET].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetDrawsomeTabletGroup(DrawsomeTabletGroup group)
ControllerEmu::ControlGroup* Wiimote::GetDrawsomeTabletGroup(DrawsomeTabletGroup group) const
{
return static_cast<DrawsomeTablet*>(
m_attachments->GetAttachmentList()[ExtensionNumber::DRAWSOME_TABLET].get())
->GetGroup(group);
}

ControllerEmu::ControlGroup* Wiimote::GetTaTaConGroup(TaTaConGroup group)
ControllerEmu::ControlGroup* Wiimote::GetTaTaConGroup(TaTaConGroup group) const
{
return static_cast<TaTaCon*>(m_attachments->GetAttachmentList()[ExtensionNumber::TATACON].get())
->GetGroup(group);
Expand Down Expand Up @@ -799,7 +799,7 @@ void Wiimote::StepDynamics()
1.f / ::Wiimote::UPDATE_FREQ);
}

Common::Vec3 Wiimote::GetAcceleration(Common::Vec3 extra_acceleration)
Common::Vec3 Wiimote::GetAcceleration(Common::Vec3 extra_acceleration) const
{
Common::Vec3 accel = GetOrientation() * GetTransformation().Transform(
m_swing_state.acceleration + extra_acceleration, 0);
Expand All @@ -810,7 +810,7 @@ Common::Vec3 Wiimote::GetAcceleration(Common::Vec3 extra_acceleration)
return accel;
}

Common::Vec3 Wiimote::GetAngularVelocity(Common::Vec3 extra_angular_velocity)
Common::Vec3 Wiimote::GetAngularVelocity(Common::Vec3 extra_angular_velocity) const
{
return GetOrientation() * (m_tilt_state.angular_velocity + m_swing_state.angular_velocity +
m_point_state.angular_velocity + extra_angular_velocity);
Expand All @@ -835,22 +835,20 @@ Common::Matrix33 Wiimote::GetOrientation() const
Common::Matrix33::RotateX(float(MathUtil::TAU / 4 * IsUpright()));
}

Common::Vec3 Wiimote::GetTotalAcceleration()
Common::Vec3 Wiimote::GetTotalAcceleration() const
{
auto accel = m_imu_accelerometer->GetState();
if (accel.has_value())
return GetAcceleration(accel.value());
else
return GetAcceleration();
if (const auto accel = m_imu_accelerometer->GetState())
return GetAcceleration(*accel);

return GetAcceleration();
}

Common::Vec3 Wiimote::GetTotalAngularVelocity()
Common::Vec3 Wiimote::GetTotalAngularVelocity() const
{
auto ang_vel = m_imu_gyroscope->GetState();
if (ang_vel.has_value())
return GetAngularVelocity(ang_vel.value());
else
return GetAngularVelocity();
if (const auto ang_vel = m_imu_gyroscope->GetState())
return GetAngularVelocity(*ang_vel);

return GetAngularVelocity();
}

Common::Matrix44 Wiimote::GetTotalTransformation() const
Expand Down
26 changes: 13 additions & 13 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -114,15 +114,15 @@ class Wiimote : public ControllerEmu::EmulatedController
std::string GetName() const override;
void LoadDefaults(const ControllerInterface& ciface) override;

ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group);
ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group);
ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group);
ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group);
ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group);
ControllerEmu::ControlGroup* GetTurntableGroup(TurntableGroup group);
ControllerEmu::ControlGroup* GetUDrawTabletGroup(UDrawTabletGroup group);
ControllerEmu::ControlGroup* GetDrawsomeTabletGroup(DrawsomeTabletGroup group);
ControllerEmu::ControlGroup* GetTaTaConGroup(TaTaConGroup group);
ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group) const;
ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group) const;
ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group) const;
ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group) const;
ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group) const;
ControllerEmu::ControlGroup* GetTurntableGroup(TurntableGroup group) const;
ControllerEmu::ControlGroup* GetUDrawTabletGroup(UDrawTabletGroup group) const;
ControllerEmu::ControlGroup* GetDrawsomeTabletGroup(DrawsomeTabletGroup group) const;
ControllerEmu::ControlGroup* GetTaTaConGroup(TaTaConGroup group) const;

void Update();
void StepDynamics();
Expand All @@ -149,10 +149,10 @@ class Wiimote : public ControllerEmu::EmulatedController

// Returns simulated accelerometer data in m/s^2.
Common::Vec3 GetAcceleration(
Common::Vec3 extra_acceleration = Common::Vec3(0, 0, float(GRAVITY_ACCELERATION)));
Common::Vec3 extra_acceleration = Common::Vec3(0, 0, float(GRAVITY_ACCELERATION))) const;

// Returns simulated gyroscope data in radians/s.
Common::Vec3 GetAngularVelocity(Common::Vec3 extra_angular_velocity = {});
Common::Vec3 GetAngularVelocity(Common::Vec3 extra_angular_velocity = {}) const;

// Returns the transformation of the world around the wiimote.
// Used for simulating camera data and for rotating acceleration data.
Expand All @@ -163,8 +163,8 @@ class Wiimote : public ControllerEmu::EmulatedController
// Returns the world rotation from the effects of sideways/upright settings.
Common::Matrix33 GetOrientation() const;

Common::Vec3 GetTotalAcceleration();
Common::Vec3 GetTotalAngularVelocity();
Common::Vec3 GetTotalAcceleration() const;
Common::Vec3 GetTotalAngularVelocity() const;
Common::Matrix44 GetTotalTransformation() const;

void HIDOutputReport(const void* data, u32 size);
Expand Down

0 comments on commit b996dcf

Please sign in to comment.