diff --git a/src/logic/BlocksController.cpp b/src/logic/BlocksController.cpp index 08e2aae7c..f859a8455 100644 --- a/src/logic/BlocksController.cpp +++ b/src/logic/BlocksController.cpp @@ -1,7 +1,5 @@ #include "BlocksController.hpp" -#include - #include "content/Content.hpp" #include "items/Inventories.hpp" #include "items/Inventory.hpp" @@ -175,12 +173,8 @@ void BlocksController::randomTick( void BlocksController::randomTick(int tickid, int parts, uint padding) { auto indices = level.content.getIndices(); - std::set chunksIterated; - for (const auto& [pid, player] : *level.players) { const auto& chunks = *player->chunks; - int offsetX = chunks.getOffsetX(); - int offsetY = chunks.getOffsetY(); int width = chunks.getWidth(); int height = chunks.getHeight(); int segments = 4; @@ -195,20 +189,15 @@ void BlocksController::randomTick(int tickid, int parts, uint padding) { if (chunk == nullptr || !chunk->flags.lighted) { continue; } - union { - int32_t pos[2]; - uint64_t key; - } posU; - posU.pos[0] = x + offsetX; - posU.pos[1] = z + offsetY; - if (chunksIterated.find(posU.key) != chunksIterated.end()) { + if (chunk->lastRandomTickId == randomTickId) { continue; } - chunksIterated.insert(posU.key); + chunk->lastRandomTickId = randomTickId; randomTick(*chunk, segments, indices); } } } + randomTickId++; } int64_t BlocksController::createBlockInventory(int x, int y, int z) { diff --git a/src/logic/BlocksController.hpp b/src/logic/BlocksController.hpp index f3fa5f67a..8b26e0190 100644 --- a/src/logic/BlocksController.hpp +++ b/src/logic/BlocksController.hpp @@ -33,6 +33,7 @@ class BlocksController { util::Clock worldTickClock; FastRandom random {}; std::vector blockInteractionCallbacks; + uint64_t randomTickId = 0; public: BlocksController(const Level& level, Lighting* lighting); diff --git a/src/voxels/Chunk.hpp b/src/voxels/Chunk.hpp index 393f05f8a..5d45629ea 100644 --- a/src/voxels/Chunk.hpp +++ b/src/voxels/Chunk.hpp @@ -40,6 +40,8 @@ public: bool dirtyHeights : 1; } flags {}; + uint64_t lastRandomTickId = -1; + /// @brief Block inventories map where key is index of block in voxels array ChunkInventoriesMap inventories; /// @brief Blocks metadata heap