User:Monster Iestyn/Source Code Documentation/g_input.h

From SRB2 Wiki
Jump to navigation Jump to search
Online link GitHub entry
File type C header file
#include guard __G_INPUT__

This header file declares constants, variables and function prototypes needed for handling inputs (keyboard, mouse or joystick), and mapping of inputs to game controls.

Includes

Macros

Constants

Macro Defined as Description
NUMKEYS 256 Total number of keyboard key inputs

Button sets

Macro Default Wii PSP Xbox Dreamcast Description
MOUSEBUTTONS 8 3 3 5 5 Total number of mouse buttons
JOYBUTTONS 32 20 14 12 8 Total number of joystick buttons
JOYHATS 4 1 1 1 2 Total number of joystick hats
JOYAXISSET 4 5 1 2 3 Total number of joystick axis sets

Functions

Macro Defined as Description
PLAYER1INPUTDOWN(gc)
(gamekeydown[gamecontrol[gc][0]] || gamekeydown[gamecontrol[gc][1]])
Determines if a key assigned to the game control is currently pressed down for player 1
PLAYER2INPUTDOWN(gc)
(gamekeydown[gamecontrolbis[gc][0]] || gamekeydown[gamecontrolbis[gc][1]])
Determines if a key assigned to the game control is currently pressed down for player 2

Typedefs

Name Type Description
key_input_e enum Key inputs.
gamecontrols_e enum Game controls.

Enumerations

key_input_e

Name Defined as Value Description
Default Wii PSP Xbox Dreamcast
KEY_MOUSE1 NUMKEYS 256 Start of mouse button inputs
KEY_JOY1 KEY_MOUSE1 + MOUSEBUTTONS 264 259 259 261 261 Start of joystick button inputs
KEY_HAT1 KEY_JOY1 + JOYBUTTONS 296 279 273 273 269 Start of joystick hat inputs
KEY_DBLMOUSE1 KEY_HAT1 + JOYHATS*4 312 283 277 277 277 Start of double-click mouse button inputs
KEY_DBLJOY1 KEY_DBLMOUSE1 + MOUSEBUTTONS 320 286 280 282 282 Start of double-click joystick button inputs
KEY_DBLHAT1 KEY_DBLJOY1 + JOYBUTTONS 352 306 294 294 290 Start of double-click joystick hat inputs
KEY_2MOUSE1 KEY_DBLHAT1 + JOYHATS*4 368 310 298 298 298 Start of second mouse button inputs
KEY_2JOY1 KEY_2MOUSE1 + MOUSEBUTTONS 376 313 301 303 303 Start of second joystick button inputs
KEY_2HAT1 KEY_2JOY1 + JOYBUTTONS 408 333 315 315 311 Start of second joystick hat inputs
KEY_DBL2MOUSE1 KEY_2HAT1 + JOYHATS*4 424 337 319 319 319 Start of double-click second mouse inputs
KEY_DBL2JOY1 KEY_DBL2MOUSE1 + MOUSEBUTTONS 432 340 322 324 324 Start of double-click second joystick button inputs
KEY_DBL2HAT1 KEY_DBL2JOY1 + JOYBUTTONS 464 360 336 336 332 Start of double-click second joystick hat inputs
KEY_MOUSEWHEELUP KEY_DBL2HAT1 + JOYHATS*4 480 364 340 340 340 Mouse wheel up input
KEY_MOUSEWHEELDOWN KEY_MOUSEWHEELUP + 1 481 365 341 341 341 Mouse wheel down input
KEY_2MOUSEWHEELUP KEY_MOUSEWHEELDOWN + 1 482 366 342 342 342 Second mouse wheel up input
KEY_2MOUSEWHEELDOWN KEY_2MOUSEWHEELUP + 1 483 367 343 343 343 Second mouse wheel down input
NUMINPUTS KEY_2MOUSEWHEELDOWN + 1 484 368 344 344 344 Total number of possible inputs

gamecontrols_e

