Namespaced FixedArray

This commit is contained in:
Marc Gilleron 2022-01-09 02:53:21 +00:00
parent 3101d7f092
commit 9c653b8a9f
17 changed files with 77 additions and 43 deletions

View File

@ -9,6 +9,8 @@
#include <scene/3d/camera_3d.h>
#include <scene/gui/menu_button.h>
using namespace zylann;
class VoxelTerrainEditorTaskIndicator : public HBoxContainer {
GDCLASS(VoxelTerrainEditorTaskIndicator, HBoxContainer)
private:

View File

@ -199,7 +199,7 @@ private:
static void gather_indices_and_weights(Span<const WeightOutput> weight_outputs,
const zylann::voxel::VoxelGraphRuntime::State &state, Vector3i rmin, Vector3i rmax, int ry,
zylann::voxel::VoxelBufferInternal &out_voxel_buffer, FixedArray<uint8_t, 4> spare_indices);
zylann::voxel::VoxelBufferInternal &out_voxel_buffer, zylann::FixedArray<uint8_t, 4> spare_indices);
static void _bind_methods();
@ -231,12 +231,12 @@ private:
zylann::voxel::VoxelGraphRuntime runtime;
// Indices that are not used in the graph.
// This is used when there are less than 4 texture weight outputs.
FixedArray<uint8_t, 4> spare_texture_indices;
zylann::FixedArray<uint8_t, 4> spare_texture_indices;
// Index to the SDF output
int sdf_output_buffer_index = -1;
FixedArray<WeightOutput, 16> weight_outputs;
zylann::FixedArray<WeightOutput, 16> weight_outputs;
// List of indices to feed queries. The order doesn't matter, can be different from `weight_outputs`.
FixedArray<unsigned int, 16> weight_output_indices;
zylann::FixedArray<unsigned int, 16> weight_output_indices;
unsigned int weight_outputs_count = 0;
};

View File

@ -34,12 +34,12 @@ public:
// Model sides:
// They are separated because this way we can occlude them easily.
// Due to these defining cube side triangles, normals are known already.
FixedArray<std::vector<Vector3>, Cube::SIDE_COUNT> side_positions;
FixedArray<std::vector<Vector2>, Cube::SIDE_COUNT> side_uvs;
FixedArray<std::vector<int>, Cube::SIDE_COUNT> side_indices;
FixedArray<std::vector<float>, Cube::SIDE_COUNT> side_tangents;
zylann::FixedArray<std::vector<Vector3>, Cube::SIDE_COUNT> side_positions;
zylann::FixedArray<std::vector<Vector2>, Cube::SIDE_COUNT> side_uvs;
zylann::FixedArray<std::vector<int>, Cube::SIDE_COUNT> side_indices;
zylann::FixedArray<std::vector<float>, Cube::SIDE_COUNT> side_tangents;
FixedArray<uint32_t, Cube::SIDE_COUNT> side_pattern_indices;
zylann::FixedArray<uint32_t, Cube::SIDE_COUNT> side_pattern_indices;
void clear() {
positions.clear();
@ -85,39 +85,59 @@ public:
// Properties
void set_voxel_name(String name);
_FORCE_INLINE_ StringName get_voxel_name() const { return _name; }
_FORCE_INLINE_ StringName get_voxel_name() const {
return _name;
}
void set_id(int id);
_FORCE_INLINE_ int get_id() const { return _id; }
_FORCE_INLINE_ int get_id() const {
return _id;
}
void set_color(Color color);
_FORCE_INLINE_ Color get_color() const { return _color; }
_FORCE_INLINE_ Color get_color() const {
return _color;
}
void set_material_id(unsigned int id);
_FORCE_INLINE_ unsigned int get_material_id() const { return _material_id; }
_FORCE_INLINE_ unsigned int get_material_id() const {
return _material_id;
}
// TODO Might become obsolete
void set_transparent(bool t = true);
_FORCE_INLINE_ bool is_transparent() const { return _transparency_index != 0; }
_FORCE_INLINE_ bool is_transparent() const {
return _transparency_index != 0;
}
void set_transparency_index(int i);
int get_transparency_index() const { return _transparency_index; }
int get_transparency_index() const {
return _transparency_index;
}
void set_custom_mesh(Ref<Mesh> mesh);
Ref<Mesh> get_custom_mesh() const { return _custom_mesh; }
Ref<Mesh> get_custom_mesh() const {
return _custom_mesh;
}
void set_random_tickable(bool rt);
inline bool is_random_tickable() const { return _random_tickable; }
inline bool is_random_tickable() const {
return _random_tickable;
}
void set_collision_mask(uint32_t mask);
inline uint32_t get_collision_mask() const { return _collision_mask; }
inline uint32_t get_collision_mask() const {
return _collision_mask;
}
Vector2 get_cube_tile(int side) const { return _cube_tiles[side]; }
Vector2 get_cube_tile(int side) const {
return _cube_tiles[side];
}
//-------------------------------------------
// Built-in geometry generators
enum GeometryType {
enum GeometryType { //
GEOMETRY_NONE = 0,
GEOMETRY_CUBE,
GEOMETRY_CUSTOM_MESH,
@ -127,7 +147,9 @@ public:
void set_geometry_type(GeometryType type);
GeometryType get_geometry_type() const;
inline bool is_empty() const { return _empty; }
inline bool is_empty() const {
return _empty;
}
Ref<Resource> duplicate(bool p_subresources) const override;
@ -136,7 +158,9 @@ public:
void bake(BakedData &baked_data, int p_atlas_size, bool bake_tangents);
const std::vector<AABB> &get_collision_aabbs() const { return _collision_aabbs; }
const std::vector<AABB> &get_collision_aabbs() const {
return _collision_aabbs;
}
private:
bool _set(const StringName &p_name, const Variant &p_value);
@ -168,7 +192,7 @@ private:
Color _color;
GeometryType _geometry_type;
FixedArray<Vector2, Cube::SIDE_COUNT> _cube_tiles;
zylann::FixedArray<Vector2, Cube::SIDE_COUNT> _cube_tiles;
Ref<Mesh> _custom_mesh;
std::vector<AABB> _collision_aabbs;
bool _random_tickable = false;

View File

@ -35,7 +35,9 @@ public:
Ref<Resource> duplicate(bool p_subresources = false) const override;
int get_used_channels_mask() const override;
bool supports_lod() const override { return false; }
bool supports_lod() const override {
return false;
}
// Using std::vector because they make this mesher twice as fast than Godot Vectors.
// See why: https://github.com/godotengine/godot/issues/24731
@ -68,7 +70,7 @@ private:
};
struct Cache {
FixedArray<Arrays, MAX_MATERIALS> arrays_per_material;
zylann::FixedArray<Arrays, MAX_MATERIALS> arrays_per_material;
};
// Parameters

View File

@ -37,7 +37,7 @@ private:
static void _bind_methods();
FixedArray<zylann::Color8, MAX_COLORS> _colors;
zylann::FixedArray<zylann::Color8, MAX_COLORS> _colors;
};
#endif // VOXEL_COLOR_PALETTE_H

View File

@ -104,7 +104,7 @@ private:
};
struct Cache {
FixedArray<Arrays, MATERIAL_COUNT> arrays_per_material;
zylann::FixedArray<Arrays, MATERIAL_COUNT> arrays_per_material;
std::vector<uint8_t> mask_memory_pool;
GreedyAtlasData greedy_atlas_data;
};

