New sync keywords in GDScript, NativeScript, Mono

This commit is contained in:
Fabio Alessandrelli 2018-05-26 10:30:36 +02:00
parent 19ba3d5da3
commit a5e8a3be5e
9 changed files with 81 additions and 5 deletions

View file

@ -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 {

View file

@ -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;
}

View file

@ -1769,6 +1769,9 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"sync",
"master",
"slave",
"remotesync",
"mastersync",
"slavesync",
0
};

View file

@ -3923,10 +3923,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;
}
@ -4003,6 +4003,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
@ -4018,6 +4019,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

View file

@ -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:

View file

@ -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,

View file

@ -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;
}
@ -1967,15 +1973,15 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) {
return NULL;
#endif
}
if (!script_class) {
if (GDMono::get_singleton()->get_project_assembly() == NULL) {
// The project assembly is not loaded
ERR_EXPLAIN("Cannot instance script because the project assembly is not loaded. Script: " + get_path());
ERR_FAIL_V(NULL);
}
// The project assembly is loaded, but the class could not found
// The project assembly is loaded, but the class could not found
ERR_EXPLAIN("Cannot instance script because the class '" + name + "' could not be found. Script: " + get_path());
ERR_FAIL_V(NULL);
}

View file

@ -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 {}
}

View file

@ -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"));