mirror of
https://github.com/godotengine/godot
synced 2024-09-04 21:28:28 +00:00
New sync keywords in GDScript, NativeScript, Mono
This commit is contained in:
parent
4524153b6e
commit
8e35d937a9
|
@ -43,6 +43,9 @@ typedef enum {
|
|||
GODOT_METHOD_RPC_MODE_SYNC,
|
||||
GODOT_METHOD_RPC_MODE_MASTER,
|
||||
GODOT_METHOD_RPC_MODE_SLAVE,
|
||||
GODOT_METHOD_RPC_MODE_REMOTESYNC,
|
||||
GODOT_METHOD_RPC_MODE_MASTERSYNC,
|
||||
GODOT_METHOD_RPC_MODE_SLAVESYNC,
|
||||
} godot_method_rpc_mode;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -766,6 +766,12 @@ MultiplayerAPI::RPCMode NativeScriptInstance::get_rpc_mode(const StringName &p_m
|
|||
return MultiplayerAPI::RPC_MODE_MASTER;
|
||||
case GODOT_METHOD_RPC_MODE_SLAVE:
|
||||
return MultiplayerAPI::RPC_MODE_SLAVE;
|
||||
case GODOT_METHOD_RPC_MODE_REMOTESYNC:
|
||||
return MultiplayerAPI::RPC_MODE_REMOTESYNC;
|
||||
case GODOT_METHOD_RPC_MODE_MASTERSYNC:
|
||||
return MultiplayerAPI::RPC_MODE_MASTERSYNC;
|
||||
case GODOT_METHOD_RPC_MODE_SLAVESYNC:
|
||||
return MultiplayerAPI::RPC_MODE_SLAVESYNC;
|
||||
default:
|
||||
return MultiplayerAPI::RPC_MODE_DISABLED;
|
||||
}
|
||||
|
|
|
@ -1769,6 +1769,9 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
|||
"sync",
|
||||
"master",
|
||||
"slave",
|
||||
"remotesync",
|
||||
"mastersync",
|
||||
"slavesync",
|
||||
0
|
||||
};
|
||||
|
||||
|
|
|
@ -3931,10 +3931,10 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
tokenizer->advance();
|
||||
}
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SLAVE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SYNC) {
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SLAVE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTESYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTERSYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SLAVESYNC) {
|
||||
|
||||
current_export = PropertyInfo();
|
||||
_set_error("Expected 'var', 'onready', 'remote', 'master', 'slave' or 'sync'.");
|
||||
_set_error("Expected 'var', 'onready', 'remote', 'master', 'slave', 'sync', 'remotesync', 'mastersync', 'slavesync'.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4011,6 +4011,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
rpc_mode = MultiplayerAPI::RPC_MODE_SLAVE;
|
||||
continue;
|
||||
} break;
|
||||
case GDScriptTokenizer::TK_PR_REMOTESYNC:
|
||||
case GDScriptTokenizer::TK_PR_SYNC: {
|
||||
|
||||
//may be fallthrough from export, ignore if so
|
||||
|
@ -4026,6 +4027,36 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
rpc_mode = MultiplayerAPI::RPC_MODE_SYNC;
|
||||
continue;
|
||||
} break;
|
||||
case GDScriptTokenizer::TK_PR_MASTERSYNC: {
|
||||
|
||||
//may be fallthrough from export, ignore if so
|
||||
tokenizer->advance();
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
|
||||
if (current_export.type)
|
||||
_set_error("Expected 'var'.");
|
||||
else
|
||||
_set_error("Expected 'var' or 'func'.");
|
||||
return;
|
||||
}
|
||||
|
||||
rpc_mode = MultiplayerAPI::RPC_MODE_MASTERSYNC;
|
||||
continue;
|
||||
} break;
|
||||
case GDScriptTokenizer::TK_PR_SLAVESYNC: {
|
||||
|
||||
//may be fallthrough from export, ignore if so
|
||||
tokenizer->advance();
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
|
||||
if (current_export.type)
|
||||
_set_error("Expected 'var'.");
|
||||
else
|
||||
_set_error("Expected 'var' or 'func'.");
|
||||
return;
|
||||
}
|
||||
|
||||
rpc_mode = MultiplayerAPI::RPC_MODE_SLAVESYNC;
|
||||
continue;
|
||||
} break;
|
||||
case GDScriptTokenizer::TK_PR_VAR: {
|
||||
//variale declaration and (eventual) initialization
|
||||
|
||||
|
|
|
@ -110,6 +110,9 @@ const char *GDScriptTokenizer::token_names[TK_MAX] = {
|
|||
"sync",
|
||||
"master",
|
||||
"slave",
|
||||
"remotesync",
|
||||
"mastersync",
|
||||
"slavesync",
|
||||
"'['",
|
||||
"']'",
|
||||
"'{'",
|
||||
|
@ -201,6 +204,9 @@ static const _kws _keyword_list[] = {
|
|||
{ GDScriptTokenizer::TK_PR_MASTER, "master" },
|
||||
{ GDScriptTokenizer::TK_PR_SLAVE, "slave" },
|
||||
{ GDScriptTokenizer::TK_PR_SYNC, "sync" },
|
||||
{ GDScriptTokenizer::TK_PR_REMOTESYNC, "remotesync" },
|
||||
{ GDScriptTokenizer::TK_PR_MASTERSYNC, "mastersync" },
|
||||
{ GDScriptTokenizer::TK_PR_SLAVESYNC, "slavesync" },
|
||||
{ GDScriptTokenizer::TK_PR_CONST, "const" },
|
||||
{ GDScriptTokenizer::TK_PR_ENUM, "enum" },
|
||||
//controlflow
|
||||
|
@ -247,6 +253,9 @@ bool GDScriptTokenizer::is_token_literal(int p_offset, bool variable_safe) const
|
|||
case TK_PR_MASTER:
|
||||
case TK_PR_SLAVE:
|
||||
case TK_PR_SYNC:
|
||||
case TK_PR_REMOTESYNC:
|
||||
case TK_PR_MASTERSYNC:
|
||||
case TK_PR_SLAVESYNC:
|
||||
return true;
|
||||
|
||||
// Literal for non-variables only:
|
||||
|
|
|
@ -115,6 +115,9 @@ public:
|
|||
TK_PR_SYNC,
|
||||
TK_PR_MASTER,
|
||||
TK_PR_SLAVE,
|
||||
TK_PR_REMOTESYNC,
|
||||
TK_PR_MASTERSYNC,
|
||||
TK_PR_SLAVESYNC,
|
||||
TK_BRACKET_OPEN,
|
||||
TK_BRACKET_CLOSE,
|
||||
TK_CURLY_BRACKET_OPEN,
|
||||
|
|
|
@ -1320,6 +1320,12 @@ MultiplayerAPI::RPCMode CSharpInstance::_member_get_rpc_mode(GDMonoClassMember *
|
|||
return MultiplayerAPI::RPC_MODE_MASTER;
|
||||
if (p_member->has_attribute(CACHED_CLASS(SlaveAttribute)))
|
||||
return MultiplayerAPI::RPC_MODE_SLAVE;
|
||||
if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute)))
|
||||
return MultiplayerAPI::RPC_MODE_REMOTESYNC;
|
||||
if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute)))
|
||||
return MultiplayerAPI::RPC_MODE_MASTERSYNC;
|
||||
if (p_member->has_attribute(CACHED_CLASS(SlaveSyncAttribute)))
|
||||
return MultiplayerAPI::RPC_MODE_SLAVESYNC;
|
||||
|
||||
return MultiplayerAPI::RPC_MODE_DISABLED;
|
||||
}
|
||||
|
|
|
@ -13,4 +13,13 @@ namespace Godot
|
|||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
|
||||
public class SlaveAttribute : Attribute {}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
|
||||
public class RemoteSyncAttribute : Attribute {}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
|
||||
public class MasterSyncAttribute : Attribute {}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field)]
|
||||
public class SlaveSyncAttribute : Attribute {}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,9 @@ void MonoCache::clear_members() {
|
|||
class_SyncAttribute = NULL;
|
||||
class_MasterAttribute = NULL;
|
||||
class_SlaveAttribute = NULL;
|
||||
class_RemoteSyncAttribute = NULL;
|
||||
class_MasterSyncAttribute = NULL;
|
||||
class_SlaveSyncAttribute = NULL;
|
||||
class_GodotMethodAttribute = NULL;
|
||||
field_GodotMethodAttribute_methodName = NULL;
|
||||
|
||||
|
@ -208,6 +211,9 @@ void update_godot_api_cache() {
|
|||
CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute));
|
||||
CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute));
|
||||
CACHE_CLASS_AND_CHECK(SlaveAttribute, GODOT_API_CLASS(SlaveAttribute));
|
||||
CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute));
|
||||
CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute));
|
||||
CACHE_CLASS_AND_CHECK(SlaveSyncAttribute, GODOT_API_CLASS(SlaveSyncAttribute));
|
||||
CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute));
|
||||
CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName"));
|
||||
|
||||
|
|
|
@ -112,6 +112,9 @@ struct MonoCache {
|
|||
GDMonoClass *class_ToolAttribute;
|
||||
GDMonoClass *class_RemoteAttribute;
|
||||
GDMonoClass *class_SyncAttribute;
|
||||
GDMonoClass *class_RemoteSyncAttribute;
|
||||
GDMonoClass *class_MasterSyncAttribute;
|
||||
GDMonoClass *class_SlaveSyncAttribute;
|
||||
GDMonoClass *class_MasterAttribute;
|
||||
GDMonoClass *class_SlaveAttribute;
|
||||
GDMonoClass *class_GodotMethodAttribute;
|
||||
|
|
Loading…
Reference in a new issue