View File

@ -22,7 +22,7 @@ public:
struct Output {
// Each surface correspond to a different material
Vector<Array> surfaces;
FixedArray<Vector<Array>, Cube::SIDE_COUNT> transition_surfaces;
zylann::FixedArray<Vector<Array>, Cube::SIDE_COUNT> transition_surfaces;
Mesh::PrimitiveType primitive_type = Mesh::PRIMITIVE_TRIANGLES;
unsigned int mesh_flags = 0;
Ref<Image> atlas_image;

View File

@ -55,7 +55,8 @@ public:
struct BlockMeshInput {
// Moore area ordered by forward XYZ iteration
FixedArray<std::shared_ptr<zylann::voxel::VoxelBufferInternal>, VoxelConstants::MAX_BLOCK_COUNT_PER_REQUEST>
zylann::FixedArray<std::shared_ptr<zylann::voxel::VoxelBufferInternal>,
VoxelConstants::MAX_BLOCK_COUNT_PER_REQUEST>
data_blocks;
unsigned int data_blocks_count = 0;
Vector3i render_block_position;
@ -354,7 +355,8 @@ private:
bool is_cancelled() override;
void apply_result() override;
FixedArray<std::shared_ptr<zylann::voxel::VoxelBufferInternal>, VoxelConstants::MAX_BLOCK_COUNT_PER_REQUEST>
zylann::FixedArray<std::shared_ptr<zylann::voxel::VoxelBufferInternal>,
VoxelConstants::MAX_BLOCK_COUNT_PER_REQUEST>
blocks;
// TODO Need to provide format
//FixedArray<uint8_t, VoxelBufferInternal::MAX_CHANNELS> channel_depths;

View File

@ -83,7 +83,7 @@ private:
uint8_t lod_count = 0;
uint8_t block_size_po2 = 0; // How many voxels in a cubic block
uint8_t region_size_po2 = 0; // How many blocks in one cubic region
FixedArray<zylann::voxel::VoxelBufferInternal::Depth, zylann::voxel::VoxelBufferInternal::MAX_CHANNELS>
zylann::FixedArray<zylann::voxel::VoxelBufferInternal::Depth, zylann::voxel::VoxelBufferInternal::MAX_CHANNELS>
channel_depths;
uint32_t sector_size = 0; // Blocks are stored at offsets multiple of that size
};

View File

@ -56,7 +56,7 @@ public:
bool used = false;
};
FixedArray<Channel, VoxelBuffer::MAX_CHANNELS> channels;
zylann::FixedArray<Channel, VoxelBuffer::MAX_CHANNELS> channels;
};
enum BlockType { VOXELS, INSTANCES };

