/**************************************************************************/ /* gdscript.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* 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 GDSCRIPT_H #define GDSCRIPT_H #include "gdscript_function.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" #include "core/doc_data.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/object/script_language.h" #include "core/templates/rb_set.h" class GDScriptNativeClass : public RefCounted { GDCLASS(GDScriptNativeClass, RefCounted); StringName name; protected: bool _get(const StringName &p_name, Variant &r_ret) const; static void _bind_methods(); public: _FORCE_INLINE_ const StringName &get_name() const { return name; } Variant _new(); Object *instantiate(); virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; GDScriptNativeClass(const StringName &p_name); }; class GDScript : public Script { GDCLASS(GDScript, Script); bool tool = false; bool valid = false; bool reloading = false; struct MemberInfo { int index = 0; StringName setter; StringName getter; GDScriptDataType data_type; PropertyInfo property_info; }; struct ClearData { RBSet functions; RBSet> scripts; void clear() { functions.clear(); scripts.clear(); } }; friend class GDScriptInstance; friend class GDScriptFunction; friend class GDScriptAnalyzer; friend class GDScriptCompiler; friend class GDScriptDocGen; friend class GDScriptLambdaCallable; friend class GDScriptLambdaSelfCallable; friend class GDScriptLanguage; friend struct GDScriptUtilityFunctionsDefinitions; Ref native; Ref base; GDScript *_base = nullptr; //fast pointer access GDScript *_owner = nullptr; //for subclasses // Members are just indices to the instantiated script. HashMap member_indices; // Includes member info of all base GDScript classes. HashSet members; // Only members of the current class. // Only static variables of the current class. HashMap static_variables_indices; Vector static_variables; // Static variable values. HashMap constants; HashMap member_functions; HashMap> subclasses; HashMap _signals; Dictionary rpc_config; struct LambdaInfo { int capture_count; bool use_self; }; HashMap lambda_info; // List is used here because a ptr to elements are stored, so the memory locations need to be stable struct UpdatableFuncPtr { List ptrs; Mutex mutex; bool initialized = false; }; struct UpdatableFuncPtrElement { List::Element *element = nullptr; Mutex *mutex = nullptr; }; static thread_local UpdatableFuncPtr func_ptrs_to_update_thread_local; static thread_local LocalVector::Element> func_ptrs_to_update_entries_thread_local; static UpdatableFuncPtr *func_ptrs_to_update_main_thread; List func_ptrs_to_update; List func_ptrs_to_update_elems; Mutex func_ptrs_to_update_mutex; UpdatableFuncPtrElement *_add_func_ptr_to_update(GDScriptFunction **p_func_ptr_ptr); static void _remove_func_ptr_to_update(const UpdatableFuncPtrElement *p_func_ptr_element); static void _fixup_thread_function_bookkeeping(); #ifdef TOOLS_ENABLED // For static data storage during hot-reloading. HashMap old_static_variables_indices; Vector old_static_variables; void _save_old_static_data(); void _restore_old_static_data(); HashMap member_lines; HashMap member_default_values; List members_cache; HashMap member_default_values_cache; Ref base_cache; HashSet inheriters_cache; bool source_changed_cache = false; bool placeholder_fallback_enabled = false; void _update_exports_values(HashMap &values, List &propnames); DocData::ClassDoc doc; Vector docs; void _clear_doc(); void _add_doc(const DocData::ClassDoc &p_inner_class); #endif GDScriptFunction *implicit_initializer = nullptr; GDScriptFunction *initializer = nullptr; //direct pointer to new , faster to locate GDScriptFunction *implicit_ready = nullptr; GDScriptFunction *static_initializer = nullptr; Error _static_init(); int subclass_count = 0; RBSet instances; bool destructing = false; bool clearing = false; //exported members String source; String path; bool path_valid = false; // False if using default path. StringName local_name; // Inner class identifier or `class_name`. StringName global_name; // `class_name`. String fully_qualified_name; String simplified_icon_path; SelfList script_list; SelfList::List pending_func_states; GDScriptFunction *_super_constructor(GDScript *p_script); void _super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error); GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error); String _get_debug_path() const; #ifdef TOOLS_ENABLED HashSet placeholders; //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; void _update_exports_down(bool p_base_exports_changed); #endif #ifdef DEBUG_ENABLED HashMap>> pending_reload_state; #endif bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr, bool p_base_exports_changed = false); void _save_orphaned_subclasses(GDScript::ClearData *p_clear_data); void _get_script_property_list(List *r_list, bool p_include_base) const; void _get_script_method_list(List *r_list, bool p_include_base) const; void _get_script_signal_list(List *r_list, bool p_include_base) const; GDScript *_get_gdscript_from_variant(const Variant &p_variant); void _get_dependencies(RBSet &p_dependencies, const GDScript *p_except); protected: bool _get(const StringName &p_name, Variant &r_ret) const; bool _set(const StringName &p_name, const Variant &p_value); void _get_property_list(List *p_properties) const; Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; static void _bind_methods(); public: #ifdef DEBUG_ENABLED static String debug_get_script_name(const Ref