Skip to content

Commit

Permalink
Refactor|Map: Separated thinker and thinker list from Map to new clas…
Browse files Browse the repository at this point in the history
…s Thinkers

Functionally unchanged. However the implementation was cleaned up and
the list array replaced with a QList.

Applied solely to cleanup the Map API.

Todo for later: Replace this krusty old mechanism with the far better
solution developed by skyjake in the old 'new-order' branch(es).
  • Loading branch information
danij-deng committed Jun 14, 2013
1 parent f3a037a commit e6eb617
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 387 deletions.
3 changes: 2 additions & 1 deletion doomsday/client/client.pro
Expand Up @@ -390,6 +390,7 @@ DENG_HEADERS += \
include/world/sector.h \
include/world/segment.h \
include/world/surface.h \
include/world/thinkers.h \
include/world/vertex.h \
include/world/world.h \
src/updater/downloaddialog.h \
Expand Down Expand Up @@ -673,7 +674,6 @@ SOURCES += \
src/world/p_objlink.cpp \
src/world/p_particle.cpp \
src/world/p_players.cpp \
src/world/p_think.cpp \
src/world/p_ticker.cpp \
src/world/plane.cpp \
src/world/polyobj.cpp \
Expand All @@ -683,6 +683,7 @@ SOURCES += \
src/world/sector.cpp \
src/world/segment.cpp \
src/world/surface.cpp \
src/world/thinkers.cpp \
src/world/vertex.cpp \
src/world/world.cpp

Expand Down
211 changes: 55 additions & 156 deletions doomsday/client/include/world/map.h
Expand Up @@ -36,8 +36,6 @@ class Sector;
class Segment;
class Vertex;

struct thinkerlist_s;

#ifdef __CLIENT__

struct clmoinfo_s;
Expand Down Expand Up @@ -78,6 +76,7 @@ class Generators;
class LightGrid;
#endif
class Mesh;
class Thinkers;

/**
* World map.
Expand Down Expand Up @@ -116,24 +115,6 @@ class Map
#endif

public: /// @todo make private:
struct thinkers_s {
int idtable[2048]; // 65536 bits telling which IDs are in use.
ushort iddealer;

size_t numLists;
struct thinkerlist_s **lists;
boolean inited;

thinkers_s()
: iddealer(0),
numLists(0),
lists(0),
inited(false)
{
zap(idtable);
}
} thinkers;

#ifdef __CLIENT__
cmhash_t clMobjHash[CLIENT_MOBJ_HASH_SIZE];

Expand Down Expand Up @@ -181,18 +162,6 @@ class Map
*/
AABoxd const &bounds() const;

/**
* @copydoc bounds()
*
* Return values:
* @param min Coordinates for the minimal point are written here.
* @param max Coordinates for the maximal point are written here.
*/
inline void bounds(coord_t *min, coord_t *max) const {
if(min) V2d_Copy(min, bounds().min);
if(max) V2d_Copy(max, bounds().max);
}

/**
* Returns the currently effective gravity multiplier for the map.
*/
Expand All @@ -210,28 +179,61 @@ class Map
*/
int ambientLightLevel() const;

/**
* Provides access to the thinker lists for the map.
*/
Thinkers /*const*/ &thinkers() const;

/**
* Provides a list of all the non-editable vertexes in the map.
*/
Vertexes const &vertexes() const;

inline int vertexCount() const { return vertexes().count(); }

/**
* Provides a list of all the non-editable lines in the map.
*/
Lines const &lines() const;

inline int lineCount() const { return lines().count(); }

inline int sideCount() const { return lines().count() * 2; }

/**
* Provides a list of all the non-editable sectors in the map.
*/
Sectors const &sectors() const;

inline int sectorCount() const { return sectors().count(); }
/**
* Provides a list of all the non-editable polyobjs in the map.
*/
Polyobjs const &polyobjs() const;

/**
* Provides access to the list of line segments for efficient traversal.
*/
Segments const &segments() const;

/**
* Provides access to the list of BSP nodes for efficient traversal.
*/
BspNodes const &bspNodes() const;

/**
* Provides access to the list of BSP leafs for efficient traversal.
*/
BspLeafs const &bspLeafs() const;

inline int vertexCount() const { return vertexes().count(); }

inline int lineCount() const { return lines().count(); }

inline int sideCount() const { return lines().count() * 2; }

inline int sectorCount() const { return sectors().count(); }

inline int polyobjCount() const { return polyobjs().count(); }

inline int segmentCount() const { return segments().count(); }

inline int bspNodeCount() const { return bspNodes().count(); }

inline int bspLeafCount() const { return bspLeafs().count(); }

/**
* Given an @a emitter origin, attempt to identify the map element
Expand All @@ -248,16 +250,6 @@ class Map
bool identifySoundEmitter(ddmobj_base_t const &emitter, Sector **sector,
Polyobj **poly, Plane **plane, Surface **surface) const;

/**
* Provides a list of all the non-editable polyobjs in the map.
*/
Polyobjs const &polyobjs() const;

/**
* Returns the total number of Polyobjs in the map.
*/
inline int polyobjCount() const { return polyobjs().count(); }

/**
* Locate a polyobj in the map by unique in-map tag.
*
Expand All @@ -271,36 +263,6 @@ class Map
*/
MapElement *bspRoot() const;

/**
* Provides access to the list of line segments for efficient traversal.
*/
Segments const &segments() const;

/**
* Returns the total number of line segments in the map.
*/
inline int segmentCount() const { return segments().count(); }

/**
* Provides access to the list of BSP nodes for efficient traversal.
*/
BspNodes const &bspNodes() const;

/**
* Returns the total number of BspNodes in the map.
*/
inline int bspNodeCount() const { return bspNodes().count(); }

/**
* Provides access to the list of BSP leafs for efficient traversal.
*/
BspLeafs const &bspLeafs() const;

/**
* Returns the total number of BspLeafs in the map.
*/
inline int bspLeafCount() const { return bspLeafs().count(); }

/**
* Determine the BSP leaf on the back side of the BS partition that lies
* in front of the specified point within the map's coordinate space.
Expand Down Expand Up @@ -534,7 +496,7 @@ class Map

struct clplane_s *clPlaneBySectorIndex(int index, clplanetype_t type);

boolean isValidClPlane(int i);
bool isValidClPlane(int i);

/**
* @note Assumes there is no existing ClPolyobj for Polyobj @a index.
Expand All @@ -547,7 +509,7 @@ class Map

struct clpolyobj_s *clPolyobjByPolyobjIndex(int index);

boolean isValidClPolyobj(int i);
bool isValidClPolyobj(int i);

/**
* Returns the set of decorated surfaces for the map.
Expand Down Expand Up @@ -613,66 +575,6 @@ class Map
*/
Line::Side *sideByIndex(int index) const;

/**
* Returns @c true iff the thinker lists been initialized.
*/
boolean thinkerListInited() const;

/**
* Init the thinker lists.
*
* @param flags @c 0x1 = Init public thinkers.
* @c 0x2 = Init private (engine-internal) thinkers.
*/
void initThinkerLists(byte flags);

/**
* Iterate the list of thinkers making a callback for each.
*
* @param thinkFunc If not @c NULL, only make a callback for thinkers
* whose function matches this.
* @param flags Thinker filter flags.
* @param callback The callback to make. Iteration will continue
* until a callback returns a non-zero value.
* @param context Passed to the callback function.
*/
int iterateThinkers(thinkfunc_t thinkFunc, byte flags,
int (*callback) (thinker_t *th, void *), void *context);

/**
* @param thinker Thinker to be added.
* @param makePublic @c true = @a thinker will be visible publically
* via the Doomsday public API thinker interface(s).
*/
void thinkerAdd(thinker_t &thinker, boolean makePublic);

/**
* Deallocation is lazy -- it will not actually be freed until its
* thinking turn comes up.
*/
void thinkerRemove(thinker_t &thinker);

/**
* Locates a mobj by it's unique identifier in the map.
*
* @param id Unique id of the mobj to lookup.
*/
struct mobj_s *mobjById(int id);

/// @todo Make private.
void clearMobjIds();

/**
* @param id Thinker id to test.
*/
boolean isUsedMobjId(thid_t id);

/**
* @param id New thinker id.
* @param inUse In-use state of @a id. @c true = the id is in use.
*/
void setMobjId(thid_t id, boolean inUse);

public: /// @todo Make private:

/**
Expand Down Expand Up @@ -721,24 +623,21 @@ class Map
* a full update.
*/
void initLightGrid();
#endif

/**
* To be called in response to a Material property changing which may
* require updating any map surfaces which are presently using it.
*
* @todo Replace with a de::Observers-based mechanism.
*/
void updateSurfacesOnMaterialChange(Material &material);
void updateMissingMaterialsForLinesOfSector(Sector const &sec);

#ifdef __CLIENT__
#endif // __CLIENT__

/**
* To be called in response to a Material property changing which may
* require updating any map surfaces which are presently using it.
*
* @todo Replace with a de::Observers-based mechanism.
*/
void updateMissingMaterialsForLinesOfSector(Sector const &sec);

#endif // __CLIENT__
void updateSurfacesOnMaterialChange(Material &material);

public:
/*
Expand All @@ -765,27 +664,27 @@ class Map
*/
Vertexes const &editableVertexes() const;

inline int editableVertexCount() const { return editableVertexes().count(); }

/**
* Provides a list of all the editable lines in the map.
*/
Lines const &editableLines() const;

inline int editableLineCount() const { return editableLines().count(); }

/**
* Provides a list of all the editable sectors in the map.
*/
Sectors const &editableSectors() const;

inline int editableSectorCount() const { return editableSectors().count(); }

/**
* Provides a list of all the editable polyobjs in the map.
*/
Polyobjs const &editablePolyobjs() const;

inline int editableVertexCount() const { return editableVertexes().count(); }

inline int editableLineCount() const { return editableLines().count(); }

inline int editableSectorCount() const { return editableSectors().count(); }

inline int editablePolyobjCount() const { return editablePolyobjs().count(); }

private:
Expand Down

0 comments on commit e6eb617

Please sign in to comment.