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"
|
2019-04-28 09:58:29 -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());
|
2017-08-12 16:19:39 -07:00
|
|
|
ScriptInstance *script = get_script_instance();
|
|
|
|
if (script) {
|
2017-01-01 17:15:57 -08:00
|
|
|
// Call script to generate buffer
|
|
|
|
Variant arg1 = out_buffer;
|
2017-08-28 06:42:54 -07:00
|
|
|
Variant arg2 = origin_in_voxels.to_vec3();
|
2019-04-29 13:57:39 -07:00
|
|
|
Variant arg3 = lod;
|
|
|
|
const Variant *args[3] = { &arg1, &arg2, &arg3 };
|
2019-06-18 02:53:32 -07:00
|
|
|
Variant::CallError err;
|
2020-01-17 12:43:28 -08:00
|
|
|
script->call(VoxelStringNames::get_singleton()->emerge_block, args, 3, err);
|
2019-11-12 21:20:05 -08:00
|
|
|
ERR_FAIL_COND_MSG(err.error != Variant::CallError::CALL_OK,
|
2020-01-02 12:29:02 -08:00
|
|
|
"voxel_stream.cpp:emerge_block gave an error: " + String::num(err.error) +
|
|
|
|
", Argument: " + String::num(err.argument) +
|
|
|
|
", Expected type: " + Variant::get_type_name(err.expected));
|
2019-11-12 21:20:05 -08:00
|
|
|
// This had to be explicitely logged due to the usual GD debugger not working with threads
|
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());
|
2017-08-12 16:19:39 -07:00
|
|
|
ScriptInstance *script = get_script_instance();
|
|
|
|
if (script) {
|
2017-01-01 17:15:57 -08:00
|
|
|
// Call script to save buffer
|
|
|
|
Variant arg1 = buffer;
|
2017-08-28 06:42:54 -07:00
|
|
|
Variant arg2 = origin_in_voxels.to_vec3();
|
2019-04-29 13:57:39 -07:00
|
|
|
Variant arg3 = lod;
|
|
|
|
const Variant *args[3] = { &arg1, &arg2, &arg3 };
|
2019-06-18 02:53:32 -07:00
|
|
|
Variant::CallError err;
|
2020-01-17 12:43:28 -08:00
|
|
|
script->call(VoxelStringNames::get_singleton()->immerge_block, args, 3, err);
|
2019-11-12 21:20:05 -08:00
|
|
|
ERR_FAIL_COND_MSG(err.error != Variant::CallError::CALL_OK,
|
2020-01-02 12:29:02 -08:00
|
|
|
"voxel_stream.cpp:immerge_block gave an error: " + String::num(err.error) +
|
|
|
|
" Argument: " + String::num(err.argument) +
|
|
|
|
" Expected type: " + Variant::get_type_name(err.expected));
|
2019-11-12 21:20:05 -08:00
|
|
|
// This had to be explicitely logged due to the usual GD debugger not working with threads
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 12:34:06 -07:00
|
|
|
void VoxelStream::emerge_blocks(Vector<VoxelStream::BlockRequest> &p_blocks) {
|
|
|
|
// Default implementation. May matter for some stream types to optimize loading.
|
|
|
|
for (int i = 0; i < p_blocks.size(); ++i) {
|
|
|
|
BlockRequest &r = p_blocks.write[i];
|
|
|
|
emerge_block(r.voxel_buffer, r.origin_in_voxels, r.lod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelStream::immerge_blocks(Vector<VoxelStream::BlockRequest> &p_blocks) {
|
|
|
|
for (int i = 0; i < p_blocks.size(); ++i) {
|
|
|
|
BlockRequest &r = p_blocks.write[i];
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-25 09:40:19 -07:00
|
|
|
VoxelStream::Stats VoxelStream::get_statistics() const {
|
2019-08-16 16:46:24 -07:00
|
|
|
return _stats;
|
|
|
|
}
|
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
void VoxelStream::_bind_methods() {
|
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
|
2017-01-01 17:15:57 -08:00
|
|
|
|
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);
|
2017-01-01 17:15:57 -08:00
|
|
|
}
|