mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51: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 "BlocksController.hpp"
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "items/Inventories.hpp"
|
#include "items/Inventories.hpp"
|
||||||
#include "items/Inventory.hpp"
|
#include "items/Inventory.hpp"
|
||||||
|
|
@ -175,12 +173,8 @@ void BlocksController::randomTick(
|
||||||
void BlocksController::randomTick(int tickid, int parts, uint padding) {
|
void BlocksController::randomTick(int tickid, int parts, uint padding) {
|
||||||
auto indices = level.content.getIndices();
|
auto indices = level.content.getIndices();
|
||||||
|
|
||||||
std::set<uint64_t> chunksIterated;
|
|
||||||
|
|
||||||
for (const auto& [pid, player] : *level.players) {
|
for (const auto& [pid, player] : *level.players) {
|
||||||
const auto& chunks = *player->chunks;
|
const auto& chunks = *player->chunks;
|
||||||
int offsetX = chunks.getOffsetX();
|
|
||||||
int offsetY = chunks.getOffsetY();
|
|
||||||
int width = chunks.getWidth();
|
int width = chunks.getWidth();
|
||||||
int height = chunks.getHeight();
|
int height = chunks.getHeight();
|
||||||
int segments = 4;
|
int segments = 4;
|
||||||
|
|
@ -195,20 +189,15 @@ void BlocksController::randomTick(int tickid, int parts, uint padding) {
|
||||||
if (chunk == nullptr || !chunk->flags.lighted) {
|
if (chunk == nullptr || !chunk->flags.lighted) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
union {
|
if (chunk->lastRandomTickId == randomTickId) {
|
||||||
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()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
chunksIterated.insert(posU.key);
|
chunk->lastRandomTickId = randomTickId;
|
||||||
randomTick(*chunk, segments, indices);
|
randomTick(*chunk, segments, indices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
randomTickId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t BlocksController::createBlockInventory(int x, int y, int z) {
|
int64_t BlocksController::createBlockInventory(int x, int y, int z) {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class BlocksController {
|
||||||
util::Clock worldTickClock;
|
util::Clock worldTickClock;
|
||||||
FastRandom random {};
|
FastRandom random {};
|
||||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||||
|
uint64_t randomTickId = 0;
|
||||||
public:
|
public:
|
||||||
BlocksController(const Level& level, Lighting* lighting);
|
BlocksController(const Level& level, Lighting* lighting);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ public:
|
||||||
bool dirtyHeights : 1;
|
bool dirtyHeights : 1;
|
||||||
} flags {};
|
} flags {};
|
||||||
|
|
||||||
|
uint64_t lastRandomTickId = -1;
|
||||||
|
|
||||||
/// @brief Block inventories map where key is index of block in voxels array
|
/// @brief Block inventories map where key is index of block in voxels array
|
||||||
ChunkInventoriesMap inventories;
|
ChunkInventoriesMap inventories;
|
||||||
/// @brief Blocks metadata heap
|
/// @brief Blocks metadata heap
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue