summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Catania <info@andreacatania.com>2020-02-27 16:06:39 +0100
committerAndrea Catania <info@andreacatania.com>2020-02-28 12:39:18 +0100
commit33ae58710b2ba63b8c238043fcc093f3dc7e1106 (patch)
tree13ed33504e81ffb3256f53cfb0fa2833b396ac23
parented0f1940cbdbe470da85f446f315ee12897038a1 (diff)
Generates the rpc and rset info for exported GDScript.
Improved the send rpc log message when fail. This work has been kindly sponsored by IMVU.
-rw-r--r--core/io/multiplayer_api.cpp3
-rw-r--r--modules/gdscript/gdscript.cpp98
-rw-r--r--modules/gdscript/gdscript.h1
3 files changed, 55 insertions, 47 deletions
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 2aef0a3274..3d3c105528 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -863,7 +863,8 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
if (method_id == UINT16_MAX && p_from->get_script_instance()) {
method_id = p_from->get_script_instance()->get_rpc_method_id(p_name);
}
- ERR_FAIL_COND_MSG(method_id == UINT16_MAX, "Unable to take the `method_id` for the function:" + p_name + ". this can happen only if this method is not marked as `remote`.");
+ ERR_FAIL_COND_MSG(method_id == UINT16_MAX,
+ vformat("Unable to take the `method_id` for the function \"%s\" at path: \"%s\". This happens when the method is not marked as `remote`.", p_name, p_from->get_path()));
if (method_id <= UINT8_MAX) {
// The ID fits in 1 byte
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index a72bb7ba49..68a5f6b83b 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -613,52 +613,7 @@ Error GDScript::reload(bool p_keep_state) {
_set_subclass_path(E->get(), path);
}
- // Copy the base rpc methods so we don't mask their IDs.
- rpc_functions.clear();
- rpc_variables.clear();
- if (base.is_valid()) {
- rpc_functions = base->rpc_functions;
- rpc_variables = base->rpc_variables;
- }
-
- GDScript *cscript = this;
- Map<StringName, Ref<GDScript> >::Element *sub_E = subclasses.front();
- while (cscript) {
- // RPC Methods
- for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) {
- if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
- ScriptNetData nd;
- nd.name = E->key();
- nd.mode = E->get()->get_rpc_mode();
- if (-1 == rpc_functions.find(nd)) {
- rpc_functions.push_back(nd);
- }
- }
- }
- // RSet
- for (Map<StringName, MemberInfo>::Element *E = cscript->member_indices.front(); E; E = E->next()) {
- if (E->get().rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) {
- ScriptNetData nd;
- nd.name = E->key();
- nd.mode = E->get().rpc_mode;
- if (-1 == rpc_variables.find(nd)) {
- rpc_variables.push_back(nd);
- }
- }
- }
-
- if (cscript != this)
- sub_E = sub_E->next();
-
- if (sub_E)
- cscript = sub_E->get().ptr();
- else
- cscript = NULL;
- }
-
- // Sort so we are 100% that they are always the same.
- rpc_functions.sort_custom<SortNetData>();
- rpc_variables.sort_custom<SortNetData>();
+ _init_rpc_methods_properties();
return OK;
}
@@ -897,6 +852,8 @@ Error GDScript::load_byte_code(const String &p_path) {
_set_subclass_path(E->get(), path);
}
+ _init_rpc_methods_properties();
+
return OK;
}
@@ -1049,6 +1006,55 @@ void GDScript::_save_orphaned_subclasses() {
}
}
+void GDScript::_init_rpc_methods_properties() {
+ // Copy the base rpc methods so we don't mask their IDs.
+ rpc_functions.clear();
+ rpc_variables.clear();
+ if (base.is_valid()) {
+ rpc_functions = base->rpc_functions;
+ rpc_variables = base->rpc_variables;
+ }
+
+ GDScript *cscript = this;
+ Map<StringName, Ref<GDScript> >::Element *sub_E = subclasses.front();
+ while (cscript) {
+ // RPC Methods
+ for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) {
+ if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = E->get()->get_rpc_mode();
+ if (-1 == rpc_functions.find(nd)) {
+ rpc_functions.push_back(nd);
+ }
+ }
+ }
+ // RSet
+ for (Map<StringName, MemberInfo>::Element *E = cscript->member_indices.front(); E; E = E->next()) {
+ if (E->get().rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = E->get().rpc_mode;
+ if (-1 == rpc_variables.find(nd)) {
+ rpc_variables.push_back(nd);
+ }
+ }
+ }
+
+ if (cscript != this)
+ sub_E = sub_E->next();
+
+ if (sub_E)
+ cscript = sub_E->get().ptr();
+ else
+ cscript = NULL;
+ }
+
+ // Sort so we are 100% that they are always the same.
+ rpc_functions.sort_custom<SortNetData>();
+ rpc_variables.sort_custom<SortNetData>();
+}
+
GDScript::~GDScript() {
for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) {
memdelete(E->get());
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 6598a0023b..5138c119ca 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -134,6 +134,7 @@ class GDScript : public Script {
bool _update_exports();
void _save_orphaned_subclasses();
+ void _init_rpc_methods_properties();
protected:
bool _get(const StringName &p_name, Variant &r_ret) const;