Skip to content

Commit

Permalink
fix: reduce function body
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Nov 19, 2024
1 parent 2e34768 commit e04c208
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5746,18 +5746,13 @@ void ProtocolGame::sendForgeHistory(uint8_t page) {
auto historyVector = player->getForgeHistory();
auto historyVectorLen = historyVector.size();

uint16_t currentPage = 1;
uint16_t lastPage = 1;
uint16_t pageFirstEntry = 0;
uint16_t pageLastEntry = 0;

std::vector<ForgeHistory> historyPerPage;
if (historyVectorLen > 0) {
lastPage = std::clamp<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1, 0, std::numeric_limits<uint16_t>::max());
currentPage = (lastPage < page) ? lastPage : page;
uint16_t lastPage = std::clamp<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1, 0, std::numeric_limits<uint16_t>::max());
uint16_t currentPage = (lastPage < page) ? lastPage : page;

pageFirstEntry = std::clamp<uint16_t>(historyVectorLen - (currentPage - 1) * 9, 0, std::numeric_limits<uint16_t>::max());
pageLastEntry = historyVectorLen > currentPage * 9 ? std::clamp<uint16_t>(historyVectorLen - currentPage * 9, 0, std::numeric_limits<uint16_t>::max()) : 0;
uint16_t pageFirstEntry = std::clamp<uint16_t>(historyVectorLen - (currentPage - 1) * 9, 0, std::numeric_limits<uint16_t>::max());
uint16_t pageLastEntry = historyVectorLen > currentPage * 9 ? std::clamp<uint16_t>(historyVectorLen - currentPage * 9, 0, std::numeric_limits<uint16_t>::max()) : 0;

for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) {
historyPerPage.emplace_back(historyVector[entry - 1]);
Expand Down

0 comments on commit e04c208

Please sign in to comment.