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 443ead2
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 3 deletions.
21 changes: 21 additions & 0 deletions modifiers/godot/voxel_modifier_gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "../../util/math/conv.h"
#include "../voxel_modifier_sdf.h"

#ifdef TOOLS_ENABLED
#include "../../util/godot/core/packed_arrays.h"
#endif

namespace zylann::voxel::gd {

VoxelModifier::VoxelModifier() {
Expand Down Expand Up @@ -141,17 +145,34 @@ void VoxelModifier::_notification(int p_what) {
#ifdef TOOLS_ENABLED

#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray VoxelModifier::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelModifier::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_MINOR <= 2
PackedStringArray VoxelModifier::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelModifier::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return to_array(warnings);
}
#endif
#endif

void VoxelModifier::get_configuration_warnings(PackedStringArray &warnings) const {
Expand Down
12 changes: 12 additions & 0 deletions modifiers/godot/voxel_modifier_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "../../util/godot/classes/node_3d.h"
#include "../voxel_modifier.h"

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

namespace zylann::voxel {
namespace gd {

Expand All @@ -28,9 +32,17 @@ class VoxelModifier : 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
33 changes: 30 additions & 3 deletions terrain/fixed_lod/voxel_terrain_multiplayer_synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "../../util/string_funcs.h"
#include "voxel_terrain.h"

#ifdef TOOLS_ENABLED
#include "../../util/godot/core/packed_arrays.h"
#endif

namespace zylann::voxel {

VoxelTerrainMultiplayerSynchronizer::VoxelTerrainMultiplayerSynchronizer() {
Expand Down Expand Up @@ -233,12 +237,37 @@ void VoxelTerrainMultiplayerSynchronizer::_b_receive_area(PackedByteArray messag
#ifdef TOOLS_ENABLED

#if defined(ZN_GODOT)
#if GODOT_VERSION_MAJOR == 4 && GODOT_VERSION_MINOR <= 2
PackedStringArray VoxelTerrainMultiplayerSynchronizer::get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelTerrainMultiplayerSynchronizer::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_MINOR <= 2
PackedStringArray VoxelTerrainMultiplayerSynchronizer::_get_configuration_warnings() const {
#endif
PackedStringArray warnings;
get_configuration_warnings(warnings);
return warnings;
}
#else
Array VoxelTerrainMultiplayerSynchronizer::_get_configuration_warnings() const {
PackedStringArray warnings;
get_configuration_warnings(warnings);
return to_array(warnings);
}
#endif
#endif

void VoxelTerrainMultiplayerSynchronizer::get_configuration_warnings(PackedStringArray &warnings) const {
if (is_inside_tree()) {
if (_terrain == nullptr) {
warnings.append(ZN_TTR("This node must be child of {0}").format(varray(VoxelTerrain::get_class_static())));
Expand All @@ -255,8 +284,6 @@ PackedStringArray VoxelTerrainMultiplayerSynchronizer::_get_configuration_warnin
}
}
}

return warnings;
}

#endif
Expand Down
12 changes: 12 additions & 0 deletions terrain/fixed_lod/voxel_terrain_multiplayer_synchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <unordered_map>
#include <vector>

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

namespace zylann::voxel {

class VoxelTerrain;
Expand All @@ -23,9 +27,17 @@ class VoxelTerrainMultiplayerSynchronizer : public Node {

#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
void get_configuration_warnings(PackedStringArray &warnings) const;
#endif
Expand Down
18 changes: 18 additions & 0 deletions terrain/instancing/voxel_instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#ifdef TOOLS_ENABLED
#include "../../editor/camera_cache.h"
#include "../../util/godot/core/packed_arrays.h"
#endif

// Only needed for debug purposes, otherwise RenderingServer is used directly
Expand Down Expand Up @@ -2015,17 +2016,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_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);
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
21 changes: 21 additions & 0 deletions terrain/voxel_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "../util/godot/classes/script.h"
#include "../util/godot/core/string.h"

#ifdef TOOLS_ENABLED
#include "../util/godot/core/packed_arrays.h"
#endif

namespace zylann::voxel {

void VoxelNode::set_mesher(Ref<VoxelMesher> mesher) {
Expand Down Expand Up @@ -64,17 +68,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_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);
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 443ead2

Please sign in to comment.