Skip to content

Commit

Permalink
Fixed: R_PrecacheMap was in charge of initializing the decorated and …
Browse files Browse the repository at this point in the history
…glowing surface lists. Consequently they would not be built if playing back a demo.

Minor cleanup.
  • Loading branch information
danij-deng committed Apr 8, 2011
1 parent 94341fc commit 553649e
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 81 deletions.
6 changes: 6 additions & 0 deletions doomsday/engine/portable/include/material.h
Expand Up @@ -97,6 +97,12 @@ boolean Material_IsSkyMasked(const material_t* mat);
/// @return @c true if Material should be rendered.
boolean Material_IsDrawable(const material_t* mat);

/// @return @c true if one or more animation stages are defined as "glowing".
boolean Material_HasGlow(material_t* mat);

/// @return @c true if one or more light decorations are defined.
boolean Material_HasDecorations(material_t* mat);

/// @return Number of layers defined by this Material.
int Material_LayerCount(const material_t* mat);

Expand Down
13 changes: 4 additions & 9 deletions doomsday/engine/portable/include/materialvariant.h
Expand Up @@ -84,19 +84,14 @@ typedef struct material_textureunit_s {
} material_textureunit_t;

typedef struct material_snapshot_s {
int width, height; // In world units.
boolean isOpaque;
boolean isDecorated;
material_textureunit_t units[NUM_MATERIAL_TEXTURE_UNITS];
int width, height; /// Material dimensions in world units.
float color[3]; /// Average color (for lighting).
float colorAmplified[3]; /// Average color amplified (for lighting).
float topColor[3]; /// Average top line color (for sky fadeout).
float shinyMinColor[3];
float glowing;
material_textureunit_t units[NUM_MATERIAL_TEXTURE_UNITS];

/// \todo: the following should be removed once incorporated into the layers (above).
struct shinydata_s {
float minColor[3];
} shiny;
boolean isOpaque;
} material_snapshot_t;

#define MSU(ms, u) ((ms)->units[u])
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -407,9 +407,9 @@ boolean R_UpdatePlane(struct plane_s* pln, boolean forceUpdate);
boolean R_UpdateSurface(struct surface_s* suf, boolean forceUpdate);

/**
* Prepare all texture resources for the current Map.
* Prepare resources for the current Map.
*/
void R_PrecacheMap(void);
void R_PrecacheForMap(void);

/**
* Prepare all texture resources for the specified mobjtype.
Expand Down
20 changes: 20 additions & 0 deletions doomsday/engine/portable/src/material.c
Expand Up @@ -121,6 +121,26 @@ boolean Material_IsDrawable(const material_t* mat)
return 0 == (mat->_flags & MATF_NO_DRAW);
}

boolean Material_HasGlow(material_t* mat)
{
assert(mat);
{
material_snapshot_t ms;
/// \fixme We should not need to prepare to determine this.
Materials_Prepare(&ms, mat, true,
Materials_VariantSpecificationForContext(MC_MAPSURFACE, 0, 0, 0, 0,
GL_REPEAT, GL_REPEAT, -1, true, true, false, false));
return (ms.glowing > .0001f);
}
}

boolean Material_HasDecorations(material_t* mat)
{
assert(mat);
/// \fixme We should not need to prepare to determine this.
return NULL != Materials_Decoration(Materials_ToMaterialNum(mat));
}

int Material_LayerCount(const material_t* mat)
{
assert(mat);
Expand Down
56 changes: 32 additions & 24 deletions doomsday/engine/portable/src/p_materialmanager.c
Expand Up @@ -1173,30 +1173,42 @@ static void setTexUnit(material_snapshot_t* ss, byte unit, const texturevariant_
blendmode_t blendMode, int magMode, float sScale, float tScale, float sOffset,
float tOffset, float alpha)
{
material_textureunit_t* mtp = &ss->units[unit];
assert(ss);
{
material_textureunit_t* tu = &MSU(ss, unit);

if(NULL != tex)
{
mtp->tex.texture = TextureVariant_GeneralCase(tex);
mtp->tex.spec = TextureVariant_Spec(tex);
mtp->tex.glName = TextureVariant_GLName(tex);
TextureVariant_Coords(tex, &mtp->tex.s, &mtp->tex.t);
tu->tex.texture = TextureVariant_GeneralCase(tex);
tu->tex.spec = TextureVariant_Spec(tex);
tu->tex.glName = TextureVariant_GLName(tex);
TextureVariant_Coords(tex, &tu->tex.s, &tu->tex.t);
}
else
{
mtp->tex.texture = NULL;
mtp->tex.spec = NULL;
mtp->tex.glName = 0;
mtp->tex.s = mtp->tex.t = 0;
tu->tex.texture = NULL;
tu->tex.spec = NULL;
tu->tex.glName = 0;
tu->tex.s = tu->tex.t = 0;
}

mtp->magMode = magMode;
mtp->blendMode = blendMode;
mtp->alpha = MINMAX_OF(0, alpha, 1);
mtp->scale[0] = sScale;
mtp->scale[1] = tScale;
mtp->offset[0] = sOffset;
mtp->offset[1] = tOffset;
tu->magMode = magMode;
tu->blendMode = blendMode;
tu->alpha = MINMAX_OF(0, alpha, 1);
tu->scale[0] = sScale;
tu->scale[1] = tScale;
tu->offset[0] = sOffset;
tu->offset[1] = tOffset;
}
}

void Materials_InitSnapshot(material_snapshot_t* ss)
{
assert(ss);
{ int i;
for(i = 0; i < MATERIALVARIANT_MAXLAYERS; ++i)
setTexUnit(ss, i, NULL, BM_NORMAL, GL_LINEAR, 1, 1, 0, 0, 0);
}
}

void Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,
Expand All @@ -1212,7 +1224,6 @@ void Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,
const ded_decor_t* decor = NULL;
materialvariant_t* variant;
materialbind_t* mb;
uint i;

// Have we already registered a suitable variant?
variant = Materials_ChooseVariant(mat, spec);
Expand Down Expand Up @@ -1334,14 +1345,11 @@ void Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,
* Take a snapshot:
*/

