All Projects → Lallapallooza → ECS

Lallapallooza / ECS

Licence: MIT license
Simple implement of ECS on C++

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to ECS

Entityplus
A C++14 Entity Component System
Stars: ✭ 181 (+1292.31%)
Mutual labels:  entity-component-system
SpaceWar-ECS
A space war game made with ECS and JobSystem in Unity.
Stars: ✭ 26 (+100%)
Mutual labels:  entity-component-system
unity-entity-component-system
A better approach to game design that allows you to concentrate on the actual problems you are solving: the data and behavior that make up your game. By moving from object-oriented to data-oriented design it will be easier for you to reuse the code and easier for others to understand and work on it.
Stars: ✭ 88 (+576.92%)
Mutual labels:  entity-component-system
Egocs
EgoCS: An Entity (GameObject) Component System framework for Unity3D
Stars: ✭ 211 (+1523.08%)
Mutual labels:  entity-component-system
Octopuskit
2D ECS game engine in 100% Swift + SwiftUI for iOS, macOS, tvOS
Stars: ✭ 246 (+1792.31%)
Mutual labels:  entity-component-system
Adria-DX11
Graphics engine written in C++ using DirectX11
Stars: ✭ 87 (+569.23%)
Mutual labels:  entity-component-system
Uecs
Ubpa Entity-Component-System (U ECS) in Unity3D-style
Stars: ✭ 174 (+1238.46%)
Mutual labels:  entity-component-system
RASM
3D Ray-Tracing WebGPU Game Engine Written in Rust WebAssembly.
Stars: ✭ 20 (+53.85%)
Mutual labels:  entity-component-system
Lovetoys
🍌 a full-featured Entity-Component-System framework for making games with lua
Stars: ✭ 252 (+1838.46%)
Mutual labels:  entity-component-system
ent-comp
A light, fast Entity Component System in JS
Stars: ✭ 25 (+92.31%)
Mutual labels:  entity-component-system
Lumixengine
3D C++ Game Engine - yet another open source game engine
Stars: ✭ 2,604 (+19930.77%)
Mutual labels:  entity-component-system
Wickedengine
3D engine focusing on modern rendering techniques and performance.
Stars: ✭ 3,148 (+24115.38%)
Mutual labels:  entity-component-system
aurora
A small entity-component-system game engine for real-time-strategy games.
Stars: ✭ 28 (+115.38%)
Mutual labels:  entity-component-system
Unity Ecs Rts
Trying to recreate a simple RTS game using Unity and pure ECS
Stars: ✭ 189 (+1353.85%)
Mutual labels:  entity-component-system
TinyECS
Tiny ECS is an easy to use Entity-Component-System framework that's designed specially for Unity3D.
Stars: ✭ 20 (+53.85%)
Mutual labels:  entity-component-system
Awesome Entity Component System
😎 A curated list of Entity-Component-System (ECS) libraries and resources
Stars: ✭ 180 (+1284.62%)
Mutual labels:  entity-component-system
typed-ecstasy
An entity component system for TypeScript (and JavaScript), based on ashley
Stars: ✭ 25 (+92.31%)
Mutual labels:  entity-component-system
ecs
Build your own Game-Engine based on the Entity Component System concept in Golang.
Stars: ✭ 68 (+423.08%)
Mutual labels:  entity-component-system
rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 617 (+4646.15%)
Mutual labels:  entity-component-system
ECS
Entity-Component-System
Stars: ✭ 122 (+838.46%)
Mutual labels:  entity-component-system

README OUTDATED BUT YOU CAN STILL USE IT FOR OVERVIEW

Simple ECS in C++

This is an implement of ECS pattern in C++. It contains:

  -Entity
  -Component
  -System
  -Pool
  -Events
  -Matcher
  -Group
  -Reactive variables
  -Some helper tools

Every ECS sytem contains three basic elements: components, entity and system. Pool and Events were added to make proccess of develepment easier.

Basics of ECS

Component contains raw data, entity comprises container of components and system performs global actions on entities and components. Pool allows your system to gain access to registered components by their type for O(1) complexcity. Pool were designed using templates. If you want to know about events you can find information here c#). You can instantiate or destroy components using collector. For additional information about ECS please follow this link here.

Component class

Class BaseComponent contains only pointer to an entity (owner) of this component.

struct ComponentPosition : public ECS::BaseComponent
{
	float x = 10;
	float y = 15;
	static int id;
};
int ComponentPosition::id = 0;

