From: black Date: Sun, 27 Jan 2008 02:18:54 +0000 (+0000) Subject: Add R_SelectScene and R_GetScenePointer that encapsulate access to an array of r_refd... X-Git-Tag: xonotic-v0.1.0preview~2492 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a757d821b12d5ec84cf4d76a9572d9c90ca77324;p=xonotic%2Fdarkplaces.git Add R_SelectScene and R_GetScenePointer that encapsulate access to an array of r_refdef_scene_t that is swapped into r_refdef on need. Change the menu to use it and fix a bug that was caused because of the menu's use of the stack for backing up the client's scene. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8020 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index d17ff715..5057febf 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -3413,6 +3413,38 @@ void R_UpdateVariables(void) r_refdef.fogenabled = false; } +static r_refdef_scene_type_t r_currentscenetype = RST_CLIENT; +static r_refdef_scene_t r_scenes_store[ RST_COUNT ]; +/* +================ +R_SelectScene +================ +*/ +void R_SelectScene( r_refdef_scene_type_t scenetype ) { + if( scenetype != r_currentscenetype ) { + // store the old scenetype + r_scenes_store[ r_currentscenetype ] = r_refdef.scene; + r_currentscenetype = scenetype; + // move in the new scene + r_refdef.scene = r_scenes_store[ r_currentscenetype ]; + } +} + +/* +================ +R_GetScenePointer +================ +*/ +r_refdef_scene_t * R_GetScenePointer( r_refdef_scene_type_t scenetype ) +{ + // of course, we could also add a qboolean that provides a lock state and a ReleaseScenePointer function.. + if( scenetype == r_currentscenetype ) { + return &r_refdef.scene; + } else { + return &r_scenes_store[ scenetype ]; + } +} + /* ================ R_RenderView diff --git a/menu.c b/menu.c index a4a3086b..c0e71be0 100644 --- a/menu.c +++ b/menu.c @@ -5049,6 +5049,9 @@ void MP_Error(const char *format, ...) // init the normal menu now -> this will also correct the menu router pointers MR_SetRouting (TRUE); + // reset the active scene, too (to be on the safe side ;)) + R_SelectScene( RST_CLIENT ); + Host_AbortCurrentFrame(); } @@ -5071,12 +5074,10 @@ void MP_KeyEvent (int key, char ascii, qboolean downevent) void MP_Draw (void) { // declarations that are needed right now - extern r_refdef_scene_t menu_scene; float oldquality; - static r_refdef_scene_t clientscene; - clientscene = r_refdef.scene; - r_refdef.scene = menu_scene; + + R_SelectScene( RST_MENU ); // reset the temp entities each frame r_refdef.scene.numtempentities = 0; @@ -5094,10 +5095,10 @@ void MP_Draw (void) PRVM_End; + // TODO: imo this should be moved into scene, too [1/27/2008 Andreas] r_refdef.view.quality = oldquality; - menu_scene = r_refdef.scene; - r_refdef.scene = clientscene; + R_SelectScene( RST_CLIENT ); } void MP_ToggleMenu_f (void) diff --git a/mvm_cmds.c b/mvm_cmds.c index 681ebb8c..5d142ac8 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1415,24 +1415,28 @@ VM_M_getextresponse // #624 string getextresponse(void) const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t); -r_refdef_scene_t menu_scene; - void VM_M_Cmd_Init(void) { + r_refdef_scene_t *scene; + VM_Cmd_Init(); VM_Polygons_Reset(); - memset (&menu_scene, 0, sizeof (menu_scene)); + scene = R_GetScenePointer( RST_MENU ); - menu_scene.maxtempentities = 128; - menu_scene.tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * menu_scene.maxtempentities); + memset (scene, 0, sizeof (*scene)); - menu_scene.maxentities = MAX_EDICTS + 256 + 512; - menu_scene.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * menu_scene.maxentities); + scene->maxtempentities = 128; + scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities); + + scene->maxentities = MAX_EDICTS + 256 + 512; + scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities); } void VM_M_Cmd_Reset(void) { + // note: the menu's render entities are automatically freed when the prog's pool is freed + //VM_Cmd_Init(); VM_Cmd_Reset(); VM_Polygons_Reset(); diff --git a/render.h b/render.h index af999c38..b30dd7d8 100644 --- a/render.h +++ b/render.h @@ -124,6 +124,14 @@ 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 +typedef enum r_refdef_scene_type_s { + RST_CLIENT, + RST_MENU, + RST_COUNT +} r_refdef_scene_type_t; + +void R_SelectScene( r_refdef_scene_type_t scenetype ); +r_refdef_scene_t * R_GetScenePointer( r_refdef_scene_type_t scenetype ); void R_SkinFrame_PrepareForPurge(void); void R_SkinFrame_MarkUsed(skinframe_t *skinframe);