File: gctl.h

package info (click to toggle)
searchandrescue 0.8.2-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,648 kB
  • ctags: 6,112
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 77
file content (360 lines) | stat: -rw-r--r-- 8,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
			       Game Controller
 */

#ifndef GCTL_H
#define GCTL_H

#include <sys/types.h>
#include "gw.h"


/*
 *	Game Controller:
 *
 *	Determines which controller(s) are in use or to be used.
 */
typedef enum {
	GCTL_CONTROLLER_KEYBOARD		= (1 << 0),
	GCTL_CONTROLLER_POINTER			= (1 << 1),
	GCTL_CONTROLLER_JOYSTICK		= (1 << 2)
} gctl_controllers;


/*
 *	Options:
 */
typedef enum {
	GCTL_OPTION_NONE			= (1 << 0)
} gctl_options;


/*
 *	Joystick Priorities:
 */
typedef enum {
	GCTL_JS_PRIORITY_BACKGROUND,
	GCTL_JS_PRIORITY_FOREGROUND,
	GCTL_JS_PRIORITY_PREEMPT
} gctl_js_priority;

/*
 *	Joystick Connections:
 */
typedef enum {
	GCTL_JS_CONNECTION_STANDARD		= 0,
	GCTL_JS_CONNECTION_USB			= 1
} gctl_js_connection;

/*
 *	Joystick Axis Roles:
 */
typedef enum {
	GCTL_JS_AXIS_ROLE_PITCH			= (1 << 0),
	GCTL_JS_AXIS_ROLE_BANK			= (1 << 1),
	GCTL_JS_AXIS_ROLE_HEADING		= (1 << 2),
	GCTL_JS_AXIS_ROLE_THROTTLE		= (1 << 3),
	GCTL_JS_AXIS_ROLE_HAT			= (1 << 4),
	/* Throttle and rudder unit joystick */
	GCTL_JS_AXIS_ROLE_AS_THROTTLE_AND_RUDDER	= (1 << 6),
	/* Joystick unit with no axises (only buttons) */
	GCTL_JS_AXIS_ROLE_NONE			= (1 << 7)
} gctl_js_axis_roles;


/*
 *	Pointer Buttons:
 */
typedef enum {
	GCTL_POINTER_BUTTON1			= (1 << 0),
	GCTL_POINTER_BUTTON2			= (1 << 1),
	GCTL_POINTER_BUTTON3			= (1 << 2)
} gctl_pointer_buttons;


/*
 *	Game Controller Joystick Values:
 */
typedef struct {

	/* Abstract string idenifying the device.
	 *
	 * When using libjsw this would be "/dev/js#" (where # is a
	 * number) or "/dev/input/js#" for libjsw USB devices
	 */
	char		*device;

	/* Priority, one of GCTL_JS_PRIORITY_* */
	gctl_js_priority	priority;

	/* Standard or USB connection, one of GCTL_JS_CONNECTION_* */
	gctl_js_connection	connection;

	/* Pointer to the toplevel window handle (for Win32) */
	void		*window;

	/* Axis role flags (any of GCTL_JS_AXIS_ROLE_*), this basically
	 * specifies how many axises there are and each of their roles
	 */
	gctl_js_axis_roles	axis_role;

	/* Joystick button mappings, indicates which joystick button
	 * number corresponds with which action
	 */
	int		button_rotate,		/* Button that treats
						 * bank as heading axis
						 */
			button_air_brakes,
			button_wheel_brakes,
			button_zoom_in,
			button_zoom_out,
			button_hoist_up,
			button_hoist_down;

} gctl_values_js_struct;
#define GCTL_VALUES_JS(p)	((gctl_values_js_struct *)(p))

/*
 *	Game Controller Values:
 */
typedef struct {

	/* Specifies which game controller type to check for (any of
	 * GCTL_CONTROLLER_*)
	 */
	gctl_controllers	controllers;

	/* General options (any of GCTL_OPT_*) */
	gctl_options		options;

	/* Joystick values, each structure reffers to a joystick */
	gctl_values_js_struct	*joystick;
	int			total_joysticks;

} gctl_values_struct;
#define GCTL_VALUES(p)	((gctl_values_struct *)(p))


/*
 *	Game Controller Joystick:
 *
 *	Used in gctl_struct
 */
typedef struct {

	/* Joystick device specific data handle
	 *
	 * For example, when using libjsw the void *joystick would be
	 * pointing to a js_data_struct structure
	 */
	void		*data;

	/* Axis role mappings, reffers an axis by number to a specific
	 * role
	 *
	 * The axis number can be -1 for non-existant
	 */
	int		axis_heading,
			axis_bank,
			axis_pitch,
			axis_throttle,
			axis_hat_x,
			axis_hat_y;

	/* Joystick button role mappings, reffers a button by number to
	 * a specific role (-1 for none)
	 */
	int		button_rotate,		/* Button that treats
						 * bank as heading axis
						 */
			button_air_brakes,
			button_wheel_brakes,
			button_zoom_in,
			button_zoom_out,
			button_hoist_up,
			button_hoist_down;

} gctl_js_struct;
#define GCTL_JS(p)	((gctl_js_struct *)(p))

/*
 *	Game Controller:
 *
 *	Contains controller positions, values, and resources.
 *
 *	This is passed to all GCTL*() functions.
 */