Every component must have id field and also must be initialized with zero. This allows Collector create unique ids for each component, it is needed for Matcher (create unique groups) and Entity (to make fast cast). For better navigation you may name your components, for example, like this: "Component_Name_".

Entity class

Class BaseEntity contains list of components and methods for adding, removing and getting your components.

Here is an example how you can work with your entity:

std::shared_ptr<ECS::BaseEntity> tree = std::make_shared<ECS::BaseEntity>(); //instantiating entity
tree->addComponent(comp_position, comp_sprite);  //comp_position and comp_sprite are base of BaseComponent

All Entities must allocate on heap!

System class

Every system (if it is not a helper system) must have at least two static methods: update and subscribe. Update method is basic method in our system. It allows to subcribe system to ECS::tools::event and call it using the ECS::Update(). Method update incapsulating logic of a system, also can add some method to your system.

class SystemPrinter : public ECS::BaseSystem
{	
public:
	static void subscribe()
	{
		ECS::Update += update;
	}
	
	static void update()
	{
		auto comps = ECS::TPool<ComponentPosition>::getComponents(); //get all component of type
		if (comps.size() != 0)
		{
			for (const auto &x : comps)
				std::cout « x->x « ' ' « x->y « std::endl;
		}
	}
};

Helper system allows to make logic of programm more independent and easier to edit. For example, we shouldn't write all code about inventory i.e. trading, showing, correct checker or other, instead of this we create nested system (system without subscribe method). example:

class SystemA : ECS::BaseSystem
{
public:
	static void update()
	{
		auto attr = ECS::TPool<ComponentAttributeStrenght>::getComponents()[0];
		
 		// some actions
 		
		SystemB::calculateDamage(attr); 
	}
};

class SystemB : ECS::BaseSystem
{
public:
	static int calculateDamage(ComponentAttributeStrenght &comp);
};

In this example we create new system to divide logic of program. If you need some function which is called in different system, create new system, if it calls only in one system, add method in it.

Collecting it:

auto comps = ECS::TPool<ComponentPosition>::getComponents();

Events are declared in "Tools.h" file. ECS::Update has 3 basic events:

1.preUpdate
2.Update
3.lateUpdate

"Subscribe" on events allows to use in the game loop 3 lines of code:

while(true)
{
    ECS::preUpdate();
    ECS::Update();
    ECS::lateUpdate();
}

Event class

Here is my implement of events in c++. It contains methods for adding and removing "subscribers" and also method to compare std::function. However, it doesn't work with lambdas.

void func();
void func2();

ECS::tools::event my_event;

my_event += func; 	//subscribe func on my_event
my_event += func2; 	//subscribe func2 on my_event

my_event(); 		//call func and func2

my_event -= func; 	//erase func

my_event(); 		//call only func2

Collector class

Collector class allows you to easily instantiate components and destoy them.

auto my_comp = ECS::tools::Collector::instantiate<ComponentPosition>(); //instantiate component of ComponentPosition type and add to the TPool
ECS::tools::Collector::destroy(my_comp); //delete refs from TPool and Entity and my_comp	

PoolManager class

auto all_entities = ECS::PoolManager::getEntities<ComponentPosition>() //return all entities with ComponentPosition

TPool class

That class allows to get component by their type for O(1) complexity:

auto comps = ECS::TPool<ComponentBlablabla>::getComponents(); //return ref on list with all ComponentBlablabla

If you forget to register component, method "getComponents" won't return it. TPool has few methods for serialization, you can create serialization function for only one component and attach it into pool, and then method serialize(), deserialize() calls you serializator/deserializator, which is used for each component in TPool. Also TPool gives you opportunity to add and remove component yourself.

Matcher class

That class allows to match entities with component you need Example:

ECS::Matcher::matchNew<Comp1, Comp2, Comp3, Comp4>();

You can list as much components as you need, because it works with "variadic" argument number. Method MatchNew creates new Match, if entities with such components exist, it will return unordered_set of pointers on that entities else returns unordered_set with size 0 When you already make match, you can use match method and get the result of last match with same arguments. Try to use match only once, because its expensive to collect it every update.

Group class

That class allows to group entities Example:

ECS::Group<g_("Some")>::add(e1);
ECS::Group<<g_("Some")>::add(e2);
ECS::Group<<g_("Some")>::add(e3);

That class allows you to collect, add, remove entites from every place of programm.

g_("Some") 

it is a unique id, which you may choose as you wish.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].