From 1add52b55e038a4fa789c64f3919f7fcab808e91 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 19 Aug 2016 16:48:08 -0300 Subject: [PATCH] Brand new networked multiplayer --- core/io/networked_multiplayer_peer.cpp | 17 +- core/io/networked_multiplayer_peer.h | 17 +- core/script_language.h | 18 +- modules/enet/networked_multiplayer_enet.cpp | 382 ++++++++++-- modules/enet/networked_multiplayer_enet.h | 33 +- modules/enet/protocol.c | 1 + modules/gdscript/gd_compiler.cpp | 6 +- modules/gdscript/gd_editor.cpp | 28 +- modules/gdscript/gd_function.cpp | 1 + modules/gdscript/gd_function.h | 12 + modules/gdscript/gd_parser.cpp | 99 ++- modules/gdscript/gd_parser.h | 8 +- modules/gdscript/gd_script.cpp | 46 +- modules/gdscript/gd_script.h | 101 +-- modules/gdscript/gd_tokenizer.cpp | 10 +- modules/gdscript/gd_tokenizer.h | 4 + modules/visual_script/visual_script.cpp | 13 +- modules/visual_script/visual_script.h | 5 +- .../visual_script_func_nodes.cpp | 6 +- scene/main/node.cpp | 574 ++++++++++++++++-- scene/main/node.h | 45 +- scene/main/scene_main_loop.cpp | 116 +++- scene/main/scene_main_loop.h | 23 +- 23 files changed, 1312 insertions(+), 253 deletions(-) diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp index 851064b6e81..a771ba06b70 100644 --- a/core/io/networked_multiplayer_peer.cpp +++ b/core/io/networked_multiplayer_peer.cpp @@ -5,14 +5,16 @@ void NetworkedMultiplayerPeer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_transfer_mode","mode"), &NetworkedMultiplayerPeer::set_transfer_mode ); ObjectTypeDB::bind_method(_MD("set_target_peer","id"), &NetworkedMultiplayerPeer::set_target_peer ); - ObjectTypeDB::bind_method(_MD("set_channel","id"), &NetworkedMultiplayerPeer::set_channel ); ObjectTypeDB::bind_method(_MD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer ); - ObjectTypeDB::bind_method(_MD("get_packet_channel"), &NetworkedMultiplayerPeer::get_packet_channel ); ObjectTypeDB::bind_method(_MD("poll"), &NetworkedMultiplayerPeer::poll ); ObjectTypeDB::bind_method(_MD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status ); + ObjectTypeDB::bind_method(_MD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id ); + + ObjectTypeDB::bind_method(_MD("set_refuse_new_connections","enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections ); + ObjectTypeDB::bind_method(_MD("is_refusing_new_connections"), &NetworkedMultiplayerPeer::is_refusing_new_connections ); BIND_CONSTANT( TRANSFER_MODE_UNRELIABLE ); BIND_CONSTANT( TRANSFER_MODE_RELIABLE ); @@ -22,8 +24,15 @@ void NetworkedMultiplayerPeer::_bind_methods() { BIND_CONSTANT( CONNECTION_CONNECTING ); BIND_CONSTANT( CONNECTION_CONNECTED ); - ADD_SIGNAL( MethodInfo("peer_connected",PropertyInfo(Variant::STRING,"id"))); - ADD_SIGNAL( MethodInfo("peer_disconnected",PropertyInfo(Variant::STRING,"id"))); + BIND_CONSTANT( TARGET_PEER_BROADCAST ); + BIND_CONSTANT( TARGET_PEER_SERVER ); + + + ADD_SIGNAL( MethodInfo("peer_connected",PropertyInfo(Variant::INT,"id"))); + ADD_SIGNAL( MethodInfo("peer_disconnected",PropertyInfo(Variant::INT,"id"))); + ADD_SIGNAL( MethodInfo("server_disconnected")); + ADD_SIGNAL( MethodInfo("connection_succeeded") ); + ADD_SIGNAL( MethodInfo("connection_failed") ); } NetworkedMultiplayerPeer::NetworkedMultiplayerPeer() { diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h index 7071a52d7b8..1c39096ab59 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/networked_multiplayer_peer.h @@ -11,6 +11,10 @@ protected: static void _bind_methods(); public: + enum { + TARGET_PEER_BROADCAST=0, + TARGET_PEER_SERVER=1 + }; enum TransferMode { TRANSFER_MODE_UNRELIABLE, TRANSFER_MODE_RELIABLE, @@ -25,17 +29,20 @@ public: virtual void set_transfer_mode(TransferMode p_mode)=0; - virtual void set_target_peer(const StringName& p_peer_id)=0; - virtual void set_channel(int p_channel)=0; + virtual void set_target_peer(int p_peer_id)=0; - - virtual StringName get_packet_peer() const=0; - virtual int get_packet_channel() const=0; + virtual int get_packet_peer() const=0; virtual bool is_server() const=0; virtual void poll()=0; + virtual int get_unique_id() const=0; + + virtual void set_refuse_new_connections(bool p_enable)=0; + virtual bool is_refusing_new_connections() const=0; + + virtual ConnectionStatus get_connection_status() const=0; NetworkedMultiplayerPeer(); diff --git a/core/script_language.h b/core/script_language.h index 0e3f2987903..aac94bb067b 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -113,7 +113,7 @@ public: virtual bool get_property_default_value(const StringName& p_property,Variant& r_value) const=0; virtual void update_exports() {} //editor tool - virtual void get_method_list(List *p_list) const=0; + virtual void get_script_method_list(List *p_list) const=0; Script() {} @@ -121,6 +121,8 @@ public: class ScriptInstance { public: + + virtual bool set(const StringName& p_name, const Variant& p_value)=0; virtual bool get(const StringName& p_name, Variant &r_ret) const=0; virtual void get_property_list(List *p_properties) const=0; @@ -148,6 +150,17 @@ public: virtual bool is_placeholder() const { return false; } + enum RPCMode { + RPC_MODE_DISABLED, + RPC_MODE_REMOTE, + RPC_MODE_SYNC, + RPC_MODE_MASTER, + RPC_MODE_SLAVE, + }; + + virtual RPCMode get_rpc_mode(const StringName& p_method) const=0; + virtual RPCMode get_rset_mode(const StringName& p_variable) const=0; + virtual ScriptLanguage *get_language()=0; virtual ~ScriptInstance(); }; @@ -279,6 +292,9 @@ public: virtual bool is_placeholder() const { return true; } + virtual RPCMode get_rpc_mode(const StringName& p_method) const { return RPC_MODE_DISABLED; } + virtual RPCMode get_rset_mode(const StringName& p_variable) const { return RPC_MODE_DISABLED; } + PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref