-
Notifications
You must be signed in to change notification settings - Fork 70
ECS FAQ
ECS stands for Entity Component System. read: http://en.wikipedia.org/wiki/Entity_component_system http://gameprogrammingpatterns.com/component.html Since the game has "Components" and "Systems", to avoid confusion we've changed the name of the ECS "Components" to "DataBlobs" and ECS "Systems" to "Processors" this gives a more Data Orented aproach to the game engine, hopefully giving it a speed improvement over a typical Object Orented aproach. the idea is that instead of having a bunch of non contigous data and iterating over a set of instructions, you have an instruction and itterate over an array of data. modern CPUs have a tiny amount of very fast memory in them called caches, due to the way memory gets loaded from the memory into the cache, you can get quite a speed bost from having your data and instructions set up in such a way that it moves data from main memory to the cache in an efficent manner.
Create a new static class in the Factories folder, see the other Factories in the folder for examples. Note that the class should be: public static. Should take an EntityManager class (though this can in some cases be derived from an Entity). contain a list of DataBlobs. Return an Entity.
In most cases you'll be passing in a faction entity. to create the entity itself, you'll need a list of DataBlobs that make up the entity. the entity is then created in the following manner: Entity foo = Entity.Create(entityManager, listofDataBlobs);
Note that an entity can have only one DataBlob of a given type
That depends on what the entity does and where it operates, note that there is no real difference between the two managers and what they do.
Entities that are not physical objects will go here. this includes: Factions, ShipClasses, Technologies, Species, ComponentDefs
each "StarSystem" has it's own Entity Manager, anything that is a physical object will go into its respective system manager. Ships, Populations, Components, those are things that should be on a system manager. Ships needs a shipyard entity to spawn at, you're going to be getting the shipyard location, so pass in the shipyard entity and use it's manager. Populations, the planet. Components, the ship.
SystemManager is for concrete things GlobalManager is for blueprints, prototypes, and ideas.
A list of DataBlobs makes up an entity.
A DataBlob is a collection of data that will change during the game.
A DataBlob cannot store another DataBlob.
A DataBlob can store a reference to an Entity, a list, or dictionary of Entities.
A DataBlob can store a reference to a StaticData object, a list, or dictionary of StaticData objects.
A DataBlob should not normally contain logic functions and methods.
Is normally created by a factory when creating an entity.
There are two cases where you may think this in neccisary:
in this case, you should store the entity, then do entity.GetDataBlob(); though you can probably get away with referencing the datablob and tagging it [JsonIgnore], then having a private void Deserialized method which is tagged [OnDeserialized] which can look up the entity datablob and re-reference it after deserialisation.
In this case, consider using a regular non datablob OO type object, or better yet, a struct. note that it'll have to serialize.
Ideally, for an ultra fast processor you want your datablob to be anemic as possible with no references to other objects.
A StaticData object is a collection of data that does not change during the game.
A StaticData object is a struct (will probably be changed to a class in the future)
Is loaded by the staticdata manager.
Is what you might typically call "mod data"
this includes things such as component definitions, mineral types, atmosphere types etc. etc. etc.
A factory is used to create all the different DataBlobs a specific entity needs put them together into an entity and returns that entity. remember, an entity is in essence just a list of datablobs, the types of datablobs that an entity has defines what the entity is capable of.
A Processor contains the game logic code and does most the heavy lifting.
A processor is typically triggered via the SystemSubPulses.AddSystemInterupt(DateTime nextDateTime, PulseActionEnum action)
or SystemSubPulses.AddEntityInterupt(DateTime nextDateTime, PulseActionEnum action, Entity entity)
see: https://github.com/Pulsar4xDevs/Pulsar4x/wiki/GameLoop-and-Interupts. for more info on those.
Ideally for an ultra fast processor, you want to process an array of same type datablobs which are anemic and without your processor looking up other datablobs.
Documentation
-
Contribution
-
Design
-
Processes
-
Datatypes
-
Guides and Resources
-
Modding & Json files