Skip to content

Commit

Permalink
API: Use Mobj_Sector() to determine the sector at the mobj's origin
Browse files Browse the repository at this point in the history
Rather than using the DMU_API to resolve the sector from a BSP leaf
directly, plugins should now use Mobj_Sector() to determine this.

The map API is now at version #3 (DE_API_MAP = 1102).
  • Loading branch information
danij-deng committed Oct 2, 2013
1 parent 14f727d commit e99991e
Show file tree
Hide file tree
Showing 42 changed files with 506 additions and 793 deletions.
31 changes: 21 additions & 10 deletions doomsday/api/api_map.h
Expand Up @@ -203,33 +203,43 @@ DENG_API_TYPEDEF(Map)
// 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);
void (*MO_Destroy)(struct mobj_s* mo);
void (*MO_Destroy)(struct mobj_s *mo);
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);
void (*MO_SpawnDamageParticleGen)(struct mobj_s* mo, struct mobj_s* inflictor, int amount);
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);
void (*MO_SpawnDamageParticleGen)(struct mobj_s *mo, struct mobj_s* inflictor, int amount);

/**
* The callback function will be called once for each line that crosses
* trough the object. This means all the lines will be two-sided.
*/
int (*MO_LinesIterator)(struct mobj_s* mo, int (*callback) (Line*, void*), void* parameters);
int (*MO_LinesIterator)(struct mobj_s *mo, int (*callback) (Line*, void*), void* parameters);

/**
* Increment validCount before calling this routine. The callback function
* will be called once for each sector the mobj is touching (totally or
* partly inside). This is not a 3D check; the mobj may actually reside
* above or under the sector.
*/
int (*MO_SectorsIterator)(struct mobj_s* mo, int (*callback) (Sector*, void*), void* parameters);
int (*MO_SectorsIterator)(struct mobj_s *mo, int (*callback) (Sector*, void*), void* parameters);

/**
* Calculate the visible @a origin of @a mobj in world space, including
* any short range offset.
*/
void (*MO_OriginSmoothed)(struct mobj_s* mobj, coord_t origin[3]);
angle_t (*MO_AngleSmoothed)(struct mobj_s* mobj);
void (*MO_OriginSmoothed)(struct mobj_s *mobj, coord_t origin[3]);
angle_t (*MO_AngleSmoothed)(struct mobj_s *mobj);

/**
* Returns the sector attributed to the BSP leaf in which the mobj's origin
* currently falls. If the mobj is not yet linked then @c 0 is returned.
*
* Note: The mobj is necessarily within the bounds of the sector!
*
* @param mobj Mobj instance.
*/
Sector *(*MO_Sector)(struct mobj_s const *mobj);

// Polyobjs

Expand Down Expand Up @@ -349,7 +359,7 @@ DENG_API_TYPEDEF(Map)
*
* @note Always returns a valid divline_t even if there is no current map.
*/
Divline const * (*TraceLOS)(void);
Divline const *(*TraceLOS)(void);

/**
* Retrieve an immutable copy of the TraceOpening state for the CURRENT map.
Expand Down Expand Up @@ -588,6 +598,7 @@ DENG_API_T(Map);
#define P_MobjSectorsIterator _api_Map.MO_SectorsIterator
#define Mobj_AngleSmoothed _api_Map.MO_AngleSmoothed
#define Mobj_OriginSmoothed _api_Map.MO_OriginSmoothed
#define Mobj_Sector _api_Map.MO_Sector

#define P_PolyobjMoveXY _api_Map.PO_MoveXY
#define P_PolyobjRotate _api_Map.PO_Rotate
Expand Down
3 changes: 2 additions & 1 deletion doomsday/api/apis.h
Expand Up @@ -93,7 +93,8 @@ enum {

DE_API_MAP_v1 = 1100, // 1.10
DE_API_MAP_v2 = 1101, // 1.11
DE_API_MAP = DE_API_MAP_v2,
DE_API_MAP_v3 = 1102, // 1.13
DE_API_MAP = DE_API_MAP_v3,

DE_API_MAP_EDIT_v1 = 1200, // 1.10
DE_API_MAP_EDIT_v2 = 1201, // 1.11
Expand Down
10 changes: 5 additions & 5 deletions doomsday/api/dd_share.h
Expand Up @@ -624,9 +624,9 @@ enum { MX, MY, MZ };
DD_BASE_DDMOBJ_ELEMENTS() \
\
nodeindex_t lineRoot; /* lines to which this is linked */ \
struct mobj_s* sNext, **sPrev; /* links in sector (if needed) */ \
struct mobj_s *sNext, **sPrev; /* links in sector (if needed) */ \
\
BspLeaf *bspLeaf; /* bspLeaf in which this resides */ \
BspLeaf *bspLeaf; /* bspLeaf in which this resides */ \
coord_t mom[3]; \
angle_t angle; \
spritenum_t sprite; /* used to find patch_t and flip value */ \
Expand All @@ -637,13 +637,13 @@ enum { MX, MY, MZ };
coord_t floorClip; /* value to use for floor clipping */ \
int valid; /* if == valid, already checked */ \
int type; /* mobj type */ \
struct state_s* state; \
struct state_s *state; \
int tics; /* state tic counter */ \
coord_t floorZ; /* highest contacted floor */ \
coord_t ceilingZ; /* lowest contacted ceiling */ \
struct mobj_s* onMobj; /* the mobj this one is on top of. */ \
struct mobj_s *onMobj; /* the mobj this one is on top of. */ \
boolean wallHit; /* the mobj is hitting a wall. */ \
struct ddplayer_s* dPlayer; /* NULL if not a player mobj. */ \
struct ddplayer_s *dPlayer; /* NULL if not a player mobj. */ \
coord_t srvo[3]; /* short-range visual offset (xyz) */ \
short visAngle; /* visual angle ("angle-servo") */ \
int selector; /* multipurpose info */ \
Expand Down
17 changes: 5 additions & 12 deletions doomsday/client/include/world/p_object.h
Expand Up @@ -72,7 +72,7 @@ void P_MobjRecycle(mobj_t *mobj);
*
* @todo Automatically link all new mobjs into the map (making this redundant).
*/
bool Mobj_IsLinked(mobj_t &mobj);
bool Mobj_IsLinked(mobj_t const &mobj);

