From 2a10cbe9394e5ead9b8307591917d139774ceb43 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 16 Aug 2011 11:39:27 +0000 Subject: [PATCH] implemented CSQC_InputEvent type 2 and type 3 mouse move events added cl_csqc_generatemousemoveevents cvar to allow this to be disabled based on gamemode (currently disabled in GAME_STEELSTORM due to csqc bugs) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11277 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 26 ++++++++++++++++++++++++++ clvm_cmds.c | 8 ++++---- cmd.c | 43 +++++++++++++++++++++++++------------------ csprogs.c | 12 ++++++++---- keys.c | 6 +++--- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/cl_input.c b/cl_input.c index 8fe0d4cb..d449bdf6 100644 --- a/cl_input.c +++ b/cl_input.c @@ -457,6 +457,8 @@ cvar_t cl_netimmediatebuttons = {CVAR_SAVE, "cl_netimmediatebuttons", "1", "send cvar_t cl_nodelta = {0, "cl_nodelta", "0", "disables delta compression of non-player entities in QW network protocol"}; +cvar_t cl_csqc_generatemousemoveevents = {0, "cl_csqc_generatemousemoveevents", "1", "enables calls to CSQC_InputEvent with type 2, for compliance with EXT_CSQC spec"}; + extern cvar_t v_flipped; /* @@ -516,6 +518,7 @@ CL_Input Send the intended movement message to the server ================ */ +extern qboolean CL_VM_InputEvent (int eventtype, int x, int y); void CL_Input (void) { float mx, my; @@ -562,6 +565,27 @@ void CL_Input (void) // allow mice or other external controllers to add to the move IN_Move (); + // send mouse move to csqc + if (cl.csqc_loaded && cl_csqc_generatemousemoveevents.integer) + { + if (cl.csqc_wantsmousemove) + { + // event type 3 is a DP_CSQC thing + static int oldwindowmouse[2]; + if (oldwindowmouse[0] != in_windowmouse_x || oldwindowmouse[1] != in_windowmouse_y) + { + CL_VM_InputEvent(3, in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height); + oldwindowmouse[0] = in_windowmouse_x; + oldwindowmouse[1] = in_windowmouse_y; + } + } + else + { + if (in_mouse_x || in_mouse_y) + CL_VM_InputEvent(2, in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height); + } + } + // apply m_accelerate if it is on if(m_accelerate.value > 1) { @@ -2234,5 +2258,7 @@ void CL_InitInput (void) Cvar_RegisterVariable(&cl_netimmediatebuttons); Cvar_RegisterVariable(&cl_nodelta); + + Cvar_RegisterVariable(&cl_csqc_generatemousemoveevents); } diff --git a/clvm_cmds.c b/clvm_cmds.c index 0b61025e..9856f21c 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -1318,7 +1318,7 @@ static void VM_CL_setpause(void) cl.csqc_paused = false; } -//#343 void(float usecursor) setcursormode (EXT_CSQC) +//#343 void(float usecursor) setcursormode (DP_CSQC) static void VM_CL_setcursormode (void) { VM_SAFEPARMCOUNT(1, VM_CL_setcursormode); @@ -1326,7 +1326,7 @@ static void VM_CL_setcursormode (void) cl_ignoremousemoves = 2; } -//#344 vector() getmousepos (EXT_CSQC) +//#344 vector() getmousepos (DP_CSQC) static void VM_CL_getmousepos(void) { VM_SAFEPARMCOUNT(0,VM_CL_getmousepos); @@ -4409,8 +4409,8 @@ VM_print, // #339 void(string s, ...) print (EXT_CSQC, DP_SV_PRINT) VM_keynumtostring, // #340 string(float keynum) keynumtostring (EXT_CSQC) VM_stringtokeynum, // #341 float(string keyname) stringtokeynum (EXT_CSQC) VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC) -VM_CL_setcursormode, // #343 void(float usecursor) setcursormode (EXT_CSQC) -VM_CL_getmousepos, // #344 vector() getmousepos (EXT_CSQC) +VM_CL_setcursormode, // #343 void(float usecursor) setcursormode (DP_CSQC) +VM_CL_getmousepos, // #344 vector() getmousepos (DP_CSQC) VM_CL_getinputstate, // #345 float(float framenum) getinputstate (EXT_CSQC) VM_CL_setsensitivityscale, // #346 void(float sens) setsensitivityscale (EXT_CSQC) VM_CL_runplayerphysics, // #347 void() runstandardplayerphysics (EXT_CSQC) diff --git a/cmd.c b/cmd.c index bbaca649..e894a8c2 100644 --- a/cmd.c +++ b/cmd.c @@ -453,6 +453,7 @@ void Cmd_StuffCmds_f (void) static void Cmd_Exec(const char *filename) { char *f; + qboolean isdefaultcfg = strlen(filename) >= 11 && !strcmp(filename + strlen(filename) - 11, "default.cfg"); if (!strcmp(filename, "config.cfg")) { @@ -472,7 +473,7 @@ static void Cmd_Exec(const char *filename) // if executing default.cfg for the first time, lock the cvar defaults // it may seem backwards to insert this text BEFORE the default.cfg // but Cbuf_InsertText inserts before, so this actually ends up after it. - if (strlen(filename) >= 11 && !strcmp(filename + strlen(filename) - 11, "default.cfg")) + if (isdefaultcfg) Cbuf_InsertText("\ncvar_lockdefaults\n"); // insert newline after the text to make sure the last line is terminated (some text editors omit the trailing newline) @@ -481,23 +482,29 @@ static void Cmd_Exec(const char *filename) Cbuf_InsertText (f); Mem_Free(f); - // special defaults for specific games go here, these execute before default.cfg - // Nehahra pushable crates malfunction in some levels if this is on - // Nehahra NPC AI is confused by blowupfallenzombies - if (gamemode == GAME_NEHAHRA) - Cbuf_InsertText("\nsv_gameplayfix_upwardvelocityclearsongroundflag 0\nsv_gameplayfix_blowupfallenzombies 0\n\n"); - // hipnotic mission pack has issues in their 'friendly monster' ai, which seem to attempt to attack themselves for some reason when findradius() returns non-solid entities. - // hipnotic mission pack has issues with bobbing water entities 'jittering' between different heights on alternate frames at the default 0.0138889 ticrate, 0.02 avoids this issue - // hipnotic mission pack has issues in their proximity mine sticking code, which causes them to bounce off. - if (gamemode == GAME_HIPNOTIC) - Cbuf_InsertText("\nsv_gameplayfix_blowupfallenzombies 0\nsys_ticrate 0.02\nsv_gameplayfix_slidemoveprojectiles 0\n\n"); - // rogue mission pack has a guardian boss that does not wake up if findradius returns one of the entities around its spawn area - if (gamemode == GAME_ROGUE) - Cbuf_InsertText("\nsv_gameplayfix_findradiusdistancetobox 0\n\n"); - if (gamemode == GAME_NEXUIZ) - Cbuf_InsertText("\nsv_gameplayfix_q2airaccelerate 1\nsv_gameplayfix_stepmultipletimes 1\n\n"); - if (gamemode == GAME_TENEBRAE) - Cbuf_InsertText("\nr_shadow_gloss 2\nr_shadow_bumpscale_basetexture 4\n\n"); + if (isdefaultcfg) + { + // special defaults for specific games go here, these execute before default.cfg + // Nehahra pushable crates malfunction in some levels if this is on + // Nehahra NPC AI is confused by blowupfallenzombies + if (gamemode == GAME_NEHAHRA) + Cbuf_InsertText("\nsv_gameplayfix_upwardvelocityclearsongroundflag 0\nsv_gameplayfix_blowupfallenzombies 0\n\n"); + // hipnotic mission pack has issues in their 'friendly monster' ai, which seem to attempt to attack themselves for some reason when findradius() returns non-solid entities. + // hipnotic mission pack has issues with bobbing water entities 'jittering' between different heights on alternate frames at the default 0.0138889 ticrate, 0.02 avoids this issue + // hipnotic mission pack has issues in their proximity mine sticking code, which causes them to bounce off. + if (gamemode == GAME_HIPNOTIC) + Cbuf_InsertText("\nsv_gameplayfix_blowupfallenzombies 0\nsys_ticrate 0.02\nsv_gameplayfix_slidemoveprojectiles 0\n\n"); + // rogue mission pack has a guardian boss that does not wake up if findradius returns one of the entities around its spawn area + if (gamemode == GAME_ROGUE) + Cbuf_InsertText("\nsv_gameplayfix_findradiusdistancetobox 0\n\n"); + if (gamemode == GAME_NEXUIZ) + Cbuf_InsertText("\nsv_gameplayfix_q2airaccelerate 1\nsv_gameplayfix_stepmultipletimes 1\n\n"); + if (gamemode == GAME_TENEBRAE) + Cbuf_InsertText("\nr_shadow_gloss 2\nr_shadow_bumpscale_basetexture 4\n\n"); + // Steel Storm: Burning Retribution csqc misinterprets CSQC_InputEvent if type is a value other than 0 or 1 + if (gamemode == GAME_STEELSTORM) + Cbuf_InsertText("\ncl_csqc_generatemousemoveevents 0\n\n"); + } } /* diff --git a/csprogs.c b/csprogs.c index 55bf6bf1..8ebaa7f2 100644 --- a/csprogs.c +++ b/csprogs.c @@ -427,7 +427,11 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum) return true; } -qboolean CL_VM_InputEvent (qboolean down, int key, int ascii) +// 0 = keydown, key, character (EXT_CSQC) +// 1 = keyup, key, character (EXT_CSQC) +// 2 = mousemove relative, x, y (EXT_CSQC) +// 3 = mousemove absolute, x, y (DP_CSQC) +qboolean CL_VM_InputEvent (int eventtype, int x, int y) { qboolean r; @@ -441,9 +445,9 @@ qboolean CL_VM_InputEvent (qboolean down, int key, int ascii) { PRVM_clientglobalfloat(time) = cl.time; PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity]; - PRVM_G_FLOAT(OFS_PARM0) = !down; // 0 is down, 1 is up - PRVM_G_FLOAT(OFS_PARM1) = key; - PRVM_G_FLOAT(OFS_PARM2) = ascii; + PRVM_G_FLOAT(OFS_PARM0) = eventtype; + PRVM_G_FLOAT(OFS_PARM1) = x; // key or x + PRVM_G_FLOAT(OFS_PARM2) = y; // ascii or y PRVM_ExecuteProgram(PRVM_clientfunction(CSQC_InputEvent), "QC function CSQC_InputEvent is missing"); r = CSQC_RETURNVAL != 0; } diff --git a/keys.c b/keys.c index 817ce92d..aa84c237 100644 --- a/keys.c +++ b/keys.c @@ -1686,7 +1686,7 @@ void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bi } } -qboolean CL_VM_InputEvent (qboolean down, int key, int ascii); +extern qboolean CL_VM_InputEvent (int eventtype, int x, int y); /* =================== @@ -1852,7 +1852,7 @@ Key_Event (int key, int ascii, qboolean down) case key_game: // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:) - q = CL_VM_InputEvent(down, key, ascii); + q = CL_VM_InputEvent(down ? 0 : 1, key, ascii); if (!q && down) MR_ToggleMenu(1); break; @@ -1936,7 +1936,7 @@ Key_Event (int key, int ascii, qboolean down) MR_KeyEvent (key, ascii, down); break; case key_game: - q = CL_VM_InputEvent(down, key, ascii); + q = CL_VM_InputEvent(down ? 0 : 1, key, ascii); // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc if (!q && bind) { -- 2.39.2