Skip to content

Commit

Permalink
API: DD_BASE_DDMOBJ_ELEMENTS() now records the BSP leaf at the origin
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 2, 2013
1 parent e99991e commit b2467c7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 76 deletions.
7 changes: 3 additions & 4 deletions doomsday/api/dd_share.h
Expand Up @@ -471,8 +471,9 @@ enum { /* Do NOT change the numerical values of the constants. */

/// @ingroup mobj
#define DD_BASE_DDMOBJ_ELEMENTS() \
thinker_t thinker; /* thinker node */ \
coord_t origin[3]; /* origin [x,y,z] */
thinker_t thinker; /* thinker node */ \
coord_t origin[3]; /* origin [x,y,z] */ \
BspLeaf *_bspLeaf; /* BSP leaf in which this resides (if known) */

/**
* All map think-able objects must use this as a base. Also used for sound
Expand Down Expand Up @@ -626,7 +627,6 @@ enum { MX, MY, MZ };
nodeindex_t lineRoot; /* lines to which this is linked */ \
struct mobj_s *sNext, **sPrev; /* links in sector (if needed) */ \
\
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 Down Expand Up @@ -666,7 +666,6 @@ enum { MX, MY, MZ };
#define DD_BASE_POLYOBJ_ELEMENTS() \
DD_BASE_DDMOBJ_ELEMENTS() \
\
BspLeaf *_bspLeaf; /* bspLeaf in which this resides */ \
int _indexInMap; \
int tag; /* Reference tag. */ \
int validCount; \
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/audio/s_main.cpp
Expand Up @@ -498,8 +498,7 @@ void S_StopSound2(int soundID, mobj_t *emitter, int flags)
if(emitter->thinker.id)
{
// Emitter is a real Mobj.
Sector &sector = emitter->bspLeaf->sector();
stopSectorSounds(&sector.soundEmitter(), soundID, flags);
stopSectorSounds(&Mobj_Sector(emitter)->soundEmitter(), soundID, flags);
return;
}

Expand Down
40 changes: 9 additions & 31 deletions doomsday/client/src/client/cl_player.cpp
@@ -1,4 +1,4 @@
/** @file
/** @file cl_player.cpp Clientside Player Management.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,11 +17,7 @@
* http://www.gnu.org/licenses</small>
*/

/**
* cl_player.c: Clientside Player Management
*/

// HEADER FILES ------------------------------------------------------------
#include <de/Vector>

#include "de_base.h"
#include "de_console.h"
Expand All @@ -32,29 +28,15 @@

#include "BspLeaf"

// MACROS ------------------------------------------------------------------
using namespace de;

#define TOP_PSPY (32)
#define BOTTOM_PSPY (128)

// TYPES -------------------------------------------------------------------

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

// PUBLIC DATA DEFINITIONS -------------------------------------------------

float pspMoveSpeed = 6;
float cplrThrustMul = 1;
clplayerstate_t clPlayerStates[DDMAXPLAYERS];

// PRIVATE DATA DEFINITIONS ------------------------------------------------

//static int fixSpeed = 15;
//static float fixPos[3];
//static int fixTics;
Expand All @@ -63,8 +45,6 @@ static float pspY;
// Console player demo momentum (used to smooth out abrupt momentum changes).
static float cpMom[3][LOCALCAM_WRITE_TICS];

// CODE --------------------------------------------------------------------

/**
* Clears the player state table.
*/
Expand Down Expand Up @@ -318,17 +298,15 @@ void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground)
cpMom[MY][SECONDS_TO_TICKS(gameTime) % LOCALCAM_WRITE_TICS] = dy;

// Calculate an average.
coord_t mom[3] = { 0, 0, 0 };
Vector2d mom;
for(int i = 0; i < LOCALCAM_WRITE_TICS; ++i)
{
mom[MX] += cpMom[MX][i];
mom[MY] += cpMom[MY][i];
mom += Vector2d(cpMom[MX][i], cpMom[MY][i]);
}
mom[MX] /= LOCALCAM_WRITE_TICS;
mom[MY] /= LOCALCAM_WRITE_TICS;
mom /= LOCALCAM_WRITE_TICS;

mo->mom[MX] = mom[MX];
mo->mom[MY] = mom[MY];
mo->mom[MX] = mom.x;
mo->mom[MY] = mom.y;

