From 7938a89abdf37e9452182f64bc9aec0293f493a3 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 8 Nov 2011 20:49:52 +0000 Subject: [PATCH] 1. make the first CSQC rendered view the "main" view, for use e.g. by origin display in r_speeds, prydon cursor, etc. 2. add an extension DP_CSQC_MAINVIEW to override DP's notion of the "main" view when necessesary git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11540 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 2 ++ clvm_cmds.c | 18 ++++++++++++++++++ csprogs.c | 7 ++++++- csprogs.h | 2 ++ dpdefs/csprogsdefs.qc | 13 ++++++++++++- gl_rmain.c | 2 +- render.h | 1 + svvm_cmds.c | 1 + 8 files changed, 43 insertions(+), 3 deletions(-) diff --git a/client.h b/client.h index a7555e86..3ece601a 100644 --- a/client.h +++ b/client.h @@ -1669,6 +1669,8 @@ typedef struct r_refdef_view_s qboolean clear; // if true, don't clear or do any post process effects (bloom, etc) qboolean isoverlay; + // if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor) + qboolean ismain; // whether to draw r_showtris and such, this is only true for the main // view render, all secondary renders (mirrors, portals, cameras, diff --git a/clvm_cmds.c b/clvm_cmds.c index 536aad05..1a6204d1 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -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; @@ -3041,6 +3048,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(); diff --git a/csprogs.c b/csprogs.c index 732b6517..e4d1ed09 100644 --- a/csprogs.c +++ b/csprogs.c @@ -450,6 +450,7 @@ qboolean CL_VM_InputEvent (int eventtype, int x, int y) } extern r_refdef_view_t csqc_original_r_refdef_view; +extern r_refdef_view_t csqc_main_r_refdef_view; qboolean CL_VM_UpdateView (void) { prvm_prog_t *prog = CLVM_prog; @@ -462,7 +463,9 @@ qboolean CL_VM_UpdateView (void) return false; R_TimeReport("pre-UpdateView"); CSQC_BEGIN + r_refdef.view.ismain = true; csqc_original_r_refdef_view = r_refdef.view; + csqc_main_r_refdef_view = r_refdef.view; //VectorCopy(cl.viewangles, oldangles); PRVM_clientglobalfloat(time) = cl.time; PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity]; @@ -478,8 +481,10 @@ qboolean CL_VM_UpdateView (void) //VectorCopy(oldangles, cl.viewangles); // Dresk : Reset Dmg Globals Here CL_VM_UpdateDmgGlobals(0, 0, emptyvector); - r_refdef.view = csqc_original_r_refdef_view; + r_refdef.view = csqc_main_r_refdef_view; + R_RenderView_UpdateViewVectors(); // we have to do this, as we undid the scene render doing this for us CSQC_END + R_TimeReport("UpdateView"); return true; } diff --git a/csprogs.h b/csprogs.h index 95e1c48d..2aba12b3 100644 --- a/csprogs.h +++ b/csprogs.h @@ -50,6 +50,8 @@ #define VF_FOG_HEIGHT 210 //(float) #define VF_FOG_FADEDEPTH 211 //(float) +#define VF_MAINVIEW 212 //(float) + #define RF_VIEWMODEL 1 // The entity is never drawn in mirrors. In engines with realtime lighting, it casts no shadows. #define RF_EXTERNALMODEL 2 // The entity is appears in mirrors but not in the normal view. It does still cast shadows in engines with realtime lighting. #define RF_DEPTHHACK 4 // The entity appears closer to the view than normal, either by scaling it wierdly or by just using a depthrange. This will usually be found in conjunction with RF_VIEWMODEL diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index cca16019..8fa52e44 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -881,4 +881,15 @@ string(string command, float bindmap) findkeysforcommand = #610; //builtin definitions: (CSQC) float(string url, float id, string content_type, string delim, float buf, float keyid) crypto_uri_postbuf = #513; //description: -//use -1 as buffer handle to justs end delim as postdata \ No newline at end of file +//use -1 as buffer handle to justs end delim as postdata + +//DP_CSQC_MAINVIEW +//idea: divVerent +//darkplaces implementation: divVerent +//constant definitions: +const float VF_MAINVIEW = 212; +//use setproperty(VF_MAINVIEW, 1); before calling R_RenderView for the render +//that shall become the "main" view, which is e.g. used by PRYDON_CLIENTCURSOR +//this flag is set for the first scene, and not cleared by R_ClearScene +//this flag is automatically cleared by R_RenderView +//so when not using this extension, the first view rendered is the main view diff --git a/gl_rmain.c b/gl_rmain.c index 8e9817ef..e8b15f35 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -5477,7 +5477,7 @@ void R_ResetViewRendering3D(int fbo, rtexture_t *depthtexture, rtexture_t *color R_RenderView_UpdateViewVectors ================ */ -static void R_RenderView_UpdateViewVectors(void) +void R_RenderView_UpdateViewVectors(void) { // break apart the view matrix into vectors for various purposes // it is important that this occurs outside the RenderScene function because that can be called from reflection renders, where the vectors come out wrong diff --git a/render.h b/render.h index d2cccc63..e81638ba 100644 --- a/render.h +++ b/render.h @@ -126,6 +126,7 @@ extern cvar_t r_dynamic; void R_Init(void); void R_UpdateVariables(void); // must call after setting up most of r_refdef, but before calling R_RenderView void R_RenderView(void); // must set r_refdef and call R_UpdateVariables first +void R_RenderView_UpdateViewVectors(void); // just updates r_refdef.view.{forward,left,up,origin,right,inverse_matrix} typedef enum r_refdef_scene_type_s { RST_CLIENT, diff --git a/svvm_cmds.c b/svvm_cmds.c index f6b0d1b6..3bb77ef6 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -24,6 +24,7 @@ const char *vm_sv_extensions = "DP_CSQC_ENTITYWORLDOBJECT " "DP_CSQC_ENTITYMODELLIGHT " "DP_CSQC_ENTITYTRANSPARENTSORTING_OFFSET " +"DP_CSQC_MAINVIEW " "DP_CSQC_MULTIFRAME_INTERPOLATION " "DP_CSQC_BOXPARTICLES " "DP_CSQC_SPAWNPARTICLE " -- 2.39.2