Working ECS and First Model


So, I talked previously about the idea of an Entity-Component-System. Near as I can make out, ECS is intended to compensate largely for the lack of facility C/C++ has in building dynamic objects. Basically (as I understand it) an Entity can be thought of as a data structure that has components, which we might call attributes, or key/value pairs in a dictionary.

So, instead I made a triple store (see the table in the last image). It defines relations to objects with a unique identifier. So, for the Robot, we have something like:

(ent robot null)
(pos robot (0 0 0))
(model robot <POINTER>) 

I can search this list to get information that I need for building the display. To do that, I made up some cheapjack imitations of the more powerful Prolog operators. First `?=` to get everything in the store that matches whichever triplets are specified, and `?v` to get the first value available for the first two triplets. I.e. `(?v STORE 'pos 'robot)` returns the robot's position.

However, I'm not sure I'm going to keep on with that. Urlang is basically a thin wrapper over JavaScript, and JavaScript offers an associative array data type which allows arbitrary keys. More importantly, it keeps them all in the same bundle, so once I have something I can just use the dictionary instead of having to sort through the STORE array again.

On the other hand, STORE isn't that bad, especially for a small game like this. So, I'll probably keep it as it is for a little while.

Leave a comment

Log in with itch.io to leave a comment.