Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,25 @@ def generate_gdextension_interface_loader_header(data):
versions = sorted(data.keys())
for version in versions:
(major, minor) = version.split(".")
result.append(f"// Godot 4.{minor} or newer.")
result.append(f"#if GODOT_VERSION_MINOR >= {minor}")
result.append(f"// Godot {major}.{minor} or newer.")
result.append(f"#if GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")

for func in data[version]:
name = func["name"]
fn = gdextension_interface_type_name(name)

if "deprecated" in func:
(deprecated_major, deprecated_minor) = func["deprecated"]["since"].split(".")
result.append(f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION_MINOR < {deprecated_minor}")
result.append(
f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION < 0x{deprecated_major.zfill(2)}{deprecated_minor.zfill(2)}00"
)

result.append(f'extern "C" {fn} {name};')

if "deprecated" in func:
result.append("#endif")

result.append(f"#endif // GODOT_VERSION_MINOR >= {minor}")
result.append(f"#endif // GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")
result.append("")

result.append("} // namespace gdextension_interface")
Expand Down Expand Up @@ -426,23 +428,25 @@ def generate_gdextension_interface_loader_source(data):

for version in versions:
(major, minor) = version.split(".")
result.append(f"// Godot 4.{minor} or newer.")
result.append(f"#if GODOT_VERSION_MINOR >= {minor}")
result.append(f"// Godot {major}.{minor} or newer.")
result.append(f"#if GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")

for func in data[version]:
name = func["name"]
fn = gdextension_interface_type_name(name)

if "deprecated" in func:
(deprecated_major, deprecated_minor) = func["deprecated"]["since"].split(".")
result.append(f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION_MINOR < {deprecated_minor}")
result.append(
f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION < 0x{deprecated_major.zfill(2)}{deprecated_minor.zfill(2)}00"
)

result.append(f"{fn} {name} = nullptr;")

if "deprecated" in func:
result.append("#endif")

result.append(f"#endif // GODOT_VERSION_MINOR >= {minor}")
result.append(f"#endif // GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")
result.append("")

result.append("} // namespace gdextension_interface")
Expand All @@ -454,8 +458,8 @@ def generate_gdextension_interface_loader_source(data):

for version in versions:
(major, minor) = version.split(".")
result.append(f"\t// Godot 4.{minor} or newer.")
result.append(f"#if GODOT_VERSION_MINOR >= {minor}")
result.append(f"\t// Godot {major}.{minor} or newer.")
result.append(f"#if GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")

for func in data[version]:
name = func["name"]
Expand All @@ -466,14 +470,16 @@ def generate_gdextension_interface_loader_source(data):

if "deprecated" in func:
(deprecated_major, deprecated_minor) = func["deprecated"]["since"].split(".")
result.append(f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION_MINOR < {deprecated_minor}")
result.append(
f"#if !defined(DISABLE_DEPRECATED) || GODOT_VERSION < 0x{deprecated_major.zfill(2)}{deprecated_minor.zfill(2)}00"
)

result.append(f"\tLOAD_PROC_ADDRESS({name}, {fn});")

if "deprecated" in func:
result.append("#endif")

result.append(f"#endif // GODOT_VERSION_MINOR >= {minor}")
result.append(f"#endif // GODOT_VERSION >= 0x{major.zfill(2)}{minor.zfill(2)}00")
result.append("")

result.append("\treturn true;")
Expand Down Expand Up @@ -1138,7 +1144,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
if class_name == "Dictionary":
result.append("\tconst Variant &operator[](const Variant &p_key) const;")
result.append("\tVariant &operator[](const Variant &p_key);")
result.append("#if GODOT_VERSION_MINOR >= 4")
result.append("#if GODOT_VERSION >= 0x040400")
result.append(
"\tvoid set_typed(uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script);"
)
Expand Down Expand Up @@ -2332,6 +2338,10 @@ def generate_version_header(api, output_dir):

header.append("")

header.append(
"#define GODOT_VERSION 0x10000 * GODOT_VERSION_MAJOR + 0x100 * GODOT_VERSION_MINOR + GODOT_VERSION_PATCH"
)

with header_file_path.open("w+", encoding="utf-8") as header_file:
header_file.write("\n".join(header))

Expand Down
28 changes: 14 additions & 14 deletions include/godot_cpp/core/class_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ class ClassDB {
static void _register_class(bool p_virtual = false, bool p_exposed = true, bool p_runtime = false);

template <typename T>
#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
static GDExtensionObjectPtr _create_instance_func(void *data, GDExtensionBool p_notify_postinitialize) {
#else
static GDExtensionObjectPtr _create_instance_func(void *data) {
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
if constexpr (!std::is_abstract_v<T>) {
Wrapped::_set_construct_info<T>();
#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
T *new_object = new ("", "") T;
if (p_notify_postinitialize) {
new_object->_postinitialize();
}
#else
T *new_object = memnew(T);
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
return new_object->_owner;
} else {
return nullptr;
Expand Down Expand Up @@ -203,11 +203,11 @@ class ClassDB {

static MethodBind *get_method(const StringName &p_class, const StringName &p_method);

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
static GDExtensionClassCallVirtual get_virtual_func(void *p_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash);
#else
static GDExtensionClassCallVirtual get_virtual_func(void *p_userdata, GDExtensionConstStringNamePtr p_name);
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400

static const GDExtensionInstanceBindingCallbacks *get_instance_binding_callbacks(const StringName &p_class);

Expand Down Expand Up @@ -255,9 +255,9 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
class_register_order.push_back(cl.name);

// Register this class with Godot
#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
GDExtensionClassCreationInfo5 class_info = {
#elif GODOT_VERSION_MINOR >= 4
#elif GODOT_VERSION >= 0x040400
GDExtensionClassCreationInfo4 class_info = {
#else
GDExtensionClassCreationInfo3 class_info = {
Expand All @@ -266,9 +266,9 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
is_abstract, // GDExtensionBool is_abstract;
p_exposed, // GDExtensionBool is_exposed;
p_runtime, // GDExtensionBool is_runtime;
#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
nullptr, // GDExtensionConstStringPtr icon_path;
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
T::set_bind, // GDExtensionClassSet set_func;
T::get_bind, // GDExtensionClassGet get_func;
T::has_get_property_list() ? T::get_property_list_bind : nullptr, // GDExtensionClassGetPropertyList get_property_list_func;
Expand All @@ -286,15 +286,15 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
&ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func;
nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func;
#if GODOT_VERSION_MINOR <= 3
#if GODOT_VERSION <= 0x040300
nullptr, // GDExtensionClassGetRID get_rid;
#endif // GODOT_VERSION_MINOR <= 3
#endif // GODOT_VERSION <= 0x040300
(void *)&T::get_class_static(), // void *class_userdata;
};

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
::godot::gdextension_interface::classdb_register_extension_class5(::godot::gdextension_interface::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info);
#elif GODOT_VERSION_MINOR >= 4
#elif GODOT_VERSION >= 0x040400
::godot::gdextension_interface::classdb_register_extension_class4(::godot::gdextension_interface::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info);
#else
::godot::gdextension_interface::classdb_register_extension_class3(::godot::gdextension_interface::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info);
Expand Down
6 changes: 3 additions & 3 deletions include/godot_cpp/godot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" GDExtensionInterfaceGetProcAddress get_proc_address;
extern "C" GDExtensionClassLibraryPtr library;
extern "C" void *token;

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
extern "C" GDExtensionGodotVersion2 godot_version;
#else
extern "C" GDExtensionGodotVersion godot_version;
Expand Down Expand Up @@ -73,7 +73,7 @@ class GDExtensionBinding {
GDExtensionInitializationLevel minimum_initialization_level = GDEXTENSION_INITIALIZATION_CORE;
Callback init_callback = nullptr;
Callback terminate_callback = nullptr;
#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
GDExtensionMainLoopCallbacks main_loop_callbacks = {};

inline bool has_main_loop_callbacks() const {
Expand Down Expand Up @@ -114,7 +114,7 @@ class GDExtensionBinding {
void register_terminator(Callback p_init) const;
void set_minimum_library_initialization_level(ModuleInitializationLevel p_level) const;

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
// Register a callback that is called after all initialization levels when Godot is fully initialized.
void register_startup_callback(GDExtensionMainLoopStartupCallback p_callback) const;
// Register a callback that is called for every process frame. This will run after all `_process()` methods on Node, and before `ScriptServer::frame()`.
Expand Down
4 changes: 2 additions & 2 deletions include/godot_cpp/variant/typed_dictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include <godot_cpp/core/version.hpp>

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400

#include <godot_cpp/core/type_info.hpp>
#include <godot_cpp/templates/pair.hpp>
Expand Down Expand Up @@ -470,4 +470,4 @@ MAKE_TYPED_DICTIONARY_INFO(IPAddress, Variant::STRING)

#else
#error "TypedDictionary is only supported when targeting Godot 4.4+"
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
4 changes: 2 additions & 2 deletions include/godot_cpp/variant/variant_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include <godot_cpp/core/version.hpp>

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400

#include <gdextension_interface.h>
#include <godot_cpp/variant/variant.hpp>
Expand Down Expand Up @@ -509,4 +509,4 @@ struct VariantDefaultInitializer {

} // namespace godot

#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
6 changes: 3 additions & 3 deletions src/classes/wrapped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Wrapped::_postinitialize() {
Wrapped::_constructing_mutex.unlock();
#endif

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
Object *obj = dynamic_cast<Object *>(this);
if (obj) {
obj->notification(Object::NOTIFICATION_POSTINITIALIZE);
Expand All @@ -70,7 +70,7 @@ void Wrapped::_postinitialize() {
if (_is_extension_class()) {
_notificationv(Object::NOTIFICATION_POSTINITIALIZE);
}
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
}

Wrapped::Wrapped(const StringName &p_godot_class) {
Expand All @@ -81,7 +81,7 @@ Wrapped::Wrapped(const StringName &p_godot_class) {
} else
#endif
{
#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
_owner = ::godot::gdextension_interface::classdb_construct_object2(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
#else
_owner = ::godot::gdextension_interface::classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
Expand Down
8 changes: 4 additions & 4 deletions src/core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ void ClassDB::bind_integer_constant(const StringName &p_class_name, const String
::godot::gdextension_interface::classdb_register_extension_class_integer_constant(::godot::gdextension_interface::library, p_class_name._native_ptr(), p_enum_name._native_ptr(), p_constant_name._native_ptr(), p_constant_value, p_is_bitfield);
}

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
GDExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash) {
#else
GDExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, GDExtensionConstStringNamePtr p_name) {
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
// This is called by Godot the first time it calls a virtual function, and it caches the result, per object instance.
// Because of this, it can happen from different threads at once.
// It should be ok not using any mutex as long as we only READ data.
Expand All @@ -304,11 +304,11 @@ GDExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, GDExtens
while (type != nullptr) {
AHashMap<StringName, ClassInfo::VirtualMethod>::ConstIterator method_it = type->virtual_methods.find(*name);

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
if (method_it != type->virtual_methods.end() && method_it->value.hash == p_hash) {
#else
if (method_it != type->virtual_methods.end()) {
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400
return method_it->value.func;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace godot {

void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
#if GODOT_VERSION_MINOR >= 6
#if GODOT_VERSION >= 0x040600
return ::godot::gdextension_interface::mem_alloc2(p_bytes, p_pad_align);
#else
void *mem = ::godot::gdextension_interface::mem_alloc(p_bytes + (p_pad_align ? DATA_OFFSET : 0));
Expand All @@ -58,7 +58,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
return nullptr;
}

#if GODOT_VERSION_MINOR >= 6
#if GODOT_VERSION >= 0x040600
return ::godot::gdextension_interface::mem_realloc2(p_memory, p_bytes, p_pad_align);
#else
uint8_t *mem = (uint8_t *)p_memory;
Expand All @@ -74,7 +74,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
}

void Memory::free_static(void *p_ptr, bool p_pad_align) {
#if GODOT_VERSION_MINOR >= 6
#if GODOT_VERSION >= 0x040600
::godot::gdextension_interface::mem_free2(p_ptr, p_pad_align);
#else
uint8_t *mem = (uint8_t *)p_ptr;
Expand Down
10 changes: 5 additions & 5 deletions src/godot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GDExtensionInterfaceGetProcAddress get_proc_address = nullptr;
GDExtensionClassLibraryPtr library = nullptr;
void *token = nullptr;

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
GDExtensionGodotVersion2 godot_version = {};
#else
GDExtensionGodotVersion godot_version = {};
Expand Down Expand Up @@ -146,7 +146,7 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
::godot::gdextension_interface::library = p_library;
::godot::gdextension_interface::token = p_library;

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
LOAD_PROC_ADDRESS(get_godot_version2, GDExtensionInterfaceGetGodotVersion2);
::godot::gdextension_interface::get_godot_version2(&::godot::gdextension_interface::godot_version);
#else
Expand Down Expand Up @@ -213,14 +213,14 @@ void GDExtensionBinding::initialize_level(void *p_userdata, GDExtensionInitializ
}
level_initialized[p_level]++;

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
if ((ModuleInitializationLevel)p_level == MODULE_INITIALIZATION_LEVEL_CORE && init_data && init_data->has_main_loop_callbacks()) {
::godot::gdextension_interface::register_main_loop_callbacks(::godot::gdextension_interface::library, &init_data->main_loop_callbacks);
}
#endif

if ((ModuleInitializationLevel)p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
::godot::gdextension_interface::editor_register_get_classes_used_callback(::godot::gdextension_interface::library, &ClassDB::_editor_get_classes_used_callback);
#endif

Expand Down Expand Up @@ -291,7 +291,7 @@ void GDExtensionBinding::InitObject::set_minimum_library_initialization_level(Mo
init_data->minimum_initialization_level = static_cast<GDExtensionInitializationLevel>(p_level);
}

#if GODOT_VERSION_MINOR >= 5
#if GODOT_VERSION >= 0x040500
void GDExtensionBinding::InitObject::register_startup_callback(GDExtensionMainLoopStartupCallback p_callback) const {
init_data->main_loop_callbacks.startup_func = p_callback;
}
Expand Down
4 changes: 2 additions & 2 deletions src/variant/packed_arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ Variant &Dictionary::operator[](const Variant &p_key) {
return *var;
}

#if GODOT_VERSION_MINOR >= 4
#if GODOT_VERSION >= 0x040400
void Dictionary::set_typed(uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script) {
// p_key_type/p_value_type are not Variant::Type so that header doesn't depend on <variant.hpp>.
::godot::gdextension_interface::dictionary_set_typed((GDExtensionTypePtr *)this, (GDExtensionVariantType)p_key_type, (GDExtensionConstStringNamePtr)&p_key_class_name, (GDExtensionConstVariantPtr)&p_key_script,
(GDExtensionVariantType)p_value_type, (GDExtensionConstStringNamePtr)&p_value_class_name, (GDExtensionConstVariantPtr)&p_value_script);
}
#endif // GODOT_VERSION_MINOR >= 4
#endif // GODOT_VERSION >= 0x040400

} // namespace godot
Loading
Loading