My Project
Loading...
Searching...
No Matches
joystick.h
1/*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef JOYSTICK_H
20#define JOYSTICK_H
21
22#include "opentyr.h"
23#include "config_file.h"
24
25#include "SDL.h"
26
27typedef enum
28{
29 NONE,
30 AXIS,
31 BUTTON,
32 HAT
33}
34Joystick_assignment_types;
35
36typedef struct
37{
38 Joystick_assignment_types type;
39 int num;
40
41 // if hat
42 bool x_axis; // else y_axis
43
44 // if hat or axis
45 bool negative_axis; // else positive
46}
48
49typedef struct
50{
51 SDL_Joystick *handle;
52
53 Joystick_assignment assignment[10][2]; // 0-3: directions, 4-9: actions
54
55 bool analog;
56 int sensitivity, threshold;
57
58 signed int x, y;
59 int analog_direction[4];
60 bool direction[4], direction_pressed[4]; // up, right, down, left (_pressed, for emulating key presses)
61
62 bool confirm, cancel;
63 bool action[6], action_pressed[6]; // fire, mode swap, left fire, right fire, menu, pause
64
65 Uint32 joystick_delay;
66 bool input_pressed;
67}
69
70extern int joystick_repeat_delay;
71extern bool joydown;
72extern bool ignore_joystick;
73extern int joysticks;
74extern Joystick *joystick;
75
76int joystick_axis_reduce(int j, int value);
77bool joystick_analog_angle(int j, float *angle);
78
79void poll_joystick(int j);
80void poll_joysticks(void);
81
82void push_key(SDL_Scancode key);
83void push_joysticks_as_keyboard(void);
84
85void init_joysticks(void);
86void deinit_joysticks(void);
87
88void reset_joystick_assignments(int j);
89bool load_joystick_assignments(Config* config, int j);
90bool save_joystick_assignments(Config* config, int j);
91
92void joystick_assignments_to_string(char *buffer, size_t buffer_len, const Joystick_assignment *assignments);
93
94bool detect_joystick_assignment(int j, Joystick_assignment *assignment);
95bool joystick_assignment_cmp(const Joystick_assignment *, const Joystick_assignment *);
96
97#endif /* JOYSTICK_H */
A configuration consisting of sections.
Definition config_file.h:182
Definition joystick.h:37
Definition joystick.h:50