From 5d4ea4d17af2a023e73d8e323a26a684bb5b242c Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 3 Apr 2013 00:38:35 +0100 Subject: [PATCH] Refactor|GameMap: Use a regular QList for the map elements Also replaced the various GameMap_* functions for traversing these lists with an appropriate in-place traversal of the relevant list. --- doomsday/client/include/map/gamemap.h | 41 ++--- doomsday/client/src/client/cl_world.cpp | 19 +- doomsday/client/src/edit_map.cpp | 212 +++++++++++------------ doomsday/client/src/map/dam_file.cpp | 14 +- doomsday/client/src/map/gamemap.cpp | 124 +++---------- doomsday/client/src/map/r_world.cpp | 48 ++--- doomsday/client/src/render/rend_main.cpp | 83 ++++----- doomsday/server/src/shelluser.cpp | 9 +- 8 files changed, 221 insertions(+), 329 deletions(-) diff --git a/doomsday/client/include/map/gamemap.h b/doomsday/client/include/map/gamemap.h index 3c465752ae..bec4412c42 100644 --- a/doomsday/client/include/map/gamemap.h +++ b/doomsday/client/include/map/gamemap.h @@ -72,6 +72,11 @@ typedef struct skyfix_s { class GameMap { public: + typedef QList Vertexes; + typedef QList Sectors; + typedef QList Lines; + typedef QList SideDefs; + typedef QList HEdges; typedef QList BspNodes; typedef QList BspLeafs; @@ -98,10 +103,10 @@ class GameMap struct clpolyobj_s *clActivePolyobjs[CLIENT_MAX_MOVERS]; // End client only data. - de::MapElementList vertexes; - de::MapElementList sectors; - de::MapElementList lines; - de::MapElementList sideDefs; + Vertexes _vertexes; + Sectors _sectors; + Lines _lines; + SideDefs _sideDefs; uint numPolyObjs; Polyobj **polyObjs; @@ -151,13 +156,21 @@ class GameMap virtual ~GameMap(); - uint vertexCount() const { return vertexes.size(); } + Vertexes const &vertexes() const { return _vertexes; } + + inline uint vertexCount() const { return vertexes().size(); } + + SideDefs const &sideDefs() const { return _sideDefs; } - uint sectorCount() const { return sectors.size(); } + inline uint sideDefCount() const { return sideDefs().size(); } - uint sideDefCount() const { return sideDefs.size(); } + Lines const &lines() const { return _lines; } - uint lineCount() const { return lines.size(); } + inline uint lineCount() const { return lines().size(); } + + Sectors const §ors() const { return _sectors; } + + inline uint sectorCount() const { return sectors().size(); } /** * Returns the root element for the map's BSP tree. @@ -767,8 +780,6 @@ int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box, */ void GameMap_LinkLineDef(GameMap *map, LineDef *line); -int GameMap_LineDefIterator(GameMap *map, int (*callback) (LineDef *, void *), void *parameters); - int GameMap_LineDefsBoxIterator(GameMap *map, AABoxd const *box, int (*callback) (LineDef *, void *), void *parameters); @@ -826,16 +837,6 @@ int GameMap_PolyobjsBoxIterator(GameMap *map, AABoxd const *box, int GameMap_PolyobjIterator(GameMap *map, int (*callback) (Polyobj *, void *), void *parameters); -int GameMap_VertexIterator(GameMap *map, int (*callback) (Vertex *, void *), void *parameters); - -int GameMap_SideDefIterator(GameMap *map, int (*callback) (SideDef *, void *), void *parameters); - -int GameMap_SectorIterator(GameMap *map, int (*callback)(Sector *, void *), void *parameters); - -int GameMap_HEdgeIterator(GameMap *map, int (*callback) (HEdge *, void *), void *parameters); - -int GameMap_BspNodeIterator(GameMap *map, int (*callback) (BspNode *, void *), void *parameters); - /** * Traces a line between @a from and @a to, making a callback for each * interceptable object linked within Blockmap cells which cover the path this diff --git a/doomsday/client/src/client/cl_world.cpp b/doomsday/client/src/client/cl_world.cpp index d725a6e41a..842de66f88 100644 --- a/doomsday/client/src/client/cl_world.cpp +++ b/doomsday/client/src/client/cl_world.cpp @@ -388,24 +388,23 @@ void Cl_MoverThinker(clplane_t* mover) } } -clplane_t* GameMap_NewClPlane(GameMap* map, uint sectorIndex, clplanetype_t type, coord_t dest, float speed) +clplane_t *GameMap_NewClPlane(GameMap *map, uint sectorIndex, clplanetype_t type, coord_t dest, float speed) { + DENG_ASSERT(map); + int dmuPlane = (type == CPT_FLOOR ? DMU_FLOOR_OF_SECTOR : DMU_CEILING_OF_SECTOR); - clplane_t* mov; - int i; - assert(map); DEBUG_Message(("GameMap_NewClPlane: Sector #%i, type:%s, dest:%f, speed:%f\n", sectorIndex, type==CPT_FLOOR? "floor" : "ceiling", dest, speed)); - if((int)sectorIndex >= map->sectors.size()) + if(int( sectorIndex ) >= map->_sectors.size()) { - assert(0); // Invalid Sector index. - return NULL; + DENG_ASSERT(false); // Invalid Sector index. + return 0; } // Remove any existing movers for the same plane. - for(i = 0; i < CLIENT_MAX_MOVERS; ++i) + for(int i = 0; i < CLIENT_MAX_MOVERS; ++i) { if(GameMap_IsValidClPlane(map, i) && map->clActivePlanes[i]->sectorIndex == sectorIndex && @@ -419,14 +418,14 @@ clplane_t* GameMap_NewClPlane(GameMap* map, uint sectorIndex, clplanetype_t type } // Add a new mover. - for(i = 0; i < CLIENT_MAX_MOVERS; ++i) + for(int i = 0; i < CLIENT_MAX_MOVERS; ++i) { if(map->clActivePlanes[i]) continue; DEBUG_Message(("GameMap_NewClPlane: ...new mover [%i]\n", i)); // Allocate a new clplane_t thinker. - mov = map->clActivePlanes[i] = (clplane_t *) Z_Calloc(sizeof(clplane_t), PU_MAP, &map->clActivePlanes[i]); + clplane_t *mov = map->clActivePlanes[i] = (clplane_t *) Z_Calloc(sizeof(clplane_t), PU_MAP, &map->clActivePlanes[i]); mov->thinker.function = reinterpret_cast(Cl_MoverThinker); mov->type = type; mov->sectorIndex = sectorIndex; diff --git a/doomsday/client/src/edit_map.cpp b/doomsday/client/src/edit_map.cpp index 531e69717e..4486fd2e17 100644 --- a/doomsday/client/src/edit_map.cpp +++ b/doomsday/client/src/edit_map.cpp @@ -573,33 +573,31 @@ static void pruneMapElements(EditMap & /*e_map*/, int /*flags*/) static void buildSectorBspLeafLists(GameMap &map) { - for(uint i = 0; i < map.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) { - Sector §or = map.sectors[i]; - - sector._bspLeafs.clear(); + sector->_bspLeafs.clear(); #ifdef DENG2_QT_4_7_OR_NEWER uint count = 0; for(uint k = 0; k < map.bspLeafCount(); ++k) { BspLeaf *bspLeaf = map.bspLeafs[k]; - if(bspLeaf->sectorPtr() == §or) + if(bspLeaf->sectorPtr() == sector) ++count; } if(0 == count) continue; - sector._bspLeafs.reserve(count); + sector->_bspLeafs.reserve(count); #endif - for(uint k = 0; k < map.bspLeafCount(); ++k) + for(uint i = 0; i < map.bspLeafCount(); ++i) { - BspLeaf *bspLeaf = map.bspLeafs[k]; - if(bspLeaf->sectorPtr() == §or) + BspLeaf *bspLeaf = map.bspLeafs[i]; + if(bspLeaf->sectorPtr() == sector) { // Ownership of the BSP leaf is not given to the sector. - sector._bspLeafs.append(bspLeaf); + sector->_bspLeafs.append(bspLeaf); } } } @@ -619,10 +617,8 @@ static void buildSectorLineLists(GameMap &map) zblockset_t *lineLinksBlockSet = ZBlockSet_New(sizeof(LineLink), 512, PU_APPSTATIC); LineLink **sectorLineLinks = (LineLink **) Z_Calloc(sizeof(*sectorLineLinks) * map.sectorCount(), PU_APPSTATIC, 0); - for(uint i = 0; i < map.lineCount(); ++i) + foreach(LineDef *line, map.lines()) { - LineDef *line = &map.lines[i]; - if(line->hasFrontSector()) { int const sectorIndex = GameMap_SectorIndex(&map, &line->frontSector()); @@ -645,18 +641,18 @@ static void buildSectorLineLists(GameMap &map) } // Build the actual sector line lists. - for(uint i = 0; i < map.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) { - Sector *sector = &map.sectors[i]; + int const sectorIndex = GameMap_SectorIndex(&map, sector); sector->_lines.clear(); - if(!sectorLineLinks[i]) continue; + if(!sectorLineLinks[sectorIndex]) continue; #ifdef DENG2_QT_4_7_OR_NEWER // Count the total number of lines in this sector. uint numLines = 0; - for(LineLink *link = sectorLineLinks[i]; link; link = link->next) + for(LineLink *link = sectorLineLinks[sectorIndex]; link; link = link->next) { numLines++; } @@ -671,7 +667,7 @@ static void buildSectorLineLists(GameMap &map) * * Sort: Original line index, ascending. */ - for(LineLink *link = sectorLineLinks[i]; link; link = link->next) + for(LineLink *link = sectorLineLinks[sectorIndex]; link; link = link->next) { // Ownership of the line is not given to the sector. sector->_lines.prepend(link->line); @@ -703,47 +699,45 @@ static void finishSectors(GameMap &map) buildSectorBspLeafLists(map); buildSectorLineLists(map); - for(uint i = 0; i < map.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) { - Sector §or = map.sectors[i]; - - sector.updateAABox(); - sector.updateRoughArea(); - sector.updateSoundEmitterOrigin(); + sector->updateAABox(); + sector->updateRoughArea(); + sector->updateSoundEmitterOrigin(); /* * Chain sound emitters (ddmobj_base_t) owned by all Surfaces in the - * sector. These chains are used for efficiently traversing all of the + * 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). */ - ddmobj_base_t &emitter = sector.soundEmitter(); + ddmobj_base_t &emitter = sector->soundEmitter(); // Clear the head of the emitter chain. emitter.thinker.next = emitter.thinker.prev = 0; // Link plane surface emitters: - foreach(Plane *plane, sector.planes()) + foreach(Plane *plane, sector->planes()) { - linkToSectorEmitterChain(sector, plane->surface().soundEmitter()); + linkToSectorEmitterChain(*sector, plane->surface().soundEmitter()); } // Link wall surface emitters: - foreach(LineDef *line, sector.lines()) + foreach(LineDef *line, sector->lines()) { - if(line->frontSectorPtr() == §or) + if(line->frontSectorPtr() == sector) { SideDef &side = line->frontSideDef(); - linkToSectorEmitterChain(sector, side.middle().soundEmitter()); - linkToSectorEmitterChain(sector, side.bottom().soundEmitter()); - linkToSectorEmitterChain(sector, side.top().soundEmitter()); + linkToSectorEmitterChain(*sector, side.middle().soundEmitter()); + linkToSectorEmitterChain(*sector, side.bottom().soundEmitter()); + linkToSectorEmitterChain(*sector, side.top().soundEmitter()); } - if(line->hasBackSideDef() && line->backSectorPtr() == §or) + if(line->hasBackSideDef() && line->backSectorPtr() == sector) { SideDef &side = line->backSideDef(); - linkToSectorEmitterChain(sector, side.middle().soundEmitter()); - linkToSectorEmitterChain(sector, side.bottom().soundEmitter()); - linkToSectorEmitterChain(sector, side.top().soundEmitter()); + linkToSectorEmitterChain(*sector, side.middle().soundEmitter()); + linkToSectorEmitterChain(*sector, side.bottom().soundEmitter()); + linkToSectorEmitterChain(*sector, side.top().soundEmitter()); } } } @@ -752,32 +746,30 @@ static void finishSectors(GameMap &map) static void finishSideDefs(GameMap &map) { // Calculate the tangent space surface vectors. - for(uint i = 0; i < map.sideDefCount(); ++i) + foreach(SideDef *sideDef, map.sideDefs()) { - SideDef &side = map.sideDefs[i]; - side.updateSurfaceTangents(); - side.updateSoundEmitterOrigins(); + sideDef->updateSurfaceTangents(); + sideDef->updateSoundEmitterOrigins(); } } static void finishLines(GameMap &map) { - for(uint i = 0; i < map.lineCount(); ++i) + foreach(LineDef *line, map.lines()) { - LineDef &line = map.lines[i]; - LineDef::Side &front = line.front(); + LineDef::Side &front = line->front(); if(!front._leftHEdge) continue; - line._v[0] = &front.leftHEdge().v1(); - line._v[1] = &front.rightHEdge().v2(); + line->_v[0] = &front.leftHEdge().v1(); + line->_v[1] = &front.rightHEdge().v2(); - line.updateSlopeType(); - line.updateAABox(); + line->updateSlopeType(); + line->updateAABox(); - line._length = V2d_Length(line._direction); - line._angle = bamsAtan2(int( line._direction[VY] ), - int( line._direction[VX] )); + line->_length = V2d_Length(line->_direction); + line->_angle = bamsAtan2(int( line->_direction[VY] ), + int( line->_direction[VX] )); } } @@ -1044,66 +1036,62 @@ static void buildVertexLineOwnerRings() } } -static void finishPlanes(GameMap &dest) +static void finishPlanes(GameMap &map) { - for(uint i = 0; i < dest.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) + foreach(Plane *plane, sector->planes()) { - Sector §or = dest.sectors[i]; + // Set target heights for each plane. + plane->_targetHeight = + plane->_oldHeight[0] = + plane->_oldHeight[1] = + plane->_visHeight = plane->_height; - foreach(Plane *plane, sector.planes()) - { - // Set target heights for each plane. - plane->_targetHeight = - plane->_oldHeight[0] = - plane->_oldHeight[1] = - plane->_visHeight = plane->_height; - - plane->_visHeightDelta = 0; + plane->_visHeightDelta = 0; - plane->surface().updateSoundEmitterOrigin(); + plane->surface().updateSoundEmitterOrigin(); #ifdef __CLIENT__ - // Resize the biassurface lists for the BSP leaf planes. - foreach(BspLeaf *bspLeaf, sector.bspLeafs()) - { - uint n = 0; + // Resize the biassurface lists for the BSP leaf planes. + foreach(BspLeaf *bspLeaf, sector->bspLeafs()) + { + uint n = 0; - biassurface_t **newList = (biassurface_t **) Z_Calloc(sector.planeCount() * sizeof(biassurface_t *), PU_MAP, 0); - // Copy the existing list? - if(bspLeaf->_bsuf) + biassurface_t **newList = (biassurface_t **) Z_Calloc(sector->planeCount() * sizeof(biassurface_t *), PU_MAP, 0); + // Copy the existing list? + if(bspLeaf->_bsuf) + { + for(; n < sector->planeCount() - 1 /* exclude newly added */; ++n) { - for(; n < sector.planeCount() - 1 /* exclude newly added */; ++n) - { - newList[n] = bspLeaf->_bsuf[n]; - } - Z_Free(bspLeaf->_bsuf); - bspLeaf->_bsuf = 0; + newList[n] = bspLeaf->_bsuf[n]; } + Z_Free(bspLeaf->_bsuf); + bspLeaf->_bsuf = 0; + } - /* - * @todo So where is this data initialized now? -ds - * If we are in map setup mode, don't create the biassurfaces now, - * as planes are created before the bias system is available. - */ - /*if(!ddMapSetup) - { - biassurface_t *bsuf = SB_CreateSurface(); + /* + * @todo So where is this data initialized now? -ds + * If we are in map setup mode, don't create the biassurfaces now, + * as planes are created before the bias system is available. + */ + /*if(!ddMapSetup) + { + biassurface_t *bsuf = SB_CreateSurface(); - bsuf->size = Rend_NumFanVerticesForBspLeaf(bspLeaf); - bsuf->illum = (vertexillum_t *) Z_Calloc(sizeof(vertexillum_t) * bsuf->size, PU_MAP, 0); + bsuf->size = Rend_NumFanVerticesForBspLeaf(bspLeaf); + bsuf->illum = (vertexillum_t *) Z_Calloc(sizeof(vertexillum_t) * bsuf->size, PU_MAP, 0); - for(uint k = 0; k < bsuf->size; ++k) - { - SB_InitVertexIllum(&bsuf->illum[k]); - } + for(uint k = 0; k < bsuf->size; ++k) + { + SB_InitVertexIllum(&bsuf->illum[k]); + } - newList[n] = bsuf; - }*/ + newList[n] = bsuf; + }*/ - bspLeaf->_bsuf = newList; - } -#endif + bspLeaf->_bsuf = newList; } +#endif } } @@ -1143,7 +1131,7 @@ static void hardenPolyobjs(GameMap &dest, EditMap &e_map) destP->lines = (LineDef **) Z_Malloc(sizeof(*destP->lines) * (destP->lineCount + 1), PU_MAP, 0); for(uint j = 0; j < destP->lineCount; ++j) { - LineDef *line = &dest.lines[srcP->lines[j]->_origIndex - 1]; + LineDef *line = GameMap_LineDef(&dest, srcP->lines[j]->_origIndex - 1); HEdge *hedge = &hedges[j]; // This line belongs to a polyobj. @@ -1318,16 +1306,16 @@ static void collateVertexes(BspBuilder &builder, GameMap &map, { uint bspVertexCount = builder.numVertexes(); - DENG2_ASSERT(map.vertexes.isEmpty()); + DENG2_ASSERT(map._vertexes.isEmpty()); #ifdef DENG2_QT_4_7_OR_NEWER - map.vertexes.reserve(numEditableVertexes + bspVertexCount); + map._vertexes.reserve(numEditableVertexes + bspVertexCount); #endif uint n = 0; for(; n < numEditableVertexes; ++n) { Vertex *vtx = const_cast(editableVertexes[n]); - map.vertexes.append(vtx); + map._vertexes.append(vtx); } for(uint i = 0; i < bspVertexCount; ++i, ++n) @@ -1335,7 +1323,7 @@ static void collateVertexes(BspBuilder &builder, GameMap &map, Vertex &vtx = builder.vertex(i); builder.take(&vtx); - map.vertexes.append(&vtx); + map._vertexes.append(&vtx); } } @@ -1695,33 +1683,33 @@ boolean MPE_End() gamemap->entityDatabase = editMap.entityDatabase; // Take ownership. // Collate sectors: - DENG2_ASSERT(gamemap->sectors.isEmpty()); + DENG2_ASSERT(gamemap->_sectors.isEmpty()); #ifdef DENG2_QT_4_7_OR_NEWER - gamemap->sectors.reserve(editMap.sectors.size()); + gamemap->_sectors.reserve(editMap.sectors.size()); #endif for(uint i = 0; i < editMap.sectors.size(); ++i) { - gamemap->sectors.append(editMap.sectors[i]); // Take ownership. + gamemap->_sectors.append(editMap.sectors[i]); // Take ownership. } // Collate sidedefs: - DENG2_ASSERT(gamemap->sideDefs.isEmpty()); + DENG2_ASSERT(gamemap->_sideDefs.isEmpty()); #ifdef DENG2_QT_4_7_OR_NEWER - gamemap->sideDefs.reserve(editMap.sideDefs.size()); + gamemap->_sideDefs.reserve(editMap.sideDefs.size()); #endif for(uint i = 0; i < editMap.sideDefs.size(); ++i) { - gamemap->sideDefs.append(editMap.sideDefs[i]); // Take ownership. + gamemap->_sideDefs.append(editMap.sideDefs[i]); // Take ownership. } // Collate lines: - DENG2_ASSERT(gamemap->lines.isEmpty()); + DENG2_ASSERT(gamemap->_lines.isEmpty()); #ifdef DENG2_QT_4_7_OR_NEWER - gamemap->lines.reserve(editMap.lines.size()); + gamemap->_lines.reserve(editMap.lines.size()); #endif for(uint i = 0; i < editMap.lines.size(); ++i) { - gamemap->lines.append(editMap.lines[i]); // Take ownership. + gamemap->_lines.append(editMap.lines[i]); // Take ownership. } buildVertexLineOwnerRings(); @@ -1736,9 +1724,9 @@ boolean MPE_End() findBounds(editMap.verticesAsArray(), editMap.vertexCount(), min, max); GameMap_InitLineDefBlockmap(gamemap, min, max); - for(uint i = 0; i < gamemap->lineCount(); ++i) + for(int i = 0; i < gamemap->_lines.count(); ++i) { - GameMap_LinkLineDef(gamemap, &gamemap->lines[i]); + GameMap_LinkLineDef(gamemap, gamemap->_lines[i]); } // Mobj and Polyobj blockmaps are maintained dynamically. diff --git a/doomsday/client/src/map/dam_file.cpp b/doomsday/client/src/map/dam_file.cpp index a969847fc8..227068d7f6 100644 --- a/doomsday/client/src/map/dam_file.cpp +++ b/doomsday/client/src/map/dam_file.cpp @@ -977,11 +977,11 @@ static void writePolyobj(GameMap *map, uint idx) LineDef *line = p->lines[i]; HEdge *he = line->front()._leftHEdge; - writeLong(map->vertexes.indexOf(he->_v[0]) + 1); - writeLong(map->vertexes.indexOf(he->_v[1]) + 1); + writeLong(map->_vertexes.indexOf(he->_v[0]) + 1); + writeLong(map->_vertexes.indexOf(he->_v[1]) + 1); writeFloat(he->_length); writeFloat(he->_lineOffset); - writeLong(he->_line? (map->lines.indexOf(he->_line) + 1) : 0); + writeLong(he->_line? (map->_lines.indexOf(he->_line) + 1) : 0); writeByte(he->_lineSide); writeLong(he->_sector? (GameMap_SectorIndex(map, he->_sector) + 1) : 0); writeLong((long) he->_angle); @@ -1021,18 +1021,18 @@ static void readPolyobj(GameMap *map, uint idx) { HEdge *he = hedges + i; - he->_v[0] = &map->vertexes[(unsigned) readLong() - 1]; - he->_v[1] = &map->vertexes[(unsigned) readLong() - 1]; + he->_v[0] = map->_vertexes[(unsigned) readLong() - 1]; + he->_v[1] = map->_vertexes[(unsigned) readLong() - 1]; he->_length = readFloat(); he->_lineOffset = readFloat(); long obIdx = readLong(); DENG_ASSERT(obIdx); - he->_line = &map->lines[(unsigned) obIdx - 1]; + he->_line = map->_lines[(unsigned) obIdx - 1]; he->_lineSide = (readByte()? 1 : 0); obIdx = readLong(); - he->_sector = (obIdx == 0? NULL : &map->sectors[(unsigned) obIdx - 1]); + he->_sector = (obIdx == 0? NULL : map->_sectors[(unsigned) obIdx - 1]); he->_angle = (angle_t) readLong(); diff --git a/doomsday/client/src/map/gamemap.cpp b/doomsday/client/src/map/gamemap.cpp index d23747677d..1354d4b7df 100644 --- a/doomsday/client/src/map/gamemap.cpp +++ b/doomsday/client/src/map/gamemap.cpp @@ -76,23 +76,21 @@ MapElement *GameMap::bspRoot() const void GameMap::updateBounds() { bool isFirst = true; - for(uint i = 0; i < sectorCount(); ++i) + foreach(Sector *sector, _sectors) { - Sector §or = sectors[i]; - // Sectors with no lines have invalid bounds; skip them. - if(!sector.lineCount()) continue; + if(!sector->lineCount()) continue; if(isFirst) { // The first sector is used as is. - V2d_CopyBox(aaBox.arvec2, sector.aaBox().arvec2); + V2d_CopyBox(aaBox.arvec2, sector->aaBox().arvec2); isFirst = false; } else { // Expand the bounding box. - V2d_UniteBox(aaBox.arvec2, sector.aaBox().arvec2); + V2d_UniteBox(aaBox.arvec2, sector->aaBox().arvec2); } } } @@ -211,68 +209,67 @@ GameMap *GameMap_SetSkyFix(GameMap *map, boolean ceiling, coord_t height) Vertex *GameMap_Vertex(GameMap *map, uint idx) { DENG2_ASSERT(map); - if(idx >= (uint)map->vertexes.size()) return NULL; - return &map->vertexes[idx]; + if(idx >= uint( map->_vertexes.size() )) return 0; + return map->_vertexes[idx]; } int GameMap_VertexIndex(GameMap *map, Vertex const *vtx) { DENG2_ASSERT(map); if(!vtx) return -1; - return map->vertexes.indexOf(vtx); + return map->_vertexes.indexOf(const_cast(vtx)); // Bad performance: O(n) } int GameMap_LineDefIndex(GameMap *map, LineDef const *line) { DENG2_ASSERT(map); if(!line) return -1; - return map->lines.indexOf(line); + return map->_lines.indexOf(const_cast(line)); // Bad performance: O(n) } LineDef *GameMap_LineDef(GameMap *map, uint idx) { DENG2_ASSERT(map); - if(idx >= (uint)map->lines.size()) return NULL; - return &map->lines[idx]; + if(idx >= uint( map->_lines.size() )) return 0; + return map->_lines[idx]; } int GameMap_SideDefIndex(GameMap *map, SideDef const *side) { DENG2_ASSERT(map); if(!side) return -1; - return map->sideDefs.indexOf(side); + return map->_sideDefs.indexOf(const_cast(side)); // Bad performance: O(n) } SideDef *GameMap_SideDef(GameMap *map, uint idx) { DENG2_ASSERT(map); - if(idx >= (uint)map->sideDefs.size()) return NULL; - return &map->sideDefs[idx]; + if(idx >= uint( map->_sideDefs.size() )) return 0; + return map->_sideDefs[idx]; } int GameMap_SectorIndex(GameMap *map, Sector const *sec) { DENG2_ASSERT(map); if(!sec) return -1; - return map->sectors.indexOf(sec); + return map->_sectors.indexOf(const_cast(sec)); // Bad performance: O(n) } Sector *GameMap_Sector(GameMap *map, uint idx) { DENG2_ASSERT(map); if(idx >= map->sectorCount()) return NULL; - return &map->sectors[idx]; + return map->_sectors[idx]; } Sector *GameMap_SectorBySoundEmitter(GameMap *map, void const *soundEmitter) { DENG2_ASSERT(map); - for(int i = 0; i < map->sectors.size(); ++i) + foreach(Sector *sector, map->_sectors) { - Sector *sec = &map->sectors[i]; - if(soundEmitter == &sec->soundEmitter()) + if(soundEmitter == §or->soundEmitter()) { - return sec; + return sector; } } return 0; // Not found. @@ -287,24 +284,18 @@ Surface *GameMap_SurfaceBySoundEmitter(GameMap *map, void const *soundEmitter) if(!soundEmitter) return 0; // First try plane surfaces. - for(uint i = 0; i < map->sectorCount(); ++i) + foreach(Sector *sector, map->_sectors) + foreach(Plane *plane, sector->planes()) { - Sector *sec = &map->sectors[i]; - - foreach(Plane *plane, sec->planes()) + if(soundEmitter == &plane->surface().soundEmitter()) { - if(soundEmitter == &plane->surface().soundEmitter()) - { - return &plane->surface(); - } + return &plane->surface(); } } // Perhaps a wall surface? - for(uint i = 0; i < map->sideDefCount(); ++i) + foreach(SideDef *sideDef, map->_sideDefs) { - SideDef *sideDef = &map->sideDefs[i]; - if(soundEmitter == &sideDef->middle().soundEmitter()) { return &sideDef->middle(); @@ -367,7 +358,7 @@ BspNode *GameMap_BspNode(GameMap *map, uint idx) uint GameMap_VertexCount(GameMap *map) { DENG2_ASSERT(map); - return map->vertexes.size(); + return map->vertexCount(); } uint GameMap_LineDefCount(GameMap *map) @@ -821,17 +812,6 @@ static int GameMap_IterateCellBlockLineDefs(GameMap *map, BlockmapCellBlock cons blockmapCellLinesIterator, (void *) &parms); } -int GameMap_LineDefIterator(GameMap *map, int (*callback) (LineDef *, void *), void *context) -{ - DENG2_ASSERT(map); - for(uint i = 0; i < map->lineCount(); ++i) - { - int result = callback(&map->lines[i], context); - if(result) return result; - } - return false; // Continue iteration. -} - void GameMap_LinkBspLeaf(GameMap *map, BspLeaf *bspLeaf) { DENG2_ASSERT(map); @@ -1163,62 +1143,6 @@ int GameMap_AllLineDefsBoxIterator(GameMap* map, const AABoxd* box, return P_LinesBoxIterator(box, callback, parameters); } -int GameMap_VertexIterator(GameMap* map, int (*callback) (Vertex*, void*), void* parameters) -{ - DENG2_ASSERT(map); - for(int i = 0; i < map->vertexes.size(); ++i) - { - int result = callback(&map->vertexes[i], parameters); - if(result) return result; - } - return false; // Continue iteration. -} - -int GameMap_SideDefIterator(GameMap* map, int (*callback) (SideDef*, void*), void* parameters) -{ - uint i; - DENG2_ASSERT(map); - for(i = 0; i < map->sideDefCount(); ++i) - { - int result = callback(&map->sideDefs[i], parameters); - if(result) return result; - } - return false; // Continue iteration. -} - -int GameMap_SectorIterator(GameMap *map, int (*callback) (Sector *, void *), void *parameters) -{ - DENG2_ASSERT(map); - for(uint i = 0; i < map->sectorCount(); ++i) - { - int result = callback(&map->sectors[i], parameters); - if(result) return result; - } - return false; // Continue iteration. -} - -int GameMap_HEdgeIterator(GameMap *map, int (*callback) (HEdge *, void *), void *parameters) -{ - DENG2_ASSERT(map); - for(uint i = 0; i < map->hedgeCount(); ++i) - { - int result = callback(map->hedges[i], parameters); - if(result) return result; - } - return false; // Continue iteration. -} - -int GameMap_BspNodeIterator(GameMap *map, int (*callback) (BspNode *, void *), void *parameters) -{ - DENG2_ASSERT(map); - for(uint i = 0; i < map->bspNodeCount(); ++i) - { - int result = callback(map->bspNodes[i], parameters); - if(result) return result; - } - return false; // Continue iteration. -} - static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2], uint const toBlock[2], coord_t const from[2], coord_t const to[2], int (*callback) (uint const block[2], void* parameters), void* parameters) diff --git a/doomsday/client/src/map/r_world.cpp b/doomsday/client/src/map/r_world.cpp index af04147047..fcbe3e9623 100644 --- a/doomsday/client/src/map/r_world.cpp +++ b/doomsday/client/src/map/r_world.cpp @@ -309,9 +309,9 @@ void GameMap_InitSkyFix(GameMap *map) map->skyFix[Plane::Ceiling].height = DDMINFLOAT; // Update for sector plane heights and mobjs which intersect the ceiling. - for(uint i = 0; i < map->sectorCount(); ++i) + foreach(Sector *sector, map->_sectors) { - GameMap_UpdateSkyFixForSector(map, &map->sectors[i]); + GameMap_UpdateSkyFixForSector(map, sector); } LOG_INFO(String("GameMap_InitSkyFix: Done in %1 seconds.").arg(begunAt.since(), 0, 'g', 2)); @@ -765,10 +765,9 @@ static void updateAllMapSectors(GameMap &map, bool forceUpdate = false) { if(novideo) return; - for(uint i = 0; i < map.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) { - Sector *sec = &map.sectors[i]; - R_UpdateSector(sec, forceUpdate); + R_UpdateSector(sector, forceUpdate); } } @@ -780,24 +779,18 @@ static inline void initSurfaceMaterialOrigin(Surface &suf) static void initAllMapSurfaceMaterialOrigins(GameMap &map) { - for(uint i = 0; i < map.sectorCount(); ++i) + foreach(Sector *sector, map.sectors()) + foreach(Plane *plane, sector->planes()) { - Sector §or = map.sectors[i]; - - foreach(Plane *plane, sector.planes()) - { - plane->_visHeight = plane->_oldHeight[0] = plane->_oldHeight[1] = plane->_height; - initSurfaceMaterialOrigin(plane->surface()); - } + plane->_visHeight = plane->_oldHeight[0] = plane->_oldHeight[1] = plane->_height; + initSurfaceMaterialOrigin(plane->surface()); } - for(uint i = 0; i < map.sideDefCount(); ++i) + foreach(SideDef *sideDef, map.sideDefs()) { - SideDef &sideDef = map.sideDefs[i]; - - initSurfaceMaterialOrigin(sideDef.top()); - initSurfaceMaterialOrigin(sideDef.middle()); - initSurfaceMaterialOrigin(sideDef.bottom()); + initSurfaceMaterialOrigin(sideDef->top()); + initSurfaceMaterialOrigin(sideDef->middle()); + initSurfaceMaterialOrigin(sideDef->bottom()); } } @@ -807,22 +800,19 @@ void GameMap::buildSurfaceLists() _decoratedSurfaces.clear(); _glowingSurfaces.clear(); - for(int i = 0; i < sideDefs.count(); ++i) + foreach(SideDef *sideDef, _sideDefs) { - SideDef &sideDef = sideDefs[i]; - addSurfaceToLists(sideDef.middle()); - addSurfaceToLists(sideDef.top()); - addSurfaceToLists(sideDef.bottom()); + addSurfaceToLists(sideDef->middle()); + addSurfaceToLists(sideDef->top()); + addSurfaceToLists(sideDef->bottom()); } - for(int i = 0; i < sectors.count(); ++i) + foreach(Sector *sector, _sectors) { - Sector §or = sectors[i]; - // Skip sectors with no lines as their planes will never be drawn. - if(!sector.lineCount()) continue; + if(!sector->lineCount()) continue; - foreach(Plane *plane, sector.planes()) + foreach(Plane *plane, sector->planes()) { addSurfaceToLists(plane->surface()); } diff --git a/doomsday/client/src/render/rend_main.cpp b/doomsday/client/src/render/rend_main.cpp index fcb4125c70..5623ed2e53 100644 --- a/doomsday/client/src/render/rend_main.cpp +++ b/doomsday/client/src/render/rend_main.cpp @@ -3127,50 +3127,6 @@ static void drawSoundOrigin(coord_t const origin[3], const char* label, coord_t } } -static int drawSideDefSoundOrigins(SideDef *sideDef, void *parameters) -{ - DENG_ASSERT(sideDef); - - uint idx = GameMap_SideDefIndex(theMap, sideDef); /// @todo Do not assume current map. - char buf[80]; - - dd_snprintf(buf, 80, "Side #%i (middle)", idx); - drawSoundOrigin(sideDef->middle().soundEmitter().origin, buf, (coord_t const *) parameters); - - dd_snprintf(buf, 80, "Side #%i (bottom)", idx); - drawSoundOrigin(sideDef->bottom().soundEmitter().origin, buf, (coord_t const *) parameters); - - dd_snprintf(buf, 80, "Side #%i (top)", idx); - drawSoundOrigin(sideDef->top().soundEmitter().origin, buf, (coord_t const *) parameters); - return false; // Continue iteration. -} - -static int drawSectorSoundOrigins(Sector *sec, void *parameters) -{ - DENG_ASSERT(sec); - - uint sectorIndex = GameMap_SectorIndex(theMap, sec); /// @todo Do not assume current map. - char buf[80]; - - if(devSoundOrigins & SOF_PLANE) - { - for(uint i = 0; i < sec->planeCount(); ++i) - { - Plane &plane = sec->plane(i); - dd_snprintf(buf, 80, "Sector #%i (pln:%i)", sectorIndex, i); - drawSoundOrigin(plane.surface().soundEmitter().origin, buf, (coord_t const *) parameters); - } - } - - if(devSoundOrigins & SOF_SECTOR) - { - dd_snprintf(buf, 80, "Sector #%i", sectorIndex); - drawSoundOrigin(sec->soundEmitter().origin, buf, (coord_t const*) parameters); - } - - return false; // Continue iteration. -} - /** * Debugging aid for visualizing sound origins. */ @@ -3187,12 +3143,47 @@ void Rend_RenderSoundOrigins() if(devSoundOrigins & SOF_SIDEDEF) { - GameMap_SideDefIterator(theMap, drawSideDefSoundOrigins, eye); + /// @todo Do not assume current map. + foreach(SideDef *sideDef, theMap->sideDefs()) + { + uint idx = GameMap_SideDefIndex(theMap, sideDef); + char buf[80]; + + dd_snprintf(buf, 80, "Side #%i (middle)", idx); + drawSoundOrigin(sideDef->middle().soundEmitter().origin, buf, eye); + + dd_snprintf(buf, 80, "Side #%i (bottom)", idx); + drawSoundOrigin(sideDef->bottom().soundEmitter().origin, buf, eye); + + dd_snprintf(buf, 80, "Side #%i (top)", idx); + drawSoundOrigin(sideDef->top().soundEmitter().origin, buf, eye); + } } if(devSoundOrigins & (SOF_SECTOR|SOF_PLANE)) { - GameMap_SectorIterator(theMap, drawSectorSoundOrigins, eye); + /// @todo Do not assume current map. + foreach(Sector *sec, theMap->sectors()) + { + uint sectorIndex = GameMap_SectorIndex(theMap, sec); + char buf[80]; + + if(devSoundOrigins & SOF_PLANE) + { + for(uint i = 0; i < sec->planeCount(); ++i) + { + Plane &plane = sec->plane(i); + dd_snprintf(buf, 80, "Sector #%i (pln:%i)", sectorIndex, i); + drawSoundOrigin(plane.surface().soundEmitter().origin, buf, eye); + } + } + + if(devSoundOrigins & SOF_SECTOR) + { + dd_snprintf(buf, 80, "Sector #%i", sectorIndex); + drawSoundOrigin(sec->soundEmitter().origin, buf, eye); + } + } } // Restore previous state. diff --git a/doomsday/server/src/shelluser.cpp b/doomsday/server/src/shelluser.cpp index f7601ff7a9..cd88e98354 100644 --- a/doomsday/server/src/shelluser.cpp +++ b/doomsday/server/src/shelluser.cpp @@ -153,12 +153,11 @@ void ShellUser::sendMapOutline() QScopedPointer packet(new shell::MapOutlinePacket); - for(uint i = 0; i < theMap->lineCount(); ++i) + foreach(LineDef *line, theMap->lines()) { - LineDef const &line = theMap->lines[i]; - packet->addLine(Vector2i(line.v1Origin()[VX], line.v1Origin()[VY]), - Vector2i(line.v2Origin()[VX], line.v2Origin()[VY]), - (line.hasFrontSector() && line.hasBackSector())? + packet->addLine(Vector2i(line->v1Origin()[VX], line->v1Origin()[VY]), + Vector2i(line->v2Origin()[VX], line->v2Origin()[VY]), + (line->hasFrontSector() && line->hasBackSector())? shell::MapOutlinePacket::TwoSidedLine : shell::MapOutlinePacket::OneSidedLine); }