duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

guncon.h (1861B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "controller.h"
      7 
      8 #include <memory>
      9 
     10 class GunCon final : public Controller
     11 {
     12 public:
     13   enum class Binding : u8
     14   {
     15     Trigger = 0,
     16     A = 1,
     17     B = 2,
     18     ShootOffscreen = 3,
     19     ButtonCount = 4,
     20 
     21     RelativeLeft = 4,
     22     RelativeRight = 5,
     23     RelativeUp = 6,
     24     RelativeDown = 7,
     25     BindingCount = 8,
     26   };
     27 
     28   static const Controller::ControllerInfo INFO;
     29 
     30   GunCon(u32 index);
     31   ~GunCon() override;
     32 
     33   static std::unique_ptr<GunCon> Create(u32 index);
     34 
     35   ControllerType GetType() const override;
     36 
     37   void Reset() override;
     38   bool DoState(StateWrapper& sw, bool apply_input_state) override;
     39 
     40   void LoadSettings(SettingsInterface& si, const char* section, bool initial) override;
     41 
     42   float GetBindState(u32 index) const override;
     43   void SetBindState(u32 index, float value) override;
     44 
     45   void ResetTransferState() override;
     46   bool Transfer(const u8 data_in, u8* data_out) override;
     47 
     48 private:
     49   enum class TransferState : u8
     50   {
     51     Idle,
     52     Ready,
     53     IDMSB,
     54     ButtonsLSB,
     55     ButtonsMSB,
     56     XLSB,
     57     XMSB,
     58     YLSB,
     59     YMSB
     60   };
     61 
     62   void UpdatePosition();
     63 
     64   // 0..1, not -1..1.
     65   std::pair<float, float> GetAbsolutePositionFromRelativeAxes() const;
     66   bool CanUseSoftwareCursor() const;
     67   u32 GetSoftwarePointerIndex() const;
     68   void UpdateSoftwarePointerPosition();
     69 
     70   std::string m_cursor_path;
     71   float m_cursor_scale = 1.0f;
     72   u32 m_cursor_color = 0xFFFFFFFFu;
     73   float m_x_scale = 1.0f;
     74 
     75   float m_relative_pos[4] = {};
     76 
     77   // buttons are active low
     78   u16 m_button_state = UINT16_C(0xFFFF);
     79   u16 m_position_x = 0;
     80   u16 m_position_y = 0;
     81   bool m_shoot_offscreen = false;
     82   bool m_has_relative_binds = false;
     83   u8 m_cursor_index = 0;
     84 
     85   TransferState m_transfer_state = TransferState::Idle;
     86 };