// Reset to the default state.
for(i = 0; i < MATERIALVARIANT_MAXLAYERS; ++i)
setTexUnit(snapshot, i, 0, BM_NORMAL, GL_LINEAR, 1, 1, 0, 0, 0);
Materials_InitSnapshot(snapshot);

snapshot->width = Material_Width(mat);
snapshot->height = Material_Height(mat);
snapshot->glowing = MaterialVariant_Layer(variant, 0)->glow * glowingTextures;
snapshot->isDecorated = (decor? true : false);

// Setup the primary texturing pass.
if(0 != MaterialVariant_Layer(variant, 0)->tex)
Expand Down Expand Up @@ -1420,9 +1428,9 @@ void Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,
// Setup the reflection (aka shiny) texturing pass(es)?
if(shinyTex && reflection)
{
snapshot->shiny.minColor[CR] = reflection->minColor[CR];
snapshot->shiny.minColor[CG] = reflection->minColor[CG];
snapshot->shiny.minColor[CB] = reflection->minColor[CB];
snapshot->shinyMinColor[CR] = reflection->minColor[CR];
snapshot->shinyMinColor[CG] = reflection->minColor[CG];
snapshot->shinyMinColor[CB] = reflection->minColor[CB];

setTexUnit(snapshot, MTU_REFLECTION, shinyTex, reflection->blendMode, GL_LINEAR,
1, 1, 0, 0, reflection->shininess);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/p_surface.c
Expand Up @@ -95,7 +95,7 @@ boolean Surface_SetMaterial(surface_t* suf, material_t* mat)
{
if(!ddMapSetup)
{
// If this plane's surface is in the deocrated list, remove it.
// If this plane's surface is in the decorated list, remove it.
R_SurfaceListRemove(decoratedSurfaceList, suf);
// If this plane's surface is in the glowing list, remove it.
R_SurfaceListRemove(glowingSurfaceList, suf);
Expand Down
34 changes: 3 additions & 31 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -2373,25 +2373,7 @@ void R_PrecacheMobjNum(int num)
}}
}

static void addToSurfaceLists(surface_t* suf, material_t* mat)
{
assert(suf);
{
material_snapshot_t ms;
if(NULL == mat)
return;
/// \fixme We should not need to prepare in order to build the lists.
Materials_Prepare(&ms, mat, true,
Materials_VariantSpecificationForContext(MC_MAPSURFACE, 0, 0, 0, 0,
GL_REPEAT, GL_REPEAT, -1, true, true, false, false));
if(ms.glowing > 0)
R_SurfaceListAdd(glowingSurfaceList, suf);
if(ms.isDecorated)
R_SurfaceListAdd(decoratedSurfaceList, suf);
}
}

void R_PrecacheMap(void)
void R_PrecacheForMap(void)
{
materialvariantspecification_t* spec;
float startTime;
Expand All @@ -2413,36 +2395,26 @@ void R_PrecacheMap(void)
sidedef_t* side = SIDE_PTR(i);

if(NULL != side->SW_middlematerial)
{
Materials_Precache(side->SW_middlematerial, spec);
addToSurfaceLists(&side->SW_middlesurface, side->SW_middlematerial);
}

if(NULL != side->SW_topmaterial)
{
Materials_Precache(side->SW_topmaterial, spec);
addToSurfaceLists(&side->SW_topsurface, side->SW_topmaterial);
}

if(NULL != side->SW_bottommaterial)
{
Materials_Precache(side->SW_bottommaterial, spec);
addToSurfaceLists(&side->SW_bottomsurface, side->SW_bottommaterial);
}
}}

