[input] Get bindings actually working

The mouse bound to movement axes works (though signs are all over the
place, so movement direction is a little off), and binding F10 (key 68)
to quit works :)
This commit is contained in:
Bill Currie 2021-11-12 00:24:04 +09:00
parent 6e85377d7a
commit adaa3c5485
6 changed files with 32 additions and 8 deletions

View file

@ -234,6 +234,7 @@ int IN_RegisterAxis (in_axis_t *axis);
in_button_t *IN_FindButton (const char *name);
in_axis_t *IN_FindAxis (const char *name);
void IN_Binding_Activate (void);
void IN_Binding_Init (void);
#endif

View file

@ -160,7 +160,7 @@ in_binding_axis (const IE_event_t *ie_event)
if (db && axis < db->num_axes) {
db->axis_info[axis].value = value;
if (db->axis_imt_id) {
if (db->axis_imt_id >= 0) {
IMT_ProcessAxis (db->axis_imt_id + axis, value);
}
}
@ -175,7 +175,7 @@ in_binding_button (const IE_event_t *ie_event)
if (db && button < db->num_buttons) {
db->button_info[button].state = state;
if (db->button_imt_id) {
if (db->button_imt_id >= 0) {
IMT_ProcessButton (db->button_imt_id + button, state);
}
}
@ -346,7 +346,7 @@ in_bind_f (void)
};
exprtab_t vars_tab = { var_syms, 0 };
exprctx_t exprctx = {
.external_variables = &vars_tab,
.symtab = &vars_tab,
.memsuper = new_memsuper (),
.messages = PL_NewArray (),
};
@ -355,9 +355,12 @@ in_bind_f (void)
int i;
for (i = 6; i < argc; i++) {
const char *arg = Cmd_Argv (i);
if (!cexpr_eval_string (arg, &exprctx)) {
PL_Message (exprctx.messages, 0, "error parsing recipe: %s",
arg);
if (cexpr_eval_string (arg, &exprctx)) {
plitem_t *messages = exprctx.messages;
for (int j = 0; j < PL_A_NumObjects (messages); j++) {
Sys_Printf ("%s\n",
PL_String (PL_ObjectAtIndex (messages, j)));
}
break;
}
}
@ -376,7 +379,7 @@ in_bind_f (void)
return;
}
if (dev->button_imt_id == -1) {
dev->button_imt_id = IMT_GetAxisBlock (dev->num_buttons);
dev->button_imt_id = IMT_GetButtonBlock (dev->num_buttons);
}
IMT_BindButton (imt, dev->button_imt_id + num, binding);
}
@ -686,6 +689,12 @@ static bindcmd_t in_binding_commands[] = {
#endif
};
void
IN_Binding_Activate (void)
{
IE_Set_Focus (in_binding_handler);
}
void
IN_Binding_Init (void)
{

View file

@ -353,6 +353,7 @@ IMT_BindAxis (imt_t *imt, int axis_num, in_axis_t *axis,
*(a->recipe = alloc_recipe ()) = *recipe;
Hash_AddElement (recipe_tab, a->recipe);
}
a->axis = axis;
}
}
@ -392,9 +393,9 @@ IMT_ProcessAxis (int axis, int value)
int deadzone = recipe->deadzone;
int minval = recipe->min + recipe->minzone;
int maxval = recipe->max - recipe->maxzone;
int input = bound (minval, value, maxval);
float output;
if (relative) {
int input = value;
if (deadzone > 0) {
if (input > deadzone) {
input -= deadzone;
@ -409,6 +410,7 @@ IMT_ProcessAxis (int axis, int value)
output = powf (output, recipe->curve);
}
} else {
int input = bound (minval, value, maxval);
int range = maxval - minval;
int zero = minval;
if (recipe->deadzone >= 0) {
@ -623,6 +625,7 @@ static imtcmd_t imt_commands[] = {
{ "imt_drop_all", imt_drop_all_f,
"delete all imt tables\n"
},
{},
};
void

View file

@ -32,6 +32,7 @@
#include "qw/protocol.h"
void CL_Input_Activate (void);
void CL_Input_Init (void);
void CL_Input_Init_Cvars (void);
void CL_ClearStates (void);

View file

@ -580,6 +580,13 @@ CL_Input_Init (void)
"Call a game function or QuakeC function.");
}
void
CL_Input_Activate (void)
{
IMT_SetContext (cl_game_context);
IN_Binding_Activate ();
}
void
CL_Input_Init_Cvars (void)
{

View file

@ -1162,6 +1162,9 @@ CL_SetState (cactive_t state)
}
}
Con_SetState (state == ca_active ? con_inactive : con_fullscreen);
if (state != old_state && state == ca_active) {
CL_Input_Activate ();
}
}
void