Skip to content

Commit

Permalink
Client: Use the Smoother for remote players
Browse files Browse the repository at this point in the history
Now works better, but there is still a timing problem
with the client's Smoother: remote movement lags
a lot even with zero latency.
  • Loading branch information
skyjake committed Jul 24, 2011
1 parent 7d4f17d commit 261e2cd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 45 deletions.
83 changes: 53 additions & 30 deletions doomsday/engine/portable/src/cl_mobj.c
Expand Up @@ -307,7 +307,9 @@ void ClMobj_CheckPlanes(mobj_t *mo, boolean justCreated)
*/
void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int flags, boolean onFloor)
{
int plrNum;
float x, y, z;
boolean addSmooth = false;
int plrNum = P_GetDDPlayerIdx(localMobj->dPlayer);

#if _DEBUG
if(!localMobj || !remoteClientMobj)
Expand All @@ -317,21 +319,6 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int fl
}
#endif

assert(localMobj->dPlayer != 0);
plrNum = P_GetDDPlayerIdx(localMobj->dPlayer);
Smoother_AddPos(clients[plrNum].smoother, Cl_FrameGameTime(),
remoteClientMobj->pos[VX],
remoteClientMobj->pos[VY],
remoteClientMobj->pos[VZ], onFloor);

/*#ifdef _DEBUG
Con_Message("Cl_UpdateRealPlayerMobj: plr=%i sm=%p gt=%f xyz=%f,%f,%f onFloor=%i\n",
plrNum, clients[plrNum].smoother, gameTime,
remoteClientMobj->pos[VX],
remoteClientMobj->pos[VY],
remoteClientMobj->pos[VZ], onFloor);
#endif*/

localMobj->radius = remoteClientMobj->radius;

if(flags & MDF_MOM_X) localMobj->mom[MX] = remoteClientMobj->mom[MX];
Expand Down Expand Up @@ -360,6 +347,11 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int fl
localMobj->selector |= remoteClientMobj->selector & DDMOBJ_SELECTOR_MASK;
localMobj->visAngle = remoteClientMobj->angle >> 16;

// Old position.
x = localMobj->pos[VX];
y = localMobj->pos[VY];
z = localMobj->pos[VZ];

if(flags & (MDF_POS_X | MDF_POS_Y))
{
// We have to unlink the real mobj before we move it.
Expand All @@ -369,37 +361,68 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int fl
P_MobjLink(localMobj, DDLINK_SECTOR | DDLINK_BLOCKMAP);*/

// This'll update the contacted floor and ceiling heights as well.
if(gx.MobjTryMove3f)
/*if(gx.MobjTryMove3f)
{
gx.MobjTryMove3f(localMobj,
remoteClientMobj->pos[VX],
remoteClientMobj->pos[VY],
remoteClientMobj->pos[VZ]);
}
}*/

addSmooth = true;

x = remoteClientMobj->pos[VX];
y = remoteClientMobj->pos[VY];
}
if(flags & MDF_POS_Z)
{
addSmooth = true;

// Stay on the floor if the mobj is locally touching the right plane.
if(onFloor) // && localMobj->floorZ == localMobj->subsector->sector->planes[PLN_FLOOR]->height)
{
// if(
// {
// It's supposed to be on the local floor Z.
// remoteClientMobj->pos[VZ] = remoteClientMobj->floorZ = localMobj->floorZ;
//}
}
else
if(!onFloor)
{
localMobj->floorZ = remoteClientMobj->floorZ;
}
localMobj->ceilingZ = remoteClientMobj->ceilingZ;

localMobj->pos[VZ] = remoteClientMobj->pos[VZ];
z = remoteClientMobj->pos[VZ];

// Don't go below the floor level.
if(localMobj->pos[VZ] < localMobj->floorZ)
localMobj->pos[VZ] = localMobj->floorZ;
if(z < localMobj->floorZ)
z = localMobj->floorZ;
}
else if(addSmooth)
{
// The Z coordinate information was not included, so we have to rely
// on local information about whether it's on the floor.

// Stay on the floor?
onFloor = Smoother_IsOnFloor(clients[plrNum].smoother);
}

/*
assert(localMobj->dPlayer != 0);
plrNum = P_GetDDPlayerIdx(localMobj->dPlayer);
Smoother_AddPos(clients[plrNum].smoother, Cl_FrameGameTime(),
remoteClientMobj->pos[VX],
remoteClientMobj->pos[VY],
remoteClientMobj->pos[VZ], onFloor);
*/

if(addSmooth)
{
Smoother_AddPos(clients[plrNum].smoother, Cl_FrameGameTime(),
x, y, z, onFloor);
}

/*#ifdef _DEBUG
Con_Message("Cl_UpdateRealPlayerMobj: plr=%i sm=%p gt=%f xyz=%f,%f,%f onFloor=%i\n",
plrNum, clients[plrNum].smoother, gameTime,
remoteClientMobj->pos[VX],
remoteClientMobj->pos[VY],
remoteClientMobj->pos[VZ], onFloor);
#endif*/

}

/**
Expand Down
51 changes: 36 additions & 15 deletions doomsday/plugins/common/src/p_user.c
Expand Up @@ -370,7 +370,7 @@ void P_PlayerRemoteMove(player_t* player)
return;

// On client, the console player is not remote.
if(IS_CLIENT) // && plrNum == CONSOLEPLAYER)
if(IS_CLIENT && plrNum == CONSOLEPLAYER)
return;

// On server, there must be valid coordinates.
Expand All @@ -389,30 +389,51 @@ void P_PlayerRemoteMove(player_t* player)
return;
}

if(P_TryMove3f(mo, xyz[VX], xyz[VY], xyz[VZ]))
if(IS_SERVER)
{
if(Smoother_IsOnFloor(smoother))
// On the server, the move must trigger all the usual player movement side-effects
// (e.g., teleporting).

if(P_TryMove3f(mo, xyz[VX], xyz[VY], xyz[VZ]))
{
mo->pos[VZ] = mo->floorZ;
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f (floorz)\n",
plrNum, mo->pos[VX], mo->pos[VY], mo->pos[VZ]);
#endif
if(INRANGE_OF(mo->pos[VX], xyz[VX], .001f) &&
INRANGE_OF(mo->pos[VY], xyz[VY], .001f) &&
Smoother_IsOnFloor(smoother))
{
// It successfully moved to the right XY coords.
mo->pos[VZ] = mo->floorZ;
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f (floorz)\n",
plrNum, mo->pos[VX], mo->pos[VY], mo->pos[VZ]);
#endif
}
else
{
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f\n",
plrNum, mo->pos[VX], mo->pos[VY], mo->pos[VZ]);
#endif
}
}
else
{
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f\n",
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f FAILED!\n",
plrNum, mo->pos[VX], mo->pos[VY], mo->pos[VZ]);
#endif
#endif
}
}
else
{
#ifdef _DEBUG
Con_Message("P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f FAILED!\n",
plrNum, mo->pos[VX], mo->pos[VY], mo->pos[VZ]);
#endif
// Clientside moves have no side-effects.
P_MobjUnlink(mo);
mo->pos[VX] = xyz[VX];
mo->pos[VY] = xyz[VY];
mo->pos[VZ] = xyz[VZ];
P_MobjLink(mo, DDLINK_SECTOR | DDLINK_BLOCKMAP);
P_CheckPosition3fv(mo, xyz);
mo->floorZ = tmFloorZ;
mo->ceilingZ = tmCeilingZ;
}
}

Expand Down

0 comments on commit 261e2cd

Please sign in to comment.