Skip to content

Commit

Permalink
All Games|libdoomsday: Notify about player weapon changes
Browse files Browse the repository at this point in the history
Added Values that specify a text identifier for each player weapon.

Expanded `G_Ticker` to perform "post-tick" for each player. This
allows doing things like status cvar updates after the tick.

Using the `Plug_Notify` mechanism, games will now inform the engine
during post-tick when a player's current weapon changes. The
notification includes the text identifier from Values.

This identifier can then be used to look for relevant assets (for
psprite 3D models).
  • Loading branch information
skyjake committed Jul 27, 2015
1 parent ccb8229 commit e810c80
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/gameapi.h
Expand Up @@ -105,7 +105,7 @@ enum {
DD_XGFUNC_LINK, ///< XG line classes
DD_SHARED_FIXED_TRIGGER_OBSOLETE, ///< obsolete
DD_GAMETIC,
DD_UNUSED5, // DD_OPENRANGE
DD_NOTIFY_PLAYER_WEAPON_CHANGED, ///< a player's weapon changed (including powerups)
DD_UNUSED6, // DD_OPENTOP
DD_UNUSED7, // DD_OPENBOTTOM
DD_UNUSED8, // DD_LOWFLOOR
Expand Down
7 changes: 7 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/plugins.h
Expand Up @@ -94,6 +94,13 @@ typedef struct {
Str translatedCustom;
} ddhook_mapinfo_convert_t;

/// Parameters for DD_NOTIFY_PLAYER_WEAPON_CHANGED
typedef struct {
int player;
int weapon; ///< Number of the weapon.
char const *weaponId; ///< Defined in Values (includes power-ups) (UTF-8).
} ddnotify_player_weapon_changed_t;

#ifdef __cplusplus

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

/**
* Called in the end of G_Ticker. Wraps up the tick for a player.
*
* @param player Player.
*/
void Player_PostTick(player_t *player);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
7 changes: 5 additions & 2 deletions doomsday/apps/plugins/common/src/g_game.cpp
Expand Up @@ -1640,8 +1640,11 @@ void G_Ticker(timespan_t ticLength)
break;
}

// Update the game status cvars for player data.
Player_UpdateStatusCVars(&players[CONSOLEPLAYER]);
// Players post-ticking.
for(int i = 0; i < MAXPLAYERS; ++i)
{
Player_PostTick(&players[i]);
}

// Servers will have to update player information and do such stuff.
if(!IS_CLIENT)
Expand Down
56 changes: 56 additions & 0 deletions doomsday/apps/plugins/common/src/player.cpp
Expand Up @@ -25,6 +25,7 @@
#include <cstring>
#include <cstdio>
#include <de/memory.h>
#include <doomsday/plugins.h>
#include "d_net.h"
#include "d_netcl.h"
#include "d_netsv.h"
Expand Down Expand Up @@ -1793,6 +1794,61 @@ void player_s::read(reader_s *reader, playerheader_t &plrHdr)
update |= PSF_REBORN;
}

String Player_WeaponId(player_t const *plr)
{
String value = "Weapon Info|";
#ifdef __JHEXEN__
static char const *className[] = { "Fighter", "Cleric", "Mage", "Pig" };
value.append(className[plr->class_]);
value.append("|");
#endif
#ifdef __JHERETIC__
if(plr->class_ == PCLASS_CHICKEN)
{
value.append("Beak");
}
else
{
value.append(QString::number(plr->readyWeapon));
}
#endif
#if defined(__JDOOM__) || defined(__JDOOM64__) || defined(__JHEXEN__)
value.append(QString::number(plr->readyWeapon));
#endif
value.append("|Id");

if(auto *def = Defs().getValueById(value))
{
return def->text;
}
return "";
}

void Player_PostTick(player_t *player)
{
if(!player->plr->inGame) return;

int const console = player - players;

// Update the game status cvars for player data.
if(console == CONSOLEPLAYER)
{
Player_UpdateStatusCVars(player);
}

// Notify engine whenever the current weapon changes.
if(player->update & PSF_READY_WEAPON)
{
Block const id = Player_WeaponId(player).toUtf8();

ddnotify_player_weapon_changed_t args;
args.player = console;
args.weapon = player->readyWeapon;
args.weaponId = id.constData();
Plug_Notify(DD_NOTIFY_PLAYER_WEAPON_CHANGED, &args);
}
}

