From 269203a02261d53eb87817c8692bc56f0cf4e3dd Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Sun, 13 Aug 2017 15:37:56 +0700 Subject: Provide NativeScript properties in definition order --- modules/gdnative/nativescript/nativescript.cpp | 57 ++++++++++++-------------- modules/gdnative/nativescript/nativescript.h | 3 +- 2 files changed, 29 insertions(+), 31 deletions(-) (limited to 'modules/gdnative') diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 724b8390da..b9bd65af53 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -315,7 +315,7 @@ void NativeScript::get_script_signal_list(List *r_signals) const { bool NativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { NativeScriptDesc *script_data = get_script_desc(); - Map::Element *P = NULL; + OrderedHashMap::Element P; while (!P && script_data) { P = script_data->properties.find(p_property); script_data = script_data->base_data; @@ -323,7 +323,7 @@ bool NativeScript::get_property_default_value(const StringName &p_property, Vari if (!P) return false; - r_value = P->get().default_value; + r_value = P.get().default_value; return true; } @@ -355,23 +355,20 @@ void NativeScript::get_script_method_list(List *p_list) const { void NativeScript::get_script_property_list(List *p_list) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) - return; - - Set properties; - + Set existing_properties; while (script_data) { - - for (Map::Element *E = script_data->properties.front(); E; E = E->next()) { - properties.insert(E->get().info); + List::Element *insert_position = p_list->front(); + bool insert_before = true; + + for (OrderedHashMap::Element E = script_data->properties.front(); E; E = E.next()) { + if (!existing_properties.has(E.key())) { + insert_position = insert_before ? p_list->insert_before(insert_position, E.get().info) : p_list->insert_after(insert_position, E.get().info); + insert_before = false; + existing_properties.insert(E.key()); + } } - script_data = script_data->base_data; } - - for (Set::Element *E = properties.front(); E; E = E->next()) { - p_list->push_back(E->get()); - } } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { @@ -461,10 +458,10 @@ bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - Map::Element *P = script_data->properties.find(p_name); + OrderedHashMap::Element P = script_data->properties.find(p_name); if (P) { - P->get().setter.set_func((godot_object *)owner, - P->get().setter.method_data, + P.get().setter.set_func((godot_object *)owner, + P.get().setter.method_data, userdata, (godot_variant *)&p_value); return true; @@ -491,11 +488,11 @@ bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - Map::Element *P = script_data->properties.find(p_name); + OrderedHashMap::Element P = script_data->properties.find(p_name); if (P) { godot_variant value; - value = P->get().getter.get_func((godot_object *)owner, - P->get().getter.method_data, + value = P.get().getter.get_func((godot_object *)owner, + P.get().getter.method_data, userdata); r_ret = *(Variant *)&value; godot_variant_destroy(&value); @@ -592,10 +589,10 @@ Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, while (script_data) { - Map::Element *P = script_data->properties.find(p_name); + OrderedHashMap::Element P = script_data->properties.find(p_name); if (P) { *r_is_valid = true; - return P->get().info.type; + return P.get().info.type; } script_data = script_data->base_data; @@ -706,9 +703,9 @@ NativeScriptInstance::RPCMode NativeScriptInstance::get_rset_mode(const StringNa while (script_data) { - Map::Element *E = script_data->properties.find(p_variable); + OrderedHashMap::Element E = script_data->properties.find(p_variable); if (E) { - switch (E->get().rset_mode) { + switch (E.get().rset_mode) { case GODOT_METHOD_RPC_MODE_DISABLED: return RPC_MODE_DISABLED; case GODOT_METHOD_RPC_MODE_REMOTE: @@ -796,12 +793,12 @@ void NativeScriptLanguage::_unload_stuff() { for (Map::Element *C = L->get().front(); C; C = C->next()) { // free property stuff first - for (Map::Element *P = C->get().properties.front(); P; P = P->next()) { - if (P->get().getter.free_func) - P->get().getter.free_func(P->get().getter.method_data); + for (OrderedHashMap::Element P = C->get().properties.front(); P; P = P.next()) { + if (P.get().getter.free_func) + P.get().getter.free_func(P.get().getter.method_data); - if (P->get().setter.free_func) - P->get().setter.free_func(P->get().setter.method_data); + if (P.get().setter.free_func) + P.get().setter.free_func(P.get().setter.method_data); } // free method stuff diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index 6c55e3e327..bc7e850d3e 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -32,6 +32,7 @@ #include "io/resource_loader.h" #include "io/resource_saver.h" +#include "ordered_hash_map.h" #include "os/thread_safe.h" #include "resource.h" #include "scene/main/node.h" @@ -65,7 +66,7 @@ struct NativeScriptDesc { }; Map methods; - Map properties; + OrderedHashMap properties; Map signals_; // QtCreator doesn't like the name signals StringName base; StringName base_native_type; -- cgit v1.2.3