2019-05-25 08:16:03 -07:00
|
|
|
#include "voxel_stream.h"
|
2021-12-13 13:38:10 -08:00
|
|
|
#include <core/object/script_language.h>
|
2017-01-01 17:15:57 -08:00
|
|
|
|
2022-01-08 14:49:48 -08:00
|
|
|
using namespace zylann::voxel;
|
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
VoxelStream::VoxelStream() {}
|
2019-08-18 15:13:12 -07:00
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
VoxelStream::~VoxelStream() {}
|
2021-01-17 09:18:05 -08:00
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
VoxelStream::Result VoxelStream::load_voxel_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) {
|
2021-01-17 09:18:05 -08:00
|
|
|
// Can be implemented in subclasses
|
|
|
|
return RESULT_BLOCK_NOT_FOUND;
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
void VoxelStream::save_voxel_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) {
|
2021-01-17 09:18:05 -08:00
|
|
|
// Can be implemented in subclasses
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
void VoxelStream::load_voxel_blocks(Span<VoxelBlockRequest> p_blocks, Vector<Result> &out_results) {
|
2019-08-14 12:34:06 -07:00
|
|
|
// Default implementation. May matter for some stream types to optimize loading.
|
2021-09-26 08:36:08 -07:00
|
|
|
for (unsigned int i = 0; i < p_blocks.size(); ++i) {
|
2021-09-25 20:14:50 -07:00
|
|
|
VoxelBlockRequest &r = p_blocks[i];
|
2022-01-15 20:21:02 -08:00
|
|
|
const Result res = load_voxel_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
|
2021-01-17 09:18:05 -08:00
|
|
|
out_results.push_back(res);
|
2019-08-14 12:34:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
void VoxelStream::save_voxel_blocks(Span<VoxelBlockRequest> p_blocks) {
|
2021-09-26 08:36:08 -07:00
|
|
|
for (unsigned int i = 0; i < p_blocks.size(); ++i) {
|
2021-01-17 09:18:05 -08:00
|
|
|
const VoxelBlockRequest &r = p_blocks[i];
|
2022-01-15 20:21:02 -08:00
|
|
|
save_voxel_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
|
2019-08-14 12:34:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 09:22:50 -08:00
|
|
|
bool VoxelStream::supports_instance_blocks() const {
|
|
|
|
// Can be implemented in subclasses
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
void VoxelStream::load_instance_blocks(Span<VoxelStreamInstanceDataRequest> out_blocks, Span<Result> out_results) {
|
2021-02-07 09:22:50 -08:00
|
|
|
// Can be implemented in subclasses
|
2021-02-16 13:44:01 -08:00
|
|
|
for (size_t i = 0; i < out_results.size(); ++i) {
|
2021-02-07 09:22:50 -08:00
|
|
|
out_results[i] = RESULT_BLOCK_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:48:49 -07:00
|
|
|
void VoxelStream::save_instance_blocks(Span<VoxelStreamInstanceDataRequest> p_blocks) {
|
2021-02-07 09:22:50 -08:00
|
|
|
// Can be implemented in subclasses
|
|
|
|
}
|
|
|
|
|
2021-10-02 17:48:07 -07:00
|
|
|
void VoxelStream::load_all_blocks(FullLoadingResult &result) {
|
|
|
|
ERR_PRINT(String("{0} does not support `load_all_blocks`").format(varray(get_class_name())));
|
|
|
|
}
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
int VoxelStream::get_used_channels_mask() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelStream::set_save_generator_output(bool enabled) {
|
|
|
|
RWLockWrite wlock(_parameters_lock);
|
|
|
|
_parameters.save_generator_output = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VoxelStream::get_save_generator_output() const {
|
|
|
|
RWLockRead rlock(_parameters_lock);
|
|
|
|
return _parameters.save_generator_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelStream::get_block_size_po2() const {
|
2022-01-08 19:06:58 -08:00
|
|
|
return constants::DEFAULT_BLOCK_SIZE_PO2;
|
2021-01-17 09:18:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelStream::get_lod_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Binding land
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
VoxelStream::Result VoxelStream::_b_load_voxel_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod) {
|
2021-01-21 11:39:42 -08:00
|
|
|
ERR_FAIL_COND_V(lod < 0, RESULT_ERROR);
|
2021-09-25 20:14:50 -07:00
|
|
|
ERR_FAIL_COND_V(out_buffer.is_null(), RESULT_ERROR);
|
2022-01-15 20:21:02 -08:00
|
|
|
return load_voxel_block(out_buffer->get_buffer(), Vector3iUtil::from_floored(origin_in_voxels), lod);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
void VoxelStream::_b_save_voxel_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels, int lod) {
|
2019-04-29 13:57:39 -07:00
|
|
|
ERR_FAIL_COND(lod < 0);
|
2021-09-26 07:49:12 -07:00
|
|
|
ERR_FAIL_COND(buffer.is_null());
|
2022-01-15 20:21:02 -08:00
|
|
|
save_voxel_block(buffer->get_buffer(), Vector3iUtil::from_floored(origin_in_voxels), lod);
|
|
|
|
}
|
|
|
|
|
|
|
|
VoxelStream::Result VoxelStream::_b_emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod) {
|
|
|
|
ERR_PRINT("VoxelStream.emerge_block is deprecated. Use `load_voxel_block` instead.");
|
|
|
|
return _b_load_voxel_block(out_buffer, origin_in_voxels, lod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelStream::_b_immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels, int lod) {
|
|
|
|
ERR_PRINT("VoxelStream.immerge_block is deprecated. Use `save_voxel_block` instead.");
|
|
|
|
return _b_save_voxel_block(buffer, origin_in_voxels, lod);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
int VoxelStream::_b_get_used_channels_mask() const {
|
2020-02-14 11:12:13 -08:00
|
|
|
return get_used_channels_mask();
|
|
|
|
}
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
Vector3 VoxelStream::_b_get_block_size() const {
|
2021-12-13 13:38:10 -08:00
|
|
|
return Vector3iUtil::create(1 << get_block_size_po2());
|
2020-08-14 12:33:09 -07:00
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::_bind_methods() {
|
2021-12-13 13:38:10 -08:00
|
|
|
ClassDB::bind_method(
|
|
|
|
D_METHOD("emerge_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelStream::_b_emerge_block);
|
|
|
|
ClassDB::bind_method(
|
|
|
|
D_METHOD("immerge_block", "buffer", "origin_in_voxels", "lod"), &VoxelStream::_b_immerge_block);
|
2022-01-15 20:21:02 -08:00
|
|
|
|
|
|
|
ClassDB::bind_method(
|
|
|
|
D_METHOD("load_voxel_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelStream::_b_load_voxel_block);
|
|
|
|
ClassDB::bind_method(
|
|
|
|
D_METHOD("save_voxel_block", "buffer", "origin_in_voxels", "lod"), &VoxelStream::_b_save_voxel_block);
|
2021-01-17 09:18:05 -08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_used_channels_mask"), &VoxelStream::_b_get_used_channels_mask);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_save_generator_output", "enabled"), &VoxelStream::set_save_generator_output);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_save_generator_output"), &VoxelStream::get_save_generator_output);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_block_size"), &VoxelStream::_b_get_block_size);
|
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "save_generator_output"), "set_save_generator_output",
|
|
|
|
"get_save_generator_output");
|
2021-01-17 09:18:05 -08:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_ERROR);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_BLOCK_FOUND);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_BLOCK_NOT_FOUND);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|