typedef struct {

	/* Specifies which controllers are checked for, any of
	 * GCTL_CONTROLLER_*
	 */
	gctl_controllers	controllers;

	/* General options (any of GCTL_OPT_*) */
	gctl_options		options;

	/* Last time GCtlUpdate() was called passing this structure,
	 * in milliseconds
	 */
	time_t		last_updated;

	/* Control positions */
	float		heading,	/* -1.0 to 1.0 */
			pitch,		/* -1.0 to 1.0 */
			bank,		/* -1.0 to 1.0 */
			throttle,	/*  0.0 to 1.0 */
			hat_x,		/* -1.0 to 1.0 */
			hat_y;		/* -1.0 to 1.0 */

	/* Zoom in and out:
	 *      *_state members specifies a boolean on/off value
	 *      *_kb_last members record the last keyboard event for this
	 *      behavour
	 *      *_coeff members determines the magnitude [0.0 to 1.0] of     
	 *      the state regardless if it is on or off. This is for when    
	 *      the game controller has gone from off to on to off in one 
	 *      call to GCtlUpdate()
	 */
	Boolean		zoom_in_state,
			zoom_out_state;
	time_t		zoom_in_kb_last,	/* In milliseconds */
			zoom_out_kb_last;
	float		zoom_in_coeff,		/* 0.0 to 1.0 */
			zoom_out_coeff;

	/* Hoist up and down:
	 *      *_state members specifies a boolean on/off value.
	 *      *_kb_last members record the last keyboard event for this
	 *      behavour.
	 *      *_coeff members determines the magnitude [0.0 to 1.0] of     
	 *      the state regardless if it is on or off. This is for when    
	 *      the game controller has gone from off to on to off in one 
	 *      call to GCtlUpdate().
	 */
	Boolean		hoist_up_state,
			hoist_down_state;
	time_t		hoist_up_kb_last,	/* In milliseconds */
			hoist_down_kb_last;
	float		hoist_up_coeff,		/* 0.0 to 1.0 */
			hoist_down_coeff;

	/* Alt, ctrl, and shift (not nessasarly keyboard) states */
	Boolean		alt_state,
			ctrl_state,
			shift_state;

	/* Wheel and air brakes:
	 *	*_state members specifies a boolean on/off value
	 *	*_kb_last members record the last keyboard event for this
	 *	behavior
	 *	*_coeff members determines the magnitude [0.0 to 1.0] of
	 *	the state regardless if it is on or off. This is for when
	 *	the game controller has gone from off to on to off in one
	 *	call to GCtlUpdate()
	 */
	Boolean		air_brakes_state;
	int		wheel_brakes_state;	/* 0 = off
						 * 1 = on
						 * 2 = parking brakes
						 */
	time_t		air_brakes_kb_last,	/* In milliseconds */
			wheel_brakes_kb_last;
	float		air_brakes_coeff,	/* 0.0 to 1.0 */
			wheel_brakes_coeff;


	/* Keyboard Specific Values */

	/* Keyboard key states */
	Boolean		heading_kb_state,
			pitch_kb_state,
			bank_kb_state,
			throttle_kb_state,
			hat_x_kb_state,
			hat_y_kb_state; 

	/* Keyboard last press time stamps for control positions */
	time_t		heading_kb_last,	/* In milliseconds */
			pitch_kb_last,
			bank_kb_last,
			throttle_kb_last,
			hat_x_kb_last,
			hat_y_kb_last;

	/* Set to True if a key is currently down and that key 
	 * would/should override a joystick or pointer controlled
	 * axis.
	 */
	Boolean		axis_kb_state;

	/* Set to True if a key is currently down and that key
	 * would/should override a joystick or pointer controlled
	 * button
	 */
	Boolean		button_kb_state;


	/* Pointer Specific Values */

	/* Current pressed pointer button(s), any flag set to true
	 * means that button is pressed
	 */
	gctl_pointer_buttons	pointer_buttons;

	/* Pointer box position and size in window coordinates, upper-left
	 * corner oriented
	 */
	int		pointer_box_x,
			pointer_box_y,
			pointer_box_width,
			pointer_box_height;

	/* Last pointer event coordinates, in window coordinates relative
	 * to pointer_box_x and pointer_box_y (upper-left corner oriented)
	 */
	int		pointer_x,
			pointer_y;


	/* Joystick specific stuff */

	/* Each structure reffers to a joystick */
	gctl_js_struct	*joystick;
	int		total_joysticks;

} gctl_struct;
#define GCTL(p)		((gctl_struct *)(p))


extern char *GCtlGetError(void);
extern gctl_struct *GCtlNew(gctl_values_struct *v);
extern void GCtlUpdate(
	gctl_struct *gc,
	Boolean heading_has_nz,		/* Include heading pitch nullzone */
	Boolean pitch_has_nz,		/* Include pitch nullzone */
	Boolean bank_has_nz,		/* Include bank nullzone */
	time_t cur_ms, time_t lapsed_ms,
	float time_compensation
);
extern void GCtlHandlePointer(
	gw_display_struct *display, gctl_struct *gc,
	gw_event_type type,
	int button,		/* Button number */
	int x, int y,
	time_t t,		/* Time stamp (in ms) */
	time_t lapsed_ms
);
extern void GCtlHandleKey(
	gw_display_struct *display, gctl_struct *gc,
	int k, Boolean state,
	Boolean alt_state, Boolean ctrl_state, Boolean shift_state,
	time_t t,			/* Time stamp (in ms) */
	time_t lapsed_ms
);
extern void GCtlResetValues(gctl_struct *gc);
extern void GCtlResetTimmers(gctl_struct *gc);
extern void GCtlDelete(gctl_struct *gc);


#endif	/* GCTL_H */