Skip to content

Commit

Permalink
Client: Fixed picking up of items (and player pos changes)
Browse files Browse the repository at this point in the history
Instead of trying to handle object position changes on its own, the engine
now relies on the exported P_TryMove3f. This ensures that any side-effects
defined by the game (such as picking up items) will be executed
appropriately as the objects are moved.
  • Loading branch information
skyjake committed Apr 18, 2011
1 parent 975e272 commit 0fe3d3f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 72 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/cl_player.h
Expand Up @@ -48,7 +48,7 @@ extern float cplrThrustMul;

void Cl_InitPlayers(void);
//void Cl_LocalCommand(void);
void ClPlayer_Move(int plrnum);
//void ClPlayer_Move(int plrnum);
void ClPlayer_MoveLocal(float dx, float dy, float dz, boolean onground);
void ClPlayer_UpdatePos(int plrnum);
//void Cl_MovePsprites(void);
Expand Down
18 changes: 6 additions & 12 deletions doomsday/engine/portable/include/p_object.h
Expand Up @@ -48,9 +48,9 @@ DD_BASE_MOBJ_ELEMENTS()} mobj_t;
#define DEFAULT_FRICTION FIX2FLT(0xe800)
#define NOMOMENTUM_THRESHOLD (0.000001f)

extern float tmpFloorZ, tmpCeilingZ;
extern mobj_t *blockingMobj;
extern boolean dontHitMobjs;
//extern float tmpFloorZ, tmpCeilingZ;
//extern mobj_t *blockingMobj;
//extern boolean dontHitMobjs;

#include "cl_def.h" // for clplayerstate_s

Expand All @@ -61,14 +61,8 @@ mobj_t *P_MobjCreate(think_t function, float x, float y, float z,
int ddflags);
void P_MobjDestroy(mobj_t *mo);
void P_MobjRecycle(mobj_t *mo);

void P_MobjSetState(mobj_t *mo, int statenum);
void P_MobjMovement(mobj_t *mo);
void P_MobjMovement2(mobj_t *mo, void *pstate);
void P_MobjZMovement(mobj_t *mo);
boolean P_TryMoveXYZ(mobj_t *mo, float x, float y, float z);
boolean P_StepMove(mobj_t *mo, float dx, float dy, float dz);
boolean P_CheckPosXY(mobj_t *mo, float x, float y);
boolean P_CheckPosXYZ(mobj_t *mo, float x, float y, float z);
boolean P_SectorPlanesChanged(uint sectornum);

boolean P_MobjSetPos(struct mobj_s* mo, float x, float y, float z);

#endif
3 changes: 0 additions & 3 deletions doomsday/engine/portable/include/sv_def.h
Expand Up @@ -64,9 +64,6 @@ size_t Sv_InfoToString(serverinfo_t* info, ddstring_t* msg);
boolean Sv_StringToInfo(const char* valuePair, serverinfo_t* info);
int Sv_GetNumPlayers(void);
int Sv_GetNumConnected(void);
void Sv_PlaceMobj(struct mobj_s* mo, float x, float y, float z,
boolean onFloor);

boolean Sv_CheckBandwidth(int playerNumber);

#endif
12 changes: 7 additions & 5 deletions doomsday/engine/portable/src/cl_player.c
Expand Up @@ -327,6 +327,7 @@ mobj_t* ClPlayer_ClMobj(int plrNum)
return ClMobj_Find(clPlayerStates[plrNum].clMobjId);
}

