From 4cfc29611e21811065d024a6de1685418e60111e Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Thu, 16 Nov 2017 18:38:18 +0100 Subject: GDScript: Refactor "GD" class prefix to "GDScript" --- modules/gdscript/gdscript.h | 450 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 modules/gdscript/gdscript.h (limited to 'modules/gdscript/gdscript.h') diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h new file mode 100644 index 000000000..3f6f43193 --- /dev/null +++ b/modules/gdscript/gdscript.h @@ -0,0 +1,450 @@ +/*************************************************************************/ +/* gdscript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://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 GDSCRIPT_H +#define GDSCRIPT_H + +#include "gdscript_function.h" +#include "io/resource_loader.h" +#include "io/resource_saver.h" +#include "script_language.h" + +class GDScriptNativeClass : public Reference { + + GDCLASS(GDScriptNativeClass, Reference); + + 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 *instance(); + GDScriptNativeClass(const StringName &p_name); +}; + +class GDScript : public Script { + + GDCLASS(GDScript, Script); + bool tool; + bool valid; + + struct MemberInfo { + int index; + StringName setter; + StringName getter; + ScriptInstance::RPCMode rpc_mode; + }; + + friend class GDScriptInstance; + friend class GDScriptFunction; + friend class GDScriptCompiler; + friend class GDScriptFunctions; + friend class GDScriptLanguage; + + Variant _static_ref; //used for static call + Ref native; + Ref base; + GDScript *_base; //fast pointer access + GDScript *_owner; //for subclasses + + Set members; //members are just indices to the instanced script. + Map constants; + Map member_functions; + Map member_indices; //members are just indices to the instanced script. + Map > subclasses; + Map > _signals; + +#ifdef TOOLS_ENABLED + + Map member_lines; + + Map member_default_values; + + List members_cache; + Map member_default_values_cache; + Ref base_cache; + Set inheriters_cache; + bool source_changed_cache; + void _update_exports_values(Map &values, List &propnames); + +#endif + Map member_info; + + GDScriptFunction *initializer; //direct pointer to _init , faster to locate + + int subclass_count; + Set instances; + //exported members + String source; + String path; + String name; + SelfList script_list; + + GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); + + void _set_subclass_path(Ref &p_sc, const String &p_path); + +#ifdef TOOLS_ENABLED + Set placeholders; + //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); +#endif + +#ifdef DEBUG_ENABLED + + Map > > pending_reload_state; + +#endif + + bool _update_exports(); + +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 call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + //void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); + + static void _bind_methods(); + +public: + bool is_valid() const { return valid; } + + const Map > &get_subclasses() const { return subclasses; } + const Map &get_constants() const { return constants; } + const Set &get_members() const { return members; } + const Map &get_member_functions() const { return member_functions; } + const Ref &get_native() const { return native; } + + virtual bool has_script_signal(const StringName &p_signal) const; + virtual void get_script_signal_list(List *r_signals) const; + + bool is_tool() const { return tool; } + Ref get_base() const; + + const Map &debug_get_member_indices() const { return member_indices; } + const Map &debug_get_member_functions() const; //this is debug only + StringName debug_get_member_by_index(int p_idx) const; + + Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + virtual bool can_instance() const; + + virtual Ref