mirror of
https://github.com/DarkflameUniverse/DarkflameServer
synced 2024-08-30 18:43:58 +00:00
push
This commit is contained in:
parent
10a2c24d5e
commit
48264e2cf4
@ -16,36 +16,6 @@
|
|||||||
#include "CDActivitiesTable.h"
|
#include "CDActivitiesTable.h"
|
||||||
#include "Metrics.hpp"
|
#include "Metrics.hpp"
|
||||||
|
|
||||||
// DON'T YOU DARE MERGE THIS WITH A GLOBAL I WANT TO TEST FAST
|
|
||||||
|
|
||||||
// The below query creates 2 derived tables
|
|
||||||
// The first is just a straight ranking of the leaderboard based on a provided ranking parameter.
|
|
||||||
// The second is a query that finds the ranking of the requested score
|
|
||||||
// The third and final query takes the score gotten above and gets the rankings as follows:.
|
|
||||||
// If the requested score is in the top 5, it will return the top 11 scores.
|
|
||||||
// If the requested score is in the bottom 5, it will return the bottom 11 scores.
|
|
||||||
// In all other cases, the second query will return the 5 scores above and below the requested score.
|
|
||||||
std::string myStandingsQueryBase =
|
|
||||||
"WITH leaderboardsRanked AS ("
|
|
||||||
" SELECT *,"
|
|
||||||
" RANK() OVER"
|
|
||||||
" ("
|
|
||||||
" ORDER BY score desc, streak, hitPercentage DESC"
|
|
||||||
" ) AS ranking"
|
|
||||||
" FROM leaderboard WHERE game_id = ?"
|
|
||||||
"),"
|
|
||||||
"myStanding AS ("
|
|
||||||
" SELECT ranking as myRank"
|
|
||||||
" FROM leaderboardsRanked"
|
|
||||||
" WHERE id = ? LIMIT 1"
|
|
||||||
")"
|
|
||||||
"SELECT * FROM leaderboardsRanked, myStanding, (SELECT MAX(leaderboardsRanked.ranking) AS lowestRank FROM leaderboardsRanked) AS lowestRanking"
|
|
||||||
"WHERE leaderboardsRanked.ranking BETWEEN"
|
|
||||||
"LEAST(GREATEST(myRank - 5, 1), lowestRanking.lowestRank - 10)"
|
|
||||||
"AND"
|
|
||||||
"LEAST(GREATEST(myRank + 5, 11), lowestRanking.lowestRank)"
|
|
||||||
"ORDER BY ranking ASC;";
|
|
||||||
|
|
||||||
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const Leaderboard::Type leaderboardType) {
|
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const Leaderboard::Type leaderboardType) {
|
||||||
this->gameID = gameID;
|
this->gameID = gameID;
|
||||||
this->weekly = weekly;
|
this->weekly = weekly;
|
||||||
@ -68,66 +38,60 @@ void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
|
|||||||
|
|
||||||
auto index = 0;
|
auto index = 0;
|
||||||
for (const auto& entry : entries) {
|
for (const auto& entry : entries) {
|
||||||
WriteLeaderboardRow(leaderboard, index, "CharacterID", eLDFType::LDF_TYPE_U64, entry.playerID);
|
|
||||||
WriteLeaderboardRow(leaderboard, index, "LastPlayed", eLDFType::LDF_TYPE_U64, entry.lastPlayed);
|
|
||||||
WriteLeaderboardRow(leaderboard, index, "NumPlayed", eLDFType::LDF_TYPE_S32, 1);
|
|
||||||
WriteLeaderboardRow(leaderboard, index, "name", eLDFType::LDF_TYPE_UTF_16, entry.playerName);
|
|
||||||
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_S32, entry.placement);
|
|
||||||
|
|
||||||
// Each minigame has its own "points" system
|
// Each minigame has its own "points" system
|
||||||
switch (leaderboardType) {
|
switch (leaderboardType) {
|
||||||
case Type::ShootingGallery:
|
case Type::ShootingGallery:
|
||||||
WriteLeaderboardRow(leaderboard, index, "HitPercentage", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
WriteLeaderboardRow(leaderboard, index, "HitPercentage", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
||||||
// HitPercentage:3 between 0 and 1
|
// HitPercentage:3 between 0 and 1
|
||||||
WriteLeaderboardRow(leaderboard, index, "Score", eLDFType::LDF_TYPE_S32, entry.score);
|
WriteLeaderboardRow(leaderboard, index, "Score", eLDFType::LDF_TYPE_S32, entry.score);
|
||||||
// Score:1
|
// Score:1
|
||||||
WriteLeaderboardRow(leaderboard, index, "Streak", eLDFType::LDF_TYPE_S32, 0);
|
WriteLeaderboardRow(leaderboard, index, "Streak", eLDFType::LDF_TYPE_S32, 0);
|
||||||
// Streak:1
|
// Streak:1
|
||||||
break;
|
break;
|
||||||
case Type::Racing:
|
case Type::Racing:
|
||||||
WriteLeaderboardRow(leaderboard, index, "BestLapTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
WriteLeaderboardRow(leaderboard, index, "BestLapTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
||||||
// BestLapTime:3
|
// BestLapTime:3
|
||||||
WriteLeaderboardRow(leaderboard, index, "BestTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
WriteLeaderboardRow(leaderboard, index, "BestTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
|
||||||
// BestTime:3
|
// BestTime:3
|
||||||
WriteLeaderboardRow(leaderboard, index, "License", eLDFType::LDF_TYPE_S32, 0);
|
WriteLeaderboardRow(leaderboard, index, "License", eLDFType::LDF_TYPE_S32, 0);
|
||||||
// License:1 - 1 if player has completed mission 637 and 0 otherwise
|
// License:1 - 1 if player has completed mission 637 and 0 otherwise
|
||||||
WriteLeaderboardRow(leaderboard, index, "NumWins", eLDFType::LDF_TYPE_S32, 0);
|
WriteLeaderboardRow(leaderboard, index, "NumWins", eLDFType::LDF_TYPE_S32, 0);
|
||||||
// NumWins:1
|
// NumWins:1
|
||||||
break;
|
break;
|
||||||
case Type::UnusedLeaderboard4:
|
case Type::UnusedLeaderboard4:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Points", eLDFType::LDF_TYPE_S32, entry.score);
|
WriteLeaderboardRow(leaderboard, index, "Points", eLDFType::LDF_TYPE_S32, entry.score);
|
||||||
// Points:1
|
// Points:1
|
||||||
break;
|
break;
|
||||||
case Type::MonumentRace:
|
case Type::MonumentRace:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
||||||
// Time:1(?)
|
// Time:1(?)
|
||||||
break;
|
break;
|
||||||
case Type::FootRace:
|
case Type::FootRace:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
||||||
// Time:1
|
// Time:1
|
||||||
break;
|
break;
|
||||||
case Type::Survival:
|
case Type::Survival:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Points", eLDFType::LDF_TYPE_S32, entry.score);
|
WriteLeaderboardRow(leaderboard, index, "Points", eLDFType::LDF_TYPE_S32, entry.score);
|
||||||
// Points:1
|
// Points:1
|
||||||
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
||||||
// Time:1
|
// Time:1
|
||||||
break;
|
break;
|
||||||
case Type::SurvivalNS:
|
case Type::SurvivalNS:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
|
||||||
// Time:1
|
// Time:1
|
||||||
WriteLeaderboardRow(leaderboard, index, "Wave", eLDFType::LDF_TYPE_S32, entry.score);
|
WriteLeaderboardRow(leaderboard, index, "Wave", eLDFType::LDF_TYPE_S32, entry.score);
|
||||||
// Wave:1
|
// Wave:1
|
||||||
break;
|
break;
|
||||||
case Type::Donations:
|
case Type::Donations:
|
||||||
WriteLeaderboardRow(leaderboard, index, "Score", eLDFType::LDF_TYPE_S32, entry.score);
|
WriteLeaderboardRow(leaderboard, index, "Score", eLDFType::LDF_TYPE_S32, entry.score);
|
||||||
// Score:1
|
// Score:1
|
||||||
// Something? idk yet.
|
// Something? idk yet.
|
||||||
break;
|
break;
|
||||||
case Type::None:
|
case Type::None:
|
||||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@ -137,9 +101,89 @@ void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Leaderboard::SetupLeaderboard() {
|
void Leaderboard::SetupLeaderboard() {
|
||||||
|
std::string queryBase =
|
||||||
|
"SELECT %s, character_id, UNIX_TIMESTAMP(last_played), charinfo.name as lastPlayed"
|
||||||
|
"FROM leaderboard JOIN charinfo"
|
||||||
|
"ON charinfo.id = leaderboard.character_id"
|
||||||
|
"WHERE game_id = ?"
|
||||||
|
"ORDER BY %s";
|
||||||
// Setup query based on activity.
|
// Setup query based on activity.
|
||||||
// Where clause will vary based on what query we are doing
|
// Where clause will vary based on what query we are doing
|
||||||
|
// Get base based on InfoType
|
||||||
|
// Fill in base with arguments based on leaderboard type
|
||||||
|
char queryBuffer[1024];
|
||||||
|
switch (leaderboardType) {
|
||||||
|
case Type::ShootingGallery:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "hitPercentage, score, streak", "score DESC, streak DESC, hitPercentage DESC");
|
||||||
|
break;
|
||||||
|
case Type::Racing:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "bestLapTime, bestTime, numWins", "bestTime ASC, bestLapTime ASC, numWins DESC");
|
||||||
|
break;
|
||||||
|
case Type::UnusedLeaderboard4:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "points", "points DESC");
|
||||||
|
break;
|
||||||
|
case Type::MonumentRace:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "time", "time ASC");
|
||||||
|
break;
|
||||||
|
case Type::FootRace:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "time", "time DESC");
|
||||||
|
break;
|
||||||
|
case Type::Survival:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "points, time", "points DESC, time DESC");
|
||||||
|
// If the config option default_survival_scoring is 1, reverse the order of the points and time columns
|
||||||
|
break;
|
||||||
|
case Type::SurvivalNS:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "time, wave", "time DESC, wave DESC");
|
||||||
|
break;
|
||||||
|
case Type::Donations:
|
||||||
|
snprintf(queryBuffer, 1024, queryBase.c_str(), "score", "score DESC");
|
||||||
|
break;
|
||||||
|
case Type::None:
|
||||||
|
Game::logger->Log("LeaderboardManager", "Attempting to get leaderboard for type none. Is this intended?");
|
||||||
|
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Game::logger->Log("LeaderboardManager", "filled in query is %s", queryBuffer);
|
||||||
|
// create and execute query here
|
||||||
|
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt(queryBuffer));
|
||||||
|
query->setInt(1, this->gameID);
|
||||||
|
std::unique_ptr<sql::ResultSet> result(query->executeQuery());
|
||||||
|
if (result->rowsCount() == 0) return;
|
||||||
|
|
||||||
|
uint32_t myRanking = 1;
|
||||||
|
uint32_t myCharacterId = 0;
|
||||||
|
// Find my ranking in the leaderboard
|
||||||
|
while (result->next()) {
|
||||||
|
if (result->getInt("character_id") != myCharacterId) myRanking++;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
// Once you've found my ranking, figure out if we need to adjust the
|
||||||
|
// row pointer to get the top 11 or the bottom 11.
|
||||||
|
|
||||||
|
int32_t lowestRanking = result->rowsCount() - 5;
|
||||||
|
if (lowestRanking > 0 && myRanking >= lowestRanking) { // I am in the bottom 10, so set row pointer back to the top of the bottom 6
|
||||||
|
for (uint32_t i = myRanking - lowestRanking; i > lowestRanking; i--) {
|
||||||
|
result->previous();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t startRanking = 1; // Default to top 11
|
||||||
|
if (myRanking >= 6) startRanking = myRanking - 5; // If i am not in the top 5, set row pointer to 5 above my ranking
|
||||||
|
else if (myRanking > result->rowsCount()) { // If i am in the bottom 10, set the row pointer to the top of the bottom 11
|
||||||
|
startRanking = result->rowsCount() - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = myRanking - 5; i > 0; i--) { // Adjust first row gotten to be 5 above my ranking.
|
||||||
|
result->previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 11; i > 0; i--) {
|
||||||
|
this->entries.push_back(LDFData<uint64_t>(u"CharacterID", result->getInt("character_id")));
|
||||||
|
this->entries.push_back(LDFData<uint64_t>(u"LastPlayed", result->getUInt64("lastPlayed")));
|
||||||
|
this->entries.push_back(LDFData<int32_t>(u"NumPlayed", 1));
|
||||||
|
this->entries.push_back(LDFData<std::u16string>(u"name", GeneralUtils::ASCIIToUTF16(result->getString("name").c_str())));
|
||||||
|
this->entries.push_back(LDFData<int32_t>(u"RowNumber", startRanking + i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Leaderboard::Send(LWOOBJID targetID) const {
|
void Leaderboard::Send(LWOOBJID targetID) const {
|
||||||
@ -166,70 +210,70 @@ std::string FormatInsert(const char* columns, const char* format, va_list args)
|
|||||||
return finishedQuery;
|
return finishedQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Leaderboard::Type leaderboardType, va_list args){
|
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Leaderboard::Type leaderboardType, va_list args) {
|
||||||
std::string insertStatement;
|
std::string insertStatement;
|
||||||
// use replace into to update the score if it already exists instead of needing an update and an insert
|
// use replace into to update the score if it already exists instead of needing an update and an insert
|
||||||
switch (leaderboardType) {
|
switch (leaderboardType) {
|
||||||
case Leaderboard::Type::ShootingGallery: {
|
case Leaderboard::Type::ShootingGallery: {
|
||||||
// Check that the score exists and is better. If the score is better update it.
|
// Check that the score exists and is better. If the score is better update it.
|
||||||
// If the score is the same but the streak is better, update it.
|
// If the score is the same but the streak is better, update it.
|
||||||
// If the score is the same and the streak is the same but the hit percentage is better, update it.
|
// If the score is the same and the streak is the same but the hit percentage is better, update it.
|
||||||
// If the score doesn't exist, insert it.
|
// If the score doesn't exist, insert it.
|
||||||
auto lookup = Database::CreatePreppedStmt("SELECT score, streak, hitPercentage FROM leaderboard WHERE playerID = ? AND gameID = ?");
|
auto lookup = Database::CreatePreppedStmt("SELECT score, streak, hitPercentage FROM leaderboard WHERE playerID = ? AND gameID = ?");
|
||||||
lookup->setInt64(1, playerID);
|
lookup->setInt64(1, playerID);
|
||||||
lookup->setInt(2, gameID);
|
lookup->setInt(2, gameID);
|
||||||
auto lookupResult = lookup->executeQuery();
|
auto lookupResult = lookup->executeQuery();
|
||||||
if (lookupResult->next()) {
|
if (lookupResult->next()) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
auto result = FormatInsert("hitPercentage, score, streak", "%f, %i, %i", args);
|
auto result = FormatInsert("hitPercentage, score, streak", "%f, %i, %i", args);
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::Racing: {
|
|
||||||
auto result = FormatInsert("bestLapTime, bestTime", "%f, %f", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::UnusedLeaderboard4: {
|
|
||||||
auto result = FormatInsert("points", "%i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::MonumentRace: {
|
|
||||||
auto result = FormatInsert("time", "%i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::FootRace: {
|
|
||||||
auto result = FormatInsert("time", "%i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::Survival: {
|
|
||||||
auto result = FormatInsert("points, time", "%i, %i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::SurvivalNS: {
|
|
||||||
auto result = FormatInsert("time, wave", "%i, %i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::Donations: {
|
|
||||||
auto result = FormatInsert("score", "%i", args);
|
|
||||||
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Leaderboard::Type::None: {
|
|
||||||
Game::logger->Log("LeaderboardManager", "Warning: Saving leaderboard of type None. Are you sure this is intended?");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
Game::logger->Log("LeaderboardManager", "Unknown leaderboard type %i. Cannot save score!", leaderboardType);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::Racing: {
|
||||||
|
auto result = FormatInsert("bestLapTime, bestTime", "%f, %f", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::UnusedLeaderboard4: {
|
||||||
|
auto result = FormatInsert("points", "%i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::MonumentRace: {
|
||||||
|
auto result = FormatInsert("time", "%i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::FootRace: {
|
||||||
|
auto result = FormatInsert("time", "%i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::Survival: {
|
||||||
|
auto result = FormatInsert("points, time", "%i, %i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::SurvivalNS: {
|
||||||
|
auto result = FormatInsert("time, wave", "%i, %i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::Donations: {
|
||||||
|
auto result = FormatInsert("score", "%i", args);
|
||||||
|
Game::logger->Log("LeaderboardManager", "%s", result.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Leaderboard::Type::None: {
|
||||||
|
Game::logger->Log("LeaderboardManager", "Warning: Saving leaderboard of type None. Are you sure this is intended?");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
Game::logger->Log("LeaderboardManager", "Unknown leaderboard type %i. Cannot save score!", leaderboardType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,15 @@ typedef uint32_t GameID;
|
|||||||
|
|
||||||
class Leaderboard {
|
class Leaderboard {
|
||||||
public:
|
public:
|
||||||
struct Entry {
|
// struct Entry {
|
||||||
LWOOBJID playerID;
|
// LWOOBJID playerID;
|
||||||
uint32_t time;
|
// uint32_t time;
|
||||||
uint32_t score;
|
// uint32_t score;
|
||||||
uint32_t placement;
|
// uint32_t placement;
|
||||||
time_t lastPlayed;
|
// time_t lastPlayed;
|
||||||
std::string playerName;
|
// std::string playerName;
|
||||||
};
|
// };
|
||||||
typedef std::vector<Entry> LeaderboardEntries;
|
typedef std::vector<LDFBaseData> LeaderboardEntries;
|
||||||
|
|
||||||
// Enums for leaderboards
|
// Enums for leaderboards
|
||||||
enum InfoType : uint32_t {
|
enum InfoType : uint32_t {
|
||||||
@ -76,7 +76,7 @@ public:
|
|||||||
* Adds a new entry to the leaderboard
|
* Adds a new entry to the leaderboard
|
||||||
* Used for debug only!
|
* Used for debug only!
|
||||||
*/
|
*/
|
||||||
void AddEntry(Entry entry) { entries.push_back(entry); }
|
void AddEntry(LDFBaseData& entry) { entries.push_back(entry); }
|
||||||
private:
|
private:
|
||||||
template<class TypeToWrite>
|
template<class TypeToWrite>
|
||||||
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, const std::string& key, const eLDFType& ldfType, const TypeToWrite& value) const;
|
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, const std::string& key, const eLDFType& ldfType, const TypeToWrite& value) const;
|
||||||
|
@ -35,10 +35,11 @@ protected:
|
|||||||
void RunTests(Leaderboard::Type type) {
|
void RunTests(Leaderboard::Type type) {
|
||||||
Game::logger->Log("LeaderboardTests", "Testing leaderboard %i for Serialize speed", type);
|
Game::logger->Log("LeaderboardTests", "Testing leaderboard %i for Serialize speed", type);
|
||||||
Leaderboard leaderboard(0, Leaderboard::InfoType::Top, false, type);
|
Leaderboard leaderboard(0, Leaderboard::InfoType::Top, false, type);
|
||||||
TestLeaderboard(leaderboard, 1);
|
leaderboard.SetupLeaderboard();
|
||||||
TestLeaderboard(leaderboard, 10);
|
// TestLeaderboard(leaderboard, 1);
|
||||||
TestLeaderboard(leaderboard, 100);
|
// TestLeaderboard(leaderboard, 10);
|
||||||
TestLeaderboard(leaderboard, 1000);
|
// TestLeaderboard(leaderboard, 100);
|
||||||
|
// TestLeaderboard(leaderboard, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBITSTREAM;
|
CBITSTREAM;
|
||||||
@ -77,20 +78,20 @@ protected:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TEST_F(LeaderboardTests, LeaderboardSpeedTest) {
|
TEST_F(LeaderboardTests, LeaderboardSpeedTest) {
|
||||||
// RunTests(Leaderboard::Type::ShootingGallery);
|
RunTests(Leaderboard::Type::ShootingGallery);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::ShootingGallery, 3, 3000, 15.0f, 100);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::ShootingGallery, 3, 3000, 15.0f, 100);
|
||||||
// RunTests(Leaderboard::Type::Racing);
|
RunTests(Leaderboard::Type::Racing);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Racing, 2, 260.0f, 250.0f);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Racing, 2, 260.0f, 250.0f);
|
||||||
// RunTests(Leaderboard::Type::MonumentRace);
|
RunTests(Leaderboard::Type::MonumentRace);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::MonumentRace, 1, 150);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::MonumentRace, 1, 150);
|
||||||
// RunTests(Leaderboard::Type::FootRace);
|
RunTests(Leaderboard::Type::FootRace);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::FootRace, 1, 150);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::FootRace, 1, 150);
|
||||||
// RunTests(Leaderboard::Type::UnusedLeaderboard4);
|
RunTests(Leaderboard::Type::UnusedLeaderboard4);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::UnusedLeaderboard4, 1, 100);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::UnusedLeaderboard4, 1, 100);
|
||||||
// RunTests(Leaderboard::Type::Survival);
|
RunTests(Leaderboard::Type::Survival);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Survival, 2, 3000, 15);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Survival, 2, 3000, 15);
|
||||||
// RunTests(Leaderboard::Type::SurvivalNS);
|
RunTests(Leaderboard::Type::SurvivalNS);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::SurvivalNS, 2, 300, 15);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::SurvivalNS, 2, 300, 15);
|
||||||
// RunTests(Leaderboard::Type::Donations);
|
RunTests(Leaderboard::Type::Donations);
|
||||||
LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Donations, 1, 300000);
|
// LeaderboardManager::Instance().SaveScore(0, 0, Leaderboard::Type::Donations, 1, 300000);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user