From 9928bbf28e8024fbc5f7385c2354843b04c73508 Mon Sep 17 00:00:00 2001 From: black Date: Sat, 5 Jan 2008 01:28:56 +0000 Subject: [PATCH] Hack everything together to make it use a stack refdef and a second global one (for now). (Untested) git-svn-id: svn://svn.icculus.org/twilight/branches/dp-mqc-render/darkplaces@7908 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 50 +++++++++++++++++++----------------------------- clvm_cmds.h | 3 --- menu.c | 8 ++++++++ menu.h | 4 ++++ mvm_cmds.c | 55 ++++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 74 insertions(+), 46 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index fa9efa28..0f1e5be4 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -5,10 +5,6 @@ #include "cl_collision.h" #include "r_shadow.h" -/* Per-VM scenes */ -renderscene_t* renderscenes[PRVM_MAXPROGS]; -#define RENDERSCENE (*renderscenes[prognum]) - //============================================================================ // Client //[515]: unsolved PROBLEMS @@ -30,11 +26,6 @@ void CSQC_RelinkAllEntities (int drawmask); void CSQC_RelinkCSQCEntities (void); const char *Key_GetBind (int key); - - - - - // #1 void(vector ang) makevectors static void VM_CL_makevectors (void) { @@ -640,7 +631,7 @@ static void VM_CL_getlight (void) //============================================================================ //[515]: SCENE MANAGER builtins -extern qboolean CSQC_AddRenderEdict (renderscene_t* scene, prvm_edict_t *ed);//csprogs.c +extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed);//csprogs.c static void CSQC_R_RecalcView (void) { @@ -2245,13 +2236,13 @@ typedef struct typedef struct vmpolygons_s { - //static float vm_polygon_linewidth = 1; - mempool_t *pool; - unsigned char current_vertices; - qboolean initialized; - vm_polygon_t *polygons; - unsigned long polygons_num, drawpolygons_num; //[515]: ok long on 64bit ? - qboolean polygonbegin; //[515]: for "no-crap-on-the-screen" check + //static float vm_polygon_linewidth = 1; + mempool_t *pool; + unsigned char current_vertices; + qboolean initialized; + vm_polygon_t *polygons; + unsigned long polygons_num, drawpolygons_num; //[515]: ok long on 64bit ? + qboolean polygonbegin; //[515]: for "no-crap-on-the-screen" check } vmpolygons_t; vmpolygons_t vmpolygons[PRVM_MAXPROGS]; #define VM_DEFPOLYNUM 64 //[515]: enough for default ? @@ -2275,8 +2266,8 @@ static void VM_InitPolygons (vmpolygons_t* polys) static void VM_DrawPolygonCallback (const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist) { int surfacelistindex; - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + // LordHavoc: FIXME: this is stupid code for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++) { @@ -2379,8 +2370,8 @@ static void VM_CL_AddPolygonTo2DScene (vm_polygon_t *p) void VM_CL_AddPolygonsToMeshQueue (void) { int i; - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + if(!polys->drawpolygons_num) return; R_Mesh_Matrix(&identitymatrix); @@ -2395,8 +2386,8 @@ void VM_CL_R_PolygonBegin (void) { vm_polygon_t *p; const char *picname; - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + VM_SAFEPARMCOUNTRANGE(2, 4, VM_CL_R_PolygonBegin); if(!polys->initialized) @@ -2441,8 +2432,8 @@ void VM_CL_R_PolygonVertex (void) { float *coords, *tx, *rgb, alpha; vm_polygon_t *p; - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + VM_SAFEPARMCOUNT(4, VM_CL_R_PolygonVertex); if(!polys->polygonbegin) @@ -2486,8 +2477,8 @@ void VM_CL_R_PolygonVertex (void) //void() R_EndPolygon void VM_CL_R_PolygonEnd (void) { - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + VM_SAFEPARMCOUNT(0, VM_CL_R_PolygonEnd); if(!polys->polygonbegin) { @@ -3388,8 +3379,8 @@ const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t); void VM_Polygons_Reset(void) { - vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); - + vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + // TODO: replace vm_polygons stuff with a more general debugging polygon system, and make vm_polygons functions use that system if(polys->initialized) { @@ -3402,7 +3393,6 @@ void VM_CL_Cmd_Init(void) { VM_Cmd_Init(); VM_Polygons_Reset(); - renderscenes[PRVM_CLIENTPROG] = &client_scene; } void VM_CL_Cmd_Reset(void) diff --git a/clvm_cmds.h b/clvm_cmds.h index 2e5ca5cb..8ec57742 100644 --- a/clvm_cmds.h +++ b/clvm_cmds.h @@ -10,9 +10,6 @@ void VM_CL_setmodel (void); void VM_CL_precache_model (void); void VM_CL_setorigin (void); -/* Per-VM scenes */ -extern renderscene_t* renderscenes[PRVM_MAXPROGS]; - void VM_CL_R_AddDynamicLight (void); void VM_CL_R_ClearScene (void); void VM_CL_R_AddEntities (void); diff --git a/menu.c b/menu.c index 29467965..63cec73b 100644 --- a/menu.c +++ b/menu.c @@ -5070,12 +5070,20 @@ void MP_KeyEvent (int key, char ascii, qboolean downevent) void MP_Draw (void) { + r_refdef_t clientrefdef = r_refdef; + r_refdef = menu_refdef; + PRVM_Begin; PRVM_SetProg(PRVM_MENUPROG); + // FIXME: this really shouldnt error out lest we have a very broken refdef state...? + // or does it kill the server too? PRVM_ExecuteProgram(prog->funcoffsets.m_draw,"m_draw() required"); PRVM_End; + + menu_refdef = r_refdef; + r_refdef = clientrefdef; } void MP_ToggleMenu_f (void) diff --git a/menu.h b/menu.h index 85833341..bae1fd54 100644 --- a/menu.h +++ b/menu.h @@ -76,6 +76,10 @@ void MP_Shutdown (void);*/ // // menu router // + +// hack +extern r_refdef_t menu_refdef; + void MR_Init_Commands (void); void MR_Init (void); void MR_Restart (void); diff --git a/mvm_cmds.c b/mvm_cmds.c index 11d0ddc9..36c759a2 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1,6 +1,7 @@ #include "quakedef.h" #include "prvm_cmds.h" +#include "clvm_cmds.h" #include "menu.h" //============================================================================ @@ -23,6 +24,7 @@ char *vm_m_extensions = #ifdef SUPPORT_GECKO "DP_GECKO_SUPPORT " #endif +"DP_QC_RENDER_SCENE" ; /* @@ -872,9 +874,9 @@ VM_altstr_ins, // #86 VM_findflags, // #87 VM_findchainflags, // #88 VM_cvar_defstring, // #89 -NULL, // #90 -NULL, // #91 -NULL, // #92 +VM_CL_setmodel, // #90 void(entity e, string m) setmodel (QUAKE) +VM_CL_precache_model, // #91 void(string s) precache_model (QUAKE) +VM_CL_setorigin, // #92 void(entity e, vector o) setorigin (QUAKE) NULL, // #93 NULL, // #94 NULL, // #95 @@ -1082,16 +1084,17 @@ NULL, // #296 NULL, // #297 NULL, // #298 NULL, // #299 -NULL, // #300 -NULL, // #301 -NULL, // #302 -NULL, // #303 -NULL, // #304 -NULL, // #305 -NULL, // #306 -NULL, // #307 -NULL, // #308 -NULL, // #309 +// CSQC range #300-#399 +VM_CL_R_ClearScene, // #300 void() clearscene (DP_QC_RENDER_SCENE) +VM_CL_R_AddEntities, // #301 void(float mask) addentities (DP_QC_RENDER_SCENE) +VM_CL_R_AddEntity, // #302 void(entity ent) addentity (DP_QC_RENDER_SCENE) +VM_CL_R_SetView, // #303 float(float property, ...) setproperty (DP_QC_RENDER_SCENE) +VM_CL_R_RenderScene, // #304 void() renderscene (DP_QC_RENDER_SCENE) +VM_CL_R_AddDynamicLight, // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (DP_QC_RENDER_SCENE) +VM_CL_R_PolygonBegin, // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon +VM_CL_R_PolygonVertex, // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex +VM_CL_R_PolygonEnd, // #308 void() R_EndPolygon +NULL/*VM_CL_R_LoadWorldModel*/, // #309 void(string modelname) R_LoadWorldModel NULL, // #310 NULL, // #311 NULL, // #312 @@ -1421,13 +1424,39 @@ VM_M_getextresponse // #624 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t); +r_refdef_t menu_refdef; + void VM_M_Cmd_Init(void) { VM_Cmd_Init(); + VM_Polygons_Reset(); + + memset (&menu_refdef, 0, sizeof (r_refdef_t)); + + menu_refdef.frustumscale_x = 1; + menu_refdef.frustumscale_y = 1; + menu_refdef.maxentities = MAX_EDICTS + 256 + 512; + menu_refdef.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * menu_refdef.maxentities); + + menu_refdef.view.width = vid.width; + menu_refdef.view.height = vid.height; + menu_refdef.view.depth = 1; + menu_refdef.view.x = 0; + menu_refdef.view.y = 0; + menu_refdef.view.z = 0; + menu_refdef.view.colormask[0] = true; + menu_refdef.view.colormask[1] = true; + menu_refdef.view.colormask[2] = true; + menu_refdef.view.colormask[3] = true; + + menu_refdef.view.useperspective = true; + menu_refdef.view.frustum_y = tan(scr_fov.value * M_PI / 360.0) * (3.0/4.0); + menu_refdef.view.frustum_x = menu_refdef.view.frustum_y * (float)menu_refdef.view.width / (float)menu_refdef.view.height / vid_pixelheight.value; } void VM_M_Cmd_Reset(void) { //VM_Cmd_Init(); VM_Cmd_Reset(); + VM_Polygons_Reset(); } -- 2.39.2