Skip to content

Commit

Permalink
Refactor|Sector: Data for ambient lighting properties now private
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed May 21, 2013
1 parent effa6a8 commit 46f5fc1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 43 deletions.
23 changes: 11 additions & 12 deletions doomsday/client/include/map/sector.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @file sector.h World Map Sector.
/** @file map/sector.h World Map Sector.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -81,6 +81,8 @@ class Sector : public de::MapElement,
#ifdef __CLIENT__
/**
* LightGrid data values for "smoothed sector lighting".
*
* @todo Encapsulate in LightGrid itself?
*/
struct LightGridData
{
Expand All @@ -99,24 +101,13 @@ class Sector : public de::MapElement,
/// @ref sectorFrameFlags
int _frameFlags;

/// Ambient light level in the sector.
float _lightLevel;

/// Ambient light color in the sector.
de::Vector3f _lightColor;

/// Head of the linked list of mobjs "in" the sector (not owned).
struct mobj_s *_mobjList;

/// List of BSP leafs which contribute to the environmental audio
/// characteristics of the sector (not owned).
BspLeafs _reverbBspLeafs;

#ifdef __CLIENT__
/// LightGrid data values.
LightGridData _lightGridData;
#endif

/// Final environmental audio characteristics.
AudioEnvironmentFactors _reverb;

Expand Down Expand Up @@ -447,6 +438,14 @@ class Sector : public de::MapElement,
*/
AudioEnvironmentFactors const &audioEnvironmentFactors() const;

#ifdef __CLIENT__
/**
* Returns the LightGrid data values (for smoothed ambient lighting) for
* the sector.
*/
LightGridData &lightGridData();
#endif

/**
* Returns the @ref sectorFrameFlags for the sector.
*/
Expand Down
79 changes: 50 additions & 29 deletions doomsday/client/src/map/sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,31 @@ DENG2_PIMPL(Sector)
/// List of BSP leafs which reference the sector (not owned).
BspLeafs bspLeafs;

/// Ambient light level in the sector.
float lightLevel;

/// Ambient light color in the sector.
de::Vector3f lightColor;

#ifdef __CLIENT__
/// LightGrid data values.
LightGridData lightGridData;
#endif

/// if == validCount, already checked.
int validCount;

Instance(Public *i)
Instance(Public *i, float lightLevel, Vector3f const &lightColor)
: Base(i),
roughArea(0),
lightLevel(lightLevel),
lightColor(lightColor),
validCount(0)
{
std::memset(&soundEmitter, 0, sizeof(soundEmitter));
zap(soundEmitter);
#ifdef __CLIENT__
zap(lightGridData);
#endif
}

~Instance()
Expand Down Expand Up @@ -107,37 +123,34 @@ DENG2_PIMPL(Sector)
int changedComponents = 0;
for(int i = 0; i < 3; ++i)
{
if(!de::fequal(self._lightColor[i], oldLightColor[i]))
if(!de::fequal(lightColor[i], oldLightColor[i]))
changedComponents |= (1 << i);
}
notifyLightColorChanged(oldLightColor, changedComponents);
}
};

Sector::Sector(float lightLevel, Vector3f const &lightColor)
: MapElement(DMU_SECTOR),
_lightLevel(lightLevel),
_lightColor(lightColor),
d(new Instance(this))
: MapElement(DMU_SECTOR), d(new Instance(this, lightLevel, lightColor))
{
_frameFlags = 0;
_mobjList = 0;
std::memset(&_lightGridData, 0, sizeof(_lightGridData));
std::memset(_reverb, 0, sizeof(_reverb));
zap(_reverb);
}

float Sector::lightLevel() const
{
return _lightLevel;
return d->lightLevel;
}

