Browse Source

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.
Raul Santos 6 months ago
parent
commit
05ffa218f3
2 changed files with 40 additions and 0 deletions
  1. 17 0
      core/extension/gdextension_interface.cpp
  2. 23 0
      core/extension/gdextension_interface.h

+ 17 - 0
core/extension/gdextension_interface.cpp

@@ -241,12 +241,26 @@ GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name)
 	return GDExtension::get_interface_function(p_name);
 	return GDExtension::get_interface_function(p_name);
 }
 }
 
 
+#ifndef DISABLE_DEPRECATED
 static void gdextension_get_godot_version(GDExtensionGodotVersion *r_godot_version) {
 static void gdextension_get_godot_version(GDExtensionGodotVersion *r_godot_version) {
 	r_godot_version->major = VERSION_MAJOR;
 	r_godot_version->major = VERSION_MAJOR;
 	r_godot_version->minor = VERSION_MINOR;
 	r_godot_version->minor = VERSION_MINOR;
 	r_godot_version->patch = VERSION_PATCH;
 	r_godot_version->patch = VERSION_PATCH;
 	r_godot_version->string = VERSION_FULL_NAME;
 	r_godot_version->string = VERSION_FULL_NAME;
 }
 }
+#endif
+
+static void gdextension_get_godot_version2(GDExtensionGodotVersion2 *r_godot_version) {
+	r_godot_version->major = VERSION_MAJOR;
+	r_godot_version->minor = VERSION_MINOR;
+	r_godot_version->patch = VERSION_PATCH;
+	r_godot_version->hex = VERSION_HEX;
+	r_godot_version->status = VERSION_STATUS;
+	r_godot_version->build = VERSION_BUILD;
+	r_godot_version->hash = VERSION_HASH;
+	r_godot_version->timestamp = VERSION_TIMESTAMP;
+	r_godot_version->string = VERSION_FULL_NAME;
+}
 
 
 // Memory Functions
 // Memory Functions
 static void *gdextension_mem_alloc(size_t p_size) {
 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)
 #define REGISTER_INTERFACE_FUNC(m_name) GDExtension::register_interface_function(#m_name, (GDExtensionInterfaceFunctionPtr) & gdextension_##m_name)
 #define REGISTER_INTERFACE_FUNC(m_name) GDExtension::register_interface_function(#m_name, (GDExtensionInterfaceFunctionPtr) & gdextension_##m_name)
 
 
 void gdextension_setup_interface() {
 void gdextension_setup_interface() {
+#ifndef DISABLE_DEPRECATED
 	REGISTER_INTERFACE_FUNC(get_godot_version);
 	REGISTER_INTERFACE_FUNC(get_godot_version);
+#endif // DISABLE_DEPRECATED
+	REGISTER_INTERFACE_FUNC(get_godot_version2);
 	REGISTER_INTERFACE_FUNC(mem_alloc);
 	REGISTER_INTERFACE_FUNC(mem_alloc);
 	REGISTER_INTERFACE_FUNC(mem_realloc);
 	REGISTER_INTERFACE_FUNC(mem_realloc);
 	REGISTER_INTERFACE_FUNC(mem_free);
 	REGISTER_INTERFACE_FUNC(mem_free);

+ 23 - 0
core/extension/gdextension_interface.h

@@ -790,9 +790,22 @@ typedef struct {
 	const char *string;
 	const char *string;
 } GDExtensionGodotVersion;
 } GDExtensionGodotVersion;
 
 
+typedef struct {
+	uint32_t major;
+	uint32_t minor;
+	uint32_t patch;
+	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)
+	const char *status; // (e.g. "stable", "beta", "rc1", "rc2")
+	const char *build; // (e.g. "custom_build")
+	const char *hash; // Full Git commit hash.
+	uint64_t timestamp; // Git commit date UNIX timestamp in seconds, or 0 if unavailable.
+	const char *string; // (e.g. "Godot v3.1.4.stable.official.mono")
+} GDExtensionGodotVersion2;
+
 /**
 /**
  * @name get_godot_version
  * @name get_godot_version
  * @since 4.1
  * @since 4.1
+ * @deprecated in Godot 4.5. Use `get_godot_version2` instead.
  *
  *
  * Gets the Godot version that the GDExtension was loaded into.
  * Gets the Godot version that the GDExtension was loaded into.
  *
  *
@@ -800,6 +813,16 @@ typedef struct {
  */
  */
 typedef void (*GDExtensionInterfaceGetGodotVersion)(GDExtensionGodotVersion *r_godot_version);
 typedef void (*GDExtensionInterfaceGetGodotVersion)(GDExtensionGodotVersion *r_godot_version);
 
 
+/**
+ * @name get_godot_version2
+ * @since 4.5
+ *
+ * Gets the Godot version that the GDExtension was loaded into.
+ *
+ * @param r_godot_version A pointer to the structure to write the version information into.
+ */
+typedef void (*GDExtensionInterfaceGetGodotVersion2)(GDExtensionGodotVersion2 *r_godot_version);
+
 /* INTERFACE: Memory */
 /* INTERFACE: Memory */
 
 
 /**
 /**