/*************************************************************************/ /* gdnative.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #ifndef GDNATIVE_H #define GDNATIVE_H #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/thread_safe.h" #include "resource.h" #include "scene/main/node.h" #include "script_language.h" #include "self_list.h" #include "godot.h" struct GDNativeScriptData; class GDNativeLibrary; struct NativeLibrary { StringName path; void *handle; GDNativeLibrary *dllib; Map scripts; static Error initialize(NativeLibrary *&p_native_lib, const StringName p_path); static Error terminate(NativeLibrary *&p_native_lib); }; struct GDNativeScriptData { /* typedef void* (InstanceFunc)(godot_object* instance); typedef void (DestroyFunc)(godot_object* instance,void* userdata); typedef godot_variant (MethodFunc)(godot_object *instance, void *userdata, void *method_data, int arg_count,godot_variant **args); typedef void (MethodDataFreeFunc)(void *method_data); typedef void (SetterFunc)(godot_object* instance,void* userdata,godot_variant value); typedef godot_variant (GetterFunc)(godot_object* instance,void* userdata);*/ struct Method { godot_instance_method method; MethodInfo info; int rpc_mode; Method() { } Method(godot_instance_method p_method, MethodInfo p_info, int p_rpc_mode) { method = p_method; info = p_info; rpc_mode = p_rpc_mode; } }; struct Property { godot_property_set_func setter; godot_property_get_func getter; PropertyInfo info; Variant default_value; int rset_mode; Property() { } Property(godot_property_set_func p_setter, godot_property_get_func p_getter) { setter = p_setter; getter = p_getter; } Property(godot_property_set_func p_setter, godot_property_get_func p_getter, PropertyInfo p_info, Variant p_default_value, int p_rset_mode) { setter = p_setter; getter = p_getter; info = p_info; default_value = p_default_value; rset_mode = p_rset_mode; } }; struct Signal { MethodInfo signal; }; Map methods; Map properties; Map signals_; // QtCreator doesn't like the name signals StringName base; StringName base_native_type; GDNativeScriptData *base_data; godot_instance_create_func create_func; godot_instance_destroy_func destroy_func; bool is_tool; GDNativeScriptData() { base = StringName(); base_data = NULL; is_tool = false; } GDNativeScriptData(StringName p_base, godot_instance_create_func p_instance, godot_instance_destroy_func p_free) { base = p_base; base_data = NULL; create_func = p_instance; destroy_func = p_free; is_tool = false; } }; class GDNativeScript : public Script { GDCLASS(GDNativeScript, Script); Ref library; StringName script_name; StringName base_native_type; Set instances; GDNativeScriptData *script_data; #ifdef TOOLS_ENABLED Set placeholders; void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); #endif friend class GDNativeInstance; friend class GDNativeScriptLanguage; friend class GDNativeReloadNode; friend class GDNativeLibrary; protected: static void _bind_methods(); public: virtual bool can_instance() const; virtual Ref