Skip to content

Commit

Permalink
chore: Convert LeaderboardManager to use BitStream refs (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadebenn authored Feb 27, 2024
1 parent 27d20dd commit 9e0dd05
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions dGame/LeaderboardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t&
leaderboard << "\nResult[0].Row[" << index << "]." << data->GetString();
}

void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
bitStream->Write(gameID);
bitStream->Write(infoType);
void Leaderboard::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(gameID);
bitStream.Write(infoType);

std::ostringstream leaderboard;

Expand All @@ -64,12 +64,12 @@ void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {

// Serialize the thing to a BitStream
uint32_t leaderboardSize = leaderboard.tellp();
bitStream->Write<uint32_t>(leaderboardSize);
bitStream.Write<uint32_t>(leaderboardSize);
// Doing this all in 1 call so there is no possbility of a dangling pointer.
bitStream->WriteAlignedBytes(reinterpret_cast<const unsigned char*>(GeneralUtils::ASCIIToUTF16(leaderboard.str()).c_str()), leaderboardSize * sizeof(char16_t));
if (leaderboardSize > 0) bitStream->Write<uint16_t>(0);
bitStream->Write0();
bitStream->Write0();
bitStream.WriteAlignedBytes(reinterpret_cast<const unsigned char*>(GeneralUtils::ASCIIToUTF16(leaderboard.str()).c_str()), leaderboardSize * sizeof(char16_t));
if (leaderboardSize > 0) bitStream.Write<uint16_t>(0);
bitStream.Write0();
bitStream.Write0();
}

void Leaderboard::QueryToLdf(std::unique_ptr<sql::ResultSet>& rows) {
Expand Down
2 changes: 1 addition & 1 deletion dGame/LeaderboardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Leaderboard {
*
* Expensive! Leaderboards are very string intensive so be wary of performatnce calling this method.
*/
void Serialize(RakNet::BitStream* bitStream) const;
void Serialize(RakNet::BitStream& bitStream) const;

/**
* Builds the leaderboard from the database based on the associated gameID
Expand Down
2 changes: 1 addition & 1 deletion dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID,
bitStream.Write(objectID);
bitStream.Write(eGameMessageType::SEND_ACTIVITY_SUMMARY_LEADERBOARD_DATA);

leaderboard->Serialize(&bitStream);
leaderboard->Serialize(bitStream);
SEND_PACKET;
}

Expand Down

0 comments on commit 9e0dd05

Please sign in to comment.