vid.c refactoring

VID_LoadRefresh with no parameters
VID_LoadRefresh doesn't need a DLL name (because there isn't one)
Rename reflib_active to ref_active
Reference to client input callbacks
All declarations are at the beginning of the file
Full reimplementation of VID_Shutdown
VID_Shutdown does all the refresher cleanup
Reimplementation of VID_FreeReflib
Implementation of VID_LoadRefresh
This commit is contained in:
Alejandro Ricoveri 2013-05-01 10:45:35 -04:30 committed by Yamagi Burmeister
parent 8e69d9dc5c
commit 6686b875cc

View file

@ -41,6 +41,41 @@
#include "../../client/header/client.h"
#include "header/input.h"
typedef struct vidmode_s
{
const char *description;
int width, height;
int mode;
} vidmode_t;
/* This must be the same as in videomenu.c! */
vidmode_t vid_modes[] = {
{"Mode 0: 320x240", 320, 240, 0},
{"Mode 1: 400x300", 400, 300, 1},
{"Mode 2: 512x384", 512, 384, 2},
{"Mode 3: 640x400", 640, 400, 3},
{"Mode 4: 640x480", 640, 480, 4},
{"Mode 5: 800x500", 800, 500, 5},
{"Mode 6: 800x600", 800, 600, 6},
{"Mode 7: 960x720", 960, 720, 7},
{"Mode 8: 1024x480", 1024, 480, 8},
{"Mode 9: 1024x640", 1024, 640, 9},
{"Mode 10: 1024x768", 1024, 768, 10},
{"Mode 11: 1152x768", 1152, 768, 11},
{"Mode 12: 1152x864", 1152, 864, 12},
{"Mode 13: 1280x800", 1280, 800, 13},
{"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 18: 1440x900", 1440, 900, 18},
{"Mode 19: 1600x1200", 1600, 1200, 19},
{"Mode 20: 1680x1050", 1680, 1050, 20},
{"Mode 21: 1920x1080", 1920, 1080, 21},
{"Mode 22: 1920x1200", 1920, 1200, 22},
{"Mode 23: 2048x1536", 2048, 1536, 23},
};
/* Structure containing functions exported from refresh DLL */
refexport_t re;
@ -52,7 +87,7 @@ cvar_t *vid_fullscreen;
/* Global variables used internally by this module */
viddef_t viddef; /* global video state; used by other modules */
qboolean reflib_active = 0;
qboolean ref_active = false; /* Is the refresher being used? */
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
@ -107,41 +142,6 @@ VID_Restart_f(void)
vid_fullscreen->modified = true;
}
typedef struct vidmode_s
{
const char *description;
int width, height;
int mode;
} vidmode_t;
/* This must be the same as in videomenu.c! */
vidmode_t vid_modes[] = {
{"Mode 0: 320x240", 320, 240, 0},
{"Mode 1: 400x300", 400, 300, 1},
{"Mode 2: 512x384", 512, 384, 2},
{"Mode 3: 640x400", 640, 400, 3},
{"Mode 4: 640x480", 640, 480, 4},
{"Mode 5: 800x500", 800, 500, 5},
{"Mode 6: 800x600", 800, 600, 6},
{"Mode 7: 960x720", 960, 720, 7},
{"Mode 8: 1024x480", 1024, 480, 8},
{"Mode 9: 1024x640", 1024, 640, 9},
{"Mode 10: 1024x768", 1024, 768, 10},
{"Mode 11: 1152x768", 1152, 768, 11},
{"Mode 12: 1152x864", 1152, 864, 12},
{"Mode 13: 1280x800", 1280, 800, 13},
{"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 18: 1440x900", 1440, 900, 18},
{"Mode 19: 1600x1200", 1600, 1200, 19},
{"Mode 20: 1680x1050", 1680, 1050, 20},
{"Mode 21: 1920x1080", 1920, 1080, 21},
{"Mode 22: 1920x1200", 1920, 1200, 22},
{"Mode 23: 2048x1536", 2048, 1536, 23},
};
qboolean
VID_GetModeInfo(int *width, int *height, int mode)
{
@ -163,55 +163,23 @@ VID_NewWindow(int width, int height)
viddef.height = height;
}
// Get rid of refexport function pointers
void
VID_FreeReflib(void)
{
/*if (reflib_library)
{
if (IN_Close_fp)
{
IN_Close_fp();
}
if (IN_BackendShutdown_fp)
{
IN_BackendShutdown_fp();
}
}*/
// Shut down the input backend
IN_Close();
IN_BackendShutdown();
// Get rid of refexport function pointers
memset(&re, 0, sizeof(re));
// Declare the refresher as inactive
reflib_active = false;
}
qboolean
//VID_LoadRefresh(char *name)
VID_LoadRefresh(void)
{
refimport_t ri; // Refresh imported functions
if (reflib_active)
{
/*if (IN_Close_fp)
{
IN_Close_fp();
}
if (IN_BackendShutdown_fp)
{
IN_BackendShutdown_fp();
}*/
re.Shutdown();
VID_FreeReflib();
}
// If the refresher is already active
// we'll shut it down
VID_Shutdown();
// Log it!
Com_Printf("----- refresher initialization -----\n");
// Fill in client functions for the refresher
@ -236,7 +204,7 @@ VID_LoadRefresh(void)
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
// Get refresher API
// Get refresher API exports
re = R_GetRefAPI(ri);
/* Init IN (Mouse) */
@ -249,19 +217,21 @@ VID_LoadRefresh(void)
// Initiate the input backend
IN_BackendInit (&in_state);
if (re.Init(0, 0) == -1)
{
re.Shutdown();
VID_FreeReflib();
return false;
}
// Initiate keyboard at the input backend
IN_KeyboardInit (Do_Key_Event);
Key_ClearStates();
// Declare the refresher as active
ref_active = true;
// Initiate the refresher
if (re.Init(0, 0) == -1)
{
VID_Shutdown(); // Isn't that just too bad? :(
return false;
}
Com_Printf("------------------------------------\n\n");
reflib_active = true;
return true;
}
@ -309,24 +279,25 @@ VID_Init(void)
void
VID_Shutdown(void)
{
if (reflib_active)
if (ref_active)
{
/*if (IN_Close_fp)
{
IN_Close_fp();
}
if (IN_BackendShutdown_fp)
{
IN_BackendShutdown_fp();
}*/
// Shut down the input backend
IN_Close();
IN_BackendShutdown();
/* Shut down the renderer */
re.Shutdown();
// Get rid of refexport function pointers
// (soon to be deleted)
VID_FreeReflib();
}
// Declare the refresher as inactive
ref_active = false;
}
/* INPUT */
/* Input callbacks from client */
void
IN_Shutdown(void)