Untangle the input system from the refresher

In the old times the refresher was a stand alone DLL. For performance
reasons and to avoid laggy input parts of the input system were
implemented in this DLL. Now that the renfresher is part of the main
binary and initialized at client startup we can remove most of the
abstractions between input system, refresher and client. Also the
input system can be treated as a normal subsystem.

Changes:
- Untangle the VID_* stuff and the IN_* stuff. The functions
  called by function pointers in in_state are now called directly
  and 'struct in_state' was removed.

- Remove input.h and rename the appropriate backend functions.
  There's no longer a need for an abstraction layer between the
  input backend and the input frontend.

- Move input initialization and shutdown into CL_Init(), like it's
  already done for all other subsystems.

- Remove Key_ClearStates(). I'm pretty sure that's a left over from
  the old Win 9x backends and unnecessary.

- General cleanup.
This commit is contained in:
Yamagi Burmeister 2015-01-16 16:58:46 +01:00
parent 08c0b8e56a
commit db10e0db87
10 changed files with 64 additions and 192 deletions

View file

@ -29,41 +29,24 @@
#include "../../../common/header/shared.h"
typedef void (*Key_Event_fp_t)(int key, qboolean down);
typedef struct in_state
{
/* Pointers to functions back in client, set by vid_so */
void (*IN_CenterView_fp)(void);
Key_Event_fp_t Key_Event_fp;
vec_t *viewangles;
int *in_strafe_state;
int *in_speed_state;
} in_state_t;
/*
* Initializes the input backend
*/
void IN_Init(void);
/*
* Keyboard initialisation. Called by the client.
* Move handling
*/
void IN_KeyboardInit(Key_Event_fp_t fp);
void IN_Move(usercmd_t *cmd);
/*
* Shuts the backend down
*/
void IN_Shutdown(void);
/*
* Updates the state of the input queue
*/
void IN_Update(void);
/*
* Initializes the input backend
*/
void IN_BackendInit(in_state_t *in_state_p);
/*
* Shuts the backend down
*/
void IN_BackendShutdown(void);
/*
* Move handling
*/
void IN_BackendMove(usercmd_t *cmd);
#endif

View file

@ -39,7 +39,6 @@
#include <errno.h>
#include "../../client/header/client.h"
#include "header/input.h"
typedef struct vidmode_s
{
@ -87,12 +86,6 @@ viddef_t viddef; /* global video state; used by other modules */
qboolean ref_active = false; /* Is the refresher being used? */
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
void Do_Key_Event(int key, qboolean down);
// Input state
in_state_t in_state;
#define MAXPRINTMSG 4096
void
@ -170,16 +163,6 @@ VID_LoadRefresh(void)
// Log it!
Com_Printf("----- refresher initialization -----\n");
/* Init IN (Mouse) */
in_state.IN_CenterView_fp = IN_CenterView;
in_state.Key_Event_fp = Do_Key_Event;
in_state.viewangles = cl.viewangles;
in_state.in_strafe_state = &in_strafe.state;
in_state.in_speed_state = &in_speed.state;
// Initiate the input backend
IN_BackendInit (&in_state);
// Declare the refresher as active
ref_active = true;
@ -190,10 +173,6 @@ VID_LoadRefresh(void)
return false;
}
// Initiate keyboard at the input backend
IN_KeyboardInit(Do_Key_Event);
Key_ClearStates();
Com_Printf("------------------------------------\n\n");
return true;
}
@ -244,9 +223,6 @@ VID_Shutdown(void)
{
if (ref_active)
{
// Shut down the input backend
IN_BackendShutdown();
/* Shut down the renderer */
R_Shutdown();
}
@ -254,24 +230,3 @@ VID_Shutdown(void)
// Declare the refresher as inactive
ref_active = false;
}
/* Input callbacks from client */
void
IN_Shutdown(void)
{
IN_BackendShutdown();
}
void
IN_Move(usercmd_t *cmd)
{
IN_BackendMove (cmd);
}
void
Do_Key_Event(int key, qboolean down)
{
Key_Event(key, down, Sys_Milliseconds());
}

View file

