]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Add full support for csqc's sensitivityscale (no clamping yet, so you can actually...
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Dec 2007 21:50:03 +0000 (21:50 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Dec 2007 21:50:03 +0000 (21:50 +0000)
Minor cleanups in the csqc (very very minor).
Change Key_Event a bit (and probably break it again :()

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7816 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
cl_main.c
clvm_cmds.c
csprogs.c
keys.c
protocol.c

index 5ee230c616bc323f9897c43f663536729fd663e0..f6e6165a8d2e7d8bb54e78c926c92840a32f185b 100644 (file)
@@ -583,38 +583,39 @@ void CL_Input (void)
        // if not in menu, apply mouse move to viewangles/movement
        if (!cl.csqc_wantsmousemove && in_client_mouse)
        {
+               float modulatedsensitivity = sensitivity.value * cl.sensitivityscale;
                if (cl_prydoncursor.integer)
                {
                        // mouse interacting with the scene, mostly stationary view
                        V_StopPitchDrift();
-                       cl.cmd.cursor_screen[0] += in_mouse_x * sensitivity.value / vid.width;
-                       cl.cmd.cursor_screen[1] += in_mouse_y * sensitivity.value / vid.height;
+                       cl.cmd.cursor_screen[0] += in_mouse_x * modulatedsensitivity / vid.width;
+                       cl.cmd.cursor_screen[1] += in_mouse_y * modulatedsensitivity / vid.height;
                }
                else if (in_strafe.state & 1)
                {
                        // strafing mode, all looking is movement
                        V_StopPitchDrift();
-                       cl.cmd.sidemove += m_side.value * in_mouse_x * sensitivity.value;
+                       cl.cmd.sidemove += m_side.value * in_mouse_x * modulatedsensitivity;
                        if (noclip_anglehack)
-                               cl.cmd.upmove -= m_forward.value * in_mouse_y * sensitivity.value;
+                               cl.cmd.upmove -= m_forward.value * in_mouse_y * modulatedsensitivity;
                        else
-                               cl.cmd.forwardmove -= m_forward.value * in_mouse_y * sensitivity.value;
+                               cl.cmd.forwardmove -= m_forward.value * in_mouse_y * modulatedsensitivity;
                }
                else if ((in_mlook.state & 1) || freelook.integer)
                {
                        // mouselook, lookstrafe causes turning to become strafing
                        V_StopPitchDrift();
                        if (lookstrafe.integer)
-                               cl.cmd.sidemove += m_side.value * in_mouse_x * sensitivity.value;
+                               cl.cmd.sidemove += m_side.value * in_mouse_x * modulatedsensitivity;
                        else
-                               cl.viewangles[YAW] -= m_yaw.value * in_mouse_x * sensitivity.value * cl.viewzoom;
-                       cl.viewangles[PITCH] += m_pitch.value * in_mouse_y * sensitivity.value * cl.viewzoom;
+                               cl.viewangles[YAW] -= m_yaw.value * in_mouse_x * modulatedsensitivity * cl.viewzoom;
+                       cl.viewangles[PITCH] += m_pitch.value * in_mouse_y * modulatedsensitivity * cl.viewzoom;
                }
                else
                {
                        // non-mouselook, yaw turning and forward/back movement
-                       cl.viewangles[YAW] -= m_yaw.value * in_mouse_x * sensitivity.value * cl.viewzoom;
-                       cl.cmd.forwardmove -= m_forward.value * in_mouse_y * sensitivity.value;
+                       cl.viewangles[YAW] -= m_yaw.value * in_mouse_x * modulatedsensitivity * cl.viewzoom;
+                       cl.cmd.forwardmove -= m_forward.value * in_mouse_y * modulatedsensitivity;
                }
        }
 
index e44fdf1d0cb0d5a5030839fc0ac4226d6c00f4ae..66d68acf4a7d595dc418f0b0298097c1195122f6 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -112,6 +112,7 @@ void CL_ClearState(void)
 
        // reset the view zoom interpolation
        cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
+       cl.sensitivityscale = 1.0f;
 
        // enable rendering of the world and such
        cl.csqc_vidvars.drawworld = true;
index 804db8a79017e7622bb16f8a285493d4f9f05582..f19b66db13b1004b8971e88d311ce7a4c75ac94e 100644 (file)
@@ -200,6 +200,7 @@ static void VM_CL_spawn (void)
 {
        prvm_edict_t *ed;
        ed = PRVM_ED_Alloc();
+       // FIXME: WTF.. this should be removed imo.. entnum points to the server.. [12/17/2007 Black]
        ed->fields.client->entnum = PRVM_NUM_FOR_EDICT(ed);     //[515]: not needed any more ?
        VM_RETURN_EDICT(ed);
 }
@@ -212,7 +213,7 @@ static void VM_CL_traceline (void)
        int             move;
        prvm_edict_t    *ent;
 
-       VM_SAFEPARMCOUNTRANGE(4, 8, VM_CL_traceline); // allow more parameters for future expansion
+       VM_SAFEPARMCOUNTRANGE(4, 4, VM_CL_traceline);
 
        prog->xfunction->builtinsprofile += 30;
 
@@ -726,79 +727,103 @@ static void VM_CL_R_SetView (void)
 
        switch(c)
        {
-       case VF_MIN:                    r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_MIN_X:                  r_view.x = (int)(k * vid.width / vid_conwidth.value);
-                                                       break;
-       case VF_MIN_Y:                  r_view.y = (int)(k * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_SIZE:                   r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_SIZE_Y:                 r_view.width = (int)(k * vid.width / vid_conwidth.value);
-                                                       break;
-       case VF_SIZE_X:                 r_view.height = (int)(k * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_VIEWPORT:               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       f = PRVM_G_VECTOR(OFS_PARM2);
-                                                       r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
-                                                       r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
-                                                       break;
-       case VF_FOV:                    r_view.frustum_x = tan(f[0] * M_PI / 360.0);r_view.ortho_x = f[0];
-                                                       r_view.frustum_y = tan(f[1] * M_PI / 360.0);r_view.ortho_y = f[1];
-                                                       break;
-       case VF_FOVX:                   r_view.frustum_x = tan(k * M_PI / 360.0);r_view.ortho_x = k;
-                                                       break;
-       case VF_FOVY:                   r_view.frustum_y = tan(k * M_PI / 360.0);r_view.ortho_y = k;
-                                                       break;
-       case VF_ORIGIN:                 VectorCopy(f, cl.csqc_origin);
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_X:               cl.csqc_origin[0] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_Y:               cl.csqc_origin[1] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ORIGIN_Z:               cl.csqc_origin[2] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES:                 VectorCopy(f, cl.csqc_angles);
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_X:               cl.csqc_angles[0] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_Y:               cl.csqc_angles[1] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_ANGLES_Z:               cl.csqc_angles[2] = k;
-                                                       CSQC_R_RecalcView();
-                                                       break;
-       case VF_DRAWWORLD:              cl.csqc_vidvars.drawworld = k;
-                                                       break;
-       case VF_DRAWENGINESBAR: cl.csqc_vidvars.drawenginesbar = k;
-                                                       break;
-       case VF_DRAWCROSSHAIR:  cl.csqc_vidvars.drawcrosshair = k;
-                                                       break;
-
-       case VF_CL_VIEWANGLES:  VectorCopy(f, cl.viewangles);
-                                                       break;
-       case VF_CL_VIEWANGLES_X:cl.viewangles[0] = k;
-                                                       break;
-       case VF_CL_VIEWANGLES_Y:cl.viewangles[1] = k;
-                                                       break;
-       case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
-                                                       break;
-
-       case VF_PERSPECTIVE:    r_view.useperspective = k != 0;
-                                                       break;
-
-       default:                                PRVM_G_FLOAT(OFS_RETURN) = 0;
-                                                       VM_Warning("VM_CL_R_SetView : unknown parm %i\n", c);
-                                                       return;
+       case VF_MIN:
+               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_MIN_X:
+               r_view.x = (int)(k * vid.width / vid_conwidth.value);
+               break;
+       case VF_MIN_Y:
+               r_view.y = (int)(k * vid.height / vid_conheight.value);
+               break;
+       case VF_SIZE:
+               r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_SIZE_Y:
+               r_view.width = (int)(k * vid.width / vid_conwidth.value);
+               break;
+       case VF_SIZE_X:
+               r_view.height = (int)(k * vid.height / vid_conheight.value);
+               break;
+       case VF_VIEWPORT:
+               r_view.x = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.y = (int)(f[1] * vid.height / vid_conheight.value);
+               f = PRVM_G_VECTOR(OFS_PARM2);
+               r_view.width = (int)(f[0] * vid.width / vid_conwidth.value);
+               r_view.height = (int)(f[1] * vid.height / vid_conheight.value);
+               break;
+       case VF_FOV:
+               r_view.frustum_x = tan(f[0] * M_PI / 360.0);r_view.ortho_x = f[0];
+               r_view.frustum_y = tan(f[1] * M_PI / 360.0);r_view.ortho_y = f[1];
+               break;
+       case VF_FOVX:
+               r_view.frustum_x = tan(k * M_PI / 360.0);r_view.ortho_x = k;
+               break;
+       case VF_FOVY:
+               r_view.frustum_y = tan(k * M_PI / 360.0);r_view.ortho_y = k;
+               break;
+       case VF_ORIGIN:
+               VectorCopy(f, cl.csqc_origin);
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_X:
+               cl.csqc_origin[0] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_Y:
+               cl.csqc_origin[1] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ORIGIN_Z:
+               cl.csqc_origin[2] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES:
+               VectorCopy(f, cl.csqc_angles);
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_X:
+               cl.csqc_angles[0] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_Y:
+               cl.csqc_angles[1] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_ANGLES_Z:
+               cl.csqc_angles[2] = k;
+               CSQC_R_RecalcView();
+               break;
+       case VF_DRAWWORLD:
+               cl.csqc_vidvars.drawworld = k;
+               break;
+       case VF_DRAWENGINESBAR:
+               cl.csqc_vidvars.drawenginesbar = k;
+               break;
+       case VF_DRAWCROSSHAIR:
+               cl.csqc_vidvars.drawcrosshair = k;
+               break;
+       case VF_CL_VIEWANGLES:
+               VectorCopy(f, cl.viewangles);
+               break;
+       case VF_CL_VIEWANGLES_X:
+               cl.viewangles[0] = k;
+               break;
+       case VF_CL_VIEWANGLES_Y:
+               cl.viewangles[1] = k;
+               break;
+       case VF_CL_VIEWANGLES_Z:
+               cl.viewangles[2] = k;
+               break;
+       case VF_PERSPECTIVE:
+               r_view.useperspective = k != 0;
+               break;
+       default:
+               PRVM_G_FLOAT(OFS_RETURN) = 0;
+               VM_Warning("VM_CL_R_SetView : unknown parm %i\n", c);
+               return;
        }
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
@@ -819,7 +844,7 @@ static void VM_CL_R_AddDynamicLight (void)
 {
        float           *pos, *col;
        matrix4x4_t     matrix;
-       VM_SAFEPARMCOUNTRANGE(3, 8, VM_CL_R_AddDynamicLight); // allow more than 3 because we may extend this in the future
+       VM_SAFEPARMCOUNTRANGE(3, 3, VM_CL_R_AddDynamicLight);
 
        // if we've run out of dlights, just return
        if (r_refdef.numlights >= MAX_DLIGHTS)
@@ -3340,6 +3365,7 @@ const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
 
 void VM_CL_Cmd_Init(void)
 {
+       VM_Cmd_Init();
        // TODO: replace vm_polygons stuff with a more general debugging polygon system, and make vm_polygons functions use that system
        if(vm_polygons_initialized)
        {
@@ -3350,6 +3376,7 @@ void VM_CL_Cmd_Init(void)
 
 void VM_CL_Cmd_Reset(void)
 {
+       VM_Cmd_Reset();
        if(vm_polygons_initialized)
        {
                Mem_FreePool(&vm_polygons_pool);
index c8a2120d2bc9a5c9d3863301e3031675e46a7bdc..96a51244acc17375b534654febcd69c1ca554431 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -78,6 +78,7 @@ static void CSQC_SetGlobals (void)
                prog->globals.client->clientcommandframe = cl.movecmd[0].sequence;
                VectorCopy(cl.viewangles, prog->globals.client->input_angles);
                VectorCopy(cl.viewangles, cl.csqc_angles);
+               // // FIXME: this actually belongs into getinputstate().. [12/17/2007 Black]
                prog->globals.client->input_buttons = cl.movecmd[0].buttons;
                VectorSet(prog->globals.client->input_movevalues, cl.movecmd[0].forwardmove, cl.movecmd[0].sidemove, cl.movecmd[0].upmove);
                //VectorCopy(cl.movement_origin, cl.csqc_origin);
@@ -239,7 +240,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
        return true;
 }
 
-qboolean CL_VM_InputEvent (qboolean pressed, int key)
+qboolean CL_VM_InputEvent (qboolean down, int key)
 {
        qboolean r;
        if(!cl.csqc_loaded)
@@ -250,7 +251,7 @@ qboolean CL_VM_InputEvent (qboolean pressed, int key)
                else
                {
                        prog->globals.client->time = cl.time;
-                       PRVM_G_FLOAT(OFS_PARM0) = pressed;
+                       PRVM_G_FLOAT(OFS_PARM0) = !down; // 0 is down, 1 is up
                        PRVM_G_FLOAT(OFS_PARM1) = key;
                        PRVM_ExecuteProgram(prog->funcoffsets.CSQC_InputEvent, "QC function CSQC_InputEvent is missing");
                        r = CSQC_RETURNVAL;
diff --git a/keys.c b/keys.c
index 7627d30bfdd2306e505459a68ed90fe9600d9cd8..8faf34f9069652a46bf9db7ada08a2f2a77e4337 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -863,7 +863,7 @@ const char *Key_GetBind (int key)
        return bind;
 }
 
-qboolean CL_VM_InputEvent (qboolean pressed, int key);
+qboolean CL_VM_InputEvent (qboolean down, int key);
 
 /*
 ===================
@@ -888,9 +888,10 @@ Key_Event (int key, char ascii, qboolean down)
        if (developer.integer >= 1000)
                Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
 
+#if 0
        if(key_dest == key_game)
        {
-               q = CL_VM_InputEvent(!down, key);
+               q = CL_VM_InputEvent(down, key);
                if(q)
                {
                        if (down)
@@ -900,6 +901,7 @@ Key_Event (int key, char ascii, qboolean down)
                        return;
                }
        }
+#endif
 
        if (down)
        {
@@ -911,13 +913,6 @@ Key_Event (int key, char ascii, qboolean down)
        {
                // clear repeat count now that the key is released
                keydown[key] = 0;
-               // key up events only generate commands if the game key binding is a button
-               // command (leading + sign).  These will occur even in console mode, to
-               // keep the character from continuing an action started before a console
-               // switch.  Button commands include the kenum as a parameter, so multiple
-               // downs can be matched with ups
-               if (bind && bind[0] == '+')
-                       Cbuf_AddText(va("-%s %i\n", bind + 1, key));
        }
 
        // key_consoleactive is a flag not a key_dest because the console is a
@@ -957,7 +952,9 @@ Key_Event (int key, char ascii, qboolean down)
                                MR_KeyEvent (key, ascii, down);
                                break;
                        case key_game:
-                               if (down)
+                               // 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);
+                               if (!q && down)
                                        MR_ToggleMenu_f ();
                                break;
                        default:
@@ -999,6 +996,17 @@ Key_Event (int key, char ascii, qboolean down)
                return;
        }
 
+
+       // FIXME: actually the up-bind should only be called if the button was actually pressed while key_dest == key_game [12/17/2007 Black]
+       //                       especially CL_VM_InputEvent should be able to prevent it from being called (to intercept the binds)
+       // key up events only generate commands if the game key binding is a button
+       // command (leading + sign).  These will occur even in console mode, to
+       // keep the character from continuing an action started before a console
+       // switch.  Button commands include the kenum as a parameter, so multiple
+       // downs can be matched with ups
+       if (!down && bind && bind[0] == '+')
+               Cbuf_AddText(va("-%s %i\n", bind + 1, key));
+
        // ignore binds while a video is played, let the video system handle the key event
        if (cl_videoplaying)
        {
@@ -1017,8 +1025,9 @@ Key_Event (int key, char ascii, qboolean down)
                        MR_KeyEvent (key, ascii, down);
                        break;
                case key_game:
-                       // ignore key repeats on binds
-                       if (bind && keydown[key] == 1 && down)
+                       q = CL_VM_InputEvent(down, key);
+                       // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
+                       if (!q && bind && keydown[key] == 1 && down)
                        {
                                // button commands add keynum as a parm
                                if (bind[0] == '+')
index 71cfa159190fb5aaccae78facd2e2b79df351137..1be46fbbf79aa0bc91c0caf5fd3098f22f58ab11 100644 (file)
@@ -300,10 +300,10 @@ void EntityFrameCSQC_WriteState (sizebuf_t *msg, int number, qboolean doupdate,
                        if(!*sectionstarted)
                                MSG_WriteByte(msg, svc_csqcentities);
                        MSG_WriteShort(msg, number);
-                       ((int *)prog->globals.generic)[OFS_PARM0] = sv.writeentitiestoclient_cliententitynumber;
+                       PRVM_G_INT(OFS_PARM0) = sv.writeentitiestoclient_cliententitynumber;
                        prog->globals.server->self = number;
                        PRVM_ExecuteProgram(val->function, "Null SendEntity\n");
-                       if(prog->globals.generic[OFS_RETURN])
+                       if(PRVM_G_FLOAT(OFS_RETURN))
                        {
                                if (msg->cursize + 2 > msg->maxsize)
                                {