View File

@ -43,7 +43,7 @@ private:
uint8_t version = -1;
uint8_t lod_count = 0;
uint8_t block_size_po2 = 0; // How many voxels in a block
FixedArray<zylann::voxel::VoxelBufferInternal::Depth, zylann::voxel::VoxelBufferInternal::MAX_CHANNELS>
zylann::FixedArray<zylann::voxel::VoxelBufferInternal::Depth, zylann::voxel::VoxelBufferInternal::MAX_CHANNELS>
channel_depths;
};

View File

@ -60,7 +60,7 @@ private:
RWLock rw_lock;
};
FixedArray<Lod, VoxelConstants::MAX_LOD> _cache;
zylann::FixedArray<Lod, VoxelConstants::MAX_LOD> _cache;
unsigned int _count = 0;
};

View File

@ -77,7 +77,7 @@ private:
set_mesh(mesh, 3);
}
FixedArray<Ref<Mesh>, MAX_MESH_LODS> _mesh_lods;
zylann::FixedArray<Ref<Mesh>, MAX_MESH_LODS> _mesh_lods;
unsigned int _mesh_lod_count = 1;
// It is preferred to have materials on the mesh already,

View File

@ -187,7 +187,7 @@ private:
// Can't use `HashMap` because it lacks move semantics.
std::unordered_map<Vector3i, std::unique_ptr<VoxelInstanceBlockData>> loaded_instances_data;
FixedArray<MeshLodDistances, VoxelInstanceLibraryItem::MAX_MESH_LODS> mesh_lod_distances;
zylann::FixedArray<MeshLodDistances, VoxelInstanceLibraryItem::MAX_MESH_LODS> mesh_lod_distances;
Lod() = default;
Lod(const Lod &) = delete; // non construction-copyable
@ -196,7 +196,7 @@ private:
UpMode _up_mode = UP_MODE_POSITIVE_Y;
FixedArray<Lod, MAX_LOD> _lods;
zylann::FixedArray<Lod, MAX_LOD> _lods;
std::vector<Block *> _blocks; // Does not have nulls
HashMap<int, Layer> _layers; // Each layer corresponds to a library item
Ref<VoxelInstanceLibrary> _library;

View File

@ -385,7 +385,7 @@ private:
}
};
FixedArray<Lod, VoxelConstants::MAX_LOD> _lods;
zylann::FixedArray<Lod, VoxelConstants::MAX_LOD> _lods;
unsigned int _lod_count = 0;
// Distance between a viewer and the end of LOD0
float _lod_distance = 0.f;

View File

@ -3,6 +3,8 @@
#include <core/error/error_macros.h>
namespace zylann {
// TODO Could use std::array, but due to how Godot compiles,
// I couldn't find a way to enable boundary checks without failing to link my module with the rest of Godot...
template <typename T, unsigned int N>
@ -75,4 +77,6 @@ private:
T _data[N];
};
} // namespace zylann
#endif // FIXED_ARRAY_H

View File

@ -38,7 +38,7 @@ public:
// TODO Remove this one, prefer to_span() specializations
template <unsigned int N>
inline Span(FixedArray<T, N> &a) {
inline Span(zylann::FixedArray<T, N> &a) {
_ptr = a.data();
_size = a.size();
}
@ -124,24 +124,24 @@ Span<const T> to_span_const(const std::vector<T> &vec) {
}
template <typename T, unsigned int N>
Span<T> to_span(FixedArray<T, N> &a) {
Span<T> to_span(zylann::FixedArray<T, N> &a) {
return Span<T>(a.data(), a.size());
}
template <typename T, unsigned int N>
Span<T> to_span(FixedArray<T, N> &a, unsigned int count) {
Span<T> to_span(zylann::FixedArray<T, N> &a, unsigned int count) {
CRASH_COND(count > a.size());
return Span<T>(a.data(), count);
}
template <typename T, unsigned int N>
Span<const T> to_span_const(const FixedArray<T, N> &a, unsigned int count) {
Span<const T> to_span_const(const zylann::FixedArray<T, N> &a, unsigned int count) {
CRASH_COND(count > a.size());
return Span<const T>(a.data(), count);
}
template <typename T, unsigned int N>
Span<const T> to_span_const(const FixedArray<T, N> &a) {
Span<const T> to_span_const(const zylann::FixedArray<T, N> &a) {
return Span<const T>(a.data(), 0, a.size());
}