CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
NetworkEntity.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
17
18#include <cstdint>
19
20namespace CeresEngine {
21
25 UInt64 raw = 0;
26
29 inline constexpr NetworkEntityID() noexcept = default;
30
34 constexpr NetworkEntityID(const NetworkEntityID& other) noexcept = default;
35
40 constexpr NetworkEntityID& operator=(const NetworkEntityID& other) noexcept = default;
41
45 explicit inline constexpr NetworkEntityID(const UInt64 raw) noexcept : raw(raw) {}
46
47 public: // Operators
53 [[nodiscard]] friend inline constexpr bool operator==(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw == b.raw; }
54
60 [[nodiscard]] friend inline constexpr bool operator!=(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw != b.raw; }
61
66 [[nodiscard]] friend inline constexpr bool operator<(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw < b.raw; }
67
72 [[nodiscard]] friend inline constexpr bool operator<=(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw <= b.raw; }
73
78 [[nodiscard]] friend inline constexpr bool operator>(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw > b.raw; }
79
84 [[nodiscard]] friend inline constexpr bool operator>=(const NetworkEntityID& a, const NetworkEntityID& b) noexcept { return a.raw >= b.raw; }
85
90 friend std::ostream& operator<<(std::ostream& os, const NetworkEntityID& id);
91 };
92
96 struct CE_SCRIPT_EXPORT() NetworkEntityComponent final : public Component<NetworkEntityComponent> {
98 struct Accessor;
99
104
105 public: // Reflection
108 template<typename Processor> static constexpr void reflect(Processor&& RTTI) { CE_REFL_DATA(id); }
109 };
110
111 struct NetworkEntityComponent::Accessor : public Component<NetworkEntityComponent>::Accessor {
113
114 public:
117 NetworkEntityID getID() const { return read(&C::id); }
118
122
123 public:
127
128 public: // Reflection
132 };
133
134 class NetworkEntity : public EntityObject<NetworkEntityComponent> {
135 using Type::Type;
136 };
137
138 // ---------------------------------------------------------------------------------------------
139
140 struct TransferAuthority final : public EntityAction<TransferAuthority> {};
141 struct HasAuthorityQuery final : public EntityAction<HasAuthorityQuery, bool> {};
142
143 // ---------------------------------------------------------------------------------------------
144
145 struct GainedAuthority final : public EntityEvent<GainedAuthority> {};
146 struct LostAuthority final : public EntityEvent<LostAuthority> {};
147
148} // namespace CeresEngine
149
150template<> struct std::hash<CeresEngine::NetworkEntityID> {
151 size_t operator()(const CeresEngine::NetworkEntityID& networkEntityID) const { return CeresEngine::hash(networkEntityID.raw); }
152};
153
156
#define CE_EXTERN_COMPONENT(T)
Definition Component.hpp:600
#define CE_ENTITY_OBJECT_HASH(T)
Definition Entity.hpp:784
#define CE_REFLECTABLE_STRUCT
Definition IReflectable.hpp:47
#define CE_REFL_DATA_GETSET(N, G, S)
Definition Macros.hpp:549
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A type-safe entity type.
Definition Entity.hpp:538
Definition NetworkEntity.hpp:134
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Accessor(const Entity &entity)
Definition Component.hpp:181
auto mutate(T C::*ptr)
Accesses an element from an existing Component.
const T & read(const T C::*ptr) const
Accesses an element from an existing Component.
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
A class that must be inherited by concrete action types.
Definition Action.hpp:33
A template class that wraps a event.
Definition Event.hpp:43
Definition NetworkEntity.hpp:145
Definition NetworkEntity.hpp:141
Definition NetworkEntity.hpp:146
Definition NetworkEntity.hpp:111
void setID(const NetworkEntityID id)
Definition NetworkEntity.hpp:121
NetworkEntityID getID() const
Definition NetworkEntity.hpp:117
The network identity component is a special component that is added on all entities that must be sync...
Definition NetworkEntity.hpp:96
NetworkEntityID id
The ID of the entity over the network.
Definition NetworkEntity.hpp:103
Definition NetworkEntity.hpp:22
friend constexpr bool operator==(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for equality.
Definition NetworkEntity.hpp:53
friend constexpr bool operator>(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for >.
Definition NetworkEntity.hpp:78
friend std::ostream & operator<<(std::ostream &os, const NetworkEntityID &id)
Prints a string representation of the Entity ID.
UInt64 raw
The raw network entity ID.
Definition NetworkEntity.hpp:25
friend constexpr bool operator!=(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for inequality.
Definition NetworkEntity.hpp:60
friend constexpr bool operator>=(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for >=.
Definition NetworkEntity.hpp:84
friend constexpr bool operator<(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for <.
Definition NetworkEntity.hpp:66
friend constexpr bool operator<=(const NetworkEntityID &a, const NetworkEntityID &b) noexcept
Compares two entity IDs for <=.
Definition NetworkEntity.hpp:72
Definition NetworkEntity.hpp:140