From 55ed30ad15c72f52aea124389b9997745d4dbf02 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 26 Sep 2002 01:24:41 +0000 Subject: [PATCH] this commit adds video mode switching, and preferred mode is saved to config, no more need for -window/-width/-height/-bpp (they still work) IN_Init and IN_Shutdown code has been merged into VID_InitMode and VID_Shutdown code in each of the video systems VID_InitCvars renamed to VID_Shared_Init VID_Open and VID_Close functions added in vid_shared, Host_Init now calls VID_Open S_Open/Close and CDAudio_Open/Close added (none of these do anything yet) VID_Open and VID_Close call R_Modules_Start, S_Open, and CDAudio_Open and their corresponding Close functions VID_Restart_f added (vid_restart command) vid_hidden now starts true (to avoid any refreshs until video is started) vid_fullscreen/width/height/bitsperpixel are now saved to config VID_Open is called after configs are parsed Render_Init now longer starts/stops modules IN_MouseEvent in vid_wgl.c no longer clamps pitch (since that's done by IN_PostMove) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2442 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_linux.c | 7 ++++ cd_null.c | 8 ++++ cd_win.c | 8 ++++ cdaudio.h | 2 + gl_rmain.c | 2 - host.c | 32 +++++---------- input.h | 4 -- snd_alsa_0_5.c | 8 ++++ snd_alsa_0_9.c | 8 ++++ snd_null.c | 9 +++++ snd_oss.c | 9 +++++ snd_win.c | 9 ++++- sound.h | 2 + vid.h | 7 +++- vid_glx.c | 13 ++----- vid_null.c | 8 ---- vid_shared.c | 75 ++++++++++++++++++++++++++++++++--- vid_wgl.c | 103 ++++++++++++++++++++----------------------------- 18 files changed, 197 insertions(+), 117 deletions(-) diff --git a/cd_linux.c b/cd_linux.c index 7ee79189..eb8ef45f 100644 --- a/cd_linux.c +++ b/cd_linux.c @@ -418,3 +418,10 @@ void CDAudio_Shutdown(void) cdfile = -1; } +void CDAudio_Open(void) +{ +} + +void CDAudio_Close(void) +{ +} diff --git a/cd_null.c b/cd_null.c index 4d6667d3..f9eb413d 100644 --- a/cd_null.c +++ b/cd_null.c @@ -56,3 +56,11 @@ void CDAudio_Shutdown(void) { } + +void CDAudio_Open(void) +{ +} + +void CDAudio_Close(void) +{ +} diff --git a/cd_win.c b/cd_win.c index d31b72e8..8d9f5684 100644 --- a/cd_win.c +++ b/cd_win.c @@ -475,3 +475,11 @@ void CDAudio_Shutdown(void) Con_DPrintf("CDAudio_Shutdown: MCI_CLOSE failed\n"); } + +void CDAudio_Open(void) +{ +} + +void CDAudio_Close(void) +{ +} diff --git a/cdaudio.h b/cdaudio.h index 09c0d300..f3191d63 100644 --- a/cdaudio.h +++ b/cdaudio.h @@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int CDAudio_Init(void); +void CDAudio_Open(void); +void CDAudio_Close(void); void CDAudio_Play(qbyte track, qboolean looping); void CDAudio_Stop(void); void CDAudio_Pause(void); diff --git a/gl_rmain.c b/gl_rmain.c index 5552b0cb..e17054dd 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -293,7 +293,6 @@ extern void Sbar_Init(void); void Render_Init(void) { - R_Modules_Shutdown(); R_Textures_Init(); Mod_RenderInit(); gl_backend_init(); @@ -309,7 +308,6 @@ void Render_Init(void) R_Explosion_Init(); ui_init(); Sbar_Init(); - R_Modules_Start(); } /* diff --git a/host.c b/host.c index 42dca46c..55aa6868 100644 --- a/host.c +++ b/host.c @@ -881,42 +881,29 @@ void Host_Init (void) if (cls.state != ca_dedicated) { - VID_InitCvars(); - Gamma_Init(); - Palette_Init(); - -#ifndef _WIN32 // on non win32, mouse comes before video for security reasons - IN_Init (); -#endif + VID_Shared_Init(); VID_Init(); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) - { - if (vid_fullscreen.integer) - { - if (!VID_Mode(true, 640, 480, 16)) - if (!VID_Mode(false, 640, 480, 16)) - Sys_Error("Video modes failed\n"); - } - else - Sys_Error("Requested windowed video mode failed\n"); - } Render_Init(); S_Init (); CDAudio_Init (); CL_Init (); -#ifdef _WIN32 // on non win32, mouse comes before video for security reasons - IN_Init (); -#endif } Cbuf_InsertText ("exec quake.rc\n"); + Cbuf_Execute (); + Cbuf_Execute (); + Cbuf_Execute (); + Cbuf_Execute (); host_initialized = true; - Sys_Printf ("========Quake Initialized=========\n"); + Con_Printf ("========Quake Initialized=========\n"); + + if (cls.state != ca_dedicated) + VID_Open(); } @@ -944,7 +931,6 @@ void Host_Shutdown(void) CDAudio_Shutdown (); NET_Shutdown (); S_Shutdown(); - IN_Shutdown (); if (cls.state != ca_dedicated) { diff --git a/input.h b/input.h index 9bff65e8..30f76ef5 100644 --- a/input.h +++ b/input.h @@ -25,10 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern cvar_t in_pitch_min; extern cvar_t in_pitch_max; -void IN_Init (void); - -void IN_Shutdown (void); - void IN_Commands (void); // oportunity for devices to stick commands on the script buffer diff --git a/snd_alsa_0_5.c b/snd_alsa_0_5.c index 1522429f..082fbe50 100644 --- a/snd_alsa_0_5.c +++ b/snd_alsa_0_5.c @@ -341,3 +341,11 @@ void *S_LockBuffer(void) void S_UnlockBuffer(void) { } + +void S_Open(void) +{ +} + +void S_Close(void) +{ +} diff --git a/snd_alsa_0_9.c b/snd_alsa_0_9.c index 0e05ef88..3d4129dd 100644 --- a/snd_alsa_0_9.c +++ b/snd_alsa_0_9.c @@ -314,3 +314,11 @@ void S_UnlockBuffer(void) { } + +void S_Open(void) +{ +} + +void S_Close(void) +{ +} diff --git a/snd_null.c b/snd_null.c index 546b0e8a..e699ac56 100755 --- a/snd_null.c +++ b/snd_null.c @@ -123,3 +123,12 @@ int S_RawSamples_SampleRate(void) { return 0; } + + +void S_Open(void) +{ +} + +void S_Close(void) +{ +} diff --git a/snd_oss.c b/snd_oss.c index 14fe64ef..c939d744 100644 --- a/snd_oss.c +++ b/snd_oss.c @@ -277,3 +277,12 @@ void *S_LockBuffer(void) void S_UnlockBuffer(void) { } + + +void S_Open(void) +{ +} + +void S_Close(void) +{ +} diff --git a/snd_win.c b/snd_win.c index 2fed37be..ef670365 100644 --- a/snd_win.c +++ b/snd_win.c @@ -766,9 +766,16 @@ void *S_LockBuffer(void) return shm->buffer; } -void S_UnlockBuffer() +void S_UnlockBuffer(void) { if (pDSBuf) pDSBuf->lpVtbl->Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2); } +void S_Open(void) +{ +} + +void S_Close(void) +{ +} diff --git a/sound.h b/sound.h index e20714bf..684102ee 100644 --- a/sound.h +++ b/sound.h @@ -90,6 +90,8 @@ typedef struct void S_Init (void); void S_Startup (void); void S_Shutdown (void); +void S_Open (void); +void S_Close (void); void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); void S_StopSound (int entnum, int entchannel); diff --git a/vid.h b/vid.h index 6c23c88b..0b83a027 100644 --- a/vid.h +++ b/vid.h @@ -94,7 +94,7 @@ void GL_CloseLibrary(void); void *GL_GetProcAddress(const char *name); int GL_CheckExtension(const char *name, const gl_extensionfunctionlist_t *funcs, const char *disableparm, int silent); -void VID_InitCvars(void); +void VID_Shared_Init(void); void GL_Init (void); @@ -119,5 +119,10 @@ void VID_GetWindowSize (int *x, int *y, int *width, int *height); void VID_Finish (void); +void VID_Restart_f(void); + +void VID_Open (void); +void VID_Close (void); + #endif diff --git a/vid_glx.c b/vid_glx.c index 706cb5fd..0ebdedac 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -474,6 +474,7 @@ void VID_Shutdown(void) if (!ctx || !vidx11_display) return; + vid_hidden = true; if (vidx11_display) { uninstall_grabs(); @@ -639,6 +640,8 @@ void VID_Init(void) Cvar_RegisterVariable (&vid_dga); Cvar_RegisterVariable (&vid_dga_mouseaccel); InitSig(); // trap evil signals + if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe")) + mouse_avail = false; } int VID_InitMode(int fullscreen, int width, int height, int bpp) @@ -842,16 +845,6 @@ void Sys_SendKeyEvents(void) HandleEvents(); } -void IN_Init(void) -{ - if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe")) - mouse_avail = false; -} - -void IN_Shutdown(void) -{ -} - /* =========== IN_Commands diff --git a/vid_null.c b/vid_null.c index 20e82484..5505ea67 100644 --- a/vid_null.c +++ b/vid_null.c @@ -96,14 +96,6 @@ void IN_Commands(void) { } -void IN_Init(void) -{ -} - -void IN_Shutdown(void) -{ -} - void IN_Move(usercmd_t *cmd) { } diff --git a/vid_shared.c b/vid_shared.c index 5cc2ed07..6fb1f5c0 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -18,15 +18,15 @@ int gl_supportslockarrays = false; int gl_videosyncavailable = false; // LordHavoc: if window is hidden, don't update screen -int vid_hidden = false; +int vid_hidden = true; // LordHavoc: if window is not the active window, don't hog as much CPU time, // let go of the mouse, turn off sound, and restore system gamma ramps... int vid_activewindow = true; -cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"}; -cvar_t vid_width = {0, "vid_width", "640"}; -cvar_t vid_height = {0, "vid_height", "480"}; -cvar_t vid_bitsperpixel = {0, "vid_bitsperpixel", "16"}; +cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"}; +cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"}; +cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"}; +cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "16"}; cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"}; cvar_t gl_combine = {0, "gl_combine", "1"}; @@ -393,7 +393,7 @@ void IN_Mouse(usercmd_t *cmd, float mx, float my) } } -void VID_InitCvars(void) +void VID_Shared_Init(void) { int i; @@ -407,6 +407,7 @@ void VID_InitCvars(void) Cvar_RegisterVariable(&in_pitch_max); Cvar_RegisterVariable(&m_filter); Cmd_AddCommand("force_centerview", Force_CenterView_f); + Cmd_AddCommand("vid_restart", VID_Restart_f); // interpret command-line parameters if ((i = COM_CheckParm("-window")) != 0) @@ -421,6 +422,10 @@ void VID_InitCvars(void) Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]); } +int current_vid_fullscreen; +int current_vid_width; +int current_vid_height; +int current_vid_bitsperpixel; extern int VID_InitMode (int fullscreen, int width, int height, int bpp); int VID_Mode(int fullscreen, int width, int height, int bpp) { @@ -429,7 +434,65 @@ int VID_Mode(int fullscreen, int width, int height, int bpp) else Con_Printf("Video: %dx%d windowed\n", width, height); if (VID_InitMode(fullscreen, width, height, bpp)) + { + current_vid_fullscreen = fullscreen; + current_vid_width = width; + current_vid_height = height; + current_vid_bitsperpixel = bpp; return true; + } else return false; } + +static void VID_OpenSystems(void) +{ + R_Modules_Start(); + S_Open(); + CDAudio_Open(); +} + +static void VID_CloseSystems(void) +{ + CDAudio_Close(); + S_Close(); + R_Modules_Shutdown(); +} + +void VID_Restart_f(void) +{ + Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n", + current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, + vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer); + VID_Close(); + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) + { + Con_Printf("Video mode change failed\n"); + if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel)) + Sys_Error("Unable to restore to last working video mode\n"); + } + VID_OpenSystems(); +} + +void VID_Open(void) +{ + Con_Printf("Starting video system\n"); + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) + { + if (vid_fullscreen.integer) + { + if (!VID_Mode(true, 640, 480, 16)) + if (!VID_Mode(false, 640, 480, 16)) + Sys_Error("Video modes failed\n"); + } + else + Sys_Error("Windowed video failed\n"); + } + VID_OpenSystems(); +} + +void VID_Close(void) +{ + VID_CloseSystems(); + VID_Shutdown(); +} diff --git a/vid_wgl.c b/vid_wgl.c index 571b5ad7..d9396128 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -645,6 +645,30 @@ void VID_Init(void) if (!RegisterClass (&wc)) Sys_Error("Couldn't register window class\n"); + + uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" ); + + // joystick variables + Cvar_RegisterVariable (&in_joystick); + Cvar_RegisterVariable (&joy_name); + Cvar_RegisterVariable (&joy_advanced); + Cvar_RegisterVariable (&joy_advaxisx); + Cvar_RegisterVariable (&joy_advaxisy); + Cvar_RegisterVariable (&joy_advaxisz); + Cvar_RegisterVariable (&joy_advaxisr); + Cvar_RegisterVariable (&joy_advaxisu); + Cvar_RegisterVariable (&joy_advaxisv); + Cvar_RegisterVariable (&joy_forwardthreshold); + Cvar_RegisterVariable (&joy_sidethreshold); + Cvar_RegisterVariable (&joy_pitchthreshold); + Cvar_RegisterVariable (&joy_yawthreshold); + Cvar_RegisterVariable (&joy_forwardsensitivity); + Cvar_RegisterVariable (&joy_sidesensitivity); + Cvar_RegisterVariable (&joy_pitchsensitivity); + Cvar_RegisterVariable (&joy_yawsensitivity); + Cvar_RegisterVariable (&joy_wwhack1); + Cvar_RegisterVariable (&joy_wwhack2); + Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f); } int VID_InitMode (int fullscreen, int width, int height, int bpp) @@ -878,6 +902,10 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) //vid_menukeyfn = VID_MenuKey; vid_hidden = false; vid_initialized = true; + + IN_StartupMouse (); + IN_StartupJoystick (); + return true; } @@ -889,8 +917,21 @@ void VID_Shutdown (void) if (vid_initialized) { vid_initialized = false; + + IN_DeactivateMouse (); + IN_ShowMouse (); + + if (g_pMouse) + IDirectInputDevice_Release(g_pMouse); + g_pMouse = NULL; + + if (g_pdi) + IDirectInput_Release(g_pdi); + g_pdi = NULL; + if (qwglGetCurrentContext) hRC = qwglGetCurrentContext(); + if (qwglGetCurrentDC) hDC = qwglGetCurrentDC(); @@ -1313,66 +1354,6 @@ void IN_StartupMouse (void) } -/* -=========== -IN_Init -=========== -*/ -void IN_Init (void) -{ - // joystick variables - Cvar_RegisterVariable (&in_joystick); - Cvar_RegisterVariable (&joy_name); - Cvar_RegisterVariable (&joy_advanced); - Cvar_RegisterVariable (&joy_advaxisx); - Cvar_RegisterVariable (&joy_advaxisy); - Cvar_RegisterVariable (&joy_advaxisz); - Cvar_RegisterVariable (&joy_advaxisr); - Cvar_RegisterVariable (&joy_advaxisu); - Cvar_RegisterVariable (&joy_advaxisv); - Cvar_RegisterVariable (&joy_forwardthreshold); - Cvar_RegisterVariable (&joy_sidethreshold); - Cvar_RegisterVariable (&joy_pitchthreshold); - Cvar_RegisterVariable (&joy_yawthreshold); - Cvar_RegisterVariable (&joy_forwardsensitivity); - Cvar_RegisterVariable (&joy_sidesensitivity); - Cvar_RegisterVariable (&joy_pitchsensitivity); - Cvar_RegisterVariable (&joy_yawsensitivity); - Cvar_RegisterVariable (&joy_wwhack1); - Cvar_RegisterVariable (&joy_wwhack2); - - Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f); - - uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" ); - - IN_StartupMouse (); - IN_StartupJoystick (); -} - -/* -=========== -IN_Shutdown -=========== -*/ -void IN_Shutdown (void) -{ - IN_DeactivateMouse (); - IN_ShowMouse (); - - if (g_pMouse) - { - IDirectInputDevice_Release(g_pMouse); - g_pMouse = NULL; - } - - if (g_pdi) - { - IDirectInput_Release(g_pdi); - g_pdi = NULL; - } -} - - /* =========== IN_MouseEvent @@ -1529,8 +1510,6 @@ void IN_Move (usercmd_t *cmd) IN_MouseMove (cmd); IN_JoyMove (cmd); } - - cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value); } -- 2.39.2