#include <assert.h>
#include <float.h>
#include "../client/client.h"
#include "winquake.h"
refexport_t re;
cvar_t *win_noalttab;
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL (WM_MOUSELAST + 1)
#endif
static UINT MSH_MOUSEWHEEL;
cvar_t *vid_gamma;
cvar_t *vid_ref; cvar_t *vid_xpos; cvar_t *vid_ypos; cvar_t *vid_fullscreen;
viddef_t viddef; HINSTANCE reflib_library; bool reflib_active = 0;
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[0]))
static bool s_alttab_disabled;
extern unsigned sys_msg_time;
#define MAXPRINTMSG 4096
void VID_Printf(int print_level, const char *fmt, ...) {
va_list argptr;
char msg[MAXPRINTMSG];
static bool inupdate;
va_start(argptr, fmt);
vsprintf(msg, fmt, argptr);
va_end(argptr);
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);
}
}
void VID_Error(int err_level, const char *fmt, ...) {
va_list argptr;
char msg[MAXPRINTMSG];
static bool inupdate;
va_start(argptr, fmt);
vsprintf(msg, fmt, argptr);
va_end(argptr);
Com_Error(err_level, "%s", msg);
}
byte scantokey[128] = {
0, 27, '1', '2', '3', '4', '5',
'6', '7', '8', '9', '0', '-', '=',
K_BACKSPACE, 9, 'q', 'w', 'e', 'r', 't', 'y', 'u',
'i', 'o', 'p', '[', ']', 13, K_CTRL,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l',
';', '\'', '`', K_SHIFT, '\\', 'z', 'x',
'c', 'v', 'b', 'n', 'm', ',', '.', '/', K_SHIFT,
'*', K_ALT, ' ', 0, K_F1, K_F2, K_F3,
K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0,
K_HOME, K_UPARROW, K_PGUP, K_KP_MINUS, K_LEFTARROW, K_KP_5, K_RIGHTARROW,
K_KP_PLUS, K_END, K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0,
K_F11, K_F12, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0 };
void AppActivate(bool fActive, bool minimize) {
Minimized = minimize;
Key_ClearStates();
if(fActive && !Minimized)
ActiveApp = true;
else
ActiveApp = false;
if(!ActiveApp) {
IN_Activate(false);
} else {
IN_Activate(true);
}
}
void VID_Restart_f(void) { vid_ref->modified = true; }
void VID_Front_f(void) {
}
typedef struct vidmode_s {
const char *description;
int width, height;
int mode;
} vidmode_t;
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}};
bool VID_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;
}
void VID_NewWindow(int width, int height) {
viddef.width = width;
viddef.height = height;
cl.force_refdef = true; }
void VID_FreeReflib(void) {
if(reflib_library != NULL) {
if(!FreeLibrary(reflib_library)) {
Com_Error(ERR_FATAL, "Reflib FreeLibrary failed");
}
reflib_library = NULL;
}
memset(&re, 0, sizeof(re));
reflib_active = false;
}
static bool load_refresh_api(GetRefAPI_t get_api, 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_Printf;
ri.Sys_Error = VID_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_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
re = get_api(ri);
if(re.Init(global_hInstance, NULL) == -1) {
re.Shutdown();
VID_FreeReflib();
return false;
}
Com_Printf("------------------------------------\n");
reflib_active = true;
return true;
}
bool VID_LoadRefresh(char *name) {
GetRefAPI_t GetRefAPI;
if(reflib_active) {
re.Shutdown();
VID_FreeReflib();
}
if((reflib_library = LoadLibrary(name)) == 0) {
Com_Printf("LoadLibrary(\"%s\") failed\n", name);
return false;
}
if((GetRefAPI = (void *)GetProcAddress(reflib_library, "GetRefAPI")) == 0)
Com_Error(ERR_FATAL, "GetProcAddress failed on %s", name);
return load_refresh_api(GetRefAPI, name);
}
void VID_CheckChanges(void) {
char name[100];
if(vid_ref->modified) {
cl.force_refdef = true; S_StopAllSounds();
}
while(vid_ref->modified) {
vid_ref->modified = false;
vid_fullscreen->modified = true;
cl.refresh_prepped = false;
cls.disable_screen = true;
if(strcmp(vid_ref->string, "internal") == 0) {
extern refexport_t GetRefAPI(refimport_t rimp);
load_refresh_api(GetRefAPI, "internal");
} else {
Com_sprintf(name, sizeof(name), "ref_%s.dll", vid_ref->string);
if(!VID_LoadRefresh(name)) {
Cvar_Set("vid_ref", "internal");
if(cls.key_dest != key_console) {
Con_ToggleConsole_f();
}
}
}
cls.disable_screen = false;
}
if(vid_xpos->modified || vid_ypos->modified) {
vid_xpos->modified = false;
vid_ypos->modified = false;
}
}
void VID_Init(void) {
vid_ref = Cvar_Get("vid_ref", "soft", CVAR_ARCHIVE);
vid_xpos = Cvar_Get("vid_xpos", "3", CVAR_ARCHIVE);
vid_ypos = Cvar_Get("vid_ypos", "22", CVAR_ARCHIVE);
vid_fullscreen = Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE);
vid_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE);
win_noalttab = Cvar_Get("win_noalttab", "0", CVAR_ARCHIVE);
Cmd_AddCommand("vid_restart", VID_Restart_f);
Cmd_AddCommand("vid_front", VID_Front_f);
#if 0#endif
putenv("FX_GLIDE_NO_SPLASH=0");
VID_CheckChanges();
}
void VID_Shutdown(void) {
if(reflib_active) {
re.Shutdown();
VID_FreeReflib();
}
}