New sync RPC modes to match all combinations

This commit is contained in:
Fabio Alessandrelli 2018-05-26 10:28:28 +02:00
parent 9de4ffde61
commit 19ba3d5da3
3 changed files with 25 additions and 4 deletions

View file

@ -42,6 +42,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
case MultiplayerAPI::RPC_MODE_REMOTE: {
//do nothing also, no need to call local
} break;
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
case MultiplayerAPI::RPC_MODE_MASTERSYNC:
case MultiplayerAPI::RPC_MODE_SLAVESYNC:
case MultiplayerAPI::RPC_MODE_SYNC: {
//call it, sync always results in call
return true;
@ -67,12 +70,15 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
case MultiplayerAPI::RPC_MODE_REMOTE: {
return true;
} break;
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
case MultiplayerAPI::RPC_MODE_SYNC: {
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTERSYNC:
case MultiplayerAPI::RPC_MODE_MASTER: {
return p_node->is_network_master();
} break;
case MultiplayerAPI::RPC_MODE_SLAVESYNC:
case MultiplayerAPI::RPC_MODE_SLAVE: {
return !p_node->is_network_master() && p_remote_id == p_node->get_network_master();
} break;
@ -797,6 +803,9 @@ void MultiplayerAPI::_bind_methods() {
BIND_ENUM_CONSTANT(RPC_MODE_SYNC);
BIND_ENUM_CONSTANT(RPC_MODE_MASTER);
BIND_ENUM_CONSTANT(RPC_MODE_SLAVE);
BIND_ENUM_CONSTANT(RPC_MODE_REMOTESYNC);
BIND_ENUM_CONSTANT(RPC_MODE_MASTERSYNC);
BIND_ENUM_CONSTANT(RPC_MODE_SLAVESYNC);
}
MultiplayerAPI::MultiplayerAPI() {

View file

@ -94,6 +94,9 @@ public:
RPC_MODE_SYNC, // Using rpc() on it will call method / set property in all remote peers and locally
RPC_MODE_MASTER, // Using rpc() on it will call method on wherever the master is, be it local or remote
RPC_MODE_SLAVE, // Using rpc() on it will call method for all slaves
RPC_MODE_REMOTESYNC, // Same as RPC_MODE_SYNC, compatibility
RPC_MODE_MASTERSYNC, // Using rpc() on it will call method / set property in the master peer and locally
RPC_MODE_SLAVESYNC, // Using rpc() on it will call method / set property in all slave peers and locally
};
void poll();

View file

@ -140,16 +140,25 @@
Used with [method Node.rpc_config] or [method Node.rset_config] to disable a method or property for all RPC calls, making it unavailable. Default for all methods.
</constant>
<constant name="RPC_MODE_REMOTE" value="1" enum="RPCMode">
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on the remote end, not locally. Analogous to the [code]remote[/code] keyword.
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on the remote end, not locally. Analogous to the [code]remote[/code] keyword. Calls and property changes are accepted from all remote peers, no matter if they are node's master or slaves.
</constant>
<constant name="RPC_MODE_SYNC" value="2" enum="RPCMode">
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed both on the remote end and locally. Analogous to the [code]sync[/code] keyword.
Behave like [constant RPC_MODE_REMOTE] but also make the call or property change locally. Analogous to the [code]sync[/code] keyword.
</constant>
<constant name="RPC_MODE_MASTER" value="3" enum="RPCMode">
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on the network master for this node. Analogous to the [code]master[/code] keyword. See [method Node.set_network_master].
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on the network master for this node. Analogous to the [code]master[/code] keyword. Only accepts calls or property changes from the node's network slaves, see [method Node.set_network_master].
</constant>
<constant name="RPC_MODE_SLAVE" value="4" enum="RPCMode">
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on slaves for this node. Analogous to the [code]slave[/code] keyword. See [method Node.set_network_master].
Used with [method Node.rpc_config] or [method Node.rset_config] to set a method to be called or a property to be changed only on slaves for this node. Analogous to the [code]slave[/code] keyword. Only accepts calls or property changes from the node's network master, see [method Node.set_network_master].
</constant>
<constant name="RPC_MODE_REMOTESYNC" value="5" enum="RPCMode">
Behave like [code]RPC_MODE_REMOTE[/code] but also make the call or property change locally. Same as [constant RPC_MODE_SYNC] which is only kept for compatibility. Analogous to the [code]remotesync[/code] keyword.
</constant>
<constant name="RPC_MODE_MASTERSYNC" value="6" enum="RPCMode">
Behave like [code]RPC_MODE_MASTER[/code] but also make the call or property change locally. Analogous to the [code]mastersync[/code] keyword.
</constant>
<constant name="RPC_MODE_SLAVESYNC" value="7" enum="RPCMode">
Behave like [code]RPC_MODE_SLAVE[/code] but also make the call or property change locally. Analogous to the [code]slavesync[/code] keyword.
</constant>
</constants>
</class>