Get it compiling, add a test and optimize heavily

This commit is contained in:
David Markowitz
2023-04-13 00:45:03 -07:00
parent c02963013b
commit c91f0d16b3
9 changed files with 125 additions and 42 deletions

View File

@@ -10,9 +10,10 @@
#include "CDClientManager.h"
#include "GeneralUtils.h"
#include "Entity.h"
#include <sstream>
#include "CDActivitiesTable.h"
#include "Metrics.hpp"
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const Leaderboard::Type leaderboardType) {
this->relatedPlayer = relatedPlayer;
this->gameID = gameID;
@@ -22,39 +23,35 @@ Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoTy
this->leaderboardType = leaderboardType;
}
bool Leaderboard::IsScoreBetter(const uint32_t score) const {
}
void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
std::string leaderboard;
std::ostringstream leaderboard;
leaderboard += "ADO.Result=7:1\n";
leaderboard += "Result.Count=1:1\n";
leaderboard += "Result[0].Index=0:RowNumber\n";
leaderboard += "Result[0].RowCount=1:" + std::to_string(entries.size()) + "\n";
leaderboard << "ADO.Result=7:1\n"; // Unused in 1.10.64, but is in captures
leaderboard << "Result.Count=1:1\n"; // number of results, always 1?
leaderboard << "Result[0].Index=0:RowNumber\n"; // "Primary key"
leaderboard << "Result[0].RowCount=1:" << entries.size() << '\n'; // number of rows
auto index = 0;
for (const auto& entry : entries) {
leaderboard += "Result[0].Row[" + std::to_string(index) + "].LastPlayed=8:" + std::to_string(entry.lastPlayed) + "\n";
leaderboard += "Result[0].Row[" + std::to_string(index) + "].CharacterID=8:" + std::to_string(entry.playerID) + "\n";
leaderboard += "Result[0].Row[" + std::to_string(index) + "].NumPlayed=1:1\n";
leaderboard += "Result[0].Row[" + std::to_string(index) + "].RowNumber=8:" + std::to_string(entry.placement) + "\n";
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Time=1:" + std::to_string(entry.time) + "\n";
leaderboard << "Result[0].Row[" << index << "].LastPlayed=8:" << entry.lastPlayed << '\n';
leaderboard << "Result[0].Row[" << index << "].CharacterID=8:" << entry.playerID << '\n';
leaderboard << "Result[0].Row[" << index << "].NumPlayed=1:1\n"; // number of times the activity was played
leaderboard << "Result[0].Row[" << index << "].RowNumber=8:" << entry.placement << '\n';
leaderboard << "Result[0].Row[" << index << "].Time=1:" << entry.time << '\n';
// Only these minigames have a points system
if (leaderboardType == Survival || leaderboardType == ShootingGallery) {
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Points=1:" + std::to_string(entry.score) + "\n";
leaderboard << "Result[0].Row[" << index << "].Points=1:"<< entry.score << '\n';
} else if (leaderboardType == SurvivalNS) {
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Wave=1:" + std::to_string(entry.score) + "\n";
leaderboard << "Result[0].Row[" << index << "].Wave=1:"<< entry.score << '\n';
}
leaderboard += "Result[0].Row[" + std::to_string(index) + "].name=0:" + entry.playerName + "\n";
leaderboard << "Result[0].Row[" << index << "].name=0:" << entry.playerName << '\n';
index++;
}
// Serialize the thing to a BitStream
bitStream->WriteAlignedBytes((const unsigned char*)leaderboard.c_str(), leaderboard.size());
bitStream->Write(leaderboard.str().c_str(), leaderboard.tellp());
}
void Leaderboard::SetupLeaderboard() {

View File

@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <climits>
#include <map>
#include <vector>
#include "Singleton.h"
#include "dCommonVars.h"
@@ -14,7 +15,7 @@ typedef uint32_t GameID;
class Leaderboard {
public:
struct Entry {
uint64_t playerID;
LWOOBJID playerID;
uint32_t time;
uint32_t score;
uint32_t placement;
@@ -56,7 +57,7 @@ public:
* @return true
* @return false
*/
bool IsScoreBetter(const uint32_t score) const;
bool IsScoreBetter(const uint32_t score) const { return false; };
/**
* Builds the leaderboard from the database based on the associated gameID
@@ -67,6 +68,12 @@ public:
* Sends the leaderboard to the client specified by targetID.
*/
void Send(LWOOBJID targetID) const;
/**
* Adds a new entry to the leaderboard
* Used for debug only!
*/
void AddEntry(Entry entry) { entries.push_back(entry); }
private:
LeaderboardEntries entries;
LWOOBJID relatedPlayer;

View File

@@ -1630,17 +1630,17 @@ void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID,
bitStream.Write(objectID);
bitStream.Write(GAME_MSG::GAME_MSG_SEND_ACTIVITY_SUMMARY_LEADERBOARD_DATA);
bitStream.Write(leaderboard->GetGameID());
bitStream.Write(leaderboard->GetInfoType());
throw "";
//bitStream.Write(leaderboard->GetGameID());
//bitStream.Write(leaderboard->GetInfoType());
// Leaderboard is written back as LDF string
const auto leaderboardString = leaderboard->ToString();
bitStream.Write<uint32_t>(leaderboardString.size());
for (const auto c : leaderboardString) {
bitStream.Write<uint16_t>(c);
}
if (!leaderboardString.empty()) bitStream.Write(uint16_t(0));
//const auto leaderboardString = leaderboard->ToString();
//bitStream.Write<uint32_t>(leaderboardString.size());
//for (const auto c : leaderboardString) {
// bitStream.Write<uint16_t>(c);
//}
//if (!leaderboardString.empty()) bitStream.Write(uint16_t(0));
bitStream.Write0();
bitStream.Write0();
@@ -1666,9 +1666,9 @@ void GameMessages::HandleRequestActivitySummaryLeaderboardData(RakNet::BitStream
bool weekly = inStream->ReadBit();
const auto* leaderboard = LeaderboardManager::GetLeaderboard(gameID, (InfoType)queryType, weekly, entity->GetObjectID());
SendActivitySummaryLeaderboardData(entity->GetObjectID(), leaderboard, sysAddr);
delete leaderboard;
//const auto* leaderboard = LeaderboardManager::GetLeaderboard(gameID, (InfoType)queryType, weekly, entity->GetObjectID());
//SendActivitySummaryLeaderboardData(entity->GetObjectID(), leaderboard, sysAddr);
//delete leaderboard;
}
void GameMessages::HandleActivityStateChangeRequest(RakNet::BitStream* inStream, Entity* entity) {