#if 0
/**
* Predict the movement of the given player.
*
Expand Down Expand Up @@ -389,6 +390,7 @@ void ClPlayer_Move(int plrNum)
// Mirror changes in the (hidden) client mobj.
ClPlayer_UpdatePos(plrNum);
}
#endif

/**
* Move the (hidden, unlinked) client player mobj to the same coordinates
Expand Down Expand Up @@ -491,22 +493,22 @@ void ClPlayer_HandleFix(void)
pos[VZ] = FIX2FLT(Msg_ReadLong());

#ifdef _DEBUG
Con_Message("Cl_HandlePlayerFix: Fix pos %i. Pos=%f, %f, %f\n",
ddpl->fixAcked.pos, pos[VX], pos[VY], pos[VZ]);
Con_Message("Cl_HandlePlayerFix: Fix pos %i. Pos=%f, %f, %f\n",
ddpl->fixAcked.pos, pos[VX], pos[VY], pos[VZ]);
#endif
if(mo)
{
#ifdef _DEBUG
Con_Message(" Applying to mobj %p...\n", mo);
Con_Message(" Applying to mobj %p...\n", mo);
#endif
Sv_PlaceMobj(mo, pos[VX], pos[VY], pos[VZ], false);
P_MobjSetPos(mo, pos[VX], pos[VY], pos[VZ]);
mo->reactionTime = 18;
}

if(clmo)
{
#ifdef _DEBUG
Con_Message(" Applying to clmobj %i...\n", clmo->thinker.id);
Con_Message(" Applying to clmobj %i...\n", clmo->thinker.id);
#endif
ClPlayer_UpdatePos(plr - ddPlayers);
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/cl_world.c
Expand Up @@ -209,7 +209,7 @@ void Cl_MoverThinker(mover_t *mover)
mover->sectornum) );
#endif

P_SectorPlanesChanged(mover->sectornum);
//P_SectorPlanesChanged(mover->sectornum);

// Make sure the client didn't get stuck as a result of this move.
if(freeMove != ClPlayer_IsFreeToMove(consolePlayer))
Expand All @@ -221,7 +221,7 @@ void Cl_MoverThinker(mover_t *mover)
// Something was blocking the way! Go back to original height.
P_SetFloat(DMU_SECTOR, mover->sectornum, mover->property, original);

P_SectorPlanesChanged(mover->sectornum);
//P_SectorPlanesChanged(mover->sectornum);
}
else if(remove) // Can we remove this thinker?
{
Expand Down Expand Up @@ -647,7 +647,7 @@ void Cl_ReadSectorDelta2(int deltaType, boolean skip)
// the sector.
if(wasChanged)
{
P_SectorPlanesChanged(GET_SECTOR_IDX(sec));
//P_SectorPlanesChanged(GET_SECTOR_IDX(sec));
}

// Do we need to start any moving planes?
Expand Down
52 changes: 44 additions & 8 deletions doomsday/engine/portable/src/p_mobj.c
Expand Up @@ -47,24 +47,26 @@
// MACROS ------------------------------------------------------------------

// Max. distance to move in one call to P_MobjMoveXY.
#define MAXMOVE 30
//#define MAXMOVE 30

// Shortest possible movement step.
#define MINMOVE (1.0f/128)
//#define MINMOVE (1.0f/128)

#define MIN_STEP(d) ((d) <= MINMOVE && (d) >= -MINMOVE)
//#define MIN_STEP(d) ((d) <= MINMOVE && (d) >= -MINMOVE)

#define STOPSPEED (0.1f/1.6f)
//#define STOPSPEED (0.1f/1.6f)

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

/*
typedef struct {
mobj_t *mo;
vec2_t box[2];
int flags;
float pos[3];
float height, floorZ, ceilingZ, dropOffZ;
} checkpos_data_t;
*/

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

Expand All @@ -77,14 +79,14 @@ typedef struct {
// PUBLIC DATA DEFINITIONS -------------------------------------------------

// If set to true, P_CheckPosition will skip the mobj hit test.
boolean dontHitMobjs = false;
//boolean dontHitMobjs = false;

float tmpFloorZ;
float tmpCeilingZ;
//float tmpFloorZ;
//float tmpCeilingZ;

// When a mobj is contacted in PIT_CheckMobj, this pointer is set.
// It's reset to NULL in the beginning of P_CheckPosition.
mobj_t *blockingMobj;
//mobj_t *blockingMobj;

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

Expand Down Expand Up @@ -154,7 +156,9 @@ mobj_t* P_MobjCreate(think_t function, float x, float y, float z,
mo->ddFlags = ddflags;
mo->thinker.function = function;
if(mo->thinker.function)
{
P_ThinkerAdd(&mo->thinker, true); // Make it public.
}

return mo;
}
Expand Down Expand Up @@ -235,6 +239,21 @@ void P_MobjSetState(mobj_t* mobj, int statenum)
}
}

/**
* Sets a mobj's position.
*
* @return @c true if successful, @c false otherwise. The object's position is
* not changed if the move fails.
*
* @note Internal to the engine.
*/
boolean P_MobjSetPos(struct mobj_s* mo, float x, float y, float z)
{
assert(gx.MobjTryMove3f != 0);
return gx.MobjTryMove3f(mo, x, y, z);
}

#if 0
/**
* Adjusts tmpFloorZ and tmpCeilingZ as lines are contacted.
*/
Expand Down Expand Up @@ -279,7 +298,9 @@ boolean PIT_LineCollide(linedef_t* ld, void* parm)
tm->mo->wallHit = false;
return true;
}
#endif

#if 0
boolean PIT_MobjCollide(mobj_t* mo, void* parm)
{
checkpos_data_t* tm = parm;
Expand Down Expand Up @@ -353,7 +374,9 @@ boolean PIT_MobjCollide(mobj_t* mo, void* parm)

return false;
}
#endif

