Skip to content

Commit

Permalink
Refactor|Surface: Surface can manage the missing-material-fix state i…
Browse files Browse the repository at this point in the history
…nternally
  • Loading branch information
danij-deng committed Mar 15, 2013
1 parent f33f916 commit db8b252
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
22 changes: 15 additions & 7 deletions doomsday/client/include/map/surface.h
Expand Up @@ -102,9 +102,6 @@ class Surface : public de::MapElement
/// @ref surfaceInternalFlags
short inFlags;

/// Old @ref surfaceInternalFlags, for tracking changes.
short _oldInFlags;

uint numDecorations;

struct surfacedecorsource_s *decorations;
Expand Down Expand Up @@ -141,17 +138,27 @@ class Surface : public de::MapElement
*/
bool hasMaterial() const;

/**
* Returns @c true iff a @em fix material is bound to the surface, which
* was chosen automatically where one was missing. Clients should not be
* notified when a fix material is bound to the surface (as they should
* perform their fixing, locally). However, if the fix material is later
* replaced with a "normally-bound" material, clients should be notified
* as per usual.
*/
bool hasFixMaterial() const;

/**
* Returns the material bound to the surface.
*
* @see hasMaterial()
* @see hasMaterial(), hasFixMaterial()
*/
Material &material() const;

/**
* Returns a pointer to the material bound to the surface; otherwise @c 0.
*
* @see hasMaterial()
* @see hasMaterial(), hasFixMaterial()
*/
inline Material *materialPtr() const { return hasMaterial()? &material() : 0; }

Expand Down Expand Up @@ -193,9 +200,10 @@ class Surface : public de::MapElement
/**
* Change Material bound to this surface.
*
* @param mat New Material.
* @param newMaterial New material to be bound.
* @param isMissingFix The new material is a fix for a "missing" material.
*/
bool setMaterial(Material *material);
bool setMaterial(Material *material, bool isMissingFix = false);

/**
* Change Material origin.
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -1313,8 +1313,7 @@ static void addMissingMaterial(SideDef *s, SideDefSection section)
if(surface.hasMaterial()) return;

// Look for a suitable replacement.
surface.setMaterial(chooseFixMaterial(s, section));
surface.inFlags |= SUIF_FIX_MISSING_MATERIAL;
surface.setMaterial(chooseFixMaterial(s, section), true/* is missing fix */);

// During map load we log missing materials.
if(ddMapSetup && verbose)
Expand Down
25 changes: 17 additions & 8 deletions doomsday/client/src/map/surface.cpp
Expand Up @@ -46,7 +46,6 @@ Surface::Surface(MapElement &owner)
V2f_Set(visOffsetDelta, 0, 0);
std::memset(rgba, 1, sizeof(rgba));
inFlags = 0;
_oldInFlags = 0;
numDecorations = 0;
decorations = 0;
}
Expand All @@ -68,7 +67,6 @@ Surface &Surface::operator = (Surface const &other)
V2f_Copy(_oldOffset[1], other._oldOffset[1]);
std::memcpy(rgba, other.rgba, sizeof(rgba));
inFlags = other.inFlags;
_oldInFlags = other._oldInFlags;

// Reset the visual offset to the actual offset.
V2f_Copy(visOffset, offset);
Expand All @@ -87,6 +85,11 @@ bool Surface::hasMaterial() const
return !!_material;
}

bool Surface::hasFixMaterial() const
{
return !!_material && !!(inFlags & SUIF_FIX_MISSING_MATERIAL);
}

Material &Surface::material() const
{
if(_material)
Expand Down Expand Up @@ -123,16 +126,23 @@ bool Surface::isAttachedToMap() const
return true;
}

