Does anyone have psuedocode or the like for an entity-component system?
ECS
You know that there are many variations of ECS in the wild? I don't mean variation in implementation details but in architectural decisions. You should have at least an idea of what you want/need before start looking into code; otherwise you may become locked on the first thing you see. This forum has several threads discussing things like implicit vs. explicit entities, code in components vs code in sub-systems, direct access vs. messaging, and so on.
I doubt that anybody has done the work to formulate an ECS in pseudocode. Too much work IMHO. However, there are a few ECS implementations in source code available on the internet, for example the Artemis framework.
Why don't you google "open source entity component system"?
You could take a look at the ECS from the Almirante 2D game engine. There's a link to it somewhere here on the forum, just google it if you can't find it.
The code is well documented and IMO easily adaptable
Talos isn't in there anymore?
It's still there sorry I renamed it to "Epos" (I like greek mythology). I thought Talos (an artificial bronze automaton) would suit better an AI library I am also starting :)
her's a quick stab at the concept:
first you have an entity list:
each entity has a reference to the following components in the component lists: render info, location, update method, and entity specific data.
then you have component lists:
render info
location
update method
entity specific data
to render an entity, you follow its references to get its render info and location info from the component lists, then use that info to render.
to update an entity, you follow its references to get its update method info, location info, and entity specific data from the component lists, then use that info to update.
the two main reasons to use ECS:
1. as a workaround for object hierarchy hell.
2. to allow non-coders to define new entity type from existing component types.
note that EXTREME cache optimization can lead to ECS-ish designs. but ECS in and of itself is not usually done for greater cache friendliness, and does not necessarily result in more cache friendly code.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.