Skip to content

Commit

Permalink
Fixed (all games): Viewer position interpolation was going haywire du…
Browse files Browse the repository at this point in the history
…e to the fact each call to G_Display would modify the engine-side offsets using the current player. Instead, we now store these offsets in player_t and G_Display merely sets the offset before drawing the player's view.

Fixed (all games): All local players shared the same 'aircounter'.

There still remains a problem with the view bobbing though.
  • Loading branch information
danij committed Aug 24, 2008
1 parent cdb0cd1 commit 9904541
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 90 deletions.
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -1030,11 +1030,7 @@ static void SV_WritePlayer(int playernum)

// Version number. Increase when you make changes to the player data
// segment format.
#if __JHEXEN__
SV_WriteByte(2);
#else
SV_WriteByte(3);
#endif
SV_WriteByte(4);

#if __JHEXEN__
// Class.
Expand Down Expand Up @@ -1183,6 +1179,8 @@ static void SV_WritePlayer(int playernum)
SV_WriteLong(p->morphTics);
#endif

SV_WriteLong(p->airCounter);

#if __JHEXEN__
SV_WriteLong(p->jumpTics);
SV_WriteLong(p->worldTimer);
Expand Down Expand Up @@ -1375,6 +1373,8 @@ static void SV_ReadPlayer(player_t *p)
p->morphTics = SV_ReadLong();
#endif

p->airCounter = SV_ReadLong();

