Line | Branch | Exec | Source |
---|---|---|---|
1 | #pragma once | ||
2 | |||
3 | #include "Types.hpp" | ||
4 | |||
5 | namespace ECS { | ||
6 | class IComponent { | ||
7 | public: | ||
8 | 20 | virtual ~IComponent() = default; | |
9 | virtual ComponentTypeID GetTypeID() const = 0; | ||
10 | }; | ||
11 | |||
12 | class ComponentTypeRegistry { | ||
13 | private: | ||
14 | 3 | static ComponentTypeID GetNextTypeID() { | |
15 | static ComponentTypeID nextID = 1; | ||
16 | 3 | return nextID++; | |
17 | } | ||
18 | |||
19 | public: | ||
20 | template<typename T> | ||
21 | 60 | static ComponentTypeID GetTypeID() { | |
22 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 27 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
60 | static ComponentTypeID typeID = GetNextTypeID(); |
23 | 60 | return typeID; | |
24 | } | ||
25 | }; | ||
26 | |||
27 | template<typename T> | ||
28 | class Component : public IComponent { | ||
29 | public: | ||
30 | ✗ | ComponentTypeID GetTypeID() const override { | |
31 | ✗ | return GetStaticTypeID(); | |
32 | } | ||
33 | |||
34 | 30 | static ComponentTypeID GetStaticTypeID() { | |
35 | 30 | return ComponentTypeRegistry::GetTypeID<T>(); | |
36 | } | ||
37 | }; | ||
38 | } | ||
39 |