mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
Input backend refactoring
Get rid of input backend function pointers + some code cleanup that is no longer necessary
This commit is contained in:
parent
99dffc3efe
commit
35e1792c91
5 changed files with 80 additions and 125 deletions
|
@ -27,8 +27,9 @@
|
|||
#ifndef GEN_INPUT_H
|
||||
#define GEN_INPUT_H
|
||||
|
||||
#include "../../../common/header/shared.h"
|
||||
|
||||
typedef void (*Key_Event_fp_t)(int key, qboolean down);
|
||||
extern void (*IN_Update_fp)(void);
|
||||
|
||||
typedef struct in_state
|
||||
{
|
||||
|
@ -40,4 +41,40 @@ typedef struct in_state
|
|||
int *in_speed_state;
|
||||
} 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
|
||||
|
|
|
@ -53,21 +53,13 @@ cvar_t *vid_fullscreen;
|
|||
|
||||
/* Global variables used internally by this module */
|
||||
viddef_t viddef; /* global video state; used by other modules */
|
||||
void *reflib_library; /* Handle to refresh DLL */
|
||||
qboolean reflib_active = 0;
|
||||
|
||||
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
|
||||
|
||||
void Do_Key_Event(int key, qboolean down);
|
||||
|
||||
void (*IN_Update_fp)(void);
|
||||
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);
|
||||
|
||||
// Input state
|
||||
in_state_t in_state;
|
||||
|
||||
#define MAXPRINTMSG 4096
|
||||
|
@ -175,7 +167,7 @@ VID_NewWindow(int width, int height)
|
|||
void
|
||||
VID_FreeReflib(void)
|
||||
{
|
||||
if (reflib_library)
|
||||
/*if (reflib_library)
|
||||
{
|
||||
if (IN_Close_fp)
|
||||
{
|
||||
|
@ -186,35 +178,27 @@ VID_FreeReflib(void)
|
|||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
}*/
|
||||
|
||||
//Sys_FreeLibrary(reflib_library);
|
||||
}
|
||||
|
||||
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;
|
||||
// Shut down the input backend
|
||||
IN_Close();
|
||||
IN_BackendShutdown();
|
||||
|
||||
// Get rid of refexport function pointers
|
||||
memset(&re, 0, sizeof(re));
|
||||
reflib_library = NULL;
|
||||
|
||||
// Declare the refresher as inactive
|
||||
reflib_active = false;
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_LoadRefresh(char *name)
|
||||
{
|
||||
refimport_t ri;
|
||||
//R_GetRefAPI_t GetRefAPI;
|
||||
|
||||
char fn[MAX_OSPATH];
|
||||
char *path;
|
||||
refimport_t ri; // Refresh imported functions
|
||||
|
||||
if (reflib_active)
|
||||
{
|
||||
if (IN_Close_fp)
|
||||
/*if (IN_Close_fp)
|
||||
{
|
||||
IN_Close_fp();
|
||||
}
|
||||
|
@ -222,27 +206,15 @@ VID_LoadRefresh(char *name)
|
|||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
}*/
|
||||
|
||||
IN_Close_fp = NULL;
|
||||
IN_BackendShutdown_fp = NULL;
|
||||
re.Shutdown();
|
||||
VID_FreeReflib();
|
||||
}
|
||||
|
||||
Com_Printf("----- refresher initialization -----\n");
|
||||
|
||||
path = Cvar_Get("basedir", ".", CVAR_NOSET)->string;
|
||||
snprintf(fn, MAX_OSPATH, "%s/%s", path, name);
|
||||
|
||||
/*Sys_LoadLibrary(fn, NULL, &reflib_library);
|
||||
|
||||
if (reflib_library == 0)
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
|
||||
|
||||
// Fill in client functions for the refresher
|
||||
ri.Cmd_AddCommand = Cmd_AddCommand;
|
||||
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
|
||||
ri.Cmd_Argc = Cmd_Argc;
|
||||
|
@ -264,21 +236,9 @@ VID_LoadRefresh(char *name)
|
|||
ri.Vid_MenuInit = VID_MenuInit;
|
||||
ri.Vid_NewWindow = VID_NewWindow;
|
||||
|
||||
/*if ((GetRefAPI = (void *)Sys_GetProcAddress(reflib_library, "R_GetRefAPI")) == 0)
|
||||
{
|
||||
Com_Error(ERR_FATAL, "Sys_GetProcAddress failed on %s", name);
|
||||
}*/
|
||||
|
||||
//re = GetRefAPI(ri);
|
||||
// Get refresher API
|
||||
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) */
|
||||
in_state.IN_CenterView_fp = IN_CenterView;
|
||||
in_state.Key_Event_fp = Do_Key_Event;
|
||||
|
@ -286,18 +246,8 @@ VID_LoadRefresh(char *name)
|
|||
in_state.in_strafe_state = &in_strafe.state;
|
||||
in_state.in_speed_state = &in_speed.state;
|
||||
|
||||
if (((IN_BackendInit_fp = Sys_GetProcAddress(reflib_library, "IN_BackendInit")) == NULL) ||
|
||||
((IN_BackendShutdown_fp = Sys_GetProcAddress(reflib_library, "IN_BackendShutdown")) == NULL) ||
|
||||
((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);
|
||||
}
|
||||
// Initiate the input backend
|
||||
IN_BackendInit (&in_state);
|
||||
|
||||
if (re.Init(0, 0) == -1)
|
||||
{
|
||||
|
@ -306,15 +256,8 @@ VID_LoadRefresh(char *name)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Init IN */
|
||||
if (((IN_KeyboardInit_fp = Sys_GetProcAddress(reflib_library, "IN_KeyboardInit")) == NULL) ||
|
||||
((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);
|
||||
// Initiate keyboard at the input backend
|
||||
IN_KeyboardInit (Do_Key_Event);
|
||||
Key_ClearStates();
|
||||
|
||||
Com_Printf("------------------------------------\n\n");
|
||||
|
@ -347,12 +290,7 @@ VID_CheckChanges(void)
|
|||
cl.cinematicpalette_active = false;
|
||||
cls.disable_screen = true;
|
||||
|
||||
#ifdef _WIN32
|
||||
sprintf(name, "ref_%s.dll", vid_ref->string);
|
||||
#else
|
||||
sprintf(name, "ref_%s.so", vid_ref->string);
|
||||
#endif
|
||||
|
||||
// Proceed to reboot the refresher
|
||||
if (!VID_LoadRefresh(name))
|
||||
{
|
||||
Cvar_Set("vid_ref", "gl");
|
||||
|
@ -385,7 +323,7 @@ VID_Shutdown(void)
|
|||
{
|
||||
if (reflib_active)
|
||||
{
|
||||
if (IN_Close_fp)
|
||||
/*if (IN_Close_fp)
|
||||
{
|
||||
IN_Close_fp();
|
||||
}
|
||||
|
@ -393,10 +331,8 @@ VID_Shutdown(void)
|
|||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
}*/
|
||||
|
||||
IN_Close_fp = NULL;
|
||||
IN_BackendShutdown_fp = NULL;
|
||||
re.Shutdown();
|
||||
VID_FreeReflib();
|
||||
}
|
||||
|
@ -407,28 +343,19 @@ VID_Shutdown(void)
|
|||
void
|
||||
IN_Shutdown(void)
|
||||
{
|
||||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
IN_BackendShutdown();
|
||||
}
|
||||
|
||||
void
|
||||
IN_Commands(void)
|
||||
{
|
||||
if (IN_BackendMouseButtons_fp)
|
||||
{
|
||||
IN_BackendMouseButtons_fp();
|
||||
}
|
||||
IN_BackendMouseButtons();
|
||||
}
|
||||
|
||||
void
|
||||
IN_Move(usercmd_t *cmd)
|
||||
{
|
||||
if (IN_BackendMove_fp)
|
||||
{
|
||||
IN_BackendMove_fp(cmd);
|
||||
}
|
||||
IN_BackendMove (cmd);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -598,8 +598,7 @@ IN_MLookUp(void)
|
|||
}
|
||||
|
||||
/*
|
||||
* Keyboard initialisation. Called
|
||||
* by the client via function pointer
|
||||
* Keyboard initialisation. Called by the client.
|
||||
*/
|
||||
void
|
||||
IN_KeyboardInit(Key_Event_fp_t fp)
|
||||
|
|
|
@ -468,10 +468,7 @@ void
|
|||
Sys_SendKeyEvents(void)
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
if (IN_Update_fp)
|
||||
{
|
||||
IN_Update_fp();
|
||||
}
|
||||
IN_Update();
|
||||
#endif
|
||||
|
||||
/* grab frame time */
|
||||
|
|
|
@ -300,12 +300,7 @@ void
|
|||
Sys_SendKeyEvents(void)
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
|
||||
if ( IN_Update_fp )
|
||||
{
|
||||
IN_Update_fp();
|
||||
}
|
||||
|
||||
IN_Update();
|
||||
#endif
|
||||
|
||||
/* grab frame time */
|
||||
|
|
Loading…
Reference in a new issue