Bläddra i källkod

Merge pull request #12803 from karroffel/gdnative-api-struct-refactor

[GDNative] better API struct versioning
Thomas Herzog 7 år sedan
förälder
incheckning
f04665f881

+ 30 - 15
modules/gdnative/SCsub

@@ -12,7 +12,7 @@ gdn_env.add_source_files(env.modules_sources, "nativescript/*.cpp")
 
 gdn_env.Append(CPPPATH=['#modules/gdnative/include/'])
 
-SConscript("nativearvr/SCsub")
+SConscript("arvr/SCsub")
 SConscript("pluginscript/SCsub")
 
 def _spaced(e):
@@ -25,7 +25,7 @@ def _build_gdnative_api_struct_header(api):
         '#define GODOT_GDNATIVE_API_STRUCT_H',
         '',
         '#include <gdnative/gdnative.h>',
-        '#include <nativearvr/godot_nativearvr.h>',
+        '#include <arvr/godot_arvr.h>',
         '#include <nativescript/godot_nativescript.h>',
         '#include <pluginscript/godot_pluginscript.h>',
         '',
@@ -35,34 +35,47 @@ def _build_gdnative_api_struct_header(api):
         'extern "C" {',
         '#endif',
         '',
+        'typedef struct godot_gdnative_api_version {',
+        '\tunsigned int major;',
+        '\tunsigned int minor;',
+        '} godot_gdnative_api_version;',
+        '',
+        'typedef struct godot_gdnative_api_struct {',
+        '\tunsigned int type;',
+        '\tgodot_gdnative_api_version version;',
+        '\tconst godot_gdnative_api_struct *next;',
+        '} godot_gdnative_api_struct;',
+        '',
         'enum GDNATIVE_API_TYPES {',
         '\tGDNATIVE_' + api['core']['type'] + ','
     ]
 
     for name in api['extensions']:
