Compare commits

..

No commits in common. "master" and "v2.4.0" have entirely different histories.

4 changed files with 76 additions and 86 deletions

View File

@ -1,8 +1,2 @@
## 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

View File

@ -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"
"twig/twig" : "v3.4.3",
"bit/metagen" : "^v3.0.0",
"bit/metagen_bhl_bind" : "^v13.0.0 || ^v14.0.0 || ^15.0.0"
},
"autoload": {
"files": [

View File

@ -54,22 +54,6 @@ class BindEclLitePlugin implements \bhl_bind\BindPlugin
$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";

View File

@ -2,20 +2,22 @@
{%- 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
{{o.name}}_Ensure
#else
null
#endif
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");
world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>().Ensure(id);
return null;
}
#else
null
#endif
,
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
);
@ -23,22 +25,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
{{o.name}}_Del
#else
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
null
#endif
#endif
,
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
);
@ -46,23 +48,25 @@
}
{
#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
{{o.name}}_Exists
#else
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
null
#endif
#endif
,
new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
);
@ -81,7 +85,11 @@
{%- macro ecslite_component_field(o, f) ~%}
{
static bhl.Coroutine {{o.name}}_{{f.name}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
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;
@ -90,7 +98,12 @@
dv = stack.Pop();
{%- endif ~%}
UnpackEcsEntity(stack, out EcsWorld world, out int id);
EcsPackedEntityWithWorld e = default;
stack.PopRelease().Decode(ref e);
if(e.Unpack(out EcsWorld world, out int id) == false)
throw new Exception("No entity found");
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
if(dv != null)
@ -118,15 +131,9 @@
throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id);
}
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}},
#endif
return null;
},
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}})
@ -138,11 +145,19 @@
{%- macro ecslite_component_func(o, m) ~%}
{
static bhl.Coroutine {{o.name}}_{{m.name}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
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;
{{ bhl_bind.read_args2natives(m, '__') }}
UnpackEcsEntity(stack, out EcsWorld world, out int id);
stack.PopRelease().Decode(ref e);
if(e.Unpack(out EcsWorld world, out int id) == false)
throw new Exception("No entity found");
var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>();
@ -162,15 +177,12 @@
else
throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id);
#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')}}"))
return null;
}
#else
null
#endif
, new FuncArgSymbol("__self", types.T("{{token(o, 'bhl_ecslite_component_entity')}}"))
{%- if m.args %},{% endif ~%}
{{ bhl_bind.func_decl_args(m) }}
);