Skip to content

Commit

Permalink
Refactor|Sector: Moved all Sector_* functions to methods of Sector
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 12, 2013
1 parent 7a56237 commit 2d3b838
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 174 deletions.
195 changes: 113 additions & 82 deletions doomsday/client/include/map/sector.h
@@ -1,9 +1,7 @@
/**
* @file sector.h
* Map Sector. @ingroup map
/** @file sector.h Map Sector.
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -23,17 +21,22 @@
#ifndef LIBDENG_MAP_SECTOR
#define LIBDENG_MAP_SECTOR

#ifndef __cplusplus
# error "map/sector.h requires C++"
#endif

#include "MapElement"
#include <QList>
#include <de/aabox.h>
#include <de/Error>
#include "map/plane.h"
#include "p_mapdata.h"
#include "p_dmu.h"
#include <QList>
#include "MapElement"

// Helper macros for accessing sector floor/ceiling plane data elements.
class BspLeaf;
class LineDef;

/*
* Helper macros for accessing the Planes of a Sector:
*/
/// @addtogroup map
///@{
#define SP_plane(n) planes[(n)]

#define SP_planesurface(n) SP_plane(n)->surface()
Expand Down Expand Up @@ -71,51 +74,86 @@
#define SP_floortarget SP_planetarget(Plane::Floor)
#define SP_floorspeed SP_planespeed(Plane::Floor)
#define SP_floorvisheight SP_planevisheight(Plane::Floor)

#define S_skyfix(n) skyFix[(n)]
#define S_floorskyfix S_skyfix(Plane::Floor)
#define S_ceilskyfix S_skyfix(Plane::Ceiling)
///@}

// 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

typedef struct msector_s {
// Sector index. Always valid after loading & pruning.
/// Sector index. Always valid after loading & pruning.
int index;
int refCount;
} msector_t;

class Plane;

/**
* Map sector.
*
* @ingroup map
*/
class Sector : public de::MapElement
{
public:
/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);

/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);

public: /// @todo Make private:
typedef QList<Plane *> Planes;

int frameFlags;
int validCount; // if == validCount, already checked.
AABoxd aaBox; // Bounding box for the sector.
coord_t roughArea; // Rough approximation of sector area.
float lightLevel;
float oldLightLevel;
float rgb[3];
float oldRGB[3];
struct mobj_s* mobjList; // List of mobjs in the sector.
unsigned int lineDefCount;
LineDef** lineDefs; // [lineDefCount+1] size.
unsigned int bspLeafCount;
BspLeaf** bspLeafs; // [bspLeafCount+1] size.
unsigned int numReverbBspLeafAttributors;
BspLeaf** reverbBspLeafs; // [numReverbBspLeafAttributors] size.
ddmobj_base_t base;
Planes planes;
unsigned int blockCount; // Number of gridblocks in the sector.
unsigned int changedBlockCount; // Number of blocks to mark changed.
unsigned short* blocks; // Light grid block indices.
float reverb[NUM_REVERB_DATA];
msector_t buildData;
int frameFlags;

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

/// Bounding box for the sector.
AABoxd aaBox;

/// Rough approximation of sector area.
coord_t roughArea;

float lightLevel;

float oldLightLevel;

float rgb[3];

float oldRGB[3];

/// List of mobjs in the sector.
struct mobj_s *mobjList;

/// [lineDefCount+1] size.
LineDef **lineDefs;
uint lineDefCount;

/// [bspLeafCount+1] size.
BspLeaf **bspLeafs;
uint bspLeafCount;

/// [numReverbBspLeafAttributors] size.
BspLeaf **reverbBspLeafs;
uint numReverbBspLeafAttributors;

ddmobj_base_t base;

Planes planes;

/// Number of gridblocks in the sector.
uint blockCount;

/// Number of blocks to mark changed.
uint changedBlockCount;

/// Light grid block indices.
ushort *blocks;

float reverb[NUM_REVERB_DATA];

msector_t buildData;

public:
Sector();
Expand All @@ -141,51 +179,44 @@ class Sector : public de::MapElement

/// @copydoc ceiling()
inline Plane const &ceiling() const { return *planes[Plane::Ceiling]; }
};

/**
* Update the Sector's map space axis-aligned bounding box to encompass the points
* defined by it's LineDefs' vertices.
*
* @pre LineDef list must have been initialized.
*
* @param sector Sector instance.
*/
void Sector_UpdateAABox(Sector* sector);
/**
* 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.
*/
void updateAABox();

/**
* Update the Sector's rough area approximation.
*
* @pre Axis-aligned bounding box must have been initialized.
*
* @param sector Sector instance.
*/
void Sector_UpdateArea(Sector* sector);
/**
* Update the sector's rough area approximation.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateArea();

/**
* 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).
*
* @param sector Sector instance.
*/
void Sector_UpdateBaseOrigin(Sector *sector);
/**
* 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();

/**
* Get a property value, selected by DMU_* name.
*
* @param sector Sector instance.
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int Sector_GetProperty(const Sector* sector, setargs_t* args);
/**
* Get a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int property(setargs_t &args) const;

/**
* Update a property value, selected by DMU_* name.
*
* @param sector Sector instance.
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int Sector_SetProperty(Sector* sector, const setargs_t* args);
/**
* Update a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);
};

#endif // LIBDENG_MAP_SECTOR
4 changes: 2 additions & 2 deletions doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -300,7 +300,7 @@ static boolean calcBspLeafReverb(BspLeaf* bspLeaf)
return true;
}

static void Sector_CalculateReverb(Sector* sec)
static void calculateSectorReverb(Sector *sec)
{
if(!sec || !sec->lineDefCount) return;

Expand Down Expand Up @@ -392,7 +392,7 @@ void S_UpdateReverbForSector(Sector* sec)
// If update has been requested for this sector, calculate it now.
if(reverbUpdateRequested.find(sec) != reverbUpdateRequested.end())
{
Sector_CalculateReverb(sec);
calculateSectorReverb(sec);
reverbUpdateRequested.erase(sec);
}
}
Expand Down
18 changes: 9 additions & 9 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -615,26 +615,26 @@ static void buildSectorLineLists(GameMap* map)
M_Free(sectorLineLinks);
}

static void finishSectors(GameMap* map)
static void finishSectors(GameMap *map)
{
DENG_ASSERT(map);

for(uint i = 0; i < map->sectorCount(); ++i)
{
Sector* sec = &map->sectors[i];
Sector &sec = map->sectors[i];

Sector_UpdateAABox(sec);
Sector_UpdateArea(sec);
Sector_UpdateBaseOrigin(sec);
sec.updateAABox();
sec.updateArea();
sec.updateBaseOrigin();

// Set the position of the sound origin for all plane sound origins.
// Set target heights for all planes.
for(uint k = 0; k < sec->planeCount(); ++k)
for(uint k = 0; k < sec.planeCount(); ++k)
{
Plane *pln = sec->planes[k];
Plane &pln = *sec.planes[k];

pln->surface().updateBaseOrigin();
pln->_targetHeight = pln->_height;
pln.surface().updateBaseOrigin();
pln._targetHeight = pln._height;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/dam_file.cpp
Expand Up @@ -537,7 +537,7 @@ static void readSector(GameMap *map, uint idx)
s->aaBox.maxX = readFloat();
s->aaBox.maxY = readFloat();

Sector_UpdateBaseOrigin(s);
s->updateBaseOrigin();
for(i = 0; i < numPlanes; ++i)
{
Plane *pln = s->planes[i];
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/p_dmu.cpp
Expand Up @@ -1038,7 +1038,7 @@ static int setProperty(void *ptr, void *context)
break;

case DMU_SECTOR:
Sector_SetProperty(elem->castTo<Sector>(), args);
elem->castTo<Sector>()->setProperty(*args);
break;

case DMU_MATERIAL:
Expand Down Expand Up @@ -1520,7 +1520,7 @@ static int getProperty(void *ptr, void *context)
break;

case DMU_SECTOR:
Sector_GetProperty(elem->castTo<Sector>(), args);
elem->castTo<Sector>()->property(*args);
break;

case DMU_SIDEDEF:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/r_world.cpp
Expand Up @@ -1491,7 +1491,7 @@ boolean R_UpdateSector(Sector *sec, boolean forceUpdate)

if(forceUpdate || planeChanged)
{
Sector_UpdateBaseOrigin(sec);
sec->updateBaseOrigin();
R_UpdateLinedefsOfSector(sec);
S_MarkSectorReverbDirty(sec);
changed = true;
Expand Down

0 comments on commit 2d3b838

Please sign in to comment.