1 // SONIC ROBO BLAST 2
2 //-----------------------------------------------------------------------------
3 // Copyright (C) 1998-2000 by DooM Legacy Team.
4 // Copyright (C) 1999-2020 by Sonic Team Junior.
5 //
6 // This program is free software distributed under the
7 // terms of the GNU General Public License, version 2.
8 // See the 'LICENSE' file for more details.
9 //-----------------------------------------------------------------------------
10 /// \file  g_input.h
11 /// \brief handle mouse/keyboard/joystick inputs,
12 ///        maps inputs to game controls (forward, spin, jump...)
13 
14 #ifndef __G_INPUT__
15 #define __G_INPUT__
16 
17 #include "d_event.h"
18 #include "keys.h"
19 #include "command.h"
20 
21 // number of total 'button' inputs, include keyboard keys, plus virtual
22 // keys (mousebuttons and joybuttons becomes keys)
23 #define NUMKEYS 256
24 
25 #define MOUSEBUTTONS 8
26 #define JOYBUTTONS   32 // 32 buttons
27 #define JOYHATS      4  // 4 hats
28 #define JOYAXISSET   4  // 4 Sets of 2 axises
29 
30 //
31 // mouse and joystick buttons are handled as 'virtual' keys
32 //
33 typedef enum
34 {
35 	KEY_MOUSE1 = NUMKEYS,
36 	KEY_JOY1 = KEY_MOUSE1 + MOUSEBUTTONS,
37 	KEY_HAT1 = KEY_JOY1 + JOYBUTTONS,
38 
39 	KEY_DBLMOUSE1 =KEY_HAT1 + JOYHATS*4, // double clicks
40 	KEY_DBLJOY1 = KEY_DBLMOUSE1 + MOUSEBUTTONS,
41 	KEY_DBLHAT1 = KEY_DBLJOY1 + JOYBUTTONS,
42 
43 	KEY_2MOUSE1 = KEY_DBLHAT1 + JOYHATS*4,
44 	KEY_2JOY1 = KEY_2MOUSE1 + MOUSEBUTTONS,
45 	KEY_2HAT1 = KEY_2JOY1 + JOYBUTTONS,
46 
47 	KEY_DBL2MOUSE1 = KEY_2HAT1 + JOYHATS*4,
48 	KEY_DBL2JOY1 = KEY_DBL2MOUSE1 + MOUSEBUTTONS,
49 	KEY_DBL2HAT1 = KEY_DBL2JOY1 + JOYBUTTONS,
50 
51 	KEY_MOUSEWHEELUP = KEY_DBL2HAT1 + JOYHATS*4,
52 	KEY_MOUSEWHEELDOWN = KEY_MOUSEWHEELUP + 1,
53 	KEY_2MOUSEWHEELUP = KEY_MOUSEWHEELDOWN + 1,
54 	KEY_2MOUSEWHEELDOWN = KEY_2MOUSEWHEELUP + 1,
55 
56 	NUMINPUTS = KEY_2MOUSEWHEELDOWN + 1,
57 } key_input_e;
58 
59 typedef enum
60 {
61 	gc_null = 0, // a key/button mapped to gc_null has no effect
62 	gc_forward,
63 	gc_backward,
64 	gc_strafeleft,
65 	gc_straferight,
66 	gc_turnleft,
67 	gc_turnright,
68 	gc_weaponnext,
69 	gc_weaponprev,
70 	gc_wepslot1,
71 	gc_wepslot2,
72 	gc_wepslot3,
73 	gc_wepslot4,
74 	gc_wepslot5,
75 	gc_wepslot6,
76 	gc_wepslot7,
77 	gc_wepslot8,
78 	gc_wepslot9,
79 	gc_wepslot10,
80 	gc_fire,
81 	gc_firenormal,
82 	gc_tossflag,
83 	gc_spin,
84 	gc_camtoggle,
85 	gc_camreset,
86 	gc_lookup,
87 	gc_lookdown,
88 	gc_centerview,
89 	gc_mouseaiming, // mouse aiming is momentary (toggleable in the menu)
90 	gc_talkkey,
91 	gc_teamkey,
92 	gc_scores,
93 	gc_jump,
94 	gc_console,
95 	gc_pause,
96 	gc_systemmenu,
97 	gc_screenshot,
98 	gc_recordgif,
99 	gc_viewpoint,
100 	gc_custom1, // Lua scriptable
101 	gc_custom2, // Lua scriptable
102 	gc_custom3, // Lua scriptable
103 	num_gamecontrols
104 } gamecontrols_e;
105 
106 typedef enum
107 {
108 	gcs_custom,
109 	gcs_fps,
110 	gcs_platform,
111 	num_gamecontrolschemes
112 } gamecontrolschemes_e;
113 
114 // mouse values are used once
115 extern consvar_t cv_mousesens, cv_mouseysens;
116 extern consvar_t cv_mousesens2, cv_mouseysens2;
117 extern consvar_t cv_controlperkey;
118 
119 extern INT32 mousex, mousey;
120 extern INT32 mlooky; //mousey with mlookSensitivity
121 extern INT32 mouse2x, mouse2y, mlook2y;
122 
123 extern INT32 joyxmove[JOYAXISSET], joyymove[JOYAXISSET], joy2xmove[JOYAXISSET], joy2ymove[JOYAXISSET];
124 
125 // current state of the keys: true if pushed
126 extern UINT8 gamekeydown[NUMINPUTS];
127 
128 // two key codes (or virtual key) per game control
129 extern INT32 gamecontrol[num_gamecontrols][2];
130 extern INT32 gamecontrolbis[num_gamecontrols][2]; // secondary splitscreen player
131 extern INT32 gamecontroldefault[num_gamecontrolschemes][num_gamecontrols][2]; // default control storage, use 0 (gcs_custom) for memory retention
132 extern INT32 gamecontrolbisdefault[num_gamecontrolschemes][num_gamecontrols][2];
133 #define PLAYER1INPUTDOWN(gc) (gamekeydown[gamecontrol[gc][0]] || gamekeydown[gamecontrol[gc][1]])
134 #define PLAYER2INPUTDOWN(gc) (gamekeydown[gamecontrolbis[gc][0]] || gamekeydown[gamecontrolbis[gc][1]])
135 #define PLAYERINPUTDOWN(p, gc) ((p) == 2 ? PLAYER2INPUTDOWN(gc) : PLAYER1INPUTDOWN(gc))
136 
137 #define num_gcl_tutorial_check 6
138 #define num_gcl_tutorial_used 8
139 #define num_gcl_tutorial_full 13
140 #define num_gcl_movement 4
141 #define num_gcl_camera 2
142 #define num_gcl_movement_camera 6
143 #define num_gcl_jump 1
144 #define num_gcl_spin 1
145 #define num_gcl_jump_spin 2
146 
147 extern const INT32 gcl_tutorial_check[num_gcl_tutorial_check];
148 extern const INT32 gcl_tutorial_used[num_gcl_tutorial_used];
149 extern const INT32 gcl_tutorial_full[num_gcl_tutorial_full];
150 extern const INT32 gcl_movement[num_gcl_movement];
151 extern const INT32 gcl_camera[num_gcl_camera];
152 extern const INT32 gcl_movement_camera[num_gcl_movement_camera];
153 extern const INT32 gcl_jump[num_gcl_jump];
154 extern const INT32 gcl_spin[num_gcl_spin];
155 extern const INT32 gcl_jump_spin[num_gcl_jump_spin];
156 
157 // peace to my little coder fingers!
158 // check a gamecontrol being active or not
159 
160 // remaps the input event to a game control.
161 void G_MapEventsToControls(event_t *ev);
162 
163 // returns the name of a key
164 const char *G_KeynumToString(INT32 keynum);
165 INT32 G_KeyStringtoNum(const char *keystr);
166 
167 // detach any keys associated to the given game control
168 void G_ClearControlKeys(INT32 (*setupcontrols)[2], INT32 control);
169 void G_ClearAllControlKeys(void);
170 void Command_Setcontrol_f(void);
171 void Command_Setcontrol2_f(void);
172 void G_DefineDefaultControls(void);
173 INT32 G_GetControlScheme(INT32 (*fromcontrols)[2], const INT32 *gclist, INT32 gclen);
174 void G_CopyControls(INT32 (*setupcontrols)[2], INT32 (*fromcontrols)[2], const INT32 *gclist, INT32 gclen);
175 void G_SaveKeySetting(FILE *f, INT32 (*fromcontrols)[2], INT32 (*fromcontrolsbis)[2]);
176 INT32 G_CheckDoubleUsage(INT32 keynum, boolean modify);
177 
178 #endif
179