New entity system: PILES
Posted: Tue Oct 14, 2014 3:08 pm
Behold, PILES!
(check out https://github.com/kuniqs/imbir8 for newest version)
Politically Incorrect Lua Entity System was inspired by <a href="http://t-machine.org/index.php/2007/09/ ... t-1/">this article</a> about database-based (durr) entity systems used in MMOs. tl;dr: You have a set of entities (bags of components) and a bunch of systems working in ordered way (functions which work on entities that have the required components). So, you can have a system named 'movement' that works on all entities with the 'position' and 'velocity' components.
I've tried others' approaches to component-based architecture, but was put off by Java-style syntax of them. I mean - come on! Lua deserves better than that.
My code is more a proof of concept than usable, and slow as hell I guess (but it wouldn't be noticeable under luajit I think). I couldn't figure out a way to remove entities from the inside of the system processing part, so the entity database gets copied before each iteration and zombie objects get buried after it. I also didn't used the observer pattern for event handling (to be fixed when I feel like it) since I'm more concerned about usability than speed at the moment.
One thing I never found an satisfying answer for is: How do you manage message passing between components? Problem is, the order of recievers of that message is undefined, so if we have situations where the order of components affects the side effects of the message (say, A tells B to 'die' but C prevents 'die' on B - with [C,A,B] order B dies but with [A,C,B] order B lives), how do I untangle this mess? The solution I have so far is to keep event flags in components and mark them as 'dead' then rethrow the message until everyone involved do their job. But that leads to bloat and unmanageable situations where you have multiple event handlers, each doing the handling in conflicting ways, meaning each one needs to know about each other to avoid errors. There MUST be a simpler way.
<a href="http://chomikuj.pl/kuniqs/PILES,4279586 ... OWNLOAD</a>
(check out https://github.com/kuniqs/imbir8 for newest version)
Politically Incorrect Lua Entity System was inspired by <a href="http://t-machine.org/index.php/2007/09/ ... t-1/">this article</a> about database-based (durr) entity systems used in MMOs. tl;dr: You have a set of entities (bags of components) and a bunch of systems working in ordered way (functions which work on entities that have the required components). So, you can have a system named 'movement' that works on all entities with the 'position' and 'velocity' components.
I've tried others' approaches to component-based architecture, but was put off by Java-style syntax of them. I mean - come on! Lua deserves better than that.
My code is more a proof of concept than usable, and slow as hell I guess (but it wouldn't be noticeable under luajit I think). I couldn't figure out a way to remove entities from the inside of the system processing part, so the entity database gets copied before each iteration and zombie objects get buried after it. I also didn't used the observer pattern for event handling (to be fixed when I feel like it) since I'm more concerned about usability than speed at the moment.
One thing I never found an satisfying answer for is: How do you manage message passing between components? Problem is, the order of recievers of that message is undefined, so if we have situations where the order of components affects the side effects of the message (say, A tells B to 'die' but C prevents 'die' on B - with [C,A,B] order B dies but with [A,C,B] order B lives), how do I untangle this mess? The solution I have so far is to keep event flags in components and mark them as 'dead' then rethrow the message until everyone involved do their job. But that leads to bloat and unmanageable situations where you have multiple event handlers, each doing the handling in conflicting ways, meaning each one needs to know about each other to avoid errors. There MUST be a simpler way.
<a href="http://chomikuj.pl/kuniqs/PILES,4279586 ... OWNLOAD</a>