]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
support pmove_flags (the actual flag values may be wrong, someone please find the...
[xonotic/darkplaces.git] / clvm_cmds.c
index 536aad05e51791c6ef7d601a8fd2e2ff649308e5..ba7926c82c896ea75bd11754a21ea7c94772c3a3 100644 (file)
@@ -24,6 +24,7 @@ extern cvar_t v_flipped;
 extern cvar_t r_equalize_entities_fullbright;
 
 r_refdef_view_t csqc_original_r_refdef_view;
+r_refdef_view_t csqc_main_r_refdef_view;
 
 // #1 void(vector ang) makevectors
 static void VM_CL_makevectors (prvm_prog_t *prog)
@@ -875,6 +876,9 @@ static void VM_CL_R_SetView (prvm_prog_t *prog)
                case VF_CLEARSCREEN:
                        PRVM_G_FLOAT(OFS_RETURN) = r_refdef.view.isoverlay;
                        break;
+               case VF_MAINVIEW:
+                       PRVM_G_FLOAT(OFS_RETURN) = r_refdef.view.ismain;
+                       break;
                case VF_FOG_DENSITY:
                        PRVM_G_FLOAT(OFS_RETURN) = r_refdef.fog_density;
                        break;
@@ -1022,6 +1026,9 @@ static void VM_CL_R_SetView (prvm_prog_t *prog)
        case VF_CLEARSCREEN:
                r_refdef.view.isoverlay = !k;
                break;
+       case VF_MAINVIEW:
+               PRVM_G_FLOAT(OFS_RETURN) = r_refdef.view.ismain;
+               break;
        case VF_FOG_DENSITY:
                r_refdef.fog_density = k;
                break;
@@ -1434,6 +1441,35 @@ static void VM_CL_setsensitivityscale (prvm_prog_t *prog)
 //#347 void() runstandardplayerphysics (EXT_CSQC)
 static void VM_CL_runplayerphysics (prvm_prog_t *prog)
 {
+       cl_clientmovement_state_t s;
+       prvm_edict_t *ent;
+
+       VM_SAFEPARMCOUNT(1, VM_CL_runplayerphysics);
+
+       ent = PRVM_G_EDICT(OFS_PARM0);
+       VectorCopy(PRVM_clientedictvector(ent, origin), s.origin);
+       VectorCopy(PRVM_clientedictvector(ent, velocity), s.velocity);
+       VectorCopy(PRVM_clientglobalvector(pmove_mins), s.mins);
+       VectorCopy(PRVM_clientglobalvector(pmove_maxs), s.maxs);
+       s.crouched = ((int)PRVM_clientedictfloat(ent, pmove_flags) & 1) != 0; // FIXME which flag?
+       s.waterjumptime = 0; // FIXME where do we get this from?
+       VectorCopy(PRVM_clientglobalvector(input_angles), s.cmd.viewangles);
+       s.cmd.forwardmove = PRVM_clientglobalvector(input_movevalues)[0];
+       s.cmd.sidemove = PRVM_clientglobalvector(input_movevalues)[1];
+       s.cmd.upmove = PRVM_clientglobalvector(input_movevalues)[2];
+       s.cmd.buttons = PRVM_clientglobalfloat(input_buttons);
+       s.cmd.frametime = PRVM_clientglobalfloat(input_timelength);
+       s.cmd.canjump = ((int)PRVM_clientedictfloat(ent, pmove_flags) & 2) != 0; // FIXME which flag?
+       s.cmd.jump = (s.cmd.buttons & 2) != 0;
+       s.cmd.crouch = (s.cmd.buttons & 16) != 0;
+
+       CL_ClientMovement_PlayerMove(&s);
+
+       VectorCopy(s.origin, PRVM_clientedictvector(ent, origin));
+       VectorCopy(s.velocity, PRVM_clientedictvector(ent, velocity));
+       PRVM_clientedictfloat(ent, pmove_flags) =
+               (s.crouched ? 1 : 0) |
+               (s.cmd.canjump ? 2 : 0);
 }
 
 //#348 string(float playernum, string keyname) getplayerkeyvalue (EXT_CSQC)
@@ -3041,6 +3077,17 @@ static void VM_CL_R_RenderScene (prvm_prog_t *prog)
        vmpolygons_t *polys = &prog->vmpolygons;
        VM_SAFEPARMCOUNT(0, VM_CL_R_RenderScene);
 
+       // update the views
+       if(r_refdef.view.ismain)
+       {
+               // set the main view
+               csqc_main_r_refdef_view = r_refdef.view;
+
+               // clear the flags so no other view becomes "main" unless CSQC sets VF_MAINVIEW
+               r_refdef.view.ismain = false;
+               csqc_original_r_refdef_view.ismain = false;
+       }
+
        // we need to update any RENDER_VIEWMODEL entities at this point because
        // csqc supplies its own view matrix
        CL_UpdateViewEntities();
@@ -3208,7 +3255,7 @@ void VM_CL_AddPolygonsToMeshQueue (prvm_prog_t *prog)
        for (i = 0;i < polys->num_triangles;i++)
        {
                VectorMAMAM(1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[0], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[1], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[2], center);
-               R_MeshQueue_AddTransparent(center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
+               R_MeshQueue_AddTransparent(MESHQUEUE_SORT_DISTANCE, center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
        }
 
        /*polys->num_triangles = 0; // now done after rendering the scene,