From a8448ef7c34833a388ee451784d61feaa7032fe5 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 18 Jun 2023 21:01:34 +0100 Subject: [PATCH] `get_class_static` returns StringName instead of String in GodotCpp --- meshers/blocky/types/voxel_blocky_type_library.cpp | 9 +++------ util/godot/classes/object.h | 14 ++++++++++++++ util/godot/core/string_name.h | 3 +++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/meshers/blocky/types/voxel_blocky_type_library.cpp b/meshers/blocky/types/voxel_blocky_type_library.cpp index be24dbedc..f5632a617 100644 --- a/meshers/blocky/types/voxel_blocky_type_library.cpp +++ b/meshers/blocky/types/voxel_blocky_type_library.cpp @@ -2,14 +2,11 @@ #include "../../../constants/voxel_string_names.h" #include "../../../util/container_funcs.h" #include "../../../util/godot/classes/json.h" +#include "../../../util/godot/classes/object.h" #include "../../../util/godot/classes/time.h" #include "../../../util/godot/core/array.h" #include "../../../util/godot/core/string.h" #include "../../../util/godot/core/typed_array.h" -#ifdef ZN_GODOT_EXTENSION -// For `MAKE_RESOURCE_TYPE_HINT` -#include "../../../util/godot/classes/object.h" -#endif #include "../../../util/profiling.h" #include "../../../util/string_funcs.h" #include "../voxel_blocky_model_cube.h" @@ -62,7 +59,7 @@ void VoxelBlockyTypeLibrary::bake() { for (size_t i = 0; i < _types.size(); ++i) { Ref type = _types[i]; ZN_ASSERT_CONTINUE_MSG( - type.is_valid(), format("{} at index {} is null", VoxelBlockyType::get_class_static(), i)); + type.is_valid(), format("{} at index {} is null", get_class_name_str(), i)); type->bake(baked_models, keys, material_indexer, nullptr); @@ -203,7 +200,7 @@ void VoxelBlockyTypeLibrary::get_configuration_warnings(PackedStringArray &out_w String sname = String(type->get_unique_name()).strip_edges(); if (sname.length() == 0) { out_warnings.push_back(String("{0} at index {1} has an empty name.") - .format(varray(VoxelBlockyType::get_class_static(), type_index))); + .format(varray(get_class_name_str(), type_index))); } type->get_configuration_warnings(out_warnings); diff --git a/util/godot/classes/object.h b/util/godot/classes/object.h index fa2581e12..9032ceec1 100644 --- a/util/godot/classes/object.h +++ b/util/godot/classes/object.h @@ -23,6 +23,20 @@ using namespace godot; namespace zylann { +// Get the name of a Godot class as a Godot String. +#if defined(ZN_GODOT) +template +inline String get_class_name_str() { + return T::get_class_static(); +} +#elif defined(ZN_GODOT_EXTENSION) +template +inline String get_class_name_str() { + // GodotCpp decided to use StringName instead + return String(T::get_class_static()); +} +#endif + // Turns out these functions are only used in editor for now. // They are generic, but I have to wrap them, otherwise GCC throws warnings-as-errors for them being unused. #ifdef TOOLS_ENABLED diff --git a/util/godot/core/string_name.h b/util/godot/core/string_name.h index 98b68a9f7..f57c2dd42 100644 --- a/util/godot/core/string_name.h +++ b/util/godot/core/string_name.h @@ -8,4 +8,7 @@ using namespace godot; #endif +// Also gave up trying to make an `operator<<(stringstream, StringName)` overload, the billion conversions it has (and +// does not have in GDExtension) makes it impossible to compile without ambiguity... + #endif // ZN_GODOT_STRING_NAME_H