Skip to content

Commit

Permalink
API: Replaced P_BspLeafAtPoint_FixedPrecision()
Browse files Browse the repository at this point in the history
Plugins should now use P_SectorAtPoint_FixedPrecision() to determine
the sector at some arbitrary point in the current map. Previously it
was necessary to first determine the BSP leaf at that point and then
use the DMU API to obtain the attributed sector. Behavior/outcome is
not affected.
  • Loading branch information
danij-deng committed Oct 2, 2013
1 parent b2467c7 commit a4c8c93
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 77 deletions.
48 changes: 25 additions & 23 deletions doomsday/api/api_map.h
Expand Up @@ -200,11 +200,32 @@ DENG_API_TYPEDEF(Map)
*/
int (*S_TouchingMobjsIterator)(Sector* sector, int (*callback) (struct mobj_s*, void*), void* parameters);

/**
* Determine the Sector on the back side of the binary space partition that
* lies in front of the specified point within the CURRENT map's coordinate
* space.
*
* A valid Sector is always returned unless the BSP leaf at that point is
* fully degenerate (thus no sector can be determnied).
*
* Note: The point may not actually lay within the sector returned! (however,
* it is on the same side of the space partition!).
*
* @param x X coordinate of the point to test.
* @param y Y coordinate of the point to test.
*
* @return Sector attributed to the BSP leaf at the specified point.
*/
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);
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);
void (*MO_Destroy)(struct mobj_s *mo);
struct mobj_s* (*MO_MobjForID)(int id);
struct mobj_s *(*MO_MobjForID)(int id);
void (*MO_SetState)(struct mobj_s *mo, int statenum);
void (*MO_Link)(struct mobj_s *mo, byte flags);
int (*MO_Unlink)(struct mobj_s *mo);
Expand Down Expand Up @@ -288,24 +309,6 @@ DENG_API_TYPEDEF(Map)
*/
void (*PO_SetCallback)(void (*func)(struct mobj_s*, void*, void*));

// BSP Leafs

BspLeaf* (*BL_AtPoint_FixedPrecision)(coord_t const point[2]);

/**
* Determine the BSP leaf on the back side of the BS partition that lies in
* front of the specified point within the CURRENT map's coordinate space.
*
* Always returns a valid BspLeaf although the point may not actually lay
* within it (however it is on the same side of the space partition!).
*
* @param x X coordinate of the point to test.
* @param y Y coordinate of the point to test.
*
* @return BspLeaf instance for that BSP node's leaf.
*/
BspLeaf* (*BL_AtPoint_FixedPrecisionXY)(coord_t x, coord_t y);

// Iterators

int (*Box_MobjsIterator)(const AABoxd* box, int (*callback) (struct mobj_s*, void*), void* parameters);
Expand Down Expand Up @@ -586,6 +589,8 @@ DENG_API_T(Map);
#define P_LineMobjsIterator _api_Map.LD_MobjsIterator

#define P_SectorTouchingMobjsIterator _api_Map.S_TouchingMobjsIterator
#define P_SectorAtPoint_FixedPrecision _api_Map.S_AtPoint_FixedPrecision
#define P_SectorAtPoint_FixedPrecisionXY _api_Map.S_AtPoint_FixedPrecisionXY

#define P_MobjCreateXYZ _api_Map.MO_CreateXYZ
#define P_MobjDestroy _api_Map.MO_Destroy
Expand All @@ -609,9 +614,6 @@ DENG_API_T(Map);
#define P_PolyobjByTag _api_Map.PO_PolyobjByTag
#define P_SetPolyobjCallback _api_Map.PO_SetCallback

#define P_BspLeafAtPoint_FixedPrecision _api_Map.BL_AtPoint_FixedPrecision
#define P_BspLeafAtPoint_FixedPrecisionXY _api_Map.BL_AtPoint_FixedPrecisionXY

#define P_MobjsBoxIterator _api_Map.Box_MobjsIterator
#define P_LinesBoxIterator _api_Map.Box_LinesIterator
#define P_AllLinesBoxIterator _api_Map.Box_AllLinesIterator
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/client/cl_player.cpp
Expand Up @@ -316,9 +316,9 @@ void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground)
P_MobjLink(mo, DDLINK_SECTOR | DDLINK_BLOCKMAP);
}

mo->_bspLeaf = P_BspLeafAtPoint_FixedPrecision(mo->origin);
mo->floorZ = Mobj_Cluster(*mo).floor().height();
mo->ceilingZ = Mobj_Cluster(*mo).ceiling().height();
mo->_bspLeaf = &App_World().map().bspLeafAt_FixedPrecision(Mobj_Origin(*mo));
mo->floorZ = Mobj_Sector(mo)->floor().height();
mo->ceilingZ = Mobj_Sector(mo)->ceiling().height();