#if 0
/**
* @return @c true, if the mobj can be positioned at the
* specified coordinates.
Expand Down Expand Up @@ -418,7 +441,9 @@ boolean P_CheckPosXYZ(mobj_t *mo, float x, float y, float z)
tmpDropOffZ = data.dropOffZ;
return result;
}
#endif

#if 0
/**
* @return @c true, if the mobj can be positioned at the
* specified coordinates, assuming traditional 2D DOOM
Expand Down Expand Up @@ -561,7 +586,9 @@ boolean P_StepMove(mobj_t *mo, float dx, float dy, float dz)

return notHit;
}
#endif

#if 0
/**
* Takes a valid mobj and adjusts the mobj->floorZ, mobj->ceilingZ, and
* possibly mobj->z. This is called for all nearby mobjs whenever a sector
Expand Down Expand Up @@ -608,7 +635,9 @@ static boolean heightClip(mobj_t *mo)
return false;
return true;
}
#endif

#if 0
/**
* Allows the player to slide along any angled walls. Adjusts the player's
* momentum vector so that the next move slides along the linedef.
Expand Down Expand Up @@ -652,7 +681,9 @@ static void wallMomSlide(linedef_t *ld)
tmpMom[VX] = newlen * FIX2FLT(fineCosine[an]);
tmpMom[VY] = newlen * FIX2FLT(finesine[an]);
}
#endif

#if 0
static boolean slideTraverse(intercept_t *in)
{
linedef_t *li;
Expand Down Expand Up @@ -700,7 +731,9 @@ static boolean slideTraverse(intercept_t *in)

return false; // Stop iteration.
}
#endif

#if 0
/**
* The momx / momy move is bad, so try to slide along a wall.
* Find the first line hit, move flush to it, and slide along it
Expand Down Expand Up @@ -799,7 +832,9 @@ static void mobjSlideMove(mobj_t *mo)
goto retry;
}
}
#endif

#if 0
/**
* After modifying a sectors floor or ceiling height, call this routine
* to adjust the positions of all mobjs that touch the sector.
Expand Down Expand Up @@ -1001,3 +1036,4 @@ void P_MobjZMovement(mobj_t *mo)
mo->pos[VZ] = mo->ceilingZ - mo->height;
}
}
#endif
53 changes: 14 additions & 39 deletions doomsday/engine/portable/src/sv_main.c
Expand Up @@ -1173,24 +1173,6 @@ boolean Sv_CheckBandwidth(int playerNumber)
return qSize <= 10 * limit;
}

void Sv_PlaceMobj(mobj_t* mo, float x, float y, float z, boolean onFloor)
{
P_CheckPosXYZ(mo, x, y, z);

P_MobjUnlink(mo);
mo->pos[VX] = x;
mo->pos[VY] = y;
mo->pos[VZ] = z;
P_MobjLink(mo, DDLINK_SECTOR | DDLINK_BLOCKMAP);
mo->floorZ = tmpFloorZ;
mo->ceilingZ = tmpCeilingZ;

if(onFloor)
{
mo->pos[VZ] = mo->floorZ;
}
}

/**
* Reads a PKT_COORDS packet from the message buffer. We trust the
* client's position and change ours to match it. The client better not
Expand Down Expand Up @@ -1228,32 +1210,25 @@ void Sv_ClientCoords(int plrNum)

// If we aren't about to forcibly change the client's position, update
// with new pos if it's valid. But it must be a valid pos.
if(ddpl->fixCounter.pos == ddpl->fixAcked.pos &&
P_CheckPosXYZ(mo, clientPos[VX], clientPos[VY], clientPos[VZ]))
if(ddpl->fixCounter.pos == ddpl->fixAcked.pos && !(ddpl->flags & DDPF_FIXPOS))
{
// Large differences in the coordinates suggest that player position
// has been misestimated on serverside.

// Prevent illegal stepups.
/*if(tmpFloorZ - mo->pos[VZ] <= 24 ||
// But also allow warping the position.
(fabs(clientPos[VX] - mo->pos[VX]) > WARP_LIMIT ||
fabs(clientPos[VY] - mo->pos[VY]) > WARP_LIMIT ||
fabs(clientPos[VZ] - mo->pos[VZ]) > WARP_LIMIT))
{*/
#ifdef _DEBUG
VERBOSE2( Con_Message("Sv_ClientCoords: Setting coords for player %i: %f, %f, %f\n", plrNum,
clientPos[VX], clientPos[VY], clientPos[VZ]) );
VERBOSE2( Con_Message("Sv_ClientCoords: Setting coords for player %i: %f, %f, %f\n", plrNum,
clientPos[VX], clientPos[VY], clientPos[VZ]) );
#endif
Sv_PlaceMobj(mo, clientPos[VX], clientPos[VY], clientPos[VZ], onFloor);
/*
if(!P_MobjSetPos(mo, clientPos[VX], clientPos[VY], clientPos[VZ]))
{
Con_Message("Sv_ClientCoords: Player %i attempts an illegal move to: %f, %f, %f\n", plrNum,
clientPos[VX], clientPos[VY], clientPos[VZ]);

// We need to restore the client's old position.
ddpl->flags |= DDPF_FIXPOS;
}
else
else // The move was successful.
{
#ifdef _DEBUG
Con_Message("Sv_ClientCoords: Discarding coords for player %i.\n", plrNum);
#endif
}*/
if(onFloor)
mo->pos[VZ] = mo->floorZ;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_actor.c
Expand Up @@ -162,7 +162,7 @@ void P_MobjRemove(mobj_t* mo, boolean noRespawn)
*/
void P_MobjSetPosition(mobj_t* mo)
{
int flags = DDLINK_BLOCKMAP;
int flags = DDLINK_BLOCKMAP;

if(!(mo->flags & MF_NOSECTOR))
flags |= DDLINK_SECTOR;
Expand Down

0 comments on commit 0fe3d3f

Please sign in to comment.