Handling Entities


So, I've been learning about the idea of an Entity-Component-System. It seems like it might solve some outstanding problems for me, while giving me a bit of trouble until I master it... Such is life.

The basic idea seems to be that you have a big list of everything in the game (and this really can be everything -- cameras, text strings, animation curves, whatever). Each item is an "entity". Any particular entity will have some properties (if we were talking object-oriented style), but instead we call them "componenents" here.

The "system" part is trickier. It seems that a "system" is just a function that takes a list of entities and does something to them.

Now to me, this sounds a lot like the Prolog triple-store. So maybe I can get somewhere with that:

store = [
 ["entity", "player", null],
 ["position", "player", [0, 0, 0]],
 ["model", "player", POINTER],
 ["entity", "treasure1", null],
 ["position", "treasure1", [10, 3, 0]],
 ["about", "treasure1", "...used gym socks."],
 ["entity", "treasure2", null],
 ["position", "treasure2", [9, -5, 0]],
 ... ];

So each three-element list here defines a relation. I can search and filter through this quickly.

Now, this may not necessarily make the best sense -- because compiling to JavaScript, I get dictionaries (hashes) for free, so I could just have a list of dictionaries and set those in the conventional way. However, I'll give it a try.

Leave a comment

Log in with itch.io to leave a comment.