WiimoteEmu: Mark several getters as const

These don't modify internal class state, so they can be made const.
This commit is contained in:
Lioncash 2020-07-24 15:42:08 -04:00
parent 520af035d2
commit f9b856aeda
2 changed files with 34 additions and 36 deletions

View File

@ -287,7 +287,7 @@ std::string Wiimote::GetName() const
return fmt::format("Wiimote{}", 1 + m_index); return fmt::format("Wiimote{}", 1 + m_index);
} }
ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const
{ {
switch (group) switch (group)
{ {
@ -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()) return static_cast<Nunchuk*>(m_attachments->GetAttachmentList()[ExtensionNumber::NUNCHUK].get())
->GetGroup(group); ->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()) return static_cast<Classic*>(m_attachments->GetAttachmentList()[ExtensionNumber::CLASSIC].get())
->GetGroup(group); ->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()) return static_cast<Guitar*>(m_attachments->GetAttachmentList()[ExtensionNumber::GUITAR].get())
->GetGroup(group); ->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()) return static_cast<Drums*>(m_attachments->GetAttachmentList()[ExtensionNumber::DRUMS].get())
->GetGroup(group); ->GetGroup(group);
} }
ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group) ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group) const
{ {
return static_cast<Turntable*>( return static_cast<Turntable*>(
m_attachments->GetAttachmentList()[ExtensionNumber::TURNTABLE].get()) m_attachments->GetAttachmentList()[ExtensionNumber::TURNTABLE].get())
->GetGroup(group); ->GetGroup(group);
} }
ControllerEmu::ControlGroup* Wiimote::GetUDrawTabletGroup(UDrawTabletGroup group) ControllerEmu::ControlGroup* Wiimote::GetUDrawTabletGroup(UDrawTabletGroup group) const
{ {
return static_cast<UDrawTablet*>( return static_cast<UDrawTablet*>(
m_attachments->GetAttachmentList()[ExtensionNumber::UDRAW_TABLET].get()) m_attachments->GetAttachmentList()[ExtensionNumber::UDRAW_TABLET].get())
->GetGroup(group); ->GetGroup(group);
} }
ControllerEmu::ControlGroup* Wiimote::GetDrawsomeTabletGroup(DrawsomeTabletGroup group) ControllerEmu::ControlGroup* Wiimote::GetDrawsomeTabletGroup(DrawsomeTabletGroup group) const
{ {
return static_cast<DrawsomeTablet*>( return static_cast<DrawsomeTablet*>(
m_attachments->GetAttachmentList()[ExtensionNumber::DRAWSOME_TABLET].get()) m_attachments->GetAttachmentList()[ExtensionNumber::DRAWSOME_TABLET].get())
->GetGroup(group); ->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()) return static_cast<TaTaCon*>(m_attachments->GetAttachmentList()[ExtensionNumber::TATACON].get())
->GetGroup(group); ->GetGroup(group);
@ -799,7 +799,7 @@ void Wiimote::StepDynamics()
1.f / ::Wiimote::UPDATE_FREQ); 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( Common::Vec3 accel = GetOrientation() * GetTransformation().Transform(
m_swing_state.acceleration + extra_acceleration, 0); m_swing_state.acceleration + extra_acceleration, 0);
@ -810,7 +810,7 @@ Common::Vec3 Wiimote::GetAcceleration(Common::Vec3 extra_acceleration)
return accel; 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 + return GetOrientation() * (m_tilt_state.angular_velocity + m_swing_state.angular_velocity +
m_point_state.angular_velocity + extra_angular_velocity); m_point_state.angular_velocity + extra_angular_velocity);
@ -835,22 +835,20 @@ Common::Matrix33 Wiimote::GetOrientation() const
Common::Matrix33::RotateX(float(MathUtil::TAU / 4 * IsUpright())); Common::Matrix33::RotateX(float(MathUtil::TAU / 4 * IsUpright()));
} }
Common::Vec3 Wiimote::GetTotalAcceleration() Common::Vec3 Wiimote::GetTotalAcceleration() const
{ {
auto accel = m_imu_accelerometer->GetState(); if (const auto accel = m_imu_accelerometer->GetState())
if (accel.has_value()) return GetAcceleration(*accel);
return GetAcceleration(accel.value());
else return GetAcceleration();
return GetAcceleration();
} }
Common::Vec3 Wiimote::GetTotalAngularVelocity() Common::Vec3 Wiimote::GetTotalAngularVelocity() const
{ {
auto ang_vel = m_imu_gyroscope->GetState(); if (const auto ang_vel = m_imu_gyroscope->GetState())
if (ang_vel.has_value()) return GetAngularVelocity(*ang_vel);
return GetAngularVelocity(ang_vel.value());
else return GetAngularVelocity();
return GetAngularVelocity();
} }
Common::Matrix44 Wiimote::GetTotalTransformation() const Common::Matrix44 Wiimote::GetTotalTransformation() const

View File

@ -114,15 +114,15 @@ public:
std::string GetName() const override; std::string GetName() const override;
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group); ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group) const;
ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group); ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group) const;
ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group); ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group) const;
ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group); ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group) const;
ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group); ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group) const;
ControllerEmu::ControlGroup* GetTurntableGroup(TurntableGroup group); ControllerEmu::ControlGroup* GetTurntableGroup(TurntableGroup group) const;
ControllerEmu::ControlGroup* GetUDrawTabletGroup(UDrawTabletGroup group); ControllerEmu::ControlGroup* GetUDrawTabletGroup(UDrawTabletGroup group) const;
ControllerEmu::ControlGroup* GetDrawsomeTabletGroup(DrawsomeTabletGroup group); ControllerEmu::ControlGroup* GetDrawsomeTabletGroup(DrawsomeTabletGroup group) const;
ControllerEmu::ControlGroup* GetTaTaConGroup(TaTaConGroup group); ControllerEmu::ControlGroup* GetTaTaConGroup(TaTaConGroup group) const;
void Update(); void Update();
void StepDynamics(); void StepDynamics();
@ -149,10 +149,10 @@ private:
// Returns simulated accelerometer data in m/s^2. // Returns simulated accelerometer data in m/s^2.
Common::Vec3 GetAcceleration( 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. // 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. // Returns the transformation of the world around the wiimote.
// Used for simulating camera data and for rotating acceleration data. // Used for simulating camera data and for rotating acceleration data.
@ -163,8 +163,8 @@ private:
// Returns the world rotation from the effects of sideways/upright settings. // Returns the world rotation from the effects of sideways/upright settings.
Common::Matrix33 GetOrientation() const; Common::Matrix33 GetOrientation() const;
Common::Vec3 GetTotalAcceleration(); Common::Vec3 GetTotalAcceleration() const;
Common::Vec3 GetTotalAngularVelocity(); Common::Vec3 GetTotalAngularVelocity() const;
Common::Matrix44 GetTotalTransformation() const; Common::Matrix44 GetTotalTransformation() const;
void HIDOutputReport(const void* data, u32 size); void HIDOutputReport(const void* data, u32 size);