From 320a3b0834bd05e77e4f659630b952d811779ea6 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 7 Apr 2019 22:10:41 +0700 Subject: [PATCH] ref_soft: Fix cache flush on reconnect, fix division by zero in decals --- r_local.h | 3 ++- r_main.c | 6 +++--- r_misc.c | 2 +- r_surf.c | 12 ++++++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/r_local.h b/r_local.h index 485a0a04..346bcce2 100644 --- a/r_local.h +++ b/r_local.h @@ -293,6 +293,7 @@ typedef struct vec3_t modelorg; // relative to viewpoint qboolean fCustomSkybox; + char mapname[MAX_STRING]; } gl_globals_t; typedef struct @@ -1247,7 +1248,7 @@ void R_ScanEdges (void); // // r_surf.c // -void D_FlushCaches( qboolean newmap ); +void D_FlushCaches( void ); // // r_draw.c diff --git a/r_main.c b/r_main.c index 7601f76f..a37797e7 100644 --- a/r_main.c +++ b/r_main.c @@ -1671,7 +1671,7 @@ void R_BeginFrame( qboolean clearScene ) // glConfig.softwareGammaUpdate = true; // GL_RebuildLightmaps(); // glConfig.softwareGammaUpdate = false; - D_FlushCaches( false ); + D_FlushCaches( ); // next frame will be restored gamma SetBits( vid_brightness->flags, FCVAR_CHANGED ); @@ -1682,7 +1682,7 @@ void R_BeginFrame( qboolean clearScene ) gEngfuncs.BuildGammaTable( vid_gamma->value, vid_brightness->value ); //glConfig.softwareGammaUpdate = true; // GL_RebuildLightmaps(); - D_FlushCaches( false ); + D_FlushCaches( ); //glConfig.softwareGammaUpdate = false; // next frame will be restored gamma ClearBits( vid_brightness->flags, FCVAR_CHANGED ); @@ -1833,7 +1833,7 @@ void R_NewMap (void) R_ClearDecals(); // clear all level decals R_StudioResetPlayerModels(); - D_FlushCaches( true ); + D_FlushCaches(); r_cnumsurfs = sw_maxsurfs->value; diff --git a/r_misc.c b/r_misc.c index 7bbb66e2..7d02bb48 100644 --- a/r_misc.c +++ b/r_misc.c @@ -318,7 +318,7 @@ void R_SetupFrameQ (void) if (r_fullbright->flags & FCVAR_CHANGED) { r_fullbright->flags &= ~FCVAR_CHANGED; - D_FlushCaches( false ); // so all lighting changes + D_FlushCaches( ); // so all lighting changes } //tr.framecount++; diff --git a/r_surf.c b/r_surf.c index 40f5c13a..9a18a81e 100644 --- a/r_surf.c +++ b/r_surf.c @@ -806,7 +806,7 @@ void R_InitCaches (void) sc_size = size; if( sc_base ) { - D_FlushCaches( false ); + D_FlushCaches( ); Mem_Free( sc_base ); } sc_base = (surfcache_t *)Mem_Calloc(r_temppool,size); @@ -823,10 +823,12 @@ void R_InitCaches (void) D_FlushCaches ================== */ -void D_FlushCaches( qboolean newmap ) +void D_FlushCaches( void ) { surfcache_t *c; - + model_t *world = WORLDMODEL; + qboolean newmap = !world || !Q_strcmp( tr.mapname, WORLDMODEL->name ); + // if newmap, surfaces already freed if( !newmap ) { @@ -836,6 +838,8 @@ void D_FlushCaches( qboolean newmap ) *c->owner = NULL; } } + else + Q_strncpy( tr.mapname, WORLDMODEL->name, MAX_STRING ); sc_rover = sc_base; sc_base->next = NULL; @@ -1040,7 +1044,7 @@ void R_DrawSurfaceDecals() if( t2 > tex->height ) t2 = tex->height; - if( !tex->pixels[0] || s1 >= s2 || t1 >= t2 ) + if( !tex->pixels[0] || s1 >= s2 || t1 >= t2 || !w ) continue; if( tex->alpha_pixels )