Skip to content

Commit

Permalink
Fixed: Material definitions referencing sprite patches not working. S…
Browse files Browse the repository at this point in the history
…ymptom - Bug #2673525 "wad midspace texture name does not work" (see http://sourceforge.net/tracker2/?func=detail&aid=2673525&group_id=74815&atid=542099).

In fixing the above I have re-implemented the way in which sprite patch records are generated. This process is no longer dependent upon Sprite (name) definitions, instead we now construct the spritedef_t databases directly from the lumps. However, as the games still depend upon an unobvious correlation between the prite name indices and the relevant spritedef_t indices, there is currently a kludge in R_InitSprites which re-indexes them as expected, using the existing Sprite (name) definitions indices.

A quick trawl over our codebase confirms to me that there are very few places remaining where the sprite name indice:spritedef_t indice assumption remains. The main instance being the sprite replacement in dpDehRead. As Doomsday itself no longer depends upon the Sprite (name) definitions; potentially they can be removed from the public shared data too (once the new DED reader/management is in place, solving the dpDehRead issue should be trivial).
  • Loading branch information
danij committed Mar 9, 2009
1 parent 73b170c commit fa52da1
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 166 deletions.
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -295,8 +295,6 @@ void R_PrecachePatch(lumpnum_t lump);

doomtexturedef_t* R_GetDoomTextureDef(int num);

int R_NewSpriteTexture(lumpnum_t lump, material_t** mat);

int R_GetSkinTexIndex(const char* skin);
skintex_t* R_GetSkinTexByIndex(int id);
int R_RegisterSkin(char* skin, const char* modelfn, char* fullpath);
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/portable/include/r_things.h
Expand Up @@ -50,6 +50,7 @@ typedef struct {
} spriteframe_t;

typedef struct {
char name[5];
int numFrames;
spriteframe_t* spriteFrames;
} spritedef_t;
Expand Down Expand Up @@ -202,7 +203,10 @@ vissprite_t* R_NewVisSprite(void);
void R_AddSprites(subsector_t* ssec);
void R_AddPSprites(void);
void R_DrawSprites(void);

void R_PreInitSprites(void);
void R_InitSprites(void);

void R_ClearSprites(void);
void R_ClipVisSprite(vissprite_t* vis, int xl, int xh);

Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -591,6 +591,7 @@ static int DD_StartupWorker(void *parm)
P_InitMaterialManager();
R_InitTextures();
R_InitFlats();
R_PreInitSprites();

// Now that we've generated the auto-materials we can initialize
// definitions.
Expand Down
52 changes: 0 additions & 52 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -1526,58 +1526,6 @@ void R_InitFlats(void)
Sys_GetSeconds() - starttime));
}

/**
* @return The new sprite index number.
*/
int R_NewSpriteTexture(lumpnum_t lump, material_t** matP)
{
int i;
spritetex_t** newList, *ptr;
material_t* mat = NULL;
const gltexture_t* tex;
lumppatch_t* patch;

// Is this lump already entered?
for(i = 0; i < numSpriteTextures; ++i)
if(spriteTextures[i]->lump == lump)
{
if(matP)
*matP = P_GetMaterial(i, MN_SPRITES);
return i;
}

newList = Z_Malloc(sizeof(spritetex_t*) * ++numSpriteTextures, PU_SPRITE, 0);
if(numSpriteTextures > 1)
{
for(i = 0; i < numSpriteTextures -1; ++i)
newList[i] = spriteTextures[i];

Z_Free(spriteTextures);
}

spriteTextures = newList;
ptr = spriteTextures[numSpriteTextures - 1] =
Z_Calloc(sizeof(spritetex_t), PU_SPRITE, 0);
ptr->lump = lump;
patch = (lumppatch_t *) W_CacheLumpNum(lump, PU_CACHE);
ptr->offX = SHORT(patch->leftOffset);
ptr->offY = SHORT(patch->topOffset);
ptr->width = SHORT(patch->width);
ptr->height = SHORT(patch->height);

tex = GL_CreateGLTexture(W_LumpName(lump), numSpriteTextures - 1,
GLT_SPRITE);

// Create a new material for this sprite texture.
mat = P_MaterialCreate(W_LumpName(lump), SHORT(patch->width),
SHORT(patch->height), 0, tex->id, MN_SPRITES, NULL);

if(matP)
*matP = mat;

return numSpriteTextures - 1;
}

void R_ExpandSkinName(char *skin, char *expanded, const char *modelfn)
{
directory_t mydir;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/r_main.c
Expand Up @@ -247,7 +247,7 @@ void R_Init(void)
R_InitData();
// viewwidth / viewheight / detailLevel are set by the defaults
R_SetViewWindow(0, 0, 320, 200);
R_InitSprites();
R_InitSprites(); // Fully initialize sprites.
R_InitModels();
R_InitTranslationTables();
Rend_Init();
Expand All @@ -267,6 +267,7 @@ void R_Update(void)
R_UpdateTexturesAndFlats();
R_InitTextures();
R_InitFlats();
R_PreInitSprites();

// Re-read definitions.
Def_Read();
Expand Down

0 comments on commit fa52da1

Please sign in to comment.