if(onground)
{
Expand Down
35 changes: 17 additions & 18 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -1599,21 +1599,6 @@ DENG_EXTERN_C int P_MobjUnlink(mobj_t *mo)
return Mobj_BspLeafAtOrigin(*mo).map().unlink(*mo);
}

#undef P_BspLeafAtPoint_FixedPrecision
DENG_EXTERN_C BspLeaf *P_BspLeafAtPoint_FixedPrecision(const_pvec2d_t point)
{
if(!App_World().hasMap()) return 0;
return &App_World().map().bspLeafAt_FixedPrecision(point);
}

#undef P_BspLeafAtPoint_FixedPrecisionXY
DENG_EXTERN_C BspLeaf *P_BspLeafAtPoint_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);
}

#undef P_MobjLinesIterator
DENG_EXTERN_C int P_MobjLinesIterator(mobj_t *mo, int (*callback) (Line *, void *), void *parameters)
{
Expand Down Expand Up @@ -1642,6 +1627,21 @@ DENG_EXTERN_C int P_SectorTouchingMobjsIterator(Sector *sector, int (*callback)
return sector->map().sectorTouchingMobjsIterator(sector, callback, parameters);
}

#undef P_SectorAtPoint_FixedPrecision
DENG_EXTERN_C Sector *P_SectorAtPoint_FixedPrecision(const_pvec2d_t point)
{
if(!App_World().hasMap()) return 0;
return App_World().map().bspLeafAt_FixedPrecision(point).sectorPtr();
}

#undef P_SectorAtPoint_FixedPrecisionXY
DENG_EXTERN_C Sector *P_SectorAtPoint_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 P_MobjsBoxIterator
DENG_EXTERN_C int P_MobjsBoxIterator(AABoxd const *box,
int (*callback) (mobj_t *, void *), void *parameters)
Expand Down Expand Up @@ -1907,6 +1907,8 @@ DENG_DECLARE_API(Map) =
P_LineMobjsIterator,

P_SectorTouchingMobjsIterator,
P_SectorAtPoint_FixedPrecision,
P_SectorAtPoint_FixedPrecisionXY,

P_MobjCreateXYZ,
P_MobjDestroy,
Expand All @@ -1930,9 +1932,6 @@ DENG_DECLARE_API(Map) =
P_PolyobjByTag,
P_SetPolyobjCallback,

P_BspLeafAtPoint_FixedPrecision,
P_BspLeafAtPoint_FixedPrecisionXY,

P_MobjsBoxIterator,
P_LinesBoxIterator,
P_AllLinesBoxIterator,
Expand Down
42 changes: 21 additions & 21 deletions doomsday/plugins/common/src/p_map.c
Expand Up @@ -256,7 +256,7 @@ int PIT_StompThing(mobj_t* mo, void* data)
boolean P_TeleportMove(mobj_t *thing, coord_t x, coord_t y, boolean alwaysStomp)
{
int stomping;
BspLeaf *newBspLeaf;
Sector *newSector;
AABoxd tmBoxExpanded;

// Kill anything occupying the position.
Expand All @@ -271,7 +271,7 @@ boolean P_TeleportMove(mobj_t *thing, coord_t x, coord_t y, boolean alwaysStomp)
tmBox.maxX = tm[VX] + tmThing->radius;
tmBox.maxY = tm[VY] + tmThing->radius;

newBspLeaf = P_BspLeafAtPoint_FixedPrecision(tm);
newSector = P_SectorAtPoint_FixedPrecision(tm);

ceilingLine = floorLine = NULL;
#if !__JHEXEN__
Expand All @@ -281,10 +281,10 @@ boolean P_TeleportMove(mobj_t *thing, coord_t x, coord_t y, boolean alwaysStomp)

// The base floor / ceiling is from the BSP leaf that contains the
// point. Any contacted lines the step closer together will adjust them.
tmFloorZ = tmDropoffZ = P_GetDoublep(newBspLeaf, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newBspLeaf, DMU_CEILING_HEIGHT);
tmFloorZ = tmDropoffZ = P_GetDoublep(newSector, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newSector, DMU_CEILING_HEIGHT);
#if __JHEXEN__
tmFloorMaterial = P_GetPtrp(newBspLeaf, DMU_FLOOR_MATERIAL);
tmFloorMaterial = P_GetPtrp(newSector, DMU_FLOOR_MATERIAL);
#endif

IterList_Clear(spechit);
Expand Down Expand Up @@ -1145,7 +1145,7 @@ int PIT_CheckLine(Line* ld, void* data)
boolean P_CheckPositionXYZ(mobj_t *thing, coord_t x, coord_t y, coord_t z)
{
AABoxd tmBoxExpanded;
Sector *newSec;
Sector *newSector;

tmThing = thing;

Expand All @@ -1168,7 +1168,7 @@ boolean P_CheckPositionXYZ(mobj_t *thing, coord_t x, coord_t y, coord_t z)
tmBox.maxX = tm[VX] + tmThing->radius;
tmBox.maxY = tm[VY] + tmThing->radius;

newSec = P_GetPtrp(P_BspLeafAtPoint_FixedPrecision(tm), DMU_SECTOR);
newSector = P_SectorAtPoint_FixedPrecision(tm);

ceilingLine = floorLine = NULL;
#if !__JHEXEN__
Expand All @@ -1178,10 +1178,10 @@ boolean P_CheckPositionXYZ(mobj_t *thing, coord_t x, coord_t y, coord_t z)

// The base floor/ceiling is from the BSP leaf that contains the point.
// Any contacted lines the step closer together will adjust them.
tmFloorZ = tmDropoffZ = P_GetDoublep(newSec, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newSec, DMU_CEILING_HEIGHT);
tmFloorZ = tmDropoffZ = P_GetDoublep(newSector, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newSector, DMU_CEILING_HEIGHT);
#if __JHEXEN__
tmFloorMaterial = P_GetPtrp(newSec, DMU_FLOOR_MATERIAL);
tmFloorMaterial = P_GetPtrp(newSector, DMU_FLOOR_MATERIAL);
#endif

IterList_Clear(spechit);
Expand Down Expand Up @@ -1659,7 +1659,7 @@ int PTR_ShootTraverse(intercept_t const *in, void *parameters)
mobj_t *th;
divline_t const *trace = P_TraceLOS();
TraceOpening const *opening;
BspLeaf *contact, *originBspLeaf;
Sector *contact, *originSector;
boolean lineWasHit;

tracePos[VX] = FIX2FLT(trace->origin[VX]);
Expand Down Expand Up @@ -1746,16 +1746,16 @@ int PTR_ShootTraverse(intercept_t const *in, void *parameters)

lineWasHit = true;

// This is the BSP leaf where the trace originates.
originBspLeaf = P_BspLeafAtPoint_FixedPrecision(tracePos);
// This is the sector where the trace originates.
originSector = P_SectorAtPoint_FixedPrecision(tracePos);

d[VX] = pos[VX] - tracePos[VX];
d[VY] = pos[VY] - tracePos[VY];
d[VZ] = pos[VZ] - tracePos[VZ];

if(!INRANGE_OF(d[VZ], 0, .0001f)) // Epsilon
{
contact = P_BspLeafAtPoint_FixedPrecision(pos);
contact = P_SectorAtPoint_FixedPrecision(pos);
step = M_ApproxDistance3(d[VX], d[VY], d[VZ] * 1.2/*aspect ratio*/);
stepv[VX] = d[VX] / step;
stepv[VY] = d[VY] / step;
Expand All @@ -1764,15 +1764,15 @@ int PTR_ShootTraverse(intercept_t const *in, void *parameters)
cFloor = P_GetDoublep(contact, DMU_FLOOR_HEIGHT);
cCeil = P_GetDoublep(contact, DMU_CEILING_HEIGHT);
// Backtrack until we find a non-empty sector.
while(cCeil <= cFloor && contact != originBspLeaf)
while(cCeil <= cFloor && contact != originSector)
{
d[VX] -= 8 * stepv[VX];
d[VY] -= 8 * stepv[VY];
d[VZ] -= 8 * stepv[VZ];
pos[VX] = tracePos[VX] + d[VX];
pos[VY] = tracePos[VY] + d[VY];
pos[VZ] = tracePos[VZ] + d[VZ];
contact = P_BspLeafAtPoint_FixedPrecision(pos);
contact = P_SectorAtPoint_FixedPrecision(pos);
}

// Should we backtrack to hit a plane instead?
Expand Down Expand Up @@ -2954,7 +2954,7 @@ int PIT_CheckOnmobjZ(mobj_t* thing, void* data)

mobj_t *P_CheckOnMobj(mobj_t *thing)
{
BspLeaf *newBspLeaf;
Sector *newSector;
coord_t pos[3];
mobj_t oldMo;
AABoxd tmBoxExpanded;
Expand Down Expand Up @@ -2985,15 +2985,15 @@ mobj_t *P_CheckOnMobj(mobj_t *thing)
tmBox.maxX = pos[VX] + tmThing->radius;
tmBox.maxY = pos[VY] + tmThing->radius;

newBspLeaf = P_BspLeafAtPoint_FixedPrecision(pos);
newSector = P_SectorAtPoint_FixedPrecision(pos);
ceilingLine = floorLine = NULL;

// The base floor/ceiling is from the BSP leaf that contains the point.
// Any contacted lines the step closer together will adjust them.

tmFloorZ = tmDropoffZ = P_GetDoublep(newBspLeaf, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newBspLeaf, DMU_CEILING_HEIGHT);
tmFloorMaterial = P_GetPtrp(newBspLeaf, DMU_FLOOR_MATERIAL);
tmFloorZ = tmDropoffZ = P_GetDoublep(newSector, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetDoublep(newSector, DMU_CEILING_HEIGHT);
tmFloorMaterial = P_GetPtrp(newSector, DMU_FLOOR_MATERIAL);

IterList_Clear(spechit);

Expand Down
3 changes: 1 addition & 2 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -421,8 +421,7 @@ static void initMapSpots()
// Sound sequence origin?
if(spot->doomEdNum >= 1400 && spot->doomEdNum < 1410)
{
BspLeaf *bspLeaf = P_BspLeafAtPoint_FixedPrecision(spot->origin);
xsector_t *xsector = P_ToXSector((Sector *)P_GetPtrp(bspLeaf, DMU_SECTOR));
xsector_t *xsector = P_ToXSector(P_SectorAtPoint_FixedPrecision(spot->origin));

xsector->seqType = seqtype_t(spot->doomEdNum - 1400);
continue;
Expand Down
5 changes: 2 additions & 3 deletions doomsday/plugins/common/src/p_saveg.cpp
Expand Up @@ -4753,7 +4753,7 @@ static void writeSoundSequences()
{
for(; i < numpolyobjs; ++i)
{
if(node->mobj == (mobj_t*) P_GetPolyobj(i | 0x80000000))
if(node->mobj == (mobj_t *) P_GetPolyobj(i | 0x80000000))
{
break;
}
Expand All @@ -4764,8 +4764,7 @@ static void writeSoundSequences()
if(i == numpolyobjs)
{
// The sound's emitter is the sector, not the polyobj itself.
BspLeaf *bspLeaf = P_BspLeafAtPoint_FixedPrecision(node->mobj->origin);
difference = P_ToIndex((Sector *)P_GetPtrp(bspLeaf, DMU_SECTOR));
difference = P_ToIndex(P_SectorAtPoint_FixedPrecision(node->mobj->origin));
SV_WriteLong(0); // 0 -- sector sound origin.
}
else
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_xgsec.c
Expand Up @@ -3136,7 +3136,7 @@ D_CMD(MovePlane)
coord_t point[2];
point[VX] = (coord_t)strtol(argv[2], 0, 0);
point[VY] = (coord_t)strtol(argv[3], 0, 0);
sector = P_GetPtrp(P_BspLeafAtPoint_FixedPrecision(point), DMU_SECTOR);
sector = P_SectorAtPoint_FixedPrecision(point);

p = 4;
}
Expand Down
3 changes: 1 addition & 2 deletions doomsday/plugins/doom64/include/p_mobj.h
Expand Up @@ -106,8 +106,7 @@
*
* Every mobj_t is linked into a single sector
* based on its origin coordinates.
* The BspLeaf is found with P_BspLeafAtPoint_FixedPrecisionXY(x,y),
* and the Sector can be found with bspLeaf->sector.
* The Sector can be found with P_SectorAtPoint_FixedPrecisionXY(x,y).
* The sector links are only used by the rendering code,
* the play simulation does not care about them at all.
*
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/heretic/src/p_mobj.c
Expand Up @@ -1124,7 +1124,7 @@ mobj_t* P_SpawnMobj(mobjtype_t type, coord_t const pos[3], angle_t angle, int sp
void P_RepositionMace(mobj_t *mo)
{
mapspot_t const *mapSpot;
BspLeaf *bspLeaf;
Sector *sector;

DENG_ASSERT(mo && mo->type == MT_WMACE);
#if _DEBUG
Expand All @@ -1144,12 +1144,12 @@ void P_RepositionMace(mobj_t *mo)
{
mo->origin[VX] = mapSpot->origin[VX];
mo->origin[VY] = mapSpot->origin[VY];
bspLeaf = P_BspLeafAtPoint_FixedPrecision(mo->origin);
sector = P_SectorAtPoint_FixedPrecision(mo->origin);

mo->floorZ = P_GetDoublep(bspLeaf, DMU_CEILING_HEIGHT);
mo->floorZ = P_GetDoublep(sector, DMU_CEILING_HEIGHT);
mo->origin[VZ] = mo->floorZ;

mo->ceilingZ = P_GetDoublep(bspLeaf, DMU_CEILING_HEIGHT);
mo->ceilingZ = P_GetDoublep(sector, DMU_CEILING_HEIGHT);
}
P_MobjSetOrigin(mo);

Expand Down

0 comments on commit a4c8c93

Please sign in to comment.