/**
* Updates game status cvars for the specified player.
*/
Expand Down
9 changes: 9 additions & 0 deletions doomsday/apps/plugins/doom/defs/values.ded
Expand Up @@ -106,6 +106,7 @@ Values {

Weapon Info {
0 {
Id = "punch";
Type = "noammo";
Up = "PUNCHUP";
Down = "PUNCHDOWN";
Expand All @@ -116,6 +117,7 @@ Values {
Static = "0";
};
1 {
Id = "pistol";
Type = "clip";
Per shot = "1";
Up = "PISTOLUP";
Expand All @@ -127,6 +129,7 @@ Values {
Static = "0";
};
2 {
Id = "sgun";
Type = "shell";
Per shot = "1";
Up = "SGUNUP";
Expand All @@ -138,6 +141,7 @@ Values {
Static = "0";
};
3 {
Id = "chain";
Type = "clip";
Per shot = "1";
Up = "CHAINUP";
Expand All @@ -149,6 +153,7 @@ Values {
Static = "0";
};
4 {
Id = "missile";
Type = "misl";
Per shot = "1";
Up = "MISSILEUP";
Expand All @@ -160,6 +165,7 @@ Values {
Static = "0";
};
5 {
Id = "plasma";
Type = "cell";
Per shot = "1";
Up = "PLASMAUP";
Expand All @@ -171,6 +177,7 @@ Values {
Static = "0";
};
6 {
Id = "bfg";
Type = "cell";
Per shot = "40";
Up = "BFGUP";
Expand All @@ -182,6 +189,7 @@ Values {
Static = "0";
};
7 {
Id = "saw";
Type = "noammo";
Up = "SAWUP";
Down = "SAWDOWN";
Expand All @@ -192,6 +200,7 @@ Values {
Static = "0";
};
8 {
Id = "dsgun";
Type = "shell";
Per shot = "2";
Up = "DSGUNUP";
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/plugins/heretic/defs/jheretic.ded
Expand Up @@ -41,3 +41,4 @@ Include "objects.ded";
Include "sprites.ded";
Include "text.ded";
Include "sounds.ded";
Include "values.ded";
52 changes: 52 additions & 0 deletions doomsday/apps/plugins/heretic/defs/values.ded
@@ -0,0 +1,52 @@
# Heretic: Values
#
# The strings from all Values definition blocks are merged together.
# This means you don't have to add all your values here; they can be
# in a Values block in another file.

Header { Version = 5; }

Values {
# Weapon Info|*|Static
# Defaults to "0". "1" = prevent the lowering of the HUD weapon when doing a switch.

Weapon Info {
0 {
Id = "staff";
Static = "0";
};
1 {
Id = "goldwand";
Static = "0";
};
2 {
Id = "crossbow";
Static = "0";
};
3 {
Id = "blaster";
Static = "0";
};
4 {
Id = "skullrod";
Static = "0";
};
5 {
Id = "phoenix";
Static = "0";
};
6 {
Id = "mace";
Static = "0";
};
7 {
Id = "gauntlet";
Static = "0";
};

# As a Chicken, there is only the Beak weapon available.
Beak {
Id = "beak";
};
};
};
2 changes: 1 addition & 1 deletion doomsday/apps/plugins/heretic/src/h_items.cpp
Expand Up @@ -470,7 +470,7 @@ AmmoDef const *P_AmmoDef(ammotype_t type)
}

/**
*Initialize weapon info, maxammo and clipammo.
* Initialize weapon info, maxammo and clipammo.
*/
void P_InitWeaponInfo()
{
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/plugins/heretic/src/p_pspr.c
Expand Up @@ -363,6 +363,7 @@ void C_DECL A_Lower(player_t *player, pspdef_t *psp)
}

player->readyWeapon = player->pendingWeapon;
player->update |= PSF_READY_WEAPON;

// Should we suddenly lower the weapon?
if(cfg.bobWeaponLower &&
Expand Down
63 changes: 61 additions & 2 deletions doomsday/apps/plugins/hexen/defs/values.ded
@@ -1,4 +1,4 @@
# libhexen: Values
# Hexen: Values
#
# The strings from all Values definition blocks are merged together.
# This means you don't have to add all your values here; they can be
Expand All @@ -13,4 +13,63 @@ Values {
Blue mana = "25";
};
};
};

Weapon Info {
Fighter {
0 {
Id = "punch";
};
1 {
Id = "axe";
};
2 {
Id = "hammer";
};
3 {
Id = "sword";
};
};
Cleric {
0 {
Id = "mace";
};
1 {
Id = "serpent";
};
2 {
Id = "flame";
};
3 {
Id = "holy";
};
};
Mage {
0 {
Id = "wand";
};
1 {
Id = "frost";
};
2 {
Id = "lightning";
};
3 {
Id = "staff";
};
};
Pig {
0 {
Id = "snout";
};
1 {
Id = "snout";
};
2 {
Id = "snout";
};
3 {
Id = "snout";
};
};
};
};
2 changes: 1 addition & 1 deletion doomsday/apps/plugins/hexen/src/p_pspr.c
Expand Up @@ -581,7 +581,7 @@ void C_DECL A_Lower(player_t *plr, pspdef_t *psp)
}

plr->readyWeapon = plr->pendingWeapon;
plr->update |= PSF_WEAPONS;
plr->update |= PSF_WEAPONS | PSF_READY_WEAPON;
P_BringUpWeapon(plr);
}

Expand Down

0 comments on commit e810c80

Please sign in to comment.