Skip to content

Commit

Permalink
Some fixes for extension build
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 9, 2024
1 parent d8f5293 commit c183a80
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 12 additions & 2 deletions edition/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#include "../util/containers/dynamic_bitset.h"
#include "../util/containers/span.h"
#include "../util/containers/std_vector.h"
#include "../util/godot/core/random_pcg.h"
#include "../util/profiling.h"
#include "../util/string/format.h"

#ifdef ZN_GODOT_EXTENSION
using namespace godot;
#endif

namespace zylann::voxel {

void copy_from_chunked_storage( //
Expand Down Expand Up @@ -257,19 +262,24 @@ void run_blocky_random_tick(
batch_count,
&cb_self,
[](void *self, Vector3i pos, int64_t val) {
const CallbackData *cd = reinterpret_cast<const CallbackData *>(self);
#ifdef ZN_GODOT
const Variant vpos = pos;
const Variant vv = val;
const Variant *args[2];
args[0] = &vpos;
args[1] = &vv;
Callable::CallError error;
Variant retval; // We don't care about the return value, Callable API requires it
const CallbackData *cd = reinterpret_cast<const CallbackData *>(self);
cd->callable.callp(args, 2, retval, error);
// TODO I would really like to know what's the correct way to report such errors...
// Examples I found in the engine are inconsistent
ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, false);
// Return if it fails, we don't want an error spam
// Return if it fails, we don't want an error spam
#elif ZN_GODOT_EXTENSION
// TODO GDX: No way to detect or report errors when calling a Callable. Do I need to?
cd->callable.call(pos, val);
#endif
return true;
}
);
Expand Down
2 changes: 1 addition & 1 deletion edition/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../util/profiling.h"

ZN_GODOT_FORWARD_DECLARE(class Callable);
ZN_GODOT_FORWARD_DECLARE(class RandomPCG);

namespace zylann::voxel {

Expand Down Expand Up @@ -226,7 +227,6 @@ AABB get_path_aabb(Span<const Vector3> positions, Span<const float> radii);

class VoxelData;
class VoxelBlockyLibraryBase;
// class RandomPCG;

// For easier unit testing (the regular one needs a terrain setup etc, harder to test atm)
// The `_static` suffix is because it otherwise conflicts with the non-static method when registering the class
Expand Down
16 changes: 9 additions & 7 deletions edition/voxel_tool_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,11 @@ void VoxelToolTerrain::for_each_voxel_metadata_in_area(AABB voxel_area, const Ca
voxels_ptr->for_each_voxel_metadata_in_area(
rel_voxel_box,
[&callback, block_origin](Vector3i rel_pos, const VoxelMetadata &meta) {
Variant v = godot::get_as_variant(meta);
const Variant key = rel_pos + block_origin;
const Variant *args[2] = { &key, &v };
const Variant v = godot::get_as_variant(meta);
const Vector3i key = rel_pos + block_origin;
#ifdef ZN_GODOT
const Variant key_v = key;
const Variant *args[2] = { &key_v, &v };
Callable::CallError err;
Variant retval; // We don't care about the return value, Callable API requires it
callback.callp(args, 2, retval, err);
Expand All @@ -447,10 +449,10 @@ void VoxelToolTerrain::for_each_voxel_metadata_in_area(AABB voxel_area, const Ca
err.error != Callable::CallError::CALL_OK,
String("Callable failed at {0}").format(varray(key))
);

// TODO Can't provide detailed error because FuncRef doesn't give us access to the object
// ERR_FAIL_COND_MSG(err.error != Variant::CallError::CALL_OK, false,
// Variant::get_call_error_text(callback->get_object(), method_name, nullptr, 0, err));
#elif defined(ZN_GODOT_EXTENSION)
// TODO GDX: No way to detect or report errors when calling a Callable. Do I need to?
callback.call(key, v);
#endif
}
);
});
Expand Down

0 comments on commit c183a80

Please sign in to comment.