#include "namco_guncon.h" #include "common/assert.h" #include "common/log.h" #include "common/state_wrapper.h" #include "gpu.h" #include "host_display.h" #include "host_interface.h" #include "resources.h" #include "system.h" #include Log_SetChannel(NamcoGunCon); NamcoGunCon::NamcoGunCon() = default; NamcoGunCon::~NamcoGunCon() = default; ControllerType NamcoGunCon::GetType() const { return ControllerType::NamcoGunCon; } std::optional NamcoGunCon::GetAxisCodeByName(std::string_view axis_name) const { return StaticGetAxisCodeByName(axis_name); } std::optional NamcoGunCon::GetButtonCodeByName(std::string_view button_name) const { return StaticGetButtonCodeByName(button_name); } void NamcoGunCon::Reset() { m_transfer_state = TransferState::Idle; } bool NamcoGunCon::DoState(StateWrapper& sw, bool apply_input_state) { if (!Controller::DoState(sw, apply_input_state)) return false; u16 button_state = m_button_state; u16 position_x = m_position_x; u16 position_y = m_position_y; sw.Do(&button_state); sw.Do(&position_x); sw.Do(&position_y); if (apply_input_state) { m_button_state = button_state; m_position_x = position_x; m_position_y = position_y; } sw.Do(&m_transfer_state); return true; } bool NamcoGunCon::GetButtonState(s32 button_code) const { if (button_code < 0 || button_code > static_cast(Button::B)) return false; const u16 bit = u16(1) << static_cast(button_code); return ((m_button_state & bit) == 0); } void NamcoGunCon::SetButtonState(Button button, bool pressed) { if (button == Button::ShootOffscreen) { if (m_shoot_offscreen != pressed) { m_shoot_offscreen = pressed; SetButtonState(Button::Trigger, pressed); } return; } static constexpr std::array(Button::Count)> indices = {{13, 3, 14}}; if (pressed) m_button_state &= ~(u16(1) << indices[static_cast(button)]); else m_button_state |= u16(1) << indices[static_cast(button)]; } void NamcoGunCon::SetButtonState(s32 button_code, bool pressed) { if (button_code < 0 || button_code >= static_cast(Button::Count)) return; SetButtonState(static_cast