{ uint i;
for(i = 0; i < numSectors; ++i)
{
sector_t* sec = SECTOR_PTR(i);
uint j;
if(0 == sec->lineDefCount)
continue;
{ uint j;
for(j = 0; j < sec->planeCount; ++j)
{
Materials_Precache(sec->SP_planematerial(j), spec);
addToSurfaceLists(&sec->SP_planesurface(j), sec->SP_planematerial(j));
}
}}
}}

// Precache sprites?
Expand Down
51 changes: 43 additions & 8 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -1242,11 +1242,9 @@ static sector_t *getContainingSectorOf(gamemap_t* map, sector_t* sec)
}
#endif

static __inline void initSurfaceMaterialOffset(surface_t *suf)
static __inline void initSurfaceMaterialOffset(surface_t* suf)
{
if(!suf)
return;

assert(suf);
suf->visOffset[VX] = suf->oldOffset[0][VX] =
suf->oldOffset[1][VX] = suf->offset[VX];
suf->visOffset[VY] = suf->oldOffset[0][VY] =
Expand All @@ -1257,7 +1255,7 @@ static __inline void initSurfaceMaterialOffset(surface_t *suf)
* Set intial values of various tracked and interpolated properties
* (lighting, smoothed planes etc).
*/
void R_InitMapSurfaces(boolean forceUpdate)
void R_MapInitSurfaces(boolean forceUpdate)
{
{ uint i;
for(i = 0; i < numSectors; ++i)
Expand Down Expand Up @@ -1286,6 +1284,41 @@ void R_InitMapSurfaces(boolean forceUpdate)
}}
}

static void addToSurfaceLists(surface_t* suf, material_t* mat)
{
if(NULL == suf || NULL == mat)
return;

if(Material_HasGlow(mat)) R_SurfaceListAdd(glowingSurfaceList, suf);
if(Material_HasDecorations(mat)) R_SurfaceListAdd(decoratedSurfaceList, suf);
}

void R_MapInitSurfaceLists(void)
{
{ uint i;
for(i = 0; i < numSideDefs; ++i)
{
sidedef_t* side = SIDE_PTR(i);

addToSurfaceLists(&side->SW_middlesurface, side->SW_middlematerial);
addToSurfaceLists(&side->SW_topsurface, side->SW_topmaterial);
addToSurfaceLists(&side->SW_bottomsurface, side->SW_bottommaterial);
}}

{ uint i;
for(i = 0; i < numSectors; ++i)
{
sector_t* sec = SECTOR_PTR(i);
if(0 == sec->lineDefCount)
continue;

{ uint j;
for(j = 0; j < sec->planeCount; ++j)
addToSurfaceLists(&sec->SP_planesurface(j), sec->SP_planematerial(j));
}
}}
}

void R_SetupMap(int mode, int flags)
{
switch(mode)
Expand All @@ -1305,7 +1338,7 @@ void R_SetupMap(int mode, int flags)
// Update everything again. Its possible that after loading we
// now have more HOMs to fix, etc..
R_InitSkyFix();
R_InitMapSurfaces(false);
R_MapInitSurfaces(false);
P_MapInitPolyobjs();
return;
}
Expand All @@ -1321,9 +1354,11 @@ void R_SetupMap(int mode, int flags)
// Recalculate the light range mod matrix.
Rend_CalcLightModRange(NULL);

R_InitMapSurfaces(true);
P_MapInitPolyobjs();
R_PrecacheMap();

R_MapInitSurfaces(true);
R_MapInitSurfaceLists();
R_PrecacheForMap();

Materials_ProcessCacheQueue();

Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/rend_main.c
Expand Up @@ -1618,9 +1618,9 @@ static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices,
// Strength of the shine.
for(i = 0; i < numVertices; ++i)
{
shinyColors[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], msA->shiny.minColor[CR]);
shinyColors[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], msA->shiny.minColor[CG]);
shinyColors[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], msA->shiny.minColor[CB]);
shinyColors[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], msA->shinyMinColor[CR]);
shinyColors[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], msA->shinyMinColor[CG]);
shinyColors[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], msA->shinyMinColor[CB]);
shinyColors[i].rgba[CA] = rTUs[TU_PRIMARY].blend;
}
}
Expand Down Expand Up @@ -2936,9 +2936,9 @@ void lightGeometry(rendpolytype_t type, size_t count, rvertex_t* rvertices, rcol
size_t i;
for(i = 0; i < count; ++i)
{
rcolorsShiny[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], msA->shiny.minColor[CR]);
rcolorsShiny[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], msA->shiny.minColor[CG]);
rcolorsShiny[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], msA->shiny.minColor[CB]);
rcolorsShiny[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], msA->shinyMinColor[CR]);
rcolorsShiny[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], msA->shinyMinColor[CG]);
rcolorsShiny[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], msA->shinyMinColor[CB]);
rcolorsShiny[i].rgba[CA] = rTUs[TU_PRIMARY].blend;
}
}
Expand Down

0 comments on commit 553649e

Please sign in to comment.