bakpakin / tiny-ecs

ECS for Lua
http://bakpakin.github.io/tiny-ecs/doc/
MIT License
675 stars 61 forks source link

Entity’s properties caching #17

Closed neoascetic closed 6 years ago

neoascetic commented 6 years ago
> t = require 'tiny'
> e = {name='Ivan'}
> s = t.processingSystem()
> function s:process(e) print(e.name) end
> s.filter = t.requireAll('name')
> w = t.world(e, s)
> w:update()
Ivan
> e.name = nil
> w:update()
nil

Is that expected behaviour? As a workaround I am currently re-adding changed entity to the world, but maybe there is a better (i. e. automatic) way?

Thank you.

shakesoda commented 6 years ago

the filter is only checked on add. this is expected.

On Fri, Jun 8, 2018, 5:13 AM Pavel Puchkin notifications@github.com wrote:

t = require 'tiny'> e = {name='Ivan'}> s = t.processingSystem()> function s:process(e) print(e.name) end> s.filter = t.requireAll('name')> w = t.world(e, s)> w:update() Ivan> e.name = nil> w:update()nil

Is that expected behaviour? As a workaround I am currently re-adding changed entity to the world, but maybe there is a better (i. e. automatic) way?

Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bakpakin/tiny-ecs/issues/17, or mute the thread https://github.com/notifications/unsubscribe-auth/AANZdlz6jCgp1IApXeMayTPAoVEOKa29ks5t6mpPgaJpZM4UgAfO .

bakpakin commented 6 years ago

Shakesoda is correct. I will close this issue.

neoascetic commented 6 years ago

Okay, so my workaround is the correct way to do things?

This is a little bit inconvenient thought because one of the features of ECS is the ability to change the list of components dynamically at runtime. Maybe there should be a special method to "notify" world about changes (with the corresponding name).

Thank you.

bakpakin commented 6 years ago

Yes that special method is the add function. There should be no need to remove the entity first.