2019-05-25 08:16:03 -07:00
|
|
|
#include "voxel_stream.h"
|
2020-01-17 12:43:28 -08:00
|
|
|
#include "../voxel_string_names.h"
|
2020-08-14 12:33:09 -07:00
|
|
|
#include <core/script_language.h>
|
2017-01-01 17:15:57 -08:00
|
|
|
|
2019-08-18 15:13:12 -07:00
|
|
|
VoxelStream::VoxelStream() {
|
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod) {
|
2017-01-01 17:15:57 -08:00
|
|
|
ERR_FAIL_COND(out_buffer.is_null());
|
2020-08-02 10:57:08 -07:00
|
|
|
try_call_script(this, VoxelStringNames::get_singleton()->emerge_block, out_buffer, origin_in_voxels.to_vec3(), lod, nullptr);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::immerge_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels, int lod) {
|
2017-01-01 17:15:57 -08:00
|
|
|
ERR_FAIL_COND(buffer.is_null());
|
2020-08-02 10:57:08 -07:00
|
|
|
try_call_script(this, VoxelStringNames::get_singleton()->immerge_block, buffer, origin_in_voxels.to_vec3(), lod, nullptr);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2020-01-26 14:34:26 -08:00
|
|
|
void VoxelStream::emerge_blocks(Vector<VoxelBlockRequest> &p_blocks) {
|
2019-08-14 12:34:06 -07:00
|
|
|
// Default implementation. May matter for some stream types to optimize loading.
|
|
|
|
for (int i = 0; i < p_blocks.size(); ++i) {
|
2020-01-26 14:34:26 -08:00
|
|
|
VoxelBlockRequest &r = p_blocks.write[i];
|
2019-08-14 12:34:06 -07:00
|
|
|
emerge_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 14:34:26 -08:00
|
|
|
void VoxelStream::immerge_blocks(Vector<VoxelBlockRequest> &p_blocks) {
|
2019-08-14 12:34:06 -07:00
|
|
|
for (int i = 0; i < p_blocks.size(); ++i) {
|
2020-01-26 14:34:26 -08:00
|
|
|
VoxelBlockRequest &r = p_blocks.write[i];
|
2019-08-14 12:34:06 -07:00
|
|
|
immerge_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:40:09 -07:00
|
|
|
bool VoxelStream::is_thread_safe() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VoxelStream::is_cloneable() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::_emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod) {
|
2019-04-29 13:57:39 -07:00
|
|
|
ERR_FAIL_COND(lod < 0);
|
|
|
|
emerge_block(out_buffer, Vector3i(origin_in_voxels), lod);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::_immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels, int lod) {
|
2019-04-29 13:57:39 -07:00
|
|
|
ERR_FAIL_COND(lod < 0);
|
|
|
|
immerge_block(buffer, Vector3i(origin_in_voxels), lod);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
|
2020-02-14 11:12:13 -08:00
|
|
|
int VoxelStream::get_used_channels_mask() const {
|
2020-08-02 10:57:08 -07:00
|
|
|
Variant ret;
|
|
|
|
if (try_call_script(this, VoxelStringNames::get_singleton()->get_used_channels_mask, nullptr, 0, &ret)) {
|
|
|
|
return ret;
|
2020-02-14 11:12:13 -08:00
|
|
|
}
|
2020-08-02 10:57:08 -07:00
|
|
|
return 0;
|
2020-02-14 11:12:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelStream::_get_used_channels_mask() const {
|
|
|
|
return get_used_channels_mask();
|
|
|
|
}
|
|
|
|
|
2019-08-25 09:40:19 -07:00
|
|
|
VoxelStream::Stats VoxelStream::get_statistics() const {
|
2019-08-16 16:46:24 -07:00
|
|
|
return _stats;
|
|
|
|
}
|
|
|
|
|
2020-08-14 12:33:09 -07:00
|
|
|
bool VoxelStream::has_script() const {
|
|
|
|
Ref<Script> s = get_script();
|
|
|
|
return s.is_valid();
|
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::_bind_methods() {
|
2020-07-11 10:05:26 -07:00
|
|
|
// TODO Make these proper virtual, it confuses C# bindings
|
2018-09-27 17:11:28 -07:00
|
|
|
// Note: C++ inheriting classes don't need to re-bind these, because they are bindings that call the actual virtual methods
|
2019-05-25 08:07:38 -07:00
|
|
|
ClassDB::bind_method(D_METHOD("emerge_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelStream::_emerge_block);
|
|
|
|
ClassDB::bind_method(D_METHOD("immerge_block", "buffer", "origin_in_voxels", "lod"), &VoxelStream::_immerge_block);
|
2020-02-14 11:12:13 -08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_used_channels_mask"), &VoxelStream::_get_used_channels_mask);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|