From 47909c014edb68f4ec1695f6f8e81f7df7c6d765 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 18 Feb 2011 17:17:12 +0000 Subject: [PATCH] Added: Support loading flats between F_START...F_END marker lumps in PNG/TGA/PCX format. --- doomsday/engine/portable/include/r_data.h | 10 +-- doomsday/engine/portable/src/gl_texmanager.c | 80 ++++++++++------- doomsday/engine/portable/src/r_data.c | 92 +++++++++++--------- 3 files changed, 105 insertions(+), 77 deletions(-) diff --git a/doomsday/engine/portable/include/r_data.h b/doomsday/engine/portable/include/r_data.h index 362fd401df..54f3c21a36 100644 --- a/doomsday/engine/portable/include/r_data.h +++ b/doomsday/engine/portable/include/r_data.h @@ -138,8 +138,8 @@ typedef struct { } doomtexturedef_t; typedef struct flat_s { - lumpnum_t lump; - short width, height; + lumpname_t name; + boolean isCustom; } flat_t; typedef struct { @@ -241,9 +241,6 @@ extern int levelFullBright; extern float glowingTextures; extern byte precacheSprites, precacheSkins; -extern int numFlats; -extern flat_t** flats; - extern spritetex_t** spriteTextures; extern int numSpriteTextures; @@ -288,6 +285,9 @@ void R_InitSystemTextures(void); void R_InitTextures(void); void R_InitFlats(void); +/// @return Flat associated to index# @a idx +flat_t* R_GetFlatForIdx(int idx); + void R_UpdateData(void); void R_ShutdownData(void); diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c index c00c0d5a7a..5442269b8c 100644 --- a/doomsday/engine/portable/src/gl_texmanager.c +++ b/doomsday/engine/portable/src/gl_texmanager.c @@ -1147,7 +1147,7 @@ byte GL_LoadModelShinySkin(image_t* image, const gltexture_inst_t* inst, void* c if(result == 0) Con_Message("GL_LoadModelShinySkin: Warning, failed to load \"%s\"\n", sn->path); - + return result; } } @@ -1209,7 +1209,7 @@ byte GL_LoadExtTexture(image_t* image, const char* name, gfxmode_t mode) { ddstring_t foundPath; byte result = 0; - + Str_Init(&foundPath); if(F_FindResource2(RC_GRAPHIC, name, &foundPath) != 0 && GL_LoadImage(image, Str_Text(&foundPath))) @@ -1253,17 +1253,16 @@ byte GL_LoadFlat(image_t* image, const gltexture_inst_t* inst, void* context) { assert(image && inst); { - flat_t* flat = flats[inst->tex->ofTypeID]; + flat_t* flat = R_GetFlatForIdx(inst->tex->ofTypeID); + byte result = 0; - // Try to load a high resolution version of this flat? + // Try to load a high resolution replacement for this flat? if(!noHighResTex && (loadExtAlways || highResWithPWAD || GLTexture_IsFromIWAD(inst->tex))) { - const char* lumpName = W_LumpName(flat->lump); ddstring_t searchPath, foundPath, suffix = { "-ck" }; - byte result = 0; // First try the flats namespace then the old-fashioned "flat-name" in the textures namespace?. - Str_Init(&searchPath); Str_Appendf(&searchPath, FLATS_RESOURCE_NAMESPACE_NAME":%s;" TEXTURES_RESOURCE_NAMESPACE_NAME":flat-%s;", lumpName, lumpName); + Str_Init(&searchPath); Str_Appendf(&searchPath, FLATS_RESOURCE_NAMESPACE_NAME":%s;" TEXTURES_RESOURCE_NAMESPACE_NAME":flat-%s;", flat->name, flat->name); Str_Init(&foundPath); if(F_FindResourceStr3(RC_GRAPHIC, &searchPath, &foundPath, &suffix) != 0 && @@ -1280,19 +1279,41 @@ byte GL_LoadFlat(image_t* image, const gltexture_inst_t* inst, void* context) } // None found. Load the original version. - initImage(image); - { size_t lumpLength = W_LumpLength(flat->lump); - image->pixels = M_Malloc(MAX_OF(lumpLength, 4096)); - if(lumpLength < 4096) - memset(image->pixels, 0, 4096); - } - W_ReadLump(flat->lump, image->pixels); + { DFILE* file; + if(NULL != (file = F_OpenLump(flat->name, false))) + { + if(0 != GL_LoadImageDFile(image, file, flat->name)) + { + result = 1; + } + else + { // It must be an old-fashioned DOOM flat. +#define FLAT_WIDTH 64 +#define FLAT_HEIGHT 64 - image->width = flat->width; - image->height = flat->height; - image->pixelSize = 1; + size_t fileLength = F_Length(file); + size_t bufSize = MAX_OF(fileLength, 4096); - return 1; + initImage(image); + image->pixels = malloc(bufSize); + if(fileLength < bufSize) + memset(image->pixels, 0, bufSize); + + // Load the raw image data. + F_Read(image->pixels, fileLength, file); + /// \fixme not all flats are 64x64! + image->width = FLAT_WIDTH; + image->height = FLAT_HEIGHT; + image->pixelSize = 1; + result = 1; + +#undef FLAT_HEIGHT +#undef FLAT_WIDTH + } + F_Close(file); + }} + + return result; } } @@ -2832,14 +2853,14 @@ gltexture_inst_t* GLTexture_Prepare(gltexture_t* tex, void* context, byte* resul if(!monochrome) { - if(tex->type == GLT_SPRITE || tex->type == GLT_MODELSKIN || tex->type == GLT_MODELSHINYSKIN) - { - if(image.pixelSize > 1) + if(tex->type == GLT_SPRITE || tex->type == GLT_MODELSKIN || tex->type == GLT_MODELSHINYSKIN) + { + if(image.pixelSize > 1) + flags |= TXCF_UPLOAD_ARG_RGBDATA; + } + else if(image.pixelSize > 2 && !(tex->type == GLT_SHINY || tex->type == GLT_MASK || tex->type == GLT_LIGHTMAP)) flags |= TXCF_UPLOAD_ARG_RGBDATA; } - else if(tmpResult == 2 && !(tex->type == GLT_SHINY || tex->type == GLT_MASK || tex->type == GLT_LIGHTMAP)) - flags |= TXCF_UPLOAD_ARG_RGBDATA; - } if(tex->type == GLT_DETAIL) { @@ -2855,8 +2876,8 @@ gltexture_inst_t* GLTexture_Prepare(gltexture_t* tex, void* context, byte* resul flags |= TXCF_MIPMAP; if(tex->type == GLT_DOOMTEXTURE || tex->type == GLT_DOOMPATCH || tex->type == GLT_SPRITE || tex->type == GLT_FLAT) - alphaChannel = ((tmpResult == 2 && image.pixelSize == 4) || - (tmpResult == 1 && (image.flags & IMGF_IS_MASKED))); + alphaChannel = ((/*tmpResult == 2 &&*/ image.pixelSize == 4) || + (/*tmpResult == 1 &&*/ image.pixelSize == 1 && (image.flags & IMGF_IS_MASKED))); else alphaChannel = image.pixelSize != 3 && !(tex->type == GLT_MASK || tex->type == GLT_SHINY); @@ -3051,7 +3072,7 @@ boolean GLTexture_IsFromIWAD(const gltexture_t* tex) switch(tex->type) { case GLT_FLAT: - return W_LumpFromIWAD(flats[tex->ofTypeID]->lump); + return R_GetFlatForIdx(tex->ofTypeID)->isCustom; case GLT_DOOMTEXTURE: return (R_GetDoomTextureDef(tex->ofTypeID)->flags & TXDF_IWAD)? true : false; @@ -3094,7 +3115,7 @@ float GLTexture_GetWidth(const gltexture_t* tex) switch(tex->type) { case GLT_FLAT: - return flats[tex->ofTypeID]->width; + return 64; /// \fixme not all flats are 64x64 case GLT_DOOMTEXTURE: return R_GetDoomTextureDef(tex->ofTypeID)->width; @@ -3137,7 +3158,7 @@ float GLTexture_GetHeight(const gltexture_t* tex) switch(tex->type) { case GLT_FLAT: - return flats[tex->ofTypeID]->height; + return 64; /// \fixme not all flats are 64x64 case GLT_DOOMTEXTURE: return R_GetDoomTextureDef(tex->ofTypeID)->height; @@ -3301,4 +3322,3 @@ D_CMD(MipMap) GL_UpdateTexParams(strtol(argv[1], NULL, 0)); return true; } - diff --git a/doomsday/engine/portable/src/r_data.c b/doomsday/engine/portable/src/r_data.c index b4b05e5a6b..b47679b094 100644 --- a/doomsday/engine/portable/src/r_data.c +++ b/doomsday/engine/portable/src/r_data.c @@ -95,9 +95,6 @@ extern boolean mapSetup; // We are currently setting up a map. byte precacheSkins = true; byte precacheSprites = true; -int numFlats = 0; -flat_t** flats = NULL; - int numSpriteTextures = 0; spritetex_t** spriteTextures = NULL; @@ -134,6 +131,9 @@ skinname_t* skinNames = NULL; // PRIVATE DATA DEFINITIONS ------------------------------------------------ +static int numFlats = 0; +static flat_t** flats = NULL; + static int numDoomTextureDefs; static doomtexturedef_t** doomTextureDefs; @@ -1734,44 +1734,47 @@ doomtexturedef_t* R_GetDoomTextureDef(int num) return doomTextureDefs[num]; } -/** - * Returns the new flat index. - */ -static int R_NewFlat(lumpnum_t lump) +flat_t* R_GetFlatForIdx(int idx) { - int i; - flat_t** newlist, *ptr; + assert(idx >= 0 && idx < numFlats); + return flats[idx]; +} - for(i = 0; i < numFlats; ++i) +int R_FindFlatIdxForName(const lumpname_t name) +{ + if(name && name[0]) { - ptr = flats[i]; - - // Is this lump already entered? - if(ptr->lump == lump) - return i; - - // Is this a known identifer? Newer idents overide old. - if(!strnicmp(W_LumpName(ptr->lump), W_LumpName(lump), 8)) + int i; + for(i = 0; i < numFlats; ++i) { - ptr->lump = lump; - return i; + if(!stricmp(flats[i]->name, name)) + return i; } } + return -1; +} + +/// @return Associated flat index. +static int R_NewFlat(const lumpname_t name, boolean isCustom) +{ + assert(name && name[0]); - newlist = Z_Malloc(sizeof(flat_t*) * ++numFlats, PU_REFRESHTEX, 0); - if(numFlats > 1) + // Is this a known identifer? + { int idx; + if(-1 != (idx = R_FindFlatIdxForName(name))) { - for(i = 0; i < numFlats -1; ++i) - newlist[i] = flats[i]; + // Update metadata for the new flat. + flats[idx]->isCustom = isCustom; + return idx; + }} - Z_Free(flats); + // A new flat. + flats = Z_Realloc(flats, sizeof(flat_t*) * ++numFlats, PU_REFRESHTEX); + { flat_t* flat = flats[numFlats - 1] = Z_Malloc(sizeof(*flat), PU_REFRESHTEX, 0); + memset(flat->name, 0, sizeof(flat->name)); + strncpy(flat->name, name, sizeof(flat->name)-1); + flat->isCustom = isCustom; } - flats = newlist; - ptr = flats[numFlats - 1] = Z_Calloc(sizeof(flat_t), PU_REFRESHTEX, 0); - ptr->lump = lump; - ptr->width = 64; /// \fixme not all flats are 64 texels in width! - ptr->height = 64; /// \fixme not all flats are 64 texels in height! - return numFlats - 1; } @@ -1780,12 +1783,12 @@ void R_InitFlats(void) uint startTime = (verbose >= 2? Sys_GetRealTime() : 0); ddstack_t* stack = Stack_New(); ddstring_t path; - int i; - VERBOSE( Con_Message("Initializing Flats ...\n") ); - numFlats = 0; + assert(numFlats == 0); - for(i = 0; i < W_NumLumps(); ++i) + VERBOSE( Con_Message("Initializing Flats ...\n") ); + { int i, numLumps = W_NumLumps(); + for(i = 0; i < numLumps; ++i) { const char* name = W_LumpName(i); @@ -1810,30 +1813,31 @@ void R_InitFlats(void) if(!Stack_Height(stack)) continue; - R_NewFlat(i); - } + R_NewFlat(name, !W_LumpFromIWAD(i)); + }} while(Stack_Height(stack)) Stack_Pop(stack); Stack_Delete(stack); Str_Init(&path); + { int i; for(i = 0; i < numFlats; ++i) { - const flat_t* flat = flats[i]; - const gltexture_t* tex = GL_CreateGLTexture(W_LumpName(flat->lump), i, GLT_FLAT); + flat_t* flat = flats[i]; + const gltexture_t* tex = GL_CreateGLTexture(flat->name, i, GLT_FLAT); dduri_t* uri; // Create a material for this flat. // \note that width = 64, height = 64 regardless of the flat dimensions. Str_Clear(&path); - Str_Appendf(&path, MATERIALS_FLATS_RESOURCE_NAMESPACE_NAME":%s", W_LumpName(flat->lump)); + Str_Appendf(&path, MATERIALS_FLATS_RESOURCE_NAMESPACE_NAME":%s", flat->name); uri = Uri_Construct2(Str_Text(&path), RC_NULL); Materials_New(uri, 64, 64, 0, tex->id, 0, 0); Uri_Destruct(uri); - } + }} Str_Free(&path); VERBOSE2( Con_Message("R_InitFlats: Done in %.2f seconds.\n", (Sys_GetRealTime() - startTime) / 1000.0f) ); @@ -1955,13 +1959,17 @@ uint R_GetSkinNumForName(const char* path) void R_DestroySkins(void) { M_Free(skinNames); - skinNames = 0; + skinNames = NULL; numSkinNames = 0; } void R_UpdateTexturesAndFlats(void) { Z_FreeTags(PU_REFRESHTEX, PU_REFRESHTEX); + flats = NULL; + numFlats = 0; + doomTextureDefs = NULL; + numDoomTextureDefs = 0; } void R_UpdateData(void)