Skip to content

Commit

Permalink
get_class_static returns StringName instead of String in GodotCpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 18, 2023
1 parent e5c875e commit a8448ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 3 additions & 6 deletions meshers/blocky/types/voxel_blocky_type_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -62,7 +59,7 @@ void VoxelBlockyTypeLibrary::bake() {
for (size_t i = 0; i < _types.size(); ++i) {
Ref<VoxelBlockyType> 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<VoxelBlockyType>(), i));

type->bake(baked_models, keys, material_indexer, nullptr);

Expand Down Expand Up @@ -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<VoxelBlockyType>(), type_index)));
}

type->get_configuration_warnings(out_warnings);
Expand Down
14 changes: 14 additions & 0 deletions util/godot/classes/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
inline String get_class_name_str() {
return T::get_class_static();
}
#elif defined(ZN_GODOT_EXTENSION)
template <typename T>
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
Expand Down
3 changes: 3 additions & 0 deletions util/godot/core/string_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a8448ef

Please sign in to comment.