only internal pool is allowed

This commit is contained in:
Michele Caini
2017-09-09 17:02:13 +02:00
parent c324ee310a
commit 02c424bd21
4 changed files with 5 additions and 156 deletions

View File

@@ -178,13 +178,9 @@ private:
};
template<typename...>
class Registry;
template<template<typename...> class... Pool, typename Entity, typename... Component>
class Registry<Pool<Entity, Component>...> {
using pool_type = std::tuple<Pool<Entity, Component>...>;
template<typename Entity, typename... Component>
class Registry {
using pool_type = std::tuple<SparseSet<Entity, Component>...>;
using mask_type = std::bitset<sizeof...(Component)+1>;
static constexpr auto validity_bit = sizeof...(Component);
@@ -430,12 +426,8 @@ private:
};
template<typename Entity, typename... Component>
using StandardRegistry = Registry<SparseSet<Entity, Component>...>;
template<typename... Component>
using DefaultRegistry = Registry<SparseSet<std::uint32_t, Component>...>;
using DefaultRegistry = Registry<std::uint32_t, Component...>;
}

View File

@@ -1,97 +0,0 @@
#ifndef ENTT_TAG_HANDLER_HPP
#define ENTT_TAG_HANDLER_HPP
#include <type_traits>
#include <utility>
#include <cstddef>
#include <cassert>
namespace entt {
template<typename Index, typename Type>
struct TagHandler {
using type = Type;
using index_type = Index;
using pos_type = index_type;
using size_type = std::size_t;
using iterator_type = const type *;
private:
inline bool valid(index_type idx) const noexcept {
return !idx && tag;
}
public:
explicit TagHandler() = default;
TagHandler(const TagHandler &) = delete;
TagHandler(TagHandler &&) = default;
~TagHandler() noexcept {
assert(not tag);
}
TagHandler & operator=(const TagHandler &) = delete;
TagHandler & operator=(TagHandler &&) = default;
bool empty() const noexcept {
return !tag;
}
size_type size() const noexcept {
return tag ? size_type{1} : size_type{0};
}
iterator_type begin() const noexcept {
return tag;
}
iterator_type end() const noexcept {
return tag ? tag + 1 : tag;
}
bool has(index_type idx) const noexcept {
return valid(idx);
}
const type & get(index_type idx) const noexcept {
assert(valid(idx));
return *tag;
}
type & get(index_type idx) noexcept {
return const_cast<type &>(const_cast<const TagHandler *>(this)->get(idx));
}
template<typename... Args>
type & construct(index_type idx, Args... args) {
assert(!valid(idx));
tag = new(&chunk) Type{std::forward<Args>(args)...};
return *tag;
}
void destroy(index_type idx) {
assert(valid(idx));
tag->~Type();
tag = nullptr;
}
void reset() {
if(tag) {
destroy(index_type{0});
}
}
private:
std::aligned_storage_t<sizeof(Type), alignof(Type)> chunk;
Type *tag{nullptr};
};
}
#endif // ENTT_TAG_HANDLER_HPP

View File

@@ -11,7 +11,7 @@ set(TARGET_BENCHMARK benchmark)
# Test TARGET_ENTT
add_executable(${TARGET_ENTT} ident.cpp registry.cpp sparse_set.cpp tag_handler.cpp)
add_executable(${TARGET_ENTT} ident.cpp registry.cpp sparse_set.cpp)
target_include_directories(${TARGET_ENTT} PRIVATE ${PROJECT_SRC_DIR})
target_link_libraries(${TARGET_ENTT} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TARGET_ENTT} COMMAND ${TARGET_ENTT})

View File

@@ -1,46 +0,0 @@
#include <gtest/gtest.h>
#include <tag_handler.hpp>
TEST(TagHandler, Functionalities) {
using TagHandler = entt::TagHandler<unsigned int, int>;
TagHandler handler;
ASSERT_TRUE(handler.empty());
ASSERT_EQ(handler.size(), 0u);
ASSERT_EQ(handler.begin(), handler.end());
ASSERT_FALSE(handler.has(0));
ASSERT_FALSE(handler.has(1));
ASSERT_EQ(handler.construct(0, 42), 42);
ASSERT_FALSE(handler.empty());
ASSERT_EQ(handler.size(), 1u);
ASSERT_NE(handler.begin(), handler.end());
ASSERT_TRUE(handler.has(0));
ASSERT_FALSE(handler.has(1));
auto begin = handler.begin();
ASSERT_EQ(*begin, 42);
ASSERT_EQ(handler.get(0), 42);
ASSERT_EQ(++begin, handler.end());
handler.destroy(0);
ASSERT_TRUE(handler.empty());
ASSERT_EQ(handler.size(), 0u);
ASSERT_EQ(handler.begin(), handler.end());
ASSERT_FALSE(handler.has(0));
ASSERT_FALSE(handler.has(1));
ASSERT_EQ(handler.construct(0, 12), 12);
handler.reset();
ASSERT_TRUE(handler.empty());
ASSERT_EQ(handler.size(), 0u);
ASSERT_EQ(handler.begin(), handler.end());
ASSERT_FALSE(handler.has(0));
ASSERT_FALSE(handler.has(1));
}