#if __JHEXEN__
p->jumpTics = SV_ReadLong();
p->worldTimer = SV_ReadLong();
Expand Down
148 changes: 70 additions & 78 deletions doomsday/plugins/common/src/p_view.c
Expand Up @@ -85,138 +85,130 @@
/**
* Calculate the walking / running height adjustment.
*/
void P_CalcHeight(player_t *player)
void P_CalcHeight(player_t* plr)
{
boolean setz = (player == &players[CONSOLEPLAYER]);
boolean airborne;
boolean morphed = false;
ddplayer_t *dplay = player->plr;
mobj_t *pmo = dplay->mo;
float zOffset, target, step;
static int aircounter = 0;
boolean airborne;
boolean morphed = false;
ddplayer_t* ddplr = plr->plr;
mobj_t* pmo = ddplr->mo;
float target, step;

// Regular movement bobbing (needs to be calculated for gun swing even
// if not on ground).
player->bob =
plr->bob =
(pmo->mom[MX] * pmo->mom[MX]) + (pmo->mom[MY] * pmo->mom[MY]);
player->bob /= 2;
if(player->bob > MAXBOB)
player->bob = MAXBOB;
plr->bob /= 2;
if(plr->bob > MAXBOB)
plr->bob = MAXBOB;

// When flying, don't bob the view.
if((pmo->flags2 & MF2_FLY) && pmo->pos[VZ] > pmo->floorZ)
{
player->bob = 1.0f / 2;
plr->bob = 1.0f / 2;
}

#if __JHERETIC__ || __JHEXEN__
if(player->morphTics)
if(plr->morphTics)
morphed = true;
#endif

// During demo playback the view is thought to be airborne if viewheight
// is zero (Cl_MoveLocalPlayer).
if(Get(DD_PLAYBACK))
airborne = !dplay->viewHeight;
airborne = !ddplr->viewHeight;
else
airborne = pmo->pos[VZ] > pmo->floorZ; // Truly in the air?

// Should view bobbing be done?
if(setz)
{ // Morphed players don't bob their view.
if(P_IsCamera(dplay->mo) /*$democam*/ ||
(dplay->flags & DDPF_CHASECAM) || airborne || morphed ||
(P_GetPlayerCheats(player) & CF_NOMOMENTUM))
{
// Reduce the bob offset to zero.
target = 0;
}
else
{
angle_t angle = (FINEANGLES / 20 * levelTime) & FINEMASK;
target = cfg.bobView * ((player->bob / 2) * FIX2FLT(finesine[angle]));
}

// Do the change gradually.
zOffset = *((float*) DD_GetVariable(DD_VIEWZ_OFFSET));
if(airborne || aircounter > 0)
step = 4.0f - (aircounter > 0 ? aircounter * 0.2f : 3.5f);
else
step = 4.0f;

if(zOffset > target)
{
if(zOffset - target > step)
zOffset -= step;
else
zOffset = target;
}
else if(zOffset < target)
{
if(target - zOffset > step)
zOffset += step;
else
zOffset = target;
}
// Morphed players don't bob their view.
if(P_IsCamera(ddplr->mo) /*$democam*/ ||
(ddplr->flags & DDPF_CHASECAM) || airborne || morphed ||
(P_GetPlayerCheats(plr) & CF_NOMOMENTUM))
{
// Reduce the bob offset to zero.
target = 0;
}
else
{
angle_t angle = (FINEANGLES / 20 * levelTime) & FINEMASK;
target = cfg.bobView * ((plr->bob / 2) * FIX2FLT(finesine[angle]));
}

DD_SetVariable(DD_VIEWZ_OFFSET, &zOffset);
// Do the change gradually.
if(airborne || plr->airCounter > 0)
step = 4.0f - (plr->airCounter > 0 ? plr->airCounter * 0.2f : 3.5f);
else
step = 4.0f;

// The aircounter will soften the touchdown after a fall.
aircounter--;
if(airborne)
aircounter = TICSPERSEC / 2;
if(plr->viewOffset[VZ] > target)
{
if(plr->viewOffset[VZ] - target > step)
plr->viewOffset[VZ] -= step;
else
plr->viewOffset[VZ] = target;
}
else if(plr->viewOffset[VZ] < target)
{
if(target - plr->viewOffset[VZ] > step)
plr->viewOffset[VZ] += step;
else
plr->viewOffset[VZ] = target;
}

// The aircounter will soften the touchdown after a fall.
plr->airCounter--;
if(airborne)
plr->airCounter = TICSPERSEC / 2;

// Should viewheight be moved? Not if camera or we're in demo.
if(!((P_GetPlayerCheats(player) & CF_NOMOMENTUM) ||
if(!((P_GetPlayerCheats(plr) & CF_NOMOMENTUM) ||
P_IsCamera(pmo) /*$democam*/ || Get(DD_PLAYBACK)))
{
// Move viewheight.
if(player->playerState == PST_LIVE)
if(plr->playerState == PST_LIVE)
{
dplay->viewHeight += dplay->viewHeightDelta;
ddplr->viewHeight += ddplr->viewHeightDelta;

if(dplay->viewHeight > VIEW_HEIGHT)
if(ddplr->viewHeight > VIEW_HEIGHT)
{
dplay->viewHeight = VIEW_HEIGHT;
dplay->viewHeightDelta = 0;
ddplr->viewHeight = VIEW_HEIGHT;
ddplr->viewHeightDelta = 0;
}
else if(dplay->viewHeight < VIEW_HEIGHT / 2.0f)
else if(ddplr->viewHeight < VIEW_HEIGHT / 2.0f)
{
dplay->viewHeight = VIEW_HEIGHT / 2.0f;
if(dplay->viewHeightDelta <= 0)
dplay->viewHeightDelta = 1;
ddplr->viewHeight = VIEW_HEIGHT / 2.0f;
if(ddplr->viewHeightDelta <= 0)
ddplr->viewHeightDelta = 1;
}

if(dplay->viewHeightDelta)
if(ddplr->viewHeightDelta)
{
dplay->viewHeightDelta += 0.25f;
if(!dplay->viewHeightDelta)
dplay->viewHeightDelta = 1;
ddplr->viewHeightDelta += 0.25f;
if(!ddplr->viewHeightDelta)
ddplr->viewHeightDelta = 1;
}
}
}

// Set the player's eye-level Z coordinate.
dplay->viewZ = pmo->pos[VZ] +
(P_IsCamera(pmo)? 0 : dplay->viewHeight);
// Set the plr's eye-level Z coordinate.
ddplr->viewZ = pmo->pos[VZ] +
(P_IsCamera(pmo)? 0 : ddplr->viewHeight);

// During demo playback (or camera mode) the viewz will not be modified
// any further.
if(!(Get(DD_PLAYBACK) || P_IsCamera(pmo) ||
(dplay->flags & DDPF_CHASECAM)))
(ddplr->flags & DDPF_CHASECAM)))
{
if(morphed)
{ // Chicken or pig.
dplay->viewZ -= 20;
ddplr->viewZ -= 20;
}

// Foot clipping is done for living players.
if(player->playerState != PST_DEAD)
if(plr->playerState != PST_DEAD)
{
if(pmo->floorClip && pmo->pos[VZ] <= pmo->floorZ)
{
dplay->viewZ -= pmo->floorClip;
ddplr->viewZ -= pmo->floorClip;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jdoom/include/d_player.h
Expand Up @@ -62,6 +62,7 @@ typedef struct player_s {
playerclass_t class; // Player class type.
playerbrain_t brain;

float viewOffset[3];
float bob; // Bounded/scaled total momentum.
int health; // This is only used between levels, mo->health is used during levels.
int armorPoints;
Expand Down Expand Up @@ -103,6 +104,7 @@ typedef struct player_s {

// The player can jump if this counter is zero.
int jumpTics;
int airCounter;
int flyHeight;
int update, startSpot;

Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom/src/p_mobj.c
Expand Up @@ -1051,6 +1051,7 @@ void P_SpawnPlayer(spawnspot_t *spot, int pnum)
p->damageCount = 0;
p->bonusCount = 0;
p->jumpTics = 0;
p->airCounter = 0;
p->plr->extraLight = 0;
p->plr->fixedColorMap = 0;
p->plr->lookDir = 0;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/jdoom64/include/d_player.h
Expand Up @@ -71,8 +71,8 @@ typedef struct player_s {
playerclass_t class; // player class type
playerbrain_t brain;

// Bounded/scaled total momentum.
float bob;
float viewOffset[3];
float bob; // Bounded/scaled total momentum.

// This is only used between levels, mo->health is used during levels.
int health;
Expand Down Expand Up @@ -135,7 +135,7 @@ typedef struct player_s {

// The player can jump if this counter is zero.
int jumpTics;

int airCounter;
int update, startSpot;

// Target view to a mobj (NULL=disabled).
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom64/src/p_mobj.c
Expand Up @@ -1112,6 +1112,7 @@ void P_SpawnPlayer(spawnspot_t *spot, int pnum)
p->plr->lookDir = 0; /* $unifiedangles */
p->plr->flags |= DDPF_FIXANGLES | DDPF_FIXPOS | DDPF_FIXMOM;
p->jumpTics = 0;
p->airCounter = 0;
mobj->player = p;
mobj->dPlayer = p->plr;
mobj->health = p->health;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/jheretic/include/h_player.h
Expand Up @@ -91,8 +91,8 @@ typedef struct player_s {
playerclass_t class; // Player class.
playerbrain_t brain;

// bounded/scaled total momentum
float bob;
float viewOffset[3];
float bob; // bounded/scaled total momentum

// This is only used between levels,
// mo->health is used during levels.
Expand Down Expand Up @@ -155,7 +155,7 @@ typedef struct player_s {

// The player can jump if this counter is zero.
int jumpTics;

int airCounter;
int update, startSpot;

// Target view to a mobj (NULL=disabled).
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jheretic/src/p_mobj.c
Expand Up @@ -1216,6 +1216,7 @@ void P_SpawnPlayer(spawnspot_t *spot, int plrnum)
p->plr->lookDir = 0;
p->plr->flags |= DDPF_FIXANGLES | DDPF_FIXPOS | DDPF_FIXMOM;
p->jumpTics = 0;
p->airCounter = 0;
mobj->player = p;
mobj->dPlayer = p->plr;
mobj->health = p->health;
Expand Down
4 changes: 3 additions & 1 deletion doomsday/plugins/jhexen/include/x_player.h
Expand Up @@ -98,6 +98,7 @@ typedef struct player_s {
playerclass_t class; // Player class type.
playerbrain_t brain;

float viewOffset[3];
fixed_t bob; // Bounded/scaled total momentum.

int flyHeight;
Expand Down Expand Up @@ -137,7 +138,8 @@ typedef struct player_s {
int colorMap; // 0-3 for which color to draw player.
pspdef_t pSprites[NUMPSPRITES]; // view sprites (gun, etc).
int morphTics; // Player is a pig if > 0.
uint jumpTics; // Delay the next jump for a moment.
int jumpTics; // Delay the next jump for a moment.
int airCounter;
unsigned int worldTimer; // Total time the player's been playing.
int update, startSpot;
// Target view to a mobj (NULL=disabled).
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jhexen/src/p_mobj.c
Expand Up @@ -1369,6 +1369,7 @@ void P_SpawnPlayer(spawnspot_t *spot, int playernum)
p->plr->lookDir = 0;/* $unifiedangles */
p->plr->flags |= DDPF_FIXANGLES | DDPF_FIXPOS | DDPF_FIXMOM;
p->jumpTics = 0;
p->airCounter = 0;
mobj->player = p;
mobj->dPlayer = p->plr;
mobj->health = p->health;
Expand Down

0 comments on commit 9904541

Please sign in to comment.