Skip to content

Commit

Permalink
libcommon: Consolidated mobj state change functions; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 2, 2013
1 parent afeb9f6 commit b84ea3e
Show file tree
Hide file tree
Showing 46 changed files with 449 additions and 805 deletions.
41 changes: 34 additions & 7 deletions doomsday/api/api_map.h
Expand Up @@ -84,16 +84,25 @@

struct intercept_s;

/**
* @defgroup mobjLinkFlags Mobj Link Flags
*/
///@{
#define DDLINK_SECTOR 0x1 ///< Link to map sectors.
#define DDLINK_BLOCKMAP 0x2 ///< Link in the map's mobj blockmap.
#define DDLINK_NOLINE 0x4 ///< Do not link to map lines.
///@}

/**
* @defgroup boxLineIteratorFlags Box Line Iterator Flags
* @ingroup apiFlags map
*/
///@{
#define BLF_SECTOR 0x1 ///< Process map lines defining sectors
#define BLF_POLYOBJ 0x2 ///< Process map lines defining polyobjs
#define BLF_SECTOR 0x1 ///< Process map lines defining sectors
#define BLF_POLYOBJ 0x2 ///< Process map lines defining polyobjs

/// Process all map line types.
#define BLF_ALL BLF_SECTOR | BLF_POLYOBJ
#define BLF_ALL BLF_SECTOR | BLF_POLYOBJ
///@}

/**
Expand Down Expand Up @@ -228,9 +237,27 @@ DENG_API_TYPEDEF(Map)
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 *mobj);
struct mobj_s *(*MO_MobjForID)(int id);

/**
* @param statenum Must be a valid state (not null!).
*/
void (*MO_SetState)(struct mobj_s *mobj, int statenum);
void (*MO_Link)(struct mobj_s *mobj, byte flags);
int (*MO_Unlink)(struct mobj_s *mobj);

/**
* To be called after a move, to link the mobj back into the world.
*
* @param mobj Mobj instance.
* @param flags @ref mobjLinkFlags
*/
void (*MO_Link)(struct mobj_s *mobj, int flags);

/**
* Unlinks a mobj from the world so that it can be moved.
*
* @param mobj Mobj instance.
*/
void (*MO_Unlink)(struct mobj_s *mobj);

void (*MO_SpawnDamageParticleGen)(struct mobj_s *mobj, struct mobj_s *inflictor, int amount);

/**
Expand Down Expand Up @@ -593,8 +620,8 @@ DENG_API_T(Map);
#define P_MobjDestroy _api_Map.MO_Destroy
#define P_MobjForID _api_Map.MO_MobjForID
#define P_MobjSetState _api_Map.MO_SetState
#define P_MobjLink _api_Map.MO_Link
#define P_MobjUnlink _api_Map.MO_Unlink
#define Mobj_Link _api_Map.MO_Link
#define Mobj_Unlink _api_Map.MO_Unlink
#define P_SpawnDamageParticleGen _api_Map.MO_SpawnDamageParticleGen
#define P_MobjLinesIterator _api_Map.MO_LinesIterator
#define P_MobjSectorsIterator _api_Map.MO_SectorsIterator
Expand Down
5 changes: 0 additions & 5 deletions doomsday/api/dd_share.h
Expand Up @@ -519,11 +519,6 @@ typedef float AudioEnvironmentFactors[NUM_REVERB_DATA];
#define LS_PASSUNDER 0x4 ///< Ray may cross under sector floor height on ray-entry side.
///@}

// For (un)linking.
#define DDLINK_SECTOR 0x1
#define DDLINK_BLOCKMAP 0x2
#define DDLINK_NOLINE 0x4

typedef enum intercepttype_e {
ICPT_MOBJ,
ICPT_LINE
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/include/client/cl_player.h
Expand Up @@ -68,6 +68,10 @@ void Cl_InitPlayers(void);
*/
void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground);

/**
* Move the (hidden, unlinked) client player mobj to the same coordinates
* where the real mobj of the player is.
*/
void ClPlayer_UpdateOrigin(int plrnum);