void Sector::setLightLevel(float newLightLevel_)
void Sector::setLightLevel(float newLightLevel)
{
float newLightLevel = de::clamp(0.f, newLightLevel_, 1.f);
if(!de::fequal(_lightLevel, newLightLevel))
newLightLevel = de::clamp(0.f, newLightLevel, 1.f);

if(!de::fequal(d->lightLevel, newLightLevel))
{
float oldLightLevel = _lightLevel;
_lightLevel = newLightLevel;
float oldLightLevel = d->lightLevel;
d->lightLevel = newLightLevel;

// Notify interested parties of the change.
d->notifyLightLevelChanged(oldLightLevel);
Expand All @@ -146,18 +159,19 @@ void Sector::setLightLevel(float newLightLevel_)

Vector3f const &Sector::lightColor() const
{
return _lightColor;
return d->lightColor;
}

void Sector::setLightColor(Vector3f const &newLightColor_)
{
Vector3f newLightColor = Vector3f(de::clamp(0.f, newLightColor_.x, 1.f),
de::clamp(0.f, newLightColor_.y, 1.f),
de::clamp(0.f, newLightColor_.z, 1.f));
if(_lightColor != newLightColor)

if(d->lightColor != newLightColor)
{
Vector3f oldLightColor = _lightColor;
_lightColor = newLightColor;
Vector3f oldLightColor = d->lightColor;
d->lightColor = newLightColor;

// Notify interested parties of the change.
d->notifyLightColorChanged(oldLightColor);
Expand All @@ -168,10 +182,10 @@ void Sector::setLightColorComponent(int component, float newStrength)
{
DENG_ASSERT(component >= 0 && component < 3);
newStrength = de::clamp(0.f, newStrength, 1.f);
if(!de::fequal(_lightColor[component], newStrength))
if(!de::fequal(d->lightColor[component], newStrength))
{
Vector3f oldLightColor = _lightColor;
_lightColor[component] = newStrength;
Vector3f oldLightColor = d->lightColor;
d->lightColor[component] = newStrength;

// Notify interested parties of the change.
d->notifyLightColorChanged(oldLightColor, (1 << component));
Expand All @@ -198,6 +212,13 @@ AudioEnvironmentFactors const &Sector::audioEnvironmentFactors() const
return _reverb;
}

#ifdef __CLIENT__
Sector::LightGridData &Sector::lightGridData()
{
return d->lightGridData;
}
#endif

int Sector::frameFlags() const
{
return _frameFlags;
Expand Down Expand Up @@ -462,21 +483,21 @@ int Sector::property(setargs_t &args) const
switch(args.prop)
{
case DMU_LIGHT_LEVEL:
DMU_GetValue(DMT_SECTOR_LIGHTLEVEL, &_lightLevel, &args, 0);
DMU_GetValue(DMT_SECTOR_LIGHTLEVEL, &d->lightLevel, &args, 0);
break;
case DMU_COLOR:
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.x, &args, 0);
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.y, &args, 1);
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.z, &args, 2);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.x, &args, 0);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.y, &args, 1);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.z, &args, 2);
break;
case DMU_COLOR_RED:
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.x, &args, 0);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.x, &args, 0);
break;
case DMU_COLOR_GREEN:
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.y, &args, 0);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.y, &args, 0);
break;
case DMU_COLOR_BLUE:
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.z, &args, 0);
DMU_GetValue(DMT_SECTOR_RGB, &d->lightColor.z, &args, 0);
break;
case DMU_EMITTER: {
ddmobj_base_t const *soundEmitterAdr = &d->soundEmitter;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/lightgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ DENG2_OBSERVES(Sector, LightLevelChange)

// LOG_DEBUG(" Sector %i: %i / %i") << theMap->sectorIndex(s) << changedCount << count;

Sector::LightGridData &lgData = sector->_lightGridData;
Sector::LightGridData &lgData = sector->lightGridData();
lgData.changedBlockCount = changedCount;
lgData.blockCount = changedCount + count;

Expand Down Expand Up @@ -811,7 +811,7 @@ DENG2_OBSERVES(Sector, LightLevelChange)
/// @todo We could dynamically join/leave the relevant audiences.
if(!lgEnabled) return;

Sector::LightGridData &lgData = sector._lightGridData;
Sector::LightGridData &lgData = sector.lightGridData();
if(!lgData.changedBlockCount && !lgData.blockCount)
return;

Expand Down

0 comments on commit 46f5fc1

Please sign in to comment.