Skip to content

Commit

Permalink
Client: Weapons changed via a request to the server
Browse files Browse the repository at this point in the history
Instead of letting the client change weapons on its own, it will
now send a request to the server, who will actually carry out
the weapon change.
  • Loading branch information
skyjake committed Mar 20, 2011
1 parent 0beadda commit d0fe1fa
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
4 changes: 4 additions & 0 deletions doomsday/engine/portable/src/cl_mobj.c
Expand Up @@ -723,6 +723,10 @@ void Cl_ReadMobjDelta2(boolean skip)
fastMom = true;
}

#ifdef _DEBUG
VERBOSE2( Con_Message("Cl_ReadMobjDelta: Reading mobj delta for %i (df:0x%x edf:0x%x skip:%i)\n", id, df, moreFlags, skip) );
#endif

if(!skip)
{
// Get a mobj for this.
Expand Down
3 changes: 1 addition & 2 deletions doomsday/engine/portable/src/sv_pool.c
Expand Up @@ -588,8 +588,7 @@ boolean Sv_RegisterCompareMobj(cregister_t* reg, const mobj_t* s,

// Mobj state sent periodically, if it keeps changing.
if((!(s->ddFlags & DDMF_MISSILE) && regMo &&
Sys_GetTime() - regMo->lastTimeStateSent > (60 + s->thinker.id%35) &&
r->state != s->state) ||
Sys_GetTime() - regMo->lastTimeStateSent > (60 + s->thinker.id%35) && r->state != s->state) ||
!Def_SameStateSequence(r->state, s->state))
{
df |= MDF_STATE;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/plugins/common/include/d_net.h
Expand Up @@ -103,7 +103,8 @@ typedef struct {
// Player action requests.
enum {
GPA_FIRE = 1,
GPA_USE = 2
GPA_USE = 2,
GPA_CHANGE_WEAPON = 3
};

// Game state flags.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/d_netcl.h
Expand Up @@ -45,6 +45,6 @@ void NetCl_SendPlayerInfo(void);
void NetCl_SaveGame(void* data);
void NetCl_LoadGame(void* data);
void NetCl_Paused(boolean setPause);
void NetCl_PlayerActionRequest(player_t* player, int actionType);
void NetCl_PlayerActionRequest(player_t* player, int actionType, int actionParam);

#endif
15 changes: 12 additions & 3 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -549,12 +549,14 @@ void NetCl_UpdatePlayerState(byte *data, int plrNum)
if(flags & PSF_PENDING_WEAPON)
{
pl->pendingWeapon = b & 0xf;
#if _DEBUG
Con_Message("NetCl_UpdatePlayerState: pendingweapon=%i\n", pl->pendingWeapon);
#endif
}

if(flags & PSF_READY_WEAPON)
{
pl->readyWeapon = b >> 4;

#if _DEBUG
Con_Message("NetCl_UpdatePlayerState: readyweapon=%i\n", pl->readyWeapon);
#endif
Expand Down Expand Up @@ -946,7 +948,7 @@ void NetCl_UpdateJumpPower(void *data)
* the clients position and angle may not be up to date when a ticcmd
* arrives.
*/
void NetCl_PlayerActionRequest(player_t *player, int actionType)
void NetCl_PlayerActionRequest(player_t *player, int actionType, int actionParam)
{
#define MSG_SIZE (28)

Expand Down Expand Up @@ -974,7 +976,14 @@ void NetCl_PlayerActionRequest(player_t *player, int actionType)
*ptr++ = LONG(FLT2FIX(player->plr->lookDir));

// Currently active weapon.
*ptr++ = LONG(player->readyWeapon);
if(actionType == GPA_CHANGE_WEAPON)
{
*ptr++ = LONG(actionParam);
}
else
{
*ptr++ = LONG(player->readyWeapon);
}

Net_SendPacket(DDSP_CONFIRM, GPT_ACTION_REQUEST, msg, MSG_SIZE);

Expand Down
8 changes: 6 additions & 2 deletions doomsday/plugins/common/src/d_netsv.c
Expand Up @@ -1411,9 +1411,9 @@ void NetSv_DoAction(int player, const char *data)

#ifdef _DEBUG
Con_Message("NetSv_DoAction: player=%i, type=%i, xyz=(%.1f,%.1f,%.1f)\n "
"angle=%x lookDir=%g\n",
"angle=%x lookDir=%g weapon=%i\n",
player, type, pos[VX], pos[VY], pos[VZ],
angle, lookDir);
angle, lookDir, readyWeapon);
#endif

if(pl->playerState == PST_DEAD)
Expand Down Expand Up @@ -1448,6 +1448,10 @@ void NetSv_DoAction(int player, const char *data)
P_FireWeapon(pl);
}
break;

case GPA_CHANGE_WEAPON:
pl->brain.changeWeapon = readyWeapon;
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_map.c
Expand Up @@ -2275,7 +2275,7 @@ void P_UseLines(player_t* player)
Con_Message("P_UseLines: Sending a use request for player %i.\n",
player - players);
#endif
NetCl_PlayerActionRequest(player, GPA_USE);
NetCl_PlayerActionRequest(player, GPA_USE, 0);
return;
}

Expand Down
21 changes: 15 additions & 6 deletions doomsday/plugins/common/src/p_user.c
Expand Up @@ -615,7 +615,7 @@ void P_DeathThink(player_t* player)
{
if(IS_CLIENT)
{
NetCl_PlayerActionRequest(player, GPA_USE);
NetCl_PlayerActionRequest(player, GPA_USE, 0);
}
else
{
Expand Down Expand Up @@ -1339,7 +1339,8 @@ void P_PlayerThinkWeapons(player_t* player)
#else
if(brain->changeWeapon != WT_NOCHANGE)
#endif
{ // Direct slot selection.
{
// Direct slot selection.
weapontype_t cand, first;

// Is this a same-slot weapon cycle?
Expand All @@ -1364,16 +1365,24 @@ void P_PlayerThinkWeapons(player_t* player)
first);
}
else if(brain->cycleWeapon)
{ // Linear cycle.
{
// Linear cycle.
newweapon = P_PlayerFindWeapon(player, brain->cycleWeapon < 0);
}

if(newweapon != WT_NOCHANGE && newweapon != player->readyWeapon)
{
if(weaponInfo[newweapon][player->class_].mode[0].gameModeBits
& gameModeBits)
if(weaponInfo[newweapon][player->class_].mode[0].gameModeBits & gameModeBits)
{
player->pendingWeapon = newweapon;
if(IS_CLIENT)
{
// Just send a request.
NetCl_PlayerActionRequest(player, GPA_CHANGE_WEAPON, newweapon);
}
else
{
player->pendingWeapon = newweapon;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jdoom/src/p_pspr.c
Expand Up @@ -157,7 +157,7 @@ void P_FireWeapon(player_t *player)
if(!P_CheckAmmo(player))
return;

NetCl_PlayerActionRequest(player, GPA_FIRE);
NetCl_PlayerActionRequest(player, GPA_FIRE, 0);

// Psprite state.
player->plr->pSprites[0].state = DDPSP_FIRE;
Expand Down

0 comments on commit d0fe1fa

Please sign in to comment.