2020-10-31 15:11:25 -07:00
|
|
|
#include "voxel_stream_script.h"
|
2021-02-21 15:58:00 -08:00
|
|
|
#include "../constants/voxel_string_names.h"
|
2021-02-17 12:34:35 -08:00
|
|
|
#include "../util/godot/funcs.h"
|
2020-10-31 15:11:25 -07:00
|
|
|
|
2022-01-09 14:13:10 -08:00
|
|
|
namespace zylann::voxel {
|
2022-01-08 14:49:48 -08:00
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
VoxelStream::Result VoxelStreamScript::load_voxel_block(
|
2021-12-13 13:38:10 -08:00
|
|
|
VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) {
|
2021-01-17 09:18:05 -08:00
|
|
|
Variant output;
|
2021-09-25 20:14:50 -07:00
|
|
|
// Create a temporary wrapper so Godot can pass it to scripts
|
|
|
|
Ref<VoxelBuffer> buffer_wrapper;
|
2021-12-13 13:38:10 -08:00
|
|
|
buffer_wrapper.instantiate();
|
2021-09-25 20:14:50 -07:00
|
|
|
buffer_wrapper->get_buffer().copy_format(out_buffer);
|
|
|
|
buffer_wrapper->get_buffer().create(out_buffer.get_size());
|
2021-12-13 13:38:10 -08:00
|
|
|
|
|
|
|
int res;
|
2022-01-15 20:21:02 -08:00
|
|
|
if (GDVIRTUAL_CALL(_load_voxel_block, buffer_wrapper, origin_in_voxels, lod, res)) {
|
2022-01-16 07:28:10 -08:00
|
|
|
// Check if the return enum is valid
|
2021-01-17 09:18:05 -08:00
|
|
|
ERR_FAIL_INDEX_V(res, _RESULT_COUNT, RESULT_ERROR);
|
2022-01-16 07:28:10 -08:00
|
|
|
// If the block was found, grab its data from the script-facing object to our internal buffer
|
|
|
|
if (res == RESULT_BLOCK_FOUND) {
|
|
|
|
buffer_wrapper->get_buffer().move_to(out_buffer);
|
|
|
|
}
|
2021-12-13 13:38:10 -08:00
|
|
|
return Result(res);
|
|
|
|
} else {
|
2022-01-16 07:28:10 -08:00
|
|
|
// The function wasn't found or failed?
|
2021-12-13 13:38:10 -08:00
|
|
|
WARN_PRINT_ONCE("VoxelStreamScript::_emerge_block is unimplemented!");
|
2021-01-17 09:18:05 -08:00
|
|
|
}
|
2021-12-13 13:38:10 -08:00
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
return RESULT_ERROR;
|
2020-10-31 15:11:25 -07:00
|
|
|
}
|
|
|
|
|
2022-01-15 20:21:02 -08:00
|
|
|
void VoxelStreamScript::save_voxel_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) {
|
2021-09-25 20:14:50 -07:00
|
|
|
Ref<VoxelBuffer> buffer_wrapper;
|
2021-12-13 13:38:10 -08:00
|
|
|
buffer_wrapper.instantiate();
|
2021-09-25 20:14:50 -07:00
|
|
|
buffer.duplicate_to(buffer_wrapper->get_buffer(), true);
|
2022-01-15 20:21:02 -08:00
|
|
|
if (!GDVIRTUAL_CALL(_save_voxel_block, buffer_wrapper, origin_in_voxels, lod)) {
|
2021-12-13 13:38:10 -08:00
|
|
|
WARN_PRINT_ONCE("VoxelStreamScript::_immerge_block is unimplemented!");
|
|
|
|
}
|
2020-10-31 15:11:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelStreamScript::get_used_channels_mask() const {
|
2021-12-13 13:38:10 -08:00
|
|
|
int mask = 0;
|
|
|
|
if (!GDVIRTUAL_CALL(_get_used_channels_mask, mask)) {
|
|
|
|
WARN_PRINT_ONCE("VoxelStreamScript::_get_used_channels_mask is unimplemented!");
|
2020-10-31 15:11:25 -07:00
|
|
|
}
|
2021-12-13 13:38:10 -08:00
|
|
|
return mask;
|
2020-10-31 15:11:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelStreamScript::_bind_methods() {
|
2021-12-13 13:38:10 -08:00
|
|
|
// TODO Test if GDVIRTUAL can print errors properly when GDScript fails inside a different thread.
|
2022-01-15 20:21:02 -08:00
|
|
|
GDVIRTUAL_BIND(_load_voxel_block, "out_buffer", "origin_in_voxels", "lod");
|
|
|
|
GDVIRTUAL_BIND(_save_voxel_block, "buffer", "origin_in_voxels", "lod");
|
2021-12-13 13:38:10 -08:00
|
|
|
GDVIRTUAL_BIND(_get_used_channels_mask);
|
|
|
|
|
|
|
|
// BIND_VMETHOD(MethodInfo("_emerge_block",
|
|
|
|
// PropertyInfo(Variant::OBJECT, "out_buffer", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "VoxelBuffer"),
|
|
|
|
// PropertyInfo(Variant::VECTOR3, "origin_in_voxels"), PropertyInfo(Variant::INT, "lod")));
|
2020-10-31 15:11:25 -07:00
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
// BIND_VMETHOD(MethodInfo("_immerge_block",
|
|
|
|
// PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "VoxelBuffer"),
|
|
|
|
// PropertyInfo(Variant::VECTOR3, "origin_in_voxels"), PropertyInfo(Variant::INT, "lod")));
|
2020-10-31 15:11:25 -07:00
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
// BIND_VMETHOD(MethodInfo(Variant::INT, "_get_used_channels_mask"));
|
2020-10-31 15:11:25 -07:00
|
|
|
}
|
2022-01-09 14:13:10 -08:00
|
|
|
|
|
|
|
} // namespace zylann::voxel
|