From 534d62d2f4ea1ff4be11b50bc79684b5780e4615 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Fri, 14 Jul 2017 01:44:14 +0200 Subject: [PATCH] [GDNative] new GDNative API This adds GDNative as a separate class type. It can be used to interface with native libraries by using "native calls", which can be registered by modules (and in future other GDNative libraries?). It also reworks the currently called "GDNativeScript" into a "NativeScript" that just makes use of the new GDNative instead of it being the component that implements that functionality. --- modules/gdnative/gdnative.cpp | 1450 +++-------------- modules/gdnative/gdnative.h | 442 +---- .../godot/{godot_array.cpp => array.cpp} | 4 +- .../gdnative/godot/{godot_array.h => array.h} | 15 +- .../godot/{godot_basis.cpp => basis.cpp} | 4 +- .../gdnative/godot/{godot_basis.h => basis.h} | 13 +- .../godot/{godot_color.cpp => color.cpp} | 4 +- .../gdnative/godot/{godot_color.h => color.h} | 12 +- .../{godot_dictionary.cpp => dictionary.cpp} | 4 +- .../{godot_dictionary.h => dictionary.h} | 14 +- .../{godot.cpp => godot/gdnative.cpp} | 70 +- modules/gdnative/godot/gdnative.h | 298 ++++ modules/gdnative/godot/icon.png.import | 23 + .../{godot_node_path.cpp => node_path.cpp} | 4 +- .../godot/{godot_node_path.h => node_path.h} | 12 +- .../godot/{godot_plane.cpp => plane.cpp} | 4 +- .../gdnative/godot/{godot_plane.h => plane.h} | 12 +- ...{godot_pool_arrays.cpp => pool_arrays.cpp} | 10 +- .../{godot_pool_arrays.h => pool_arrays.h} | 61 +- .../godot/{godot_quat.cpp => quat.cpp} | 4 +- .../gdnative/godot/{godot_quat.h => quat.h} | 12 +- .../godot/{godot_rect2.cpp => rect2.cpp} | 4 +- .../gdnative/godot/{godot_rect2.h => rect2.h} | 6 +- .../godot/{godot_rect3.cpp => rect3.cpp} | 4 +- .../gdnative/godot/{godot_rect3.h => rect3.h} | 14 +- .../gdnative/godot/{godot_rid.cpp => rid.cpp} | 4 +- modules/gdnative/godot/{godot_rid.h => rid.h} | 10 +- .../godot/{godot_string.cpp => string.cpp} | 4 +- .../godot/{godot_string.h => string.h} | 11 +- .../{godot_transform.cpp => transform.cpp} | 4 +- .../godot/{godot_transform.h => transform.h} | 16 +- ...{godot_transform2d.cpp => transform2d.cpp} | 4 +- .../{godot_transform2d.h => transform2d.h} | 14 +- .../godot/{godot_variant.cpp => variant.cpp} | 4 +- .../godot/{godot_variant.h => variant.h} | 45 +- .../godot/{godot_vector2.cpp => vector2.cpp} | 4 +- .../godot/{godot_vector2.h => vector2.h} | 10 +- .../godot/{godot_vector3.cpp => vector3.cpp} | 4 +- .../godot/{godot_vector3.h => vector3.h} | 12 +- modules/gdnative/register_types.cpp | 56 +- modules/nativescript/SCsub | 10 + .../api_generator.cpp | 0 .../api_generator.h | 0 modules/nativescript/config.py | 8 + modules/nativescript/godot_nativescript.cpp | 205 +++ .../godot_nativescript.h} | 267 +-- modules/nativescript/nativescript.cpp | 1088 +++++++++++++ modules/nativescript/nativescript.h | 281 ++++ modules/nativescript/register_types.cpp | 93 ++ modules/nativescript/register_types.h | 31 + 50 files changed, 2611 insertions(+), 2074 deletions(-) rename modules/gdnative/godot/{godot_array.cpp => array.cpp} (99%) rename modules/gdnative/godot/{godot_array.h => array.h} (95%) rename modules/gdnative/godot/{godot_basis.cpp => basis.cpp} (99%) rename modules/gdnative/godot/{godot_basis.h => basis.h} (96%) rename modules/gdnative/godot/{godot_color.cpp => color.cpp} (98%) rename modules/gdnative/godot/{godot_color.h => color.h} (95%) rename modules/gdnative/godot/{godot_dictionary.cpp => dictionary.cpp} (98%) rename modules/gdnative/godot/{godot_dictionary.h => dictionary.h} (94%) rename modules/gdnative/{godot.cpp => godot/gdnative.cpp} (70%) create mode 100644 modules/gdnative/godot/gdnative.h create mode 100644 modules/gdnative/godot/icon.png.import rename modules/gdnative/godot/{godot_node_path.cpp => node_path.cpp} (98%) rename modules/gdnative/godot/{godot_node_path.h => node_path.h} (94%) rename modules/gdnative/godot/{godot_plane.cpp => plane.cpp} (98%) rename modules/gdnative/godot/{godot_plane.h => plane.h} (95%) rename modules/gdnative/godot/{godot_pool_arrays.cpp => pool_arrays.cpp} (99%) rename modules/gdnative/godot/{godot_pool_arrays.h => pool_arrays.h} (90%) rename modules/gdnative/godot/{godot_quat.cpp => quat.cpp} (98%) rename modules/gdnative/godot/{godot_quat.h => quat.h} (95%) rename modules/gdnative/godot/{godot_rect2.cpp => rect2.cpp} (98%) rename modules/gdnative/godot/{godot_rect2.h => rect2.h} (97%) rename modules/gdnative/godot/{godot_rect3.cpp => rect3.cpp} (98%) rename modules/gdnative/godot/{godot_rect3.h => rect3.h} (95%) rename modules/gdnative/godot/{godot_rid.cpp => rid.cpp} (97%) rename modules/gdnative/godot/{godot_rid.h => rid.h} (94%) rename modules/gdnative/godot/{godot_string.cpp => string.cpp} (98%) rename modules/gdnative/godot/{godot_string.h => string.h} (94%) rename modules/gdnative/godot/{godot_transform.cpp => transform.cpp} (98%) rename modules/gdnative/godot/{godot_transform.h => transform.h} (95%) rename modules/gdnative/godot/{godot_transform2d.cpp => transform2d.cpp} (98%) rename modules/gdnative/godot/{godot_transform2d.h => transform2d.h} (95%) rename modules/gdnative/godot/{godot_variant.cpp => variant.cpp} (99%) rename modules/gdnative/godot/{godot_variant.h => variant.h} (93%) rename modules/gdnative/godot/{godot_vector2.cpp => vector2.cpp} (99%) rename modules/gdnative/godot/{godot_vector2.h => vector2.h} (97%) rename modules/gdnative/godot/{godot_vector3.cpp => vector3.cpp} (99%) rename modules/gdnative/godot/{godot_vector3.h => vector3.h} (96%) create mode 100644 modules/nativescript/SCsub rename modules/{gdnative => nativescript}/api_generator.cpp (100%) rename modules/{gdnative => nativescript}/api_generator.h (100%) create mode 100644 modules/nativescript/config.py create mode 100644 modules/nativescript/godot_nativescript.cpp rename modules/{gdnative/godot.h => nativescript/godot_nativescript.h} (52%) create mode 100644 modules/nativescript/nativescript.cpp create mode 100644 modules/nativescript/nativescript.h create mode 100644 modules/nativescript/register_types.cpp create mode 100644 modules/nativescript/register_types.h diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 214164ef891..65bfbb0ff7c 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -36,725 +36,54 @@ #include "project_settings.h" #include "scene/main/scene_tree.h" -#include "scene/resources/scene_format_text.h" -#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) -#include "api_generator.h" -#endif +const String init_symbol = "godot_gdnative_init"; +const String terminate_symbol = "godot_gdnative_terminate"; -#ifdef TOOLS_ENABLED -#include "editor/editor_node.h" -#endif +String GDNativeLibrary::platform_names[NUM_PLATFORMS] = { + "X11_32bit", + "X11_64bit", + "Windows_32bit", + "Windows_64bit", + "OSX", -Error NativeLibrary::initialize(NativeLibrary *&p_native_lib, const StringName p_path) { + "Android", + "iOS", - if (GDNativeScriptLanguage::get_singleton()->initialized_libraries.has(p_path)) { - p_native_lib = GDNativeScriptLanguage::get_singleton()->initialized_libraries[p_path]; - return OK; - } + "WebAssembly" +}; +String GDNativeLibrary::platform_lib_ext[NUM_PLATFORMS] = { + "so", + "so", + "dll", + "dll", + "dylib", - NativeLibrary *lib = memnew(NativeLibrary); - lib->path = p_path; + "so", + "dylib", - p_native_lib = lib; - - // Open the file - - Error error; - error = OS::get_singleton()->open_dynamic_library(p_path, lib->handle); - if (error) return error; - ERR_FAIL_COND_V(!lib->handle, ERR_BUG); - - // Get the method - - void *library_init; - error = OS::get_singleton()->get_dynamic_library_symbol_handle(lib->handle, GDNativeScriptLanguage::get_init_symbol_name(), library_init); - if (error) return error; - ERR_FAIL_COND_V(!library_init, ERR_BUG); - - void (*library_init_fpointer)(godot_native_init_options *) = (void (*)(godot_native_init_options *))library_init; - - godot_native_init_options options; - - options.in_editor = SceneTree::get_singleton()->is_editor_hint(); - options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); - options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); - options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); - - library_init_fpointer(&options); // Catch errors? - - GDNativeScriptLanguage::get_singleton()->initialized_libraries[p_path] = lib; - - return OK; -} - -Error NativeLibrary::terminate(NativeLibrary *&p_native_lib) { - - if (!GDNativeScriptLanguage::get_singleton()->initialized_libraries.has(p_native_lib->path)) { - OS::get_singleton()->close_dynamic_library(p_native_lib->handle); - p_native_lib->handle = 0; - return OK; - } - - Error error = OK; - void *library_terminate; - error = OS::get_singleton()->get_dynamic_library_symbol_handle(p_native_lib->handle, GDNativeScriptLanguage::get_terminate_symbol_name(), library_terminate); - if (!error) { - - void (*library_terminate_pointer)(godot_native_terminate_options *) = (void (*)(godot_native_terminate_options *))library_terminate; - - godot_native_terminate_options options; - options.in_editor = SceneTree::get_singleton()->is_editor_hint(); - - library_terminate_pointer(&options); - } - - GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path); - - OS::get_singleton()->close_dynamic_library(p_native_lib->handle); - p_native_lib->handle = 0; - - return OK; -} - -// Script -#ifdef TOOLS_ENABLED - -void GDNativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { - ERR_FAIL_COND(!script_data); - - List pinfo; - Map values; - - for (Map::Element *E = script_data->properties.front(); E; E = E->next()) { - PropertyInfo p = E->get().info; - p.name = String(E->key()); - pinfo.push_back(p); - values[p.name] = E->get().default_value; - } - - p_placeholder->update(pinfo, values); -} - -void GDNativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - - placeholders.erase(p_placeholder); -} - -#endif - -bool GDNativeScript::can_instance() const { -#ifdef TOOLS_ENABLED - return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled()); -#else - // allow defaultlibrary without editor features - if (!library.is_valid()) { - String path = GLOBAL_GET("gdnative/default_gdnativelibrary"); - - RES lib = ResourceLoader::load(path); - - if (lib.is_valid() && lib->cast_to()) { - return true; - } - } - - return script_data; -#endif - //return script_data || (!tool && !ScriptServer::is_scripting_enabled()); - // change to true enable in editor stuff. -} - -Ref