diff --git a/tpl/macro.twig b/tpl/macro.twig index 1f616ba..f9e8192 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -6,6 +6,8 @@ {{ _self.decl_struct(u.object) }} {%- elseif u.object is instanceof('\\mtgMetaEnum') -%} {{ _self.decl_enum(u.object) }} +{%- elseif u.object is instanceof('\\mtgMetaRPC') -%} +{{ _self.decl_rpc(u.object) }} {%- endif ~%} {%- endfor ~%} @@ -81,10 +83,10 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_class(o)}} public {{_self.override(o)}} int getWritableFieldsCount() { -{%- if has_token(o, 'bitfields') ~%} +{%~ if has_token(o, 'bitfields') ~%} return Meta.GetDirtyFieldsCount(fields_mask, fields_count: {{fields_count(o)}}) + Meta.MASK_HEADER_FIELDS_COUNT; -{%- else -%} +{% else %} return {{fields_count(o)}}; {%- endif ~%} } @@ -225,8 +227,77 @@ base.syncFields(ctx); {%- endfor ~%} } + public void SetDirtyMask() + { + fields_mask = ~0L; + } + + public void SetDirtyMaskDeep() + { + SetDirtyMask(); +{%- for f in o.fields ~%} +{%- if f.type is instanceof('\\mtgMetaStruct') and has_token(f.type, 'bitfields') ~%} + {{f.name}}.SetDirtyMaskDeep(); +{%- elseif f.type is instanceof('\\mtgArrType') and f.type.value is instanceof('\\mtgMetaStruct') and has_token(f.type.value, "bitfields") ~%} + { + for(int i=0;i<{{f.name}}.Count;++i) + { + var __tmp = {{f.name}}[i]; + __tmp.SetDirtyMaskDeep(); + {{f.name}}[i] = __tmp; + } + } +{%- endif -%} +{%- endfor ~%} + } + {%- endmacro -%} {% macro decl_enum(o) %} +{{_self.attributes(o)}} +public enum {{o.name}} +{ +{%- for n,v in o.values ~%} + {{n}} = {{v}}, +{%- endfor ~%} +} {% endmacro %} +{% macro decl_rpc(o) %} + +{{_self.decl_struct(o.req)}} +{{_self.decl_struct(o.rsp)}} + +public class {{o.name}} : IRpc +{ + public IRpcError error = null; + public {{o.req.name}} req = new {{o.req.name}}(); + public {{o.rsp.name}} rsp = new {{o.rsp.name}}(); + + public int getCode() + { + return {{o.code}}; + } + + public void setError(IRpcError error) + { + this.error = error; + } + + public IRpcError getError() + { + return error; + } + + public IMetaStruct getRequest() + { + return req as IMetaStruct; + } + + public IMetaStruct getResponse() + { + return rsp as IMetaStruct; + } +} + +{% endmacro %}