Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ECS_Entity.h
Go to the documentation of this file.
1/*
2Olympe Engine V2 - 2025
3Nicolas Chereau
4nchereau@gmail.com
5
6This file is part of Olympe Engine V2.
7Olympe Engine V2 is free software: you can redistribute it and/or modify
8
9ECS Types purpose: Basic type definitions for the Entity-Component-System (ECS) architecture.
10
11*/
12#pragma once
13
14#include <cstdint>
15#include <bitset>
16#include <vector>
17#include <functional>
18
19// --- 1. Entity (Identity) ---
20// An Entity is just a unique ID.
21using EntityID = std::uint64_t;
22// /*DEPRECATED LIMITATION*/ const EntityID MAX_ENTITIES = 5000;
23const EntityID INVALID_ENTITY_ID = 0; // Use 0 for invalid
24
25// --- 2. Component (Data) ---
26// Each component type gets a unique ID (its index in the bitset).
27using ComponentTypeID = std::uint64_t;
28const ComponentTypeID MAX_COMPONENTS = 32; // Limits the number of component types
29
30// The Signature: indicates which components an Entity possesses.
31using ComponentSignature = std::bitset<MAX_COMPONENTS>;
32
33// Alias for the system update function
34using SystemUpdateFn = std::function<void(float)>;
35
36// --- 3. Pool Interface (for the World Registry) ---
37// Virtual base class to store all component pools polymorphically
39{
40public:
41 virtual ~IComponentPool() = default;
42 // The virtual Remove method is essential for DestroyEntity()
43 virtual void RemoveComponent(EntityID entity) = 0;
44};
45
46// --- Utility Functions for Type IDs ---
47// Static counter to assign a unique ID to each new component type
49{
50 static ComponentTypeID nextID = 1;
51 return nextID++;
52}
53
54// Added templated GetComponentTypeID_Static to ensure a unique static typeID per component type
55template<typename T>
const ComponentTypeID MAX_COMPONENTS
Definition ECS_Entity.h:28
std::function< void(float)> SystemUpdateFn
Definition ECS_Entity.h:34
ComponentTypeID GetComponentTypeID()
Definition ECS_Entity.h:48
std::bitset< MAX_COMPONENTS > ComponentSignature
Definition ECS_Entity.h:31
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
std::uint64_t ComponentTypeID
Definition ECS_Entity.h:27
const EntityID INVALID_ENTITY_ID
Definition ECS_Entity.h:23
virtual void RemoveComponent(EntityID entity)=0
virtual ~IComponentPool()=default