@ -68,8 +68,6 @@
#define MOUSE_MIN 40
/* Globals */
Key_Event_fp_t Key_Event_fp;
static in_state_t *in_state;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static qboolean have_grab;
@ -341,22 +339,22 @@ IN_Update(void)
/* The mouse wheel */
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL:
in_state->Key_Event_fp((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), true);
in_state->Key_Event_fp((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), false);
Key_Event((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), true);
Key_Event((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), false);
break;
#endif
case SDL_MOUSEBUTTONDOWN:
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (event.button.button == 4)
{
in_state->Key_Event_fp(K_MWHEELUP, true);
in_state->Key_Event_fp(K_MWHEELUP, false);
Key_Event(K_MWHEELUP, true);
Key_Event(K_MWHEELUP, false);
break;
}
else if (event.button.button == 5)
{
in_state->Key_Event_fp(K_MWHEELDOWN, true);
in_state->Key_Event_fp(K_MWHEELDOWN, false);
Key_Event(K_MWHEELDOWN, true);
Key_Event(K_MWHEELDOWN, false);
break;
}
#endif
@ -383,20 +381,24 @@ IN_Update(void)
return;
}
in_state->Key_Event_fp(key, (event.type == SDL_MOUSEBUTTONDOWN));
Key_Event(key, (event.type == SDL_MOUSEBUTTONDOWN));
break;
case SDL_MOUSEMOTION:
#if SDL_VERSION_ATLEAST(2, 0, 0)
/* This is a hack to work around an unsuccessful
* SDL_SetRelativeMouseMode(). This can happen if
* some broken security software is blocking raw
* input (to prevent keyloggers accessing the input
* queue), or if - on Linux / Unix - XInput2 is not
* available.
* Since SDL_WarpMouseInWindow() injects a movement
* event into the queue, we ignore events that move
* the mouse exactly to the warp position. */
SDL_SetRelativeMouseMode(). This can happen if
some broken security software is blocking raw
input (to prevent keyloggers accessing the input
queue), or if - on Linux / Unix - XInput2 is not
available.
Since SDL_WarpMouseInWindow() injects a movement
event into the queue, we ignore events that move
the mouse exactly to the warp position.
The underlying issue _should_ be solved in SDL
2.0.3 an above. */
if (have_grab && !in_relativemode)
{
int center_x = vid.width / 2;
@ -425,10 +427,7 @@ IN_Update(void)
break;
}
/* Make Shift+Escape toggle the console. This
really belongs in Key_Event(), but since
Key_ClearStates() can mess up the internal
K_SHIFT state let's do it here instead. */
/* Make Shift+Escape toggle the console. */
if ((modstate & KMOD_SHIFT) && (event.key.keysym.sym == SDLK_ESCAPE))
{
Cbuf_ExecuteText(EXEC_NOW, "toggleconsole");
@ -440,7 +439,7 @@ IN_Update(void)
if (key)
{
in_state->Key_Event_fp(key, true);
Key_Event(key, true);
}
break;
@ -453,7 +452,7 @@ IN_Update(void)
if (key)
{
in_state->Key_Event_fp(key, false);
Key_Event(key, false);
}
break;
@ -476,7 +475,7 @@ IN_Update(void)
* Move handling
*/
void
IN_BackendMove(usercmd_t *cmd)
IN_Move(usercmd_t *cmd)
{
if (m_filter->value)
{
@ -530,20 +529,18 @@ IN_BackendMove(usercmd_t *cmd)
}
/* add mouse X/Y movement to cmd */
if ((*in_state->in_strafe_state & 1) ||
(lookstrafe->value && mlooking))
if ((in_strafe.state & 1) || (lookstrafe->value && mlooking))
{
cmd->sidemove += m_side->value * mouse_x;
}
else
{
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
}
if ((mlooking || freelook->value) &&
!(*in_state->in_strafe_state & 1))
if ((mlooking || freelook->value) && !(in_strafe.state & 1))
{
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
cl.viewangles[PITCH] += m_pitch->value * mouse_y;
}
else
{
@ -562,7 +559,7 @@ IN_BackendMove(usercmd_t *cmd)
static void
IN_ForceCenterView(void)
{
in_state->viewangles[PITCH] = 0;
cl.viewangles[PITCH] = 0;
}
/*
@ -581,38 +578,19 @@ static void
IN_MLookUp(void)
{
mlooking = false;
in_state->IN_CenterView_fp();
IN_CenterView();
}
/* ------------------------------------------------------------------ */
/*
* Keyboard initialisation. Called by the client.
*/
void
IN_KeyboardInit(Key_Event_fp_t fp)
{
Key_Event_fp = fp;
/* SDL stuff. Moved here from IN_BackendInit because
this must be done after video is initialized. */
have_grab = GLimp_InputIsGrabbed();
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetRelativeMouseMode(have_grab ? SDL_TRUE : SDL_FALSE);
in_relativemode = (SDL_GetRelativeMouseMode() == SDL_TRUE);
#else
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#endif
}
/*
* Initializes the backend
*/
void
IN_BackendInit(in_state_t *in_state_p)
IN_Init(void)
{
in_state = in_state_p;
Com_Printf("------- input initialization -------\n");
mouse_x = mouse_y = 0;
exponential_speedup = Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE);
@ -633,22 +611,31 @@ IN_BackendInit(in_state_t *in_state_p)
Cmd_AddCommand("-mlook", IN_MLookUp);
Cmd_AddCommand("force_centerview", IN_ForceCenterView);
VID_Printf(PRINT_ALL, "Input initialized.\n");
have_grab = GLimp_InputIsGrabbed();
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetRelativeMouseMode(have_grab ? SDL_TRUE : SDL_FALSE);
in_relativemode = (SDL_GetRelativeMouseMode() == SDL_TRUE);
#else
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#endif
Com_Printf("------------------------------------\n\n");
}
/*
* Shuts the backend down
*/
void
IN_BackendShutdown(void)
IN_Shutdown(void)
{
Cmd_RemoveCommand("force_centerview");
Cmd_RemoveCommand("+mlook");
Cmd_RemoveCommand("-mlook");
VID_Printf(PRINT_ALL, "Input shut down.\n");
Com_Printf("Shutting down input.\n");
}
/* ------------------------------------------------------------------ */

View file

@ -26,6 +26,7 @@
*/
#include "header/client.h"
#include "../backends/generic/header/input.h"
cvar_t *cl_nodelta;

View file

@ -898,10 +898,11 @@ Key_Init(void)
* Should NOT be called during an interrupt!
*/
void
Key_Event(int key, qboolean down, unsigned time)
Key_Event(int key, qboolean down)
{
char *kb;
char cmd[1024];
unsigned int time = Sys_Milliseconds();
/* hack for modal presses */
if (key_waiting == -1)
@ -1108,25 +1109,6 @@ Key_Event(int key, qboolean down, unsigned time)
}
}
void
Key_ClearStates(void)
{
int i;
anykeydown = false;
for (i = 0; i < K_LAST; i++)
{
if (keydown[i] || key_repeats[i])
{
Key_Event(i, false, 0);
}
keydown[i] = 0;
key_repeats[i] = 0;
}
}
int
Key_GetKey(void)
{

View file

@ -26,6 +26,7 @@
*/
#include "header/client.h"
#include "../backends/generic/header/input.h"
void CL_ForwardToServer_f(void);
void CL_Changing_f(void);
@ -877,6 +878,8 @@ CL_Init(void)
VID_Init();
IN_Init();
V_Init();
net_message.data = net_message_buffer;
@ -920,6 +923,7 @@ CL_Shutdown(void)
OGG_Stop();
#endif
S_Shutdown();
IN_Shutdown();
VID_Shutdown();
}

View file

@ -50,7 +50,6 @@
#include "ref.h"
#include "vid.h"
#include "screen.h"
#include "input.h"
#include "keyboard.h"
#include "console.h"

View file

@ -1,37 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* =======================================================================
*
* Header for the upper layer of the input system. This is for all
* non-keyboard devices.
*
* =======================================================================
*/
#ifndef CL_HEADER_INPUT_H
#define CL_HEADER_INPUT_H
void IN_Shutdown (void);
void IN_Frame (void);
/* add additional movement on top of the keyboard move cmd */
void IN_Move (usercmd_t *cmd);
#endif

View file

@ -287,11 +287,10 @@ extern int chat_bufferlen;
extern int chat_cursorpos;
extern qboolean chat_team;
void Key_Event (int key, qboolean down, unsigned time);
void Key_Event (int key, qboolean down);
void Key_Init (void);
void Key_WriteBindings (FILE *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);
int Key_GetKey (void);
#endif

View file

@ -95,7 +95,6 @@ M_ForceMenuOff(void)
m_keyfunc = NULL;
cls.key_dest = key_game;
m_menudepth = 0;
Key_ClearStates();
Cvar_Set("paused", "0");
}