Debian Codegraph @

lib/Controller.h

raw symbols SCIP
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lib/Controller.h $
21 * $Revision: 21 $
22 * $Date: 3/20/00 12:25p $
23 * $Author: Matt $
24 *
25 * Universal controller header
26 *
27 * $Log: /DescentIII/Main/lib/Controller.h $
28 *
29 * 21 3/20/00 12:25p Matt
30 * Merge of Duane's post-1.3 changes.
31 * Added declaration.
32 *
33 * 20 8/11/99 6:06p Samir
34 * added flag to determine whether packet contained mouse info.
35 *
36 * 19 7/20/99 4:53p Samir
37 * added ability to manually set the deadzone for a controller.
38 *
39 * 18 7/16/99 11:14a Samir
40 * multiple hat support and improved direct input support.
41 *
42 * 17 4/29/99 2:23a Samir
43 * moved binding text functions to wincontroller.cpp and new text for
44 * multiple joysticks.
45 *
46 * 16 4/16/99 7:34p Jeff
47 * added linux controller
48 *
49 * 15 2/16/99 11:59a Samir
50 * added proper constants for controller and binding null values.
51 *
52 * 14 12/18/98 6:00p Samir
53 * added enable_function.
54 *
55 * 13 10/24/98 2:18p Samir
56 * added mouse and joytick raw value retrieval functions.
57 *
58 * 12 10/21/98 10:36a Samir
59 * added code to turn on or off joystick or mouse.
60 *
61 * 11 10/18/98 7:29p Samir
62 * made assign_function public.
63 *
64 * 10 10/17/98 7:31p Samir
65 * added invertible axes
66 *
67 * 9 9/10/98 12:39p Samir
68 * added senstivity issures for controller.
69 *
70 * 8 6/18/98 4:48p Samir
71 * added changes for multiple configs for joystick controls.
72 *
73 * 7 5/15/98 3:13p Samir
74 * added 2 key support for controller functions.
75 *
76 * 6 2/24/98 11:03a Samir
77 * Added flush function to controller system.
78 *
79 * 5 2/16/98 3:04p Samir
80 * ctAxis instead of ctXAxis, ctYAxis, etc.
81 *
82 * 4 2/13/98 6:38p Samir
83 * Added get and set controller function.
84 *
85 * 3 12/03/97 7:35p Samir
86 * Newer joystick library support and some POV.
87 *
88 * 2 10/29/97 4:44p Samir
89 * Added ctDownCount format.
90 *
91 * 8 5/21/97 3:51p Samir
92 * changed ct_need to ct_function
93 *
94 * 7 5/12/97 4:39 PM Jeremy
95 * #include of macController.h on Macintosh
96 *
97 * 6 5/12/97 1:21p Samir
98 * Added suspend and resume functions.
99 *
100 * 5 4/23/97 1:07p Samir
101 * Now we can poll for either positonal or evaluator data.
102 *
103 * 4 4/16/97 1:04p Samir
104 * For get packet, allow one to return an alternate format value if that
105 * function supports it.
106 *
107 * 3 4/16/97 12:27p Samir
108 * Added mouse support.
109 *
110 * 2 4/11/97 2:13p Samir
111 * Universal header for control system. first version
112 *
113 * $NoKeywords: $
114 */
115
116 #ifndef CONTROLLER_Hcxx . . $ `lib/Controller.h:117:9`!
117 #define CONTROLLER_Hcxx . . $ `lib/Controller.h:117:9`!
118
119 #include <cstdint>
120
121 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
122 #include "Macros.h"cxx . . $ `<file>/lib/Macros.h`/
123
124 enum ct_formatcxx . . $ ct_format# {
125 ctNoFormatcxx . . $ ctNoFormat.,
126 ctAnalogcxx . . $ ctAnalog., // analog information (-1.0 to 1.0)
127 ctDigitalcxx . . $ ctDigital., // digital information (0 or 1)
128 ctDownCountcxx . . $ ctDownCount., // special information for key presses and button/mouse presses.
129 ctTimecxx . . $ ctTime. // time in seconds format
130 };
131
132 enum ct_typecxx . . $ ct_type# {
133 ctNonecxx . . $ ctNone.,
134 ctAxiscxx . . $ ctAxis., // axis element of controller.
135 ctPOVcxx . . $ ctPOV., // function value (hiword = +axis, loword = -axis)
136 ctButtoncxx . . $ ctButton., // fn value: controller button #
137 ctKeycxx . . $ ctKey., // fn value: lobyte(key constant), hibyte(alternate key constant)
138 ctMouseAxiscxx . . $ ctMouseAxis.,
139 ctMouseButtoncxx . . $ ctMouseButton.,
140 ctPOV2cxx . . $ ctPOV2.,
141 ctPOV3cxx . . $ ctPOV3.,
142 ctPOV4cxx . . $ ctPOV4. // auxillary POV values.
143 };
144
145 struct ct_functioncxx . . $ ct_function# {
146 int idcxx . . $ ct_function#id.; // identifier for the function (like forward thrust)
147 ct_formatcxx . . $ ct_format# formatcxx . . $ ct_function#format.; // what format should the return value be for this function
148 ct_typecxx . . $ ct_type# ctypecxx . . $ ct_function#ctype.[2]; // type of controller requested for this id. (1 for each value packed.)
149 uint8_tcxx . . $ uint8_t# valuecxx . . $ ct_function#value.[2]; // corresponding value to ctype
150 uint8_tcxx . . $ uint8_t# flagscxx . . $ ct_function#flags.[2]; // flags.
151 };
152
153 struct ct_packetcxx . . $ ct_packet# {
154 ct_formatcxx . . $ ct_format# formatcxx . . $ ct_packet#format.; // format of value.
155 float valuecxx . . $ ct_packet#value.; // time value for buttons, absolute value for axis values
156 unsigned flagscxx . . $ ct_packet#flags.; // additional information (see below)
157 };
158
159 typedef unsigned ct_config_datacxx . . $ ct_config_data#; // passed by controller system to the outside, and back to controller system
160
161 // values for ct_packet.flags
162 #define CTPK_ELEMENTACTIVEcxx . . $ `lib/Controller.h:162:9`! 0x1 // indicates element was activated but no time/analog information is available.
163 #define CTPK_MOUSEcxx . . $ `lib/Controller.h:163:9`! 0x2 // this is coming from a mouse device. default is joystick/keyboard.
164
165 // element values
166 const uint8_tcxx . . $ uint8_t# CT_X_AXIScxx . . $ CT_X_AXIS. = 1, // AXIS constants for ctAxis
167 CT_Y_AXIScxx . . $ CT_Y_AXIS. = 2, CT_Z_AXIScxx . . $ CT_Z_AXIS. = 3, CT_R_AXIScxx . . $ CT_R_AXIS. = 4, CT_U_AXIScxx . . $ CT_U_AXIS. = 5, CT_V_AXIScxx . . $ CT_V_AXIS. = 6,
168 CT_NUM_AXEScxx . . $ CT_NUM_AXES. = 6; // number of axes
169
170 #define makewordcxx . . $ `lib/Controller.h:170:9`!(_h, _l) (((_h) << 16) + ((_l) & 0xffff))
171 #define hiwordcxx . . $ `lib/Controller.h:171:9`!(_v) ((_v) >> 16)
172 #define lowordcxx . . $ `lib/Controller.h:172:9`!(_v) ((_v) & 0x0000ffff)
173 #define makeshortcxx . . $ `lib/Controller.h:173:9`!(_h, _l) (((_h) << 8) + ((_l) & 0x00ff))
174 #define hibytecxx . . $ `lib/Controller.h:174:9`!(_w) ((_w) >> 8)
175 #define lobytecxx . . $ `lib/Controller.h:175:9`!(_w) ((_w) & 0x00ff)
176
177 // ct_function flags
178 #define CTFNF_INVERTcxx . . $ `lib/Controller.h:178:9`! 0x1 // invert values returned via get_packet.
179
180 #define NULL_BINDINGcxx . . $ `lib/Controller.h:180:9`! 0x00
181 #define NULL_CONTROLLERcxx . . $ `lib/Controller.h:181:9`! 0xff
182 #define INVALID_CONTROLLER_INFOcxx . . $ `lib/Controller.h:182:9`! 0xffff
183
184 #define CONTROLLER_KEY1_VALUEcxx . . $ `lib/Controller.h:184:9`!(_b) lobytecxx . . $ `lib/Controller.h:175:9`!(_b)
185 #define CONTROLLER_KEY2_VALUEcxx . . $ `lib/Controller.h:185:9`!(_b) hibytecxx . . $ `lib/Controller.h:174:9`!(_b)
186 #define CONTROLLER_KEY_VALUEcxx . . $ `lib/Controller.h:186:9`!(_k1, _k2) makeshort(_k2, _k1)
187
188 #define CONTROLLER_CTL1_VALUEcxx . . $ `lib/Controller.h:188:9`!(_b) CONTROLLER_KEY1_VALUEcxx . . $ `lib/Controller.h:184:9`!(_b)
189 #define CONTROLLER_CTL2_VALUEcxx . . $ `lib/Controller.h:189:9`!(_b) CONTROLLER_KEY2_VALUEcxx . . $ `lib/Controller.h:185:9`!(_b)
190 #define CONTROLLER_CTL_VALUEcxx . . $ `lib/Controller.h:190:9`!(_l, _h) makeshortcxx . . $ `lib/Controller.h:173:9`!(_h, _l)
191
192 #define CONTROLLER_CTL1_INFOcxx . . $ `lib/Controller.h:192:9`!(_b) ((int8_t)lobytecxx . . $ `lib/Controller.h:175:9`!(_b))
193 #define CONTROLLER_CTL2_INFOcxx . . $ `lib/Controller.h:193:9`!(_b) ((int8_t)hibytecxx . . $ `lib/Controller.h:174:9`!(_b))
194 #define CONTROLLER_CTL_INFOcxx . . $ `lib/Controller.h:194:9`!(_l, _h) makeshortcxx . . $ `lib/Controller.h:173:9`!(_h, _l)
195
196 #define CONTROLLER_VALUEcxx . . $ `lib/Controller.h:196:9`!(_l) ((uint16_t)lowordcxx . . $ `lib/Controller.h:172:9`!(_l))
197 #define CONTROLLER_INFOcxx . . $ `lib/Controller.h:197:9`!(_l) ((int16_t)hiwordcxx . . $ `lib/Controller.h:171:9`!(_l))
198 #define MAKE_CONFIG_DATAcxx . . $ `lib/Controller.h:198:9`!(_c, _v) makewordcxx . . $ `lib/Controller.h:170:9`!(_c, _v)
199
200 #define CTLBINDS_PER_FUNCcxx . . $ `lib/Controller.h:200:9`! 2
201
202 class gameControllercxx . . $ gameController# {
203 public:
204 gameControllercxx . . $ gameController#gameController(a236fb5fab16b1bf).(int num_funcs, ct_functioncxx . . $ ct_function# *funcs){};
205 virtual ~cxx . . $ gameController#`~gameController`(ced63f7c635d850d).gameControllercxx . . $ gameController#(){};
206
207 // these functions suspend or resume any controller reading. this is really only useful for
208 // preemptive controller polling, but they should be used to activate and deactivate controller
209 // reading.
210 virtual void suspendcxx . . $ gameController#suspend(49f6e7a06ebc5aa8).(){};
211 virtual void resumecxx . . $ gameController#resume(49f6e7a06ebc5aa8).(){};
212
213 // this functions polls the controllers if needed. some systems may not need to implement
214 // this function.
215 virtual void pollcxx . . $ gameController#poll(49f6e7a06ebc5aa8).(){};
216
217 // flushes all controller information
218 virtual void flushcxx . . $ gameController#flush(49f6e7a06ebc5aa8).() = 0;
219
220 // returns the value of a requested controller type. make sure you flush the controller before polling.
221 virtual ct_config_datacxx . . $ ct_config_data# get_controller_valuecxx . . $ gameController#get_controller_value(1248184eb8b5e5af).(ct_typecxx . . $ ct_type# type_req) = 0;
222
223 // sets the configuration of a function (type must be of an array == CTLBINDS_PER_FUNC)
224 virtual void set_controller_functioncxx . . $ gameController#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) = 0;
225
226 // returns information about a requested function (type must be of an array == CTLBINDS_PER_FUNC)
227 virtual void get_controller_functioncxx . . $ gameController#get_controller_function(c004c324aa6068e0).(int id, ct_typecxx . . $ ct_type# *type, ct_config_datacxx . . $ ct_config_data# *value, uint8_tcxx . . $ uint8_t# *flags) = 0;
228
229 // temporarily enables or disables a function
230 virtual void enable_functioncxx . . $ gameController#enable_function(918ebd27a9ddbad3).(int id, bool enable) = 0;
231
232 // all systems need to implement this function. this returns information about the controller
233 virtual bool get_packetcxx . . $ gameController#get_packet(c1da47aee99b4b74).(int id, ct_packetcxx . . $ ct_packet# *packet, ct_formatcxx . . $ ct_format# alt_format = ctNoFormatcxx . . $ ctNoFormat.) = 0;
234
235 // gets sensitivity of axis item
236 virtual float get_axis_sensitivitycxx . . $ gameController#get_axis_sensitivity(13d73da2a9b3a1ee).(ct_typecxx . . $ ct_type# axis_type, uint8_tcxx . . $ uint8_t# axis) = 0;
237
238 // sets sensitivity of axis item
239 virtual void set_axis_sensitivitycxx . . $ gameController#set_axis_sensitivity(b979151824fed4c4).(ct_typecxx . . $ ct_type# axis_type, uint8_tcxx . . $ uint8_t# axis, float val) = 0;
240
241 // assigns an individual function
242 virtual int assign_functioncxx . . $ gameController#assign_function(2608e8495e192ac3).(ct_functioncxx . . $ ct_function# *fn) = 0;
243
244 // activates or deactivates mouse and or controller
245 virtual void mask_controllerscxx . . $ gameController#mask_controllers(b0b38cda41d4ede4).(bool joystick, bool mouse) = 0;
246
247 // retrieves binding text for desired function, binding, etc.
248 virtual const char *get_binding_textcxx . . $ gameController#get_binding_text(c156078267dcf458).(ct_typecxx . . $ ct_type# type, uint8_tcxx . . $ uint8_t# ctrl, uint8_tcxx . . $ uint8_t# bind) = 0;
249
250 // get raw values for the controllers
251 virtual int get_mouse_raw_valuescxx . . $ gameController#get_mouse_raw_values(aa23d0250da59a45).(int *x, int *y) = 0;
252 virtual unsigned get_joy_raw_valuescxx . . $ gameController#get_joy_raw_values(ef0362c0d321f56b).(int *x, int *y) = 0;
253
254 // toggles use of deadzone for controllers. ctl can be 0 to ???
255 // dead zone is from 0.0 to 0.5
256 virtual void set_controller_deadzonecxx . . $ gameController#set_controller_deadzone(43c79ee2f1b9aefe).(int ctl, float deadzone){};
257 virtual float get_controller_deadzonecxx . . $ gameController#get_controller_deadzone(5cde91ea12d43f46).(int ctl) { return 0; };
258
259 // toggles use of axis on controllers. ctl can be 0 to ???
260 // axis is a CT_?_AXIS value
261 void toggle_controller_axiscxx . . $ gameController#toggle_controller_axis(6908015b96d379c0).(int ctl, int axis, bool toggle){};
262 };
263
264 gameControllercxx . . $ gameController# *CreateControllercxx . . $ CreateController(81c4a189a587b469).(int num_funcs, ct_functioncxx . . $ ct_function# *funcs, char *remote_ip);
265 void DestroyControllercxx . . $ DestroyController(66dd5cf3e0c6b3e1).(gameControllercxx . . $ gameController# *ctl);
266
267 #if defined(DX_APP)
268 #include "win\WinController.h"
269 #else
270 #include "lnxcontroller.h"cxx . . $ `<file>/linux/lnxcontroller.h`/
271 #endif
272
273 #endif