| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __LNXCONTROLLER_H_ |
| 20 | #define __LNXCONTROLLER_H_cxx . . $ `linux/lnxcontroller.h:20:9`! |
| 21 | |
| 22 | #include "Controller.h"cxx . . $ `<file>/lib/Controller.h`/ |
| 23 | #include "joystick.h"cxx . . $ `<file>/lib/joystick.h`/ |
| 24 | |
| 25 | #define NULL_LNXCONTROLLERcxx . . $ `linux/lnxcontroller.h:25:9`! ((int8_t)NULL_CONTROLLERcxx . . $ `lib/Controller.h:181:9`!) |
| 26 | |
| 27 | const int CTF_POVcxx . . $ CTF_POV. = 64, // POV control |
| 28 | CTF_POV2cxx . . $ CTF_POV2. = 128, // POV 2 |
| 29 | CTF_POV3cxx . . $ CTF_POV3. = 256, // POV 3 |
| 30 | CTF_POV4cxx . . $ CTF_POV4. = 512; // POV 4 |
| 31 | |
| 32 | const unsigned CTF_X_AXIScxx . . $ CTF_X_AXIS. = (1 << (CT_X_AXIScxx . . $ CT_X_AXIS. - 1)), // AXIS constants for ctAxis |
| 33 | CTF_Y_AXIScxx . . $ CTF_Y_AXIS. = (1 << (CT_Y_AXIScxx . . $ CT_Y_AXIS. - 1)), CTF_Z_AXIScxx . . $ CTF_Z_AXIS. = (1 << (CT_Z_AXIScxx . . $ CT_Z_AXIS. - 1)), CTF_R_AXIScxx . . $ CTF_R_AXIS. = (1 << (CT_R_AXIScxx . . $ CT_R_AXIS. - 1)), |
| 34 | CTF_U_AXIScxx . . $ CTF_U_AXIS. = (1 << (CT_U_AXIScxx . . $ CT_U_AXIS. - 1)), CTF_V_AXIScxx . . $ CTF_V_AXIS. = (1 << (CT_V_AXIScxx . . $ CT_V_AXIS. - 1)); |
| 35 | |
| 36 | const unsigned CT_MAX_CONTROLLERScxx . . $ CT_MAX_CONTROLLERS. = 32, CT_MAX_ELEMENTScxx . . $ CT_MAX_ELEMENTS. = 255, CT_MAX_EXTCTLScxx . . $ CT_MAX_EXTCTLS. = 16, CT_MAX_BUTTONScxx . . $ CT_MAX_BUTTONS. = 32; |
| 37 | |
| 38 | // rules for adding controllers |
| 39 | // any nonstandard special controllers should be added to the below list starting at |
| 40 | // CTID_MOUSE-1 (meaning a value of -3, -4 and so on) |
| 41 | |
| 42 | const int CTID_KEYBOARDcxx . . $ CTID_KEYBOARD. = -1, // always -1 for keyboards |
| 43 | CTID_MOUSEcxx . . $ CTID_MOUSE. = -2, // always -2 for mice |
| 44 | CTID_INVALIDcxx . . $ CTID_INVALID. = -3; // invalid controller |
| 45 | |
| 46 | // External controls |
| 47 | // these are standard controllers handled through DDIO interface |
| 48 | // like joysticks, etc. |
| 49 | |
| 50 | const int CTID_EXTCONTROL0cxx . . $ CTID_EXTCONTROL0. = 0; |
| 51 | |
| 52 | class lnxgameControllercxx . . $ lnxgameController# : public gameControllercxx . . $ gameController# { |
| 53 | public: |
| 54 | lnxgameControllercxx . . $ lnxgameController#lnxgameController(a236fb5fab16b1bf).(int num_funcs, ct_functioncxx . . $ ct_function# *funcs); |
| 55 | ~cxx . . $ lnxgameController#`~lnxgameController`(ced63f7c635d850d).lnxgameControllercxx . . $ lnxgameController#(); |
| 56 | |
| 57 | // these functions suspend or resume any controller reading. this is really only useful for |
| 58 | // preemptive controller polling, but they should be used to activate and deactivate controller |
| 59 | // reading. |
| 60 | virtual void suspendcxx . . $ lnxgameController#suspend(49f6e7a06ebc5aa8).(); |
| 61 | virtual void resumecxx . . $ lnxgameController#resume(49f6e7a06ebc5aa8).(); |
| 62 | |
| 63 | // this functions polls the controllers if needed. some systems may not need to implement |
| 64 | // this function. |
| 65 | virtual void pollcxx . . $ lnxgameController#poll(49f6e7a06ebc5aa8).(); |
| 66 | |
| 67 | // flushes all controller information |
| 68 | virtual void flushcxx . . $ lnxgameController#flush(49f6e7a06ebc5aa8).(); |
| 69 | |
| 70 | // returns the value of a requested controller type. make sure you flush the controller before polling. |
| 71 | virtual ct_config_datacxx . . $ ct_config_data# get_controller_valuecxx . . $ lnxgameController#get_controller_value(1248184eb8b5e5af).(ct_typecxx . . $ ct_type# type_req); |
| 72 | |
| 73 | // sets the configuration of a function (type must be of an array == CTLBINDS_PER_FUNC) |
| 74 | virtual void set_controller_functioncxx . . $ lnxgameController#set_controller_function(a87bf4975f40b925).(int id, const ct_typecxx . . $ ct_type# *type, ct_config_datacxx . . $ ct_config_data# value, const uint8_tcxx . . $ uint8_t# *flags); |
| 75 | |
| 76 | // returns information about a requested function (type must be of an array == CTLBINDS_PER_FUNC) |
| 77 | virtual void get_controller_functioncxx . . $ lnxgameController#get_controller_function(c004c324aa6068e0).(int id, ct_typecxx . . $ ct_type# *type, ct_config_datacxx . . $ ct_config_data# *value, uint8_tcxx . . $ uint8_t# *flags); |
| 78 | |
| 79 | // temporarily enables or disables a function |
| 80 | virtual void enable_functioncxx . . $ lnxgameController#enable_function(918ebd27a9ddbad3).(int id, bool enable); |
| 81 | |
| 82 | // all systems need to implement this function. this returns information about the controller |
| 83 | virtual bool get_packetcxx . . $ lnxgameController#get_packet(c1da47aee99b4b74).(int id, ct_packetcxx . . $ ct_packet# *packet, ct_formatcxx . . $ ct_format# alt_format = ctNoFormatcxx . . $ ctNoFormat.); |
| 84 | |
| 85 | // gets sensitivity of axis item |
| 86 | virtual float get_axis_sensitivitycxx . . $ lnxgameController#get_axis_sensitivity(13d73da2a9b3a1ee).(ct_typecxx . . $ ct_type# axis_type, uint8_tcxx . . $ uint8_t# axis); |
| 87 | |
| 88 | // sets sensitivity of axis item |
| 89 | virtual void set_axis_sensitivitycxx . . $ lnxgameController#set_axis_sensitivity(b979151824fed4c4).(ct_typecxx . . $ ct_type# axis_type, uint8_tcxx . . $ uint8_t# axis, float val); |
| 90 | |
| 91 | // assigns an individual function |
| 92 | virtual int assign_functioncxx . . $ lnxgameController#assign_function(2608e8495e192ac3).(ct_functioncxx . . $ ct_function# *fn); |
| 93 | |
| 94 | // activates or deactivates mouse and or controller |
| 95 | virtual void mask_controllerscxx . . $ lnxgameController#mask_controllers(b0b38cda41d4ede4).(bool joystick, bool mouse); |
| 96 | |
| 97 | // get raw values for the controllers |
| 98 | virtual int get_mouse_raw_valuescxx . . $ lnxgameController#get_mouse_raw_values(aa23d0250da59a45).(int *x, int *y); |
| 99 | virtual unsigned get_joy_raw_valuescxx . . $ lnxgameController#get_joy_raw_values(ef0362c0d321f56b).(int *x, int *y); |
| 100 | |
| 101 | // retrieves binding text for desired function, binding, etc. |
| 102 | virtual const char *get_binding_textcxx . . $ lnxgameController#get_binding_text(c156078267dcf458).(ct_typecxx . . $ ct_type# type, uint8_tcxx . . $ uint8_t# ctrl, uint8_tcxx . . $ uint8_t# bind); |
| 103 | |
| 104 | // toggles use of deadzone for controllers |
| 105 | void set_controller_deadzonecxx . . $ lnxgameController#set_controller_deadzone(43c79ee2f1b9aefe).(int ctl, float deadzone); |
| 106 | |
| 107 | private: |
| 108 | int m_NumControlscxx . . $ lnxgameController#m_NumControls.; // number of controllers available |
| 109 | int m_Suspendedcxx . . $ lnxgameController#m_Suspended.; // is controller polling suspended? |
| 110 | bool m_JoyActivecxx . . $ lnxgameController#m_JoyActive., m_MouseActivecxx . . $ lnxgameController#m_MouseActive.; // enables or disables mouse, joystick control |
| 111 | |
| 112 | struct t_controllercxx . . $ lnxgameController#t_controller# { |
| 113 | int idcxx . . $ lnxgameController#t_controller#id.; |
| 114 | uint16_tcxx . . $ uint16_t# flagscxx . . $ lnxgameController#t_controller#flags.; |
| 115 | uint16_tcxx . . $ uint16_t# buttonscxx . . $ lnxgameController#t_controller#buttons.; |
| 116 | unsigned btnmaskcxx . . $ lnxgameController#t_controller#btnmask.; |
| 117 | float normalizercxx . . $ lnxgameController#t_controller#normalizer.[CT_NUM_AXEScxx . . $ CT_NUM_AXES.]; |
| 118 | float senscxx . . $ lnxgameController#t_controller#sens.[CT_NUM_AXEScxx . . $ CT_NUM_AXES.]; |
| 119 | float sensmodcxx . . $ lnxgameController#t_controller#sensmod.[CT_NUM_AXEScxx . . $ CT_NUM_AXES.]; |
| 120 | float deadzonecxx . . $ lnxgameController#t_controller#deadzone.; |
| 121 | } m_ControlListcxx . . $ lnxgameController#m_ControlList.[CT_MAX_CONTROLLERScxx . . $ CT_MAX_CONTROLLERS.]; // the control list. |
| 122 | |
| 123 | struct ct_elementcxx . . $ lnxgameController#ct_element# { |
| 124 | ct_formatcxx . . $ ct_format# formatcxx . . $ lnxgameController#ct_element#format.; |
| 125 | int8_tcxx . . $ int8_t# ctlcxx . . $ lnxgameController#ct_element#ctl.[CTLBINDS_PER_FUNCcxx . . $ `lib/Controller.h:200:9`!]; |
| 126 | uint8_tcxx . . $ uint8_t# valuecxx . . $ lnxgameController#ct_element#value.[CTLBINDS_PER_FUNCcxx . . $ `lib/Controller.h:200:9`!]; |
| 127 | ct_typecxx . . $ ct_type# ctypecxx . . $ lnxgameController#ct_element#ctype.[CTLBINDS_PER_FUNCcxx . . $ `lib/Controller.h:200:9`!]; |
| 128 | uint8_tcxx . . $ uint8_t# flagscxx . . $ lnxgameController#ct_element#flags.[2]; |
| 129 | bool enabledcxx . . $ lnxgameController#ct_element#enabled.; |
| 130 | } m_ElementListcxx . . $ lnxgameController#m_ElementList.[CT_MAX_ELEMENTScxx . . $ CT_MAX_ELEMENTS.]; |
| 131 | |
| 132 | bool enum_controllerscxx . . $ lnxgameController#enum_controllers(c9857a73d68e59ba).(); |
| 133 | |
| 134 | // sets up an elements information structure |
| 135 | void assign_elementcxx . . $ lnxgameController#assign_element(3ef7288ee539ac42).(int id, ct_elementcxx . . $ lnxgameController#ct_element# *elem); |
| 136 | |
| 137 | // this returns an index into the control list. |
| 138 | int8_tcxx . . $ int8_t# get_axis_controllercxx . . $ lnxgameController#get_axis_controller(bea2bd53c861b042).(uint8_tcxx . . $ uint8_t# axis); |
| 139 | |
| 140 | // returns controller with specified button |
| 141 | int8_tcxx . . $ int8_t# get_button_controllercxx . . $ lnxgameController#get_button_controller(bea2bd53c861b042).(uint8_tcxx . . $ uint8_t# btn); |
| 142 | |
| 143 | // returns the controller with a pov hat |
| 144 | int8_tcxx . . $ int8_t# get_pov_controllercxx . . $ lnxgameController#get_pov_controller(bea2bd53c861b042).(uint8_tcxx . . $ uint8_t# pov); |
| 145 | |
| 146 | // note controller is index into ControlList. |
| 147 | float get_axis_valuecxx . . $ lnxgameController#get_axis_value(a4bbe37243b73efe).(int8_tcxx . . $ int8_t# controller, uint8_tcxx . . $ uint8_t# axis, ct_formatcxx . . $ ct_format# format, bool invert = false); |
| 148 | |
| 149 | // get value of button in seconds, presses, etc. |
| 150 | float get_button_valuecxx . . $ lnxgameController#get_button_value(aea33017bc1b5815).(int8_tcxx . . $ int8_t# controller, ct_formatcxx . . $ ct_format# format, uint8_tcxx . . $ uint8_t# button); |
| 151 | |
| 152 | // get value of pov (using JOYPOV values) |
| 153 | float get_pov_valuecxx . . $ lnxgameController#get_pov_value(c199c3612abc2a26).(int8_tcxx . . $ int8_t# controller, ct_formatcxx . . $ ct_format# format, uint8_tcxx . . $ uint8_t# pov_number, uint8_tcxx . . $ uint8_t# pov); |
| 154 | |
| 155 | // get keyboard info |
| 156 | float get_key_valuecxx . . $ lnxgameController#get_key_value(5d9504f2bec60a96).(int key, ct_formatcxx . . $ ct_format# format); |
| 157 | |
| 158 | void parse_ctl_filecxx . . $ lnxgameController#parse_ctl_file(66835f578de1bcb3).(int devnum, const char *ctlname); |
| 159 | |
| 160 | private: |
| 161 | struct t_msestatecxx . . $ lnxgameController#t_msestate# { |
| 162 | int xcxx . . $ lnxgameController#t_msestate#x., ycxx . . $ lnxgameController#t_msestate#y., zcxx . . $ lnxgameController#t_msestate#z.; |
| 163 | int mxcxx . . $ lnxgameController#t_msestate#mx., mycxx . . $ lnxgameController#t_msestate#my.; |
| 164 | unsigned btnmaskcxx . . $ lnxgameController#t_msestate#btnmask.; |
| 165 | } m_MseStatecxx . . $ lnxgameController#m_MseState.; |
| 166 | |
| 167 | struct t_extctlstatecxx . . $ lnxgameController#t_extctlstate# { |
| 168 | int xcxx . . $ lnxgameController#t_extctlstate#x., ycxx . . $ lnxgameController#t_extctlstate#y., zcxx . . $ lnxgameController#t_extctlstate#z., rcxx . . $ lnxgameController#t_extctlstate#r., ucxx . . $ lnxgameController#t_extctlstate#u., vcxx . . $ lnxgameController#t_extctlstate#v.; |
| 169 | int povcxx . . $ lnxgameController#t_extctlstate#pov.[JOYPOV_NUMcxx . . $ `lib/joystick.h:72:9`!]; |
| 170 | int last_povcxx . . $ lnxgameController#t_extctlstate#last_pov.[JOYPOV_NUMcxx . . $ `lib/joystick.h:72:9`!]; |
| 171 | float povstartscxx . . $ lnxgameController#t_extctlstate#povstarts.[JOYPOV_NUMcxx . . $ `lib/joystick.h:72:9`!][JOYPOV_DIRcxx . . $ `lib/joystick.h:87:9`!]; |
| 172 | float povtimescxx . . $ lnxgameController#t_extctlstate#povtimes.[JOYPOV_NUMcxx . . $ `lib/joystick.h:72:9`!][JOYPOV_DIRcxx . . $ `lib/joystick.h:87:9`!]; |
| 173 | uint8_tcxx . . $ uint8_t# povpressescxx . . $ lnxgameController#t_extctlstate#povpresses.[JOYPOV_NUMcxx . . $ `lib/joystick.h:72:9`!][JOYPOV_DIRcxx . . $ `lib/joystick.h:87:9`!]; |
| 174 | unsigned buttonscxx . . $ lnxgameController#t_extctlstate#buttons.; |
| 175 | uint8_tcxx . . $ uint8_t# btnpressescxx . . $ lnxgameController#t_extctlstate#btnpresses.[CT_MAX_BUTTONScxx . . $ CT_MAX_BUTTONS.]; |
| 176 | float btnstartscxx . . $ lnxgameController#t_extctlstate#btnstarts.[CT_MAX_BUTTONScxx . . $ CT_MAX_BUTTONS.]; |
| 177 | float btntimescxx . . $ lnxgameController#t_extctlstate#btntimes.[CT_MAX_BUTTONScxx . . $ CT_MAX_BUTTONS.]; |
| 178 | } m_ExtCtlStatescxx . . $ lnxgameController#m_ExtCtlStates.[CT_MAX_EXTCTLScxx . . $ CT_MAX_EXTCTLS.]; |
| 179 | |
| 180 | // thread info. |
| 181 | int64_tcxx . . $ int64_t# m_frame_timer_mscxx . . $ lnxgameController#m_frame_timer_ms.; |
| 182 | float m_frame_timecxx . . $ lnxgameController#m_frame_time.; |
| 183 | |
| 184 | // note id is id value from controller in control list. |
| 185 | void extctl_getposcxx . . $ lnxgameController#extctl_getpos(d4f767463ce0a6b3).(int id); |
| 186 | |
| 187 | // this gets timings for mouse buttons |
| 188 | void mouse_getevalcxx . . $ lnxgameController#mouse_geteval(49f6e7a06ebc5aa8).(); |
| 189 | }; |
| 190 | |
| 191 | #endif |