Migrating to newer client library

This commit is contained in:
Pavel Shevaev 2023-07-25 19:02:52 +03:00
parent 5816f3cf7f
commit f34cf52297
2 changed files with 27 additions and 41 deletions

View File

@ -314,7 +314,7 @@ function var_reset($name, \mtgType $type, $default = null)
}
else if($type instanceof \mtgArrType)
{
$str = "Meta.ClearList(ref $name);";
$str = "MetaSync.ClearList(ref $name);";
if($default)
{
@ -354,7 +354,7 @@ function var_reset($name, \mtgType $type, $default = null)
if($is_pod)
$str .= "$name.reset(); ";
else
$str .= "Meta.Reset(ref $name); ";
$str .= "MetaSync.Reset(ref $name); ";
}
if($default)
@ -390,38 +390,40 @@ function var_sync($fname, \mtgType $type, $buf, array $tokens, $opts)
if($optional)
$opts .= " | MetaSyncFieldOpts.SKIP_OPTIONAL";
$key_name = array_key_exists('alias', $tokens) ? $tokens['alias'] : $fname;
$str = '';
if($type instanceof \mtgBuiltinType)
{
$str .= "Meta.Sync({$buf}, ref {$fname}, {$opts});\n";
$str .= "MetaSync.Sync({$buf}, ref {$fname}, \"{$key_name}\", {$opts});\n";
}
else if($type instanceof \mtgMetaStruct)
{
if(array_key_exists('virtual', $tokens))
$str .= "{$fname} = ({$type->getName()})Meta.SyncGeneric({$buf}, {$fname}, {$opts});\n";
$str .= "{$fname} = ({$type->getName()})MetaSync.SyncGeneric({$buf}, {$fname}, \"{$key_name}\", {$opts});\n";
else
$str .= "Meta.Sync({$buf}, ref {$fname}, {$opts});\n";
$str .= "MetaSync.Sync({$buf}, ref {$fname}, \"{$key_name}\", {$opts});\n";
}
else if($type instanceof \mtgMetaEnum)
{
$str .= "int __tmp_{$fname} = (int)$fname;\n";
$str .= "Meta.Sync({$buf}, ref __tmp_{$fname}, {$opts});\n";
$str .= "MetaSync.Sync({$buf}, ref __tmp_{$fname}, \"{$key_name}\", {$opts});\n";
$str .= "if($buf.is_read) {$fname} = ({$type->getName()})__tmp_{$fname};\n";
}
else if($type instanceof \mtgArrType)
{
if(array_key_exists('virtual', $tokens))
$str .= "Meta.SyncGeneric({$buf}, {$fname}, {$opts});\n";
$str .= "MetaSync.SyncGeneric({$buf}, {$fname}, \"{$key_name}\", {$opts});\n";
else
{
if($type->getValue() instanceof \mtgMetaEnum)
{
$str .= "Meta.tmp_enums_list.Clear(); if(!{$buf}.is_read) { foreach(var _enum_tmp in {$fname}) Meta.tmp_enums_list.Add((int)_enum_tmp); }\n";
$str .= "Meta.Sync({$buf}, Meta.tmp_enums_list, {$opts});\n";
$str .= "if({$buf}.is_read) foreach(var _int_tmp in Meta.tmp_enums_list) { {$fname}.Add(({$type->getValue()->getName()}) _int_tmp); }\n";
$str .= "MetaSync.tmp_enums_list.Clear(); if(!{$buf}.is_read) { foreach(var _enum_tmp in {$fname}) MetaSync.tmp_enums_list.Add((int)_enum_tmp); }\n";
$str .= "MetaSync.Sync({$buf}, MetaSync.tmp_enums_list, \"{$key_name}\", {$opts});\n";
$str .= "if({$buf}.is_read) foreach(var _int_tmp in MetaSync.tmp_enums_list) { {$fname}.Add(({$type->getValue()->getName()}) _int_tmp); }\n";
}
else
$str .= "Meta.Sync({$buf}, {$fname}, {$opts});\n";
$str .= "MetaSync.Sync({$buf}, {$fname}, \"{$key_name}\", {$opts});\n";
}
}
else

View File

@ -50,28 +50,10 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}}
}
{{_self.comment_non_cloneable_begin(o)}}
public {{_self.virtual_clone(o)}} void copy(IMetaStruct other)
{
copyFrom(({{o.name}})other);
}
public void copyFrom({{o.name}} other)
{
var ctx = Meta.PrepareForClone(ref other);
ctx.factory = AutogenBundle.createById;
ctx.reader.BeginContainer();
reset();
syncFields(ctx);
ctx.reader.EndContainer();
{%- if has_token(o, 'bitfields') ~%}
fields_mask = other.fields_mask;
{%- endif ~%}
}
public {{_self.virtual_clone(o)}} IMetaStruct clone()
{
var copy = new {{o.name}}();
copy.copy(this);
MetaSync.Clone(this, ref copy, AutogenBundle.createById);
return copy;
}
{{_self.comment_non_cloneable_end(o)}}
@ -89,9 +71,9 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}}
public {{_self.override(o)}} int getWritableFieldsCount()
{
{%~ if has_token(o, 'bitfields') ~%}
return fields_mask.GetDirtyFieldsCount() + Meta.MASK_HEADER_FIELDS_COUNT;
return fields_mask.GetDirtyFieldsCount() + MetaSync.MASK_HEADER_FIELDS_COUNT;
{% else %}
return {{fields_count(o)}};
return getFieldsCount();
{%- endif ~%}
}
@ -228,7 +210,7 @@ override
{%- macro sync_fields(o) -%}
{%- if has_token(o, 'bitfields') ~%}
var bitctx = new Meta.BitfieldsContext(ctx, fields_mask);
var bitctx = new MetaSync.BitfieldsContext(ctx, fields_mask);
bitctx.SyncMaskHeader();
{%- endif -%}
{%- if o.parent ~%}
@ -250,7 +232,7 @@ base.syncFields(ctx);
{
{%- for f in o.fields ~%}
{%- if is_primary_field(o, f) ~%}
Meta.SetFieldDirty(ref fields_mask, {{loop.index0}});
MetaSync.SetFieldDirty(ref fields_mask, {{loop.index0}});
{%- endif -%}
{%- endfor ~%}
}
@ -458,9 +440,9 @@ public class {{o.name}} : IRpc
}
//if(changed.Count > 0)
// Meta.LogDebug("Changed in collection {{u.name}}");
// MetaSync.LogDebug("Changed in collection {{u.name}}");
//if(removed_ids.Count > 0)
// Meta.LogDebug("Removed in collection {{u.name}}");
// MetaSync.LogDebug("Removed in collection {{u.name}}");
return has_diff;
}
@ -536,7 +518,7 @@ public class {{o.name}} : IRpc
!= (b.{{f.name}} == null ? "" : b.{{f.name}}))
{% if has_token(o, 'bitfields') ~%}
{
Meta.SetFieldDirty(ref a.fields_mask, {{field_idx}});
MetaSync.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
}
{% else ~%}
@ -546,7 +528,7 @@ public class {{o.name}} : IRpc
if(a.{{f.name}} != b.{{f.name}})
{% if has_token(o, 'bitfields') ~%}
{
Meta.SetFieldDirty(ref a.fields_mask, {{field_idx}});
MetaSync.SetFieldDirty(ref a.fields_mask, {{field_idx}});
is_equal = false;
}
{% else ~%}
@ -571,7 +553,7 @@ public class {{o.name}} : IRpc
if(diff != null)
{
diff.{{f.name}} = __tmp;
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
MetaSync.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
}
}
}
@ -587,7 +569,9 @@ public class {{o.name}} : IRpc
{
no_changes &= false;
if(diff != null)
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
MetaSync.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
if(removed != null && removed.{{f.name}}.Count > 0)
MetaSync.SetFieldDirty(ref removed.fields_mask, {{field_idx}});
}
{% elseif f.type is instanceof('\\mtgBuiltinType') %}
if(diff != null)
@ -597,7 +581,7 @@ public class {{o.name}} : IRpc
{
no_changes &= false;
if(diff != null)
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
MetaSync.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
}
{% else %}
Error("Diff for field '"~ f.name ~"' is not supported");