-        out += ['\tGDNATIVE_' + api['extensions'][name]['type'] + ',']
+        out += ['\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',']
 
     out += ['};', '']
 
     for name in api['extensions']:
         out += [
-            'typedef struct godot_gdnative_' + name + '_api_struct {',
+            'typedef struct godot_gdnative_ext_' + name + '_api_struct {',
             '\tunsigned int type;',
-            '\tconst void *next;'
+            '\tgodot_gdnative_api_version version;',
+            '\tconst godot_gdnative_api_struct *next;'
         ]
 
         for funcdef in api['extensions'][name]['api']:
             args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
             out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
 
-        out += ['} godot_gdnative_' + name + '_api_struct;', '']
+        out += ['} godot_gdnative_ext_' + name + '_api_struct;', '']
 
     out += [
-        'typedef struct godot_gdnative_api_struct {',
+        'typedef struct godot_gdnative_core_api_struct {',
         '\tunsigned int type;',
-        '\tconst void *next;',
+        '\tgodot_gdnative_api_version version;',
+        '\tconst godot_gdnative_api_struct *next;',
         '\tunsigned int num_extensions;',
-        '\tconst void **extensions;',
+        '\tconst godot_gdnative_api_struct **extensions;',
     ]
 
     for funcdef in api['core']['api']:
@@ -70,7 +83,7 @@ def _build_gdnative_api_struct_header(api):
         out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
 
     out += [
-        '} godot_gdnative_api_struct;',
+        '} godot_gdnative_core_api_struct;',
         '',
         '#ifdef __cplusplus',
         '}',
@@ -91,8 +104,9 @@ def _build_gdnative_api_struct_source(api):
 
     for name in api['extensions']:
         out += [
-            'extern const godot_gdnative_' + name + '_api_struct api_extension_' + name + '_struct = {',
-            '\tGDNATIVE_' + api['extensions'][name]['type'] + ',',
+            'extern const godot_gdnative_ext_' + name + '_api_struct api_extension_' + name + '_struct = {',
+            '\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',',
+            '\t{' + str(api['extensions'][name]['version']['major']) + ', ' + str(api['extensions'][name]['version']['minor']) + '},',
             '\tNULL,'
         ]
 
@@ -101,16 +115,17 @@ def _build_gdnative_api_struct_source(api):
 
         out += ['};\n']
 
-    out += ['', 'const void *gdnative_extensions_pointers[] = {']
+    out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
 
     for name in api['extensions']:
-        out += ['\t(void *)&api_extension_' + name + '_struct,']
+        out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
 
     out += ['};\n']
 
     out += [
-        'extern const godot_gdnative_api_struct api_struct = {',
+        'extern const godot_gdnative_core_api_struct api_struct = {',
         '\tGDNATIVE_' + api['core']['type'] + ',',
+        '\t{' + str(api['core']['version']['major']) + ', ' + str(api['core']['version']['minor']) + '},',
         '\tNULL,',
         '\t' + str(len(api['extensions'])) + ',',
         '\tgdnative_extensions_pointers,',

+ 0 - 0
modules/gdnative/nativearvr/SCsub → modules/gdnative/arvr/SCsub


+ 0 - 0
modules/gdnative/nativearvr/arvr_interface_gdnative.cpp → modules/gdnative/arvr/arvr_interface_gdnative.cpp


+ 0 - 0
modules/gdnative/nativearvr/arvr_interface_gdnative.h → modules/gdnative/arvr/arvr_interface_gdnative.h


+ 0 - 0
modules/gdnative/nativearvr/config.py → modules/gdnative/arvr/config.py


+ 2 - 2
modules/gdnative/nativearvr/register_types.cpp → modules/gdnative/arvr/register_types.cpp

@@ -31,9 +31,9 @@
 #include "register_types.h"
 #include "arvr_interface_gdnative.h"
 
-void register_nativearvr_types() {
+void register_arvr_types() {
 	ClassDB::register_class<ARVRInterfaceGDNative>();
 }
 
-void unregister_nativearvr_types() {
+void unregister_arvr_types() {
 }

+ 2 - 2
modules/gdnative/nativearvr/register_types.h → modules/gdnative/arvr/register_types.h

@@ -28,5 +28,5 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 
-void register_nativearvr_types();
-void unregister_nativearvr_types();
+void register_arvr_types();
+void unregister_arvr_types();

+ 1 - 1
modules/gdnative/gdnative.cpp

@@ -41,7 +41,7 @@ const String init_symbol = "godot_gdnative_init";
 const String terminate_symbol = "godot_gdnative_terminate";
 
 // Defined in gdnative_api_struct.gen.cpp
-extern const godot_gdnative_api_struct api_struct;
+extern const godot_gdnative_core_api_struct api_struct;
 
 String GDNativeLibrary::platform_names[NUM_PLATFORMS + 1] = {
 	"X11_32bit",

+ 20 - 4
modules/gdnative/gdnative_api.json

@@ -1,6 +1,10 @@
 {
   "core": {
-    "type": "CORE_1_0_0",
+    "type": "CORE",
+    "version": {
+      "major": 1,
+      "minor": 0
+    },
     "api": [
       {
         "name": "godot_color_new_rgba",
@@ -5604,7 +5608,11 @@
   },
   "extensions": {
     "nativescript": {
-      "type": "NATIVESCRIPT_1_0_0",
+      "type": "NATIVESCRIPT",
+      "version": {
+        "major": 1,
+        "minor": 0
+      },
       "api": [
         {
           "name": "godot_nativescript_register_class",
@@ -5670,7 +5678,11 @@
       ]
     },
     "pluginscript": {
-      "type": "PLUGINSCRIPT_1_0_0",
+      "type": "PLUGINSCRIPT",
+      "version": {
+        "major": 1,
+        "minor": 0
+      },
       "api": [
         {
           "name": "godot_pluginscript_register_language",
@@ -5682,7 +5694,11 @@
       ]
     },
     "nativearvr": {
-      "type": "NATIVEARVR_1_0_0",
+      "type": "NATIVEARVR",
+      "version": {
+        "major": 1,
+        "minor": 0
+      },
       "api": [
         {
           "name": "godot_arvr_register_interface",

+ 1 - 1
modules/gdnative/include/nativearvr/godot_nativearvr.h → modules/gdnative/include/arvr/godot_arvr.h

@@ -1,5 +1,5 @@
 /*************************************************************************/
-/*  godot_nativearvr.h                                                   */
+/*  godot_arvr.h                                                         */
 /*************************************************************************/
 /*                       This file is part of:                           */
 /*                           GODOT ENGINE                                */

+ 1 - 1
modules/gdnative/include/gdnative/gdnative.h

@@ -237,7 +237,7 @@ typedef struct {
 	uint64_t editor_api_hash;
 	uint64_t no_api_hash;
 	godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized
-	const struct godot_gdnative_api_struct *api_struct;
+	const struct godot_gdnative_core_api_struct *api_struct;
 	const godot_string *active_library_path;
 } godot_gdnative_init_options;
 

+ 3 - 3
modules/gdnative/register_types.cpp

@@ -35,7 +35,7 @@
 #include "io/resource_loader.h"
 #include "io/resource_saver.h"
 
-#include "nativearvr/register_types.h"
+#include "arvr/register_types.h"
 #include "nativescript/register_types.h"
 #include "pluginscript/register_types.h"
 
@@ -157,7 +157,7 @@ void register_gdnative_types() {
 
 	GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall);
 
-	register_nativearvr_types();
+	register_arvr_types();
 	register_nativescript_types();
 	register_pluginscript_types();
 
@@ -214,7 +214,7 @@ void unregister_gdnative_types() {
 
 	unregister_pluginscript_types();
 	unregister_nativescript_types();
-	unregister_nativearvr_types();
+	unregister_arvr_types();
 
 	memdelete(GDNativeCallRegistry::singleton);