input_engine: Take BasicMotion by const reference with SetMotion() and TriggerOnMotionChange()

Copies the BasicMotion instance once instead of twice.
master
Lioncash 2021-12-13 09:26:44 +07:00
parent a92dbec962
commit 755822ceec
3 changed files with 7 additions and 6 deletions

@ -88,7 +88,7 @@ public:
return true; return true;
} }
BasicMotion GetMotion() { const BasicMotion& GetMotion() const {
return motion; return motion;
} }
@ -367,7 +367,7 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
if (joystick->UpdateMotion(event.csensor)) { if (joystick->UpdateMotion(event.csensor)) {
const PadIdentifier identifier = joystick->GetPadIdentifier(); const PadIdentifier identifier = joystick->GetPadIdentifier();
SetMotion(identifier, 0, joystick->GetMotion()); SetMotion(identifier, 0, joystick->GetMotion());
}; }
} }
break; break;
} }

@ -91,7 +91,7 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, BatteryLevel value
TriggerOnBatteryChange(identifier, value); TriggerOnBatteryChange(identifier, value);
} }
void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value) { void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) {
{ {
std::lock_guard lock{mutex}; std::lock_guard lock{mutex};
ControllerData& controller = controller_list.at(identifier); ControllerData& controller = controller_list.at(identifier);
@ -286,7 +286,7 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
} }
void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
BasicMotion value) { const BasicMotion& value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const std::pair<int, InputIdentifier> poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;

@ -190,7 +190,7 @@ protected:
void SetHatButton(const PadIdentifier& identifier, int button, u8 value); void SetHatButton(const PadIdentifier& identifier, int button, u8 value);
void SetAxis(const PadIdentifier& identifier, int axis, f32 value); void SetAxis(const PadIdentifier& identifier, int axis, f32 value);
void SetBattery(const PadIdentifier& identifier, BatteryLevel value); void SetBattery(const PadIdentifier& identifier, BatteryLevel value);
void SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value); void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value);
virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const {
return "Unknown"; return "Unknown";
@ -209,7 +209,8 @@ private:
void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value);
void TriggerOnAxisChange(const PadIdentifier& identifier, int button, f32 value); void TriggerOnAxisChange(const PadIdentifier& identifier, int button, f32 value);
void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value); void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value);
void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, BasicMotion value); void TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
const BasicMotion& value);
bool IsInputIdentifierEqual(const InputIdentifier& input_identifier, bool IsInputIdentifierEqual(const InputIdentifier& input_identifier,
const PadIdentifier& identifier, EngineInputType type, const PadIdentifier& identifier, EngineInputType type,