Compare commits
14 Commits
Author | SHA1 | Date |
---|---|---|
|
d3678bb8b9 | |
|
64d00bee4c | |
|
294faf5faf | |
|
7e75c1aba0 | |
|
8ad4b6c460 | |
|
df8ba2db00 | |
|
814993936e | |
|
c2030384f0 | |
|
852f860499 | |
|
3be17ed0d0 | |
|
8218301b0c | |
|
4fe094e39c | |
|
a45406df59 | |
|
587b3b607d |
|
@ -1,2 +1,8 @@
|
|||
## v2.6.0
|
||||
- More flexible composer dependencies
|
||||
|
||||
## v2.5.0
|
||||
- Using local static functions instead of lambdas for better stack traces
|
||||
|
||||
## v2.0.0
|
||||
- Bumping dependency from bit/metagen_bhl_bind up to v13.0.0
|
|
@ -4,9 +4,9 @@
|
|||
"homepage": "https://git.bit5.ru/bit/metagen_bhl_bind_ecslite",
|
||||
"require": {
|
||||
"php": ">=7.4",
|
||||
"twig/twig" : "v3.4.3",
|
||||
"bit/metagen" : "^v3.0.0",
|
||||
"bit/metagen_bhl_bind" : "^v13.0.0 || ^v14.0.0"
|
||||
"twig/twig" : "^v3.4.3",
|
||||
"bit/metagen" : ">=v3.0.0",
|
||||
"bit/metagen_bhl_bind" : ">=v13.0.0"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
|
|
@ -48,14 +48,52 @@ class BindEclLitePlugin implements \bhl_bind\BindPlugin
|
|||
return '';
|
||||
}
|
||||
|
||||
function codegenRegisterDecls(\Twig\Environment $twig)
|
||||
{
|
||||
$sliced = \bhl_bind\slice_units($this->units, 20);
|
||||
|
||||
$code = '';
|
||||
|
||||
$code .= "#if !BHL_FRONT\n";
|
||||
$code .= "public static bool TryUnpackEcsEntity(ValStack stack, out EcsWorld world, out int id)\n";
|
||||
$code .= "{\n";
|
||||
$code .= " var e = stack.PopRelease().Decode(new EcsPackedEntityWithWorld());\n\n";
|
||||
$code .= " return e.Unpack(out world, out id);\n";
|
||||
$code .= "}\n\n";
|
||||
|
||||
$code .= "public static void UnpackEcsEntity(ValStack stack, out EcsWorld world, out int id)\n";
|
||||
$code .= "{\n";
|
||||
$code .= " var e = stack.PopRelease().Decode(new EcsPackedEntityWithWorld());\n\n";
|
||||
$code .= " if(e.Unpack(out world, out id) == false)\n";
|
||||
$code .= " throw new Exception(\"No entity found\");\n";
|
||||
$code .= "}\n\n";
|
||||
|
||||
$code .= "#endif\n";
|
||||
|
||||
foreach($sliced as $idx => $units)
|
||||
{
|
||||
$code .= "public static void Register_Ecslite_$idx(Types types)\n";
|
||||
$code .= "{\n";
|
||||
|
||||
foreach($units as $u)
|
||||
{
|
||||
if($u->object->hasToken('bhl_ecslite_component'))
|
||||
$code .= $twig->render('bind_ecslite.twig', ['unit' => $u->object]);
|
||||
}
|
||||
$code .= "\n}\n";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
function codegenRegister(\Twig\Environment $twig)
|
||||
{
|
||||
$sliced = \bhl_bind\slice_units($this->units, 20);
|
||||
|
||||
$code = '';
|
||||
foreach($this->units as $u)
|
||||
{
|
||||
if($u->object->hasToken('bhl_ecslite_component'))
|
||||
$code .= $twig->render('bind_ecslite.twig', ['unit' => $u->object]);
|
||||
}
|
||||
foreach($sliced as $idx => $units)
|
||||
$code .= "Register_Ecslite_$idx(types);\n";
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,20 @@
|
|||
|
||||
{%- macro reg_ecslite_component(o) ~%}
|
||||
{
|
||||
#if !BHL_FRONT
|
||||
static bhl.Coroutine {{o.name}}_Ensure(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
UnpackEcsEntity(stack, out EcsWorld world, out int id);
|
||||
world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
throw new Exception("No entity found");
|
||||
|
||||
ref var cmp = ref world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
{{o.name}}_Ensure
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
);
|
||||
|
@ -25,22 +23,22 @@
|
|||
}
|
||||
|
||||
{
|
||||
#if !BHL_FRONT
|
||||
static bhl.Coroutine {{o.name}}_Del(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
if(TryUnpackEcsEntity(stack, out EcsWorld world, out int id) == false)
|
||||
return null;
|
||||
|
||||
world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Del(id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
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.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Del(id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
{{o.name}}_Del
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
);
|
||||
|
@ -48,25 +46,23 @@
|
|||
}
|
||||
|
||||
{
|
||||
#if !BHL_FRONT
|
||||
static bhl.Coroutine {{o.name}}_Exists(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
var dv = bhl.Val.New(frm.vm);
|
||||
if(TryUnpackEcsEntity(stack, out EcsWorld world, out int id) == false)
|
||||
dv.SetBool(false);
|
||||
else
|
||||
dv.SetBool(world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Has(id));
|
||||
stack.Push(dv);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
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);
|
||||
|
||||
var dv = bhl.Val.New(frm.vm);
|
||||
|
||||
if(e.Unpack(out EcsWorld world, out int id) == false)
|
||||
dv.SetBool(false);
|
||||
else
|
||||
dv.SetBool(world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Has(id));
|
||||
stack.Push(dv);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
{{o.name}}_Exists
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
#endif
|
||||
,
|
||||
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
);
|
||||
|
@ -85,11 +81,7 @@
|
|||
|
||||
{%- 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) {
|
||||
static bhl.Coroutine {{o.name}}_{{f.name}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
#if !BHL_FRONT
|
||||
Val dv = null;
|
||||
|
||||
|
@ -98,36 +90,43 @@
|
|||
dv = stack.Pop();
|
||||
{%- endif ~%}
|
||||
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
stack.PopRelease().Decode(ref e);
|
||||
|
||||
if(e.Unpack(out EcsWorld world, out int id) == false)
|
||||
throw new Exception("No entity found");
|
||||
|
||||
ref var cmp = ref world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
|
||||
var v = cmp.{{f.name}};
|
||||
UnpackEcsEntity(stack, out EcsWorld world, out int id);
|
||||
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
if(dv != null) {
|
||||
if(dv != null)
|
||||
{
|
||||
ref var cmp = ref world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
|
||||
{%- if f.type is instanceof('\\mtgArrType') -%}
|
||||
if(dv._obj != null && !dv._obj.Equals(v))
|
||||
if(dv._obj != null && !dv._obj.Equals(cmp.{{f.name}}))
|
||||
{%- endif ~%}
|
||||
{
|
||||
{{ bhl_bind.val2native(f.type, 'dv', 'v') }};
|
||||
cmp.{{f.name}} = v;
|
||||
{{ bhl_bind.val2native(f.type, 'dv', 'cmp.'~f.name) }};
|
||||
}
|
||||
dv.Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{%- endif ~%}
|
||||
{
|
||||
var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>();
|
||||
ref var comp = ref pool.GetOrDefault(id, out bool exists);
|
||||
if(exists)
|
||||
{
|
||||
dv = Val.New(frm.vm);
|
||||
var v = comp.{{f.name}};
|
||||
{{ bhl_bind.native2val(f.type, 'v', 'dv') }};
|
||||
}
|
||||
else
|
||||
throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id);
|
||||
}
|
||||
stack.Push(dv);
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
dv = Val.New(frm.vm);
|
||||
{
|
||||
{{ bhl_bind.native2val(f.type, 'v', 'dv') }};
|
||||
}
|
||||
stack.Push(dv);
|
||||
#endif
|
||||
return null;
|
||||
},
|
||||
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 ~%}
|
||||
{{o.name}}_{{f.name}},
|
||||
new FuncArgSymbol("e", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
|
||||
, new FuncArgSymbol("v", {{f.type|bhl_type_ref}})
|
||||
|
@ -139,38 +138,39 @@
|
|||
|
||||
{%- 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) }},
|
||||
static bhl.Coroutine {{o.name}}_{{m.name}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
#if !BHL_FRONT
|
||||
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
|
||||
EcsPackedEntityWithWorld e = default;
|
||||
|
||||
{{ bhl_bind.read_args2natives(m, '__') }}
|
||||
|
||||
stack.PopRelease().Decode(ref e);
|
||||
UnpackEcsEntity(stack, out EcsWorld world, out int id);
|
||||
|
||||
if(e.Unpack(out EcsWorld world, out int id) == false)
|
||||
throw new Exception("No entity found");
|
||||
|
||||
ref var cmp = ref world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
|
||||
var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>();
|
||||
|
||||
{%~ if m.returntype %}
|
||||
var return_val =
|
||||
{%- endif ~%}
|
||||
ref var comp = ref pool.GetOrDefault(id, out bool exists);
|
||||
if(exists)
|
||||
{
|
||||
{%~ if m.returntype %}
|
||||
var return_val =
|
||||
{%- endif ~%}
|
||||
|
||||
cmp.{{m.name}}(
|
||||
{%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%}
|
||||
);
|
||||
comp.{{m.name}}(
|
||||
{%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%}
|
||||
);
|
||||
|
||||
{{ bhl_bind.return_val(m, 'return_val') }}
|
||||
{{ bhl_bind.return_val(m, 'return_val') }}
|
||||
}
|
||||
else
|
||||
throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id);
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
null
|
||||
#endif
|
||||
, new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
var fn = new FuncSymbolNative(new Origin(), "{{o.name}}_{{m.name}}",
|
||||
{{m.returntype|bhl_type_ref}},
|
||||
{{ count_default_args(m) }},
|
||||
{{o.name}}_{{m.name}},
|
||||
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
|
||||
{%- if m.args %},{% endif ~%}
|
||||
{{ bhl_bind.func_decl_args(m) }}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue