Input backend refactoring

Get rid of input backend function pointers + some code cleanup that is no longer necessary
This commit is contained in:
Alejandro Ricoveri 2013-04-28 15:03:08 -04:30 committed by Yamagi Burmeister
parent 99dffc3efe
commit 35e1792c91
5 changed files with 80 additions and 125 deletions

View file

@ -27,8 +27,9 @@
#ifndef GEN_INPUT_H #ifndef GEN_INPUT_H
#define GEN_INPUT_H #define GEN_INPUT_H
#include "../../../common/header/shared.h"
typedef void (*Key_Event_fp_t)(int key, qboolean down); typedef void (*Key_Event_fp_t)(int key, qboolean down);
extern void (*IN_Update_fp)(void);
typedef struct in_state typedef struct in_state
{ {
@ -40,4 +41,40 @@ typedef struct in_state
int *in_speed_state; int *in_speed_state;
} in_state_t; } in_state_t;
/*
* Keyboard initialisation. Called by the client.
*/
void IN_KeyboardInit(Key_Event_fp_t fp);
/*
* 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);
/*
* Shuts the input backend down
*/
void IN_BackendMouseButtons(void);
/*
* Move handling
*/
void IN_BackendMove(usercmd_t *cmd);
/*
* Closes all inputs and clears
* the input queue.
*/
void IN_Close(void);
#endif #endif

View file

