Compare commits

..

6 Commits

Author SHA1 Message Date
Pavel Shevaev d3678bb8b9 Migrating to more robust bhl_custom_rw semantics 2024-12-28 15:21:11 +03:00
Pavel Shevaev 64d00bee4c Обновить CHANGELOG.md 2024-12-19 10:56:05 +03:00
Pavel Shevaev 294faf5faf Merge branch 'master' of https://git.bit5.ru/bit/metagen_bhl_bind_ecslite 2024-12-05 19:43:31 +03:00
Pavel Shevaev 7e75c1aba0 Trying make more flexible deps 2024-12-05 19:42:59 +03:00
Pavel Shevaev 8ad4b6c460 Обновить CHANGELOG.md 2024-11-21 14:37:12 +03:00
Pavel Shevaev df8ba2db00 Using local static functions instead of lambdas 2024-11-21 11:48:22 +03:00
4 changed files with 86 additions and 76 deletions

View File

@ -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

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

View File

@ -54,6 +54,22 @@ 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,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");
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,12 +90,7 @@
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");
UnpackEcsEntity(stack, out EcsWorld world, out int id);
{%- if token_or(f, 'bhl_set', 1) != 0 ~%}
if(dv != null)
@ -131,9 +118,15 @@
throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id);
}
stack.Push(dv);
#endif
return null;
},
#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}})
@ -145,19 +138,11 @@
{%- 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);
if(e.Unpack(out EcsWorld world, out int id) == false)
throw new Exception("No entity found");
UnpackEcsEntity(stack, out EcsWorld world, out int id);
var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>();
@ -177,12 +162,15 @@
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) }}
);