Skip to content

Commit

Permalink
Fixed: Bug which resulted in the weapon bob for all local players to …
Browse files Browse the repository at this point in the history
…be synced with that of the console player. This was caused by the bob code assuming that only one viewer was altering the engine-side bob offset and so used it as though it persisted over multiple frames.
  • Loading branch information
danij committed Aug 23, 2008
1 parent c935e2b commit 144f6bf
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 76 deletions.
4 changes: 3 additions & 1 deletion doomsday/plugins/jdoom/include/p_pspr.h
Expand Up @@ -52,9 +52,11 @@ typedef enum {
} psprnum_t;

typedef struct {
state_t *state; // A NULL state means not active.
state_t* state; // A NULL state means not active.
int tics;
float pos[2]; // [x, y].
} pspdef_t;

void R_GetWeaponBob(int player, float* x, float* y);

#endif
14 changes: 5 additions & 9 deletions doomsday/plugins/jdoom/src/d_api.c
Expand Up @@ -82,7 +82,7 @@ int G_GetInteger(int id)
/**
* Get a pointer to the value of a variable. Added for 64-bit support.
*/
void *G_GetVariable(int id)
void* G_GetVariable(int id)
{
static float bob[2];

Expand Down Expand Up @@ -113,16 +113,12 @@ void *G_GetVariable(int id)
return xgClasses;

case DD_PSPRITE_BOB_X:
bob[VX] = 1 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);

return &bob[VX];
R_GetWeaponBob(DISPLAYPLAYER, &bob[0], NULL);
return &bob[0];

case DD_PSPRITE_BOB_Y:
bob[VY] = 32 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);

return &bob[VY];
R_GetWeaponBob(DISPLAYPLAYER, NULL, &bob[1]);
return &bob[1];

default:
break;
Expand Down
26 changes: 20 additions & 6 deletions doomsday/plugins/jdoom/src/p_pspr.c
Expand Up @@ -71,7 +71,22 @@ static float bulletSlope;

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

void P_SetPsprite(player_t *player, int position, statenum_t stnum)
void R_GetWeaponBob(int player, float* x, float* y)
{
if(x)
{
*x = 1 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);
}

if(y)
{
*y = 32 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);
}
}

void P_SetPsprite(player_t* player, int position, statenum_t stnum)
{
pspdef_t *psp;
state_t *state;
Expand Down Expand Up @@ -232,8 +247,7 @@ void C_DECL A_WeaponReady(player_t *player, pspdef_t *psp)
player->attackDown = false;

// Bob the weapon based on movement speed.
psp->pos[VX] = *((float *)G_GetVariable(DD_PSPRITE_BOB_X));
psp->pos[VY] = *((float *)G_GetVariable(DD_PSPRITE_BOB_Y));
R_GetWeaponBob(player - players, &psp->pos[0], &psp->pos[1]);

// Psprite state.
player->plr->pSprites[0].state = DDPSP_BOBBING;
Expand Down Expand Up @@ -681,15 +695,15 @@ void C_DECL A_BFGSpray(mobj_t *mo)
}
}

void C_DECL A_BFGsound(player_t *player, pspdef_t *psp)
void C_DECL A_BFGsound(player_t* player, pspdef_t* psp)
{
S_StartSound(SFX_BFG, player->plr->mo);
}

/**
* Called at start of level for each player.
*/
void P_SetupPsprites(player_t *player)
void P_SetupPsprites(player_t* player)
{
int i;

Expand All @@ -707,7 +721,7 @@ void P_SetupPsprites(player_t *player)
/**
* Called every tic by player thinking routine.
*/
void P_MovePsprites(player_t *player)
void P_MovePsprites(player_t* player)
{
int i;
pspdef_t *psp;
Expand Down
12 changes: 7 additions & 5 deletions doomsday/plugins/jdoom64/include/p_pspr.h
Expand Up @@ -45,14 +45,16 @@ typedef enum {
} psprnum_t;

typedef struct {
state_t *state; // A NULL state means not active.
state_t* state; // A NULL state means not active.
int tics;
float pos[2]; // [x, y]
} pspdef_t;

void P_SetupPsprites(struct player_s *curplayer);
void P_MovePsprites(struct player_s *curplayer);
void P_DropWeapon(struct player_s *player);
void P_SetPsprite(struct player_s *player, int position, statenum_t stnum);
void P_SetupPsprites(struct player_s* curplayer);
void P_MovePsprites(struct player_s* curplayer);
void P_DropWeapon(struct player_s* player);
void P_SetPsprite(struct player_s* player, int position, statenum_t stnum);

void R_GetWeaponBob(int player, float* x, float* y);

#endif
12 changes: 4 additions & 8 deletions doomsday/plugins/jdoom64/src/d_api.c
Expand Up @@ -114,16 +114,12 @@ void *G_GetVariable(int id)
return xgClasses;

case DD_PSPRITE_BOB_X:
bob[VX] = 1 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);

return &bob[VX];
R_GetWeaponBob(CONSOLEPLAYER, &bob[0], NULL);
return &bob[0];

case DD_PSPRITE_BOB_Y:
bob[VY] = 32 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);