/**
* Returns a copy of the mobj's map space origin.
Expand Down Expand Up @@ -102,7 +102,7 @@ boolean Mobj_SetOrigin(mobj_t *mobj, coord_t x, coord_t y, coord_t z);
*
* @see Mobj_IsLinked(), Mobj_SetOrigin()
*/
BspLeaf &Mobj_BspLeafAtOrigin(mobj_t &mobj);
BspLeaf &Mobj_BspLeafAtOrigin(mobj_t const &mobj);

/**
* Returns @c true iff the sector cluster at the mobj's origin is known (i.e.,
Expand All @@ -111,7 +111,7 @@ BspLeaf &Mobj_BspLeafAtOrigin(mobj_t &mobj);
*
* @param mobj Mobj instance.
*/
bool Mobj_HasCluster(mobj_t &mobj);
bool Mobj_HasCluster(mobj_t const &mobj);

/**
* Returns the sector cluster in which the mobj currently resides.
Expand All @@ -120,7 +120,7 @@ bool Mobj_HasCluster(mobj_t &mobj);
*
* @see Mobj_HasCluster()
*/
SectorCluster &Mobj_Cluster(mobj_t &mobj);
SectorCluster &Mobj_Cluster(mobj_t const &mobj);

/**
* Returns a pointer to sector cluster in which the mobj currently resides, or
Expand All @@ -130,14 +130,7 @@ SectorCluster &Mobj_Cluster(mobj_t &mobj);
*
* @see Mobj_HasCluster()
*/
SectorCluster *Mobj_ClusterPtr(mobj_t &mobj);

/**
* Convenient method of returning the sector in which the mobj currently resides.
*
* @see Mobj_Cluster(), Sector::Cluster::sector()
*/
Sector &Mobj_Sector(mobj_t &mobj);
SectorCluster *Mobj_ClusterPtr(mobj_t const &mobj);

#ifdef __CLIENT__

Expand Down
18 changes: 10 additions & 8 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -1761,18 +1761,19 @@ DENG_EXTERN_C void P_SetTraceOpening(Line *line)
}

// p_mobj.c
DENG_EXTERN_C mobj_t* P_MobjCreateXYZ(thinkfunc_t function, coord_t x, coord_t y, coord_t z, angle_t angle, coord_t radius, coord_t height, int ddflags);
DENG_EXTERN_C void P_MobjDestroy(mobj_t* mo);
DENG_EXTERN_C void P_MobjDestroy(mobj_t* mobj);
DENG_EXTERN_C void P_MobjSetState(mobj_t* mobj, int statenum);
DENG_EXTERN_C angle_t Mobj_AngleSmoothed(mobj_t* mo);
DENG_EXTERN_C void Mobj_OriginSmoothed(mobj_t* mo, coord_t origin[3]);
DENG_EXTERN_C mobj_t *P_MobjCreateXYZ(thinkfunc_t function, coord_t x, coord_t y, coord_t z, angle_t angle, coord_t radius, coord_t height, int ddflags);
DENG_EXTERN_C void P_MobjDestroy(mobj_t *mobj);
DENG_EXTERN_C void P_MobjDestroy(mobj_t *mobj);
DENG_EXTERN_C void P_MobjSetState(mobj_t *mobj, int statenum);
DENG_EXTERN_C angle_t Mobj_AngleSmoothed(mobj_t *mobj);
DENG_EXTERN_C void Mobj_OriginSmoothed(mobj_t *mobj, coord_t origin[3]);
DENG_EXTERN_C Sector *Mobj_Sector(mobj_t const *mobj);