@ -53,21 +53,13 @@ cvar_t *vid_fullscreen;
/* Global variables used internally by this module */ /* Global variables used internally by this module */
viddef_t viddef; /* global video state; used by other modules */ viddef_t viddef; /* global video state; used by other modules */
void *reflib_library; /* Handle to refresh DLL */
qboolean reflib_active = 0; qboolean reflib_active = 0;
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0])) #define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
void Do_Key_Event(int key, qboolean down); void Do_Key_Event(int key, qboolean down);
void (*IN_Update_fp)(void); // Input state
void (*IN_KeyboardInit_fp)(Key_Event_fp_t fp);
void (*IN_Close_fp)(void);
void (*IN_BackendInit_fp)(in_state_t *in_state_p);
void (*IN_BackendShutdown_fp)(void);
void (*IN_BackendMouseButtons_fp)(void);
void (*IN_BackendMove_fp)(usercmd_t *cmd);
in_state_t in_state; in_state_t in_state;
#define MAXPRINTMSG 4096 #define MAXPRINTMSG 4096
@ -142,7 +134,7 @@ vidmode_t vid_modes[] = {
{"Mode 14: 1280x854", 1280, 854, 14}, {"Mode 14: 1280x854", 1280, 854, 14},
{"Mode 15: 1280x960", 1280, 960, 15}, {"Mode 15: 1280x960", 1280, 960, 15},
{"Mode 16: 1280x1024", 1280, 1024, 16}, {"Mode 16: 1280x1024", 1280, 1024, 16},
{"Mode 17: 1366x768", 1366, 768, 17}, {"Mode 17: 1366x768", 1366, 768, 17},
{"Mode 18: 1440x900", 1440, 900, 18}, {"Mode 18: 1440x900", 1440, 900, 18},
{"Mode 19: 1600x1200", 1600, 1200, 19}, {"Mode 19: 1600x1200", 1600, 1200, 19},
{"Mode 20: 1680x1050", 1680, 1050, 20}, {"Mode 20: 1680x1050", 1680, 1050, 20},
@ -175,7 +167,7 @@ VID_NewWindow(int width, int height)
void void
VID_FreeReflib(void) VID_FreeReflib(void)
{ {
if (reflib_library) /*if (reflib_library)
{ {
if (IN_Close_fp) if (IN_Close_fp)
{ {
@ -186,35 +178,27 @@ VID_FreeReflib(void)
{ {
IN_BackendShutdown_fp(); IN_BackendShutdown_fp();
} }
}*/
//Sys_FreeLibrary(reflib_library); // Shut down the input backend
} IN_Close();
IN_BackendShutdown();
IN_KeyboardInit_fp = NULL;
IN_Update_fp = NULL;
IN_Close_fp = NULL;
IN_BackendInit_fp = NULL;
IN_BackendShutdown_fp = NULL;
IN_BackendMouseButtons_fp = NULL;
IN_BackendMove_fp = NULL;
// Get rid of refexport function pointers
memset(&re, 0, sizeof(re)); memset(&re, 0, sizeof(re));
reflib_library = NULL;
// Declare the refresher as inactive
reflib_active = false; reflib_active = false;
} }
qboolean qboolean
VID_LoadRefresh(char *name) VID_LoadRefresh(char *name)
{ {
refimport_t ri; refimport_t ri; // Refresh imported functions
//R_GetRefAPI_t GetRefAPI;
char fn[MAX_OSPATH];
char *path;
if (reflib_active) if (reflib_active)
{ {
if (IN_Close_fp) /*if (IN_Close_fp)
{ {
IN_Close_fp(); IN_Close_fp();
} }
@ -222,27 +206,15 @@ VID_LoadRefresh(char *name)
if (IN_BackendShutdown_fp) if (IN_BackendShutdown_fp)
{ {
IN_BackendShutdown_fp(); IN_BackendShutdown_fp();
} }*/
IN_Close_fp = NULL;
IN_BackendShutdown_fp = NULL;
re.Shutdown(); re.Shutdown();
VID_FreeReflib(); VID_FreeReflib();
} }
Com_Printf("----- refresher initialization -----\n"); Com_Printf("----- refresher initialization -----\n");
path = Cvar_Get("basedir", ".", CVAR_NOSET)->string; // Fill in client functions for the refresher
snprintf(fn, MAX_OSPATH, "%s/%s", path, name);
/*Sys_LoadLibrary(fn, NULL, &reflib_library);
if (reflib_library == 0)
{
return false;
}*/
ri.Cmd_AddCommand = Cmd_AddCommand; ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand; ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc; ri.Cmd_Argc = Cmd_Argc;
@ -264,20 +236,8 @@ VID_LoadRefresh(char *name)
ri.Vid_MenuInit = VID_MenuInit; ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow; ri.Vid_NewWindow = VID_NewWindow;
/*if ((GetRefAPI = (void *)Sys_GetProcAddress(reflib_library, "R_GetRefAPI")) == 0) // Get refresher API
{ re = R_GetRefAPI(ri);
Com_Error(ERR_FATAL, "Sys_GetProcAddress failed on %s", name);
}*/
//re = GetRefAPI(ri);
re = R_GetRefAPI(ri);
// This is never going to happen
/*if (re.api_version != API_VERSION)
{
VID_FreeReflib();
Com_Error(ERR_FATAL, "%s has incompatible api_version", name);
}*/
/* Init IN (Mouse) */ /* Init IN (Mouse) */
in_state.IN_CenterView_fp = IN_CenterView; in_state.IN_CenterView_fp = IN_CenterView;
@ -286,18 +246,8 @@ VID_LoadRefresh(char *name)
in_state.in_strafe_state = &in_strafe.state; in_state.in_strafe_state = &in_strafe.state;
in_state.in_speed_state = &in_speed.state; in_state.in_speed_state = &in_speed.state;
if (((IN_BackendInit_fp = Sys_GetProcAddress(reflib_library, "IN_BackendInit")) == NULL) || // Initiate the input backend
((IN_BackendShutdown_fp = Sys_GetProcAddress(reflib_library, "IN_BackendShutdown")) == NULL) || IN_BackendInit (&in_state);
((IN_BackendMouseButtons_fp = Sys_GetProcAddress(reflib_library, "IN_BackendMouseButtons")) == NULL) ||
((IN_BackendMove_fp = Sys_GetProcAddress(reflib_library, "IN_BackendMove")) == NULL))
{
Com_Error(ERR_FATAL, "No input backend init functions in REF.\n");
}
if (IN_BackendInit_fp)
{
IN_BackendInit_fp(&in_state);
}
if (re.Init(0, 0) == -1) if (re.Init(0, 0) == -1)
{ {
@ -306,15 +256,8 @@ VID_LoadRefresh(char *name)
return false; return false;
} }
/* Init IN */ // Initiate keyboard at the input backend
if (((IN_KeyboardInit_fp = Sys_GetProcAddress(reflib_library, "IN_KeyboardInit")) == NULL) || IN_KeyboardInit (Do_Key_Event);
((IN_Update_fp = Sys_GetProcAddress(reflib_library, "IN_Update")) == NULL) ||
((IN_Close_fp = Sys_GetProcAddress(reflib_library, "IN_Close")) == NULL))
{
Com_Error(ERR_FATAL, "No keyboard input functions in REF.\n");
}
IN_KeyboardInit_fp(Do_Key_Event);
Key_ClearStates(); Key_ClearStates();
Com_Printf("------------------------------------\n\n"); Com_Printf("------------------------------------\n\n");
@ -347,12 +290,7 @@ VID_CheckChanges(void)
cl.cinematicpalette_active = false; cl.cinematicpalette_active = false;
cls.disable_screen = true; cls.disable_screen = true;
#ifdef _WIN32 // Proceed to reboot the refresher
sprintf(name, "ref_%s.dll", vid_ref->string);
#else
sprintf(name, "ref_%s.so", vid_ref->string);
#endif
if (!VID_LoadRefresh(name)) if (!VID_LoadRefresh(name))
{ {
Cvar_Set("vid_ref", "gl"); Cvar_Set("vid_ref", "gl");
@ -385,7 +323,7 @@ VID_Shutdown(void)
{ {
if (reflib_active) if (reflib_active)
{ {
if (IN_Close_fp) /*if (IN_Close_fp)
{ {
IN_Close_fp(); IN_Close_fp();
} }
@ -393,10 +331,8 @@ VID_Shutdown(void)
if (IN_BackendShutdown_fp) if (IN_BackendShutdown_fp)
{ {
IN_BackendShutdown_fp(); IN_BackendShutdown_fp();
} }*/
IN_Close_fp = NULL;
IN_BackendShutdown_fp = NULL;
re.Shutdown(); re.Shutdown();
VID_FreeReflib(); VID_FreeReflib();
} }
@ -407,28 +343,19 @@ VID_Shutdown(void)
void void
IN_Shutdown(void) IN_Shutdown(void)
{ {
if (IN_BackendShutdown_fp) IN_BackendShutdown();
{
IN_BackendShutdown_fp();
}
} }
void void
IN_Commands(void) IN_Commands(void)
{ {
if (IN_BackendMouseButtons_fp) IN_BackendMouseButtons();
{
IN_BackendMouseButtons_fp();
}
} }
void void
IN_Move(usercmd_t *cmd) IN_Move(usercmd_t *cmd)
{ {
if (IN_BackendMove_fp) IN_BackendMove (cmd);
{
IN_BackendMove_fp(cmd);
}
} }
void void

View file

@ -24,7 +24,7 @@
* *
* ======================================================================= * =======================================================================
*/ */
#include "../../refresh/header/local.h" #include "../../refresh/header/local.h"
#include "../../client/header/keyboard.h" #include "../../client/header/keyboard.h"
#include "../generic/header/input.h" #include "../generic/header/input.h"
@ -91,7 +91,7 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE)) if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE))
{ {
/* These happen to match /* These happen to match
the ASCII chars */ the ASCII chars */
key = (int)keysym; key = (int)keysym;
} }
@ -353,7 +353,7 @@ IN_GetEvent(SDL_Event *event)
/* Fullscreen switch via Alt-Return */ /* Fullscreen switch via Alt-Return */
if ((KeyStates[SDLK_LALT] || if ((KeyStates[SDLK_LALT] ||
KeyStates[SDLK_RALT]) && KeyStates[SDLK_RALT]) &&
(event->key.keysym.sym == SDLK_RETURN)) (event->key.keysym.sym == SDLK_RETURN))
{ {
SDL_WM_ToggleFullScreen(surface); SDL_WM_ToggleFullScreen(surface);
@ -598,8 +598,7 @@ IN_MLookUp(void)
} }
/* /*
* Keyboard initialisation. Called * Keyboard initialisation. Called by the client.
* by the client via function pointer
*/ */
void void
IN_KeyboardInit(Key_Event_fp_t fp) IN_KeyboardInit(Key_Event_fp_t fp)

View file

@ -468,10 +468,7 @@ void
Sys_SendKeyEvents(void) Sys_SendKeyEvents(void)
{ {
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
if (IN_Update_fp) IN_Update();
{
IN_Update_fp();
}
#endif #endif
/* grab frame time */ /* grab frame time */
@ -483,7 +480,7 @@ Sys_GetHomeDir(void)
{ {
static char gdir[MAX_OSPATH]; static char gdir[MAX_OSPATH];
char *home; char *home;
home = getenv("HOME"); home = getenv("HOME");
if (!home) if (!home)
@ -499,7 +496,7 @@ Sys_GetHomeDir(void)
void * void *
Sys_GetProcAddress(void *handle, const char *sym) Sys_GetProcAddress(void *handle, const char *sym)
{ {
return dlsym(handle, sym); return dlsym(handle, sym);
} }
void * void *

View file

@ -56,7 +56,7 @@ unsigned int sys_msg_time;
unsigned int sys_frame_time; unsigned int sys_frame_time;
static char console_text[256]; static char console_text[256];
static int console_textlen; static int console_textlen;
char findbase[MAX_OSPATH]; char findbase[MAX_OSPATH];
char findpath[MAX_OSPATH]; char findpath[MAX_OSPATH];
@ -76,7 +76,7 @@ Sys_Error(char *error, ...)
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
CL_Shutdown(); CL_Shutdown();
#endif #endif
Qcommon_Shutdown(); Qcommon_Shutdown();
va_start(argptr, error); va_start(argptr, error);
@ -164,7 +164,7 @@ Sys_Init(void)
limit Yamagi Quake II to Windows XP and limit Yamagi Quake II to Windows XP and
above. Testing older version would be a above. Testing older version would be a
PITA. */ PITA. */
if (!((vinfo.dwMajorVersion > 5) || if (!((vinfo.dwMajorVersion > 5) ||
((vinfo.dwMajorVersion == 5) && ((vinfo.dwMajorVersion == 5) &&
(vinfo.dwMinorVersion >= 1)))) (vinfo.dwMinorVersion >= 1))))
{ {
@ -300,12 +300,7 @@ void
Sys_SendKeyEvents(void) Sys_SendKeyEvents(void)
{ {
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
IN_Update();
if ( IN_Update_fp )
{
IN_Update_fp();
}
#endif #endif
/* grab frame time */ /* grab frame time */
@ -367,7 +362,7 @@ Sys_GetGameAPI(void *parms)
{ {
Com_DPrintf("LoadLibrary (%s)\n", name); Com_DPrintf("LoadLibrary (%s)\n", name);
break; break;
} }
} }
GetGameAPI = (void *)GetProcAddress(game_library, "GetGameAPI"); GetGameAPI = (void *)GetProcAddress(game_library, "GetGameAPI");
@ -432,7 +427,7 @@ Sys_Milliseconds(void)
curtime = timeGetTime() - base; curtime = timeGetTime() - base;
return curtime; return curtime;
} }
/* ======================================================================= */ /* ======================================================================= */
@ -554,7 +549,7 @@ Sys_FindClose(void)
} }
findhandle = 0; findhandle = 0;
} }
void void
Sys_Mkdir(char *path) Sys_Mkdir(char *path)
@ -633,7 +628,7 @@ Sys_GetHomeDir(void)
} }
old = cur; old = cur;
cur = strchr(old + 1, '\\'); cur = strchr(old + 1, '\\');
} }
} }
@ -688,7 +683,7 @@ Sys_RedirectStdout(void)
/* ======================================================================= */ /* ======================================================================= */
/* /*
* Windows main function. Containts the * Windows main function. Containts the
* initialization code and the main loop * initialization code and the main loop
*/ */
int WINAPI int WINAPI