return &bob[VY];
R_GetWeaponBob(CONSOLEPLAYER, NULL, &bob[1]);
return &bob[1];

default:
break;
Expand Down
22 changes: 18 additions & 4 deletions doomsday/plugins/jdoom64/src/p_pspr.c
Expand Up @@ -75,6 +75,21 @@ static float bulletSlope;

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

void R_GetWeaponBob(int player, float* x, float* y)
{
if(x)
{
*x = 1 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);
}

if(y)
{
*y = 32 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);
}
}

void P_SetPsprite(player_t *player, int position, statenum_t stnum)
{
pspdef_t *psp;
Expand Down Expand Up @@ -184,9 +199,9 @@ void P_DropWeapon(player_t *player)
* The player can fire the weapon or change to another weapon at this time.
* Follows after getting weapon up, or after previous attack/fire sequence.
*/
void C_DECL A_WeaponReady(player_t *player, pspdef_t *psp)
void C_DECL A_WeaponReady(player_t* player, pspdef_t* psp)
{
weaponmodeinfo_t *wminfo;
weaponmodeinfo_t* wminfo;

// Enable the pspr Y offset (might be disabled in A_Lower).
DD_SetInteger(DD_WEAPON_OFFSET_SCALE_Y, 1000);
Expand Down Expand Up @@ -230,8 +245,7 @@ void C_DECL A_WeaponReady(player_t *player, pspdef_t *psp)
player->attackDown = false;

// Bob the weapon based on movement speed.
psp->pos[VX] = *((float *)G_GetVariable(DD_PSPRITE_BOB_X));
psp->pos[VY] = *((float *)G_GetVariable(DD_PSPRITE_BOB_Y));
R_GetWeaponBob(player - players, &psp->pos[0], &psp->pos[1]);

// Psprite state.
player->plr->pSprites[0].state = DDPSP_BOBBING;
Expand Down
4 changes: 3 additions & 1 deletion doomsday/plugins/jheretic/include/p_pspr.h
Expand Up @@ -41,9 +41,11 @@ typedef enum {
} psprnum_t;

typedef struct pspdef_s {
state_t *state; // a NULL state means not active.
state_t* state; // a NULL state means not active.
int tics;
float pos[2];
} pspdef_t;

void R_GetWeaponBob(int player, float* x, float* y);

#endif
14 changes: 5 additions & 9 deletions doomsday/plugins/jheretic/src/h_api.c
Expand Up @@ -93,7 +93,7 @@ int G_GetInteger(int id)
/**
* Get a pointer to the value of a variable. Added for 64-bit support.
*/
void *G_GetVariable(int id)
void* G_GetVariable(int id)
{
static float bob[2];

Expand Down Expand Up @@ -128,16 +128,12 @@ void *G_GetVariable(int id)
return xgClasses;

case DD_PSPRITE_BOB_X:
bob[VX] = 1 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);

return &bob[VX];
R_GetWeaponBob(DISPLAYPLAYER, &bob[0], NULL);
return &bob[0];

case DD_PSPRITE_BOB_Y:
bob[VY] = 32 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);

return &bob[VY];
R_GetWeaponBob(DISPLAYPLAYER, NULL, &bob[1]);
return &bob[1];

default:
break;
Expand Down
20 changes: 17 additions & 3 deletions doomsday/plugins/jheretic/src/p_pspr.c
Expand Up @@ -643,6 +643,21 @@ float bulletSlope;

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

void R_GetWeaponBob(int player, float* x, float* y)
{
if(x)
{
*x = 1 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);
}

if(y)
{
*y = 32 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);
}
}

