From 37d33a15ac06ecbdfdc4571aafd41054da432a57 Mon Sep 17 00:00:00 2001 From: divverent Date: Sat, 19 Nov 2011 12:50:40 +0000 Subject: [PATCH] support viewentity to be shared; DP_CSQC_V_CALCREFDEF git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11565 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=9fde8925b467809f91376ba9e6008f39dbe0d2d6 --- cl_main.c | 3 --- client.h | 2 +- clvm_cmds.c | 46 ++++++++++++++++++++++++++++++++++++++----- csprogs.c | 10 ++++++++++ csprogs.h | 2 ++ dpdefs/csprogsdefs.qc | 18 +++++++++++++++++ snd_main.c | 4 ++-- svvm_cmds.c | 1 + view.c | 6 +++--- 9 files changed, 78 insertions(+), 14 deletions(-) diff --git a/cl_main.c b/cl_main.c index cb03ffab..327a2f78 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2488,6 +2488,3 @@ void CL_Init (void) CL_Video_Init(); } - - - diff --git a/client.h b/client.h index f28e5adb..b5fd04fa 100644 --- 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); diff --git a/clvm_cmds.c b/clvm_cmds.c index 094f550e..8647ff23 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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); diff --git a/csprogs.c b/csprogs.c index 47573d3c..5816a3c6 100644 --- 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; +} diff --git a/csprogs.h b/csprogs.h index 67fd489a..958cfece 100644 --- 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 diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index fe200ae4..416d3d28 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -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 diff --git a/snd_main.c b/snd_main.c index 71f8b4d7..614b1687 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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) diff --git a/svvm_cmds.c b/svvm_cmds.c index 1faeeafd..043f2200 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -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 e5bdad59..5cc58755 100644 --- 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 { -- 2.39.2