From b63f7e558b4b54d89eff2eb3bfd2a015fd77a973 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 2 Oct 2011 22:37:33 +0000 Subject: [PATCH] maint: refactor closing cache files and removing duplicate pointers into their own functions git-svn-id: https://svn.eduke32.com/eduke32@2064 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/polymost.c | 122 +++++++++------------------ 1 file changed, 42 insertions(+), 80 deletions(-) diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index fc3e5c726..82b9fadfa 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -569,6 +569,43 @@ float glox1, gloy1, glox2, gloy2; static int32_t gltexcacnum = -1; extern void freevbos(void); + +static void Cachefile_CloseBoth(void) +{ + if (cachefilehandle != -1) + { + Bclose(cachefilehandle); + cachefilehandle = -1; + } + + if (cacheindexptr) + { + Bfclose(cacheindexptr); + cacheindexptr = NULL; + } +} + +static void Cachefile_RemoveDups(void) +{ + int32_t i; + + for (i = numcacheentries-1; i >= 0; i--) + if (cacheptrs[i]) + { + int32_t ii; + for (ii = numcacheentries-1; ii >= 0; ii--) + if (i != ii && cacheptrs[ii] == cacheptrs[i]) + { + /*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/ + cacheptrs[ii] = NULL; + } + + Bfree(cacheptrs[i]); + cacheptrs[i] = NULL; + } +} + + void polymost_cachesync(void) { if (memcachedata && cachefilehandle != -1 && filelength(cachefilehandle) > memcachesize) @@ -647,34 +684,7 @@ void polymost_glreset() memset(gltexcachead,0,sizeof(gltexcachead)); glox1 = -1; - /* - if (cachefilehandle != -1) - { - Bclose(cachefilehandle); - cachefilehandle = -1; - } - - if (cacheindexptr) - { - Bfclose(cacheindexptr); - cacheindexptr = NULL; - } - */ - - for (i = numcacheentries-1; i >= 0; i--) - if (cacheptrs[i]) - { - int32_t ii; - for (ii = numcacheentries-1; ii >= 0; ii--) - if (i != ii && cacheptrs[ii] == cacheptrs[i]) - { - /*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/ - cacheptrs[ii] = NULL; - } - - Bfree(cacheptrs[i]); - cacheptrs[i] = NULL; - } + Cachefile_RemoveDups(); polymost_cachesync(); #ifdef DEBUGGINGAIDS @@ -737,17 +747,7 @@ void polymost_glinit() bglEnableClientState(GL_VERTEX_ARRAY); bglEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (cachefilehandle != -1) - { - Bclose(cachefilehandle); - cachefilehandle = -1; - } - - if (cacheindexptr) - { - Bfclose(cacheindexptr); - cacheindexptr = NULL; - } + Cachefile_CloseBoth(); if (memcachedata) { @@ -756,20 +756,7 @@ void polymost_glinit() memcachesize = -1; } - for (i = numcacheentries-1; i >= 0; i--) - if (cacheptrs[i]) - { - int32_t ii; - for (ii = numcacheentries-1; ii >= 0; ii--) - if (i != ii && cacheptrs[ii] == cacheptrs[i]) - { - /*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/ - cacheptrs[ii] = NULL; - } - - Bfree(cacheptrs[i]); - cacheptrs[i] = NULL; - } + Cachefile_RemoveDups(); curcacheindex = firstcacheindex = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex)); numcacheentries = 0; @@ -858,8 +845,6 @@ void polymost_glinit() void invalidatecache(void) { - int32_t i; - #ifdef DEBUGGINGAIDS OSD_Printf("invalidatecache()\n"); #endif @@ -867,17 +852,7 @@ void invalidatecache(void) polymost_glreset(); - if (cachefilehandle != -1) - { - Bclose(cachefilehandle); - cachefilehandle = -1; - } - - if (cacheindexptr) - { - Bfclose(cacheindexptr); - cacheindexptr = NULL; - } + Cachefile_CloseBoth(); if (memcachedata) { @@ -886,20 +861,7 @@ void invalidatecache(void) memcachesize = -1; } - for (i = numcacheentries-1; i >= 0; i--) - if (cacheptrs[i]) - { - int32_t ii; - for (ii = numcacheentries-1; ii >= 0; ii--) - if (i != ii && cacheptrs[ii] == cacheptrs[i]) - { - /*OSD_Printf("removing duplicate cacheptr %d\n",ii);*/ - cacheptrs[ii] = NULL; - } - - Bfree(cacheptrs[i]); - cacheptrs[i] = NULL; - } + Cachefile_RemoveDups(); curcacheindex = firstcacheindex = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex)); numcacheentries = 0;