VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
View.hpp
1#pragma once
2#include <tuple>
3#include "Types.hpp"
4#include "Registry.hpp"
5
6namespace vex {
7
15
16template<typename... Components>
17class View {
18private:
21
22public:
25 View(Registry& reg) : m_registry(reg) {}
26
39 template<typename Func>
40 void each(Func func) {
41 using FirstT = typename std::tuple_element<0, std::tuple<Components...>>::type;
42
43 auto* leadArray = m_registry.try_get_storage_internal<FirstT>();
44 if (!leadArray) return;
45
46 auto& entities = leadArray->get_entities();
47
48 for (ptrdiff_t i = static_cast<ptrdiff_t>(entities.size()) - 1; i >= 0; --i) {
49
50 if (i >= static_cast<ptrdiff_t>(entities.size())) continue;
51
52 Entity e = entities[i];
53
54 if ((m_registry.has<Components>(e) && ...)) {
55 func(e, m_registry.get<Components>(e)...);
56 }
57 }
58 }
59};
60
61}
Central registry for managing entities and their components in the ECS system.
Definition Registry.hpp:29
Registry & m_registry
Reference to the Registry containing the component data.
Definition View.hpp:20
View(Registry &reg)
Constructs a View for querying entities with the specified component types.
Definition View.hpp:25
void each(Func func)
Iterates over all entities with the specified component types.
Definition View.hpp:40
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11