godot_voxel/storage/voxel_data_block.h
Marc Gilleron 922f361cb0 Made it compile in Godot 4
- Made a bunch of changes to comply with Godot 4 API
- Use Godot's Vector3i and add the missing stuff with helper functions
- Transvoxel uses custom attributes API, the old way would not work
- Wrap MeshOptimizer in a unique namespace (see build script why)
- Added clang-format file for the module as some rules now differ
- Prevent thirdparty code and lookup tables from being clang-formatted
- Very likely full of runtime bugs that need fixing
2021-12-13 21:38:10 +00:00

89 lines
2.3 KiB
C++

#ifndef VOXEL_DATA_BLOCK_H
#define VOXEL_DATA_BLOCK_H
#include "../storage/voxel_buffer_internal.h"
#include "../util/macros.h"
#include "voxel_ref_count.h"
#include <memory>
// Stores loaded voxel data for a chunk of the volume. Mesh and colliders are stored separately.
class VoxelDataBlock {
public:
const Vector3i position;
const unsigned int lod_index = 0;
VoxelRefCount viewers;
static VoxelDataBlock *create(
Vector3i bpos, std::shared_ptr<VoxelBufferInternal> &buffer, unsigned int size, unsigned int p_lod_index) {
const int bs = size;
ERR_FAIL_COND_V(buffer == nullptr, nullptr);
ERR_FAIL_COND_V(buffer->get_size() != Vector3i(bs, bs, bs), nullptr);
return memnew(VoxelDataBlock(bpos, buffer, p_lod_index));
}
VoxelBufferInternal &get_voxels() {
#ifdef DEBUG_ENABLED
CRASH_COND(_voxels == nullptr);
#endif
return *_voxels;
}
const VoxelBufferInternal &get_voxels_const() const {
#ifdef DEBUG_ENABLED
CRASH_COND(_voxels == nullptr);
#endif
return *_voxels;
}
std::shared_ptr<VoxelBufferInternal> get_voxels_shared() const {
#ifdef DEBUG_ENABLED
CRASH_COND(_voxels == nullptr);
#endif
return _voxels;
}
void set_voxels(std::shared_ptr<VoxelBufferInternal> &buffer) {
ERR_FAIL_COND(buffer == nullptr);
_voxels = buffer;
}
void set_modified(bool modified) {
#ifdef TOOLS_ENABLED
if (_modified == false && modified) {
PRINT_VERBOSE(String("Marking block {0} as modified").format(varray(position)));
}
#endif
_modified = modified;
}
inline bool is_modified() const {
return _modified;
}
void set_needs_lodding(bool need_lodding) {
_needs_lodding = need_lodding;
}
inline bool get_needs_lodding() const {
return _needs_lodding;
}
private:
VoxelDataBlock(Vector3i bpos, std::shared_ptr<VoxelBufferInternal> &buffer, unsigned int p_lod_index) :
position(bpos), lod_index(p_lod_index), _voxels(buffer) {}
std::shared_ptr<VoxelBufferInternal> _voxels;
// The block was edited, which requires its LOD counterparts to be recomputed
bool _needs_lodding = false;
// Indicates if this block is different from the time it was loaded (should be saved)
bool _modified = false;
// Tells if it's worth requesting a more precise version of the data.
// Will be `true` if it's not worth it.
bool _max_lod_hint = false;
};
#endif // VOXEL_DATA_BLOCK_H