Skip to content

Project Architecture

Fazan64 edited this page Jul 13, 2017 · 5 revisions

Project Architecture (WiP)

The project uses an Entity-Component-System architecture, powered by the Entitas library.

Entity-Component-System is a data-oriented approach. That means the entire state of the game is data, and various kinds of logic perform operations on that data.

The Data

The game state is a set of entities. Each entity is nothing more than a bag of components of different types. Each component is a object whose sole purpose is storing data. A component has no business logic, apart from maybe a few methods to help working with the data it's storing. Think how Vector3 is just a struct with three floats, but has handy properties like magnitude to simplify working with it.

Here are a few example entities:

This is a static piece of scenery:

  • TransformComponent
  • GameObjectComponent

This is a player character:

  • TransformComponent
  • RigidbodyStateComponent
  • PlayerComponent
  • HandheldComponent
  • IdComponent
  • GameObjectComponent

Notice how both entities are of the same type, but represent completely different things just by having different components.

Contexts

In Entitas, groups of entities are managed by contexts. There are different context types, like GameContext and NetworkingContext. There are different entity types corresponding to types of their contexts: GameEntity, NetworkingEntity. This division makes it possible to have different component types be available on some entity types and not others, which reduces the memory footprint of each entity.

A GameContext contains entities which represent things in the game world like player characters, guns, bullets etc. Things which have components such as TransformComponent, RigidbodyStateComponent etc.

A NetworkingContext contains entities which represent things like connections. Components such as ConnectionComponent, IncomingMessageQueue, OutgoingMessageQueue.

Contexts are accessible from a singleton Contexts object:

var contexts = Contexts.sharedInstance;

GameContext game = contexts.game;
NetworkingContext networking = contexts.networking;

Contexts and every context and entity type is autogenerated by the code generator of Entitas.

Contexts provide lots of handy functionality for querying and tracking entities.

Here's a blogpost which explains the need for different contexts.

The Logic

To be written...

Clone this wiki locally