From cb7e87d0a4c29e6ab876bf1ae1ea92f95296c5d7 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 3 Apr 2013 22:09:16 +0100 Subject: [PATCH] Refactor|GameMap: Moved more GameMap_* functions to methods of GameMap Map element in-box and path traversals. --- doomsday/client/include/map/gamemap.h | 102 +++++++++++--------- doomsday/client/src/map/bsp/partitioner.cpp | 2 +- doomsday/client/src/map/gamemap.cpp | 90 +++++++---------- doomsday/client/src/map/p_maputil.cpp | 62 ++++++------ doomsday/client/src/render/r_fakeradio.cpp | 2 +- 5 files changed, 129 insertions(+), 129 deletions(-) diff --git a/doomsday/client/include/map/gamemap.h b/doomsday/client/include/map/gamemap.h index c413719f12..af163516da 100644 --- a/doomsday/client/include/map/gamemap.h +++ b/doomsday/client/include/map/gamemap.h @@ -292,6 +292,38 @@ class GameMap return bspLeafAtPoint(point); } + int mobjsBoxIterator(AABoxd const &box, + int (*callback) (struct mobj_s *, void *), void *parameters = 0); + + int linesBoxIterator(AABoxd const &box, + int (*callback) (LineDef *, void *), void *parameters = 0); + + int polyobjLinesBoxIterator(AABoxd const &box, + int (*callback) (LineDef *, void *), void *parameters = 0); + + /** + * LineDefs and Polyobj lines (note polyobj lines are iterated first). + * + * @note validCount should be incremented before calling this to begin + * a new logical traversal. Otherwise LineDefs marked with a validCount + * equal to this will be skipped over (can be used to avoid processing + * a line multiple times during complex / non-linear traversals. + */ + int allLinesBoxIterator(AABoxd const &box, + int (*callback) (LineDef *, void *), void *parameters = 0); + + int bspLeafsBoxIterator(AABoxd const &box, Sector *sector, + int (*callback) (BspLeaf *, void *), void *parameters = 0); + + /** + * @note validCount should be incremented before calling this to begin a + * new logical traversal. Otherwise LineDefs marked with a validCount equal + * to this will be skipped over (can be used to avoid processing a line + * multiple times during complex / non-linear traversals. + */ + int polyobjsBoxIterator(AABoxd const &box, + int (*callback) (struct polyobj_s *, void *), void *parameters = 0); + /** * Traces a line of sight. * @@ -305,6 +337,30 @@ class GameMap bool lineOfSight(const_pvec3d_t from, const_pvec3d_t to, coord_t bottomSlope, coord_t topSlope, int flags); + /** + * Trace a line between @a from and @a to, making a callback for each + * interceptable object linked within Blockmap cells which cover the path + * this defines. + */ + int pathTraverse(const_pvec2d_t from, const_pvec2d_t to, int flags, + traverser_t callback, void *parameters = 0); + + /** + * @copybrief pathTraverse() + * + * @param fromX X axis map space coordinate for the path origin. + * @param fromY Y axis map space coordinate for the path origin. + * @param toX X axis map space coordinate for the path origin. + * @param toY Y axis map space coordinate for the path origin. + */ + inline int pathTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, + int flags, traverser_t callback, void *parameters = 0) + { + coord_t from[2] = { fromX, fromY }; + coord_t to[2] = { toX, toY }; + return pathTraverse(from, to, flags, callback, parameters); + } + coord_t skyFix(bool ceiling) const; inline coord_t skyFixFloor() const { return skyFix(false /*the floor*/); } @@ -683,52 +739,6 @@ boolean GameMap_IsUsedMobjID(GameMap* map, thid_t id); */ void GameMap_SetMobjID(GameMap *map, thid_t id, boolean inUse); -int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box, - int (*callback) (struct mobj_s *, void *), void *parameters); - -int GameMap_LinesBoxIterator(GameMap *map, AABoxd const *box, - int (*callback) (LineDef *, void *), void *parameters); - -int GameMap_PolyobjLinesBoxIterator(GameMap *map, AABoxd const *box, - int (*callback) (LineDef *, void *), void *parameters); - -/** - * LineDefs and Polyobj lines (note polyobj lines are iterated first). - * - * @note validCount should be incremented before calling this to begin a new logical traversal. - * Otherwise LineDefs marked with a validCount equal to this will be skipped over (can - * be used to avoid processing a line multiple times during complex / non-linear traversals. - */ -int GameMap_AllLinesBoxIterator(GameMap *map, AABoxd const *box, - int (*callback) (LineDef *, void *), void *parameters); - -int GameMap_BspLeafsBoxIterator(GameMap *map, AABoxd const *box, Sector *sector, - int (*callback) (BspLeaf *, void *), void *parameters); - -/** - * @note validCount should be incremented before calling this to begin a new logical traversal. - * Otherwise LineDefs marked with a validCount equal to this will be skipped over (can - * be used to avoid processing a line multiple times during complex / non-linear traversals. - */ -int GameMap_PolyobjsBoxIterator(GameMap *map, AABoxd const *box, - int (*callback) (struct polyobj_s *, 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 - * defines. - */ -int GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to, - int flags, traverser_t callback, void *parameters = 0); - -inline int GameMap_PathTraverse(GameMap *map, coord_t fromX, coord_t fromY, - coord_t toX, coord_t toY, int flags, traverser_t callback, void *parameters = 0) -{ - coord_t from[2] = { fromX, fromY }; - coord_t to[2] = { toX, toY }; - return GameMap_PathTraverse(map, from, to, flags, callback, parameters); -} - // The current map. DENG_EXTERN_C GameMap *theMap; diff --git a/doomsday/client/src/map/bsp/partitioner.cpp b/doomsday/client/src/map/bsp/partitioner.cpp index 2e62550d94..f7682b7229 100644 --- a/doomsday/client/src/map/bsp/partitioner.cpp +++ b/doomsday/client/src/map/bsp/partitioner.cpp @@ -370,7 +370,7 @@ struct Partitioner::Instance scanRegion.maxX = de::max(line->v1Origin()[VX], line->v2Origin()[VX]) + DIST_EPSILON; } validCount++; - GameMap_LinesBoxIterator(map, &scanRegion, testForWindowEffectWorker, &p); + map->linesBoxIterator(scanRegion, testForWindowEffectWorker, &p); if(p.backOpen && p.frontOpen && line->frontSectorPtr() == p.backOpen) { diff --git a/doomsday/client/src/map/gamemap.cpp b/doomsday/client/src/map/gamemap.cpp index 243df7bde9..44cfa92539 100644 --- a/doomsday/client/src/map/gamemap.cpp +++ b/doomsday/client/src/map/gamemap.cpp @@ -512,13 +512,12 @@ static int GameMap_IterateCellBlockMobjs(GameMap *map, BlockmapCellBlock const * blockmapCellMobjsIterator, (void*) &args); } -int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box, +int GameMap::mobjsBoxIterator(AABoxd const &box, int (*callback) (mobj_t *, void *), void *parameters) { - DENG2_ASSERT(map); BlockmapCellBlock cellBlock; - Blockmap_CellBlock(map->mobjBlockmap, &cellBlock, box); - return GameMap_IterateCellBlockMobjs(map, &cellBlock, callback, parameters); + Blockmap_CellBlock(mobjBlockmap, &cellBlock, &box); + return GameMap_IterateCellBlockMobjs(this, &cellBlock, callback, parameters); } void GameMap::linkLine(LineDef &line) @@ -721,21 +720,19 @@ static int GameMap_IterateCellBlockBspLeafs(GameMap *map, BlockmapCellBlock cons blockmapCellBspLeafsIterator, (void*) &args); } -int GameMap_BspLeafsBoxIterator(GameMap *map, AABoxd const *box, Sector *sector, +int GameMap::bspLeafsBoxIterator(AABoxd const &box, Sector *sector, int (*callback) (BspLeaf *, void *), void *parameters) { - DENG2_ASSERT(map); - static int localValidCount = 0; // This is only used here. localValidCount++; BlockmapCellBlock cellBlock; - Blockmap_CellBlock(map->bspLeafBlockmap, &cellBlock, box); + Blockmap_CellBlock(bspLeafBlockmap, &cellBlock, &box); - return GameMap_IterateCellBlockBspLeafs(map, &cellBlock, sector, box, - localValidCount, callback, parameters); + return GameMap_IterateCellBlockBspLeafs(this, &cellBlock, sector, &box, + localValidCount, callback, parameters); } void GameMap::linkPolyobj(Polyobj &polyobj) @@ -809,13 +806,12 @@ static int GameMap_IterateCellBlockPolyobjs(GameMap* map, const BlockmapCellBloc blockmapCellPolyobjsIterator, (void*) &args); } -int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxd* box, - int (*callback) (struct polyobj_s*, void*), void* parameters) +int GameMap::polyobjsBoxIterator(AABoxd const &box, + int (*callback) (struct polyobj_s *, void *), void *parameters) { BlockmapCellBlock cellBlock; - DENG2_ASSERT(map); - Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box); - return GameMap_IterateCellBlockPolyobjs(map, &cellBlock, callback, parameters); + Blockmap_CellBlock(polyobjBlockmap, &cellBlock, &box); + return GameMap_IterateCellBlockPolyobjs(this, &cellBlock, callback, parameters); } typedef struct poiterparams_s { @@ -868,41 +864,31 @@ static int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const BlockmapC blockmapCellPolyobjsIterator, (void*) &args); } -int GameMap_LinesBoxIterator(GameMap* map, const AABoxd* box, - int (*callback) (LineDef*, void*), void* parameters) +int GameMap::linesBoxIterator(AABoxd const &box, + int (*callback) (LineDef *, void *), void *parameters) { BlockmapCellBlock cellBlock; - DENG2_ASSERT(map); - Blockmap_CellBlock(map->lineBlockmap, &cellBlock, box); - return GameMap_IterateCellBlockLineDefs(map, &cellBlock, callback, parameters); + Blockmap_CellBlock(lineBlockmap, &cellBlock, &box); + return GameMap_IterateCellBlockLineDefs(this, &cellBlock, callback, parameters); } -int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxd* box, - int (*callback) (LineDef*, void*), void* parameters) +int GameMap::polyobjLinesBoxIterator(AABoxd const &box, + int (*callback) (LineDef *, void *), void *parameters) { BlockmapCellBlock cellBlock; - DENG2_ASSERT(map); - Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box); - return GameMap_IterateCellBlockPolyobjLineDefs(map, &cellBlock, callback, parameters); + Blockmap_CellBlock(polyobjBlockmap, &cellBlock, &box); + return GameMap_IterateCellBlockPolyobjLineDefs(this, &cellBlock, callback, parameters); } -/** - * LineDefs and Polyobj LineDefs (note Polyobj LineDefs are iterated first). - * - * The validCount flags are used to avoid checking lines that are marked - * in multiple mapblocks, so increment validCount before the first call - * to GameMap_IterateCellLineDefs(), then make one or more calls to it. - */ -int GameMap_AllLinesBoxIterator(GameMap *map, AABoxd const *box, +int GameMap::allLinesBoxIterator(AABoxd const &box, int (*callback) (LineDef *, void *), void *parameters) { - DENG2_ASSERT(map); - if(map->polyobjCount() != 0) + if(!_polyobjs.isEmpty()) { - int result = P_PolyobjLinesBoxIterator(box, callback, parameters); + int result = P_PolyobjLinesBoxIterator(&box, callback, parameters); if(result) return result; } - return P_LinesBoxIterator(box, callback, parameters); + return P_LinesBoxIterator(&box, callback, parameters); } static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2], @@ -1095,32 +1081,30 @@ static int iteratePolyobjLines(Polyobj *po, void *parameters) return po->lineIterator(p->callback, p->parameters); } -static int collectPolyobjLineIntercepts(uint const block[2], void* parameters) +static int collectPolyobjLineIntercepts(uint const block[2], void *parameters) { - GameMap* map = (GameMap*)parameters; + GameMap *map = (GameMap *)parameters; iteratepolyobjlines_params_t iplParams; - iplParams.callback = PIT_AddLineDefIntercepts; - iplParams.parameters = NULL; - return GameMap_IterateCellPolyobjs(map, block, iteratePolyobjLines, (void*)&iplParams); + iplParams.callback = PIT_AddLineDefIntercepts; + iplParams.parameters = 0; + return GameMap_IterateCellPolyobjs(map, block, iteratePolyobjLines, (void *)&iplParams); } -static int collectLineIntercepts(uint const block[2], void* parameters) +static int collectLineIntercepts(uint const block[2], void *parameters) { - GameMap* map = (GameMap*)parameters; + GameMap *map = (GameMap *)parameters; return GameMap_IterateCellLines(map, block, PIT_AddLineDefIntercepts, NULL); } static int collectMobjIntercepts(uint const block[2], void* parameters) { - GameMap* map = (GameMap*)parameters; + GameMap *map = (GameMap *)parameters; return GameMap_IterateCellMobjs(map, block, PIT_AddMobjIntercepts, NULL); } -int GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to, - int flags, traverser_t callback, void *parameters) +int GameMap::pathTraverse(const_pvec2d_t from, const_pvec2d_t to, int flags, + traverser_t callback, void *parameters) { - DENG2_ASSERT(map); - // A new intercept trace begins... P_ClearIntercepts(); validCount++; @@ -1128,15 +1112,15 @@ int GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to, // Step #1: Collect intercepts. if(flags & PT_ADDLINES) { - if(theMap->polyobjCount() != 0) + if(!_polyobjs.isEmpty()) { - traverseCellPath(map, map->polyobjBlockmap, from, to, collectPolyobjLineIntercepts, (void *)map); + traverseCellPath(this, polyobjBlockmap, from, to, collectPolyobjLineIntercepts, (void *)this); } - traverseCellPath(map, map->lineBlockmap, from, to, collectLineIntercepts, (void *)map); + traverseCellPath(this, lineBlockmap, from, to, collectLineIntercepts, (void *)this); } if(flags & PT_ADDMOBJS) { - traverseCellPath(map, map->mobjBlockmap, from, to, collectMobjIntercepts, (void *)map); + traverseCellPath(this, mobjBlockmap, from, to, collectMobjIntercepts, (void *)this); } // Step #2: Process sorted intercepts. diff --git a/doomsday/client/src/map/p_maputil.cpp b/doomsday/client/src/map/p_maputil.cpp index 4e7640f889..c7d2f1e5de 100644 --- a/doomsday/client/src/map/p_maputil.cpp +++ b/doomsday/client/src/map/p_maputil.cpp @@ -684,69 +684,75 @@ DENG_EXTERN_C int P_SectorTouchingMobjsIterator(Sector *sector, int (*callback) } #undef P_MobjsBoxIterator -DENG_EXTERN_C int P_MobjsBoxIterator(const AABoxd* box, int (*callback) (mobj_t*, void*), void* parameters) +DENG_EXTERN_C int P_MobjsBoxIterator(AABoxd const *box, + int (*callback) (mobj_t *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_MobjsBoxIterator(theMap, box, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->mobjsBoxIterator(*box, callback, parameters); } #undef P_PolyobjsBoxIterator -DENG_EXTERN_C int P_PolyobjsBoxIterator(const AABoxd* box, int (*callback) (struct polyobj_s*, void*), void* parameters) +DENG_EXTERN_C int P_PolyobjsBoxIterator(AABoxd const *box, + int (*callback) (struct polyobj_s *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_PolyobjsBoxIterator(theMap, box, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->polyobjsBoxIterator(*box, callback, parameters); } #undef P_LinesBoxIterator -DENG_EXTERN_C int P_LinesBoxIterator(const AABoxd* box, int (*callback) (LineDef*, void*), void* parameters) +DENG_EXTERN_C int P_LinesBoxIterator(AABoxd const *box, + int (*callback) (LineDef *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_LinesBoxIterator(theMap, box, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->linesBoxIterator(*box, callback, parameters); } #undef P_PolyobjLinesBoxIterator -DENG_EXTERN_C int P_PolyobjLinesBoxIterator(const AABoxd* box, int (*callback) (LineDef*, void*), void* parameters) +DENG_EXTERN_C int P_PolyobjLinesBoxIterator(AABoxd const *box, + int (*callback) (LineDef *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_PolyobjLinesBoxIterator(theMap, box, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->polyobjLinesBoxIterator(*box, callback, parameters); } #undef P_BspLeafsBoxIterator -DENG_EXTERN_C int P_BspLeafsBoxIterator(const AABoxd* box, Sector* sector, - int (*callback) (BspLeaf*, void*), void* parameters) +DENG_EXTERN_C int P_BspLeafsBoxIterator(AABoxd const *box, Sector *sector, + int (*callback) (BspLeaf *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_BspLeafsBoxIterator(theMap, box, sector, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->bspLeafsBoxIterator(*box, sector, callback, parameters); } #undef P_AllLinesBoxIterator -DENG_EXTERN_C int P_AllLinesBoxIterator(const AABoxd* box, int (*callback) (LineDef*, void*), void* parameters) +DENG_EXTERN_C int P_AllLinesBoxIterator(AABoxd const *box, + int (*callback) (LineDef *, void *), void *parameters) { - if(!theMap) return false; // Continue iteration. - return GameMap_AllLinesBoxIterator(theMap, box, callback, parameters); + if(!theMap || !box) return false; // Continue iteration. + return theMap->allLinesBoxIterator(*box, callback, parameters); } #undef P_PathTraverse2 -DENG_EXTERN_C int P_PathTraverse2(const_pvec2d_t from, const_pvec2d_t to, int flags, traverser_t callback, - void *parameters) +DENG_EXTERN_C int P_PathTraverse2(const_pvec2d_t from, const_pvec2d_t to, + int flags, traverser_t callback, void *parameters) { if(!theMap) return false; // Continue iteration. - return GameMap_PathTraverse(theMap, from, to, flags, callback, parameters); + return theMap->pathTraverse(from, to, flags, callback, parameters); } #undef P_PathTraverse -DENG_EXTERN_C int P_PathTraverse(const_pvec2d_t from, const_pvec2d_t to, int flags, traverser_t callback) +DENG_EXTERN_C int P_PathTraverse(const_pvec2d_t from, const_pvec2d_t to, + int flags, traverser_t callback) { if(!theMap) return false; // Continue iteration. - return GameMap_PathTraverse(theMap, from, to, flags, callback); + return theMap->pathTraverse(from, to, flags, callback); } #undef P_PathXYTraverse2 -DENG_EXTERN_C int P_PathXYTraverse2(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, int flags, - traverser_t callback, void* paramaters) +DENG_EXTERN_C int P_PathXYTraverse2(coord_t fromX, coord_t fromY, + coord_t toX, coord_t toY, int flags, traverser_t callback, void* paramaters) { if(!theMap) return false; // Continue iteration. - return GameMap_PathTraverse(theMap, fromX, fromY, toX, toY, flags, callback, paramaters); + return theMap->pathTraverse(fromX, fromY, toX, toY, flags, callback, paramaters); } #undef P_PathXYTraverse @@ -754,7 +760,7 @@ DENG_EXTERN_C int P_PathXYTraverse(coord_t fromX, coord_t fromY, coord_t toX, co traverser_t callback) { if(!theMap) return false; // Continue iteration. - return GameMap_PathTraverse(theMap, fromX, fromY, toX, toY, flags, callback); + return theMap->pathTraverse(fromX, fromY, toX, toY, flags, callback); } #undef P_CheckLineSight diff --git a/doomsday/client/src/render/r_fakeradio.cpp b/doomsday/client/src/render/r_fakeradio.cpp index 71a201033f..39ca74fda6 100644 --- a/doomsday/client/src/render/r_fakeradio.cpp +++ b/doomsday/client/src/render/r_fakeradio.cpp @@ -278,7 +278,7 @@ void Rend_RadioInitForMap() // Link the shadowing line to all the BspLeafs whose axis-aligned // bounding box intersects 'bounds'. - GameMap_BspLeafsBoxIterator(theMap, &bounds, side.sectorPtr(), + theMap->bspLeafsBoxIterator(bounds, side.sectorPtr(), RIT_ShadowBspLeafLinker, &parms); } }