Compare commits

...

11 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
Pavel Shevaev 814993936e Splitting registration methods 2024-11-20 15:34:22 +03:00
Pavel Shevaev c2030384f0 More optimal retrival of components: 1) using refs 2) using EcsPool<T>.GetOrDefault(..) 2024-11-20 12:10:08 +03:00
Pavel Shevaev 852f860499 Reverting experimental code 2024-11-19 15:37:43 +03:00
Pavel Shevaev 3be17ed0d0 Starting to use faster EcsPools caching 2024-11-19 11:27:25 +03:00
Pavel Shevaev 8218301b0c Making it forward compatible with newer version of metagen_bhl_bind 2024-11-14 20:20:34 +03:00
4 changed files with 119 additions and 89 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"
"twig/twig" : "^v3.4.3",
"bit/metagen" : ">=v3.0.0",
"bit/metagen_bhl_bind" : ">=v13.0.0"
},
"autoload": {
"files": [

View File

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

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)
@ -115,28 +102,31 @@
{
{{ bhl_bind.val2native(f.type, 'dv', 'cmp.'~f.name) }};
}
//NOTE: uncomment to disable 'dv' variable re-use
//dv.Release();
//dv = Val.New(frm.vm);
//{{ bhl_bind.native2val(f.type, 'cmp.'~f.name, 'dv') }};
}
else
{%- endif ~%}
{
var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>();
if(pool.Has(id))
ref var comp = ref pool.GetOrDefault(id, out bool exists);
if(exists)
{
dv = Val.New(frm.vm);
var v = pool.Get(id).{{f.name}};
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;
},
#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}})
@ -148,29 +138,22 @@
{%- 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)}}>();
if(pool.Has(id))
ref var comp = ref pool.GetOrDefault(id, out bool exists);
if(exists)
{
{%~ if m.returntype %}
var return_val =
{%- endif ~%}
pool.Get(id).{{m.name}}(
comp.{{m.name}}(
{%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%}
);
@ -179,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) }}
);