vecs
Fast, flexible ecs in C++ with ergonomic API
Loading...
Searching...
No Matches
type_id.h
1#ifndef __VECS_TYPE_ID_H__
2#define __VECS_TYPE_ID_H__
3
4#include <cstddef>
5#include <type_traits>
6
7#include "dynamic_bitset.h"
8
9namespace vecs {
10
11using Entity = size_t;
12using ComponentId = size_t;
13using ComponentMask = storage::dynamic_bitset;
14
16 public:
17 template<typename T>
18 static std::size_t get_type_id() {
19 return get_decayed_type_id<std::decay_t<T>>();
20 }
21
22 private:
23 template<typename DecayedT>
24 static std::size_t get_decayed_type_id() {
25 static std::size_t type_id = m_counter++;
26 return type_id;
27 }
28
29 static std::size_t m_counter;
30};
31
32template<typename... Components>
33ComponentMask compute_mask() {
34 ComponentMask mask;
35 (mask.set(TypeIDGenerator::get_type_id<Components>()), ...);
36 return mask;
37}
38
39} // namespace vecs
40
41#endif
Definition type_id.h:15
A dynamic bitset that automatically grows to support an arbitrary number of bits.
Definition dynamic_bitset.h:19