]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
support viewentity to be shared; DP_CSQC_V_CALCREFDEF
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 19 Nov 2011 12:50:40 +0000 (12:50 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 19 Nov 2011 12:50:40 +0000 (12:50 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11565 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
client.h
clvm_cmds.c
csprogs.c
csprogs.h
dpdefs/csprogsdefs.qc
snd_main.c
svvm_cmds.c
view.c

index cb03ffab1d8154ec72a966686125934eb6d30008..327a2f7853c51bba602fe99d9b12255a13866582 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -2488,6 +2488,3 @@ void CL_Init (void)
 
        CL_Video_Init();
 }
-
-
-
index f28e5adb78cdfef974f843555895af22ac927d90..b5fd04fa4532801cac0483fc203fc477b2c9ae1a 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1889,7 +1889,7 @@ void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size
 void V_DriftPitch(void);
 void V_FadeViewFlashs(void);
 void V_CalcViewBlend(void);
-void V_CalcRefdefUsing(const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump);
+void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump, float clstatsviewheight);
 void V_CalcRefdef(void);
 void CL_Locs_Reload_f(void);
 
index 094f550e389dedbcef67530d70bd552ad6873a98..8647ff23e918fdeae381bb20e2917194485fd8ee 100644 (file)
@@ -1446,9 +1446,10 @@ static void VM_CL_setsensitivityscale (prvm_prog_t *prog)
 }
 
 //#347 void() runstandardplayerphysics (EXT_CSQC)
-#define PMF_JUMP_HELD 1
-#define PMF_LADDER 2 // not used by DP
-#define PMF_DUCKED 4 // FIXME FTEQW doesn't have this for Q1 like movement
+#define PMF_JUMP_HELD 1 // matches FTEQW
+#define PMF_LADDER 2 // not used by DP, FTEQW sets this in runplayerphysics but does not read it
+#define PMF_DUCKED 4 // FIXME FTEQW doesn't have this for Q1 like movement because Q1 cannot crouch
+#define PMF_ONGROUND 8 // FIXME FTEQW doesn't have this for Q1 like movement and expects CSQC code to do its own trace, this is stupid CPU waste
 static void VM_CL_runplayerphysics (prvm_prog_t *prog)
 {
        cl_clientmovement_state_t s;
@@ -1479,7 +1480,8 @@ static void VM_CL_runplayerphysics (prvm_prog_t *prog)
        VectorCopy(s.velocity, PRVM_clientedictvector(ent, velocity));
        PRVM_clientedictfloat(ent, pmove_flags) =
                (s.crouched ? PMF_DUCKED : 0) |
-               (s.cmd.canjump ? 0 : PMF_JUMP_HELD);
+               (s.cmd.canjump ? 0 : PMF_JUMP_HELD) |
+               (s.onground ? PMF_ONGROUND : 0);
 }
 
 //#348 string(float playernum, string keyname) getplayerkeyvalue (EXT_CSQC)
@@ -4117,6 +4119,39 @@ static void VM_CL_loadcubemap(prvm_prog_t *prog)
        R_GetCubemap(name);
 }
 
