Skip to content

Commit

Permalink
Fix compiling with latest Godot master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Feb 10, 2024
1 parent 2fa6cd0 commit 092e43e
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 0 deletions.
17 changes: 17 additions & 0 deletions terrain/instancing/voxel_instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,17 +2015,34 @@ bool VoxelInstancer::debug_get_draw_flag(DebugDrawFlag flag_index) const {
#ifdef TOOLS_ENABLED

#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray VoxelInstancer::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelInstancer::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
// TODO Eventually make use of new features introduced in Godot 4.3
return to_array(warnings);
}
#endif
#elif defined(ZN_GODOT_EXTENSION)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MAJOR <= 2
PackedStringArray VoxelInstancer::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelInstancer::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return to_array(warnings);
}
#endif
#endif

void VoxelInstancer::get_configuration_warnings(PackedStringArray &warnings) const {
Expand Down
9 changes: 9 additions & 0 deletions terrain/instancing/voxel_instancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifdef TOOLS_ENABLED
#include "../../editor/voxel_debug.h"
#include "../../util/godot/core/version.h"
#endif

//#include <scene/resources/material.h> // Included by node.h lol
Expand Down Expand Up @@ -114,9 +115,17 @@ class VoxelInstancer : public Node3D, public VoxelInstanceLibrary::IListener {

#ifdef TOOLS_ENABLED
#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray get_configuration_warnings() const override;
#else
Array get_configuration_warnings() const override;
#endif
#elif defined(ZN_GODOT_EXTENSION)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray _get_configuration_warnings() const override;
#else
Array _get_configuration_warnings() const override;
#endif
#endif
virtual void get_configuration_warnings(PackedStringArray &warnings) const;
#endif
Expand Down
17 changes: 17 additions & 0 deletions terrain/voxel_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,34 @@ Ref<VoxelTool> VoxelNode::get_voxel_tool() {
#ifdef TOOLS_ENABLED

#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray VoxelNode::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelNode::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
// TODO Eventually make use of new features introduced in Godot 4.3
return to_array(warnings);
}
#endif
#elif defined(ZN_GODOT_EXTENSION)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MAJOR <= 2
PackedStringArray VoxelNode::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelNode::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return to_array(warnings);
}
#endif
#endif

void VoxelNode::get_configuration_warnings(PackedStringArray &warnings) const {
Expand Down
11 changes: 11 additions & 0 deletions terrain/voxel_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "../streams/voxel_stream.h"
#include "../util/godot/classes/geometry_instance_3d.h"
#include "../util/godot/classes/node_3d.h"
#ifdef TOOLS_ENABLED
#include "../util/godot/core/version.h"
#endif

namespace zylann::voxel {

Expand Down Expand Up @@ -45,9 +48,17 @@ class VoxelNode : public Node3D {

#ifdef TOOLS_ENABLED
#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray get_configuration_warnings() const override;
#else
Array get_configuration_warnings() const override;
#endif
#elif defined(ZN_GODOT_EXTENSION)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray _get_configuration_warnings() const override;
#else
Array _get_configuration_warnings() const override;
#endif
#endif
virtual void get_configuration_warnings(PackedStringArray &warnings) const;
#endif
Expand Down
19 changes: 19 additions & 0 deletions util/godot/core/packed_arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "../../math/conv.h"
#include "../../profiling.h"

#ifdef TOOLS_ENABLED
#include "packed_string_array.h"
#endif

namespace zylann {

void copy_to(PackedVector3Array &dst, const std::vector<Vector3f> &src) {
Expand Down Expand Up @@ -105,4 +109,19 @@ void copy_to(Span<float> dst, const PackedFloat32Array &src) {
memcpy(dst.data(), src_data, src_size * sizeof(float));
}

#ifdef TOOLS_ENABLED

Array to_array(const PackedStringArray &src) {
Array dst;
const int size = src.size();
dst.resize(size);
const String *src_p = src.ptr();
for (int i = 0; i < size; ++i) {
dst[i] = src_p[i];
}
return dst;
}

#endif

} // namespace zylann
10 changes: 10 additions & 0 deletions util/godot/core/packed_arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <cstdint>
#include <vector>

#ifdef TOOLS_ENABLED
#include "../macros.h"
#include "array.h"
#include "packed_string_array_fwd.h"
#endif

namespace zylann {

// Specialized copy functions for vectors because they use `real_t`, which can be either `float` or `double`
Expand Down Expand Up @@ -82,6 +88,10 @@ inline Span<const uint8_t> to_span(const PackedByteArray &a) {
return Span<const uint8_t>(a.ptr(), a.size());
}

#ifdef TOOLS_ENABLED
Array to_array(const PackedStringArray &src);
#endif

} // namespace zylann

#endif // ZN_GODOT_PACKED_ARRAYS_H
11 changes: 11 additions & 0 deletions util/godot/core/packed_string_array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ZN_GODOT_PACKED_STRING_ARRAY_H
#define ZN_GODOT_PACKED_STRING_ARRAY_H

#if defined(ZN_GODOT)
#include <core/variant/variant.h>
#elif defined(ZN_GODOT_EXTENSION)
#include <godot_cpp/variant/packed_string_array.hpp>
using namespace godot;
#endif

#endif // ZN_GODOT_PACKED_STRING_ARRAY_H
17 changes: 17 additions & 0 deletions util/godot/core/packed_string_array_fwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ZN_GODOT_PACKED_STRING_ARRAY_FWD_H
#define ZN_GODOT_PACKED_STRING_ARRAY_FWD_H

#if defined(ZN_GODOT)
class String;

template <typename T>
class Vector;
typedef Vector<String> PackedStringArray;

#elif defined(ZN_GODOT_EXTENSION)
#include "../macros.h"
ZN_GODOT_FORWARD_DECLARE(PackedStringArray);

#endif

#endif // ZN_GODOT_PACKED_STRING_ARRAY_FWD_H

0 comments on commit 092e43e

Please sign in to comment.