mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
[input] Move button name and description
This puts the name and description into the button itself, making it much easier to look them up.
This commit is contained in:
parent
09e3e62a0a
commit
fae9e043df
4 changed files with 193 additions and 177 deletions
|
@ -91,6 +91,7 @@ typedef struct in_button_s {
|
||||||
int down[2]; ///< button ids holding this button down
|
int down[2]; ///< button ids holding this button down
|
||||||
int state; ///< in_button_state
|
int state; ///< in_button_state
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *description;
|
||||||
} in_button_t;
|
} in_button_t;
|
||||||
|
|
||||||
typedef struct in_axisbinding_s {
|
typedef struct in_axisbinding_s {
|
||||||
|
@ -211,8 +212,7 @@ IN_ButtonReleased (in_button_t *button)
|
||||||
|
|
||||||
void IN_ButtonAction (in_button_t *buttin, int id, int pressed);
|
void IN_ButtonAction (in_button_t *buttin, int id, int pressed);
|
||||||
|
|
||||||
int IN_RegisterButton (in_button_t *button, const char *name,
|
int IN_RegisterButton (in_button_t *button);
|
||||||
const char *description);
|
|
||||||
int IN_RegisterAxis (in_axis_t *axis, const char *name,
|
int IN_RegisterAxis (in_axis_t *axis, const char *name,
|
||||||
const char *description);
|
const char *description);
|
||||||
in_button_t *IN_FindButton (const char *name);
|
in_button_t *IN_FindButton (const char *name);
|
||||||
|
|
|
@ -45,8 +45,6 @@
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
|
|
||||||
typedef struct regbutton_s {
|
typedef struct regbutton_s {
|
||||||
const char *name;
|
|
||||||
const char *description;
|
|
||||||
in_button_t *button;
|
in_button_t *button;
|
||||||
char *press_cmd;
|
char *press_cmd;
|
||||||
char *release_cmd;
|
char *release_cmd;
|
||||||
|
@ -58,7 +56,7 @@ static const char *
|
||||||
button_get_key (const void *b, void *data)
|
button_get_key (const void *b, void *data)
|
||||||
{
|
{
|
||||||
__auto_type regbutton = (const regbutton_t *) b;
|
__auto_type regbutton = (const regbutton_t *) b;
|
||||||
return regbutton->name;
|
return regbutton->button->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -162,16 +160,14 @@ button_release_cmd (void *_b)
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE int
|
VISIBLE int
|
||||||
IN_RegisterButton (in_button_t *button, const char *name,
|
IN_RegisterButton (in_button_t *button)
|
||||||
const char *description)
|
|
||||||
{
|
{
|
||||||
|
const char *name = button->name;
|
||||||
if (Hash_Find (button_tab, name)) {
|
if (Hash_Find (button_tab, name)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t size = strlen (name) + 2;
|
size_t size = strlen (name) + 2;
|
||||||
regbutton_t *regbutton = malloc (sizeof (regbutton_t) + 2 * size);
|
regbutton_t *regbutton = malloc (sizeof (regbutton_t) + 2 * size);
|
||||||
regbutton->name = name;
|
|
||||||
regbutton->description = description;
|
|
||||||
regbutton->button = button;
|
regbutton->button = button;
|
||||||
|
|
||||||
regbutton->press_cmd = (char *) (regbutton + 1);
|
regbutton->press_cmd = (char *) (regbutton + 1);
|
||||||
|
|
|
@ -50,88 +50,99 @@
|
||||||
#include "nq/include/client.h"
|
#include "nq/include/client.h"
|
||||||
#include "nq/include/host.h"
|
#include "nq/include/host.h"
|
||||||
|
|
||||||
/*
|
in_button_t in_left = {
|
||||||
KEY BUTTONS
|
.name = "left",
|
||||||
|
.description = "When active the player is turning left"
|
||||||
|
};
|
||||||
|
in_button_t in_right = {
|
||||||
|
.name = "right",
|
||||||
|
.description = "When active the player is turning right"
|
||||||
|
};
|
||||||
|
in_button_t in_forward = {
|
||||||
|
.name = "forward",
|
||||||
|
.description = "When active the player is moving forward"
|
||||||
|
};
|
||||||
|
in_button_t in_back = {
|
||||||
|
.name = "back",
|
||||||
|
.description = "When active the player is moving backwards"
|
||||||
|
};
|
||||||
|
in_button_t in_lookup = {
|
||||||
|
.name = "lookup",
|
||||||
|
.description = "When active the player's view is looking up"
|
||||||
|
};
|
||||||
|
in_button_t in_lookdown = {
|
||||||
|
.name = "lookdown",
|
||||||
|
.description = "When active the player's view is looking down"
|
||||||
|
};
|
||||||
|
in_button_t in_moveleft = {
|
||||||
|
.name = "moveleft",
|
||||||
|
.description = "When active the player is strafing left"
|
||||||
|
};
|
||||||
|
in_button_t in_moveright = {
|
||||||
|
.name = "moveright",
|
||||||
|
.description = "When active the player is strafing right"
|
||||||
|
};
|
||||||
|
in_button_t in_use = {
|
||||||
|
.name = "use",
|
||||||
|
.description = "Left over command for opening doors and triggering"
|
||||||
|
" switches"
|
||||||
|
};
|
||||||
|
in_button_t in_jump = {
|
||||||
|
.name = "jump",
|
||||||
|
.description = "When active the player is jumping"
|
||||||
|
};
|
||||||
|
in_button_t in_attack = {
|
||||||
|
.name = "attack",
|
||||||
|
.description = "When active player is firing/using current weapon"
|
||||||
|
};
|
||||||
|
in_button_t in_up = {
|
||||||
|
.name = "moveup",
|
||||||
|
.description = "When active the player is swimming up in a liquid"
|
||||||
|
};
|
||||||
|
in_button_t in_down = {
|
||||||
|
.name = "movedown",
|
||||||
|
.description = "When active the player is swimming down in a liquid"
|
||||||
|
};
|
||||||
|
in_button_t in_strafe = {
|
||||||
|
.name = "strafe",
|
||||||
|
.description = "When active, +left and +right function like +moveleft and"
|
||||||
|
" +moveright"
|
||||||
|
};
|
||||||
|
in_button_t in_klook = {
|
||||||
|
.name = "klook",
|
||||||
|
.description = "When active, +forward and +back perform +lookup and"
|
||||||
|
" +lookdown"
|
||||||
|
};
|
||||||
|
in_button_t in_speed = {
|
||||||
|
.name = "speed",
|
||||||
|
.description = "When active the player is running"
|
||||||
|
};
|
||||||
|
in_button_t in_mlook = {
|
||||||
|
.name = "mlook",
|
||||||
|
.description = "When active moving the mouse or joystick forwards "
|
||||||
|
"and backwards performs +lookup and "
|
||||||
|
"+lookdown"
|
||||||
|
};
|
||||||
|
|
||||||
Continuous button event tracking is complicated by the fact that two
|
static in_button_t *cl_in_buttons[] = {
|
||||||
different input sources (say, mouse button 1 and the control key) can
|
&in_left,
|
||||||
both press the same button, but the button should be released only when
|
&in_right,
|
||||||
both of the pressing key have been released.
|
&in_forward,
|
||||||
|
&in_back,
|
||||||
When a key event issues a button command (+forward, +attack, etc), it
|
&in_lookup,
|
||||||
appends its key number as a parameter to the command so it can be
|
&in_lookdown,
|
||||||
matched up with the release.
|
&in_moveleft,
|
||||||
|
&in_moveright,
|
||||||
state bit 0 is the current state of the key
|
&in_use,
|
||||||
state bit 1 is edge triggered on the up to down transition
|
&in_jump,
|
||||||
state bit 2 is edge triggered on the down to up transition
|
&in_attack,
|
||||||
*/
|
&in_up,
|
||||||
|
&in_down,
|
||||||
in_button_t in_left, in_right, in_forward, in_back;
|
&in_strafe,
|
||||||
in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
|
&in_klook,
|
||||||
in_button_t in_use, in_jump, in_attack;
|
&in_speed,
|
||||||
in_button_t in_up, in_down;
|
&in_mlook,
|
||||||
in_button_t in_strafe, in_klook, in_speed, in_mlook;
|
0
|
||||||
|
|
||||||
static struct {
|
|
||||||
const char *name;
|
|
||||||
in_button_t *button;
|
|
||||||
const char *description;
|
|
||||||
} cl_in_buttons[] = {
|
|
||||||
{ "left", &in_left,
|
|
||||||
"When active the player is turning left"
|
|
||||||
},
|
|
||||||
{ "right", &in_right,
|
|
||||||
"When active the player is turning right"
|
|
||||||
},
|
|
||||||
{ "forward", &in_forward,
|
|
||||||
"When active the player is moving forward"
|
|
||||||
},
|
|
||||||
{ "back", &in_back,
|
|
||||||
"When active the player is moving backwards"
|
|
||||||
},
|
|
||||||
{ "lookup", &in_lookup,
|
|
||||||
"When active the player's view is looking up"
|
|
||||||
},
|
|
||||||
{ "lookdown", &in_lookdown,
|
|
||||||
"When active the player's view is looking down"
|
|
||||||
},
|
|
||||||
{ "moveleft", &in_moveleft,
|
|
||||||
"When active the player is strafing left"
|
|
||||||
},
|
|
||||||
{ "moveright", &in_moveright,
|
|
||||||
"When active the player is strafing right"
|
|
||||||
},
|
|
||||||
{ "use", &in_use,
|
|
||||||
"Left over command for opening doors and triggering switches"
|
|
||||||
},
|
|
||||||
{ "jump", &in_jump,
|
|
||||||
"When active the player is jumping"
|
|
||||||
},
|
|
||||||
{ "attack", &in_attack,
|
|
||||||
"When active player is firing/using current weapon"
|
|
||||||
},
|
|
||||||
{ "moveup", &in_up,
|
|
||||||
"When active the player is swimming up in a liquid"
|
|
||||||
},
|
|
||||||
{ "movedown", &in_down,
|
|
||||||
"When active the player is swimming down in a liquid"
|
|
||||||
},
|
|
||||||
{ "strafe", &in_strafe,
|
|
||||||
"When active, +left and +right function like +moveleft and +moveright"
|
|
||||||
},
|
|
||||||
{ "speed", &in_speed,
|
|
||||||
"When active the player is running"
|
|
||||||
},
|
|
||||||
{ "klook", &in_klook,
|
|
||||||
"When active, +forward and +back perform +lookup and +lookdown"
|
|
||||||
},
|
|
||||||
{ "mlook", &in_mlook,
|
|
||||||
"When active moving the mouse or joystick forwards "
|
|
||||||
"and backwards performs +lookup and "
|
|
||||||
"+lookdown"
|
|
||||||
},
|
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int in_impulse;
|
int in_impulse;
|
||||||
|
@ -351,9 +362,8 @@ CL_SendMove (usercmd_t *cmd)
|
||||||
void
|
void
|
||||||
CL_Input_Init (void)
|
CL_Input_Init (void)
|
||||||
{
|
{
|
||||||
for (int i = 0; cl_in_buttons[i].name; i++) {
|
for (int i = 0; cl_in_buttons[i]; i++) {
|
||||||
IN_RegisterButton (cl_in_buttons[i].button, cl_in_buttons[i].name,
|
IN_RegisterButton (cl_in_buttons[i]);
|
||||||
cl_in_buttons[i].description);
|
|
||||||
}
|
}
|
||||||
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
||||||
"Call a game function or QuakeC function.");
|
"Call a game function or QuakeC function.");
|
||||||
|
|
|
@ -63,88 +63,99 @@ cvar_t *cl_nodelta;
|
||||||
cvar_t *cl_maxnetfps;
|
cvar_t *cl_maxnetfps;
|
||||||
cvar_t *cl_spamimpulse;
|
cvar_t *cl_spamimpulse;
|
||||||
|
|
||||||
/*
|
in_button_t in_left = {
|
||||||
KEY BUTTONS
|
.name = "left",
|
||||||
|
.description = "When active the player is turning left"
|
||||||
|
};
|
||||||
|
in_button_t in_right = {
|
||||||
|
.name = "right",
|
||||||
|
.description = "When active the player is turning right"
|
||||||
|
};
|
||||||
|
in_button_t in_forward = {
|
||||||
|
.name = "forward",
|
||||||
|
.description = "When active the player is moving forward"
|
||||||
|
};
|
||||||
|
in_button_t in_back = {
|
||||||
|
.name = "back",
|
||||||
|
.description = "When active the player is moving backwards"
|
||||||
|
};
|
||||||
|
in_button_t in_lookup = {
|
||||||
|
.name = "lookup",
|
||||||
|
.description = "When active the player's view is looking up"
|
||||||
|
};
|
||||||
|
in_button_t in_lookdown = {
|
||||||
|
.name = "lookdown",
|
||||||
|
.description = "When active the player's view is looking down"
|
||||||
|
};
|
||||||
|
in_button_t in_moveleft = {
|
||||||
|
.name = "moveleft",
|
||||||
|
.description = "When active the player is strafing left"
|
||||||
|
};
|
||||||
|
in_button_t in_moveright = {
|
||||||
|
.name = "moveright",
|
||||||
|
.description = "When active the player is strafing right"
|
||||||
|
};
|
||||||
|
in_button_t in_use = {
|
||||||
|
.name = "use",
|
||||||
|
.description = "Left over command for opening doors and triggering"
|
||||||
|
" switches"
|
||||||
|
};
|
||||||
|
in_button_t in_jump = {
|
||||||
|
.name = "jump",
|
||||||
|
.description = "When active the player is jumping"
|
||||||
|
};
|
||||||
|
in_button_t in_attack = {
|
||||||
|
.name = "attack",
|
||||||
|
.description = "When active player is firing/using current weapon"
|
||||||
|
};
|
||||||
|
in_button_t in_up = {
|
||||||
|
.name = "moveup",
|
||||||
|
.description = "When active the player is swimming up in a liquid"
|
||||||
|
};
|
||||||
|
in_button_t in_down = {
|
||||||
|
.name = "movedown",
|
||||||
|
.description = "When active the player is swimming down in a liquid"
|
||||||
|
};
|
||||||
|
in_button_t in_strafe = {
|
||||||
|
.name = "strafe",
|
||||||
|
.description = "When active, +left and +right function like +moveleft and"
|
||||||
|
" +moveright"
|
||||||
|
};
|
||||||
|
in_button_t in_klook = {
|
||||||
|
.name = "klook",
|
||||||
|
.description = "When active, +forward and +back perform +lookup and"
|
||||||
|
" +lookdown"
|
||||||
|
};
|
||||||
|
in_button_t in_speed = {
|
||||||
|
.name = "speed",
|
||||||
|
.description = "When active the player is running"
|
||||||
|
};
|
||||||
|
in_button_t in_mlook = {
|
||||||
|
.name = "mlook",
|
||||||
|
.description = "When active moving the mouse or joystick forwards "
|
||||||
|
"and backwards performs +lookup and "
|
||||||
|
"+lookdown"
|
||||||
|
};
|
||||||
|
|
||||||
Continuous button event tracking is complicated by the fact that two
|
static in_button_t *cl_in_buttons[] = {
|
||||||
different input sources (say, mouse button 1 and the control key) can
|
&in_left,
|
||||||
both press the same button, but the button should be released only when
|
&in_right,
|
||||||
both of the pressing key have been released.
|
&in_forward,
|
||||||
|
&in_back,
|
||||||
When a key event issues a button command (+forward, +attack, etc), it
|
&in_lookup,
|
||||||
appends its key number as a parameter to the command so it can be
|
&in_lookdown,
|
||||||
matched up with the release.
|
&in_moveleft,
|
||||||
|
&in_moveright,
|
||||||
state bit 0 is the current state of the key
|
&in_use,
|
||||||
state bit 1 is edge triggered on the up to down transition
|
&in_jump,
|
||||||
state bit 2 is edge triggered on the down to up transition
|
&in_attack,
|
||||||
*/
|
&in_up,
|
||||||
|
&in_down,
|
||||||
in_button_t in_left, in_right, in_forward, in_back;
|
&in_strafe,
|
||||||
in_button_t in_lookup, in_lookdown, in_moveleft, in_moveright;
|
&in_klook,
|
||||||
in_button_t in_use, in_jump, in_attack;
|
&in_speed,
|
||||||
in_button_t in_up, in_down;
|
&in_mlook,
|
||||||
in_button_t in_strafe, in_klook, in_speed, in_mlook;
|
0
|
||||||
|
|
||||||
static struct {
|
|
||||||
const char *name;
|
|
||||||
in_button_t *button;
|
|
||||||
const char *description;
|
|
||||||
} cl_in_buttons[] = {
|
|
||||||
{ "left", &in_left,
|
|
||||||
"When active the player is turning left"
|
|
||||||
},
|
|
||||||
{ "right", &in_right,
|
|
||||||
"When active the player is turning right"
|
|
||||||
},
|
|
||||||
{ "forward", &in_forward,
|
|
||||||
"When active the player is moving forward"
|
|
||||||
},
|
|
||||||
{ "back", &in_back,
|
|
||||||
"When active the player is moving backwards"
|
|
||||||
},
|
|
||||||
{ "lookup", &in_lookup,
|
|
||||||
"When active the player's view is looking up"
|
|
||||||
},
|
|
||||||
{ "lookdown", &in_lookdown,
|
|
||||||
"When active the player's view is looking down"
|
|
||||||
},
|
|
||||||
{ "moveleft", &in_moveleft,
|
|
||||||
"When active the player is strafing left"
|
|
||||||
},
|
|
||||||
{ "moveright", &in_moveright,
|
|
||||||
"When active the player is strafing right"
|
|
||||||
},
|
|
||||||
{ "use", &in_use,
|
|
||||||
"Left over command for opening doors and triggering switches"
|
|
||||||
},
|
|
||||||
{ "jump", &in_jump,
|
|
||||||
"When active the player is jumping"
|
|
||||||
},
|
|
||||||
{ "attack", &in_attack,
|
|
||||||
"When active player is firing/using current weapon"
|
|
||||||
},
|
|
||||||
{ "moveup", &in_up,
|
|
||||||
"When active the player is swimming up in a liquid"
|
|
||||||
},
|
|
||||||
{ "movedown", &in_down,
|
|
||||||
"When active the player is swimming down in a liquid"
|
|
||||||
},
|
|
||||||
{ "strafe", &in_strafe,
|
|
||||||
"When active, +left and +right function like +moveleft and +moveright"
|
|
||||||
},
|
|
||||||
{ "speed", &in_speed,
|
|
||||||
"When active the player is running"
|
|
||||||
},
|
|
||||||
{ "klook", &in_klook,
|
|
||||||
"When active, +forward and +back perform +lookup and +lookdown"
|
|
||||||
},
|
|
||||||
{ "mlook", &in_mlook,
|
|
||||||
"When active moving the mouse or joystick forwards "
|
|
||||||
"and backwards performs +lookup and "
|
|
||||||
"+lookdown"
|
|
||||||
},
|
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int in_impulse;
|
int in_impulse;
|
||||||
|
@ -508,9 +519,8 @@ CL_SendCmd (void)
|
||||||
void
|
void
|
||||||
CL_Input_Init (void)
|
CL_Input_Init (void)
|
||||||
{
|
{
|
||||||
for (int i = 0; cl_in_buttons[i].name; i++) {
|
for (int i = 0; cl_in_buttons[i]; i++) {
|
||||||
IN_RegisterButton (cl_in_buttons[i].button, cl_in_buttons[i].name,
|
IN_RegisterButton (cl_in_buttons[i]);
|
||||||
cl_in_buttons[i].description);
|
|
||||||
}
|
}
|
||||||
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
Cmd_AddDataCommand ("impulse", IN_Impulse, 0,
|
||||||
"Call a game function or QuakeC function.");
|
"Call a game function or QuakeC function.");
|
||||||
|
|
Loading…
Reference in a new issue