#undef P_SpawnDamageParticleGen
DENG_EXTERN_C void P_SpawnDamageParticleGen(mobj_t *mo, mobj_t *inflictor, int amount)
DENG_EXTERN_C void P_SpawnDamageParticleGen(mobj_t *mobj, mobj_t *inflictor, int amount)
{
#ifdef __CLIENT__
P_SpawnMapDamageParticleGen(mo, inflictor, amount);
P_SpawnMapDamageParticleGen(mobj, inflictor, amount);
#endif
}

Expand Down Expand Up @@ -1918,6 +1919,7 @@ DENG_DECLARE_API(Map) =
P_MobjSectorsIterator,
Mobj_OriginSmoothed,
Mobj_AngleSmoothed,
Mobj_Sector,

P_PolyobjMoveXY,
P_PolyobjRotate,
Expand Down
16 changes: 9 additions & 7 deletions doomsday/client/src/world/p_mobj.cpp
Expand Up @@ -271,12 +271,12 @@ DENG_EXTERN_C void Mobj_OriginSmoothed(mobj_t *mo, coord_t origin[3])
}
}

bool Mobj_IsLinked(mobj_t &mobj)
bool Mobj_IsLinked(mobj_t const &mobj)
{
return mobj.bspLeaf != 0;
}

BspLeaf &Mobj_BspLeafAtOrigin(mobj_t &mobj)
BspLeaf &Mobj_BspLeafAtOrigin(mobj_t const &mobj)
{
if(Mobj_IsLinked(mobj))
{
Expand All @@ -285,25 +285,27 @@ BspLeaf &Mobj_BspLeafAtOrigin(mobj_t &mobj)
throw Error("Mobj_BspLeafAtOrigin", "Mobj is not yet linked");
}

bool Mobj_HasCluster(mobj_t &mobj)
bool Mobj_HasCluster(mobj_t const &mobj)
{
if(!Mobj_IsLinked(mobj)) return false;
return Mobj_BspLeafAtOrigin(mobj).hasCluster();
}

SectorCluster &Mobj_Cluster(mobj_t &mobj)
SectorCluster &Mobj_Cluster(mobj_t const &mobj)
{
return Mobj_BspLeafAtOrigin(mobj).cluster();
}

SectorCluster *Mobj_ClusterPtr(mobj_t &mobj)
SectorCluster *Mobj_ClusterPtr(mobj_t const &mobj)
{
return Mobj_HasCluster(mobj)? &Mobj_Cluster(mobj) : 0;
}

Sector &Mobj_Sector(mobj_t &mobj)
#undef Mobj_Sector
DENG_EXTERN_C Sector *Mobj_Sector(mobj_t const *mobj)
{
return Mobj_Cluster(mobj).sector();
if(!mobj) return 0;
return Mobj_BspLeafAtOrigin(*mobj).sectorPtr();
}

#ifdef __CLIENT__
Expand Down
11 changes: 4 additions & 7 deletions doomsday/plugins/common/src/mobj.c
Expand Up @@ -47,7 +47,7 @@
/// Threshold for stopping walk animation.
#define STANDSPEED (1.0 / 2) // FIX2FLT(0x8000)

static coord_t getFriction(mobj_t* mo)
static coord_t getFriction(mobj_t *mo)
{
if((mo->flags2 & MF2_FLY) && !(mo->origin[VZ] <= mo->floorZ) && !mo->onMobj)
{
Expand All @@ -56,7 +56,7 @@ static coord_t getFriction(mobj_t* mo)
}

#ifdef __JHERETIC__
if(P_ToXSector(P_GetPtrp(mo->bspLeaf, DMU_SECTOR))->special == 15)
if(P_ToXSector(Mobj_Sector(mo))->special == 15)
{
// Low friction.
return FRICTION_LOW;
Expand Down Expand Up @@ -104,17 +104,14 @@ void Mobj_XYMoveStopping(mobj_t* mo)
#ifndef __JHEXEN__
if(cfg.slidingCorpses)
{
/**
* $dropoff_fix:
* Add objects falling off ledges. Does not apply to players!
*/
// $dropoff_fix: Add objects falling off ledges. Does not apply to players!
if(((mo->flags & MF_CORPSE) || (mo->intFlags & MIF_FALLING)) && !mo->player)
{
// Do not stop sliding if halfway off a step with some momentum.
if(!INRANGE_OF(mo->mom[MX], 0, DROPOFFMOMENTUM_THRESHOLD) ||
!INRANGE_OF(mo->mom[MY], 0, DROPOFFMOMENTUM_THRESHOLD))
{
if(!FEQUAL(mo->floorZ, P_GetDoublep(mo->bspLeaf, DMU_FLOOR_HEIGHT)))
if(!FEQUAL(mo->floorZ, P_GetDoublep(Mobj_Sector(mo), DMU_FLOOR_HEIGHT)))
return;
}
}
Expand Down

0 comments on commit e99991e

Please sign in to comment.