From 4cca36ae5f609a196d70196ca0e31a2c8a87e577 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 15 Mar 2013 03:57:03 +0000 Subject: [PATCH] Sector: Added getter methods for all Sector property values --- doomsday/api/dd_share.h | 3 + .../client/include/map/bsp/hedgeintercept.h | 4 +- .../client/include/map/bsp/superblockmap.h | 2 +- doomsday/client/include/map/r_world.h | 2 +- doomsday/client/include/map/sector.h | 154 ++++++++++++++---- doomsday/client/include/map/sidedef.h | 2 +- doomsday/client/include/map/surface.h | 2 +- doomsday/client/src/audio/s_environ.cpp | 60 +++---- doomsday/client/src/audio/s_main.cpp | 14 +- doomsday/client/src/audio/s_sfx.cpp | 4 +- doomsday/client/src/client/cl_sound.cpp | 2 +- doomsday/client/src/client/cl_world.cpp | 6 +- doomsday/client/src/edit_bias.cpp | 14 +- doomsday/client/src/edit_map.cpp | 82 +++++----- doomsday/client/src/map/bsp/partitioner.cpp | 12 +- doomsday/client/src/map/dam_file.cpp | 60 +++---- doomsday/client/src/map/gamemap.cpp | 8 +- doomsday/client/src/map/p_maputil.cpp | 16 +- doomsday/client/src/map/p_particle.cpp | 12 +- doomsday/client/src/map/r_world.cpp | 38 +++-- doomsday/client/src/map/sector.cpp | 147 +++++++++++------ doomsday/client/src/map/sidedef.cpp | 8 +- doomsday/client/src/map/surface.cpp | 8 +- doomsday/client/src/render/lumobj.cpp | 6 +- doomsday/client/src/render/r_lgrid.cpp | 51 +++--- doomsday/client/src/render/r_main.cpp | 2 +- doomsday/client/src/render/r_things.cpp | 4 +- doomsday/client/src/render/rend_bias.cpp | 6 +- doomsday/client/src/render/rend_decor.cpp | 18 +- doomsday/client/src/render/rend_fakeradio.cpp | 2 +- doomsday/client/src/render/rend_main.cpp | 16 +- doomsday/client/src/render/rend_particle.cpp | 8 +- doomsday/client/src/render/rend_shadow.cpp | 16 +- doomsday/client/src/render/sprite.cpp | 4 +- doomsday/libdeng1/include/de/vector1.h | 23 ++- doomsday/libdeng1/src/vector1.c | 4 +- doomsday/server/src/server/sv_pool.cpp | 36 ++-- 37 files changed, 507 insertions(+), 349 deletions(-) diff --git a/doomsday/api/dd_share.h b/doomsday/api/dd_share.h index 8d06dd3edb..5b95f15700 100644 --- a/doomsday/api/dd_share.h +++ b/doomsday/api/dd_share.h @@ -576,6 +576,9 @@ enum { NUM_REVERB_DATA }; +/// Environmental audio characteristics. @ingroup map +typedef float AudioEnvironmentFactors[NUM_REVERB_DATA]; + /// SideDef section indices. @ingroup map typedef enum sidedefsection_e { SS_MIDDLE, diff --git a/doomsday/client/include/map/bsp/hedgeintercept.h b/doomsday/client/include/map/bsp/hedgeintercept.h index fac00775f3..dfe50774db 100644 --- a/doomsday/client/include/map/bsp/hedgeintercept.h +++ b/doomsday/client/include/map/bsp/hedgeintercept.h @@ -63,8 +63,8 @@ struct HEdgeIntercept << inst.vertex->_buildData.index << inst.vertex->origin()[VX] << inst.vertex->origin()[VY] - << (inst.before? inst.before->buildData.index : -1) - << (inst.after? inst.after->buildData.index : -1) + << (inst.before? inst.before->origIndex() : -1) + << (inst.after? inst.after->origIndex() : -1) << (inst.selfRef? "SELFREF" : ""); }) }; diff --git a/doomsday/client/include/map/bsp/superblockmap.h b/doomsday/client/include/map/bsp/superblockmap.h index fa829a2f4f..c40d5e54f1 100644 --- a/doomsday/client/include/map/bsp/superblockmap.h +++ b/doomsday/client/include/map/bsp/superblockmap.h @@ -247,7 +247,7 @@ class SuperBlock HEdge* hedge = *it; LOG_DEBUG("Build: %s %p sector: %d [%1.1f, %1.1f] -> [%1.1f, %1.1f]") << (hedge->lineDef? "NORM" : "MINI") - << hedge << hedge->sector->buildData.index + << hedge << hedge->sector->origIndex() << hedge->v[0]->origin()[VX] << hedge->v[0]->origin()[VY] << hedge->v[1]->origin()[VX] << hedge->v[1]->origin()[VY]; } diff --git a/doomsday/client/include/map/r_world.h b/doomsday/client/include/map/r_world.h index bfecfbbd7d..5b771f0017 100644 --- a/doomsday/client/include/map/r_world.h +++ b/doomsday/client/include/map/r_world.h @@ -60,7 +60,7 @@ extern boolean firstFrameAfterLoad; /** * Sector light color may be affected by the sky light color. */ -const float* R_GetSectorLightColor(const Sector *sector); +const_pvec3f_t &R_GetSectorLightColor(Sector const *sector); float R_DistAttenuateLightLevel(float distToViewer, float lightLevel); diff --git a/doomsday/client/include/map/sector.h b/doomsday/client/include/map/sector.h index bfd2d056da..8ecdba9f15 100644 --- a/doomsday/client/include/map/sector.h +++ b/doomsday/client/include/map/sector.h @@ -23,6 +23,7 @@ #include #include +#include #include #include "map/plane.h" #include "p_mapdata.h" @@ -32,16 +33,17 @@ class BspLeaf; class LineDef; -// Sector frame flags -#define SIF_VISIBLE 0x1 // Sector is visible on this frame. -#define SIF_FRAME_CLEAR 0x1 // Flags to clear before each frame. -#define SIF_LIGHT_CHANGED 0x2 +/** + * @defgroup sectorFrameFlags Sector frame flags + * @ingroup map + */ +///@{ +#define SIF_VISIBLE 0x1 ///< Sector is visible on this frame. +#define SIF_LIGHT_CHANGED 0x2 -typedef struct msector_s { - /// Sector index. Always valid after loading & pruning. - int index; - int refCount; -} msector_t; +// Flags to clear before each frame. +#define SIF_FRAME_CLEAR SIF_VISIBLE +///@} /** * Map sector. @@ -64,28 +66,48 @@ class Sector : public de::MapElement typedef QList Planes; typedef QList BspLeafs; + /** + * LightGrid data values for "smoothed sector lighting". + */ + struct LightGridData + { + /// Number of blocks attributed to the sector. + uint blockCount; + + /// Number of attributed blocks to mark changed. + uint changedBlockCount; + + /// Block indices. + ushort *blocks; + }; + public: /// @todo Make private: - int frameFlags; + /// @ref sectorFrameFlags + int _frameFlags; /// if == validCount, already checked. - int validCount; + int _validCount; /// Bounding box for the sector. - AABoxd aaBox; + AABoxd _aaBox; /// Rough approximation of sector area. - coord_t roughArea; + coord_t _roughArea; - float lightLevel; + /// Ambient light level in the sector. + float _lightLevel; - float oldLightLevel; + /// Old ambient light level in the sector. For smoothing. + float _oldLightLevel; - float rgb[3]; + /// Ambient light color in the sector. + vec3f_t _lightColor; - float oldRGB[3]; + /// Old ambient light color in the sector. For smoothing. + vec3f_t _oldLightColor; - /// List of mobjs "in" the sector (not owned). - struct mobj_s *mobjList; + /// Head of the linked list of mobjs "in" the sector (not owned). + struct mobj_s *_mobjList; /// List of lines which reference the sector (not owned). Lines _lines; @@ -97,28 +119,73 @@ class Sector : public de::MapElement /// characteristics of the sector (not owned). BspLeafs _reverbBspLeafs; - ddmobj_base_t base; + /// Primary sound emitter. Others are linked to this, forming a chain. + ddmobj_base_t _soundEmitter; /// List of sector planes (owned). Planes _planes; - /// Number of gridblocks attributed to the sector. - uint blockCount; - - /// Number of attributed blocks to mark changed. - uint changedBlockCount; + /// LightGrid data values. + LightGridData _lightGridData; - /// Light grid block indices. - ushort *blocks; + /// Final environmental audio characteristics. + AudioEnvironmentFactors _reverb; - float reverb[NUM_REVERB_DATA]; - - msector_t buildData; + /// Original index in the archived map. + int _origIndex; public: Sector(); ~Sector(); + /** + * Returns the ambient light level in the sector. + */ + float lightLevel() const; + + /** + * Returns the ambient light color in the sector. + */ + const_pvec3f_t &lightColor() const; + + /** + * Returns the first mobj in the linked list of mobjs "in" the sector. + */ + struct mobj_s *firstMobj() const; + + /** + * Returns the primary sound emitter for the sector. Other emitters in the + * sector are linked to this, forming a chain which can be traversed using + * the 'next' pointer of the emitter's thinker_t. + */ + ddmobj_base_t &soundEmitter(); + + /// @copydoc soundEmitter() + ddmobj_base_t const &soundEmitter() const; + + /** + * Returns the final environmental audio characteristics of the sector. + */ + AudioEnvironmentFactors const &audioEnvironmentFactors() const; + + /** + * Returns the original index of the sector. + */ + uint origIndex() const; + + /** + * Returns the @ref sectorFrameFlags for the sector. + */ + int frameFlags() const; + + /** + * Returns the @em validCount of the sector. Used by some legacy iteration + * algorithms for marking sectors as processed/visited. + * + * @todo Refactor away. + */ + int validCount() const; + /** * Returns the sector plane with the specified @a planeIndex. */ @@ -214,27 +281,46 @@ class Sector : public de::MapElement */ inline uint reverbBspLeafCount() const { return uint(reverbBspLeafs().count()); } + /** + * Returns the axis-aligned bounding box which encompases all vertex + * origin points for lines which reference the sector, in map coordinate + * space units. Note that if no lines reference the sector the bounding + * box will be invalid (has negative dimensions). + * + * @deprecated Algorithms which are dependent on this are likely making + * invalid assumptions about the geometry of the map. + */ + AABoxd const &aaBox() const; + /** * Update the sector's map space axis-aligned bounding box to encompass * the points defined by it's LineDefs' vertexes. - * - * @pre LineDef list must have been initialized. + * @pre Line list must have been initialized. */ void updateAABox(); + /** + * Returns a rough approximation of the area of the sector in the map + * coordinate space (units squared). + * + * @deprecated Algorithms which are dependent on this are likely making + * invalid assumptions about the geometry of the map. + */ + coord_t roughArea() const; + /** * Update the sector's rough area approximation. * * @pre Axis-aligned bounding box must have been initialized. */ - void updateArea(); + void updateRoughArea(); /** * Update the origin of the sector according to the point defined by the * center of the sector's axis-aligned bounding box (which must be * initialized before calling). */ - void updateBaseOrigin(); + void updateSoundEmitterOrigin(); /** * Get a property value, selected by DMU_* name. diff --git a/doomsday/client/include/map/sidedef.h b/doomsday/client/include/map/sidedef.h index 31a1c8d156..a31a3a2428 100644 --- a/doomsday/client/include/map/sidedef.h +++ b/doomsday/client/include/map/sidedef.h @@ -162,7 +162,7 @@ class SideDef : public de::MapElement * defined by the associated LineDef's vertices and the plane heights of the * Sector on this side. If no LineDef is presently associated this is a no-op. */ - void updateBaseOrigins(); + void updateSoundEmitterOrigins(); /** * Update the side's map space surface tangents according to the points diff --git a/doomsday/client/include/map/surface.h b/doomsday/client/include/map/surface.h index 04e145ef1e..6dfadab2b5 100644 --- a/doomsday/client/include/map/surface.h +++ b/doomsday/client/include/map/surface.h @@ -97,7 +97,7 @@ class Surface : public de::MapElement * * If no owner is presently associated this is a no-op. */ - void updateBaseOrigin(); + void updateSoundEmitterOrigin(); /// @return @c true= is drawable (i.e., a drawable Material is bound). bool isDrawable() const; diff --git a/doomsday/client/src/audio/s_environ.cpp b/doomsday/client/src/audio/s_environ.cpp index 0c1ed4a290..6cfec45ab2 100644 --- a/doomsday/client/src/audio/s_environ.cpp +++ b/doomsday/client/src/audio/s_environ.cpp @@ -140,7 +140,7 @@ static void findBspLeafsAffectingSector(GameMap *map, uint secIDX) ownerlist_t bspLeafOwnerList; std::memset(&bspLeafOwnerList, 0, sizeof(bspLeafOwnerList)); - AABoxd aaBox = sec->aaBox; + AABoxd aaBox = sec->aaBox(); aaBox.minX -= 128; aaBox.minY -= 128; aaBox.maxX += 128; @@ -312,80 +312,80 @@ static void calculateSectorReverb(Sector *sec) /// In general a sector should never be considered as playing any /// part in the definition of a map's geometry. -ds uint spaceVolume = (int) (sec->ceiling().height() - sec->floor().height()) * - (sec->aaBox.maxX - sec->aaBox.minX) * - (sec->aaBox.maxY - sec->aaBox.minY); + (sec->aaBox().maxX - sec->aaBox().minX) * + (sec->aaBox().maxY - sec->aaBox().minY); - sec->reverb[SRD_SPACE] = sec->reverb[SRD_VOLUME] = - sec->reverb[SRD_DECAY] = sec->reverb[SRD_DAMPING] = 0; + sec->_reverb[SRD_SPACE] = sec->_reverb[SRD_VOLUME] = + sec->_reverb[SRD_DECAY] = sec->_reverb[SRD_DAMPING] = 0; foreach(BspLeaf *bspLeaf, sec->reverbBspLeafs()) { if(calcBspLeafReverb(bspLeaf)) { - sec->reverb[SRD_SPACE] += bspLeaf->_reverb[SRD_SPACE]; + sec->_reverb[SRD_SPACE] += bspLeaf->_reverb[SRD_SPACE]; - sec->reverb[SRD_VOLUME] += bspLeaf->_reverb[SRD_VOLUME] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; - sec->reverb[SRD_DECAY] += bspLeaf->_reverb[SRD_DECAY] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; - sec->reverb[SRD_DAMPING] += bspLeaf->_reverb[SRD_DAMPING] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; + sec->_reverb[SRD_VOLUME] += bspLeaf->_reverb[SRD_VOLUME] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; + sec->_reverb[SRD_DECAY] += bspLeaf->_reverb[SRD_DECAY] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; + sec->_reverb[SRD_DAMPING] += bspLeaf->_reverb[SRD_DAMPING] / 255.0f * bspLeaf->_reverb[SRD_SPACE]; } } float spaceScatter; - if(sec->reverb[SRD_SPACE]) + if(sec->_reverb[SRD_SPACE]) { - spaceScatter = spaceVolume / sec->reverb[SRD_SPACE]; + spaceScatter = spaceVolume / sec->_reverb[SRD_SPACE]; // These three are weighted by the space. - sec->reverb[SRD_VOLUME] /= sec->reverb[SRD_SPACE]; - sec->reverb[SRD_DECAY] /= sec->reverb[SRD_SPACE]; - sec->reverb[SRD_DAMPING] /= sec->reverb[SRD_SPACE]; + sec->_reverb[SRD_VOLUME] /= sec->_reverb[SRD_SPACE]; + sec->_reverb[SRD_DECAY] /= sec->_reverb[SRD_SPACE]; + sec->_reverb[SRD_DAMPING] /= sec->_reverb[SRD_SPACE]; } else { spaceScatter = 0; - sec->reverb[SRD_VOLUME] = .2f; - sec->reverb[SRD_DECAY] = .4f; - sec->reverb[SRD_DAMPING] = 1; + sec->_reverb[SRD_VOLUME] = .2f; + sec->_reverb[SRD_DECAY] = .4f; + sec->_reverb[SRD_DAMPING] = 1; } // If the space is scattered, the reverb effect lessens. - sec->reverb[SRD_SPACE] /= (spaceScatter > .8 ? 10 : spaceScatter > .6 ? 4 : 1); + sec->_reverb[SRD_SPACE] /= (spaceScatter > .8 ? 10 : spaceScatter > .6 ? 4 : 1); // Normalize the reverb space [0..1] // 0= very small // .99= very large // 1.0= only for open areas (special case). - sec->reverb[SRD_SPACE] /= 120e6; - if(sec->reverb[SRD_SPACE] > .99) - sec->reverb[SRD_SPACE] = .99f; + sec->_reverb[SRD_SPACE] /= 120e6; + if(sec->_reverb[SRD_SPACE] > .99) + sec->_reverb[SRD_SPACE] = .99f; if(sec->ceilingSurface().isSkyMasked() || sec->floorSurface().isSkyMasked()) { // An "open" sector. // It can still be small, in which case; reverb is diminished a bit. - if(sec->reverb[SRD_SPACE] > .5) - sec->reverb[SRD_VOLUME] = 1; // Full volume. + if(sec->_reverb[SRD_SPACE] > .5) + sec->_reverb[SRD_VOLUME] = 1; // Full volume. else - sec->reverb[SRD_VOLUME] = .5f; // Small, but still open. + sec->_reverb[SRD_VOLUME] = .5f; // Small, but still open. - sec->reverb[SRD_SPACE] = 1; + sec->_reverb[SRD_SPACE] = 1; } else { // A "closed" sector. // Large spaces have automatically a bit more audible reverb. - sec->reverb[SRD_VOLUME] += sec->reverb[SRD_SPACE] / 4; + sec->_reverb[SRD_VOLUME] += sec->_reverb[SRD_SPACE] / 4; } - if(sec->reverb[SRD_VOLUME] > 1) - sec->reverb[SRD_VOLUME] = 1; + if(sec->_reverb[SRD_VOLUME] > 1) + sec->_reverb[SRD_VOLUME] = 1; } -void S_ResetReverb(void) +void S_ResetReverb() { reverbUpdateRequested.clear(); } -void S_UpdateReverbForSector(Sector* sec) +void S_UpdateReverbForSector(Sector *sec) { if(reverbUpdateRequested.empty()) return; diff --git a/doomsday/client/src/audio/s_main.cpp b/doomsday/client/src/audio/s_main.cpp index 85c3f14359..ea27d30a38 100644 --- a/doomsday/client/src/audio/s_main.cpp +++ b/doomsday/client/src/audio/s_main.cpp @@ -446,27 +446,27 @@ int S_ConsoleSound(int soundID, mobj_t* origin, int targetConsole) * @param soundID Unique identifier of the sound to be stopped. If @c 0, ID not checked. * @param flags @ref soundStopFlags */ -static void stopSectorSounds(ddmobj_base_t* sectorEmitter, int soundID, int flags) +static void stopSectorSounds(ddmobj_base_t *sectorEmitter, int soundID, int flags) { - ddmobj_base_t* base; + ddmobj_base_t *base; if(!sectorEmitter || !flags) return; // Are we stopping with this sector's emitter? if(flags & SSF_SECTOR) { - _api_S.StopSound(soundID, (mobj_t*)sectorEmitter); + _api_S.StopSound(soundID, (mobj_t *)sectorEmitter); } // Are we stopping with linked emitters? if(!(flags & SSF_SECTOR_LINKED_SURFACES)) return; // Process the rest of the emitter chain. - base = (ddmobj_base_t*)sectorEmitter; - while((base = (ddmobj_base_t*)base->thinker.next)) + base = sectorEmitter; + while((base = (ddmobj_base_t *)base->thinker.next)) { // Stop sounds from this emitter. - _api_S.StopSound(soundID, (mobj_t*)base); + _api_S.StopSound(soundID, (mobj_t *)base); } } @@ -501,7 +501,7 @@ void S_StopSound2(int soundID, mobj_t *emitter, int flags) { // Emitter is a real Mobj. Sector §or = emitter->bspLeaf->sector(); - stopSectorSounds((ddmobj_base_t *)§or.base, soundID, flags); + stopSectorSounds(§or.soundEmitter(), soundID, flags); return; } diff --git a/doomsday/client/src/audio/s_sfx.cpp b/doomsday/client/src/audio/s_sfx.cpp index 71e89189ef..787b061b92 100644 --- a/doomsday/client/src/audio/s_sfx.cpp +++ b/doomsday/client/src/audio/s_sfx.cpp @@ -563,9 +563,11 @@ void Sfx_ListenerUpdate() // It may be necessary to recalculate the reverb properties. S_UpdateReverbForSector(listenerSector); + AudioEnvironmentFactors const &envFactors = listenerSector->audioEnvironmentFactors(); + for(int i = 0; i < NUM_REVERB_DATA; ++i) { - vec[i] = listenerSector->reverb[i]; + vec[i] = envFactors[i]; if(i == SRD_VOLUME) { vec[i] *= sfxReverbStrength; diff --git a/doomsday/client/src/client/cl_sound.cpp b/doomsday/client/src/client/cl_sound.cpp index 4d705b6722..33f08ba849 100644 --- a/doomsday/client/src/client/cl_sound.cpp +++ b/doomsday/client/src/client/cl_sound.cpp @@ -330,7 +330,7 @@ void Cl_Sound(void) Con_Message("Cl_Sound: Invalid sector number %i.", num); return; } - mo = (mobj_t*) &SECTOR_PTR(num)->base; + mo = (mobj_t *) &SECTOR_PTR(num)->soundEmitter(); //S_StopSound(0, mo); S_LocalSoundAtVolume(sound, mo, volume / 127.0f); } diff --git a/doomsday/client/src/client/cl_world.cpp b/doomsday/client/src/client/cl_world.cpp index 66606c7dd3..a26bb91bf0 100644 --- a/doomsday/client/src/client/cl_world.cpp +++ b/doomsday/client/src/client/cl_world.cpp @@ -664,11 +664,11 @@ void Cl_ReadSectorDelta2(int deltaType, boolean /*skip*/) speed[PLN_CEILING] = FIX2FLT(Reader_ReadByte(msgReader) << (df & SDF_CEILING_SPEED_44 ? 12 : 15)); if(df & SDF_COLOR_RED) - sec->rgb[0] = Reader_ReadByte(msgReader) / 255.f; + sec->_lightColor[0] = Reader_ReadByte(msgReader) / 255.f; if(df & SDF_COLOR_GREEN) - sec->rgb[1] = Reader_ReadByte(msgReader) / 255.f; + sec->_lightColor[1] = Reader_ReadByte(msgReader) / 255.f; if(df & SDF_COLOR_BLUE) - sec->rgb[2] = Reader_ReadByte(msgReader) / 255.f; + sec->_lightColor[2] = Reader_ReadByte(msgReader) / 255.f; if(df & SDF_FLOOR_COLOR_RED) sec->floorSurface().setColorRed(Reader_ReadByte(msgReader) / 255.f); diff --git a/doomsday/client/src/edit_bias.cpp b/doomsday/client/src/edit_bias.cpp index d1a947e3a9..bf4c6bd28c 100644 --- a/doomsday/client/src/edit_bias.cpp +++ b/doomsday/client/src/edit_bias.cpp @@ -712,14 +712,14 @@ static void SBE_DrawLevelGauge(Point2Raw const *origin, int height) Sector §or = bspLeaf->sector(); if(lastSector != §or) { - minLevel = maxLevel = sector.lightLevel; + minLevel = maxLevel = sector.lightLevel(); lastSector = §or; } - if(sector.lightLevel < minLevel) - minLevel = sector.lightLevel; - if(sector.lightLevel > maxLevel) - maxLevel = sector.lightLevel; + if(sector.lightLevel() < minLevel) + minLevel = sector.lightLevel(); + if(sector.lightLevel() > maxLevel) + maxLevel = sector.lightLevel(); FR_SetFont(fontFixed); FR_LoadDefaultAttrib(); @@ -734,7 +734,7 @@ static void SBE_DrawLevelGauge(Point2Raw const *origin, int height) glVertex2f(origin->x + off, origin->y); glVertex2f(origin->x + off, origin->y + height); // Normal lightlevel. - int secY = origin->y + height * (1.0f - sector.lightLevel); + int secY = origin->y + height * (1.0f - sector.lightLevel()); glVertex2f(origin->x + off - 4, secY); glVertex2f(origin->x + off, secY); if(maxLevel != minLevel) @@ -769,7 +769,7 @@ static void SBE_DrawLevelGauge(Point2Raw const *origin, int height) // The number values. Point2Raw labelOrigin(origin->x, secY); char buf[80]; - sprintf(buf, "%03i", (short) (255.0f * sector.lightLevel)); + sprintf(buf, "%03i", (short) (255.0f * sector.lightLevel())); UI_TextOutEx2(buf, &labelOrigin, UI_Color(UIC_TITLE), .7f, 0, DTF_ONLY_SHADOW); if(maxLevel != minLevel) { diff --git a/doomsday/client/src/edit_map.cpp b/doomsday/client/src/edit_map.cpp index 80ee96793a..ba8362a946 100644 --- a/doomsday/client/src/edit_map.cpp +++ b/doomsday/client/src/edit_map.cpp @@ -103,13 +103,17 @@ static SideDef* createSide(void) return side; } -static Sector* createSector(void) -{ - Sector* sec = new Sector; - +static Sector *createSector(Vector3f const &ambientLightColor, float lightLevel) +{ + Sector *sec = new Sector; + sec->_lightColor[CR] = de::clamp(0.f, ambientLightColor.x, 1.f); + sec->_lightColor[CG] = de::clamp(0.f, ambientLightColor.y, 1.f); + sec->_lightColor[CB] = de::clamp(0.f, ambientLightColor.z, 1.f); + sec->_lightLevel = de::clamp(0.f, lightLevel, 1.f); + e_map->sectors.push_back(sec); + sec->_origIndex = e_map->sectors.size(); // 1-based index, 0 = NIL. - sec->buildData.index = e_map->sectors.size(); // 1-based index, 0 = NIL. return sec; } @@ -604,8 +608,8 @@ static void finishSectors(GameMap *map) Sector &sec = map->sectors[i]; sec.updateAABox(); - sec.updateArea(); - sec.updateBaseOrigin(); + sec.updateRoughArea(); + sec.updateSoundEmitterOrigin(); // Set the position of the sound origin for all plane sound origins. // Set target heights for all planes. @@ -613,7 +617,7 @@ static void finishSectors(GameMap *map) { Plane &pln = sec.plane(k); - pln.surface().updateBaseOrigin(); + pln.surface().updateSoundEmitterOrigin(); pln._targetHeight = pln._height; } } @@ -624,39 +628,39 @@ static void finishSectors(GameMap *map) * @param base Mobj base to link in @a sector. Caller should ensure that the * same object is not linked multiple times into the chain. */ -static void linkBaseToSectorChain(Sector* sector, ddmobj_base_t* base) +static void linkToSectorEmitterChain(Sector *sector, ddmobj_base_t *otherEmitter) { - if(!sector || !base) return; + if(!sector || !otherEmitter) return; // The sector's base is always head of the chain, so link the other after it. - base->thinker.prev = §or->base.thinker; - base->thinker.next = sector->base.thinker.next; - if(base->thinker.next) - base->thinker.next->prev = &base->thinker; - sector->base.thinker.next = &base->thinker; + otherEmitter->thinker.prev = §or->_soundEmitter.thinker; + otherEmitter->thinker.next = sector->_soundEmitter.thinker.next; + if(otherEmitter->thinker.next) + otherEmitter->thinker.next->prev = &otherEmitter->thinker; + sector->_soundEmitter.thinker.next = &otherEmitter->thinker; } /** * Chain together the ddmobj_base_t objects owned by all Surfaces in all sectors. - * These chains are used for efficiently traversing all of the base objects in a - * sector, for example; stopping sounds emitted from all origins within a sector. + * These chains are used for efficiently traversing all of the sound emitters in + * a sector (e.g., when stopping all sounds emitted in the sector). */ -static void chainSectorBases(GameMap *map) +static void chainSectorSoundEmitters(GameMap *map) { DENG_ASSERT(map); for(uint i = 0; i < map->sectorCount(); ++i) { Sector *sec = GameMap_Sector(map, i); - ddmobj_base_t *base = &sec->base; + ddmobj_base_t &emitter = sec->soundEmitter(); - // Clear the chain head. - base->thinker.next = base->thinker.prev = 0; + // Clear the head of the sound emitter chain. + emitter.thinker.next = emitter.thinker.prev = 0; // Add all plane base mobjs. foreach(Plane *plane, sec->planes()) { - linkBaseToSectorChain(sec, &plane->surface().base); + linkToSectorEmitterChain(sec, &plane->surface().base); } // Add all sidedef base mobjs. @@ -665,16 +669,16 @@ static void chainSectorBases(GameMap *map) if(line->frontSectorPtr() == sec) { SideDef &side = line->frontSideDef(); - linkBaseToSectorChain(sec, &side.SW_middlesurface.base); - linkBaseToSectorChain(sec, &side.SW_bottomsurface.base); - linkBaseToSectorChain(sec, &side.SW_topsurface.base); + linkToSectorEmitterChain(sec, &side.SW_middlesurface.base); + linkToSectorEmitterChain(sec, &side.SW_bottomsurface.base); + linkToSectorEmitterChain(sec, &side.SW_topsurface.base); } if(line->hasBackSideDef() && line->backSectorPtr() == sec) { SideDef &side = line->backSideDef(); - linkBaseToSectorChain(sec, &side.SW_middlesurface.base); - linkBaseToSectorChain(sec, &side.SW_bottomsurface.base); - linkBaseToSectorChain(sec, &side.SW_topsurface.base); + linkToSectorEmitterChain(sec, &side.SW_middlesurface.base); + linkToSectorEmitterChain(sec, &side.SW_bottomsurface.base); + linkToSectorEmitterChain(sec, &side.SW_topsurface.base); } } } @@ -689,7 +693,7 @@ static void finishSideDefs(GameMap *map) { SideDef &side = map->sideDefs[i]; side.updateSurfaceTangents(); - side.updateBaseOrigins(); + side.updateSoundEmitterOrigins(); } } @@ -736,13 +740,13 @@ static void updateMapBounds(GameMap *map) if(isFirst) { // The first sector is used as is. - V2d_CopyBox(map->aaBox.arvec2, sec->aaBox.arvec2); + V2d_CopyBox(map->aaBox.arvec2, sec->aaBox().arvec2); isFirst = false; } else { // Expand the bounding box. - V2d_UniteBox(map->aaBox.arvec2, sec->aaBox.arvec2); + V2d_UniteBox(map->aaBox.arvec2, sec->aaBox().arvec2); } } } @@ -1038,10 +1042,10 @@ static void hardenLinedefs(GameMap *dest, EditMap *src) destL->backSideDef().line = destL; destL->front()._sector = (srcL->front()._sector? - &dest->sectors[srcL->front()._sector->buildData.index - 1] : NULL); + &dest->sectors[srcL->front()._sector->_origIndex - 1] : NULL); destL->back()._sector = (srcL->back()._sector? - &dest->sectors[srcL->back()._sector->buildData.index - 1] : NULL); + &dest->sectors[srcL->back()._sector->_origIndex - 1] : NULL); } } @@ -1591,7 +1595,7 @@ boolean MPE_End(void) finishSideDefs(gamemap); finishLineDefs(gamemap); finishSectors(gamemap); - chainSectorBases(gamemap); + chainSectorSoundEmitters(gamemap); updateMapBounds(gamemap); S_DetermineBspLeafsAffectingSectorReverb(gamemap); @@ -1937,14 +1941,8 @@ uint MPE_SectorCreate(float lightlevel, float red, float green, float blue) { if(!editMapInited) return 0; - Sector* s = createSector(); - - s->rgb[CR] = MINMAX_OF(0, red, 1); - s->rgb[CG] = MINMAX_OF(0, green, 1); - s->rgb[CB] = MINMAX_OF(0, blue, 1); - s->lightLevel = MINMAX_OF(0, lightlevel, 1); - - return s->buildData.index; + Sector *s = createSector(Vector3f(red, green, blue), lightlevel); + return s->origIndex(); } uint MPE_PolyobjCreate(uint *lines, uint lineCount, int tag, int sequenceType, diff --git a/doomsday/client/src/map/bsp/partitioner.cpp b/doomsday/client/src/map/bsp/partitioner.cpp index 7187431403..b41fc2e841 100644 --- a/doomsday/client/src/map/bsp/partitioner.cpp +++ b/doomsday/client/src/map/bsp/partitioner.cpp @@ -376,7 +376,7 @@ struct Partitioner::Instance if(p.backOpen && p.frontOpen && line->frontSectorPtr() == p.backOpen) { LOG_VERBOSE("LineDef #%d seems to be a One-Sided Window (back faces sector #%d).") - << line->origIndex() - 1 << p.backOpen->buildData.index - 1; + << line->origIndex() - 1 << p.backOpen->origIndex() - 1; lineInfo.windowEffect = p.frontOpen; line->_inFlags |= LF_BSPWINDOW; /// @todo Refactor away. @@ -653,8 +653,8 @@ struct Partitioner::Instance if(!cur->selfRef && !next->selfRef) { LOG_DEBUG("Sector mismatch (#%d [%1.1f, %1.1f] != #%d [%1.1f, %1.1f]).") - << cur->after->buildData.index-1 << cur->vertex->origin()[VX] << cur->vertex->origin()[VY] - << next->before->buildData.index-1 << next->vertex->origin()[VX] << next->vertex->origin()[VY]; + << cur->after->origIndex() - 1 << cur->vertex->origin()[VX] << cur->vertex->origin()[VY] + << next->before->origIndex() - 1 << next->vertex->origin()[VX] << next->vertex->origin()[VY]; } if(cur->selfRef && !next->selfRef) @@ -2266,7 +2266,7 @@ struct Partitioner::Instance // In the absence of a better mechanism, simply log this right away. /// @todo Implement something better! LOG_WARNING("Sector %p (#%d) is unclosed near [%1.1f, %1.1f].") - << de::dintptr(sector) << sector->buildData.index - 1 << x << y; + << de::dintptr(sector) << sector->origIndex() - 1 << x << y; return true; } @@ -2346,11 +2346,11 @@ struct Partitioner::Instance /// @todo Implement something better! if(migrant->lineDef) LOG_WARNING("Sector #%d has migrant HEdge facing #%d (line #%d).") - << sector->buildData.index - 1 << migrant->sector->buildData.index - 1 + << sector->origIndex() - 1 << migrant->sector->origIndex() - 1 << migrant->lineDef->origIndex() - 1; else LOG_WARNING("Sector #%d has migrant HEdge facing #%d.") - << sector->buildData.index - 1 << migrant->sector->buildData.index - 1; + << sector->origIndex() - 1 << migrant->sector->origIndex() - 1; return true; } diff --git a/doomsday/client/src/map/dam_file.cpp b/doomsday/client/src/map/dam_file.cpp index 915a2ff269..5becc98a0f 100644 --- a/doomsday/client/src/map/dam_file.cpp +++ b/doomsday/client/src/map/dam_file.cpp @@ -399,7 +399,7 @@ static void readSide(GameMap *map, uint idx) } s->flags = readShort(); - s->updateBaseOrigins(); + s->updateSoundEmitterOrigins(); } static void archiveSides(GameMap *map, boolean write) @@ -438,10 +438,10 @@ static void writeSector(GameMap *map, uint idx) Sector *s = &map->sectors[idx]; - writeFloat(s->lightLevel); - writeFloat(s->rgb[CR]); - writeFloat(s->rgb[CG]); - writeFloat(s->rgb[CB]); + writeFloat(s->_lightLevel); + writeFloat(s->_lightColor[CR]); + writeFloat(s->_lightColor[CG]); + writeFloat(s->_lightColor[CB]); writeLong((long) s->_planes.count()); foreach(Plane *plane, s->_planes) { @@ -466,19 +466,19 @@ static void writeSector(GameMap *map, uint idx) writeFloat(surface.rgba[CA]); } - writeFloat(s->aaBox.minX); - writeFloat(s->aaBox.minY); - writeFloat(s->aaBox.maxX); - writeFloat(s->aaBox.maxY); + writeFloat(s->_aaBox.minX); + writeFloat(s->_aaBox.minY); + writeFloat(s->_aaBox.maxX); + writeFloat(s->_aaBox.maxY); for(uint i = 0; i < NUM_REVERB_DATA; ++i) - writeFloat(s->reverb[i]); + writeFloat(s->_reverb[i]); // Lightgrid block indices. - writeLong((long) s->changedBlockCount); - writeLong((long) s->blockCount); - for(uint i = 0; i < s->blockCount; ++i) - writeShort(s->blocks[i]); + writeLong((long) s->_lightGridData.changedBlockCount); + writeLong((long) s->_lightGridData.blockCount); + for(uint i = 0; i < s->_lightGridData.blockCount; ++i) + writeShort(s->_lightGridData.blocks[i]); // Line list. writeLong((long) s->_lines.count()); @@ -508,10 +508,10 @@ static void readSector(GameMap *map, uint idx) Sector *s = &map->sectors[idx]; - s->lightLevel = readFloat(); - s->rgb[CR] = readFloat(); - s->rgb[CG] = readFloat(); - s->rgb[CB] = readFloat(); + s->_lightLevel = readFloat(); + s->_lightColor[CR] = readFloat(); + s->_lightColor[CG] = readFloat(); + s->_lightColor[CB] = readFloat(); uint numPlanes = (uint) readLong(); float offset[2], rgba[4]; @@ -546,30 +546,30 @@ static void readSector(GameMap *map, uint idx) p->_surface.numDecorations = 0; } - s->aaBox.minX = readFloat(); - s->aaBox.minY = readFloat(); - s->aaBox.maxX = readFloat(); - s->aaBox.maxY = readFloat(); + s->_aaBox.minX = readFloat(); + s->_aaBox.minY = readFloat(); + s->_aaBox.maxX = readFloat(); + s->_aaBox.maxY = readFloat(); - s->updateBaseOrigin(); + s->updateSoundEmitterOrigin(); for(uint i = 0; i < numPlanes; ++i) { Plane *pln = s->_planes[i]; - pln->_surface.updateBaseOrigin(); + pln->_surface.updateSoundEmitterOrigin(); } for(uint i = 0; i < NUM_REVERB_DATA; ++i) { - s->reverb[i] = readFloat(); + s->_reverb[i] = readFloat(); } // Lightgrid block indices. - s->changedBlockCount = (uint) readLong(); - s->blockCount = (uint) readLong(); - s->blocks = (ushort *) Z_Malloc(sizeof(ushort) * s->blockCount, PU_MAP, 0); - for(uint i = 0; i < s->blockCount; ++i) + s->_lightGridData.changedBlockCount = (uint) readLong(); + s->_lightGridData.blockCount = (uint) readLong(); + s->_lightGridData.blocks = (ushort *) Z_Malloc(sizeof(ushort) * s->_lightGridData.blockCount, PU_MAP, 0); + for(uint i = 0; i < s->_lightGridData.blockCount; ++i) { - s->blocks[i] = readShort(); + s->_lightGridData.blocks[i] = readShort(); } // Line list. diff --git a/doomsday/client/src/map/gamemap.cpp b/doomsday/client/src/map/gamemap.cpp index 7c8121b5a4..ad62f9338f 100644 --- a/doomsday/client/src/map/gamemap.cpp +++ b/doomsday/client/src/map/gamemap.cpp @@ -223,20 +223,20 @@ int GameMap_SectorIndex(GameMap *map, Sector const *sec) return map->sectors.indexOf(sec); // Note: Bad performance! } -Sector* GameMap_Sector(GameMap* map, uint idx) +Sector *GameMap_Sector(GameMap* map, uint idx) { DENG2_ASSERT(map); if(idx >= map->sectorCount()) return NULL; return &map->sectors[idx]; } -Sector* GameMap_SectorByBase(GameMap* map, const void* ddMobjBase) +Sector *GameMap_SectorByBase(GameMap *map, void const *ddMobjBase) { DENG2_ASSERT(map); for(int i = 0; i < map->sectors.size(); ++i) { - Sector* sec = &map->sectors[i]; - if(ddMobjBase == &sec->base) + Sector *sec = &map->sectors[i]; + if(ddMobjBase == &sec->soundEmitter()) { return sec; } diff --git a/doomsday/client/src/map/p_maputil.cpp b/doomsday/client/src/map/p_maputil.cpp index 98ab69fd33..c7ab3aa968 100644 --- a/doomsday/client/src/map/p_maputil.cpp +++ b/doomsday/client/src/map/p_maputil.cpp @@ -325,10 +325,10 @@ DENG_EXTERN_C void P_MobjLink(mobj_t *mo, byte flags) // Prev pointers point to the pointer that points back to us. // (Which practically disallows traversing the list backwards.) - if((mo->sNext = sec.mobjList)) + if((mo->sNext = sec.firstMobj())) mo->sNext->sPrev = &mo->sNext; - *(mo->sPrev = &sec.mobjList) = mo; + *(mo->sPrev = &sec._mobjList) = mo; } // Link into blockmap? @@ -411,7 +411,7 @@ int GameMap_MobjSectorsIterator(GameMap *map, mobj_t *mo, // Always process the mobj's own sector first. Sector &ownSec = mo->bspLeaf->sector(); *end++ = &ownSec; - ownSec.validCount = validCount; + ownSec._validCount = validCount; // Any good lines around here? if(mo->lineRoot) @@ -423,20 +423,20 @@ int GameMap_MobjSectorsIterator(GameMap *map, mobj_t *mo, // All these lines are two-sided. Try front side. Sector &frontSec = ld->frontSector(); - if(frontSec.validCount != validCount) + if(frontSec.validCount() != validCount) { *end++ = &frontSec; - frontSec.validCount = validCount; + frontSec._validCount = validCount; } // And then the back side. if(ld->hasBackSideDef()) { Sector &backSec = ld->backSector(); - if(backSec.validCount != validCount) + if(backSec.validCount() != validCount) { *end++ = &backSec; - backSec.validCount = validCount; + backSec._validCount = validCount; } } } @@ -484,7 +484,7 @@ int GameMap_SectorTouchingMobjsIterator(GameMap *map, Sector *sector, void **end = linkStore; // Collate mobjs that obviously are in the sector. - for(mobj_t *mo = sector->mobjList; mo; mo = mo->sNext) + for(mobj_t *mo = sector->firstMobj(); mo; mo = mo->sNext) { if(mo->validCount == validCount) continue; mo->validCount = validCount; diff --git a/doomsday/client/src/map/p_particle.cpp b/doomsday/client/src/map/p_particle.cpp index 9083362058..9c8f3cf154 100644 --- a/doomsday/client/src/map/p_particle.cpp +++ b/doomsday/client/src/map/p_particle.cpp @@ -317,7 +317,7 @@ void P_SpawnMobjParticleGen(ded_ptcgen_t const *def, mobj_t *source) // Size of source sector might determine count. if(def->flags & PGF_SCALED_RATE) { - gen->spawnRateMultiplier = source->bspLeaf->sector().roughArea; + gen->spawnRateMultiplier = source->bspLeaf->sector().roughArea(); } else { @@ -387,7 +387,7 @@ void P_SpawnPlaneParticleGen(ded_ptcgen_t const *def, Plane *plane) // Size of source sector might determine count. if(def->flags & PGF_PARTS_PER_128) { - gen->spawnRateMultiplier = plane->sector().roughArea; + gen->spawnRateMultiplier = plane->sector().roughArea(); } else { @@ -648,10 +648,10 @@ static void P_NewParticle(ptcgen_t *gen) */ for(i = 0; i < 5; ++i) // Try a couple of times (max). { - float x = sector->aaBox.minX + - RNG_RandFloat() * (sector->aaBox.maxX - sector->aaBox.minX); - float y = sector->aaBox.minY + - RNG_RandFloat() * (sector->aaBox.maxY - sector->aaBox.minY); + float x = sector->aaBox().minX + + RNG_RandFloat() * (sector->aaBox().maxX - sector->aaBox().minX); + float y = sector->aaBox().minY + + RNG_RandFloat() * (sector->aaBox().maxY - sector->aaBox().minY); subsec = P_BspLeafAtPointXY(x, y); if(subsec->sectorPtr() == sector) break; diff --git a/doomsday/client/src/map/r_world.cpp b/doomsday/client/src/map/r_world.cpp index d3691d7850..b59dcb002b 100644 --- a/doomsday/client/src/map/r_world.cpp +++ b/doomsday/client/src/map/r_world.cpp @@ -264,7 +264,7 @@ Plane *R_NewPlaneForSector(Sector *sec) // Initialize the surface. /// @todo The initial material should be the "unknown" material. - plane->surface().updateBaseOrigin(); + plane->surface().updateSoundEmitterOrigin(); #ifdef __CLIENT__ /** @@ -380,7 +380,7 @@ void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec) } // Check that all the mobjs in the sector fit in. - for(mobj_t *mo = sec->mobjList; mo; mo = mo->sNext) + for(mobj_t *mo = sec->firstMobj(); mo; mo = mo->sNext) { float extent = mo->origin[VZ] + mo->height; @@ -1137,7 +1137,7 @@ void R_ClearSectorFlags() { Sector *sec = SECTOR_PTR(i); // Clear all flags that can be cleared before each frame. - sec->frameFlags &= ~SIF_FRAME_CLEAR; + sec->_frameFlags &= ~SIF_FRAME_CLEAR; } } @@ -1402,17 +1402,17 @@ boolean R_UpdatePlane(Plane *pln, boolean forceUpdate) } // Update the base origins for this plane and all affected wall surfaces. - pln->surface().updateBaseOrigin(); + pln->surface().updateSoundEmitterOrigin(); foreach(LineDef *line, sec->lines()) { if(line->hasFrontSideDef()) // $degenleaf { - line->frontSideDef().updateBaseOrigins(); + line->frontSideDef().updateSoundEmitterOrigins(); } if(line->hasBackSideDef()) { - line->backSideDef().updateBaseOrigins(); + line->backSideDef().updateSoundEmitterOrigins(); } } @@ -1456,21 +1456,21 @@ boolean R_UpdateSector(Sector *sec, boolean forceUpdate) // Check if there are any lightlevel or color changes. if(forceUpdate || - (sec->lightLevel != sec->oldLightLevel || - sec->rgb[0] != sec->oldRGB[0] || - sec->rgb[1] != sec->oldRGB[1] || - sec->rgb[2] != sec->oldRGB[2])) + (sec->_lightLevel != sec->_oldLightLevel || + sec->_lightColor[0] != sec->_oldLightColor[0] || + sec->_lightColor[1] != sec->_oldLightColor[1] || + sec->_lightColor[2] != sec->_oldLightColor[2])) { - sec->frameFlags |= SIF_LIGHT_CHANGED; - sec->oldLightLevel = sec->lightLevel; - std::memcpy(sec->oldRGB, sec->rgb, sizeof(sec->oldRGB)); + sec->_frameFlags |= SIF_LIGHT_CHANGED; + sec->_oldLightLevel = sec->_lightLevel; + std::memcpy(sec->_oldLightColor, sec->_lightColor, sizeof(sec->_oldLightColor)); LG_SectorChanged(static_cast(sec)); changed = true; } else { - sec->frameFlags &= ~SIF_LIGHT_CHANGED; + sec->_frameFlags &= ~SIF_LIGHT_CHANGED; } foreach(Plane *plane, sec->planes()) @@ -1483,7 +1483,7 @@ boolean R_UpdateSector(Sector *sec, boolean forceUpdate) if(forceUpdate || planeChanged) { - sec->updateBaseOrigin(); + sec->updateSoundEmitterOrigin(); #ifdef __CLIENT__ updateMissingMaterialsForLinesOfSector(*sec); #endif @@ -1565,10 +1565,11 @@ float R_CheckSectorLight(float lightlevel, float min, float max) #ifdef __CLIENT__ -float const *R_GetSectorLightColor(Sector const *sector) +const_pvec3f_t &R_GetSectorLightColor(Sector const *sector) { static vec3f_t skyLightColor, oldSkyAmbientColor = { -1, -1, -1 }; static float oldRendSkyLight = -1; + if(rendSkyLight > .001f && R_SectorContainsSkySurfaces(sector)) { ColorRawf const *ambientColor = Sky_AmbientColor(); @@ -1588,11 +1589,14 @@ float const *R_GetSectorLightColor(Sector const *sector) LG_MarkAllForUpdate(); V3f_Copy(oldSkyAmbientColor, ambientColor->rgb); } + oldRendSkyLight = rendSkyLight; return skyLightColor; } + // A non-skylight sector (i.e., everything else!) - return sector->rgb; // The sector's ambient light color. + // Return the sector's ambient light color. + return sector->lightColor(); } #endif // __CLIENT__ diff --git a/doomsday/client/src/map/sector.cpp b/doomsday/client/src/map/sector.cpp index f77cc3eb1e..53e89a128e 100644 --- a/doomsday/client/src/map/sector.cpp +++ b/doomsday/client/src/map/sector.cpp @@ -31,21 +31,19 @@ using namespace de; Sector::Sector() : MapElement(DMU_SECTOR) { - frameFlags = 0; - validCount = 0; - std::memset(&aaBox, 0, sizeof(aaBox)); - roughArea = 0; - lightLevel = 0; - oldLightLevel = 0; - std::memset(rgb, 0, sizeof(rgb)); - std::memset(oldRGB, 0, sizeof(oldRGB)); - mobjList = 0; - std::memset(&base, 0, sizeof(base)); - blockCount = 0; - changedBlockCount = 0; - blocks = 0; - std::memset(reverb, 0, sizeof(reverb)); - std::memset(&buildData, 0, sizeof(buildData)); + _frameFlags = 0; + _validCount = 0; + std::memset(&_aaBox, 0, sizeof(_aaBox)); + _roughArea = 0; + _lightLevel = 0; + _oldLightLevel = 0; + V3f_Set(_lightColor, 0, 0, 0); + V3f_Set(_oldLightColor, 0, 0, 0); + _mobjList = 0; + std::memset(&_soundEmitter, 0, sizeof(_soundEmitter)); + std::memset(&_lightGridData, 0, sizeof(_lightGridData)); + std::memset(_reverb, 0, sizeof(_reverb)); + _origIndex = 0; } Sector::~Sector() @@ -53,6 +51,51 @@ Sector::~Sector() qDeleteAll(_planes); } +float Sector::lightLevel() const +{ + return _lightLevel; +} + +const_pvec3f_t &Sector::lightColor() const +{ + return _lightColor; +} + +struct mobj_s *Sector::firstMobj() const +{ + return _mobjList; +} + +ddmobj_base_t &Sector::soundEmitter() +{ + return _soundEmitter; +} + +ddmobj_base_t const &Sector::soundEmitter() const +{ + return const_cast(const_cast(*this).soundEmitter()); +} + +AudioEnvironmentFactors const &Sector::audioEnvironmentFactors() const +{ + return _reverb; +} + +uint Sector::origIndex() const +{ + return _origIndex; +} + +int Sector::frameFlags() const +{ + return _frameFlags; +} + +int Sector::validCount() const +{ + return _validCount; +} + Plane &Sector::plane(int planeIndex) { if(planeIndex >= 0 && planeIndex < _planes.count()) @@ -88,39 +131,49 @@ Sector::BspLeafs const &Sector::reverbBspLeafs() const return _reverbBspLeafs; } +AABoxd const &Sector::aaBox() const +{ + return _aaBox; +} + +coord_t Sector::roughArea() const +{ + return _roughArea; +} + void Sector::updateAABox() { - V2d_Set(aaBox.min, DDMAXFLOAT, DDMAXFLOAT); - V2d_Set(aaBox.max, DDMINFLOAT, DDMINFLOAT); + V2d_Set(_aaBox.min, DDMAXFLOAT, DDMAXFLOAT); + V2d_Set(_aaBox.max, DDMINFLOAT, DDMINFLOAT); if(!_lines.count()) return; QListIterator lineIt(_lines); LineDef *line = lineIt.next(); - V2d_InitBox(aaBox.arvec2, line->aaBox().min); - V2d_AddToBox(aaBox.arvec2, line->aaBox().max); + V2d_InitBox(_aaBox.arvec2, line->aaBox().min); + V2d_AddToBox(_aaBox.arvec2, line->aaBox().max); while(lineIt.hasNext()) { line = lineIt.next(); - V2d_AddToBox(aaBox.arvec2, line->aaBox().min); - V2d_AddToBox(aaBox.arvec2, line->aaBox().max); + V2d_AddToBox(_aaBox.arvec2, line->aaBox().min); + V2d_AddToBox(_aaBox.arvec2, line->aaBox().max); } } -void Sector::updateArea() +void Sector::updateRoughArea() { // Only a very rough estimate is required. - roughArea = ((aaBox.maxX - aaBox.minX) / 128) * - ((aaBox.maxY - aaBox.minY) / 128); + _roughArea = ((_aaBox.maxX - _aaBox.minX) / 128) * + ((_aaBox.maxY - _aaBox.minY) / 128); } -void Sector::updateBaseOrigin() +void Sector::updateSoundEmitterOrigin() { - base.origin[VX] = (aaBox.minX + aaBox.maxX) / 2; - base.origin[VY] = (aaBox.minY + aaBox.maxY) / 2; - base.origin[VZ] = (floor().height() + ceiling().height()) / 2; + _soundEmitter.origin[VX] = (_aaBox.minX + _aaBox.maxX) / 2; + _soundEmitter.origin[VY] = (_aaBox.minY + _aaBox.maxY) / 2; + _soundEmitter.origin[VZ] = (floor().height() + ceiling().height()) / 2; } int Sector::property(setargs_t &args) const @@ -128,35 +181,35 @@ 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, &_lightLevel, &args, 0); break; case DMU_COLOR: - DMU_GetValue(DMT_SECTOR_RGB, &rgb[0], &args, 0); - DMU_GetValue(DMT_SECTOR_RGB, &rgb[1], &args, 1); - DMU_GetValue(DMT_SECTOR_RGB, &rgb[2], &args, 2); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[0], &args, 0); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[1], &args, 1); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[2], &args, 2); break; case DMU_COLOR_RED: - DMU_GetValue(DMT_SECTOR_RGB, &rgb[0], &args, 0); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[0], &args, 0); break; case DMU_COLOR_GREEN: - DMU_GetValue(DMT_SECTOR_RGB, &rgb[1], &args, 0); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[1], &args, 0); break; case DMU_COLOR_BLUE: - DMU_GetValue(DMT_SECTOR_RGB, &rgb[2], &args, 0); + DMU_GetValue(DMT_SECTOR_RGB, &_lightColor[2], &args, 0); break; case DMU_BASE: { - ddmobj_base_t const *baseAdr = &base; - DMU_GetValue(DMT_SECTOR_BASE, &baseAdr, &args, 0); + ddmobj_base_t const *soundEmitterAdr = &_soundEmitter; + DMU_GetValue(DMT_SECTOR_BASE, &soundEmitterAdr, &args, 0); break; } case DMU_LINEDEF_COUNT: { int val = _lines.count(); DMU_GetValue(DDVT_INT, &val, &args, 0); break; } case DMT_MOBJS: - DMU_GetValue(DMT_SECTOR_MOBJLIST, &mobjList, &args, 0); + DMU_GetValue(DMT_SECTOR_MOBJLIST, &_mobjList, &args, 0); break; case DMU_VALID_COUNT: - DMU_GetValue(DMT_SECTOR_VALIDCOUNT, &validCount, &args, 0); + DMU_GetValue(DMT_SECTOR_VALIDCOUNT, &_validCount, &args, 0); break; case DMU_FLOOR_PLANE: { Plane *pln = _planes[Plane::Floor]; @@ -179,24 +232,24 @@ int Sector::setProperty(setargs_t const &args) switch(args.prop) { case DMU_COLOR: - DMU_SetValue(DMT_SECTOR_RGB, &rgb[0], &args, 0); - DMU_SetValue(DMT_SECTOR_RGB, &rgb[1], &args, 1); - DMU_SetValue(DMT_SECTOR_RGB, &rgb[2], &args, 2); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[0], &args, 0); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[1], &args, 1); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[2], &args, 2); break; case DMU_COLOR_RED: - DMU_SetValue(DMT_SECTOR_RGB, &rgb[0], &args, 0); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[0], &args, 0); break; case DMU_COLOR_GREEN: - DMU_SetValue(DMT_SECTOR_RGB, &rgb[1], &args, 0); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[1], &args, 0); break; case DMU_COLOR_BLUE: - DMU_SetValue(DMT_SECTOR_RGB, &rgb[2], &args, 0); + DMU_SetValue(DMT_SECTOR_RGB, &_lightColor[2], &args, 0); break; case DMU_LIGHT_LEVEL: - DMU_SetValue(DMT_SECTOR_LIGHTLEVEL, &lightLevel, &args, 0); + DMU_SetValue(DMT_SECTOR_LIGHTLEVEL, &_lightLevel, &args, 0); break; case DMU_VALID_COUNT: - DMU_SetValue(DMT_SECTOR_VALIDCOUNT, &validCount, &args, 0); + DMU_SetValue(DMT_SECTOR_VALIDCOUNT, &_validCount, &args, 0); break; default: /// @throw WritePropertyError The requested property is not writable. diff --git a/doomsday/client/src/map/sidedef.cpp b/doomsday/client/src/map/sidedef.cpp index dcfa6cdfe2..217a433ff8 100644 --- a/doomsday/client/src/map/sidedef.cpp +++ b/doomsday/client/src/map/sidedef.cpp @@ -41,12 +41,12 @@ SideDef::SideDef() : de::MapElement(DMU_SIDEDEF) SideDef::~SideDef() {} -void SideDef::updateBaseOrigins() +void SideDef::updateSoundEmitterOrigins() { if(!line) return; - SW_middlesurface.updateBaseOrigin(); - SW_bottomsurface.updateBaseOrigin(); - SW_topsurface.updateBaseOrigin(); + SW_middlesurface.updateSoundEmitterOrigin(); + SW_bottomsurface.updateSoundEmitterOrigin(); + SW_topsurface.updateSoundEmitterOrigin(); } void SideDef::updateSurfaceTangents() diff --git a/doomsday/client/src/map/surface.cpp b/doomsday/client/src/map/surface.cpp index 238866ddf8..b315bb27b4 100644 --- a/doomsday/client/src/map/surface.cpp +++ b/doomsday/client/src/map/surface.cpp @@ -274,9 +274,9 @@ void Surface::update() inFlags |= SUIF_UPDATE_DECORATIONS; } -void Surface::updateBaseOrigin() +void Surface::updateSoundEmitterOrigin() { - LOG_AS("Surface::updateBaseOrigin"); + LOG_AS("Surface::updateSoundEmitterOrigin"); if(!owner) return; switch(owner->type()) @@ -285,8 +285,8 @@ void Surface::updateBaseOrigin() Plane *pln = owner->castTo(); Sector &sec = pln->sector(); - base.origin[VX] = sec.base.origin[VX]; - base.origin[VY] = sec.base.origin[VY]; + base.origin[VX] = sec.soundEmitter().origin[VX]; + base.origin[VY] = sec.soundEmitter().origin[VY]; base.origin[VZ] = pln->height(); break; } diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index 2c6b73443f..c6c8f3482e 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -1029,7 +1029,7 @@ static void createGlowLightForSurface(Surface &suf) } } -void LO_AddLuminousMobjs(void) +void LO_AddLuminousMobjs() { if(!useDynLights && !useWallGlow) return; if(!theMap) return; @@ -1040,9 +1040,9 @@ BEGIN_PROF( PROF_LUMOBJ_INIT_ADD ); { for(uint i = 0; i < NUM_SECTORS; ++i) { - Sector* sec = GameMap_Sector(theMap, i); + Sector *sec = GameMap_Sector(theMap, i); - for(mobj_t* iter = sec->mobjList; iter; iter = iter->sNext) + for(mobj_t *iter = sec->firstMobj(); iter; iter = iter->sNext) { iter->lumIdx = 0; addLuminous(iter); diff --git a/doomsday/client/src/render/r_lgrid.cpp b/doomsday/client/src/render/r_lgrid.cpp index 2bf62f0e23..85f2ec1920 100644 --- a/doomsday/client/src/render/r_lgrid.cpp +++ b/doomsday/client/src/render/r_lgrid.cpp @@ -517,24 +517,25 @@ void LG_InitForMap(void) Con_Message(" Sector %i: %i / %i", s, changedCount, count); #endif*/ - sector->changedBlockCount = changedCount; - sector->blockCount = changedCount + count; + Sector::LightGridData &lgData = sector->_lightGridData; + lgData.changedBlockCount = changedCount; + lgData.blockCount = changedCount + count; - if(sector->blockCount > 0) + if(lgData.blockCount > 0) { - sector->blocks = (unsigned short *) Z_Malloc(sizeof(unsigned short) * sector->blockCount, - PU_MAPSTATIC, 0); + lgData.blocks = (ushort *) Z_Malloc(sizeof(*lgData.blocks) * lgData.blockCount, PU_MAPSTATIC, 0); + for(x = 0, a = 0, b = changedCount; x < lgBlockWidth * lgBlockHeight; ++x) { if(HasIndexBit(x, 0, indexBitfield)) - sector->blocks[a++] = x; + lgData.blocks[a++] = x; else if(HasIndexBit(x, 0, contributorBitfield)) - sector->blocks[b++] = x; + lgData.blocks[b++] = x; } - assert(a == changedCount); - //assert(b == info->blockCount); + DENG_ASSERT(a == changedCount); + //DENG_ASSERT(b == info->blockCount); } } @@ -590,33 +591,37 @@ static void LG_ApplySector(gridblock_t *block, const float *color, float level, /** * Called when a sector has changed its light level. */ -void LG_SectorChanged(Sector* sector) +void LG_SectorChanged(Sector *sector) { if(!lgInited) return; - if(!sector || (!sector->changedBlockCount && !sector->blockCount)) return; + if(!sector) return; + + Sector::LightGridData &lgData = sector->_lightGridData; + if(!lgData.changedBlockCount && !lgData.blockCount) return; // Mark changed blocks and contributors. - { uint i; - for(i = 0; i < sector->changedBlockCount; ++i) + for(uint i = 0; i < lgData.changedBlockCount; ++i) { - ushort n = sector->blocks[i]; + ushort n = lgData.blocks[i]; + // The color will be recalculated. if(!(grid[n].flags & GBF_CHANGED)) - memcpy(grid[n].oldRGB, grid[n].rgb, sizeof(grid[n].oldRGB)); + { + std::memcpy(grid[n].oldRGB, grid[n].rgb, sizeof(grid[n].oldRGB)); + } - { int j; - for(j = 0; j < 3; ++j) + for(int j = 0; j < 3; ++j) + { grid[n].rgb[j] = 0; } grid[n].flags |= GBF_CHANGED | GBF_CONTRIBUTOR; - }} + } - { uint i; - for(i = 0; i < sector->blockCount; ++i) + for(uint i = 0; i < lgData.blockCount; ++i) { - grid[sector->blocks[i]].flags |= GBF_CONTRIBUTOR; - }} + grid[lgData.blocks[i]].flags |= GBF_CONTRIBUTOR; + } needsUpdate = true; } @@ -839,7 +844,7 @@ BEGIN_PROF( PROF_GRID_UPDATE ); if(other->flags & GBF_CHANGED) { - LG_ApplySector(other, color, sector->lightLevel, + LG_ApplySector(other, color, sector->lightLevel(), factors[(b + 2)*5 + a + 2]/8, bias); } } diff --git a/doomsday/client/src/render/r_main.cpp b/doomsday/client/src/render/r_main.cpp index 7975e52df4..6557010804 100644 --- a/doomsday/client/src/render/r_main.cpp +++ b/doomsday/client/src/render/r_main.cpp @@ -806,7 +806,7 @@ BEGIN_PROF( PROF_MOBJ_INIT_ADD ); for(uint i = 0; i < NUM_SECTORS; ++i) { Sector *sec = GameMap_Sector(theMap, i); - for(mobj_t *iter = sec->mobjList; iter; iter = iter->sNext) + for(mobj_t *iter = sec->firstMobj(); iter; iter = iter->sNext) { R_ObjlinkCreate(iter, OT_MOBJ); // For spreading purposes. } diff --git a/doomsday/client/src/render/r_things.cpp b/doomsday/client/src/render/r_things.cpp index 14cc69c241..bce8ab70fd 100644 --- a/doomsday/client/src/render/r_things.cpp +++ b/doomsday/client/src/render/r_things.cpp @@ -543,7 +543,7 @@ float R_ShadowStrength(mobj_t *mo) } else { - ambientLightLevel = mo->bspLeaf->sector().lightLevel; + ambientLightLevel = mo->bspLeaf->sector().lightLevel(); Rend_ApplyLightAdaptation(&ambientLightLevel); } @@ -923,7 +923,7 @@ void getLightingParams(coord_t x, coord_t y, coord_t z, BspLeaf *bspLeaf, else { Sector &sec = bspLeaf->sector(); - float lightLevel = sec.lightLevel; + float lightLevel = sec.lightLevel(); float const *secColor = R_GetSectorLightColor(&sec); /* if(spr->type == VSPR_DECORATION) diff --git a/doomsday/client/src/render/rend_bias.cpp b/doomsday/client/src/render/rend_bias.cpp index 835a56508d..982f75ea6e 100644 --- a/doomsday/client/src/render/rend_bias.cpp +++ b/doomsday/client/src/render/rend_bias.cpp @@ -688,15 +688,15 @@ BEGIN_PROF( PROF_BIAS_UPDATE ); Sector §or = P_BspLeafAtPoint(s->origin)->sector(); // The lower intensities are useless for light emission. - if(sector.lightLevel >= maxLevel) + if(sector.lightLevel() >= maxLevel) { s->intensity = s->primaryIntensity; } - if(sector.lightLevel >= minLevel && minLevel != maxLevel) + if(sector.lightLevel() >= minLevel && minLevel != maxLevel) { s->intensity = s->primaryIntensity * - (sector.lightLevel - minLevel) / (maxLevel - minLevel); + (sector.lightLevel() - minLevel) / (maxLevel - minLevel); } else { diff --git a/doomsday/client/src/render/rend_decor.cpp b/doomsday/client/src/render/rend_decor.cpp index 625430065b..36e1689593 100644 --- a/doomsday/client/src/render/rend_decor.cpp +++ b/doomsday/client/src/render/rend_decor.cpp @@ -96,7 +96,7 @@ static void projectSource(decorsource_t const &src) float min = decor->lightLevels[0]; float max = decor->lightLevels[1]; - float brightness = R_CheckSectorLight(src.bspLeaf->sector().lightLevel, min, max); + float brightness = R_CheckSectorLight(src.bspLeaf->sector().lightLevel(), min, max); if(!(brightness > 0)) return; if(src.fadeMul <= 0) return; @@ -187,7 +187,7 @@ static void addLuminousDecoration(decorsource_t &src) float min = decor->lightLevels[0]; float max = decor->lightLevels[1]; - float brightness = R_CheckSectorLight(src.bspLeaf->sector().lightLevel, min, max); + float brightness = R_CheckSectorLight(src.bspLeaf->sector().lightLevel(), min, max); if(!(brightness > 0)) return; // Apply the brightness factor (was calculated using sector lightlevel). @@ -454,14 +454,16 @@ static void plotSourcesForPlane(Plane &pln) Surface &suf = pln.surface(); if(!suf.material) return; - Sector &sec = pln.sector(); - Vector3d v1(sec.aaBox.minX, pln.type() == Plane::Floor? sec.aaBox.maxY : sec.aaBox.minY, pln.visHeight()); - Vector3d v2(sec.aaBox.maxX, pln.type() == Plane::Floor? sec.aaBox.minY : sec.aaBox.maxY, pln.visHeight()); + Sector §or = pln.sector(); + AABoxd const §orAABox = sector.aaBox(); - Vector2f offset(-fmod(sec.aaBox.minX, 64) - suf.visOffset[0], - -fmod(sec.aaBox.minY, 64) - suf.visOffset[1]); + Vector3d v1(sectorAABox.minX, pln.type() == Plane::Floor? sectorAABox.maxY : sectorAABox.minY, pln.visHeight()); + Vector3d v2(sectorAABox.maxX, pln.type() == Plane::Floor? sectorAABox.minY : sectorAABox.maxY, pln.visHeight()); - updateSurfaceDecorations(suf, offset, v1, v2, &sec); + Vector2f offset(-fmod(sectorAABox.minX, 64) - suf.visOffset[0], + -fmod(sectorAABox.minY, 64) - suf.visOffset[1]); + + updateSurfaceDecorations(suf, offset, v1, v2, §or); } static void plotSourcesForLineDef(LineDef &line, byte side, SideDefSection section) diff --git a/doomsday/client/src/render/rend_fakeradio.cpp b/doomsday/client/src/render/rend_fakeradio.cpp index 97ab652a1b..ec6c5f61c9 100644 --- a/doomsday/client/src/render/rend_fakeradio.cpp +++ b/doomsday/client/src/render/rend_fakeradio.cpp @@ -1449,7 +1449,7 @@ void Rend_RadioBspLeafEdges(BspLeaf &bspLeaf) static byte *doPlanes = 0; Sector §or = bspLeaf.sector(); - float sectorlight = sector.lightLevel; + float sectorlight = sector.lightLevel(); boolean workToDo = false; Rend_ApplyLightAdaptation(§orlight); diff --git a/doomsday/client/src/render/rend_main.cpp b/doomsday/client/src/render/rend_main.cpp index 510a9ea308..db13293d06 100644 --- a/doomsday/client/src/render/rend_main.cpp +++ b/doomsday/client/src/render/rend_main.cpp @@ -1386,7 +1386,7 @@ static void renderPlane(BspLeaf *bspLeaf, Plane::Type type, coord_t height, params.normal = normal; params.texTL = texTL; params.texBR = texBR; - params.sectorLightLevel = sec->lightLevel; + params.sectorLightLevel = sec->lightLevel(); params.sectorLightColor = R_GetSectorLightColor(sec); params.surfaceLightLevelDL = params.surfaceLightLevelDR = 0; params.surfaceColor = sufColor; @@ -1783,7 +1783,7 @@ static boolean Rend_RenderHEdge(HEdge *hedge, byte sections) { Rend_RadioUpdateLine(*hedge->lineDef, hedge->side); opaque = rendHEdgeSection(hedge, SS_MIDDLE, RHF_ADD_DYNLIGHTS|RHF_ADD_DYNSHADOWS|RHF_ADD_RADIO, - frontSec->lightLevel, R_GetSectorLightColor(frontSec), + frontSec->lightLevel(), R_GetSectorLightColor(frontSec), &leftWallDivs, &rightWallDivs, matOffset); } @@ -1845,7 +1845,7 @@ static boolean Rend_RenderHEdgeTwosided(HEdge *hedge, byte sections) Rend_RadioUpdateLine(*hedge->lineDef, hedge->side); solidSeg = rendHEdgeSection(hedge, SS_MIDDLE, rhFlags, - front->sector().lightLevel, R_GetSectorLightColor(front->sectorPtr()), + front->sector().lightLevel(), R_GetSectorLightColor(front->sectorPtr()), &leftWallDivs, &rightWallDivs, matOffset); if(solidSeg) { @@ -1885,7 +1885,7 @@ static boolean Rend_RenderHEdgeTwosided(HEdge *hedge, byte sections) { Rend_RadioUpdateLine(*hedge->lineDef, hedge->side); rendHEdgeSection(hedge, SS_TOP, RHF_ADD_DYNLIGHTS|RHF_ADD_DYNSHADOWS|RHF_ADD_RADIO, - front->sector().lightLevel, R_GetSectorLightColor(front->sectorPtr()), + front->sector().lightLevel(), R_GetSectorLightColor(front->sectorPtr()), &leftWallDivs, &rightWallDivs, matOffset); } } @@ -1901,7 +1901,7 @@ static boolean Rend_RenderHEdgeTwosided(HEdge *hedge, byte sections) { Rend_RadioUpdateLine(*hedge->lineDef, hedge->side); rendHEdgeSection(hedge, SS_BOTTOM, RHF_ADD_DYNLIGHTS|RHF_ADD_DYNSHADOWS|RHF_ADD_RADIO, - front->sector().lightLevel, R_GetSectorLightColor(front->sectorPtr()), + front->sector().lightLevel(), R_GetSectorLightColor(front->sectorPtr()), &leftWallDivs, &rightWallDivs, matOffset); } } @@ -2858,7 +2858,7 @@ static void Rend_RenderBspLeaf(BspLeaf *bspLeaf) // Mark the sector visible for this frame. Sector §or = bspLeaf->sector(); - sector.frameFlags |= SIF_VISIBLE; + sector._frameFlags |= SIF_VISIBLE; Rend_MarkSegsFacingFront(bspLeaf); @@ -3149,7 +3149,7 @@ static int drawSectorSoundOrigins(Sector *sec, void *parameters) if(devSoundOrigins & SOF_SECTOR) { dd_snprintf(buf, 80, "Sector #%i", sectorIndex); - drawSoundOrigin(sec->base.origin, buf, (coord_t const*) parameters); + drawSoundOrigin(sec->soundEmitter().origin, buf, (coord_t const*) parameters); } return false; // Continue iteration. @@ -3833,7 +3833,7 @@ static int drawMobjBBox(thinker_t *th, void * /*context*/) if(mo == ddPlayers[consolePlayer].shared.mo) return false; // Continue iteration. // Is it vissible? - if(!(mo->bspLeaf && mo->bspLeaf->sector().frameFlags & SIF_VISIBLE)) + if(!(mo->bspLeaf && mo->bspLeaf->sector().frameFlags() & SIF_VISIBLE)) return false; // Continue iteration. V3d_Set(eye, vOrigin[VX], vOrigin[VZ], vOrigin[VY]); diff --git a/doomsday/client/src/render/rend_particle.cpp b/doomsday/client/src/render/rend_particle.cpp index ed3d2d4000..4d3cf66d8b 100644 --- a/doomsday/client/src/render/rend_particle.cpp +++ b/doomsday/client/src/render/rend_particle.cpp @@ -313,7 +313,7 @@ static int populateSortBuffer(ptcgen_t* gen, void* parameters) continue; // Is the particle's sector visible? - if(!(pt->sector->frameFlags & SIF_VISIBLE)) + if(!(pt->sector->frameFlags() & SIF_VISIBLE)) continue; // No; this particle can't be seen. // Don't allow zero distance. @@ -463,8 +463,8 @@ static void setupModelParamsForParticle(rendmodelparams_t* params, } else { - float lightLevel = pt->sector->lightLevel; - const float* secColor = R_GetSectorLightColor(pt->sector); + float lightLevel = pt->sector->lightLevel(); + float const *secColor = R_GetSectorLightColor(pt->sector); // Apply distance attenuation. lightLevel = R_DistAttenuateLightLevel(params->distance, lightLevel); @@ -633,7 +633,7 @@ static void renderParticles(int rtype, boolean withBlend) // This is a simplified version of sectorlight (no distance // attenuation or range compression). if(pt->sector) - color[c] *= pt->sector->lightLevel; + color[c] *= pt->sector->lightLevel(); } } diff --git a/doomsday/client/src/render/rend_shadow.cpp b/doomsday/client/src/render/rend_shadow.cpp index 198358e1aa..5e93ffe5a2 100644 --- a/doomsday/client/src/render/rend_shadow.cpp +++ b/doomsday/client/src/render/rend_shadow.cpp @@ -181,10 +181,10 @@ void Rend_RenderMobjShadows() // We are only interested in those mobjs within sectors marked as // 'visible' for the current render frame (viewer dependent). - if(!(sec->frameFlags & SIF_VISIBLE)) continue; + if(!(sec->frameFlags() & SIF_VISIBLE)) continue; // Process all mobjs linked to this sector: - for(mobj_t *mo = sec->mobjList; mo; mo = mo->sNext) + for(mobj_t *mo = sec->firstMobj(); mo; mo = mo->sNext) { processMobjShadow(mo); } @@ -192,13 +192,13 @@ void Rend_RenderMobjShadows() } /// Generates a new primitive for each shadow projection. -int RIT_RenderShadowProjectionIterator(const shadowprojection_t* sp, void* paramaters) +int RIT_RenderShadowProjectionIterator(shadowprojection_t const *sp, void *parameters) { - static const float black[3] = { 0, 0, 0 }; - rendershadowprojectionparams_t* p = (rendershadowprojectionparams_t*)paramaters; - rvertex_t* rvertices; - rtexcoord_t* rtexcoords; - ColorRawf* rcolors; + static float const black[3] = { 0, 0, 0 }; + rendershadowprojectionparams_t *p = (rendershadowprojectionparams_t *)parameters; + rvertex_t *rvertices; + rtexcoord_t *rtexcoords; + ColorRawf *rcolors; uint i, c; // Allocate enough for the divisions too. diff --git a/doomsday/client/src/render/sprite.cpp b/doomsday/client/src/render/sprite.cpp index 64d5892373..4e11f18137 100644 --- a/doomsday/client/src/render/sprite.cpp +++ b/doomsday/client/src/render/sprite.cpp @@ -344,7 +344,7 @@ static void setupPSpriteParams(rendpspriteparams_t *params, vispsprite_t *spr) float const *secColor = R_GetSectorLightColor(§or); // No need for distance attentuation. - float lightLevel = sector.lightLevel; + float lightLevel = sector.lightLevel(); // Add extra light plus bonus. lightLevel += R_ExtraLightDelta(); @@ -731,7 +731,7 @@ static void setupModelParamsForVisPSprite(rendmodelparams_t *params, vispsprite_ float const *secColor = R_GetSectorLightColor(§or); // Diminished light (with compression). - float lightLevel = sector.lightLevel; + float lightLevel = sector.lightLevel(); // No need for distance attentuation. diff --git a/doomsday/libdeng1/include/de/vector1.h b/doomsday/libdeng1/include/de/vector1.h index 17f9cdacca..b861b87427 100644 --- a/doomsday/libdeng1/include/de/vector1.h +++ b/doomsday/libdeng1/include/de/vector1.h @@ -39,16 +39,21 @@ extern "C" { typedef float vectorcompf_t; typedef vectorcompf_t vec2f_t[2]; typedef float const const_pvec2f_t[2]; -typedef vectorcompf_t* pvec2f_t; -typedef vec2f_t* arvec2f_t; +typedef vectorcompf_t *pvec2f_t; + +typedef vec2f_t *arvec2f_t; +typedef vec2f_t const *const_arvec2f_t; // Double floating-point. typedef double vectorcompd_t; typedef vectorcompd_t vec2d_t[2]; typedef double const const_pvec2d_t[2]; -typedef vectorcompd_t* pvec2d_t; -typedef vectorcompd_t const * pcvec2d_t; -typedef vec2d_t* arvec2d_t; +typedef vectorcompd_t *pvec2d_t; + +typedef vec2d_t *arvec2d_t; +typedef vec2d_t const *const_arvec2d_t; + +typedef vectorcompd_t const *pcvec2d_t; /// @todo Remove me DENG_PUBLIC fixed_t V2x_Intersection(fixed_t const v1[2], fixed_t const v1Delta[2], fixed_t const v2[2], fixed_t const v2Delta[2]); @@ -329,9 +334,9 @@ DENG_PUBLIC void V2d_InitBox(arvec2d_t box, const_pvec2d_t point); DENG_PUBLIC void V2d_AddToBox(arvec2d_t box, const_pvec2d_t point); -DENG_PUBLIC void V2d_UniteBox(arvec2d_t box, arvec2d_t const other); +DENG_PUBLIC void V2d_UniteBox(arvec2d_t box, const_arvec2d_t other); -DENG_PUBLIC void V2d_CopyBox(arvec2d_t dest, arvec2d_t const src); +DENG_PUBLIC void V2d_CopyBox(arvec2d_t dest, const_arvec2d_t src); /// @} @@ -638,8 +643,8 @@ DENG_PUBLIC void V4f_Lerp(pvec4f_t dest, const_pvec4f_t a, const_pvec4f_t b, flo typedef vectorcompd_t vec4d_t[4]; typedef double const const_pvec4d_t[4]; -typedef vectorcompd_t* pvec4d_t; -typedef vec4d_t* arvec4d_t; +typedef vectorcompd_t *pvec4d_t; +typedef vec4d_t *arvec4d_t; /** * Set the vector's x, y, z and w components. diff --git a/doomsday/libdeng1/src/vector1.c b/doomsday/libdeng1/src/vector1.c index ddf2ca11ba..a34b4eef7b 100644 --- a/doomsday/libdeng1/src/vector1.c +++ b/doomsday/libdeng1/src/vector1.c @@ -640,7 +640,7 @@ void V2d_AddToBox(arvec2d_t box, const_pvec2d_t point) box[1][VY] = point[VY]; } -void V2d_UniteBox(arvec2d_t box, arvec2d_t const other) +void V2d_UniteBox(arvec2d_t box, const_arvec2d_t other) { if(other[0][VX] < box[0][VX]) box[0][VX] = other[0][VX]; @@ -655,7 +655,7 @@ void V2d_UniteBox(arvec2d_t box, arvec2d_t const other) box[1][VY] = other[1][VY]; } -void V2d_CopyBox(arvec2d_t dest, arvec2d_t const src) +void V2d_CopyBox(arvec2d_t dest, const_arvec2d_t src) { V2d_Copy(dest[0], src[0]); V2d_Copy(dest[1], src[1]); diff --git a/doomsday/server/src/server/sv_pool.cpp b/doomsday/server/src/server/sv_pool.cpp index 863fbe04da..291b9853ad 100644 --- a/doomsday/server/src/server/sv_pool.cpp +++ b/doomsday/server/src/server/sv_pool.cpp @@ -433,8 +433,8 @@ void Sv_RegisterSector(dt_sector_t *reg, uint number) { Sector *sec = SECTOR_PTR(number); - reg->lightLevel = sec->lightLevel; - std::memcpy(reg->rgb, sec->rgb, sizeof(reg->rgb)); + reg->lightLevel = sec->lightLevel(); + std::memcpy(reg->rgb, sec->lightColor(), sizeof(reg->rgb)); // @todo $nplanes for(uint i = 0; i < 2; ++i) // number of planes in sector. @@ -622,27 +622,27 @@ boolean Sv_RegisterComparePlayer(cregister_t* reg, uint number, } /** - * @return @c true, if the result is not void. + * @return @c true, if the result is not void. */ -boolean Sv_RegisterCompareSector(cregister_t* reg, uint number, - sectordelta_t* d, byte doUpdate) +boolean Sv_RegisterCompareSector(cregister_t *reg, uint number, + sectordelta_t *d, byte doUpdate) { - dt_sector_t* r = ®->sectors[number]; - const Sector* s = SECTOR_PTR(number); - int df = 0; + dt_sector_t *r = ®->sectors[number]; + Sector const *s = SECTOR_PTR(number); + int df = 0; // Determine which data is different. if(s->floorSurface().material != r->planes[PLN_FLOOR].surface.material) df |= SDF_FLOOR_MATERIAL; if(s->ceilingSurface().material != r->planes[PLN_CEILING].surface.material) df |= SDF_CEILING_MATERIAL; - if(r->lightLevel != s->lightLevel) + if(r->lightLevel != s->lightLevel()) df |= SDF_LIGHT; - if(r->rgb[0] != s->rgb[0]) + if(r->rgb[0] != s->lightColor()[0]) df |= SDF_COLOR_RED; - if(r->rgb[1] != s->rgb[1]) + if(r->rgb[1] != s->lightColor()[1]) df |= SDF_COLOR_GREEN; - if(r->rgb[2] != s->rgb[2]) + if(r->rgb[2] != s->lightColor()[2]) df |= SDF_COLOR_BLUE; if(r->planes[PLN_FLOOR].surface.rgba[0] != s->floorSurface().rgba[0]) @@ -1524,18 +1524,18 @@ coord_t Sv_MobjDistance(const mobj_t* mo, const ownerinfo_t* info, boolean isRea /** * Approximate the distance to the given sector. */ -coord_t Sv_SectorDistance(int index, const ownerinfo_t* info) +coord_t Sv_SectorDistance(int index, ownerinfo_t const *info) { - Sector* sector = SECTOR_PTR(index); + Sector *sector = SECTOR_PTR(index); - return M_ApproxDistance3(info->origin[VX] - sector->base.origin[VX], - info->origin[VY] - sector->base.origin[VY], - (info->origin[VZ] - sector->base.origin[VZ]) * 1.2); + return M_ApproxDistance3(info->origin[VX] - sector->soundEmitter().origin[VX], + info->origin[VY] - sector->soundEmitter().origin[VY], + (info->origin[VZ] - sector->soundEmitter().origin[VZ]) * 1.2); } coord_t Sv_SideDistance(int index, int deltaFlags, ownerinfo_t const *info) { - SideDef* side = SIDE_PTR(index); + SideDef *side = SIDE_PTR(index); ddmobj_base_t *base = (deltaFlags & SNDDF_SIDE_MIDDLE? &side->SW_middlesurface.base : deltaFlags & SNDDF_SIDE_TOP? &side->SW_topsurface.base