Skip to content

Commit

Permalink
All Games|libdoomsday: Added notification about psprite state changes
Browse files Browse the repository at this point in the history
Whenever a psprite changes state, a plugin notification is sent so
the client can react to the change.
  • Loading branch information
skyjake committed Jul 31, 2015
1 parent 9a0fdfb commit 377512d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/gameapi.h
Expand Up @@ -106,7 +106,7 @@ enum {
DD_SHARED_FIXED_TRIGGER_OBSOLETE, ///< obsolete
DD_GAMETIC,
DD_NOTIFY_PLAYER_WEAPON_CHANGED, ///< a player's weapon changed (including powerups)
DD_UNUSED6, // DD_OPENTOP
DD_NOTIFY_PSPRITE_STATE_CHANGED, ///< a player's psprite state has changed
DD_UNUSED7, // DD_OPENBOTTOM
DD_UNUSED8, // DD_LOWFLOOR
DD_CPLAYER_THRUST_MUL_OBSOLETE, ///< obsolete
Expand Down
6 changes: 6 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/plugins.h
Expand Up @@ -101,6 +101,12 @@ typedef struct {
char const *weaponId; ///< Defined in Values (includes power-ups) (UTF-8).
} ddnotify_player_weapon_changed_t;

/// Parameters for DD_NOTIFY_PSPRITE_STATE_CHANGED
typedef struct {
int player;
struct state_s const *state;
} ddnotify_psprite_state_changed_t;

#ifdef __cplusplus

#include <de/Observers>
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/common/include/player.h
Expand Up @@ -256,6 +256,8 @@ angle_t Player_ViewYawAngle(int playerNum);
*/
void Player_UpdateStatusCVars(player_t const *player);

void Player_NotifyPSpriteChange(player_t *player, int position);

/**
* Called in the end of G_Ticker. Wraps up the tick for a player.
*
Expand Down
11 changes: 11 additions & 0 deletions doomsday/apps/plugins/common/src/player.cpp
Expand Up @@ -1849,6 +1849,17 @@ void Player_PostTick(player_t *player)
}
}

void Player_NotifyPSpriteChange(player_t *player, int position)
{
if(position == ps_weapon)
{
ddnotify_psprite_state_changed_t args;
args.player = player - players;
args.state = player->pSprites[position].state;
Plug_Notify(DD_NOTIFY_PSPRITE_STATE_CHANGED, &args);
}
}

/**
* Updates game status cvars for the specified player.
*/
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/doom/src/p_pspr.c
Expand Up @@ -104,6 +104,8 @@ void P_SetPsprite(player_t* player, int position, statenum_t stnum)
psp->state = state;
psp->tics = state->tics; // Could be 0.

Player_NotifyPSpriteChange(player, position);

if(state->misc[0])
{
// Coordinate set.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/doom64/src/p_pspr.c
Expand Up @@ -110,6 +110,8 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum)
psp->state = state;
psp->tics = state->tics; // Could be 0.

Player_NotifyPSpriteChange(player, position);

if(state->misc[0])
{
// Coordinate set.
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/plugins/heretic/src/p_pspr.c
Expand Up @@ -76,6 +76,7 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum)
state = &STATES[stnum];
psp->state = state;
psp->tics = state->tics; // Could be 0.
Player_NotifyPSpriteChange(player, position);
if(state->misc[0])
{ // Set coordinates.
psp->pos[VX] = (float) state->misc[0];
Expand Down
4 changes: 4 additions & 0 deletions doomsday/apps/plugins/hexen/src/p_pspr.c
Expand Up @@ -317,6 +317,8 @@ void P_SetPsprite(player_t *plr, int position, statenum_t stnum)
psp->tics = state->tics; // could be 0
P_SetPSpriteOffset(psp, plr, state);

Player_NotifyPSpriteChange(plr, position);

if(state->action)
{ // Call action routine.
state->action(plr, psp);
Expand Down Expand Up @@ -351,7 +353,9 @@ void P_SetPspriteNF(player_t *plr, int position, statenum_t stnum)
psp->state = state;
psp->tics = state->tics; // could be 0

Player_NotifyPSpriteChange(plr, position);
P_SetPSpriteOffset(psp, plr, state);

stnum = psp->state->nextState;
} while(!psp->tics); // An initial state of 0 could cycle through.
}
Expand Down

0 comments on commit 377512d

Please sign in to comment.