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.
This commit is contained in:
Ignacio Etcheverry 2017-10-09 23:49:17 +02:00
parent eb920406ae
commit 0c2e882210
7 changed files with 53 additions and 0 deletions

View file

@ -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());

View file

@ -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>;
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>;
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<String> *p_extensions);
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);

View file

@ -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<Object>();
ClassDB::register_virtual_class<Script>();
ClassDB::register_class<Reference>();
ClassDB::register_class<WeakRef>();
ClassDB::register_class<Resource>();
@ -136,6 +139,7 @@ void register_core_types() {
ClassDB::register_virtual_class<IP>();
ClassDB::register_virtual_class<PacketPeer>();
ClassDB::register_class<PacketPeerStream>();
ClassDB::register_virtual_class<NetworkedMultiplayerPeer>();
ClassDB::register_class<MainLoop>();
//ClassDB::register_type<OptimizedSaver>();
ClassDB::register_class<Translation>();
@ -185,6 +189,20 @@ void register_core_settings() {
void register_core_singletons() {
ClassDB::register_class<ProjectSettings>();
ClassDB::register_virtual_class<IP>();
ClassDB::register_class<_Geometry>();
ClassDB::register_class<_ResourceLoader>();
ClassDB::register_class<_ResourceSaver>();
ClassDB::register_class<_OS>();
ClassDB::register_class<_Engine>();
ClassDB::register_class<_ClassDB>();
ClassDB::register_class<_Marshalls>();
ClassDB::register_class<TranslationServer>();
ClassDB::register_virtual_class<Input>();
ClassDB::register_class<InputMap>();
ClassDB::register_class<_JSON>();
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("ProjectSettings", ProjectSettings::get_singleton()));
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("IP", IP::get_singleton()));
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("Geometry", _Geometry::get_singleton()));

View file

@ -256,6 +256,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
translation_server = memnew(TranslationServer);
performance = memnew(Performance);
ClassDB::register_class<Performance>();
globals->add_singleton(ProjectSettings::Singleton("Performance", performance));
GLOBAL_DEF("debug/settings/crash_handler/message", String("Please include this when reporting the bug on https://github.com/godotengine/godot/issues"));

View file

@ -44,6 +44,7 @@ void register_mono_types() {
_godotsharp = memnew(_GodotSharp);
ClassDB::register_class<_GodotSharp>();
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("GodotSharp", _GodotSharp::get_singleton()));
script_language_cs = memnew(CSharpLanguage);

View file

@ -261,9 +261,11 @@ void register_scene_types() {
ClassDB::register_class<Control>();
ClassDB::register_class<Button>();
ClassDB::register_class<Label>();
ClassDB::register_class<ScrollBar>();
ClassDB::register_class<HScrollBar>();
ClassDB::register_class<VScrollBar>();
ClassDB::register_class<ProgressBar>();
ClassDB::register_class<Slider>();
ClassDB::register_class<HSlider>();
ClassDB::register_class<VSlider>();
ClassDB::register_class<Popup>();
@ -347,6 +349,7 @@ void register_scene_types() {
#ifndef _3D_DISABLED
ClassDB::register_class<BoneAttachment>();
ClassDB::register_virtual_class<VisualInstance>();
ClassDB::register_virtual_class<GeometryInstance>();
ClassDB::register_class<Camera>();
ClassDB::register_class<Listener>();
ClassDB::register_class<ARVRCamera>();
@ -356,6 +359,7 @@ void register_scene_types() {
ClassDB::register_class<InterpolatedCamera>();
ClassDB::register_class<MeshInstance>();
ClassDB::register_class<ImmediateGeometry>();
ClassDB::register_virtual_class<SpriteBase3D>();
ClassDB::register_class<Sprite3D>();
ClassDB::register_class<AnimatedSprite3D>();
ClassDB::register_virtual_class<Light>();
@ -375,6 +379,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
ClassDB::register_virtual_class<CollisionObject>();
ClassDB::register_virtual_class<PhysicsBody>();
ClassDB::register_class<StaticBody>();
ClassDB::register_class<RigidBody>();
ClassDB::register_class<KinematicCollision>();
@ -489,6 +494,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
ClassDB::register_virtual_class<Shape>();
ClassDB::register_class<RayShape>();
ClassDB::register_class<SphereShape>();
ClassDB::register_class<BoxShape>();
@ -526,6 +532,7 @@ void register_scene_types() {
ClassDB::register_class<DynamicFontData>();
ClassDB::register_class<DynamicFont>();
ClassDB::register_virtual_class<StyleBox>();
ClassDB::register_class<StyleBoxEmpty>();
ClassDB::register_class<StyleBoxTexture>();
ClassDB::register_class<StyleBoxFlat>();

View file

@ -79,6 +79,12 @@ ARVRServer *arvr_server = NULL;
void register_server_types() {
arvr_server = memnew(ARVRServer);
ClassDB::register_virtual_class<VisualServer>();
ClassDB::register_class<AudioServer>();
ClassDB::register_virtual_class<PhysicsServer>();
ClassDB::register_virtual_class<Physics2DServer>();
ClassDB::register_class<ARVRServer>();
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("VisualServer", VisualServer::get_singleton()));
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("AudioServer", AudioServer::get_singleton()));
ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
@ -95,6 +101,8 @@ void register_server_types() {
ClassDB::register_virtual_class<AudioStreamPlayback>();
ClassDB::register_class<AudioStreamRandomPitch>();
ClassDB::register_virtual_class<AudioEffect>();
ClassDB::register_class<AudioEffectEQ>();
ClassDB::register_class<AudioEffectFilter>();
ClassDB::register_class<AudioBusLayout>();
{