/**
*Initialize weapon info, maxammo and clipammo.
*/
Expand Down Expand Up @@ -845,10 +860,9 @@ void C_DECL A_WeaponReady(player_t *player, pspdef_t *psp)
if(!player->morphTics)
{
// Bob the weapon based on movement speed.
psp->pos[VX] = *((float *)G_GetVariable(DD_PSPRITE_BOB_X));
psp->pos[VY] = *((float *)G_GetVariable(DD_PSPRITE_BOB_Y));
R_GetWeaponBob(player - players, &psp->pos[0], &psp->pos[1]);

ddpsp->offset[VX] = ddpsp->offset[VY] = 0;
ddpsp->offset[0] = ddpsp->offset[1] = 0;
}

// Psprite state.
Expand Down
10 changes: 6 additions & 4 deletions doomsday/plugins/jhexen/include/p_pspr.h
Expand Up @@ -3,7 +3,7 @@
* License: GPL + jHeretic/jHexen Exception
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2006-2007 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2006-2008 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,8 +36,8 @@
* p_pspr.h: Sprite animation.
*/

#ifndef __P_PSPR__
#define __P_PSPR__
#ifndef __P_PSPR_H__
#define __P_PSPR_H__

#ifndef __JHEXEN__
# error "Using jHexen headers without __JHEXEN__"
Expand All @@ -50,9 +50,11 @@ typedef enum {
} psprnum_t;

typedef struct {
state_t *state; // a NULL state means not active
state_t* state; // @c NULL means not active.
int tics;
float pos[2];
} pspdef_t;

void R_GetWeaponBob(int player, float* x, float* y);

#endif
28 changes: 24 additions & 4 deletions doomsday/plugins/jhexen/src/p_pspr.c
Expand Up @@ -361,6 +361,27 @@ weaponinfo_t weaponInfo[NUM_WEAPON_TYPES][NUM_PLAYER_CLASSES] = {

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

void R_GetWeaponBob(int player, float* x, float* y)
{
if(x)
{
if(players[player].morphTics > 0)
*x = 0;
else
*x = 1 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);
}

if(y)
{
if(players[player].morphTics > 0)
*y = 0;
else
*y = 32 + (cfg.bobWeapon * players[player].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);
}
}

/**
* Offset in state->misc1/2.
*/
Expand Down Expand Up @@ -586,10 +607,9 @@ void C_DECL A_WeaponReady(player_t *plr, pspdef_t *psp)
if(!plr->morphTics)
{
// Bob the weapon based on movement speed.
psp->pos[VX] = *((float *)G_GetVariable(DD_PSPRITE_BOB_X));
psp->pos[VY] = *((float *)G_GetVariable(DD_PSPRITE_BOB_Y));
R_GetWeaponBob(plr - players, &psp->pos[0], &psp->pos[1]);

ddpsp->offset[VX] = ddpsp->offset[VY] = 0;
ddpsp->offset[0] = ddpsp->offset[1] = 0;
}

// Psprite state.
Expand All @@ -599,7 +619,7 @@ void C_DECL A_WeaponReady(player_t *plr, pspdef_t *psp)
/**
* The player can re fire the weapon without lowering it entirely.
*/
void C_DECL A_ReFire(player_t *plr, pspdef_t *psp)
void C_DECL A_ReFire(player_t* plr, pspdef_t* psp)
{
if((plr->brain.attack) &&
plr->pendingWeapon == WT_NOCHANGE && plr->health)
Expand Down
26 changes: 4 additions & 22 deletions doomsday/plugins/jhexen/src/x_api.c
Expand Up @@ -128,30 +128,12 @@ void *G_GetVariable(int id)
return NULL;

case DD_PSPRITE_BOB_X:
if(players[CONSOLEPLAYER].morphTics > 0)
{
bob[VX] = 0;
}
else
{
bob[VX] = 1 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finecosine[(128 * levelTime) & FINEMASK]);
}

return &bob[VX];
R_GetWeaponBob(DISPLAYPLAYER, &bob[0], NULL);
return &bob[0];

case DD_PSPRITE_BOB_Y:
if(players[CONSOLEPLAYER].morphTics > 0)
{
bob[VY] = 0;
}
else
{
bob[VY] = 32 + (cfg.bobWeapon * players[CONSOLEPLAYER].bob) *
FIX2FLT(finesine[(128 * levelTime) & FINEMASK & (FINEANGLES / 2 - 1)]);
}

return &bob[VY];
R_GetWeaponBob(DISPLAYPLAYER, NULL, &bob[1]);
return &bob[1];

default:
break;
Expand Down

0 comments on commit 144f6bf

Please sign in to comment.