Entity-component system (ECS) is an architectural pattern that follows Composition over inheritance principle
ECS allows greater flexibility in defining entities where every object in a game's scene is an entity (e.g. enemies, bullets, vehicles, etc.). Every Entity consists of one or more components which add additional behavior or functionality. Therefore, the behavior of an entity can be changed at runtime by adding or removing components. This eliminates the ambiguity problems of deep and wide inheritance hierarchies that are difficult to understand, maintain and extend.
The entity is a general purpose object. Usually, it only consists of a unique id. They "tag every coarse gameobject as a separate item". Implementations typically use a plain integer for this.
The raw data for one aspect of the object, and how it interacts with the world. "Labels the Entity as possessing this particular aspect". Implementations typically use Structs, Classes, or Associative Arrays.
"Each System runs continuously (as though each System had its own private thread) and performs global actions on every Entity that possesses a Component of the same aspect as that System."
This project includes proof of concept ECS example project. The project sets up Go Dev environment using vagrant.
EntityComponentSystem
| -- ecs
| -- component.go
| -- entitymanager.go
| -- run
| -- main.go
| -- subsystems
| -- cleanup.go
| -- fallback.go
| -- movement.go
| -- render.go
| -- system.go
| -- wireup
| -- Initialize.go
Contains core of ECS. component.go has components info and entitymanager.go manages "entities" and "components". Basically entitymanager.go acts as the Datastore and management of ECS.
run main.go to start the project
subsystems implement System interface from system.go. subsystems run on seperate go routines.
Creates new entities, adds components and starts the susbsystems.
- Install VirtualBox and Vagrant
- Clone this repo
Start:
$ vagrant up
This does the following:
- Installs Git
- Downloads Go version 1.8.3 and installs it
SSH into the server
$ vagrant ssh
Check Go version- This should display the version of go installed.
$ go version
cd into project run directory
$ cd ECS-GO/src/EntityComponentSystem/run/
run the project
$ go run main.go