]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Add R_SelectScene and R_GetScenePointer that encapsulate access to an array of r_refd...
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Jan 2008 02:18:54 +0000 (02:18 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Jan 2008 02:18:54 +0000 (02:18 +0000)
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

gl_rmain.c
menu.c
mvm_cmds.c
render.h

index d17ff7155189330500e22ecb03ba6f66180f4eb2..5057febfdebc9f0da7fe6d4c0b9b9fcdd572befb 100644 (file)
@@ -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 a4a3086bb8dcad5556034b11ecd6c3a9b9ddd614..c0e71be0eba11627dfb24a1438c2a572e6a56cb8 100644 (file)
--- 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)
index 681ebb8c40206f84f1653fd5cdd76b26afdcc18b..5d142ac8a0710c46e34b31ac56dec2a5d89e3a73 100644 (file)
@@ -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();
index af999c388ae42efb38401ef6e14d766607a1d72e..b30dd7d8cff63c392af9abfc8c06e6cc1cb39deb 100644 (file)
--- 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);