Use MAX_LOD global constant
This commit is contained in:
parent
87afb8f96c
commit
0b4860b40d
@ -4,7 +4,10 @@
|
||||
#include "../math/rect3i.h"
|
||||
#include "../math/vector3i.h"
|
||||
#include "../util/array_slice.h"
|
||||
#include "../util/fixed_array.h"
|
||||
#include "../util/utility.h"
|
||||
#include "../voxel_constants.h"
|
||||
|
||||
#include <core/os/os.h>
|
||||
#include <core/os/semaphore.h>
|
||||
#include <algorithm>
|
||||
@ -23,7 +26,6 @@
|
||||
template <typename InputBlockData_T, typename OutputBlockData_T>
|
||||
class VoxelBlockThreadManager {
|
||||
public:
|
||||
static const int MAX_LOD = 32; // Like VoxelLodTerrain
|
||||
static const int MAX_JOBS = 8; // Arbitrary, should be enough
|
||||
|
||||
// Specialization must be copyable
|
||||
@ -51,7 +53,7 @@ public:
|
||||
Vector3i priority_position; // In LOD0 block coordinates
|
||||
Vector3 priority_direction; // Where the viewer is looking at
|
||||
int exclusive_region_extent = 0; // Region beyond which the processor is allowed to discard requests
|
||||
int exclusive_region_max_lod = MAX_LOD; // LOD beyond which exclusive region won't be used
|
||||
int exclusive_region_max_lod = VoxelConstants::MAX_LOD; // LOD beyond which exclusive region won't be used
|
||||
bool use_exclusive_region = false;
|
||||
int max_lod_index = 0;
|
||||
|
||||
@ -99,7 +101,7 @@ public:
|
||||
VoxelBlockThreadManager(
|
||||
unsigned int job_count,
|
||||
unsigned int sync_interval_ms,
|
||||
BlockProcessingFunc *processors,
|
||||
ArraySlice<BlockProcessingFunc> processors,
|
||||
bool duplicate_rejection = true,
|
||||
unsigned int batch_count = 1) {
|
||||
|
||||
@ -295,7 +297,7 @@ private:
|
||||
Mutex *output_mutex = nullptr;
|
||||
// Indexes which blocks are present in shared_input,
|
||||
// so if we push a duplicate request with the same coordinates, we can discard it without a linear search
|
||||
HashMap<Vector3i, int, Vector3iHasher> shared_input_block_indexes[MAX_LOD];
|
||||
FixedArray<HashMap<Vector3i, int, Vector3iHasher>, VoxelConstants::MAX_LOD> shared_input_block_indexes;
|
||||
bool needs_sort = false;
|
||||
// Only read by the thread
|
||||
bool thread_exit = false;
|
||||
@ -335,7 +337,7 @@ private:
|
||||
for (unsigned int i = begin; i < end; ++i) {
|
||||
|
||||
const InputBlock &block = input_blocks[i];
|
||||
CRASH_COND(block.lod >= MAX_LOD)
|
||||
CRASH_COND(block.lod >= VoxelConstants::MAX_LOD);
|
||||
|
||||
if (job.duplicate_rejection) {
|
||||
|
||||
@ -520,7 +522,7 @@ private:
|
||||
|
||||
if (data.duplicate_rejection) {
|
||||
// We emptied shared input, empty shared_input_block_indexes then
|
||||
for (unsigned int lod_index = 0; lod_index < MAX_LOD; ++lod_index) {
|
||||
for (unsigned int lod_index = 0; lod_index < data.shared_input_block_indexes.size(); ++lod_index) {
|
||||
data.shared_input_block_indexes[lod_index].clear();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ VoxelDataLoader::VoxelDataLoader(unsigned int thread_count, Ref<VoxelStream> str
|
||||
|
||||
// TODO I'm not sure it's worth to configure more than one thread for voxel streams
|
||||
|
||||
Mgr::BlockProcessingFunc processors[Mgr::MAX_JOBS];
|
||||
FixedArray<Mgr::BlockProcessingFunc, Mgr::MAX_JOBS> processors;
|
||||
|
||||
processors[0] = [this, stream](ArraySlice<InputBlock> inputs, ArraySlice<OutputBlock> outputs, Mgr::ProcessorStats &stats) {
|
||||
this->process_blocks_thread_func(inputs, outputs, stream, stats);
|
||||
|
@ -282,7 +282,7 @@ void VoxelLodTerrain::stop_updater() {
|
||||
|
||||
_blocks_pending_main_thread_update.clear();
|
||||
|
||||
for (int i = 0; i < MAX_LOD; ++i) {
|
||||
for (int i = 0; i < _lods.size(); ++i) {
|
||||
|
||||
Lod &lod = _lods[i];
|
||||
lod.blocks_pending_update.clear();
|
||||
@ -309,7 +309,7 @@ void VoxelLodTerrain::stop_streamer() {
|
||||
_stream_thread = nullptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_LOD; ++i) {
|
||||
for (int i = 0; i < _lods.size(); ++i) {
|
||||
Lod &lod = _lods[i];
|
||||
lod.blocks_to_load.clear();
|
||||
}
|
||||
@ -339,7 +339,7 @@ float VoxelLodTerrain::get_lod_split_scale() const {
|
||||
|
||||
void VoxelLodTerrain::set_lod_count(int p_lod_count) {
|
||||
|
||||
ERR_FAIL_COND(p_lod_count >= MAX_LOD);
|
||||
ERR_FAIL_COND(p_lod_count >= VoxelConstants::MAX_LOD);
|
||||
ERR_FAIL_COND(p_lod_count < 1);
|
||||
|
||||
if (get_lod_count() != p_lod_count) {
|
||||
@ -349,7 +349,7 @@ void VoxelLodTerrain::set_lod_count(int p_lod_count) {
|
||||
|
||||
void VoxelLodTerrain::_set_lod_count(int p_lod_count) {
|
||||
|
||||
CRASH_COND(p_lod_count >= MAX_LOD);
|
||||
CRASH_COND(p_lod_count >= VoxelConstants::MAX_LOD);
|
||||
CRASH_COND(p_lod_count < 1);
|
||||
|
||||
_lod_count = p_lod_count;
|
||||
@ -371,7 +371,7 @@ void VoxelLodTerrain::_set_lod_count(int p_lod_count) {
|
||||
void VoxelLodTerrain::reset_maps() {
|
||||
// Clears all blocks and reconfigures maps to account for new LOD count and block sizes
|
||||
|
||||
for (int lod_index = 0; lod_index < MAX_LOD; ++lod_index) {
|
||||
for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) {
|
||||
|
||||
Lod &lod = _lods[lod_index];
|
||||
|
||||
@ -453,7 +453,7 @@ void VoxelLodTerrain::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_WORLD: {
|
||||
World *world = *get_world();
|
||||
for (int lod_index = 0; lod_index < MAX_LOD; ++lod_index) {
|
||||
for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) {
|
||||
if (_lods[lod_index].map.is_valid()) {
|
||||
_lods[lod_index].map->for_all_blocks([world](VoxelBlock *block) {
|
||||
block->set_world(world);
|
||||
@ -463,7 +463,7 @@ void VoxelLodTerrain::_notification(int p_what) {
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_WORLD: {
|
||||
for (int lod_index = 0; lod_index < MAX_LOD; ++lod_index) {
|
||||
for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) {
|
||||
if (_lods[lod_index].map.is_valid()) {
|
||||
_lods[lod_index].map->for_all_blocks([](VoxelBlock *block) {
|
||||
block->set_world(nullptr);
|
||||
@ -474,7 +474,7 @@ void VoxelLodTerrain::_notification(int p_what) {
|
||||
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
bool visible = is_visible();
|
||||
for (int lod_index = 0; lod_index < MAX_LOD; ++lod_index) {
|
||||
for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) {
|
||||
if (_lods[lod_index].map.is_valid()) {
|
||||
_lods[lod_index].map->for_all_blocks([visible](VoxelBlock *block) {
|
||||
block->set_parent_visible(visible);
|
||||
|
@ -21,9 +21,6 @@ class VoxelBlock;
|
||||
class VoxelLodTerrain : public Spatial {
|
||||
GDCLASS(VoxelLodTerrain, Spatial)
|
||||
public:
|
||||
// TODO Put this in a constant outside, I had to re-declare it in various places
|
||||
static const int MAX_LOD = 32;
|
||||
|
||||
VoxelLodTerrain();
|
||||
~VoxelLodTerrain();
|
||||
|
||||
@ -176,7 +173,7 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
FixedArray<Lod, MAX_LOD> _lods;
|
||||
FixedArray<Lod, VoxelConstants::MAX_LOD> _lods;
|
||||
int _lod_count = 0;
|
||||
float _lod_split_scale = 0.f;
|
||||
unsigned int _view_distance_voxels = 512;
|
||||
|
@ -29,7 +29,7 @@ VoxelMeshUpdater::VoxelMeshUpdater(unsigned int thread_count, MeshingParams para
|
||||
_maximum_padding = max(_maximum_padding, smooth_mesher->get_maximum_padding());
|
||||
}
|
||||
|
||||
Mgr::BlockProcessingFunc processors[Mgr::MAX_LOD];
|
||||
FixedArray<Mgr::BlockProcessingFunc, VoxelConstants::MAX_LOD> processors;
|
||||
|
||||
for (unsigned int i = 0; i < thread_count; ++i) {
|
||||
|
||||
|
@ -1,17 +1,24 @@
|
||||
#ifndef ARRAY_SLICE_H
|
||||
#define ARRAY_SLICE_H
|
||||
|
||||
#include "fixed_array.h"
|
||||
#include <core/error_macros.h>
|
||||
|
||||
template <typename T>
|
||||
class ArraySlice {
|
||||
public:
|
||||
ArraySlice(T *p_ptr, size_t p_begin, size_t p_end) {
|
||||
inline ArraySlice(T *p_ptr, size_t p_begin, size_t p_end) {
|
||||
CRASH_COND(p_end <= p_begin);
|
||||
_ptr = p_ptr + p_begin;
|
||||
_size = p_end - p_begin;
|
||||
}
|
||||
|
||||
template <unsigned int N>
|
||||
inline ArraySlice(FixedArray<T, N> &a) {
|
||||
_ptr = a.data();
|
||||
_size = a.size();
|
||||
}
|
||||
|
||||
inline T &operator[](size_t i) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
CRASH_COND(i >= _size)
|
||||
@ -30,6 +37,14 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
inline T *data() {
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
inline const T *data() const {
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
T *_ptr;
|
||||
size_t _size;
|
||||
|
@ -34,6 +34,10 @@ public:
|
||||
return _data[i];
|
||||
}
|
||||
|
||||
inline T *data() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
inline unsigned int size() const {
|
||||
return N;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user