1#ifndef ENTT_ENTITY_SNAPSHOT_HPP
2#define ENTT_ENTITY_SNAPSHOT_HPP
10#include "../config/config.h"
11#include "../container/dense_map.hpp"
12#include "../core/type_traits.hpp"
22template<
typename Registry>
23void orphans(Registry ®istry) {
24 auto &
storage =
registry.template storage<typename Registry::entity_type>();
46template<
typename Registry>
48 static_assert(!std::is_const_v<Registry>,
"Non-const registry type required");
96 const typename registry_type::common_type &base = *
storage;
100 if constexpr(std::is_same_v<Type, entity_type>) {
103 for(
auto first = base.rbegin(), last = base.rend(); first != last; ++first) {
107 for(
auto it = base.rbegin(), last = base.rend();
it != last; ++
it) {
139 template<
typename Type,
typename Archive,
typename It>
141 static_assert(!std::is_same_v<Type, entity_type>,
"Entity types not supported");
146 for(; first != last; ++first) {
175template<
typename Registry>
177 static_assert(!std::is_const_v<Registry>,
"Non-const registry type required");
232 if constexpr(std::is_same_v<Type, entity_type>) {
251 ENTT_ASSERT(
entity ==
entt,
"Entity not available for use");
278 internal::orphans(*reg);
302template<
typename Registry>
304 static_assert(!std::is_const_v<Registry>,
"Non-const registry type required");
307 void restore(
typename Registry::entity_type
entt) {
309 if(!reg->valid(remloc[
entity].second)) {
310 remloc[
entity].second = reg->create();
317 template<
typename Container>
323 using first_type = std::remove_const_t<
typename std::decay_t<
decltype(
pair)>::first_type>;
324 using second_type =
typename std::decay_t<
decltype(
pair)>::second_type;
326 if constexpr(std::is_same_v<first_type, entity_type> && std::is_same_v<second_type, entity_type>) {
328 }
else if constexpr(std::is_same_v<first_type, entity_type>) {
331 static_assert(std::is_same_v<second_type, entity_type>,
"Neither the key nor the value are of entity type");
340 template<
typename Container>
343 static_assert(std::is_same_v<typename Container::value_type, entity_type>,
"Invalid value type");
350 template<
typename Component,
typename Other,
typename Member>
352 if constexpr(!std::is_same_v<Component, Other>) {
354 }
else if constexpr(std::is_same_v<Member, entity_type>) {
358 update(0, instance.*
member);
373 : remloc{
source.get_allocator()},
419 if constexpr(std::is_same_v<Type, entity_type>) {
434 if(reg->valid(remloc[
entity].second)) {
435 reg->destroy(remloc[
entity].second);
442 for(
auto &&
ref: remloc) {
475 internal::orphans(*reg);
496 return it->second.second;
Utility class for continuous loading.
basic_continuous_loader(const basic_continuous_loader &)=delete
Default copy constructor, deleted on purpose.
basic_continuous_loader(registry_type &source) noexcept
Constructs an instance that is bound to a given registry.
basic_continuous_loader(basic_continuous_loader &&) noexcept=default
Default move constructor.
typename registry_type::entity_type entity_type
Underlying entity identifier.
bool contains(entity_type entt) const noexcept
Tests if a loader knows about a given entity.
entity_type map(entity_type entt) const noexcept
Returns the identifier to which an entity refers.
basic_continuous_loader & orphans()
Destroys those entities that have no elements.
typename Traits::entity_type entity_type
Underlying entity type.
Utility class to restore a snapshot as a whole.
basic_snapshot_loader(registry_type &source) noexcept
Constructs an instance that is bound to a given registry.
typename registry_type::entity_type entity_type
Underlying entity identifier.
basic_snapshot_loader(basic_snapshot_loader &&) noexcept=default
Default move constructor.
basic_snapshot_loader & orphans()
Destroys those entities that have no elements.
basic_snapshot_loader(const basic_snapshot_loader &)=delete
Default copy constructor, deleted on purpose.
Utility class to create snapshots from a registry.
basic_snapshot(const registry_type &source) noexcept
Constructs an instance that is bound to a given registry.
typename registry_type::entity_type entity_type
Underlying entity identifier.
basic_snapshot(const basic_snapshot &)=delete
Default copy constructor, deleted on purpose.
const basic_snapshot & get(Archive &archive, It first, It last, const id_type id=type_hash< Type >::value()) const
Serializes all elements of a type with associated identifiers for the entities in a range.
basic_snapshot(basic_snapshot &&) noexcept=default
Default move constructor.
size_type size() const noexcept
Returns the number of elements in a sparse set.
bool contains(const entity_type entt) const noexcept
Checks if a sparse set contains an entity.
size_type free_list() const noexcept
Returns data on the free list whose meaning depends on the mode.
bool empty() const noexcept
Checks whether a sparse set is empty.
bool remove(const entity_type entt)
Removes an entity from a sparse set if it exists.
reverse_iterable reach() noexcept
Returns a reverse iterable object to use to visit a storage.
void reserve(const size_type cap) override
Increases the capacity of a storage.
value_type & emplace(const entity_type entt, Args &&...args)
Assigns an entity to a storage and constructs its object.
std::tuple< const value_type & > get_as_tuple(const entity_type entt) const noexcept
Returns the object assigned to an entity as a tuple.
Associative container for key-value pairs with unique keys.
bool contains(const key_type &key) const
Checks if the container contains an element with a given key.
const_iterator cend() const noexcept
Returns an iterator to the end.
iterator find(const key_type &key)
Finds an element with a given key.
iterator erase(const_iterator pos)
Removes an element from a given position.
std::pair< iterator, bool > insert_or_assign(const key_type &key, Arg &&value)
Inserts an element into the container or assigns to the current element if the key already exists.
entity
Default entity identifier.
constexpr entt_traits< Entity >::entity_type to_entity(const Entity value) noexcept
Returns the entity part once converted to the underlying type.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
constexpr null_t null
Compile-time constant for null entities.
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
std::uint32_t id_type
Alias declaration for type identifiers.
constexpr void swap(compressed_pair< First, Second > &lhs, compressed_pair< First, Second > &rhs)
Swaps two compressed pair objects.
constexpr get_t< Type... > get
Variable template for lists of observed elements.
basic_registry<> registry
Alias declaration for the most common use case.
@ in_place
In-place deletion policy.
@ ref
Aliasing mode, the object points to a non-const element.
basic_storage< Type > storage
Alias declaration for the most common use case.