if(dx != 0 || dy != 0)
{
Expand All @@ -338,7 +316,7 @@ 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->_bspLeaf = P_BspLeafAtPoint_FixedPrecision(mo->origin);
mo->floorZ = Mobj_Cluster(*mo).floor().height();
mo->ceilingZ = Mobj_Cluster(*mo).ceiling().height();

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -623,7 +623,7 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
{
if(Mobj_IsSectorLinked(&mobj))
{
mobj.bspLeaf->sector().unlink(&mobj);
Mobj_Sector(&mobj)->unlink(&mobj);
return true;
}
return false;
Expand Down Expand Up @@ -1968,7 +1968,7 @@ void Map::link(mobj_t &mo, byte flags)
d->unlinkMobjFromSectors(mo);
bspLeafAtOrigin.sector().link(&mo);
}
mo.bspLeaf = &bspLeafAtOrigin;
mo._bspLeaf = &bspLeafAtOrigin;

// Link into blockmap?
if(flags & DDLINK_BLOCKMAP)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/world/p_mobj.cpp
Expand Up @@ -164,7 +164,7 @@ void P_MobjRecycle(mobj_t* mo)

boolean Mobj_IsSectorLinked(mobj_t *mo)
{
return mo != 0 && mo->bspLeaf != 0 && mo->sPrev != 0;
return mo != 0 && mo->_bspLeaf != 0 && mo->sPrev != 0;
}

/**
Expand Down Expand Up @@ -273,14 +273,14 @@ DENG_EXTERN_C void Mobj_OriginSmoothed(mobj_t *mo, coord_t origin[3])

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

BspLeaf &Mobj_BspLeafAtOrigin(mobj_t const &mobj)
{
if(Mobj_IsLinked(mobj))
{
return *mobj.bspLeaf;
return *mobj._bspLeaf;
}
throw Error("Mobj_BspLeafAtOrigin", "Mobj is not yet linked");
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/p_objlink.cpp
Expand Up @@ -688,8 +688,8 @@ int R_IterateBspLeafContacts(BspLeaf &bspLeaf, objtype_t type,

void R_ObjlinkCreate(mobj_t &mobj)
{
if(!mobj.bspLeaf) return;
createObjlink(*mobj.bspLeaf, &mobj, OT_MOBJ);
if(!Mobj_IsLinked(mobj)) return;
createObjlink(Mobj_BspLeafAtOrigin(mobj), &mobj, OT_MOBJ);
}

void R_LinkObjToBspLeaf(BspLeaf &bspLeaf, mobj_t &mobj)
Expand Down
64 changes: 32 additions & 32 deletions doomsday/server/src/server/sv_pool.cpp
Expand Up @@ -312,35 +312,35 @@ float Sv_GetMaxedMobjZ(const mobj_t* mo)
* Store the state of the mobj into the register-mobj.
* Called at register init and after each delta generation cycle.
*/
void Sv_RegisterMobj(dt_mobj_t* reg, const mobj_t* mo)
void Sv_RegisterMobj(dt_mobj_t *reg, mobj_t const *mo)
{
// (dt_mobj_t <=> mobj_t)
// Just copy the data we need.
reg->thinker.id = mo->thinker.id;
reg->type = mo->type;
reg->dPlayer = mo->dPlayer;
reg->bspLeaf = mo->bspLeaf;
reg->origin[VX] = mo->origin[VX];
reg->origin[VY] = mo->origin[VY];
reg->origin[VZ] = Sv_GetMaxedMobjZ(mo);
reg->floorZ = mo->floorZ;
reg->ceilingZ = mo->ceilingZ;
reg->mom[MX] = mo->mom[MX];
reg->mom[MY] = mo->mom[MY];
reg->mom[MZ] = mo->mom[MZ];
reg->angle = mo->angle;
reg->selector = mo->selector;
reg->state = mo->state;
reg->radius = mo->radius;
reg->height = mo->height;
reg->ddFlags = mo->ddFlags;
reg->flags = mo->flags;
reg->flags2 = mo->flags2;
reg->flags3 = mo->flags3;
reg->health = mo->health;
reg->floorClip = mo->floorClip;
reg->thinker.id = mo->thinker.id;
reg->type = mo->type;
reg->dPlayer = mo->dPlayer;
reg->_bspLeaf = mo->_bspLeaf;
reg->origin[VX] = mo->origin[VX];
reg->origin[VY] = mo->origin[VY];
reg->origin[VZ] = Sv_GetMaxedMobjZ(mo);
reg->floorZ = mo->floorZ;
reg->ceilingZ = mo->ceilingZ;
reg->mom[MX] = mo->mom[MX];
reg->mom[MY] = mo->mom[MY];
reg->mom[MZ] = mo->mom[MZ];
reg->angle = mo->angle;
reg->selector = mo->selector;
reg->state = mo->state;
reg->radius = mo->radius;
reg->height = mo->height;
reg->ddFlags = mo->ddFlags;
reg->flags = mo->flags;
reg->flags2 = mo->flags2;
reg->flags3 = mo->flags3;
reg->health = mo->health;
reg->floorClip = mo->floorClip;
reg->translucency = mo->translucency;
reg->visTarget = mo->visTarget;
reg->visTarget = mo->visTarget;
}

/**
Expand Down Expand Up @@ -1171,22 +1171,22 @@ void Sv_SubtractDelta(void* deltaPtr1, const void* deltaPtr2)
* Applies the data in the source delta to the destination delta.
* Both must be in the NEW state. Handles all types of deltas.
*/
void Sv_ApplyDeltaData(void* destDelta, const void* srcDelta)
void Sv_ApplyDeltaData(void *destDelta, void const *srcDelta)
{
const delta_t* src = (delta_t const *) srcDelta;
delta_t* dest = (delta_t *) destDelta;
int sf = src->flags;
delta_t const *src = (delta_t const *) srcDelta;
delta_t *dest = (delta_t *) destDelta;
int sf = src->flags;

if(src->type == DT_MOBJ)
{
const dt_mobj_t* s = &((const mobjdelta_t *) src)->mo;
dt_mobj_t* d = &((mobjdelta_t *) dest)->mo;
dt_mobj_t const *s = &((mobjdelta_t const *) src)->mo;
dt_mobj_t *d = &((mobjdelta_t *) dest)->mo;

// *Always* set the player pointer.
d->dPlayer = s->dPlayer;

if(sf & (MDF_ORIGIN_X | MDF_ORIGIN_Y))
d->bspLeaf = s->bspLeaf;
d->_bspLeaf = s->_bspLeaf;
if(sf & MDF_ORIGIN_X)
d->origin[VX] = s->origin[VX];
if(sf & MDF_ORIGIN_Y)
Expand Down

0 comments on commit b2467c7

Please sign in to comment.