From 587b3b607d9aba99e7d98a8d5a5fd7b205bb0a43 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 5 Nov 2024 19:07:14 +0300 Subject: [PATCH] Trying to implement more optimal access to components, not using Ensure for getters --- tpl/bind_ecslite.twig | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tpl/bind_ecslite.twig b/tpl/bind_ecslite.twig index 18f47e0..c9b2581 100644 --- a/tpl/bind_ecslite.twig +++ b/tpl/bind_ecslite.twig @@ -103,28 +103,35 @@ 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}}; + {%- 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(); - } + //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 ~%} - - dv = Val.New(frm.vm); - { - {{ bhl_bind.native2val(f.type, 'v', 'dv') }}; - } - stack.Push(dv); + { + dv = Val.New(frm.vm); + var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>(); + if(pool.Has(id)) + { + var v = pool.Get(id).{{f.name}}; + {{ bhl_bind.native2val(f.type, 'v', 'dv') }}; + } + } + stack.Push(dv); #endif return null; },