From ec3c30028686a9fcd814ace9472bc561771eb01c Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 12 Oct 2013 22:39:26 +0100 Subject: [PATCH] API|Map: Unused functions removed; P_PathTraverse reformatted --- doomsday/api/api_map.h | 28 +-- doomsday/client/include/world/blockmap.h | 7 +- doomsday/client/src/world/api_map.cpp | 57 +---- doomsday/client/src/world/blockmap.cpp | 8 +- doomsday/client/src/world/map.cpp | 38 +-- doomsday/plugins/common/include/dmu_lib.h | 12 + doomsday/plugins/common/src/dmu_lib.cpp | 18 ++ doomsday/plugins/common/src/p_map.c | 292 +++++++++++----------- doomsday/plugins/common/src/p_xgline.c | 46 ++-- 9 files changed, 227 insertions(+), 279 deletions(-) diff --git a/doomsday/api/api_map.h b/doomsday/api/api_map.h index 14e4a0b7f5..4bfd886968 100644 --- a/doomsday/api/api_map.h +++ b/doomsday/api/api_map.h @@ -164,8 +164,11 @@ typedef struct lineopening_s { * @ingroup apiFlags map */ ///@{ -#define PT_ADDLINES 1 ///< Intercept with Lines. -#define PT_ADDMOBJS 2 ///< Intercept with Mobjs. +#define PTF_LINE 0x1 ///< Intercept with map lines. +#define PTF_MOBJ 0x2 ///< Intercept with mobjs. + +/// Process all interceptable map element types. +#define PTF_ALL PTF_LINE | PTF_MOBJ ///@} typedef enum intercepttype_e { @@ -273,9 +276,7 @@ DENG_API_TYPEDEF(Map) int (*L_BoxOnSide)(Line *line, AABoxd const *box); int (*L_BoxOnSide_FixedPrecision)(Line *line, AABoxd const *box); coord_t (*L_PointDistance)(Line *line, coord_t const point[2], coord_t *offset); - coord_t (*L_PointXYDistance)(Line *line, coord_t x, coord_t y, coord_t *offset); coord_t (*L_PointOnSide)(Line const *line, coord_t const point[2]); - coord_t (*L_PointXYOnSide)(Line const *line, coord_t x, coord_t y); int (*L_MobjsIterator)(Line *line, int (*callback) (struct mobj_s *, void *), void *context); void (*L_Opening)(Line *line, LineOpening *opening); @@ -309,9 +310,6 @@ DENG_API_TYPEDEF(Map) */ Sector *(*S_AtPoint_FixedPrecision)(coord_t const point[2]); - /// @copydoc S_AtPoint_FixedPrecision() - Sector *(*S_AtPoint_FixedPrecisionXY)(coord_t x, coord_t y); - // Map Objects struct mobj_s *(*MO_CreateXYZ)(thinkfunc_t function, coord_t x, coord_t y, coord_t z, angle_t angle, coord_t radius, coord_t height, int ddflags); @@ -425,15 +423,8 @@ DENG_API_TYPEDEF(Map) // Traversers + int (*PathTraverse)(coord_t const from[2], coord_t const to[2], int (*callback) (TraceState *trace, struct intercept_s const *, void *context), void *context); int (*PathTraverse2)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (TraceState *trace, struct intercept_s const *, void *context), void *context); - int (*PathTraverse)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (TraceState *trace, struct intercept_s const *, void *context)/*, context=0*/); - - /** - * Same as P_PathTraverse except 'from' and 'to' arguments are specified - * as two sets of separate X and Y map space coordinates. - */ - int (*PathXYTraverse2)(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, int flags, int (*callback) (TraceState *trace, struct intercept_s const *, void *context), void *context); - int (*PathXYTraverse)(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, int flags, int (*callback) (TraceState *trace, struct intercept_s const *, void *context)/*, context=0*/); /** * Traces a line of sight. @@ -663,15 +654,12 @@ DENG_API_T(Map); #define Line_BoxOnSide _api_Map.L_BoxOnSide #define Line_BoxOnSide_FixedPrecision _api_Map.L_BoxOnSide_FixedPrecision #define Line_PointDistance _api_Map.L_PointDistance -#define Line_PointXYDistance _api_Map.L_PointXYDistance #define Line_PointOnSide _api_Map.L_PointOnSide -#define Line_PointXYOnSide _api_Map.L_PointXYOnSide #define Line_TouchingMobjsIterator _api_Map.L_MobjsIterator #define Line_Opening _api_Map.L_Opening #define Sector_TouchingMobjsIterator _api_Map.S_TouchingMobjsIterator #define Sector_AtPoint_FixedPrecision _api_Map.S_AtPoint_FixedPrecision -#define Sector_AtPoint_FixedPrecisionXY _api_Map.S_AtPoint_FixedPrecisionXY #define Mobj_CreateXYZ _api_Map.MO_CreateXYZ #define Mobj_Destroy _api_Map.MO_Destroy @@ -699,10 +687,8 @@ DENG_API_T(Map); #define BspLeaf_BoxIterator _api_Map.BL_BoxIterator -#define P_PathTraverse2 _api_Map.PathTraverse2 #define P_PathTraverse _api_Map.PathTraverse -#define P_PathXYTraverse2 _api_Map.PathXYTraverse2 -#define P_PathXYTraverse _api_Map.PathXYTraverse +#define P_PathTraverse2 _api_Map.PathTraverse2 #define P_CheckLineSight _api_Map.CheckLineSight #define P_TraceAdjustOpening _api_Map.TraceAdjustOpening #define P_SetTraceOpening _api_Map.SetTraceOpening diff --git a/doomsday/client/include/world/blockmap.h b/doomsday/client/include/world/blockmap.h index 6a10e50126..06d64a1f13 100644 --- a/doomsday/client/include/world/blockmap.h +++ b/doomsday/client/include/world/blockmap.h @@ -138,11 +138,11 @@ class Blockmap bool link(Cell const &cell, void *elem); - bool link(CellBlock const &cellBlock, void *elem); + bool link(AABoxd const ®ion, void *elem); bool unlink(Cell const &cell, void *elem); - bool unlink(CellBlock const &cellBlock, void *elem); + bool unlink(AABoxd const ®ion, void *elem); void unlinkAll(); @@ -152,7 +152,8 @@ class Blockmap int iterate(Cell const &cell, int (*callback) (void *elem, void *context), void *context = 0) const; /** - * Iterate over all elements in the specified map space @a region. + * Iterate over all elements in cells which intercept the specified map space + * @a region. */ int iterate(AABoxd const ®ion, int (*callback) (void *elem, void *context), void *context = 0) const; diff --git a/doomsday/client/src/world/api_map.cpp b/doomsday/client/src/world/api_map.cpp index 2308080870..9fa19ff418 100644 --- a/doomsday/client/src/world/api_map.cpp +++ b/doomsday/client/src/world/api_map.cpp @@ -1586,14 +1586,6 @@ DENG_EXTERN_C Sector *Sector_AtPoint_FixedPrecision(const_pvec2d_t point) return App_World().map().bspLeafAt_FixedPrecision(point).sectorPtr(); } -#undef Sector_AtPoint_FixedPrecisionXY -DENG_EXTERN_C Sector *Sector_AtPoint_FixedPrecisionXY(coord_t x, coord_t y) -{ - if(!App_World().hasMap()) return 0; - coord_t point[2] = { x, y }; - return App_World().map().bspLeafAt_FixedPrecision(point).sectorPtr(); -} - #undef Mobj_BoxIterator DENG_EXTERN_C int Mobj_BoxIterator(AABoxd const *box, int (*callback) (mobj_t *, void *), void *context) @@ -1729,11 +1721,11 @@ static int traverseMapPath(Map &map, Vector2d const &from, Vector2d const &to, validCount++; // Step #1: Collect intercepts. - if(flags & PT_ADDLINES) + if(flags & PTF_LINE) { map.linePathIterator(from, to, collectCellLineInterceptsWorker, &trace); } - if(flags & PT_ADDMOBJS) + if(flags & PTF_MOBJ) { map.mobjPathIterator(from, to, collectCellMobjInterceptsWorker, &trace); } @@ -1752,30 +1744,10 @@ DENG_EXTERN_C int P_PathTraverse2(const_pvec2d_t from, const_pvec2d_t to, #undef P_PathTraverse DENG_EXTERN_C int P_PathTraverse(const_pvec2d_t from, const_pvec2d_t to, - int flags, traverser_t callback) -{ - if(!App_World().hasMap()) return false; // Continue iteration. - return traverseMapPath(App_World().map(), 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 *context) + traverser_t callback, void *context) { if(!App_World().hasMap()) return false; // Continue iteration. - return traverseMapPath(App_World().map(), - Vector2d(fromX, fromY), Vector2d(toX, toY), - flags, callback, context); -} - -#undef P_PathXYTraverse -DENG_EXTERN_C int P_PathXYTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, int flags, - traverser_t callback) -{ - if(!App_World().hasMap()) return false; // Continue iteration. - return traverseMapPath(App_World().map(), - Vector2d(fromX, fromY), Vector2d(toX, toY), - flags, callback); + return traverseMapPath(App_World().map(), from, to, PTF_ALL, callback, context); } #undef P_CheckLineSight @@ -1888,13 +1860,6 @@ DENG_EXTERN_C coord_t Line_PointDistance(Line *line, coord_t const point[2], coo return line->pointDistance(point, offset); } -#undef Line_PointXYDistance -DENG_EXTERN_C coord_t Line_PointXYDistance(Line* line, coord_t x, coord_t y, coord_t* offset) -{ - DENG_ASSERT(line); - return line->pointDistance(Vector2d(x, y), offset); -} - #undef Line_PointOnSide DENG_EXTERN_C coord_t Line_PointOnSide(Line const *line, coord_t const point[2]) { @@ -1908,13 +1873,6 @@ DENG_EXTERN_C coord_t Line_PointOnSide(Line const *line, coord_t const point[2]) return line->pointOnSide(point); } -#undef Line_PointXYOnSide -DENG_EXTERN_C coord_t Line_PointXYOnSide(Line const *line, coord_t x, coord_t y) -{ - DENG_ASSERT(line); - return line->pointOnSide(Vector2d(x, y)); -} - #undef Line_BoxOnSide DENG_EXTERN_C int Line_BoxOnSide(Line *line, AABoxd const *box) { @@ -1948,15 +1906,12 @@ DENG_DECLARE_API(Map) = Line_BoxOnSide, Line_BoxOnSide_FixedPrecision, Line_PointDistance, - Line_PointXYDistance, Line_PointOnSide, - Line_PointXYOnSide, Line_TouchingMobjsIterator, Line_Opening, Sector_TouchingMobjsIterator, Sector_AtPoint_FixedPrecision, - Sector_AtPoint_FixedPrecisionXY, Mobj_CreateXYZ, Mobj_Destroy, @@ -1984,10 +1939,8 @@ DENG_DECLARE_API(Map) = BspLeaf_BoxIterator, - P_PathTraverse2, P_PathTraverse, - P_PathXYTraverse2, - P_PathXYTraverse, + P_PathTraverse2, P_CheckLineSight, P_TraceAdjustOpening, diff --git a/doomsday/client/src/world/blockmap.cpp b/doomsday/client/src/world/blockmap.cpp index 13e164992e..92fa1f2367 100644 --- a/doomsday/client/src/world/blockmap.cpp +++ b/doomsday/client/src/world/blockmap.cpp @@ -455,13 +455,13 @@ bool Blockmap::link(Cell const &cell, void *elem) return false; // Outside the blockmap? } -bool Blockmap::link(CellBlock const &cellBlock_, void *elem) +bool Blockmap::link(AABoxd const ®ion, void *elem) { if(!elem) return false; // Huh? bool didLink = false; - CellBlock cellBlock = cellBlock_; + CellBlock cellBlock = toCellBlock(region); d->clipBlock(cellBlock); Cell cell; @@ -491,13 +491,13 @@ bool Blockmap::unlink(Cell const &cell, void *elem) return false; } -bool Blockmap::unlink(CellBlock const &cellBlock_, void *elem) +bool Blockmap::unlink(AABoxd const ®ion, void *elem) { if(!elem) return false; // Huh? bool didUnlink = false; - CellBlock cellBlock = cellBlock_; + CellBlock cellBlock = toCellBlock(region); d->clipBlock(cellBlock); Cell cell; diff --git a/doomsday/client/src/world/map.cpp b/doomsday/client/src/world/map.cpp index ec9325651d..7938cdb1e7 100644 --- a/doomsday/client/src/world/map.cpp +++ b/doomsday/client/src/world/map.cpp @@ -834,8 +834,7 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound) // BspLeafs without a sector cluster don't get in. if(bspLeaf->hasCluster()) { - BlockmapCellBlock cellBlock = bspLeafBlockmap->toCellBlock(bspLeaf->poly().aaBox()); - bspLeafBlockmap->link(cellBlock, bspLeaf); + bspLeafBlockmap->link(bspLeaf->poly().aaBox(), bspLeaf); } } } @@ -1854,14 +1853,12 @@ void Map::link(mobj_t &mo, int flags) void Map::unlink(Polyobj &polyobj) { - BlockmapCellBlock cellBlock = d->polyobjBlockmap->toCellBlock(polyobj.aaBox); - d->polyobjBlockmap->unlink(cellBlock, &polyobj); + d->polyobjBlockmap->unlink(polyobj.aaBox, &polyobj); } void Map::link(Polyobj &polyobj) { - BlockmapCellBlock cellBlock = d->polyobjBlockmap->toCellBlock(polyobj.aaBox); - d->polyobjBlockmap->link(cellBlock, &polyobj); + d->polyobjBlockmap->link(polyobj.aaBox, &polyobj); } struct blockmapcellpolyobjsiterator_params_t @@ -2050,7 +2047,6 @@ BspLeaf &Map::bspLeafAt_FixedPrecision(Vector2d const &point) const fixed_t lineOriginX[2] = { DBL2FIX(partition.origin.x), DBL2FIX(partition.origin.y) }; fixed_t lineDirectionX[2] = { DBL2FIX(partition.direction.x), DBL2FIX(partition.direction.y) }; - int side = V2x_PointOnLineSide(pointX, lineOriginX, lineDirectionX); // Decend to the child subspace on "this" side. @@ -2102,14 +2098,12 @@ void Map::initSkyFix() /// @todo Can't we defer this? foreach(Sector *sector, d->sectors) { - if(!sector->sideCount()) - continue; + if(!sector->sideCount()) continue; bool const skyFloor = sector->floorSurface().hasSkyMaskedMaterial(); bool const skyCeil = sector->ceilingSurface().hasSkyMaskedMaterial(); - if(!skyFloor && !skyCeil) - continue; + if(!skyFloor && !skyCeil) continue; if(skyCeil) { @@ -2237,15 +2231,6 @@ Map::Lumobjs const &Map::lumobjs() const return d->lumobjs; } -Lumobj *Map::lumobj(int index) const -{ - if(index >= 0 && index < lumobjCount()) - { - return lumobjs().at(index); - } - return 0; -} - BiasSource &Map::addBiasSource(BiasSource const &biasSource) { if(biasSourceCount() < MAX_BIAS_SOURCES) @@ -2746,13 +2731,16 @@ struct VertexInfo // Order is firstly X axis major. if(int(vertex->origin().x) != int(other.vertex->origin().x)) + { return int(vertex->origin().x) - int(other.vertex->origin().x); + } // Order is secondly Y axis major. return int(vertex->origin().y) - int(other.vertex->origin().y); } - bool operator < (VertexInfo const &other) const { + bool operator < (VertexInfo const &other) const + { return compareVertexOrigins(other) < 0; } }; @@ -2832,8 +2820,7 @@ void pruneVertexes(Mesh &mesh, Map::Lines const &lines) { Vertex *vertex = info.vertex; - if(info.refCount) - continue; + if(info.refCount) continue; mesh.removeVertex(*vertex); @@ -2846,7 +2833,9 @@ void pruneVertexes(Mesh &mesh, Map::Lines const &lines) // Re-index with a contiguous range of indices. int ord = 0; foreach(Vertex *vertex, mesh.vertexes()) + { vertex->setIndexInMap(ord++); + } /// Update lines. @todo Line should handle this itself. foreach(Line *line, lines) @@ -2862,8 +2851,7 @@ void pruneVertexes(Mesh &mesh, Map::Lines const &lines) bool Map::endEditing() { - if(!d->editingEnabled) - return true; // Huh? + if(!d->editingEnabled) return true; // Huh? d->editingEnabled = false; diff --git a/doomsday/plugins/common/include/dmu_lib.h b/doomsday/plugins/common/include/dmu_lib.h index bbd7de1615..8e7990b265 100644 --- a/doomsday/plugins/common/include/dmu_lib.h +++ b/doomsday/plugins/common/include/dmu_lib.h @@ -151,6 +151,18 @@ typedef enum sidesection_e { extern "C" { #endif +/** + * Same as P_PathTraverse except 'from' and 'to' arguments are specified + * as two sets of separate X and Y map space coordinates. + */ +int P_PathXYTraverse2(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, + int flags, int (*callback) (TraceState *, struct intercept_s const *, void *), + void *context); + +int P_PathXYTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, + int (*callback) (TraceState *, struct intercept_s const *, void *), + void *context); + void P_BuildLineTagLists(void); void P_DestroyLineTagLists(void); diff --git a/doomsday/plugins/common/src/dmu_lib.cpp b/doomsday/plugins/common/src/dmu_lib.cpp index 7672b0bfb3..258c4b33ee 100644 --- a/doomsday/plugins/common/src/dmu_lib.cpp +++ b/doomsday/plugins/common/src/dmu_lib.cpp @@ -27,6 +27,24 @@ #include "dmu_lib.h" +int P_PathXYTraverse2(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, + int flags, int (*callback) (TraceState *, struct intercept_s const *, void *), + void *context) +{ + vec2d_t from = { fromX, fromY }; + vec2d_t to = { toX, toY }; + return P_PathTraverse2(from, to, flags, callback, context); +} + +int P_PathXYTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY, + int (*callback) (TraceState *, struct intercept_s const *, void *), + void *context) +{ + vec2d_t from = { fromX, fromY }; + vec2d_t to = { toX, toY }; + return P_PathTraverse(from, to, callback, context); +} + struct TagList { iterlist_t *list; diff --git a/doomsday/plugins/common/src/p_map.c b/doomsday/plugins/common/src/p_map.c index 6d7a5b0a45..26a0804a82 100644 --- a/doomsday/plugins/common/src/p_map.c +++ b/doomsday/plugins/common/src/p_map.c @@ -345,25 +345,29 @@ void P_TelefragMobjsTouchingPlayers(void) * * @param data Unused. */ -int PIT_CrossLine(Line* ld, void* data) +int PIT_CrossLine(Line *line, void *context) { - int flags = P_GetIntp(ld, DMU_FLAGS); + int flags = P_GetIntp(line, DMU_FLAGS); + + DENG_UNUSED(context); if((flags & DDLF_BLOCKING) || - (P_ToXLine(ld)->flags & ML_BLOCKMONSTERS) || - (!P_GetPtrp(ld, DMU_FRONT_SECTOR) || !P_GetPtrp(ld, DMU_BACK_SECTOR))) + (P_ToXLine(line)->flags & ML_BLOCKMONSTERS) || + (!P_GetPtrp(line, DMU_FRONT_SECTOR) || !P_GetPtrp(line, DMU_BACK_SECTOR))) { - AABoxd* aaBox = P_GetPtrp(ld, DMU_BOUNDING_BOX); + AABoxd *aaBox = P_GetPtrp(line, DMU_BOUNDING_BOX); if(!(tmBox.minX > aaBox->maxX || tmBox.maxX < aaBox->minX || tmBox.maxY < aaBox->minY || tmBox.minY > aaBox->maxY)) { - if(Line_PointXYOnSide(ld, startPos[VX], startPos[VY]) < 0 != - Line_PointXYOnSide(ld, endPos[VX], endPos[VY]) < 0) - // Line blocks trajectory. + // Line blocks trajectory? + if(Line_PointOnSide(line, startPos) < 0 != + Line_PointOnSide(line, endPos) < 0) + { return true; + } } } @@ -1525,8 +1529,8 @@ static boolean P_TryMove2(mobj_t *thing, coord_t x, coord_t y, boolean dropoff) // See if the line was crossed. if(P_ToXLine(ld)->special) { - side = Line_PointXYOnSide(ld, thing->origin[VX], thing->origin[VY]) < 0; - oldSide = Line_PointXYOnSide(ld, oldpos[VX], oldpos[VY]) < 0; + side = Line_PointOnSide(ld, thing->origin) < 0; + oldSide = Line_PointOnSide(ld, oldpos) < 0; if(side != oldSide) { #if __JHEXEN__ @@ -1575,7 +1579,7 @@ static boolean P_TryMove2(mobj_t *thing, coord_t x, coord_t y, boolean dropoff) while((ld = IterList_MoveIterator(spechit)) != NULL) { // See if the line was crossed. - side = Line_PointXYOnSide(ld, thing->origin[VX], thing->origin[VY]) < 0; + side = Line_PointOnSide(ld, thing->origin) < 0; checkForPushSpecial(ld, side, thing); } } @@ -1599,7 +1603,7 @@ boolean P_TryMoveXY(mobj_t* thing, coord_t x, coord_t y, boolean dropoff, boolea { // Move not possible, see if the thing hit a line and send a Hit // event to it. - XL_HitLine(tmHitLine, Line_PointXYOnSide(tmHitLine, thing->origin[VX], thing->origin[VY]) < 0, + XL_HitLine(tmHitLine, Line_PointOnSide(tmHitLine, thing->origin) < 0, thing); } @@ -1662,6 +1666,8 @@ int PTR_ShootTraverse(TraceState *trace, intercept_t const *in, void *context) Sector *contact, *originSector; boolean lineWasHit; + DENG_UNUSED(context); + tracePos[VX] = FIX2FLT(trace->line.origin[VX]); tracePos[VY] = FIX2FLT(trace->line.origin[VY]); tracePos[VZ] = shootZ; @@ -1676,7 +1682,7 @@ int PTR_ShootTraverse(TraceState *trace, intercept_t const *in, void *context) if(!backSec || !(xline->flags & ML_TWOSIDED)) { - if(Line_PointXYOnSide(li, tracePos[VX], tracePos[VY]) < 0) + if(Line_PointOnSide(li, tracePos) < 0) return false; // Continue traversal. } @@ -1960,6 +1966,8 @@ int PTR_AimTraverse(TraceState *trace, intercept_t const *in, void *context) coord_t slope, thingTopSlope, thingBottomSlope, dist; mobj_t *th; + DENG_UNUSED(context); + if(in->type == ICPT_LINE) { Line *li = in->d.line; @@ -1977,7 +1985,7 @@ int PTR_AimTraverse(TraceState *trace, intercept_t const *in, void *context) tracePos[VY] = FIX2FLT(trace->line.origin[VY]); tracePos[VZ] = shootZ; - return !(Line_PointXYOnSide(li, tracePos[VX], tracePos[VY]) < 0); + return !(Line_PointOnSide(li, tracePos) < 0); } // Crosses a two sided line. @@ -2111,7 +2119,7 @@ float P_AimLineAttack(mobj_t* t1, angle_t angle, coord_t distance) lineTarget = NULL; shootThing = t1; - P_PathTraverse(t1->origin, target, PT_ADDLINES | PT_ADDMOBJS, PTR_AimTraverse); + P_PathTraverse(t1->origin, target, PTR_AimTraverse, 0); if(lineTarget) { @@ -2165,7 +2173,7 @@ void P_LineAttack(mobj_t* t1, angle_t angle, coord_t distance, coord_t slope, in attackRange = distance; aimSlope = slope; - if(!P_PathTraverse(t1->origin, target, PT_ADDLINES | PT_ADDMOBJS, PTR_ShootTraverse)) + if(!P_PathTraverse(t1->origin, target, PTR_ShootTraverse, 0)) { #if __JHEXEN__ switch(PuffType) @@ -2353,11 +2361,11 @@ int PTR_UseTraverse(TraceState *trace, intercept_t const *in, void *context) * * @param player The player to test. */ -void P_UseLines(player_t* player) +void P_UseLines(player_t *player) { uint an; coord_t pos[3]; - mobj_t* mo; + mobj_t *mo; if(IS_CLIENT) { @@ -2379,8 +2387,7 @@ void P_UseLines(player_t* player) pos[VX] += USERANGE * FIX2FLT(finecosine[an]); pos[VY] += USERANGE * FIX2FLT(finesine[an]); - P_PathXYTraverse(mo->origin[VX], mo->origin[VY], pos[VX], pos[VY], - PT_ADDLINES, PTR_UseTraverse); + P_PathTraverse2(mo->origin, pos, PTF_LINE, PTR_UseTraverse, 0); } /** @@ -2450,13 +2457,13 @@ static boolean P_ThingHeightClip(mobj_t* thing) * * @param ld The line being slid along. */ -static void P_HitSlideLine(Line* ld) +static void P_HitSlideLine(Line *line) { int side; unsigned int an; angle_t lineAngle, moveAngle, deltaAngle; coord_t moveLen, newLen, d1[2]; - slopetype_t slopeType = P_GetIntp(ld, DMU_SLOPETYPE); + slopetype_t slopeType = P_GetIntp(line, DMU_SLOPETYPE); if(slopeType == ST_HORIZONTAL) { @@ -2469,8 +2476,8 @@ static void P_HitSlideLine(Line* ld) return; } - side = Line_PointXYOnSide(ld, slideMo->origin[VX], slideMo->origin[VY]) < 0; - P_GetDoublepv(ld, DMU_DXY, d1); + side = Line_PointOnSide(line, slideMo->origin) < 0; + P_GetDoublepv(line, DMU_DXY, d1); lineAngle = M_PointXYToAngle2(0, 0, d1[0], d1[1]); moveAngle = M_PointXYToAngle2(0, 0, tmMove[MX], tmMove[MY]); @@ -2491,28 +2498,30 @@ static void P_HitSlideLine(Line* ld) int PTR_SlideTraverse(TraceState *trace, intercept_t const *in, void *context) { - Line *li; + Line *line; + + DENG_UNUSED(context); if(in->type != ICPT_LINE) Con_Error("PTR_SlideTraverse: Not a line?"); - li = in->d.line; + line = in->d.line; - if(!(P_ToXLine(li)->flags & ML_TWOSIDED) || - !P_GetPtrp(li, DMU_FRONT_SECTOR) || !P_GetPtrp(li, DMU_BACK_SECTOR)) + if(!(P_ToXLine(line)->flags & ML_TWOSIDED) || + !P_GetPtrp(line, DMU_FRONT_SECTOR) || !P_GetPtrp(line, DMU_BACK_SECTOR)) { - if(Line_PointXYOnSide(li, slideMo->origin[VX], slideMo->origin[VY]) < 0) + if(Line_PointOnSide(line, slideMo->origin) < 0) return false; // Don't hit the back side. goto isblocking; } #if __JDOOM64__ - if(P_ToXLine(li)->flags & ML_BLOCKALL) // jd64 + if(P_ToXLine(line)->flags & ML_BLOCKALL) // jd64 goto isblocking; #endif - P_TraceAdjustOpening(trace, li); + P_TraceAdjustOpening(trace, line); if(trace->opening.range < slideMo->height) goto isblocking; // Doesn't fit. @@ -2533,7 +2542,7 @@ int PTR_SlideTraverse(TraceState *trace, intercept_t const *in, void *context) secondSlideDistance = bestSlideDistance; secondSlideLine = bestSlideLine; bestSlideDistance = in->distance; - bestSlideLine = li; + bestSlideLine = line; } return true; // Stop. @@ -2547,64 +2556,55 @@ int PTR_SlideTraverse(TraceState *trace, intercept_t const *in, void *context) * * @param mo The mobj to attempt the slide move. */ -void P_SlideMove(mobj_t* mo) +void P_SlideMove(mobj_t *mo) { - coord_t oldPos[2] = { mo->origin[VX], mo->origin[VY] }; - int hitcount = 3; +#ifdef _DEBUG + vec2d_t oldOrigin; +#endif + vec2d_t leadPos, trailPos; + int hitCount; - slideMo = mo; + if(!mo) return; // Huh? + +#ifdef _DEBUG + V2d_Copy(oldOrigin, mo->origin); +#endif + hitCount = 3; do { - coord_t leadpos[3], trailpos[3], newPos[3]; - - if(--hitcount == 0) + if(--hitCount == 0) goto stairstep; // Don't loop forever. // Trace along the three leading corners. - leadpos[VX] = trailpos[VX] = mo->origin[VX]; - leadpos[VY] = trailpos[VY] = mo->origin[VY]; - leadpos[VZ] = trailpos[VZ] = mo->origin[VZ]; - - if(mo->mom[MX] > 0) - { - leadpos[VX] += mo->radius; - trailpos[VX] -= mo->radius; - } - else - { - leadpos[VX] -= mo->radius; - trailpos[VX] += mo->radius; - } + V2d_Set(leadPos, mo->origin[VX] + (mo->mom[MX] > 0? mo->radius : -mo->radius), + mo->origin[VY] + (mo->mom[MY] > 0? mo->radius : -mo->radius)); - if(mo->mom[MY] > 0) - { - leadpos[VY] += mo->radius; - trailpos[VY] -= mo->radius; - } - else - { - leadpos[VY] -= mo->radius; - trailpos[VY] += mo->radius; - } + V2d_Set(trailPos, mo->origin[VX] - (mo->mom[MX] > 0? mo->radius : -mo->radius), + mo->origin[VY] - (mo->mom[MY] > 0? mo->radius : -mo->radius)); + slideMo = mo; bestSlideDistance = 1; - P_PathXYTraverse(leadpos[VX], leadpos[VY], - leadpos[VX] + mo->mom[MX], leadpos[VY] + mo->mom[MY], - PT_ADDLINES, PTR_SlideTraverse); - P_PathXYTraverse(trailpos[VX], leadpos[VY], - trailpos[VX] + mo->mom[MX], leadpos[VY] + mo->mom[MY], - PT_ADDLINES, PTR_SlideTraverse); - P_PathXYTraverse(leadpos[VX], trailpos[VY], - leadpos[VX] + mo->mom[MX], trailpos[VY] + mo->mom[MY], - PT_ADDLINES, PTR_SlideTraverse); + P_PathXYTraverse2(leadPos[VX], leadPos[VY], + leadPos[VX] + mo->mom[MX], leadPos[VY] + mo->mom[MY], + PTF_LINE, PTR_SlideTraverse, 0); + + P_PathXYTraverse2(trailPos[VX], leadPos[VY], + trailPos[VX] + mo->mom[MX], leadPos[VY] + mo->mom[MY], + PTF_LINE, PTR_SlideTraverse, 0); + + P_PathXYTraverse2(leadPos[VX], trailPos[VY], + leadPos[VX] + mo->mom[MX], trailPos[VY] + mo->mom[MY], + PTF_LINE, PTR_SlideTraverse, 0); // Move up to the wall. if(bestSlideDistance == 1) - { // The move must have hit the middle, so stairstep. $dropoff_fix + { + // The move must have hit the middle, so stairstep. $dropoff_fix stairstep: - /** + + /* * Ideally we would set the directional momentum of the mobj to zero * here should a move fail (to prevent noticeable stuttering against * the blocking surface/thing). However due to the mechanics of the @@ -2626,36 +2626,34 @@ void P_SlideMove(mobj_t* mo) bestSlideDistance -= (1.0f / 32); if(bestSlideDistance > 0) { - newPos[VX] = mo->mom[MX] * bestSlideDistance; - newPos[VY] = mo->mom[MY] * bestSlideDistance; - newPos[VZ] = DDMAXFLOAT; // Just initialize with *something*. + vec2d_t newPos = { mo->origin[VX] + mo->mom[MX] * bestSlideDistance, + mo->origin[VY] + mo->mom[MY] * bestSlideDistance }; // $dropoff_fix: Allow objects to drop off ledges #if __JHEXEN__ - if(!P_TryMoveXY(mo, mo->origin[VX] + newPos[VX], mo->origin[VY] + newPos[VY])) - goto stairstep; + if(!P_TryMoveXY(mo, newPos[VX], newPos[VY])) #else - if(!P_TryMoveXY(mo, mo->origin[VX] + newPos[VX], mo->origin[VY] + newPos[VY], - true, true)) - goto stairstep; + if(!P_TryMoveXY(mo, newPos[VX], newPos[VY], true, true)) #endif + { + goto stairstep; + } } // Now continue along the wall. // First calculate remainder. - bestSlideDistance = 1 - (bestSlideDistance + (1.0f / 32)); - if(bestSlideDistance > 1) - bestSlideDistance = 1; + bestSlideDistance = MIN_OF(1 - (bestSlideDistance + (1.0f / 32)), 1); if(bestSlideDistance <= 0) + { break; + } - tmMove[MX] = mo->mom[MX] * bestSlideDistance; - tmMove[MY] = mo->mom[MY] * bestSlideDistance; + V2d_Set(tmMove, mo->mom[VX] * bestSlideDistance, + mo->mom[VY] * bestSlideDistance); P_HitSlideLine(bestSlideLine); // Clip the move. - mo->mom[MX] = tmMove[MX]; - mo->mom[MY] = tmMove[MY]; + V2d_Copy(mo->mom, tmMove); // $dropoff_fix: Allow objects to drop off ledges: #if __JHEXEN__ @@ -2668,7 +2666,7 @@ void P_SlideMove(mobj_t* mo) #ifdef _DEBUG // Didn't move? - if(mo->player && mo->origin[VX] == oldPos[VX] && mo->origin[VY] == oldPos[VY]) + if(mo->player && mo->origin[VX] == oldOrigin[VX] && mo->origin[VY] == oldOrigin[VY]) { Con_Message("P_SlideMove: Mobj pos stays the same."); } @@ -3105,22 +3103,24 @@ static void checkForPushSpecial(Line* line, int side, mobj_t* mobj) int PTR_BounceTraverse(TraceState *trace, intercept_t const *in, void *context) { - Line *li; + Line *line; + + DENG_UNUSED(context); if(in->type != ICPT_LINE) Con_Error("PTR_BounceTraverse: Not a line?"); - li = in->d.line; + line = in->d.line; - if(!P_GetPtrp(li, DMU_FRONT_SECTOR) || !P_GetPtrp(li, DMU_BACK_SECTOR)) + if(!P_GetPtrp(line, DMU_FRONT_SECTOR) || !P_GetPtrp(line, DMU_BACK_SECTOR)) { - if(Line_PointXYOnSide(li, slideMo->origin[VX], slideMo->origin[VY]) < 0) + if(Line_PointOnSide(line, slideMo->origin) < 0) return false; // Don't hit the back side. goto bounceblocking; } - P_TraceAdjustOpening(trace, li); + P_TraceAdjustOpening(trace, line); if(trace->opening.range < slideMo->height) goto bounceblocking; // Doesn't fit. @@ -3137,63 +3137,51 @@ int PTR_BounceTraverse(TraceState *trace, intercept_t const *in, void *context) secondSlideDistance = bestSlideDistance; secondSlideLine = bestSlideLine; bestSlideDistance = in->distance; - bestSlideLine = li; + bestSlideLine = line; } return true; // Stop. } -void P_BounceWall(mobj_t* mo) +void P_BounceWall(mobj_t *mo) { - angle_t lineAngle, moveAngle, deltaAngle; - coord_t moveLen, leadPos[3], d1[2]; - unsigned int an; - int side; + coord_t leadPos[2], destPos[2]; - slideMo = mo; + // Trace a line from the origin to the would be destination point (which is + // apparently not reachable) to find a line from which we'll calculate the + // inverse "bounce" vector. + V2d_Set(leadPos, mo->origin[VX] + (mo->mom[MX] > 0? mo->radius : -mo->radius), + mo->origin[VY] + (mo->mom[MY] > 0? mo->radius : -mo->radius)); + V2d_Sum(destPos, leadPos, mo->mom); - // Trace along the three leading corners. - leadPos[VX] = mo->origin[VX]; - leadPos[VY] = mo->origin[VY]; - leadPos[VZ] = mo->origin[VZ]; - - if(mo->mom[MX] > 0) - leadPos[VX] += mo->radius; - else - leadPos[VX] -= mo->radius; - - if(mo->mom[MY] > 0) - leadPos[VY] += mo->radius; - else - leadPos[VY] -= mo->radius; - - bestSlideLine = NULL; + slideMo = mo; + bestSlideLine = 0; bestSlideDistance = 1; - P_PathXYTraverse(leadPos[VX], leadPos[VY], - leadPos[VX] + mo->mom[MX], leadPos[VY] + mo->mom[MY], - PT_ADDLINES, PTR_BounceTraverse); - if(!bestSlideLine) - return; // We don't want to crash. + P_PathTraverse2(leadPos, destPos, PTF_LINE, PTR_BounceTraverse, 0); - side = Line_PointXYOnSide(bestSlideLine, mo->origin[VX], mo->origin[VY]) < 0; - P_GetDoublepv(bestSlideLine, DMU_DXY, d1); - lineAngle = M_PointXYToAngle2(0, 0, d1[0], d1[1]); - if(side == 1) - lineAngle += ANG180; + if(bestSlideLine) + { + int const side = Line_PointOnSide(bestSlideLine, mo->origin) < 0; + angle_t lineAngle, moveAngle, deltaAngle; + coord_t lineDirection[2]; + coord_t moveLen; + uint an; - moveAngle = M_PointXYToAngle2(0, 0, mo->mom[MX], mo->mom[MY]); - deltaAngle = (2 * lineAngle) - moveAngle; + P_GetDoublepv(bestSlideLine, DMU_DXY, lineDirection); - moveLen = M_ApproxDistance(mo->mom[MX], mo->mom[MY]); - moveLen *= 0.75f; // Friction. + lineAngle = M_PointXYToAngle2(0, 0, lineDirection[0], lineDirection[1]) + side? ANG180 : 0; + moveAngle = M_PointXYToAngle2(0, 0, mo->mom[MX], mo->mom[MY]); + deltaAngle = (2 * lineAngle) - moveAngle; - if(moveLen < 1) - moveLen = 2; + moveLen = M_ApproxDistance(mo->mom[MX], mo->mom[MY]); + moveLen *= 0.75f; // Friction. + if(moveLen < 1) moveLen = 2; - an = deltaAngle >> ANGLETOFINESHIFT; - mo->mom[MX] = moveLen * FIX2FLT(finecosine[an]); - mo->mom[MY] = moveLen * FIX2FLT(finesine[an]); + an = deltaAngle >> ANGLETOFINESHIFT; + mo->mom[MX] = moveLen * FIX2FLT(finecosine[an]); + mo->mom[MY] = moveLen * FIX2FLT(finesine[an]); + } } int PTR_PuzzleItemTraverse(TraceState *trace, intercept_t const *in, void *context) @@ -3241,8 +3229,7 @@ int PTR_PuzzleItemTraverse(TraceState *trace, intercept_t const *in, void *conte return false; // Continue searching... } - if(Line_PointXYOnSide(line, puzzleItemUser->origin[VX], - puzzleItemUser->origin[VY]) < 0) + if(Line_PointOnSide(line, puzzleItemUser->origin) < 0) return true; // Don't use back sides. if(puzzleItemType != xline->arg1) @@ -3284,25 +3271,26 @@ int PTR_PuzzleItemTraverse(TraceState *trace, intercept_t const *in, void *conte * @param itemType The type of item to try to use. * @return boolean true if the puzzle item was used. */ -boolean P_UsePuzzleItem(player_t* player, int itemType) +boolean P_UsePuzzleItem(player_t *player, int itemType) { - int angle; - coord_t pos1[3], pos2[3]; + coord_t farUsePoint[2]; + mobj_t *mobj; + uint an; - puzzleItemType = itemType; - puzzleItemUser = player->plr->mo; - puzzleActivated = false; + DENG2_ASSERT(player != 0); - angle = player->plr->mo->angle >> ANGLETOFINESHIFT; + mobj = player->plr->mo; + if(!mobj) return false; // Huh? - memcpy(pos1, player->plr->mo->origin, sizeof(pos1)); - memcpy(pos2, player->plr->mo->origin, sizeof(pos2)); + puzzleItemType = itemType; + puzzleItemUser = mobj; + puzzleActivated = false; - pos2[VX] += FIX2FLT(USERANGE * finecosine[angle]); - pos2[VY] += FIX2FLT(USERANGE * finesine[angle]); + an = mobj->angle >> ANGLETOFINESHIFT; + V2d_Set(farUsePoint, mobj->origin[VX] + FIX2FLT(USERANGE * finecosine[an]), + mobj->origin[VY] + FIX2FLT(USERANGE * finesine [an])); - P_PathXYTraverse(pos1[VX], pos1[VY], pos2[VX], pos2[VY], - PT_ADDLINES | PT_ADDMOBJS, PTR_PuzzleItemTraverse); + P_PathTraverse(mobj->origin, farUsePoint, PTR_PuzzleItemTraverse, 0); if(!puzzleActivated) { diff --git a/doomsday/plugins/common/src/p_xgline.c b/doomsday/plugins/common/src/p_xgline.c index 1a7a89c8b8..1bdb978fab 100644 --- a/doomsday/plugins/common/src/p_xgline.c +++ b/doomsday/plugins/common/src/p_xgline.c @@ -1527,24 +1527,26 @@ int C_DECL XLTrav_Music(Line* line, boolean dummy, void* context, return false; // Only do this once! } -int C_DECL XLTrav_LineTeleport(Line* newLine, boolean dummy, - void* context, void* context2, mobj_t* mobj) +int C_DECL XLTrav_LineTeleport(Line *newLine, boolean dummy, + void *context, void* context2, mobj_t* mobj) { // Maximum units to move object to avoid hiccups. #define FUDGEFACTOR 10 int fudge = FUDGEFACTOR; int side = 0, stepDown; - unsigned int an; - mobj_t* flash; - Line* line = (Line *) context; - linetype_t* info = (linetype_t *) context2; - Vertex* newV1, *newV2, *oldV1, *oldV2; - Sector* newFrontSec, *newBackSec; - coord_t newX, newY, newZ, pos, s, c; + uint an; + mobj_t *flash; + Line *line = (Line *) context; + linetype_t *info = (linetype_t *) context2; + Vertex *newV1, *newV2, *oldV1, *oldV2; + Sector *newFrontSec, *newBackSec; + coord_t newPos[3], pos, s, c; coord_t oldLineDelta[2], newLineDelta[2]; angle_t angle; + DENG_UNUSED(dummy); + // Don't teleport things marked noteleport! if(mobj->flags2 & MF2_NOTELEPORT) { @@ -1607,8 +1609,8 @@ int C_DECL XLTrav_LineTeleport(Line* newLine, boolean dummy, M_PointXYToAngle2(0, 0, oldLineDelta[0], oldLineDelta[1]); // Interpolate position across the exit line. - newX = P_GetDoublep(newV2, DMU_X) - (pos * newLineDelta[0]); - newY = P_GetDoublep(newV2, DMU_Y) - (pos * newLineDelta[1]); + newPos[VX] = P_GetDoublep(newV2, DMU_X) - (pos * newLineDelta[0]); + newPos[VY] = P_GetDoublep(newV2, DMU_Y) - (pos * newLineDelta[1]); // Sine, cosine of angle adjustment s = FIX2FLT(finesine[angle >> ANGLETOFINESHIFT]); @@ -1622,7 +1624,7 @@ int C_DECL XLTrav_LineTeleport(Line* newLine, boolean dummy, stepDown = false; // Height of thing above ground. - newZ = mobj->origin[VZ] - mobj->floorZ; + newPos[VZ] = mobj->origin[VZ] - mobj->floorZ; /** * Side to exit the line on positionally. @@ -1651,16 +1653,16 @@ int C_DECL XLTrav_LineTeleport(Line* newLine, boolean dummy, side = 1; // Make sure we are on correct side of exit line. - while(Line_PointXYOnSide(newLine, newX, newY) < 0 != side && --fudge >= 0) + while(Line_PointOnSide(newLine, newPos) < 0 != side && --fudge >= 0) { if(fabs(newLineDelta[0]) > fabs(newLineDelta[1])) - newY -= FIX2FLT((newLineDelta[0] < 0) != side ? -1 : 1); + newPos[VY] -= FIX2FLT((newLineDelta[0] < 0) != side ? -1 : 1); else - newX += FIX2FLT((newLineDelta[1] < 0) != side ? -1 : 1); + newPos[VX] += FIX2FLT((newLineDelta[1] < 0) != side ? -1 : 1); } // Do the Teleport - if(!P_TeleportMove(mobj, newX, newY, (info->iparm[5] > 0? true : false))) + if(!P_TeleportMove(mobj, newPos[VX], newPos[VY], (info->iparm[5] > 0? true : false))) { XG_Dev("XLTrav_Teleport: Something went horribly wrong... aborting."); return false; @@ -1670,20 +1672,20 @@ int C_DECL XLTrav_LineTeleport(Line* newLine, boolean dummy, // level at the exit is measured as the higher of the two floor heights // at the exit line. if(stepDown) - mobj->origin[VZ] = newZ + P_GetDoublep(newFrontSec, DMU_FLOOR_HEIGHT); + mobj->origin[VZ] = newPos[VZ] + P_GetDoublep(newFrontSec, DMU_FLOOR_HEIGHT); else - mobj->origin[VZ] = newZ + P_GetDoublep(newBackSec, DMU_FLOOR_HEIGHT); + mobj->origin[VZ] = newPos[VZ] + P_GetDoublep(newBackSec, DMU_FLOOR_HEIGHT); // Rotate mobj's orientation according to difference in line angles. mobj->angle += angle; // Update momentum of mobj crossing teleporter line? - newX = mobj->mom[MX]; - newY = mobj->mom[MY]; + newPos[VX] = mobj->mom[MX]; + newPos[VY] = mobj->mom[MY]; // Rotate mobj's momentum to come out of exit just like it entered. - mobj->mom[MX] = (newX * c) - (newY * s); - mobj->mom[MY] = (newY * c) + (newX * s); + mobj->mom[MX] = (newPos[VX] * c) - (newPos[VY] * s); + mobj->mom[MY] = (newPos[VY] * c) + (newPos[VX] * s); // Feet clipped? if(mobj->flags2 & MF2_FLOORCLIP)