Improve a bit the performance by using Login instead of Account Id

This commit is contained in:
Beu 2023-07-10 18:09:00 +02:00
parent bd358b7acb
commit 3cabb3bce9

View File

@ -183,7 +183,7 @@ declare Integer Map_NextMalusPreparationTime;
declare Integer Map_MalusDuration; declare Integer Map_MalusDuration;
declare Integer Map_RoundsPerMap; declare Integer Map_RoundsPerMap;
declare Text[] AccountIdsOfPlayers for This = []; declare Text[] LoginsOfPlayers for This = [];
declare Integer LandmarkIndex for This = 0; declare Integer LandmarkIndex for This = 0;
declare Integer[Text] CustomTimes for This = []; declare Integer[Text] CustomTimes for This = [];
declare K_Malus[Text] MalusQueue; declare K_Malus[Text] MalusQueue;
@ -273,11 +273,11 @@ MalusQueue = [];
// Spawn players for the race // Spawn players for the race
---Rounds_CanSpawn--- ---Rounds_CanSpawn---
declare Text[] AccountIdsOfPlayers for This = []; declare Text[] LoginsOfPlayers for This = [];
declare CMapLandmark PlayerLM; declare CMapLandmark PlayerLM;
declare Integer LandmarkIndex for This = 0; declare Integer LandmarkIndex for This = 0;
AccountIdsOfPlayers = []; LoginsOfPlayers = [];
// Suffle Players list to randomise spawn // Suffle Players list to randomise spawn
declare CSmPlayer[] ShuffledPlayers = Players; declare CSmPlayer[] ShuffledPlayers = Players;
@ -307,11 +307,11 @@ foreach (Player in ShuffledPlayers) {
LandmarkIndex = LandmarkIndex + 1 ; LandmarkIndex = LandmarkIndex + 1 ;
} }
Race::Start(Player, PlayerLM , StartTime); Race::Start(Player, PlayerLM , StartTime);
AccountIdsOfPlayers.add(Player.User.WebServicesUserId); LoginsOfPlayers.add(Player.User.Login);
MalusQueue[Player.User.WebServicesUserId] = GetNewMalus(C_Malus_Reset, 1500); MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Reset, 1500);
} }
Net_NBPlayers = AccountIdsOfPlayers.count; Net_NBPlayers = LoginsOfPlayers.count;
UpdateCustomRanking(Null, -1); UpdateCustomRanking(Null, -1);
StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]); StateMgr::ForcePlayersStates([StateMgr::C_State_Playing]);
@ -332,7 +332,7 @@ MalusQueue = [];
if (!RankInitialized) { if (!RankInitialized) {
RankInitialized = True; RankInitialized = True;
Net_PlayersNbAlive = PlayersNbAlive; Net_PlayersNbAlive = PlayersNbAlive;
Net_NBPlayers = AccountIdsOfPlayers.count; Net_NBPlayers = LoginsOfPlayers.count;
foreach (Player in Players) { foreach (Player in Players) {
CarRank::SetRank(Player, PlayersNbAlive); CarRank::SetRank(Player, PlayersNbAlive);
} }
@ -345,7 +345,7 @@ if (Now < StartTime + 3000) {
declare CMapLandmark PlayerLM = Null; declare CMapLandmark PlayerLM = Null;
if (PlayersNbDead >= 1) { if (PlayersNbDead >= 1) {
foreach (Player in Players) { foreach (Player in Players) {
if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && !AccountIdsOfPlayers.exists(Player.User.WebServicesUserId)) { if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && !LoginsOfPlayers.exists(Player.User.Login)) {
PlayerSpawned = True; PlayerSpawned = True;
PlayerLM = Null; PlayerLM = Null;
while (PlayerLM == Null) { while (PlayerLM == Null) {
@ -358,15 +358,15 @@ if (Now < StartTime + 3000) {
LandmarkIndex = LandmarkIndex + 1 ; LandmarkIndex = LandmarkIndex + 1 ;
} }
Race::Start(Player, PlayerLM , StartTime); Race::Start(Player, PlayerLM , StartTime);
AccountIdsOfPlayers.add(Player.User.WebServicesUserId); LoginsOfPlayers.add(Player.User.Login);
MalusQueue[Player.User.WebServicesUserId] = GetNewMalus(C_Malus_Reset); MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Reset);
} }
} }
} }
if (PlayerSpawned) { if (PlayerSpawned) {
PlayerSpawned = False; PlayerSpawned = False;
Net_NBPlayers = AccountIdsOfPlayers.count; Net_NBPlayers = LoginsOfPlayers.count;
Net_PlayersNbAlive = PlayersNbAlive; Net_PlayersNbAlive = PlayersNbAlive;
UpdateCustomRanking(Null, -1); UpdateCustomRanking(Null, -1);
foreach (Player in Players) { foreach (Player in Players) {
@ -412,7 +412,7 @@ foreach (Event in PendingEvents) {
Events::Invalid(Event); Events::Invalid(Event);
} }
if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player if (PlayersNbAlive <= 1 && LoginsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player
Net_TimeBeforeMalus = -1; Net_TimeBeforeMalus = -1;
MB_StopRound(); MB_StopRound();
} }
@ -468,7 +468,7 @@ if (Players.count > 0 && S_MalusDuration > 0 && MalusTime != -1 && Now > MalusTi
Net_TimeBeforeMalus = NextStepMalusTime; Net_TimeBeforeMalus = NextStepMalusTime;
} else if (PendingMalus && !ActiveMalus) { } else if (PendingMalus && !ActiveMalus) {
foreach (Player in Players) { foreach (Player in Players) {
MalusQueue[Player.User.WebServicesUserId] = GetNewMalus(MalusIndex); MalusQueue[Player.User.Login] = GetNewMalus(MalusIndex);
} }
PendingMalus = False; PendingMalus = False;
ActiveMalus = True; ActiveMalus = True;
@ -483,7 +483,7 @@ if (Players.count > 0 && S_MalusDuration > 0 && MalusTime != -1 && Now > MalusTi
} else if (!PendingMalus && ActiveMalus) { } else if (!PendingMalus && ActiveMalus) {
if (MalusIndex != 99) { if (MalusIndex != 99) {
foreach (Player in Players) { foreach (Player in Players) {
MalusQueue[Player.User.WebServicesUserId] = GetNewMalus(C_Malus_Reset); MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Reset);
} }
PendingMalus = False; PendingMalus = False;
ActiveMalus = False; ActiveMalus = False;
@ -498,7 +498,7 @@ if (Players.count > 0 && S_MalusDuration > 0 && MalusTime != -1 && Now > MalusTi
Net_TimeBeforeMalus = NextStepMalusTime; Net_TimeBeforeMalus = NextStepMalusTime;
} else { } else {
foreach (Player in Players) { foreach (Player in Players) {
MalusQueue[Player.User.WebServicesUserId] = GetNewMalus(C_Malus_Nightmare); MalusQueue[Player.User.Login] = GetNewMalus(C_Malus_Nightmare);
} }
NextStepMalusTime = Now + (S_MalusDuration*1000); NextStepMalusTime = Now + (S_MalusDuration*1000);
} }
@ -506,14 +506,14 @@ if (Players.count > 0 && S_MalusDuration > 0 && MalusTime != -1 && Now > MalusTi
} }
} }
foreach (AccountId => Malus in MalusQueue) { foreach (Login => Malus in MalusQueue) {
declare CSmPlayer Player = ModeUtils::GetPlayerFromAccountId(AccountId); declare CSmPlayer Player = GetPlayer(Login);
if (Malus.Time + 1000 < Now) { // Clear old entry if (Malus.Time + 1000 < Now) { // Clear old entry
MalusQueue.removekey(AccountId); MalusQueue.removekey(Login);
} else if (Player != Null && Malus.Time <= Now && (Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned || Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawning)) { } else if (Player != Null && Malus.Time <= Now && (Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned || Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawning)) {
Log::Log("[ApplyPhysics] Trying to set Event " ^ C_Malus_Name[Malus.MalusIndex] ^ " for " ^ Player.User.Name); Log::Log("[ApplyPhysics] Trying to set Event " ^ C_Malus_Name[Malus.MalusIndex] ^ " for " ^ Player.User.Name);
if (SetMalus(Player, Malus.MalusIndex)) { if (SetMalus(Player, Malus.MalusIndex)) {
MalusQueue.removekey(AccountId); MalusQueue.removekey(Login);
} }
} }
} }
@ -546,7 +546,7 @@ if (Round_ForceEndRound || Round_SkipPauseRound) {
declare CSmScore WinnerScore <=> Scores::GetBestPlayer(Scores::C_Sort_RoundPoints); declare CSmScore WinnerScore <=> Scores::GetBestPlayer(Scores::C_Sort_RoundPoints);
if (WinnerScore == Null) { if (WinnerScore == Null) {
foreach (Score in Scores) { foreach (Score in Scores) {
if (Score.BestRaceTimes.count <= 0 && Score.User != Null && AccountIdsOfPlayers.exists(Score.User.WebServicesUserId)) { if (Score.BestRaceTimes.count <= 0 && Score.User != Null && LoginsOfPlayers.exists(Score.User.Login)) {
declare CSmPlayer Player = GetPlayer(Score.User.Login); declare CSmPlayer Player = GetPlayer(Score.User.Login);
if (Player != Null && !Player.RequestsSpectate) { if (Player != Null && !Player.RequestsSpectate) {
WinnerScore <=> Score; WinnerScore <=> Score;
@ -614,8 +614,8 @@ if (Round_ForceEndRound || Round_SkipPauseRound) {
*/ */
Void UpdateCustomRanking(CSmPlayer _EliminatedPlayer, Integer _EventType) { Void UpdateCustomRanking(CSmPlayer _EliminatedPlayer, Integer _EventType) {
declare Integer[Text] CustomTimes for This; declare Integer[Text] CustomTimes for This;
declare Text[] AccountIdsOfPlayers for This; declare Text[] LoginsOfPlayers for This;
foreach (Index => Score in Scores) { foreach (Score in Scores) {
if (Score == Null) continue; if (Score == Null) continue;
declare CSmPlayer Player = GetPlayer(Score.User.Login); declare CSmPlayer Player = GetPlayer(Score.User.Login);
if (Player == Null) continue; if (Player == Null) continue;
@ -632,7 +632,7 @@ if (Round_ForceEndRound || Round_SkipPauseRound) {
Scores::SetPlayerRoundPoints(Score,PlayersNbDead); Scores::SetPlayerRoundPoints(Score,PlayersNbDead);
} }
} }
UIModules_ScoresTable::DisplayOnly(AccountIdsOfPlayers); UIModules_ScoresTable::DisplayOnly(LoginsOfPlayers);
UIModules_ScoresTable::SetCustomTimes(CustomTimes); UIModules_ScoresTable::SetCustomTimes(CustomTimes);
} }