From facaed0509e7b7c30d6ec3f9d3438ee21f77c6e8 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 8 May 2008 09:10:10 +0000 Subject: [PATCH] implemented support for turning off mousegrab in csqc (feature existed but was buggy in Windows build and not implemented in others) cleaned up menu mousegrab handling, among other mousegrab state issues git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8285 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 24 ++++++++++++------------ cl_screen.c | 18 +++++++++++++++--- host.c | 2 -- input.h | 1 + prvm_cmds.c | 8 ++++---- todo | 11 +++++++++-- vid_agl.c | 21 ++++++++++----------- vid_glx.c | 31 +++++++++---------------------- vid_sdl.c | 5 +++++ vid_shared.c | 3 ++- vid_wgl.c | 29 +++++++++-------------------- 11 files changed, 76 insertions(+), 77 deletions(-) diff --git a/cl_input.c b/cl_input.c index f5506ca0..be24b9a1 100644 --- a/cl_input.c +++ b/cl_input.c @@ -550,20 +550,9 @@ void CL_Input (void) cl.cmd.upmove *= cl_movespeedkey.value; } - in_mouse_x = 0; - in_mouse_y = 0; - // allow mice or other external controllers to add to the move IN_Move (); - // ignore a mouse move if mouse was activated/deactivated this frame - if (cl_ignoremousemoves) - { - cl_ignoremousemoves--; - in_mouse_x = 0; - in_mouse_y = 0; - } - // apply m_filter if it is on mx = in_mouse_x; my = in_mouse_y; @@ -575,8 +564,16 @@ void CL_Input (void) old_mouse_x = mx; old_mouse_y = my; + // ignore a mouse move if mouse was activated/deactivated this frame + if (cl_ignoremousemoves) + { + cl_ignoremousemoves--; + in_mouse_x = old_mouse_x = 0; + in_mouse_y = old_mouse_y = 0; + } + // if not in menu, apply mouse move to viewangles/movement - if (!cl.csqc_wantsmousemove && in_client_mouse) + if (!key_consoleactive && key_dest == key_game && !cl.csqc_wantsmousemove) { float modulatedsensitivity = sensitivity.value * cl.sensitivityscale; if (cl_prydoncursor.integer) @@ -624,6 +621,9 @@ void CL_Input (void) // clamp after the move to prevent rendering with bad angles CL_AdjustAngles (); + + in_mouse_x = 0; + in_mouse_y = 0; } #include "cl_collision.h" diff --git a/cl_screen.c b/cl_screen.c index a46093d2..b2d2ecc3 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -2112,12 +2112,11 @@ void CL_UpdateScreen(void) { double rendertime1; float conwidth, conheight; + qboolean grabmouse; if (!scr_initialized || !con_initialized) return; // not initialized yet - VID_GrabMouse((vid.fullscreen || (vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))) && vid_activewindow && !cl.csqc_wantsmousemove); - if(gamemode == GAME_NEXUIZ) { // play a bit with the palette (experimental) @@ -2273,7 +2272,20 @@ void CL_UpdateScreen(void) else cl_updatescreen_quality = 1; - VID_GrabMouse((vid.fullscreen || (vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))) && vid_activewindow && !cl.csqc_wantsmousemove); + if (key_consoleactive) + grabmouse = false; + else if (key_dest == key_menu_grabbed) + grabmouse = true; + else if (key_dest == key_menu) + grabmouse = in_client_mouse; + else if (key_dest == key_game) + grabmouse = (vid.fullscreen || vid_mouse.integer) && !cls.demoplayback && !cl.csqc_wantsmousemove; + else + grabmouse = false; + if (!vid_activewindow) + grabmouse = false; + + VID_GrabMouse(grabmouse); VID_Finish(); } diff --git a/host.c b/host.c index 0bafb91a..38571e69 100644 --- a/host.c +++ b/host.c @@ -869,8 +869,6 @@ void Host_Main(void) if (host_speeds.integer) time1 = Sys_DoubleTime(); - //ui_update(); - CL_Video_Frame(); CL_Gecko_Frame(); diff --git a/input.h b/input.h index d2e3c086..3f98f68d 100644 --- a/input.h +++ b/input.h @@ -26,6 +26,7 @@ extern cvar_t in_pitch_min; extern cvar_t in_pitch_max; extern qboolean in_client_mouse; +extern float in_windowmouse_x, in_windowmouse_y; extern float in_mouse_x, in_mouse_y; //enum input_dest_e {input_game,input_message,input_menu} input_dest; diff --git a/prvm_cmds.c b/prvm_cmds.c index 367fe96b..bdaf712b 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2307,12 +2307,12 @@ vector getmousepos() */ void VM_getmousepos(void) { - VM_SAFEPARMCOUNT(0,VM_getmousepos); - PRVM_G_VECTOR(OFS_RETURN)[0] = in_mouse_x * vid_conwidth.integer / vid.width; - PRVM_G_VECTOR(OFS_RETURN)[1] = in_mouse_y * vid_conheight.integer / vid.height; - PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + if (cl.csqc_wantsmousemove) + VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0); + else + VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0); } /* diff --git a/todo b/todo index 60b61ae5..81616126 100644 --- a/todo +++ b/todo @@ -1,10 +1,10 @@ - todo: difficulty ratings are: 0 = trivial, 1 = easy, 2 = easy-moderate, 3 = moderate, 4 = moderate-hard, 5 = hard, 6 = hard++, 7 = nightmare, d = done, -d = done but have not notified the people who asked for it, f = failed, -f = failed but have not notified the people who asked for it -0 bug csqc client: darkplaces lacks prediction support -0 bug csqc: there is no WriteFloat, making ReadFloat useless (Urre) +0 bug darkplaces client csqc: darkplaces's standard prediction builtin is empty 0 bug darkplaces client csqc: engine prediction function is not implemented - could just return the engine's current cl.movement_origin (Spike) 0 bug darkplaces client csqc: entities not being drawn with VF_PERSPECTIVE 0? (daemon) 0 bug darkplaces client csqc: input queue functions needed for csqc prediction aren't implemented (Spike) 0 bug darkplaces client csqc: precaches on client don't work, have to precache on server - what's going wrong here? (daemon, Urre) +0 bug darkplaces client csqc: there is no WriteFloat, making ReadFloat useless (Urre) 0 bug darkplaces client qw: add .mvd demo support 0 bug darkplaces client qw: add .qwd demo support 0 bug darkplaces client qw: add spectator cvar (Plague Monkey Rat) @@ -18,9 +18,13 @@ 0 bug darkplaces client win64: crash in R_DrawRTLight due to stack overflow, change the pointer arrays to indexes into r_refdef.scene.entities, or increase projects to build with 4MB stack instead of 2MB - also clean up these warnings: http://dp.deathmask.net/log/dp_x64_buildlog_r8078.txt (Willis) 0 bug darkplaces client: can't move mouse around in nexuiz menu if vid_mouse is 0 0 bug darkplaces client: if you press 1 during the demo loop when quake starts, escape doesn't do anything until you hit some other key (daemon) +0 bug darkplaces effects: add a cvar to disable colored dlights (leileilol) +0 bug darkplaces effects: dlights don't look anything like quake ones, bring back lightmap dlights as a cvar - with both classic and old dp falloff modes (leileilol) +0 bug darkplaces effects: quake mode blood trails don't have the appropriate slight gravity - there may be other effects missing this also (leileilol) 0 bug darkplaces loader: crash when a mdl model has more replacement skins than the model contains (Lardarse) 0 bug darkplaces loader: make rtlight entity loader support q3map/q3map2 lights properly, they use a spawnflag for LINEAR mode, by default they use 1/(x*x) falloff (Carni, motorsep) 0 bug darkplaces loader: mcbsp hull selection is ignoring the custom hulls supported by mcbsp (div0) +0 bug darkplaces loader: png loading crashes if the image is transparent (Urre) 0 bug darkplaces loader: q1bsp loader computes wrong submodel size for submodels with no surfaces, such as a func_wall comprised entirely of SKIP or CAULK brushes (neg|ke) 0 bug darkplaces memory: memstats doesn't account for memory used by VBO/EBO buffers in models 0 bug darkplaces menu: load/save game menus show files that are not in the highest priority gamedir, such as id1 saves showing up when playing dpmod (Dooomer, WodahsEht) @@ -135,6 +139,7 @@ 0 feature darkplaces prvm: if developer is >= 100, list unfreed strzone strings when level ends (div0) 0 feature darkplaces prvm: modify PRVM_ExecuteProgram to be able to call builtins directly, and add prog->argc = before every PRVM_ExecuteProgram call (div0) 0 feature darkplaces qc: add FTE_STRINGS extension, and specifically support -1 for strncmp/strncasecmp to compare whole string (div0) +0 feature darkplaces qc: add support for ZQ_QC_TOKENIZE so that csqc can use tokenize too (KrimZon) 0 feature darkplaces quakec: DP_QC_STRFTIME extension providing strftime function to find out what the current time is with a format string (FrikaC) 0 feature darkplaces quakec: add a DP_QC_STRCATREPEAT extension providing string(float atimes, string a[, float btimes, string b, [float ctimes, string c, [float dtimes, string d]]]) strcatrepeat = #???; which repeats the given strings a given number of times and concatenates them together (like many strcat calls), can be given 2, 4, 6, or 8 parameters, stores it into a temp buffer, and returns the temp buffer (FA-Zalon) 0 feature darkplaces quakec: add crossproduct builtin, as DP_QC_CROSSPRODUCT, and suggest that this is a viable alternative to vectorvectors when you have two vectors already @@ -150,6 +155,7 @@ 0 feature darkplaces renderer: add r_shadow_light_polygonoffset and polygonfactor cvars for lighting polygons (Diablo-D3) 0 feature darkplaces renderer: add r_showsurfaces cvar which adds an extra texture layer of additive flat color, based on the surface number, similar to r_drawflat in software quake (div0) 0 feature darkplaces renderer: add rtlight "avelocity" parameter to make lights that spin, useful with cubemaps (romi) +0 feature darkplaces renderer: document dp_water, dp_reflect, dp_refract .shader commands, add extension indicating this feature and document it in dpextensions.qc (leileilol) 0 feature darkplaces renderer: gl_picmip -1 and -2 settings based on twilight code (Harout Darmanchyan) 0 feature darkplaces renderer: make showfps display GL renderer string and CPU - figure out how to detect this from the OS 0 feature darkplaces renderer: save r_shadow_glsl* cvars (and possibly a few others) to config because they are useful user settings (SavageX) @@ -175,6 +181,7 @@ 0 feature darkplaces server: make noclip/fly cheats use MOVETYPE_CHEATNOCLIP/MOVETYPE_CHEATFLY which would have the nicer movement interface (Spikester) 0 feature darkplaces server: when "exec config.cfg" is encountered, add on an automatic "exec server.cfg" if running a dedicated server (mortenoesterlundjoer) 0 feature darkplaces sound: Lordhavoc needs to talk to fuh about snd_macos.c (fuh) +0 feature darkplaces sound: add extension info for mod music playback (leileilol) 0 feature darkplaces sound: the new sound engine should have a cvar for random variations of pitch on sounds like in doom (RenegadeC) 0 feature darkplaces website: add download link for deluxemaps_id1.pk3 0 feature darkplaces website: add q1source.zip to downloads page and suggest that mingw/Dev-C++ users may need the dx headers from it (cpuforbrain) diff --git a/vid_agl.c b/vid_agl.c index 67173880..df4f817f 100644 --- a/vid_agl.c +++ b/vid_agl.c @@ -61,7 +61,6 @@ static qboolean multithreadedgl; static qboolean mouse_avail = true; static qboolean vid_usingmouse = false; static qboolean vid_usingnoaccel = false; -static float mouse_x, mouse_y; static qboolean vid_isfullscreen = false; static qboolean vid_usingvsync = false; @@ -159,7 +158,6 @@ void VID_GrabMouse(qboolean grab) } } - mouse_x = mouse_y = 0; vid_usingmouse = true; vid_usingnoaccel = !!apple_mouse_noaccel.integer; } @@ -965,11 +963,19 @@ void Sys_SendKeyEvents(void) case kEventMouseDragged: { HIPoint deltaPos; + HIPoint windowPos; GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos); + GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(windowPos), NULL, &windowPos); - mouse_x += deltaPos.x; - mouse_y += deltaPos.y; + if (vid_usingmouse) + { + in_mouse_x += deltaPos.x; + in_mouse_y += deltaPos.y; + } + + in_windowmouse_x = windowPos.x; + in_windowmouse_y = windowPos.y; break; } @@ -1102,11 +1108,4 @@ void Sys_SendKeyEvents(void) void IN_Move (void) { - if (mouse_avail) - { - in_mouse_x = mouse_x; - in_mouse_y = mouse_y; - } - mouse_x = 0; - mouse_y = 0; } diff --git a/vid_glx.c b/vid_glx.c index 3969fe16..47f7360b 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -94,8 +94,6 @@ static qboolean vid_usevsync = false; static qboolean vid_x11_hardwaregammasupported = false; static qboolean vid_x11_dgasupported = false; static int vid_x11_gammarampsize = 0; -static float mouse_x, mouse_y; -static int p_mouse_x, p_mouse_y; #if !defined(__APPLE__) && !defined(SUNOS) cvar_t vid_dgamouse = {CVAR_SAVE, "vid_dgamouse", "1", "make use of DGA mouse input"}; @@ -286,7 +284,6 @@ void VID_GrabMouse(qboolean grab) if (vid_grabkeyboard.integer || vid_isfullscreen) XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); - mouse_x = mouse_y = 0; cl_ignoremousemoves = 2; vid_usingmouse = true; #if !defined(__APPLE__) && !defined(SUNOS) @@ -373,26 +370,23 @@ static void HandleEvents(void) #if !defined(__APPLE__) && !defined(SUNOS) if (vid_dgamouse.integer == 1 && vid_x11_dgasupported) { - mouse_x += event.xmotion.x_root; - mouse_y += event.xmotion.y_root; + in_mouse_x += event.xmotion.x_root; + in_mouse_y += event.xmotion.y_root; } else #endif { - if (!event.xmotion.send_event) { - mouse_x += event.xmotion.x - p_mouse_x; - mouse_y += event.xmotion.y - p_mouse_y; + in_mouse_x += event.xmotion.x - in_windowmouse_x; + in_mouse_y += event.xmotion.y - in_windowmouse_y; if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4) dowarp = true; } - p_mouse_x = event.xmotion.x; - p_mouse_y = event.xmotion.y; } } - //else - // ui_mouseupdate(event.xmotion.x, event.xmotion.y); + in_windowmouse_x = event.xmotion.x; + in_windowmouse_y = event.xmotion.y; break; case ButtonPress: @@ -467,9 +461,9 @@ static void HandleEvents(void) if (dowarp) { /* move the mouse to the window center again */ - p_mouse_x = vid.width / 2; - p_mouse_y = vid.height / 2; - XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, p_mouse_x, p_mouse_y); + in_windowmouse_x = (int)(vid.width / 2); + in_windowmouse_y = (int)(vid.height / 2); + XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, (int)in_windowmouse_x, (int)in_windowmouse_y); } } @@ -899,11 +893,4 @@ void Sys_SendKeyEvents(void) void IN_Move (void) { - if (mouse_avail) - { - in_mouse_x = mouse_x; - in_mouse_y = mouse_y; - } - mouse_x = 0; - mouse_y = 0; } diff --git a/vid_sdl.c b/vid_sdl.c index 3a636cc1..b38a22a3 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -305,6 +305,11 @@ void IN_Move( void ) in_mouse_y = y; } } + + SDL_GetMouseState(&x, &y); + in_windowmouse_x = x; + in_windowmouse_y = y; + if (vid_numjoysticks && joy_enable.integer && joy_index.integer >= 0 && joy_index.integer < vid_numjoysticks) { SDL_Joystick *joy = vid_joysticks[joy_index.integer]; diff --git a/vid_shared.c b/vid_shared.c index 0e907dd7..cf694995 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -10,10 +10,11 @@ qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, qboolean isRagePro = false; // LordHavoc: the ATI Rage Pro has limitations with per pixel alpha (the color scaler does not apply to per pixel alpha images...), although not as bad as a G200. // AK FIXME -> input_dest -qboolean in_client_mouse = true; +qboolean in_client_mouse = false; // AK where should it be placed ? float in_mouse_x, in_mouse_y; +float in_windowmouse_x, in_windowmouse_y; // value of GL_MAX_TEXTURE__SIZE int gl_max_texture_size = 0; diff --git a/vid_wgl.c b/vid_wgl.c index e664cf05..0c551102 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -1471,15 +1471,14 @@ IN_MouseMove */ static void IN_MouseMove (void) { - int mx, my; POINT current_pos; + GetCursorPos (¤t_pos); + in_windowmouse_x = current_pos.x - window_x; + in_windowmouse_y = current_pos.y - window_y; + if (!vid_usingmouse) - { - //GetCursorPos (¤t_pos); - //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y); return; - } #ifdef SUPPORTDIRECTX if (dinput_acquired) @@ -1488,8 +1487,6 @@ static void IN_MouseMove (void) DIDEVICEOBJECTDATA od; DWORD dwElements; HRESULT hr; - mx = 0; - my = 0; for (;;) { @@ -1513,11 +1510,11 @@ static void IN_MouseMove (void) switch (od.dwOfs) { case DIMOFS_X: - mx += (LONG) od.dwData; + in_mouse_x += (LONG) od.dwData; break; case DIMOFS_Y: - my += (LONG) od.dwData; + in_mouse_y += (LONG) od.dwData; break; case DIMOFS_Z: @@ -1568,23 +1565,15 @@ static void IN_MouseMove (void) if ((mstate_di ^ mouse_oldbuttonstate) & (1<