Small update on chunking

This commit is contained in:
Jocy 2017-05-15 19:31:24 +02:00
parent 7ed2fe4d74
commit b7de245ccd
3 changed files with 18 additions and 8 deletions

View File

@ -56,7 +56,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor'; const ACTION_SEARCH_AUTHOR = 'MapList.SearchAuthor';
const ACTION_RESET = 'MapList.ResetMapList'; const ACTION_RESET = 'MapList.ResetMapList';
const MAX_MAPS_PER_PAGE = 13; const MAX_MAPS_PER_PAGE = 13;
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 10;
const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'MCTeam\KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const CACHE_CURRENT_PAGE = 'CurrentPage'; const CACHE_CURRENT_PAGE = 'CurrentPage';

View File

@ -60,7 +60,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'MCTeam\CustomVotesPlugin';
const SHOWN_MAIN_WINDOW = -1; const SHOWN_MAIN_WINDOW = -1;
const MAX_PLAYERS_PER_PAGE = 15; const MAX_PLAYERS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 10;
/* /*
* Private properties * Private properties
@ -119,6 +119,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
* @param Player $player * @param Player $player
*/ */
public function closeWidget(Player $player) { public function closeWidget(Player $player) {
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
unset($this->playersListShown[$player->login]); unset($this->playersListShown[$player->login]);
} }

View File

@ -39,7 +39,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
const ACTION_SORT_STATS = 'SimpleStatsList.SortStats'; const ACTION_SORT_STATS = 'SimpleStatsList.SortStats';
const ACTION_PAGING_CHUNKS = 'SimpleStatsList.PagingChunk'; const ACTION_PAGING_CHUNKS = 'SimpleStatsList.PagingChunk';
const MAX_PLAYERS_PER_PAGE = 15; const MAX_PLAYERS_PER_PAGE = 15;
const MAX_PAGES_PER_CHUNK = 2; const MAX_PAGES_PER_CHUNK = 10;
const CACHE_CURRENT_PAGE = 'SimpleStatsList.CurrentPage'; const CACHE_CURRENT_PAGE = 'SimpleStatsList.CurrentPage';
@ -131,16 +131,21 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight(); $height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
$limit = 2000;
if ($pageIndex < 0) { if ($pageIndex < 0) {
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE); $pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
} }
$player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex); $player->setCache($this, self::CACHE_CURRENT_PAGE, $pageIndex);
$totalPlayersCount = $this->maniaControl->getStatisticManager()->getTotalStatsPlayerCount(-1); $totalPlayersCount = $this->maniaControl->getStatisticManager()->getTotalStatsPlayerCount(-1);
if ($totalPlayersCount > $limit) {
$totalPlayersCount = $limit;
}
$chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount); $chunkIndex = $this->getChunkIndexFromPageNumber($pageIndex, $totalPlayersCount);
$playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex); $playerBeginIndex = $this->getChunkStatsBeginIndex($chunkIndex);
$pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE); $pagesCount = ceil($totalPlayersCount / self::MAX_PLAYERS_PER_PAGE);
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
@ -201,7 +206,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
foreach ($this->statArray as $key => $stat) { foreach ($this->statArray as $key => $stat) {
$ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"], -1, -1, 20000); $ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"], -1, -1, $limit);
if (!empty($ranking)) { if (!empty($ranking)) {
$statRankings[$stat["Name"]] = $ranking; $statRankings[$stat["Name"]] = $ranking;
@ -287,7 +292,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
} }
$labelLine->addLabelEntryText($playerIndex, $xStart + 5, 9); $labelLine->addLabelEntryText($playerIndex, $xStart + 5, 9);
$labelLine->addLabelEntryText($listPlayer->login, $xStart + 14, 41); $labelLine->addLabelEntryText($listPlayer->nickname, $xStart + 14, 41);
$labelLine->render(); $labelLine->render();
$playerFrame->setY($posY); $playerFrame->setY($posY);
@ -368,6 +373,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
switch ($action) { switch ($action) {
case self::ACTION_SORT_STATS: case self::ACTION_SORT_STATS:
$this->showStatsList($player, $actionArray[2]); $this->showStatsList($player, $actionArray[2]);
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
break;
case ManialinkManager::ACTION_CLOSEWIDGET:
$player->destroyCache($this, self::CACHE_CURRENT_PAGE);
break; break;
default: default:
if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) { if (substr($actionId, 0, strlen(self::ACTION_PAGING_CHUNKS)) === self::ACTION_PAGING_CHUNKS) {