CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
EntityID.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
16
17#include <cstdint>
18#include <iosfwd>
19
20namespace CeresEngine {
21
24
27 CE_SCRIPT_EXPORT(readonly = true)
28 EntityIndex index = 0;
29
31 CE_SCRIPT_EXPORT(readonly = true)
32 EntityVersion version = 0;
33
36 inline EntityID() noexcept = default;
37
41 EntityID(const EntityID& other) noexcept = default;
42
46 EntityID& operator=(const EntityID& other) noexcept = default;
47
51 CE_SCRIPT_EXPORT(readonly = true)
52 inline EntityID(const EntityIndex index, const EntityVersion version) noexcept : index(index), version(version) {}
53
54 public: // Operators
60 friend inline constexpr bool operator==(const EntityID& a, const EntityID& b) noexcept { return a.index == b.index && a.version == b.version; }
61
67 friend inline constexpr bool operator!=(const EntityID& a, const EntityID& b) noexcept { return a.index != b.index || a.version != b.version; }
68
73 friend std::ostream& operator<<(std::ostream& os, const EntityID& entityID);
74 };
75
105
106} // namespace CeresEngine
107
109 size_t operator()(const CeresEngine::EntityID& entityID) const { return CeresEngine::hash(entityID.index, entityID.version); }
110};
#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
Definition EntityID.hpp:76
void release(EntityID entityID) noexcept
Releases a previously allocated entity ID.
HashMap< EntityIndex, EntityVersion > mEntityVersions
A map of entity versions, indexed by their entity indexes.
Definition EntityID.hpp:79
EntityVersion getLatestVersion(EntityIndex index) const noexcept
Gets the latest version of a given entity index.
EntityID allocate() noexcept
Allocates a new entity ID from the allocator.
EntityIndex mNextEntityIndex
The EntityIndex for the next entity allocation if the freeList is empty.
Definition EntityID.hpp:83
Vector< EntityID > mFreeList
A list of free entities that are ready to be reused.
Definition EntityID.hpp:86
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
UInt32 EntityVersion
Definition EntityID.hpp:23
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
UInt32 EntityIndex
Definition EntityID.hpp:22
Definition Span.hpp:668
Definition EntityID.hpp:25
EntityIndex index
The entity index.
Definition EntityID.hpp:28
EntityVersion version
The entity version.
Definition EntityID.hpp:32
friend std::ostream & operator<<(std::ostream &os, const EntityID &entityID)
Prints a string representation of the Entity ID.
friend constexpr bool operator==(const EntityID &a, const EntityID &b) noexcept
Compares two entity IDs for equality.
Definition EntityID.hpp:60
friend constexpr bool operator!=(const EntityID &a, const EntityID &b) noexcept
Compares two entity IDs for inequality.
Definition EntityID.hpp:67