Skip to content

Pablyco/Simple-ECS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Simple ECS (Entity Component System)

Design Philosophy

  • Composition over Inheritance: Entities are collections of components
  • Data-Oriented: Components are pure data, Systems contain logic
  • Template-Based: Type-safe generic component storage

Architecture

Entity

  • Unique uint32_t identifier
  • Can have multiple components of different types

Component

  • Pure data (no logic)
  • Example: Position {x, y}, Velocity {vx, vy}

System

  • Operates on entities with specific components
  • Example: MovementSystem updates Position based on Velocity

Query

  • Find all entities with a specific set of components
  • world.Query<Position, Velocity>() returns entities with both

Usage Example

World world;
uint32_t player = world.CreateEntity();
world.AddComponent<Position>(player, {0, 0});
world.AddComponent<Velocity>(player, {1, 0});

// Update all moving entities
auto movingEntities = world.Query<Position, Velocity>();
for (uint32_t id : movingEntities) {
    auto& pos = world.GetComponent<Position>(id);
    auto& vel = world.GetComponent<Velocity>(id);
    pos.x += vel.vx;
    pos.y += vel.vy;
}

What I Learned

  • Template metaprogramming and static maps
  • Generic container design
  • How engines separate data from behavior

About

Implemented a simplify version of Entity Component System(ECS) in C++ for learning purposes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors