Motor OpenGL
Cargando...
Buscando...
Nada coincide
ec.h
1#pragma once
2#include <cstdint> // wtf
3#include <memory>
4#define _CMPS_LIST_ TRANSFORM, MESH_RENDERER, NUM_COMPONENTS
5#define _GRPS_LIST_ TRANSPARENT, NUM_GROUP
6
7namespace ec
8{
9 class Entity;
10 class Component;
11 using entity_t = std::shared_ptr<Entity>;
12
13 // Para ahorrar, no hay tantos componentes
14 using cmpID_t = uint8_t;
15 namespace comp
16 {
17 enum cmpID : cmpID_t
18 {
19 DEFAULT = 0,
20 _CMPS_LIST_
21 };
22 constexpr cmpID_t maxComponentId = NUM_COMPONENTS;
23 }
24
25 // Dado un componente, devolver su ID que corresponde al enum cmpID
26 // Para ello el componente tiene que estar "registrado"
27 // El tipo es uint8_t, el mismo para el cmpID
28 template<typename T>
29 constexpr cmpID_t getComponentID = T::id;
30
31
32 using groupID_t = uint8_t;
33 namespace ent
34 {
35 enum groupID : groupID_t
36 {
37 None = 0,
38 _GRPS_LIST_
39 };
40 constexpr groupID_t maxGroupLayer = NUM_GROUP;
41 }
42
43 class RenderComponent;
44 class UpdateComponent;
45
46 template<typename T>
47 inline RenderComponent* tryGetAsRender(T* self) {
48 if constexpr (std::is_base_of_v<RenderComponent, T>)
49 return static_cast<RenderComponent*>(self);
50 return nullptr;
51 }
52
53 template<typename T>
54 inline UpdateComponent* tryGetAsUpdate(T* self) {
55 if constexpr (std::is_base_of_v<UpdateComponent, T>)
56 return static_cast<UpdateComponent*>(self);
57 return nullptr;
58 }
59}
60
61#define __CMPID_DECL__(cId) constexpr static ec::cmpID_t id = cId; \
62 ec::cmpID_t getID() const override { return id; } \
63 ec::RenderComponent* getAsRender() override { return ec::tryGetAsRender(this); } \
64 ec::UpdateComponent* getAsUpdate() override { return ec::tryGetAsUpdate(this); }
Declaracion adelantada, para evitar dependencia circular.
Definition component.h:20
Componente de render.
Definition component.h:64
Componente de update.
Definition component.h:74