Skip to content

Commit

Permalink
multijoin / multistat: Avoid unnecessary copies
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 11, 2023
1 parent aaa5ff1 commit be9fc1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/multijoin.cpp
Expand Up @@ -542,7 +542,7 @@ bool MultiPlayerJoin(UDWORD playerIndex)
{
if (NetPlay.players[i].allocated)
{
setMultiStats(i, getMultiStats(i), false);
sendMultiStats(i);
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/multistat.cpp
Expand Up @@ -220,10 +220,19 @@ bool swapPlayerMultiStatsLocal(uint32_t playerIndexA, uint32_t playerIndexB)
return true;
}

static bool sendMultiStats(uint32_t playerIndex)
bool sendMultiStats(uint32_t playerIndex, optional<uint32_t> recipientPlayerIndex /*= nullopt*/)
{
NETQUEUE queue;
if (!recipientPlayerIndex.has_value())
{
queue = NETbroadcastQueue();
}
else
{
queue = NETnetQueue(recipientPlayerIndex.value());
}
// Now send it to all other players
NETbeginEncode(NETbroadcastQueue(), NET_PLAYER_STATS);
NETbeginEncode(queue, NET_PLAYER_STATS);
// Send the ID of the player's stats we're updating
NETuint32_t(&playerIndex);

Expand Down
3 changes: 2 additions & 1 deletion src/multistat.h
Expand Up @@ -89,7 +89,8 @@ struct RESEARCH;
bool saveMultiStats(const char *sFName, const char *sPlayerName, const PLAYERSTATS *playerStats); // to disk
bool loadMultiStats(char *sPlayerName, PLAYERSTATS *playerStats); // form disk
PLAYERSTATS const &getMultiStats(UDWORD player); // get from net
bool setMultiStats(uint32_t player, PLAYERSTATS plStats, bool bLocal); // send to net.
bool setMultiStats(uint32_t player, PLAYERSTATS plStats, bool bLocal); // set + send to net.
bool sendMultiStats(uint32_t playerIndex, optional<uint32_t> recipientPlayerIndex = nullopt); // send to net
bool sendMultiStatsScoreUpdates(uint32_t player);
void updateMultiStatsDamage(UDWORD attacker, UDWORD defender, UDWORD inflicted);
void updateMultiStatsGames();
Expand Down

0 comments on commit be9fc1c

Please sign in to comment.