From 0c2e882210f8848475f7d9547af50a202f53a110 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Mon, 9 Oct 2017 23:49:17 +0200 Subject: [PATCH 1/2] Adds 'exposed' field to ClassInfo This field represents if the class is exposed to the scripting API. The value is 'true' if the class was registered manually ('ClassDB::register_*class()'), otherwise it's false (registered on '_post_initialize'). - Added missing registration of classes that are meant to be exposed. --- core/class_db.cpp | 10 ++++++++++ core/class_db.h | 8 ++++++++ core/register_core_types.cpp | 18 ++++++++++++++++++ main/main.cpp | 1 + modules/mono/register_types.cpp | 1 + scene/register_scene_types.cpp | 7 +++++++ servers/register_server_types.cpp | 8 ++++++++ 7 files changed, 53 insertions(+) diff --git a/core/class_db.cpp b/core/class_db.cpp index f5ddd9c7616..12310f61510 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -205,6 +205,7 @@ ClassDB::ClassInfo::ClassInfo() { creation_func = NULL; inherits_ptr = NULL; disabled = false; + exposed = false; } ClassDB::ClassInfo::~ClassInfo() { } @@ -1284,6 +1285,15 @@ bool ClassDB::is_class_enabled(StringName p_class) { return !ti->disabled; } +bool ClassDB::is_class_exposed(StringName p_class) { + + OBJTYPE_RLOCK; + + ClassInfo *ti = classes.getptr(p_class); + ERR_FAIL_COND_V(!ti, false); + return ti->exposed; +} + StringName ClassDB::get_category(const StringName &p_node) { ERR_FAIL_COND_V(!classes.has(p_node), StringName()); diff --git a/core/class_db.h b/core/class_db.h index f6b97748b04..5910a2ce01b 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -127,6 +127,7 @@ public: StringName inherits; StringName name; bool disabled; + bool exposed; Object *(*creation_func)(); ClassInfo(); ~ClassInfo(); @@ -168,6 +169,7 @@ public: ClassInfo *t = classes.getptr(T::get_class_static()); ERR_FAIL_COND(!t); t->creation_func = &creator; + t->exposed = true; T::register_custom_data_to_otdb(); } @@ -176,6 +178,9 @@ public: GLOBAL_LOCK_FUNCTION; T::initialize_class(); + ClassInfo *t = classes.getptr(T::get_class_static()); + ERR_FAIL_COND(!t); + t->exposed = true; //nothing } @@ -193,6 +198,7 @@ public: ClassInfo *t = classes.getptr(T::get_class_static()); ERR_FAIL_COND(!t); t->creation_func = &_create_ptr_func; + t->exposed = true; T::register_custom_data_to_otdb(); } @@ -347,6 +353,8 @@ public: static void set_class_enabled(StringName p_class, bool p_enable); static bool is_class_enabled(StringName p_class); + static bool is_class_exposed(StringName p_class); + static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class); static void get_resource_base_extensions(List *p_extensions); static void get_extensions_for_type(const StringName &p_class, List *p_extensions); diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 0e34a3eea56..c6d7cd44e8d 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -40,6 +40,7 @@ #include "io/config_file.h" #include "io/http_client.h" #include "io/marshalls.h" +#include "io/networked_multiplayer_peer.h" #include "io/packet_peer.h" #include "io/packet_peer_udp.h" #include "io/pck_packer.h" @@ -109,6 +110,8 @@ void register_core_types() { ClassDB::register_class(); + ClassDB::register_virtual_class