From 127458ed175c5aeac8dee7f09d23fae4c8928eb7 Mon Sep 17 00:00:00 2001 From: reduz Date: Sat, 7 Nov 2020 19:33:38 -0300 Subject: Reorganized core/ directory, it was too fatty already -Removed FuncRef, since Callable makes it obsolete -Removed int_types.h as its obsolete in c++11+ -Changed color names code --- core/object/script_language.h | 460 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 460 insertions(+) create mode 100644 core/object/script_language.h (limited to 'core/object/script_language.h') diff --git a/core/object/script_language.h b/core/object/script_language.h new file mode 100644 index 0000000000..447216f14f --- /dev/null +++ b/core/object/script_language.h @@ -0,0 +1,460 @@ +/*************************************************************************/ +/* script_language.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 SCRIPT_LANGUAGE_H +#define SCRIPT_LANGUAGE_H + +#include "core/io/multiplayer_api.h" +#include "core/io/resource.h" +#include "core/templates/map.h" +#include "core/templates/pair.h" + +class ScriptLanguage; + +typedef void (*ScriptEditRequestFunction)(const String &p_path); + +struct ScriptNetData { + StringName name; + MultiplayerAPI::RPCMode mode; + bool operator==(ScriptNetData const &p_other) const { + return name == p_other.name; + } +}; + +struct SortNetData { + StringName::AlphCompare compare; + bool operator()(const ScriptNetData &p_a, const ScriptNetData &p_b) const { + return compare(p_a.name, p_b.name); + } +}; + +class ScriptServer { + enum { + + MAX_LANGUAGES = 16 + }; + + static ScriptLanguage *_languages[MAX_LANGUAGES]; + static int _language_count; + static bool scripting_enabled; + static bool reload_scripts_on_save; + static bool languages_finished; + + struct GlobalScriptClass { + StringName language; + String path; + String base; + }; + + static HashMap global_classes; + +public: + static ScriptEditRequestFunction edit_request_func; + + static void set_scripting_enabled(bool p_enabled); + static bool is_scripting_enabled(); + _FORCE_INLINE_ static int get_language_count() { return _language_count; } + static ScriptLanguage *get_language(int p_idx); + static void register_language(ScriptLanguage *p_language); + static void unregister_language(ScriptLanguage *p_language); + + static void set_reload_scripts_on_save(bool p_enable); + static bool is_reload_scripts_on_save_enabled(); + + static void thread_enter(); + static void thread_exit(); + + static void global_classes_clear(); + static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path); + static void remove_global_class(const StringName &p_class); + static bool is_global_class(const StringName &p_class); + static StringName get_global_class_language(const StringName &p_class); + static String get_global_class_path(const String &p_class); + static StringName get_global_class_base(const String &p_class); + static StringName get_global_class_native_base(const String &p_class); + static void get_global_class_list(List *r_global_classes); + static void save_global_classes(); + + static void init_languages(); + static void finish_languages(); + + static bool are_languages_finished() { return languages_finished; } +}; + +class ScriptInstance; +class PlaceHolderScriptInstance; + +class Script : public Resource { + GDCLASS(Script, Resource); + OBJ_SAVE_TYPE(Script); + +protected: + virtual bool editor_can_reload_from_file() override { return false; } // this is handled by editor better + void _notification(int p_what); + static void _bind_methods(); + + friend class PlaceHolderScriptInstance; + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {} + + Variant _get_property_default_value(const StringName &p_property); + Array _get_script_property_list(); + Array _get_script_method_list(); + Array _get_script_signal_list(); + Dictionary _get_script_constant_map(); + +public: + virtual bool can_instance() const = 0; + + virtual Ref