Gradually adding support for all features

This commit is contained in:
Pavel Shevaev 2022-12-07 16:11:32 +03:00
parent 9fa57439db
commit a9e4265c19
1 changed files with 69 additions and 2 deletions

View File

@ -334,8 +334,26 @@ public class {{o.name}} : IRpc
{%- macro diffable_support(o) -%}
public bool GetDiff({{o.name}} old, {{o.name}} diff = null, List<DataClassIds> removed = null)
{
if(diff != null)
diff.reset();
bool no_changes = true;
{% set field_idx = -1 %}
{%- for f in o.fields ~%}
{% set field_idx = field_idx + 1 %}
{%- if not has_token(f, 'nodiff') -%}
{{_self.field_diff(f, field_idx)}}
{%- endif -%}
{% endfor %}
return !no_changes;
}
{% for u in get_diff_related_units(o) %}
{{_self.diff_methods(u)}}
{{_self.diff_methods_for(u)}}
{% endfor %}
static public List<ulong> GetClassRemovedIds(List<DataClassIds> removed_ids, uint class_id)
@ -369,7 +387,7 @@ public class {{o.name}} : IRpc
{% endmacro %}
{%- macro diff_methods(u) -%}
{%- macro diff_methods_for(u) -%}
static public bool DiffOne(ref {{u.name}} curr, {{u.name}} old)
{
@ -482,3 +500,52 @@ public class {{o.name}} : IRpc
{% macro compare_func_name(o) %}
{{has_token(u, 'bitfields')?'CompareAndMarkFields':'IsEqual'}}
{% endmacro %}
{%- macro field_diff(f, field_idx) -%}
{% if f.type is instanceof('\\mtgMetaStruct') %}
{%- if not has_token(f.type, 'POD') -%}
Error("Diffable struct '" ~ f.type ~ "' must be POD");
{%- endif -%}
{
var __tmp = {{f.name}};
if(DiffOne(ref __tmp, old.{{f.name}}))
{
no_changes &= false;
if(diff != null)
{
diff.{{f.name}} = __tmp;
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
}
}
}
{% elseif f.type is instanceof('\\mtgArrType') %}
{%- if not has_token(f.type.value, 'POD') -%}
Error("Diffable struct '" ~ f.type.value ~ "' must be POD");
{%- endif -%}
if(DiffCollection({{f.name}}, old.{{f.name}},
diff == null ? null : diff.{{f.name}},
removed
))
{
no_changes &= false;
if(diff != null)
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
}
{% elseif f.type is instanceof('\\mtgBuiltinType') %}
if(diff != null)
diff.{{f.name}} = {{f.name}};
if({{f.name}} != old.{{f.name}})
{
no_changes &= false;
if(diff != null)
Meta.SetFieldDirty(ref diff.fields_mask, {{field_idx}});
}
{% else %}
Error("Diff for field '"~ f.name ~"' is not supported");
{% endif %}
{% endmacro %}