bool Surface::setMaterial(Material *newMaterial)
bool Surface::setMaterial(Material *newMaterial, bool isMissingFix)
{
if(_material != newMaterial)
{
if(isAttachedToMap())
// Update the missing-material-fix state.
if(!_material)
{
// No longer a missing texture fix?
if(newMaterial && (_oldInFlags & SUIF_FIX_MISSING_MATERIAL))
inFlags &= ~SUIF_FIX_MISSING_MATERIAL;
if(newMaterial && isMissingFix)
inFlags |= SUIF_FIX_MISSING_MATERIAL;
}
else if(newMaterial && (inFlags & SUIF_FIX_MISSING_MATERIAL))
{
inFlags &= ~SUIF_FIX_MISSING_MATERIAL;
}

if(isAttachedToMap())
{
if(!ddMapSetup)
{
#ifdef __CLIENT__
Expand Down Expand Up @@ -170,7 +180,6 @@ bool Surface::setMaterial(Material *newMaterial)
}

_material = newMaterial;
_oldInFlags = inFlags;
if(isAttachedToMap())
{
inFlags |= SUIF_UPDATE_DECORATIONS;
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1198,8 +1198,7 @@ static uint radioEdgeHackType(LineDef const *line, Sector const *front, Sector c
{
Surface const &surface = line->sideDef(backside).surface(isCeiling? SS_TOP:SS_BOTTOM);

if(fz < bz && !surface.hasMaterial() &&
!(surface.inFlags & SUIF_FIX_MISSING_MATERIAL))
if(fz < bz && !surface.hasMaterial())
return 3; // Consider it fully open.

// Is the back sector closed?
Expand Down
8 changes: 3 additions & 5 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1626,8 +1626,7 @@ static boolean rendHEdgeSection(HEdge *hedge, SideDefSection section,
// Lighting debug mode; render using System:gray.
mat = &App_Materials().find(de::Uri("System", Path("gray"))).material();
}
else if(!surface->hasMaterial() ||
((surface->inFlags & SUIF_FIX_MISSING_MATERIAL) && devNoTexFix))
else if(!surface->hasMaterial() || (surface->hasFixMaterial() && devNoTexFix))
{
// Missing material debug mode; render using System:missing.
mat = &App_Materials().find(de::Uri("System", Path("missing"))).material();
Expand Down Expand Up @@ -1710,8 +1709,7 @@ static boolean rendHEdgeSection(HEdge *hedge, SideDefSection section,
// Do not apply an angle based lighting delta if this surface's material
// has been chosen as a HOM fix (we must remain consistent with the lighting
// applied to the back plane (on this half-edge's back side)).
if(frontSide && isTwoSided && section != SS_MIDDLE &&
(surface->inFlags & SUIF_FIX_MISSING_MATERIAL))
if(frontSide && isTwoSided && section != SS_MIDDLE && surface->hasFixMaterial())
{
deltaL = deltaR = 0;
}
Expand Down Expand Up @@ -2717,7 +2715,7 @@ static void Rend_RenderPlanes()

if(renderTextures == 2)
texMode = 2;
else if(!suf->hasMaterial() || (devNoTexFix && (suf->inFlags & SUIF_FIX_MISSING_MATERIAL)))
else if(!suf->hasMaterial() || (devNoTexFix && suf->hasFixMaterial()))
texMode = 1;
else
texMode = 0;
Expand Down
9 changes: 3 additions & 6 deletions doomsday/server/src/server/sv_pool.cpp
Expand Up @@ -756,24 +756,21 @@ boolean Sv_RegisterCompareSide(cregister_t *reg, uint number,
byte sideFlags = s->flags & 0xff;
int df = 0;

if(r->top.material != s->top().materialPtr() &&
!(s->top().inFlags & SUIF_FIX_MISSING_MATERIAL))
if(!s->top().hasFixMaterial() && r->top.material != s->top().materialPtr())
{
df |= SIDF_TOP_MATERIAL;
if(doUpdate)
r->top.material = s->top().materialPtr();
}

if(r->middle.material != s->middle().materialPtr() &&
!(s->middle().inFlags & SUIF_FIX_MISSING_MATERIAL))
if(!s->middle().hasFixMaterial() && r->middle.material != s->middle().materialPtr())
{
df |= SIDF_MID_MATERIAL;
if(doUpdate)
r->middle.material = s->middle().materialPtr();
}

if(r->bottom.material != s->bottom().materialPtr() &&
!(s->bottom().inFlags & SUIF_FIX_MISSING_MATERIAL))
if(!s->bottom().hasFixMaterial() && r->bottom.material != s->bottom().materialPtr())
{
df |= SIDF_BOTTOM_MATERIAL;
if(doUpdate)
Expand Down

0 comments on commit db8b252

Please sign in to comment.