mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
optimize BlocksController::randomTick & reduce small allocations count
This commit is contained in:
parent
fb0ad19a65
commit
f1a015d3e7
3 changed files with 6 additions and 14 deletions
|
|
@ -1,7 +1,5 @@
|
|||
#include "BlocksController.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
#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<uint64_t> 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) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class BlocksController {
|
|||
util::Clock worldTickClock;
|
||||
FastRandom random {};
|
||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||
uint64_t randomTickId = 0;
|
||||
public:
|
||||
BlocksController(const Level& level, Lighting* lighting);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue