Skip to content

Commit

Permalink
Refactor: Allow clearing flats independently from patch-composite tex…
Browse files Browse the repository at this point in the history
…tures.
  • Loading branch information
danij-deng committed Aug 5, 2011
1 parent 4e76adf commit 5c637c7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/dd_zone.h
Expand Up @@ -34,7 +34,8 @@
*/
//#define FAKE_MEMORY_ZONE 1

#define PU_REFRESHTEX 11 // Textures and Flats
#define PU_REFRESHFLAT 10 // Flats
#define PU_REFRESHTEX 11 // Textures
//#define PU_REFRESHCM 12 // Colormap.
#define PU_REFRESHTRANS 13
//#define PU_REFRESHSPR 14
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -277,8 +277,6 @@ void R_DivTexCoords(rtexcoord_t* dst, const rtexcoord_t* src,
const walldiv_t* divs, float bL, float tL,
float bR, float tR);

void R_UpdatePatchCompositesAndFlats(void);

void R_InitTranslationTables(void);
void R_UpdateTranslationTables(void);

Expand Down
64 changes: 39 additions & 25 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -1322,6 +1322,22 @@ void R_UpdateRawTexs(void)
R_InitRawTexs();
}

static void clearPatchComposites(void)
{
int i;

if(patchCompositeTexturesCount == 0) return;

for(i = 0; i < patchCompositeTexturesCount; ++i)
{
patchcompositetex_t* pcomTex = patchCompositeTextures[i];
Str_Free(&pcomTex->name);
}
Z_FreeTags(PU_REFRESHTEX, PU_REFRESHTEX);
patchCompositeTextures = NULL;
patchCompositeTexturesCount = 0;
}

static patchname_t* loadPatchNames(lumpnum_t lumpNum, int* num)
{
size_t lumpSize = W_LumpLength(lumpNum);
Expand Down Expand Up @@ -1910,11 +1926,9 @@ void R_InitPatchComposites(void)
{
uint startTime = (verbose >= 2? Sys_GetRealTime() : 0);

clearPatchComposites();
VERBOSE( Con_Message("Initializing PatchComposites...\n") )

patchCompositeTexturesCount = 0;
patchCompositeTextures = NULL;

// Load texture definitions from TEXTURE1/2 lumps.
loadPatchCompositeDefs();
createTexturesForPatchCompositeDefs();
Expand Down Expand Up @@ -1982,8 +1996,8 @@ static int R_NewFlat(const char* name, lumpnum_t lumpNum, boolean isCustom)
}}

// A new flat.
flatTextures = Z_Realloc(flatTextures, sizeof(flat_t*) * ++flatTexturesCount, PU_REFRESHTEX);
{ flat_t* flat = flatTextures[flatTexturesCount - 1] = Z_Malloc(sizeof(*flat), PU_REFRESHTEX, 0);
flatTextures = Z_Realloc(flatTextures, sizeof(flat_t*) * ++flatTexturesCount, PU_REFRESHFLAT);
{ flat_t* flat = flatTextures[flatTexturesCount - 1] = Z_Malloc(sizeof(*flat), PU_REFRESHFLAT, 0);
Str_Init(&flat->name);
Str_Set(&flat->name, name);
flat->lumpNum = lumpNum;
Expand All @@ -1993,11 +2007,31 @@ static int R_NewFlat(const char* name, lumpnum_t lumpNum, boolean isCustom)
return flatTexturesCount - 1;
}

/**
* Free all memory acquired for Flat textures.
* \note Does nothing about any Textures or Materials created from these!
*/
static void clearFlatTextures(void)
{
int i;
if(0 == flatTexturesCount) return;

for(i = 0; i < flatTexturesCount; ++i)
{
flat_t* flat = flatTextures[i];
Str_Free(&flat->name);
}
Z_FreeTags(PU_REFRESHFLAT, PU_REFRESHFLAT);
flatTextures = NULL;
flatTexturesCount = 0;
}

void R_InitFlatTextures(void)
{
uint startTime = (verbose >= 2? Sys_GetRealTime() : 0);
ddstack_t* stack = Stack_New();

clearFlatTextures();
assert(flatTexturesCount == 0);

VERBOSE( Con_Message("Initializing Flats...\n") )
Expand Down Expand Up @@ -2350,26 +2384,6 @@ void R_ReleaseGLTexturesForSkins(void)
}
}

void R_UpdatePatchCompositesAndFlats(void)
{
int i;
for(i = 0; i < flatTexturesCount; ++i)
{
flat_t* flat = flatTextures[i];
Str_Free(&flat->name);
}
for(i = 0; i < patchCompositeTexturesCount; ++i)
{
patchcompositetex_t* pcomTex = patchCompositeTextures[i];
Str_Free(&pcomTex->name);
}
Z_FreeTags(PU_REFRESHTEX, PU_REFRESHTEX);
flatTextures = NULL;
flatTexturesCount = 0;
patchCompositeTextures = NULL;
patchCompositeTexturesCount = 0;
}

void R_UpdateData(void)
{
R_UpdateRawTexs();
Expand Down
1 change: 0 additions & 1 deletion doomsday/engine/portable/src/r_main.c
Expand Up @@ -441,7 +441,6 @@ void R_Init(void)
*/
void R_Update(void)
{
R_UpdatePatchCompositesAndFlats();
R_InitPatchComposites();
R_InitFlatTextures();
R_InitSpriteTextures();
Expand Down

0 comments on commit 5c637c7

Please sign in to comment.