void ClPlayer_HandleFix(void);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/m_nodepile.h
Expand Up @@ -36,7 +36,7 @@
* that a single mobj is linked simultaneously to multiple lines (which
* is common).
*
* All these rings are maintained by P_MobjLink() and P_MobjUnlink().
* All these rings are maintained by Mobj_Link() and Mobj_Unlink().
* @ingroup mobj
*/
typedef struct linknode_s {
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/world/p_object.h
Expand Up @@ -59,7 +59,7 @@ void P_InitUnusedMobjList();
*/
void Mobj_ConsoleRegister();

mobj_t *P_MobjCreate(thinkfunc_t function, coord_t const post[3], angle_t angle,
mobj_t *P_MobjCreate(thinkfunc_t function, de::Vector3d const &origin, angle_t angle,
coord_t radius, coord_t height, int ddflags);

void P_MobjRecycle(mobj_t *mobj);
Expand Down
24 changes: 12 additions & 12 deletions doomsday/client/src/client/cl_mobj.cpp
Expand Up @@ -188,14 +188,14 @@ int Map::clMobjIterator(int (*callback) (mobj_t *, void *), void *context)
return true;
}

void ClMobj_Unlink(mobj_t* mo)
void ClMobj_Unlink(mobj_t *mo)
{
P_MobjUnlink(mo);
Mobj_Unlink(mo);
}

void ClMobj_Link(mobj_t* mo)
void ClMobj_Link(mobj_t *mo)
{
clmoinfo_t* info = ClMobj_GetInfo(mo);
clmoinfo_t *info = ClMobj_GetInfo(mo);

CL_ASSERT_CLMOBJ(mo);

Expand All @@ -209,8 +209,8 @@ void ClMobj_Link(mobj_t* mo)
DEBUG_VERBOSE2_Message(("ClMobj_Link: id %i, x%f Y%f, solid:%s\n", mo->thinker.id,
mo->origin[VX], mo->origin[VY], mo->ddFlags & DDMF_SOLID? "yes" : "no"));

P_MobjLink(mo, (mo->ddFlags & DDMF_DONTDRAW ? 0 : DDLINK_SECTOR) |
(mo->ddFlags & DDMF_SOLID ? DDLINK_BLOCKMAP : 0));
Mobj_Link(mo, (mo->ddFlags & DDMF_DONTDRAW ? 0 : DDLINK_SECTOR) |
(mo->ddFlags & DDMF_SOLID ? DDLINK_BLOCKMAP : 0));
}

#undef ClMobj_EnableLocalActions
Expand All @@ -233,7 +233,7 @@ void ClMobj_EnableLocalActions(struct mobj_s *mo, boolean enable)
#undef ClMobj_LocalActionsEnabled
boolean ClMobj_LocalActionsEnabled(struct mobj_s *mo)
{
clmoinfo_t* info = ClMobj_GetInfo(mo);
clmoinfo_t *info = ClMobj_GetInfo(mo);
if(!isClient || !info) return true;
return (info->flags & CLMF_LOCAL_ACTIONS) != 0;
}
Expand All @@ -246,8 +246,8 @@ void ClMobj_SetState(mobj_t *mo, int stnum)
{
P_MobjSetState(mo, stnum);
stnum = states[stnum].nextState;
}
while(!mo->tics && stnum > 0);

} while(!mo->tics && stnum > 0);
}

