Improve performance of computing of the roundpoints + support teams roundpoints

This commit is contained in:
Beu 2023-04-11 11:55:52 +02:00
parent 43072d6088
commit 8736c183d1

View File

@ -37,7 +37,7 @@ use ManiaControl\Callbacks\TimerListener; // for pause
class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin { class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
const PLUGIN_ID = 152; const PLUGIN_ID = 152;
const PLUGIN_VERSION = 4.1; const PLUGIN_VERSION = 4.2;
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -321,7 +321,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
private $settings_pointlimit = 100; private $settings_pointlimit = 100;
private $currentscore = array(); private $currentscore = array();
private $preendroundscore = array(); /** @var OnScoresStructure|null $preendroundscore */
private $preendroundscore = null;
private $currentteamsscore = array(); private $currentteamsscore = array();
private $pausetimer = 0; private $pausetimer = 0;
private $pauseon = false; private $pauseon = false;
@ -1527,7 +1528,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
} elseif ($structure->getSection() == "EndMap" && $this->hidenextmaps && isset($this->maps[$this->nbmaps])) { } elseif ($structure->getSection() == "EndMap" && $this->hidenextmaps && isset($this->maps[$this->nbmaps])) {
$this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]); $this->maniaControl->getClient()->addMap($this->maps[$this->nbmaps]);
} elseif ($structure->getSection() == "PreEndRound") { } elseif ($structure->getSection() == "PreEndRound") {
$this->preendroundscore = $structure->getPlayerScores(); $this->preendroundscore = $structure;
} elseif ($structure->getSection() == "EndRound") { } elseif ($structure->getSection() == "EndRound") {
$timestamp = time(); $timestamp = time();
@ -1543,6 +1544,14 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO"); Logger::Log("No data are save in RoyalTimeAttack for the moment, it's not implemented on server side. Waiting a fix from NADEO");
} }
$preendroundplayersscore = [];
$preendroundteamsscore = [];
if ($this->preendroundscore !== null) {
$preendroundplayersscore = $this->preendroundscore->getPlayerScores();
$preendroundteamsscore = $this->preendroundscore->getTeamScores();;
}
$this->preendroundscore = null;
//$rank = 1; //$rank = 1;
foreach ($results as $result) { foreach ($results as $result) {
/** @var \ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore $result */ /** @var \ManiaControl\Callbacks\Structures\TrackMania\Models\PlayerScore $result */
@ -1558,19 +1567,18 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$prevracetime = $result->getPrevRaceTime(); $prevracetime = $result->getPrevRaceTime();
$prevracecheckpoints = implode(",", $result->getPrevRaceCheckpoints()); $prevracecheckpoints = implode(",", $result->getPrevRaceCheckpoints());
if (count($this->preendroundscore) > 0) { if (count($preendroundplayersscore) > 0) {
foreach ($this->preendroundscore as $k => $preendroundresult) { $preendroundarray = array_filter($preendroundplayersscore, function ($e) use ($player) { return $e->getPlayer() === $player ; });
if ($preendroundresult->getPlayer() === $player) {
if ($roundpoints == 0 && $preendroundresult->getRoundPoints() != 0) {
$roundpoints = $preendroundresult->getRoundPoints();
}
if ($mappoints == 0 && $preendroundresult->getMapPoints() != 0) {
$mappoints = $preendroundresult->getMapPoints();
}
unset($this->preendroundscore[$k]); foreach ($preendroundarray as $key => $preendround) {
break; if ($roundpoints == 0 && $preendround->getRoundPoints() != 0) {
$roundpoints = $preendround->getRoundPoints();
} }
if ($mappoints == 0 && $preendround->getMapPoints() != 0) {
$mappoints = $preendround->getMapPoints();
}
unset($preendroundplayersscore[$key]);
break;
} }
} }
@ -1597,6 +1605,21 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$mappoints = $teamresult->getMapPoints(); $mappoints = $teamresult->getMapPoints();
$roundpoints = $teamresult->getRoundPoints(); $roundpoints = $teamresult->getRoundPoints();
if (count($preendroundteamsscore) > 0) {
$preendroundarray = array_filter($preendroundteamsscore, function ($e) use ($teamid) { return $e->getTeamId() === $teamid ; });
foreach ($preendroundarray as $key => $preendround) {
if ($roundpoints == 0 && $preendround->getRoundPoints() != 0) {
$roundpoints = $preendround->getRoundPoints();
}
if ($mappoints == 0 && $preendround->getMapPoints() != 0) {
$mappoints = $preendround->getMapPoints();
}
unset($preendroundteamsscore[$key]);
break;
}
}
$this->currentteamsscore = array_merge($this->currentteamsscore, array( $this->currentteamsscore = array_merge($this->currentteamsscore, array(
array($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints) array($rank, $teamid, $teamname, $matchpoints, $mappoints, $roundpoints)
)); ));
@ -1607,7 +1630,6 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
// //
// End Round Routines // End Round Routines
// //
$this->preendroundscore = array();
if (!$this->pauseon && !$this->skipround) { if (!$this->pauseon && !$this->skipround) {
if ($this->currentgmbase != "Cup") { if ($this->currentgmbase != "Cup") {
$this->nbrounds++; $this->nbrounds++;