mirror of
https://github.com/godotengine/godot-visual-script.git
synced 2025-12-31 21:48:42 +03:00
[Net] Modularize multiplayer, expose MultiplayerAPI to extensions.
- RPC configurations are now dictionaries. - Script.get_rpc_methods renamed to Script.get_rpc_config. - Node.rpc[_id] and Callable.rpc now return an Error. - Refactor MultiplayerAPI to allow extension. - New MultiplayerAPI.rpc method with Array argument (for scripts). - Move the default MultiplayerAPI implementation to a module.
This commit is contained in:
@@ -948,7 +948,7 @@ bool VisualScript::are_subnodes_edited() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
const Vector<Multiplayer::RPCConfig> VisualScript::get_rpc_methods() const {
|
||||
const Variant VisualScript::get_rpc_config() const {
|
||||
return rpc_functions;
|
||||
}
|
||||
|
||||
@@ -1012,22 +1012,16 @@ void VisualScript::_set_data(const Dictionary &p_data) {
|
||||
for (const KeyValue<StringName, Function> &E : functions) {
|
||||
if (E.value.func_id >= 0 && nodes.has(E.value.func_id)) {
|
||||
Ref<VisualScriptFunction> vsf = nodes[E.value.func_id].node;
|
||||
if (vsf.is_valid()) {
|
||||
if (vsf->get_rpc_mode() != Multiplayer::RPC_MODE_DISABLED) {
|
||||
Multiplayer::RPCConfig nd;
|
||||
nd.name = E.key;
|
||||
nd.rpc_mode = vsf->get_rpc_mode();
|
||||
nd.transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; // TODO
|
||||
if (rpc_functions.find(nd) == -1) {
|
||||
rpc_functions.push_back(nd);
|
||||
}
|
||||
}
|
||||
if (!vsf.is_valid() || vsf->get_rpc_mode() == MultiplayerAPI::RPC_MODE_DISABLED) {
|
||||
continue;
|
||||
}
|
||||
Dictionary nd;
|
||||
nd["rpc_mode"] = vsf->get_rpc_mode();
|
||||
nd["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; // TODO
|
||||
nd["call_local"] = false; // TODO
|
||||
rpc_functions[E.key] = nd;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort so we are 100% that they are always the same.
|
||||
rpc_functions.sort_custom<Multiplayer::SortRPCConfig>();
|
||||
}
|
||||
|
||||
Dictionary VisualScript::_get_data() const {
|
||||
@@ -1811,8 +1805,8 @@ Ref<Script> VisualScriptInstance::get_script() const {
|
||||
return script;
|
||||
}
|
||||
|
||||
const Vector<Multiplayer::RPCConfig> VisualScriptInstance::get_rpc_methods() const {
|
||||
return script->get_rpc_methods();
|
||||
const Variant VisualScriptInstance::get_rpc_config() const {
|
||||
return script->get_rpc_config();
|
||||
}
|
||||
|
||||
void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) {
|
||||
|
||||
@@ -235,7 +235,7 @@ private:
|
||||
HashMap<StringName, Function> functions;
|
||||
HashMap<StringName, Variable> variables;
|
||||
HashMap<StringName, Vector<Argument>> custom_signals;
|
||||
Vector<Multiplayer::RPCConfig> rpc_functions;
|
||||
Dictionary rpc_functions;
|
||||
|
||||
HashMap<Object *, VisualScriptInstance *> instances;
|
||||
|
||||
@@ -363,7 +363,7 @@ public:
|
||||
|
||||
virtual int get_member_line(const StringName &p_member) const override;
|
||||
|
||||
virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override;
|
||||
virtual const Variant get_rpc_config() const override;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual bool are_subnodes_edited() const;
|
||||
@@ -444,7 +444,7 @@ public:
|
||||
|
||||
virtual ScriptLanguage *get_language();
|
||||
|
||||
virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const;
|
||||
virtual const Variant get_rpc_config() const;
|
||||
|
||||
VisualScriptInstance();
|
||||
~VisualScriptInstance();
|
||||
|
||||
@@ -90,7 +90,7 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value
|
||||
}
|
||||
|
||||
if (p_name == "rpc/mode") {
|
||||
rpc_mode = Multiplayer::RPCMode(int(p_value));
|
||||
rpc_mode = MultiplayerAPI::RPCMode(int(p_value));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -261,11 +261,11 @@ int VisualScriptFunction::get_argument_count() const {
|
||||
return arguments.size();
|
||||
}
|
||||
|
||||
void VisualScriptFunction::set_rpc_mode(Multiplayer::RPCMode p_mode) {
|
||||
void VisualScriptFunction::set_rpc_mode(MultiplayerAPI::RPCMode p_mode) {
|
||||
rpc_mode = p_mode;
|
||||
}
|
||||
|
||||
Multiplayer::RPCMode VisualScriptFunction::get_rpc_mode() const {
|
||||
MultiplayerAPI::RPCMode VisualScriptFunction::get_rpc_mode() const {
|
||||
return rpc_mode;
|
||||
}
|
||||
|
||||
@@ -311,14 +311,14 @@ void VisualScriptFunction::reset_state() {
|
||||
stack_size = 256;
|
||||
stack_less = false;
|
||||
sequenced = true;
|
||||
rpc_mode = Multiplayer::RPC_MODE_DISABLED;
|
||||
rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
|
||||
}
|
||||
|
||||
VisualScriptFunction::VisualScriptFunction() {
|
||||
stack_size = 256;
|
||||
stack_less = false;
|
||||
sequenced = true;
|
||||
rpc_mode = Multiplayer::RPC_MODE_DISABLED;
|
||||
rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
|
||||
}
|
||||
|
||||
void VisualScriptFunction::set_stack_less(bool p_enable) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "scene/main/multiplayer_api.h"
|
||||
#include "visual_script.h"
|
||||
|
||||
class VisualScriptFunction : public VisualScriptNode {
|
||||
@@ -49,7 +50,7 @@ class VisualScriptFunction : public VisualScriptNode {
|
||||
|
||||
bool stack_less;
|
||||
int stack_size;
|
||||
Multiplayer::RPCMode rpc_mode;
|
||||
MultiplayerAPI::RPCMode rpc_mode;
|
||||
bool sequenced;
|
||||
|
||||
protected:
|
||||
@@ -90,8 +91,8 @@ public:
|
||||
void set_stack_size(int p_size);
|
||||
int get_stack_size() const;
|
||||
|
||||
void set_rpc_mode(Multiplayer::RPCMode p_mode);
|
||||
Multiplayer::RPCMode get_rpc_mode() const;
|
||||
void set_rpc_mode(MultiplayerAPI::RPCMode p_mode);
|
||||
MultiplayerAPI::RPCMode get_rpc_mode() const;
|
||||
|
||||
virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user