FECS
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
8
9#pragma once
10#include <cstdint>
11#include <limits>
12
14#ifndef FECS_SPARSE_PAGE_SIZE
15#define FECS_SPARSE_PAGE_SIZE 2048
16#endif
17
18namespace FECS
19{
24 {
25 };
26
28 using Entity = std::uint32_t;
29
31 using ComponentIndex = std::uint32_t;
32
34 static constexpr Entity INVALID_ENTITY = std::numeric_limits<Entity>::max();
35
37 static constexpr std::size_t SPARSE_PAGE_SIZE = FECS_SPARSE_PAGE_SIZE;
38
40 static constexpr std::uint32_t INDEX_BITS = 20;
41
43 static constexpr std::uint32_t VERSION_BITS = 12;
44
46 static constexpr std::uint32_t INDEX_MASK = (1u << INDEX_BITS) - 1;
47
49 static constexpr std::uint32_t VERSION_MASK = ~INDEX_MASK;
50
52 static constexpr std::uint32_t NPOS = std::numeric_limits<std::uint32_t>::max();
53
63 inline Entity BuildEntityIndex(std::uint32_t index, std::uint32_t version)
64 {
65 return (version << INDEX_BITS) | (index & INDEX_MASK);
66 }
67
73 inline std::uint32_t GetEntityIndex(Entity e)
74 {
75 return e & INDEX_MASK;
76 }
77
83 inline std::uint32_t GetEntityVersion(Entity e)
84 {
85 return (e & VERSION_MASK) >> INDEX_BITS;
86 }
87}
Dummy tag component used for tracking global ECS changes (e.g. full view rebuilds).
Definition types.h:24
Entity BuildEntityIndex(std::uint32_t index, std::uint32_t version)
Combines an entity index and version into a single 32-bit entity ID.
Definition types.h:63
#define FECS_SPARSE_PAGE_SIZE
Defines the default number of elements per sparse page, if not specified.
Definition types.h:15
std::uint32_t ComponentIndex
Type alias for identifying component type indices.
Definition types.h:31
std::uint32_t GetEntityIndex(Entity e)
Extracts the index portion from an entity ID.
Definition types.h:73
std::uint32_t Entity
Type alias for entity IDs (32-bit unsigned integer)
Definition types.h:28
std::uint32_t GetEntityVersion(Entity e)
Extracts the verison portion from an entity ID.
Definition types.h:83