vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
entity_mapping.h
1#pragma once
2
3#include <cstdint>
4#include <type_traits>
5
6#include "ecs/entity.h"
7
8namespace Vkm::Engine {
9
10template<typename Signature>
11class EntityMapping;
12
23template<typename R, typename A>
24class EntityMapping<R(A)> {
25 public:
34 template<typename Fn, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Fn>, EntityMapping>>>
35 EntityMapping(Fn& fn) noexcept
36 : m_carrier(&fn)
37 , m_call([](void* c, A from) -> R { return (*static_cast<Fn*>(c))(from); })
38 {}
39 ~EntityMapping() = default;
40
41 EntityMapping(const EntityMapping& other) = default;
42 EntityMapping& operator=(const EntityMapping& other) = default;
43
44 EntityMapping(EntityMapping && other) = default;
45 EntityMapping& operator=(EntityMapping && other) = default;
46
53 R operator()(A from) const {
54 return from ? m_call(m_carrier, from) : R{};
55 }
56
57 private:
58 void* m_carrier = nullptr;
59 R (*m_call)(void*, A) = nullptr;
60};
61
65using EntityResolver = EntityMapping<EntityId(uint32_t)>;
66
70using EntityNamer = EntityMapping<uint32_t(EntityId)>;
71
72} // namespace Vkm::Engine
EntityMapping(Fn &fn) noexcept
Wrap fn, the carrier's mapping.
Definition entity_mapping.h:35
R operator()(A from) const
Map one reference.
Definition entity_mapping.h:53