[Net] Move multiplayer to core subdir, split RPCManager.
Move multiplayer classes to "core/multiplayer" subdir. Move the RPCConfig and enums (TransferMode, RPCMode) to a separate file (multiplayer.h), and bind them to the global namespace. Move the RPC handling code to its own class (RPCManager). Renames "get_rpc_sender_id" to "get_remote_sender_id".
This commit is contained in:
parent
b0b30aaf41
commit
bf9aae09ba
57 changed files with 976 additions and 767 deletions
|
|
@ -900,7 +900,7 @@ void GDScript::get_members(Set<StringName> *p_members) {
|
|||
}
|
||||
}
|
||||
|
||||
const Vector<MultiplayerAPI::RPCConfig> GDScript::get_rpc_methods() const {
|
||||
const Vector<Multiplayer::RPCConfig> GDScript::get_rpc_methods() const {
|
||||
return rpc_functions;
|
||||
}
|
||||
|
||||
|
|
@ -1164,8 +1164,8 @@ void GDScript::_init_rpc_methods_properties() {
|
|||
while (cscript) {
|
||||
// RPC Methods
|
||||
for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) {
|
||||
MultiplayerAPI::RPCConfig config = E->get()->get_rpc_config();
|
||||
if (config.rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) {
|
||||
Multiplayer::RPCConfig config = E->get()->get_rpc_config();
|
||||
if (config.rpc_mode != Multiplayer::RPC_MODE_DISABLED) {
|
||||
config.name = E->get()->get_name();
|
||||
if (rpc_functions.find(config) == -1) {
|
||||
rpc_functions.push_back(config);
|
||||
|
|
@ -1185,7 +1185,7 @@ void GDScript::_init_rpc_methods_properties() {
|
|||
}
|
||||
|
||||
// Sort so we are 100% that they are always the same.
|
||||
rpc_functions.sort_custom<MultiplayerAPI::SortRPCConfig>();
|
||||
rpc_functions.sort_custom<Multiplayer::SortRPCConfig>();
|
||||
}
|
||||
|
||||
GDScript::~GDScript() {
|
||||
|
|
@ -1541,7 +1541,7 @@ ScriptLanguage *GDScriptInstance::get_language() {
|
|||
return GDScriptLanguage::get_singleton();
|
||||
}
|
||||
|
||||
const Vector<MultiplayerAPI::RPCConfig> GDScriptInstance::get_rpc_methods() const {
|
||||
const Vector<Multiplayer::RPCConfig> GDScriptInstance::get_rpc_methods() const {
|
||||
return script->get_rpc_methods();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class GDScript : public Script {
|
|||
Map<StringName, MemberInfo> member_indices; //members are just indices to the instantiated script.
|
||||
Map<StringName, Ref<GDScript>> subclasses;
|
||||
Map<StringName, Vector<StringName>> _signals;
|
||||
Vector<MultiplayerAPI::RPCConfig> rpc_functions;
|
||||
Vector<Multiplayer::RPCConfig> rpc_functions;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ public:
|
|||
virtual void get_constants(Map<StringName, Variant> *p_constants) override;
|
||||
virtual void get_members(Set<StringName> *p_members) override;
|
||||
|
||||
virtual const Vector<MultiplayerAPI::RPCConfig> get_rpc_methods() const override;
|
||||
virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; }
|
||||
|
|
@ -298,7 +298,7 @@ public:
|
|||
|
||||
void reload_members();
|
||||
|
||||
virtual const Vector<MultiplayerAPI::RPCConfig> get_rpc_methods() const;
|
||||
virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const;
|
||||
|
||||
GDScriptInstance();
|
||||
~GDScriptInstance();
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ void GDScriptByteCodeGenerator::end_parameters() {
|
|||
function->default_arguments.reverse();
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) {
|
||||
void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, Multiplayer::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) {
|
||||
function = memnew(GDScriptFunction);
|
||||
debug_stack = EngineDebugger::is_active();
|
||||
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ public:
|
|||
virtual void start_block() override;
|
||||
virtual void end_block() override;
|
||||
|
||||
virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) override;
|
||||
virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, Multiplayer::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) override;
|
||||
virtual GDScriptFunction *write_end() override;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#ifndef GDSCRIPT_CODEGEN
|
||||
#define GDSCRIPT_CODEGEN
|
||||
|
||||
#include "core/io/multiplayer_api.h"
|
||||
#include "core/multiplayer/multiplayer.h"
|
||||
#include "core/string/string_name.h"
|
||||
#include "core/variant/variant.h"
|
||||
#include "gdscript_function.h"
|
||||
|
|
@ -80,7 +80,7 @@ public:
|
|||
virtual void start_block() = 0;
|
||||
virtual void end_block() = 0;
|
||||
|
||||
virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) = 0;
|
||||
virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, Multiplayer::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) = 0;
|
||||
virtual GDScriptFunction *write_end() = 0;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
|
|
|||
|
|
@ -1857,7 +1857,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
|
|||
|
||||
StringName func_name;
|
||||
bool is_static = false;
|
||||
MultiplayerAPI::RPCConfig rpc_config;
|
||||
Multiplayer::RPCConfig rpc_config;
|
||||
GDScriptDataType return_type;
|
||||
return_type.has_type = true;
|
||||
return_type.kind = GDScriptDataType::BUILTIN;
|
||||
|
|
@ -2086,7 +2086,7 @@ Error GDScriptCompiler::_parse_setter_getter(GDScript *p_script, const GDScriptP
|
|||
return_type = _gdtype_from_datatype(p_variable->get_datatype(), p_script);
|
||||
}
|
||||
|
||||
codegen.generator->write_start(p_script, func_name, false, MultiplayerAPI::RPCConfig(), return_type);
|
||||
codegen.generator->write_start(p_script, func_name, false, Multiplayer::RPCConfig(), return_type);
|
||||
|
||||
if (p_is_setter) {
|
||||
uint32_t par_addr = codegen.generator->add_parameter(p_variable->setter_parameter->name, false, _gdtype_from_datatype(p_variable->get_datatype()));
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ private:
|
|||
|
||||
int _initial_line = 0;
|
||||
bool _static = false;
|
||||
MultiplayerAPI::RPCConfig rpc_config;
|
||||
Multiplayer::RPCConfig rpc_config;
|
||||
|
||||
GDScript *_script = nullptr;
|
||||
|
||||
|
|
@ -588,7 +588,7 @@ public:
|
|||
void disassemble(const Vector<String> &p_code_lines) const;
|
||||
#endif
|
||||
|
||||
_FORCE_INLINE_ MultiplayerAPI::RPCConfig get_rpc_config() const { return rpc_config; }
|
||||
_FORCE_INLINE_ Multiplayer::RPCConfig get_rpc_config() const { return rpc_config; }
|
||||
GDScriptFunction();
|
||||
~GDScriptFunction();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ GDScriptParser::GDScriptParser() {
|
|||
register_annotation(MethodInfo("@export_flags_3d_physics"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_PHYSICS, Variant::INT>);
|
||||
register_annotation(MethodInfo("@export_flags_3d_navigation"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_NAVIGATION, Variant::INT>);
|
||||
// Networking.
|
||||
register_annotation(MethodInfo("@rpc", { Variant::STRING, "mode" }, { Variant::STRING, "sync" }, { Variant::STRING, "transfer_mode" }, { Variant::INT, "transfer_channel" }), AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_AUTHORITY>, 4, true);
|
||||
register_annotation(MethodInfo("@rpc", { Variant::STRING, "mode" }, { Variant::STRING, "sync" }, { Variant::STRING, "transfer_mode" }, { Variant::INT, "transfer_channel" }), AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<Multiplayer::RPC_MODE_AUTHORITY>, 4, true);
|
||||
// TODO: Warning annotations.
|
||||
}
|
||||
|
||||
|
|
@ -3393,11 +3393,11 @@ bool GDScriptParser::warning_annotations(const AnnotationNode *p_annotation, Nod
|
|||
ERR_FAIL_V_MSG(false, "Not implemented.");
|
||||
}
|
||||
|
||||
template <MultiplayerAPI::RPCMode t_mode>
|
||||
template <Multiplayer::RPCMode t_mode>
|
||||
bool GDScriptParser::network_annotations(const AnnotationNode *p_annotation, Node *p_node) {
|
||||
ERR_FAIL_COND_V_MSG(p_node->type != Node::VARIABLE && p_node->type != Node::FUNCTION, false, vformat(R"("%s" annotation can only be applied to variables and functions.)", p_annotation->name));
|
||||
|
||||
MultiplayerAPI::RPCConfig rpc_config;
|
||||
Multiplayer::RPCConfig rpc_config;
|
||||
rpc_config.rpc_mode = t_mode;
|
||||
if (p_annotation->resolved_arguments.size()) {
|
||||
int last = p_annotation->resolved_arguments.size() - 1;
|
||||
|
|
@ -3412,19 +3412,19 @@ bool GDScriptParser::network_annotations(const AnnotationNode *p_annotation, Nod
|
|||
for (int i = last; i >= 0; i--) {
|
||||
String mode = p_annotation->resolved_arguments[i].operator String();
|
||||
if (mode == "any") {
|
||||
rpc_config.rpc_mode = MultiplayerAPI::RPC_MODE_ANY;
|
||||
rpc_config.rpc_mode = Multiplayer::RPC_MODE_ANY;
|
||||
} else if (mode == "auth") {
|
||||
rpc_config.rpc_mode = MultiplayerAPI::RPC_MODE_AUTHORITY;
|
||||
rpc_config.rpc_mode = Multiplayer::RPC_MODE_AUTHORITY;
|
||||
} else if (mode == "sync") {
|
||||
rpc_config.sync = true;
|
||||
} else if (mode == "nosync") {
|
||||
rpc_config.sync = false;
|
||||
} else if (mode == "reliable") {
|
||||
rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE;
|
||||
rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE;
|
||||
} else if (mode == "unreliable") {
|
||||
rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_UNRELIABLE;
|
||||
rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_UNRELIABLE;
|
||||
} else if (mode == "ordered") {
|
||||
rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_UNRELIABLE_ORDERED;
|
||||
rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_ORDERED;
|
||||
} else {
|
||||
push_error(R"(Invalid RPC argument. Must be one of: 'sync'/'nosync' (local calls), 'any'/'auth' (permission), 'reliable'/'unreliable'/'ordered' (transfer mode).)", p_annotation);
|
||||
}
|
||||
|
|
@ -3433,7 +3433,7 @@ bool GDScriptParser::network_annotations(const AnnotationNode *p_annotation, Nod
|
|||
switch (p_node->type) {
|
||||
case Node::FUNCTION: {
|
||||
FunctionNode *function = static_cast<FunctionNode *>(p_node);
|
||||
if (function->rpc_config.rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) {
|
||||
if (function->rpc_config.rpc_mode != Multiplayer::RPC_MODE_DISABLED) {
|
||||
push_error(R"(RPC annotations can only be used once per function.)", p_annotation);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
#ifndef GDSCRIPT_PARSER_H
|
||||
#define GDSCRIPT_PARSER_H
|
||||
|
||||
#include "core/io/multiplayer_api.h"
|
||||
#include "core/io/resource.h"
|
||||
#include "core/multiplayer/multiplayer.h"
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/string/string_name.h"
|
||||
|
|
@ -729,7 +729,7 @@ public:
|
|||
SuiteNode *body = nullptr;
|
||||
bool is_static = false;
|
||||
bool is_coroutine = false;
|
||||
MultiplayerAPI::RPCConfig rpc_config;
|
||||
Multiplayer::RPCConfig rpc_config;
|
||||
MethodInfo info;
|
||||
LambdaNode *source_lambda = nullptr;
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
|
@ -1340,7 +1340,7 @@ private:
|
|||
template <PropertyHint t_hint, Variant::Type t_type>
|
||||
bool export_annotations(const AnnotationNode *p_annotation, Node *p_target);
|
||||
bool warning_annotations(const AnnotationNode *p_annotation, Node *p_target);
|
||||
template <MultiplayerAPI::RPCMode t_mode>
|
||||
template <Multiplayer::RPCMode t_mode>
|
||||
bool network_annotations(const AnnotationNode *p_annotation, Node *p_target);
|
||||
// Statements.
|
||||
Node *parse_statement();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue