Skip to content

Commit 05ffa21

Browse files
committed
GDExtension: Add all Engine.get_version_info fields to get_godot_version
Added in a new `get_godot_version2` function with a new `GDExtensionGodotVersion2` to avoid breaking compatibility.
1 parent 394508d commit 05ffa21

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

core/extension/gdextension_interface.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,26 @@ GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name)
241241
return GDExtension::get_interface_function(p_name);
242242
}
243243

244+
#ifndef DISABLE_DEPRECATED
244245
static void gdextension_get_godot_version(GDExtensionGodotVersion *r_godot_version) {
245246
r_godot_version->major = VERSION_MAJOR;
246247
r_godot_version->minor = VERSION_MINOR;
247248
r_godot_version->patch = VERSION_PATCH;
248249
r_godot_version->string = VERSION_FULL_NAME;
249250
}
251+
#endif
252+
253+
static void gdextension_get_godot_version2(GDExtensionGodotVersion2 *r_godot_version) {
254+
r_godot_version->major = VERSION_MAJOR;
255+
r_godot_version->minor = VERSION_MINOR;
256+
r_godot_version->patch = VERSION_PATCH;
257+
r_godot_version->hex = VERSION_HEX;
258+
r_godot_version->status = VERSION_STATUS;
259+
r_godot_version->build = VERSION_BUILD;
260+
r_godot_version->hash = VERSION_HASH;
261+
r_godot_version->timestamp = VERSION_TIMESTAMP;
262+
r_godot_version->string = VERSION_FULL_NAME;
263+
}
250264

251265
// Memory Functions
252266
static void *gdextension_mem_alloc(size_t p_size) {
@@ -1666,7 +1680,10 @@ static void gdextension_editor_help_load_xml_from_utf8_chars(const char *p_data)
16661680
#define REGISTER_INTERFACE_FUNC(m_name) GDExtension::register_interface_function(#m_name, (GDExtensionInterfaceFunctionPtr) & gdextension_##m_name)
16671681

16681682
void gdextension_setup_interface() {
1683+
#ifndef DISABLE_DEPRECATED
16691684
REGISTER_INTERFACE_FUNC(get_godot_version);
1685+
#endif // DISABLE_DEPRECATED
1686+
REGISTER_INTERFACE_FUNC(get_godot_version2);
16701687
REGISTER_INTERFACE_FUNC(mem_alloc);
16711688
REGISTER_INTERFACE_FUNC(mem_realloc);
16721689
REGISTER_INTERFACE_FUNC(mem_free);

core/extension/gdextension_interface.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,39 @@ typedef struct {
790790
const char *string;
791791
} GDExtensionGodotVersion;
792792

793+
typedef struct {
794+
uint32_t major;
795+
uint32_t minor;
796+
uint32_t patch;
797+
uint32_t hex; // Full version encoded as hexadecimal with one byte (2 hex digits) per number (e.g. for "3.1.12" it would be 0x03010C)
798+
const char *status; // (e.g. "stable", "beta", "rc1", "rc2")
799+
const char *build; // (e.g. "custom_build")
800+
const char *hash; // Full Git commit hash.
801+
uint64_t timestamp; // Git commit date UNIX timestamp in seconds, or 0 if unavailable.
802+
const char *string; // (e.g. "Godot v3.1.4.stable.official.mono")
803+
} GDExtensionGodotVersion2;
804+
793805
/**
794806
* @name get_godot_version
795807
* @since 4.1
808+
* @deprecated in Godot 4.5. Use `get_godot_version2` instead.
796809
*
797810
* Gets the Godot version that the GDExtension was loaded into.
798811
*
799812
* @param r_godot_version A pointer to the structure to write the version information into.
800813
*/
801814
typedef void (*GDExtensionInterfaceGetGodotVersion)(GDExtensionGodotVersion *r_godot_version);
802815

816+
/**
817+
* @name get_godot_version2
818+
* @since 4.5
819+
*
820+
* Gets the Godot version that the GDExtension was loaded into.
821+
*
822+
* @param r_godot_version A pointer to the structure to write the version information into.
823+
*/
824+
typedef void (*GDExtensionInterfaceGetGodotVersion2)(GDExtensionGodotVersion2 *r_godot_version);
825+
803826
/* INTERFACE: Memory */
804827

805828
/**

0 commit comments

Comments
 (0)