Value Name Description
0 gc_null Null game control
1 gc_forward Move Forward
2 gc_backward Move Backward
3 gc_strafeleft Move Left
4 gc_straferight Move Right
5 gc_turnleft Turn Left
6 gc_turnright Turn Right
7 gc_weaponnext Next Weapon
8 gc_weaponprev Previous Weapon
9 gc_wepslot1 Weapon Slot 1
10 gc_wepslot2 Weapon Slot 2
11 gc_wepslot3 Weapon Slot 3
12 gc_wepslot4 Weapon Slot 4
13 gc_wepslot5 Weapon Slot 5
14 gc_wepslot6 Weapon Slot 6
15 gc_wepslot7 Weapon Slot 7
16 gc_wepslot8 Weapon Slot 8 (Unused)
17 gc_wepslot9 Weapon Slot 9 (Unused)
18 gc_wepslot10 Weapon Slot 10 (Unused)
19 gc_fire Ring Toss
20 gc_firenormal Ring Toss Normal
21 gc_tossflag Toss Flag
22 gc_use Spin
23 gc_camtoggle Toggle Third-Person
24 gc_camleft Rotate Camera L
25 gc_camright Rotate Camera R
26 gc_camreset Reset Camera
27 gc_lookup Look Up
28 gc_lookdown Look Down
29 gc_centerview Center View
30 gc_mouseaiming Toggle Mouselook
31 gc_talkkey Talk key
32 gc_teamkey Team-Talk key
33 gc_scores Rankings/Scores
34 gc_jump Jump
35 gc_console Console
36 gc_pause Pause
37 gc_systemmenu Open/Close Menu (ESC)
38 gc_screenshot Screenshot
39 gc_recordgif Toggle GIF Recording
40 gc_viewpoint Change Viewpoint
41 gc_custom1 Custom Action 1
42 gc_custom2 Custom Action 2
43 gc_custom3 Custom Action 3
44 num_gamecontrols Total number of game controls

Externs

Data name Data type Non-extern location(s) Description
cv_mousesens
cv_mouseysens
consvar_t g_input.c mousesens and mouseysens console variable structs.
cv_mousesens2
cv_mouseysens2
consvar_t g_input.c mousesens2 and mouseysens2 console variable structs.
cv_controlperkey consvar_t g_input.c controlperkey console variable struct.
mousex
mousey
INT32 g_input.c Mouse movement in X and Y axes.
mlooky INT32 g_input.c Mouselook movement in Y axis.
mouse2x
mouse2y
mlook2y
INT32 g_input.c Second mouse movement in X and Y axes, and second mouse mouselook movement in Y axis.
joyxmove[JOYAXISSET]
joyymove[JOYAXISSET]
joy2xmove[JOYAXISSET]
joy2ymove[JOYAXISSET]
INT32 g_input.c Tables for first and second joystick axis movement in X and Y axes.
gamekeydown[NUMINPUTS] UINT8 g_input.c Table storing the current state of all keys: set to 1 if pushed, 0 if not.
gamecontrol[num_gamecontrols][2] INT32 g_input.c The game controls table for player 1. Two key codes are allowed per game control.
gamecontrolbis[num_gamecontrols][2] INT32 g_input.c The game controls table for player 2. Two key codes are allowed per game control.

Function prototypes

Console commands

Function name Return type Params Defined in Description
Command_Setcontrol_f void none g_input.c The function called by the setcontrol console command.
Command_Setcontrol2_f void none g_input.c The function called by the setcontrol2 console command.

Other

Function name Return type Params Defined in Description
G_MapEventsToControls void event_t *ev g_input.c Remaps the inputs to game controls.
G_KeynumToString const char * INT32 keynum g_input.c Returns the string name for a key. This may be either a printable character (letters, numbers, punctuation, etc.), one of the special key names, or otherwise a string in the format KEYkeynum (for keys without either of the former).
G_KeyStringtoNum INT32 const char *keystr g_input.c Returns the key number for a string. (the reverse of G_KeynumToString)
G_ClearControlKeys void INT32 (*setupcontrols)[2],
INT32 control
g_input.c Detaches any keys assigned to the given game control. setupcontrols should be the pointer to the game controls table for the player being edited (either gamecontrol or gamecontrolbis).
G_ClearAllControlKeys void none g_input.c
G_Controldefault void none g_input.c Assigns the default keys for all game controls. Note: the default keys given depend on the port of SRB2 the source code is compiled for.
G_SaveKeySetting void FILE *f g_input.c Saves the keys assigned to all game controls to the file (typically a configuration file such as config.cfg). They will be saved as strings in the format used by the setcontrol and setcontrol2 console commands to assign keys to controls.
G_CheckDoubleUsage INT32 INT32 keynum,
boolean modify
g_input.c If the console variable controlperkey is set to 1 (one key per control), this checks if any game controls are already assigned to the key (for both player 1 and player 2) – if any of them do, the controls will be cleared.