}
static void vid__Close(void) {
if(vid__library_loaded) {
uv_dlclose(&vid__library);
vid__library_loaded = false;
}
vid__active = false;
}
static void vid__API_Printf(int print_level, const char *fmt, ...) {
va_list ap;
const char * msg;
va_start(ap, fmt);
alias_str_stack_formatv(msg, fmt, ap);
va_end(ap);
if(print_level == PRINT_ALL) {
Com_Printf("%s", msg);
} else if(print_level == PRINT_DEVELOPER) {
Com_DPrintf("%s", msg);
} else if(print_level == PRINT_ALERT) {
// MessageBox(0, msg, "PRINT_ALERT", MB_ICONWARNING);
// OutputDebugString(msg);
}
}
static void vid__API_Error(int err_level, const char *fmt, ...) {
va_list ap;
const char * msg;
va_start(ap, fmt);
alias_str_stack_formatv(msg, fmt, ap);
va_end(ap);
Com_Error(err_level, "%s", msg);
}
typedef struct vidmode_s {
const char *description;
int width, height;
int mode;
} vidmode_t;
static vidmode_t vid_modes[] = {{"Mode 0: 320x240", 320, 240, 0}, {"Mode 1: 400x300", 400, 300, 1},
{"Mode 2: 512x384", 512, 384, 2}, {"Mode 3: 640x480", 640, 480, 3},
{"Mode 4: 800x600", 800, 600, 4}, {"Mode 5: 960x720", 960, 720, 5},
{"Mode 6: 1024x768", 1024, 768, 6}, {"Mode 7: 1152x864", 1152, 864, 7},
{"Mode 8: 1280x960", 1280, 960, 8}, {"Mode 9: 1600x1200", 1600, 1200, 9}};
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
static bool vid__API_GetModeInfo(int *width, int *height, int mode) {
if(mode < 0 || mode >= VID_NUM_MODES)
return false;
*width = vid_modes[mode].width;
*height = vid_modes[mode].height;
return true;
}
static void vid__API_NewWindow(int width, int height) {
viddef.width = width;
viddef.height = height;
cl.force_refdef = true; // can't use a paused refdef
}
static bool vid__OpenFunction(GetRefAPI_t function, const char *name) {
refimport_t ri;
Com_Printf("------- Loading %s -------\n", name);
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Con_Printf = vid__API_Printf;
ri.Sys_Error = vid__API_Error;
ri.FS_LoadFile = FS_LoadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_Gamedir = FS_Gamedir;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = vid__API_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = vid__API_NewWindow;
re = function(ri);
if(re.Init(NULL, NULL) != 0) {
re.Shutdown();
vid__Close();
return false;
}
Com_Printf("------------------------------------\n");
vid__active = true;
return true;
}
static bool vid__OpenLibrary(const char *name) {
if(uv_dlopen(name, &vid__library) < 0) {
return false;
}
GetRefAPI_t function;
if(uv_dlsym(&vid__library, "GetRefAPI", (void **)&function) < 0) {
return false;
}
return vid__OpenFunction(function, name);