+#define REFDEFFLAG_TELEPORTED 1
+#define REFDEFFLAG_JUMPING 2
+static void VM_CL_V_CalcRefdef(prvm_prog_t *prog)
+{
+       matrix4x4_t entrendermatrix;
+       vec3_t clviewangles;
+       qboolean teleported;
+       qboolean clonground;
+       qboolean clcmdjump;
+       float clstatsviewheight;
+       prvm_edict_t *ent;
+       int flags;
+
+       VM_SAFEPARMCOUNT(2, VM_CL_V_CalcRefdef);
+       ent = PRVM_G_EDICT(OFS_PARM0);
+       flags = PRVM_G_FLOAT(OFS_PARM1);
+
+       // use the CL_GetTagMatrix function on self to ensure consistent behavior (duplicate code would be bad)
+       CL_GetTagMatrix(prog, &entrendermatrix, ent, 0);
+
+       VectorCopy(cl.csqc_viewangles, clviewangles);
+       teleported = (flags & REFDEFFLAG_TELEPORTED) != 0;
+       clonground = ((int)PRVM_clientedictfloat(ent, pmove_flags) & PMF_ONGROUND) != 0;
+       clcmdjump = (flags & REFDEFFLAG_JUMPING) != 0;
+       clstatsviewheight = PRVM_clientedictvector(ent, view_ofs)[2];
+
+       V_CalcRefdefUsing(&entrendermatrix, clviewangles, teleported, clonground, clcmdjump, clstatsviewheight);
+
+       VectorCopy(cl.csqc_vieworiginfromengine, cl.csqc_vieworigin);
+       VectorCopy(cl.csqc_viewanglesfromengine, cl.csqc_viewangles);
+       CSQC_R_RecalcView();
+}
+
 //============================================================================
 
 // To create a almost working builtin file from this replace:
@@ -4771,7 +4806,8 @@ NULL,                                                     // #636
 NULL,                                                  // #637
 VM_CL_RotateMoves,                                     // #638
 VM_digest_hex,                                         // #639
-NULL,                                                  // #640
+VM_CL_V_CalcRefdef,                                    // #640 void(entity e) V_CalcRefdef (DP_CSQC_V_CALCREFDEF)
+NULL,                                                  // #641
 };
 
 const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
index 47573d3cf8cc446661775e2d4d0cb6d4238f8eb7..5816a3c6f0b7a687d9854220fca0c258465bbe66 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -373,6 +373,9 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
                if(renderflags & RF_ADDITIVE) entrender->flags |= RENDER_ADDITIVE;
        }
 
+       if(edictnum == CL_VM_GetViewEntity())
+               entrender->flags |= RENDER_EXTERIORMODEL;
+
        c = (int)PRVM_clientedictfloat(ed, colormap);
        if (c <= 0)
                CL_SetEntityColormapColors(entrender, -1);
@@ -1223,3 +1226,10 @@ qboolean CL_VM_TransformView(int entnum, matrix4x4_t *viewmatrix, mplane_t *clip
 
        return ret;
 }
+
+int CL_VM_GetViewEntity(void)
+{
+       if(cl.csqc_server2csqcentitynumber[cl.viewentity])
+               return cl.csqc_server2csqcentitynumber[cl.viewentity];
+       return cl.viewentity;
+}
index 67fd489a2c7f1b0fb6a9db88587bfd4ac9bbb2c6..958cfece1a127e34367cebc1ae69c67fd933843b 100644 (file)
--- a/csprogs.h
+++ b/csprogs.h
@@ -109,4 +109,6 @@ void CSQC_R_RecalcView(void);
 
 dp_model_t *CL_GetModelByIndex(int modelindex);
 
+int CL_VM_GetViewEntity(void);
+
 #endif
index fe200ae414a7824b26dcebbb8c6b73ca225de44e..416d3d284fdabd37c62291fb6d026a3157fe0ccb 100644 (file)
@@ -901,3 +901,21 @@ const float VF_MAINVIEW         = 212;
 const float VF_MINFPS_QUALITY   = 213;
 //use getproperty(VF_MINFPS_QUALITY); to do CSQC based LOD based on cl_minfps
 //1 should lead to an unmodified view
+
+//DP_CSQC_V_CALCREFDEF_WIP1
+//idea: divVerent
+//darkplaces implementation: divVerent
+//builtin definitions:
+void(entity e, float refdefflags) V_CalcRefdef = #640;
+//constant definitions:
+float PMF_DUCKED = 4;
+float PMF_ONGROUND = 8;
+float REFDEFFLAG_TELEPORTED = 1;
+float REFDEFFLAG_JUMPING = 2;
+//- use this on the player entity after performing prediction
+//- pass REFDEFFLAG_TELEPORTED if the player teleported since last frame
+//- pass REFDEFFLAG_JUMPING if jump button is pressed
+//- the player entity needs to have origin, velocity, pmove_flags set according
+//  to prediction (the above two PMF_ flags are used in the player's pmove_flags)
+//- NOTE: to check for this, ALSO OR a check with DP_CSQC_V_CALCREFDEF to also support
+//  the finished extension once done
index 71f8b4d73e80c6612f7c3c32677ba22a440bf4b0..614b16879dcb0dffc8578f0f4a09b19a4eec7dd8 100644 (file)
@@ -1262,7 +1262,7 @@ static channel_t *SND_PickChannel(int entnum, int entchannel)
                }
 
                // don't let monster sounds override player sounds
