godot_voxel/streams/voxel_stream.cpp

79 lines
2.6 KiB
C++
Raw Normal View History

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"
#include <core/script_language.h>
VoxelStream::VoxelStream() {
}
2019-05-25 08:07:38 -07:00
void VoxelStream::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod) {
ERR_FAIL_COND(out_buffer.is_null());
try_call_script(this, VoxelStringNames::get_singleton()->emerge_block, out_buffer, origin_in_voxels.to_vec3(), lod, nullptr);
}
2019-05-25 08:07:38 -07:00
void VoxelStream::immerge_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels, int lod) {
ERR_FAIL_COND(buffer.is_null());
try_call_script(this, VoxelStringNames::get_singleton()->immerge_block, buffer, origin_in_voxels.to_vec3(), lod, nullptr);
}
void VoxelStream::emerge_blocks(Vector<VoxelBlockRequest> &p_blocks) {
// Default implementation. May matter for some stream types to optimize loading.
for (int i = 0; i < p_blocks.size(); ++i) {
VoxelBlockRequest &r = p_blocks.write[i];
emerge_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
}
}
void VoxelStream::immerge_blocks(Vector<VoxelBlockRequest> &p_blocks) {
for (int i = 0; i < p_blocks.size(); ++i) {
VoxelBlockRequest &r = p_blocks.write[i];
immerge_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
}
}
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);
}
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);
}
2020-02-14 11:12:13 -08:00
int VoxelStream::get_used_channels_mask() const {
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
}
return 0;
2020-02-14 11:12:13 -08:00
}
int VoxelStream::_get_used_channels_mask() const {
return get_used_channels_mask();
}
VoxelStream::Stats VoxelStream::get_statistics() const {
return _stats;
}
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() {
// TODO Make these proper virtual, it confuses C# bindings
// 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);
}