void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj,
Expand Down Expand Up @@ -312,9 +312,9 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj,
if(gx.MobjTryMoveXYZ)
{
if(gx.MobjTryMoveXYZ(localMobj,
remoteClientMobj->origin[VX],
remoteClientMobj->origin[VY],
(flags & MDF_ORIGIN_Z)? remoteClientMobj->origin[VZ] : localMobj->origin[VZ]))
remoteClientMobj->origin[VX],
remoteClientMobj->origin[VY],
(flags & MDF_ORIGIN_Z)? remoteClientMobj->origin[VZ] : localMobj->origin[VZ]))
{
if((flags & MDF_ORIGIN_Z) && onFloor)
{
Expand Down
42 changes: 8 additions & 34 deletions doomsday/client/src/client/cl_player.cpp
Expand Up @@ -92,26 +92,18 @@ DENG_EXTERN_C struct mobj_s* ClPlayer_ClMobj(int plrNum)
return ClMobj_Find(clPlayerStates[plrNum].clMobjId);
}

/**
* Move the (hidden, unlinked) client player mobj to the same coordinates
* where the real mobj of the player is.
*/
void ClPlayer_UpdateOrigin(int plrNum)
{
player_t *plr;
mobj_t *remoteClientMobj, *localMobj;
clplayerstate_t *s;
DENG2_ASSERT(plrNum >= 0 && plrNum < DDMAXPLAYERS);

assert(plrNum >= 0 && plrNum < DDMAXPLAYERS);

plr = &ddPlayers[plrNum];
s = ClPlayer_State(plrNum);
player_t *plr = &ddPlayers[plrNum];
clplayerstate_t *s = ClPlayer_State(plrNum);

if(!s->clMobjId || !plr->shared.mo)
return; // Must have a mobj!

remoteClientMobj = ClMobj_Find(s->clMobjId);
localMobj = plr->shared.mo;
mobj_t *remoteClientMobj = ClMobj_Find(s->clMobjId);
mobj_t *localMobj = plr->shared.mo;

// The client mobj is never solid.
remoteClientMobj->ddFlags &= ~DDMF_SOLID;
Expand All @@ -121,32 +113,14 @@ void ClPlayer_UpdateOrigin(int plrNum)
// The player's client mobj is not linked to any lists, so position
// can be updated without any hassles.
memcpy(remoteClientMobj->origin, localMobj->origin, sizeof(localMobj->origin));
P_MobjLink(remoteClientMobj, 0); // Update bspLeaf pointer.
Mobj_Link(remoteClientMobj, 0); // Update bspLeaf pointer.
remoteClientMobj->floorZ = localMobj->floorZ;
remoteClientMobj->ceilingZ = localMobj->ceilingZ;
remoteClientMobj->mom[MX] = localMobj->mom[MX];
remoteClientMobj->mom[MY] = localMobj->mom[MY];
remoteClientMobj->mom[MZ] = localMobj->mom[MZ];
}

/*
void ClPlayer_CoordsReceived(void)
{
if(playback)
return;
#ifdef _DEBUG
//Con_Printf("ClPlayer_CoordsReceived\n");
#endif
fixPos[VX] = (float) Msg_ReadShort();
fixPos[VY] = (float) Msg_ReadShort();
fixTics = fixSpeed;
fixPos[VX] /= fixSpeed;
fixPos[VY] /= fixSpeed;
}
*/

void ClPlayer_ApplyPendingFixes(int plrNum)
{
clplayerstate_t *state = ClPlayer_State(plrNum);
Expand Down Expand Up @@ -310,10 +284,10 @@ void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground)

if(dx != 0 || dy != 0)
{
P_MobjUnlink(mo);
Mobj_Unlink(mo);
mo->origin[VX] += dx;
mo->origin[VY] += dy;
P_MobjLink(mo, DDLINK_SECTOR | DDLINK_BLOCKMAP);
Mobj_Link(mo, DDLINK_SECTOR | DDLINK_BLOCKMAP);
}

mo->_bspLeaf = &App_World().map().bspLeafAt_FixedPrecision(Mobj_Origin(*mo));
Expand Down
29 changes: 17 additions & 12 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -1535,18 +1535,18 @@ DENG_EXTERN_C fixed_t P_GetGMOFixed(int entityId, int elementIndex, int property
DENG_EXTERN_C angle_t P_GetGMOAngle(int entityId, int elementIndex, int propertyId);
DENG_EXTERN_C float P_GetGMOFloat(int entityId, int elementIndex, int propertyId);

#undef P_MobjLink
DENG_EXTERN_C void P_MobjLink(mobj_t *mo, byte flags)
#undef Mobj_Link
DENG_EXTERN_C void Mobj_Link(mobj_t *mobj, int flags)
{
if(!mo || !App_World().hasMap()) return;
App_World().map().link(*mo, flags);
if(!mobj || !App_World().hasMap()) return; // Huh?
App_World().map().link(*mobj, flags);
}

#undef P_MobjUnlink
DENG_EXTERN_C int P_MobjUnlink(mobj_t *mo)
#undef Mobj_Unlink
DENG_EXTERN_C void Mobj_Unlink(mobj_t *mobj)
{
if(!mo || !Mobj_IsLinked(*mo)) return 0;
return Mobj_BspLeafAtOrigin(*mo).map().unlink(*mo);
if(!mobj || !Mobj_IsLinked(*mobj)) return;
Mobj_BspLeafAtOrigin(*mobj).map().unlink(*mobj);
}

#undef P_MobjLinesIterator
Expand Down Expand Up @@ -1696,9 +1696,14 @@ DENG_EXTERN_C void P_SetTraceOpening(Line *line)
line->map().setTraceOpening(*line);
}

#undef P_MobjCreateXYZ
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)
{
return P_MobjCreate(function, Vector3d(x, y, z), angle, radius, height, ddflags);
}

// 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 *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);
Expand Down Expand Up @@ -1850,8 +1855,8 @@ DENG_DECLARE_API(Map) =
P_MobjDestroy,
P_MobjForID,
P_MobjSetState,
P_MobjLink,
P_MobjUnlink,
Mobj_Link,
Mobj_Unlink,
P_SpawnDamageParticleGen,
P_MobjLinesIterator,
P_MobjSectorsIterator,
Expand Down

0 comments on commit b84ea3e

Please sign in to comment.