-               if (ch->entnum == cl.viewentity && entnum != cl.viewentity)
+               if ((ch->entnum == cl.viewentity || ch->entnum == CL_VM_GetViewEntity()) && !(entnum == cl.viewentity || entnum == CL_VM_GetViewEntity()))
                        continue;
 
                // don't override looped sounds
@@ -1459,7 +1459,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
 
        // anything coming from the view entity will always be full volume
        // LordHavoc: make sounds with ATTN_NONE have no spatialization
-       if (ch->entnum == cl.viewentity || ch->distfade == 0)
+       if (ch->entnum == cl.viewentity || ch->entnum == CL_VM_GetViewEntity() || ch->distfade == 0)
        {
                ch->prologic_invert = 1;
                if (snd_spatialization_prologic.integer != 0)
index 1faeeafd811e0a5e3c249b764173d36e1bc3c765..043f2200a807fe8f9deb749cf80d8f6bb594b4e2 100644 (file)
@@ -32,6 +32,7 @@ const char *vm_sv_extensions =
 "DP_CSQC_QUERYRENDERENTITY "
 "DP_CSQC_ROTATEMOVES "
 "DP_CSQC_SETPAUSE "
+"DP_CSQC_V_CALCREFDEF_WIP1 "
 "DP_EF_ADDITIVE "
 "DP_EF_BLUE "
 "DP_EF_DOUBLESIDED "
diff --git a/view.c b/view.c
index e5bdad5999b59d828bc91164052f1efc2b43ba1f..5cc5875534cbf4285666d25d493c1f19096ab8b3 100644 (file)
--- a/view.c
+++ b/view.c
@@ -428,7 +428,7 @@ static void highpass3_limited(vec3_t value, vec_t fracx, vec_t limitx, vec_t fra
        out[2] = highpass_limited(value[2], fracz, limitz, &store[2]);
 }
 
-void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump)
+void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewangles, qboolean teleported, qboolean clonground, qboolean clcmdjump, float clstatsviewheight)
 {
        float vieworg[3], viewangles[3], smoothtime;
        float gunorg[3], gunangles[3];
@@ -505,7 +505,7 @@ void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewa
                // apply the viewofs (even if chasecam is used)
                // Samual: Lets add smoothing for this too so that things like crouching are done with a transition.
                viewheight = bound(0, (cl.time - cl.oldtime) / max(0.0001, cl_smoothviewheight.value), 1);
-               viewheightavg = viewheightavg * (1 - viewheight) + cl.stats[STAT_VIEWHEIGHT] * viewheight;
+               viewheightavg = viewheightavg * (1 - viewheight) + clstatsviewheight * viewheight;
                vieworg[2] += viewheightavg;
 
                if (chase_active.value)
@@ -832,7 +832,7 @@ void V_CalcRefdef (void)
                // ent is the view entity (visible when out of body)
                ent = &cl.entities[cl.viewentity];
 
-               V_CalcRefdefUsing(&ent->render.matrix, cl.viewangles, !ent->persistent.trail_allowed, cl.onground, cl.cmd.jump); // FIXME use a better way to detect teleport/warp than trail_allowed
+               V_CalcRefdefUsing(&ent->render.matrix, cl.viewangles, !ent->persistent.trail_allowed, cl.onground, cl.cmd.jump, cl.stats[STAT_VIEWHEIGHT]); // FIXME use a better way to detect teleport/warp than trail_allowed
        }
        else
        {