summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/class_db.cpp53
-rw-r--r--core/class_db.h3
-rw-r--r--core/io/multiplayer_api.cpp1
-rw-r--r--core/object.h1
-rw-r--r--core/register_core_types.cpp1
5 files changed, 51 insertions, 8 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp
index c9527e3c8f..34bc83c89a 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -545,6 +545,11 @@ bool ClassDB::can_instance(const StringName &p_class) {
ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_COND_V(!ti, false);
+#ifdef TOOLS_ENABLED
+ if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
+ return false;
+ }
+#endif
return (!ti->disabled && ti->creation_func != NULL);
}
@@ -980,6 +985,13 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons
type->property_setget[p_pinfo.name] = psg;
}
+void ClassDB::set_property_default_value(StringName p_class, const StringName &p_name, const Variant &p_default) {
+ if (!default_values.has(p_class)) {
+ default_values[p_class] = HashMap<StringName, Variant>();
+ }
+ default_values[p_class][p_name] = p_default;
+}
+
void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
OBJTYPE_RLOCK;
@@ -1383,27 +1395,47 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p
}
HashMap<StringName, HashMap<StringName, Variant> > ClassDB::default_values;
+Set<StringName> ClassDB::default_values_cached;
Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property) {
- if (!default_values.has(p_class)) {
+ if (!default_values_cached.has(p_class)) {
- default_values[p_class] = HashMap<StringName, Variant>();
+ if (!default_values.has(p_class)) {
+ default_values[p_class] = HashMap<StringName, Variant>();
+ }
- if (ClassDB::can_instance(p_class)) {
+ Object *c = NULL;
+ bool cleanup_c = false;
+
+ if (Engine::get_singleton()->has_singleton(p_class)) {
+ c = Engine::get_singleton()->get_singleton_object(p_class);
+ cleanup_c = false;
+ } else if (ClassDB::can_instance(p_class)) {
+ c = ClassDB::instance(p_class);
+ cleanup_c = true;
+ }
+
+ if (c) {
- Object *c = ClassDB::instance(p_class);
List<PropertyInfo> plist;
c->get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR)) {
- Variant v = c->get(E->get().name);
- default_values[p_class][E->get().name] = v;
+ if (!default_values[p_class].has(E->get().name)) {
+ Variant v = c->get(E->get().name);
+ default_values[p_class][E->get().name] = v;
+ }
}
}
- memdelete(c);
+
+ if (cleanup_c) {
+ memdelete(c);
+ }
}
+
+ default_values_cached.insert(p_class);
}
if (!default_values.has(p_class)) {
@@ -1424,6 +1456,12 @@ void ClassDB::init() {
lock = RWLock::create();
}
+void ClassDB::cleanup_defaults() {
+
+ default_values.clear();
+ default_values_cached.clear();
+}
+
void ClassDB::cleanup() {
//OBJTYPE_LOCK; hah not here
@@ -1443,7 +1481,6 @@ void ClassDB::cleanup() {
classes.clear();
resource_base_extensions.clear();
compat_classes.clear();
- default_values.clear();
memdelete(lock);
}
diff --git a/core/class_db.h b/core/class_db.h
index efa1a46866..8adbc9ba98 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -162,6 +162,7 @@ public:
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
static HashMap<StringName, HashMap<StringName, Variant> > default_values;
+ static Set<StringName> default_values_cached;
public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
@@ -329,6 +330,7 @@ public:
static void add_property_group(StringName p_class, const String &p_name, const String &p_prefix = "");
static void add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
+ static void set_property_default_value(StringName p_class, const StringName &p_name, const Variant &p_default);
static void get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = NULL);
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = NULL);
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
@@ -373,6 +375,7 @@ public:
static void set_current_api(APIType p_api);
static APIType get_current_api();
+ static void cleanup_defaults();
static void cleanup();
};
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 2779837190..33dc4dbde4 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -874,6 +874,7 @@ void MultiplayerAPI::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer");
+ ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false);
ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id")));
diff --git a/core/object.h b/core/object.h
index 4394c1c3da..1e0b22c086 100644
--- a/core/object.h
+++ b/core/object.h
@@ -130,6 +130,7 @@ enum PropertyUsageFlags {
#define ADD_SIGNAL(m_signal) ClassDB::add_signal(get_class_static(), m_signal)
#define ADD_PROPERTY(m_property, m_setter, m_getter) ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter))
#define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter), m_index)
+#define ADD_PROPERTY_DEFAULT(m_property, m_default) ClassDB::set_property_default_value(get_class_static(), m_property, m_default)
#define ADD_GROUP(m_name, m_prefix) ClassDB::add_property_group(get_class_static(), m_name, m_prefix)
struct PropertyInfo {
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 135df4e5bd..af863dd385 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -273,6 +273,7 @@ void unregister_core_types() {
ResourceLoader::finalize();
+ ClassDB::cleanup_defaults();
ObjectDB::cleanup();
unregister_variant_methods();