added ecs lite bindings
This commit is contained in:
parent
12470844f3
commit
4793f65fcc
|
@ -27,6 +27,7 @@ function supported_tokens()
|
|||
'bhl_bind',
|
||||
'bhl_no_new',
|
||||
'bhl_ecs_component',
|
||||
'bhl_ecslite_component',
|
||||
'bhl_ecs_component_ref',
|
||||
'bhl_coroutine',
|
||||
'bhl_static',
|
||||
|
@ -49,7 +50,7 @@ function prepare_meta(\mtgMetaInfo $orig)
|
|||
$arr_proxies = array();
|
||||
foreach($meta->getUnits() as $u)
|
||||
{
|
||||
if($u->object instanceof \mtgMetaStruct && !$u->object->hasToken('bhl_ecs_component'))
|
||||
if($u->object instanceof \mtgMetaStruct && !$u->object->hasToken('bhl_ecs_component') && !$u->object->hasToken('bhl_ecslite_component'))
|
||||
{
|
||||
$need_to_replace = false;
|
||||
$fields = $u->object->getFields();
|
||||
|
@ -59,6 +60,7 @@ function prepare_meta(\mtgMetaInfo $orig)
|
|||
if($fld->getType() instanceof \mtgArrType)
|
||||
{
|
||||
$proxy_name = "List_{$fld->getType()->getValue()->getName()}";
|
||||
var_dump($proxy_name);
|
||||
if(!isset($arr_proxies[$proxy_name]))
|
||||
{
|
||||
$proxy = new \mtgMetaStruct($proxy_name);
|
||||
|
|
176
tpl/macro.twig
176
tpl/macro.twig
|
@ -933,6 +933,178 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
|
|||
}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro reg_ecslite_component(o) ~%}
|
||||
{
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_Ensure", Types.Void,
|
||||
#if !BHL_FRONT
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if (e.Unpack(out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
ref var cmp = ref world.Ensure<ecs.{{o.name}}>(id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("ecs.Entity"))
|
||||
);
|
||||
types.ns.Define(fn);
|
||||
}
|
||||
|
||||
{
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_Del", Types.Void,
|
||||
#if !BHL_FRONT
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if (e.Unpack(out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
world.Del<ecs.{{o.name}}>(id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("ecs.Entity"))
|
||||
);
|
||||
types.ns.Define(fn);
|
||||
}
|
||||
|
||||
{
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_Exists", Types.Bool,
|
||||
#if !BHL_FRONT
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if (e.Unpack(out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
var dv = bhl.Val.New(frm.vm);
|
||||
dv.SetBool(world.Has<ecs.{{o.name}}>(id));
|
||||
stack.Push(dv);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("ecs.Entity"))
|
||||
);
|
||||
types.ns.Define(fn);
|
||||
}
|
||||
|
||||
{% for f in o.getfields %}
|
||||
{{ _self.ecslite_component_field(o, f) }}
|
||||
{% endfor %}
|
||||
|
||||
{% for m in o.getfuncs %}
|
||||
{{ _self.ecslite_component_func(o, m) }}
|
||||
{% endfor %}
|
||||
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro ecslite_component_field(o, f) ~%}
|
||||
{
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_{{f.name}}", {{f.type|bhl_type_ref}},
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
1,
|
||||
{%- endif ~%}
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
#if !BHL_FRONT
|
||||
Val dv = null;
|
||||
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
if(args_info.CountArgs() > 1)
|
||||
dv = stack.Pop();
|
||||
{%- endif ~%}
|
||||
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if (e.Unpack(out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
ref var cmp = ref world.Ensure<ecs.{{o.name}}>(id);
|
||||
var v = cmp.{{f.name}};
|
||||
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
if(dv != null) {
|
||||
{{ _self.val2native(f.type, 'dv', 'v') }};
|
||||
cmp.{{f.name}} = v;
|
||||
dv.Release();
|
||||
}
|
||||
{%- endif ~%}
|
||||
|
||||
dv = Val.New(frm.vm);
|
||||
{
|
||||
{{ _self.native2val(f.type, 'v', 'dv') }};
|
||||
}
|
||||
stack.Push(dv);
|
||||
#endif
|
||||
return null;
|
||||
},
|
||||
new FuncArgSymbol("e", types.T("ecs.Entity"))
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
, new FuncArgSymbol("v", {{f.type|bhl_type_ref}})
|
||||
{%- endif ~%}
|
||||
);
|
||||
types.ns.Define(fn);
|
||||
}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro ecslite_component_func(o, m) ~%}
|
||||
{
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_{{m.name}}",
|
||||
{{m.returntype|bhl_type_ref}},
|
||||
{{ count_default_args(m) }},
|
||||
#if !BHL_FRONT
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
|
||||
{{ _self.read_args2natives(m, '__') }}
|
||||
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if (e.Unpack(out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
ref var cmp = ref world.Ensure<ecs.{{o.name}}>(id);
|
||||
|
||||
{%~ if m.returntype %}
|
||||
var return_val =
|
||||
{%- endif ~%}
|
||||
|
||||
cmp.{{m.name}}(
|
||||
{%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%}
|
||||
);
|
||||
|
||||
{{ _self.return_val(m, 'return_val') }}
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
, new FuncArgSymbol("__self", types.T("ecs.Entity"))
|
||||
{%- if m.args %},{% endif ~%}
|
||||
{{ _self.func_decl_args(m) }}
|
||||
);
|
||||
types.ns.Define(fn);
|
||||
}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro return_val(f, return_var) -%}
|
||||
{%- if f.returntype -%}
|
||||
{%- if f.returntype is instanceof('\\mtgMultiType') -%}
|
||||
|
@ -1055,6 +1227,8 @@ public partial class Script_{{u.object.name}} {
|
|||
|
||||
{%- if has_token(u.object, 'bhl_ecs_component') -%}
|
||||
{{ _self.reg_ecs_component(u.object) }}
|
||||
{%- elseif has_token(u.object, 'bhl_ecslite_component') -%}
|
||||
{{ _self.reg_ecslite_component(u.object) }}
|
||||
{%- elseif has_token(u.object, 'bhl_native_arr_proxy') -%}
|
||||
{{ _self.reg_native_arr_proxy(u.object) }}
|
||||
{%- else -%}
|
||||
|
@ -1080,7 +1254,7 @@ public partial class Script_{{u.object.name}} {
|
|||
//assign global static types
|
||||
{%- for u in units -%}
|
||||
{%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%}
|
||||
{%- if not has_token(u.object, 'bhl_ecs_component') ~%}
|
||||
{%- if not has_token(u.object, 'bhl_ecs_component') and not has_token(u.object, 'bhl_ecslite_component') ~%}
|
||||
{
|
||||
var tmp = types.T("{{u.object.name}}").Get();
|
||||
if(tmp == null)
|
||||
|
|
Loading…
Reference in New Issue