Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Entity.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** Entity.hpp
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31*/
32
42#ifndef RTYPE_ENTITY_HPP_
43 #define RTYPE_ENTITY_HPP_
44
45 #include <compare>
46 #include <cstdint>
47 #include <limits>
48 #include <functional>
49
50namespace rtp::ecs
51{
63 class Entity {
64 public:
65 static constexpr std::uint32_t MAX_INDEX =
66 std::numeric_limits<std::uint32_t>::max();
67 static constexpr std::uint64_t INDEX_MASK = MAX_INDEX;
68 static constexpr std::uint64_t GEN_SHIFT = 32;
69
70 constexpr Entity(std::uint32_t index, std::uint32_t generation);
71
72 constexpr Entity(void);
73
74 [[nodiscard]]
75 constexpr std::uint32_t index(void) const;
76
77 [[nodiscard]]
78 constexpr std::uint32_t generation(void) const;
79
80 constexpr auto operator<=>(const Entity &) const = default;
81
82 constexpr operator std::uint64_t(void) const noexcept;
83
84 [[nodiscard]]
85 constexpr bool isNull(void) const noexcept;
86
87 private:
88 std::uint64_t _id;
90 friend struct std::hash<Entity>;
91 };
92}
93
94namespace std
95{
96 template <>
97 struct hash<rtp::ecs::Entity> {
98 size_t operator()(const rtp::ecs::Entity &e) const
99 {
100 return hash<std::uint64_t>{}(e._id);
101 }
102 };
103}
104
105 #include "Entity.inl"
106
107namespace rtp::ecs
108{
109 constexpr Entity NullEntity{};
110}
111
112#endif /* !RTYPE_ENTITY_HPP_ */
Represents an entity in the ECS (Entity-Component-System) architecture.
Definition Entity.hpp:63
static constexpr std::uint64_t INDEX_MASK
Definition Entity.hpp:67
constexpr Entity(std::uint32_t index, std::uint32_t generation)
constexpr std::uint32_t index(void) const
std::uint64_t _id
The unique identifier for the entity.
Definition Entity.hpp:88
constexpr std::uint32_t generation(void) const
constexpr Entity(void)
constexpr auto operator<=>(const Entity &) const =default
static constexpr std::uint32_t MAX_INDEX
Definition Entity.hpp:65
static constexpr std::uint64_t GEN_SHIFT
Definition Entity.hpp:68
constexpr bool isNull(void) const noexcept
File : RenderSystem.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
constexpr Entity NullEntity
Definition Entity.hpp:109
STL namespace.
size_t operator()(const rtp::ecs::Entity &e) const
Definition Entity.hpp:98