Skip to content

Commit

Permalink
Fixed|Multiplayer: Server sends total kill, item and secret counts
Browse files Browse the repository at this point in the history
The client was unaware of the map's total kill, item and secret counts,
as clients do not spawn mobjs when the map is loaded. Now the total
counts are sent, allowing the clients to show correct statistics during
intermission.
  • Loading branch information
skyjake committed Mar 16, 2013
1 parent 2015678 commit e046632
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doomsday/plugins/common/include/d_net.h
Expand Up @@ -78,7 +78,8 @@ enum {
GPT_FLOOR_HIT_REQUEST,
GPT_MAYBE_CHANGE_WEAPON, // Server suggests weapon change.
GPT_FINALE_STATE, // State of the InFine script.
GPT_LOCAL_MOBJ_STATE // Set a state on a mobj and enable local actions.
GPT_LOCAL_MOBJ_STATE, // Set a state on a mobj and enable local actions.
GPT_TOTAL_COUNTS // Total kill, item, secret counts in the map.
};

#if 0
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/include/d_netcl.h
Expand Up @@ -27,6 +27,7 @@

void NetCl_UpdateGameState(Reader* msg);
void NetCl_PlayerSpawnPosition(Reader* msg);
void NetCl_UpdateTotalCounts(Reader *msg);
void NetCl_UpdatePlayerState(Reader* msg, int plrNum);
void NetCl_UpdatePlayerState2(Reader* msg, int plrNum);
void NetCl_UpdatePSpriteState(Reader* msg);
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/include/d_netsv.h
Expand Up @@ -38,6 +38,7 @@ void P_Telefrag(mobj_t* thing);
void NetSv_NewPlayerEnters(int plrNum);
void NetSv_ResetPlayerFrags(int plrNum);
void NetSv_SendGameState(int flags, int to);
void NetSv_SendTotalCounts(int to);
void NetSv_SendPlayerSpawnPosition(int plrNum, float x, float y, float z, int angle);
void NetSv_SendMessage(int plrNum, const char *msg);
void NetSv_SendYellowMessage(int plrNum, const char *msg);
Expand Down
4 changes: 4 additions & 0 deletions doomsday/plugins/common/src/d_net.c
Expand Up @@ -489,6 +489,10 @@ void D_HandlePacket(int fromplayer, int type, void *data, size_t length)
NetCl_PlayerSpawnPosition(reader);
break;

case GPT_TOTAL_COUNTS:
NetCl_UpdateTotalCounts(reader);
break;

case GPT_MOBJ_IMPULSE:
NetCl_MobjImpulse(reader);
break;
Expand Down
14 changes: 14 additions & 0 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -1065,3 +1065,17 @@ void NetCl_DamageRequest(mobj_t* target, mobj_t* inflictor, mobj_t* source, int

Net_SendPacket(0, GPT_DAMAGE_REQUEST, Writer_Data(msg), Writer_Size(msg));
}

void NetCl_UpdateTotalCounts(Reader *msg)
{
#ifndef __JHEXEN__
totalKills = Reader_ReadInt32(msg);
totalItems = Reader_ReadInt32(msg);
totalSecret = Reader_ReadInt32(msg);

#ifdef _DEBUG
Con_Message("NetCl_UpdateTotalCounts: kills=%i, items=%i, secrets=%i",
totalKills, totalItems, totalSecret);
#endif
#endif
}
24 changes: 23 additions & 1 deletion doomsday/plugins/common/src/d_netsv.c
Expand Up @@ -647,6 +647,7 @@ void NetSv_NewPlayerEnters(int plrNum)
P_Telefrag(plr->plr->mo);

NetSv_TellCycleRulesToPlayerAfterTics(plrNum, 5 * TICSPERSEC);
NetSv_SendTotalCounts(plrNum);
}

void NetSv_Intermission(int flags, int state, int time)
Expand Down Expand Up @@ -675,7 +676,7 @@ void NetSv_Intermission(int flags, int state, int time)
if(flags & IMF_BEGIN)
{
Writer_WriteByte(msg, state); // LeaveMap
Writer_WriteByte(msg, time); // LeavePosition
Writer_WriteByte(msg, time); // LeavePosition
}
#endif

Expand Down Expand Up @@ -732,6 +733,27 @@ void NetSv_Finale(int flags, const char* script, const boolean* conds, byte numC
}
#endif

void NetSv_SendTotalCounts(int to)
{
// Hexen does not have total counts.
#ifndef __JHEXEN__
Writer *writer = 0;

if(IS_CLIENT)
return;

writer = D_NetWrite();
Writer_WriteInt32(writer, totalKills);
Writer_WriteInt32(writer, totalItems);
Writer_WriteInt32(writer, totalSecret);

// Send the packet.
Net_SendPacket(to, GPT_TOTAL_COUNTS, Writer_Data(writer), Writer_Size(writer));
#else
DENG_UNUSED(to);
#endif
}

void NetSv_SendGameState(int flags, int to)
{
int i;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/plugins/common/src/p_mapsetup.c
Expand Up @@ -785,7 +785,10 @@ void P_SetupMap(Uri* mapUri, uint episode, uint map)
}

if(IS_SERVER)
{
R_SetAllDoomsdayFlags();
NetSv_SendTotalCounts(DDSP_ALL_PLAYERS);
}

P_FinalizeMap();

Expand Down

0 comments on commit e046632

Please sign in to comment.