diff --git a/src/backends/generic/header/input.h b/src/backends/generic/header/input.h index 151155ee..4fd32850 100644 --- a/src/backends/generic/header/input.h +++ b/src/backends/generic/header/input.h @@ -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 diff --git a/src/backends/generic/vid.c b/src/backends/generic/vid.c index f6c6a64a..543ba4ed 100644 --- a/src/backends/generic/vid.c +++ b/src/backends/generic/vid.c @@ -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 @@ -142,7 +134,7 @@ vidmode_t vid_modes[] = { {"Mode 14: 1280x854", 1280, 854, 14}, {"Mode 15: 1280x960", 1280, 960, 15}, {"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 19: 1600x1200", 1600, 1200, 19}, {"Mode 20: 1680x1050", 1680, 1050, 20}, @@ -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,20 +236,8 @@ 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); - 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); - }*/ + // Get refresher API + re = R_GetRefAPI(ri); /* Init IN (Mouse) */ 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_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 diff --git a/src/backends/sdl/input.c b/src/backends/sdl/input.c index 4076babe..b450f823 100644 --- a/src/backends/sdl/input.c +++ b/src/backends/sdl/input.c @@ -24,7 +24,7 @@ * * ======================================================================= */ - + #include "../../refresh/header/local.h" #include "../../client/header/keyboard.h" #include "../generic/header/input.h" @@ -91,7 +91,7 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym) if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE)) { - /* These happen to match + /* These happen to match the ASCII chars */ key = (int)keysym; } @@ -353,7 +353,7 @@ IN_GetEvent(SDL_Event *event) /* Fullscreen switch via Alt-Return */ if ((KeyStates[SDLK_LALT] || - KeyStates[SDLK_RALT]) && + KeyStates[SDLK_RALT]) && (event->key.keysym.sym == SDLK_RETURN)) { SDL_WM_ToggleFullScreen(surface); @@ -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) diff --git a/src/backends/unix/system.c b/src/backends/unix/system.c index 54586c44..79cb9428 100644 --- a/src/backends/unix/system.c +++ b/src/backends/unix/system.c @@ -468,10 +468,7 @@ void Sys_SendKeyEvents(void) { #ifndef DEDICATED_ONLY - if (IN_Update_fp) - { - IN_Update_fp(); - } + IN_Update(); #endif /* grab frame time */ @@ -483,7 +480,7 @@ Sys_GetHomeDir(void) { static char gdir[MAX_OSPATH]; char *home; - + home = getenv("HOME"); if (!home) @@ -499,7 +496,7 @@ Sys_GetHomeDir(void) void * Sys_GetProcAddress(void *handle, const char *sym) { - return dlsym(handle, sym); + return dlsym(handle, sym); } void * diff --git a/src/backends/windows/system.c b/src/backends/windows/system.c index 9cde34c5..c179aae1 100644 --- a/src/backends/windows/system.c +++ b/src/backends/windows/system.c @@ -56,7 +56,7 @@ unsigned int sys_msg_time; unsigned int sys_frame_time; static char console_text[256]; -static int console_textlen; +static int console_textlen; char findbase[MAX_OSPATH]; char findpath[MAX_OSPATH]; @@ -76,7 +76,7 @@ Sys_Error(char *error, ...) #ifndef DEDICATED_ONLY CL_Shutdown(); #endif - + Qcommon_Shutdown(); va_start(argptr, error); @@ -164,7 +164,7 @@ Sys_Init(void) limit Yamagi Quake II to Windows XP and above. Testing older version would be a PITA. */ - if (!((vinfo.dwMajorVersion > 5) || + if (!((vinfo.dwMajorVersion > 5) || ((vinfo.dwMajorVersion == 5) && (vinfo.dwMinorVersion >= 1)))) { @@ -300,12 +300,7 @@ void Sys_SendKeyEvents(void) { #ifndef DEDICATED_ONLY - - if ( IN_Update_fp ) - { - IN_Update_fp(); - } - + IN_Update(); #endif /* grab frame time */ @@ -367,7 +362,7 @@ Sys_GetGameAPI(void *parms) { Com_DPrintf("LoadLibrary (%s)\n", name); break; - } + } } GetGameAPI = (void *)GetProcAddress(game_library, "GetGameAPI"); @@ -432,7 +427,7 @@ Sys_Milliseconds(void) curtime = timeGetTime() - base; return curtime; -} +} /* ======================================================================= */ @@ -554,7 +549,7 @@ Sys_FindClose(void) } findhandle = 0; -} +} void Sys_Mkdir(char *path) @@ -633,7 +628,7 @@ Sys_GetHomeDir(void) } 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 */ int WINAPI