This commit is contained in:
Michele Caini
2019-11-08 11:46:01 +01:00
parent 8025a84aeb
commit 02f777a143
3 changed files with 26 additions and 46 deletions

2
TODO
View File

@@ -27,6 +27,8 @@
* meta: members+class as fake functions, is it possible?
* meta: are fake types not backed by actual types possible?
* meta: export implicitly generated named types if possible
* flip ENTT_NO_ATOMIC and make it opt-in rather than opt-out
* welcome -ftime-trace to inspect compilation time
* add meta support to registry:
- entity for each component
- opaque get

View File

@@ -119,60 +119,39 @@ class basic_registry {
template<typename...>
struct group_handler;
template<typename... Exclude, typename... Get>
struct group_handler<exclude_t<Exclude...>, get_t<Get...>> {
const std::tuple<pool_type<Get> *..., pool_type<Exclude> *...> cpools{};
sparse_set<Entity> set{};
template<typename Component>
void maybe_valid_if(const Entity entt) {
if([this, entt]() {
if constexpr(std::disjunction_v<std::is_same<Get, Component>...>) {
return ((std::is_same_v<Component, Get> || std::get<pool_type<Get> *>(cpools)->has(entt)) && ...)
&& (!std::get<pool_type<Exclude> *>(cpools)->has(entt) && ...);
} else if constexpr(std::disjunction_v<std::is_same<Exclude, Component>...>) {
return (std::get<pool_type<Get> *>(cpools)->has(entt) && ...)
&& ((std::is_same_v<Exclude, Component> || !std::get<pool_type<Exclude> *>(cpools)->has(entt)) && ...);
}
}() && !set.has(entt)) {
set.construct(entt);
}
}
void discard_if(const Entity entt) {
if(set.has(entt)) {
set.destroy(entt);
}
}
};
template<typename... Exclude, typename... Get, typename... Owned>
struct group_handler<exclude_t<Exclude...>, get_t<Get...>, Owned...> {
const std::tuple<pool_type<Owned> *..., pool_type<Get> *..., pool_type<Exclude> *...> cpools{};
std::size_t owned{};
std::conditional_t<sizeof...(Owned) == 0, sparse_set<Entity>, std::size_t> owned{};
template<typename Component>
void maybe_valid_if(const Entity entt) {
if([this, entt]() {
if constexpr(std::disjunction_v<std::is_same<Owned, Component>..., std::is_same<Get, Component>...>) {
return ((std::is_same_v<Component, Owned> || std::get<pool_type<Owned> *>(cpools)->has(entt)) && ...)
&& ((std::is_same_v<Component, Get> || std::get<pool_type<Get> *>(cpools)->has(entt)) && ...)
&& (!std::get<pool_type<Exclude> *>(cpools)->has(entt) && ...);
} else if constexpr(std::disjunction_v<std::is_same<Exclude, Component>...>) {
return (std::get<pool_type<Owned> *>(cpools)->has(entt) && ...)
&& (std::get<pool_type<Get> *>(cpools)->has(entt) && ...)
&& ((std::is_same_v<Exclude, Component> || !std::get<pool_type<Exclude> *>(cpools)->has(entt)) && ...);
const auto is_valid = ((std::is_same_v<Component, Owned> || std::get<pool_type<Owned> *>(cpools)->has(entt)) && ...)
&& ((std::is_same_v<Component, Get> || std::get<pool_type<Get> *>(cpools)->has(entt)) && ...)
&& ((std::is_same_v<Exclude, Component> || !std::get<pool_type<Exclude> *>(cpools)->has(entt)) && ...);
if constexpr(sizeof...(Owned) == 0) {
if(is_valid && !owned.has(entt)) {
owned.construct(entt);
}
} else {
if(is_valid && !(std::get<0>(cpools)->index(entt) < owned)) {
const auto pos = owned++;
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->data()[pos], entt), ...);
}
}() && !(std::get<0>(cpools)->index(entt) < owned)) {
const auto pos = owned++;
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->data()[pos], entt), ...);
}
}
void discard_if(const Entity entt) {
if(std::get<0>(cpools)->has(entt) && std::get<0>(cpools)->index(entt) < owned) {
const auto pos = --owned;
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->data()[pos], entt), ...);
if constexpr(sizeof...(Owned) == 0) {
if(owned.has(entt)) {
owned.destroy(entt);
}
} else {
if(std::get<0>(cpools)->has(entt) && std::get<0>(cpools)->index(entt) < owned) {
const auto pos = --owned;
(std::get<pool_type<Owned> *>(cpools)->swap(std::get<pool_type<Owned> *>(cpools)->data()[pos], entt), ...);
}
}
}
};
@@ -1399,7 +1378,7 @@ public:
&& !(std::get<pool_type<Exclude> *>(cpools)->has(entity) || ...))
{
if constexpr(sizeof...(Owned) == 0) {
handler->set.construct(entity);
handler->owned.construct(entity);
} else {
if(!(std::get<0>(cpools)->index(entity) < handler->owned)) {
const auto pos = handler->owned++;
@@ -1411,7 +1390,7 @@ public:
}
if constexpr(sizeof...(Owned) == 0) {
return { &handler->set, std::get<pool_type<Get> *>(cpools)... };
return { &handler->owned, std::get<pool_type<Get> *>(cpools)... };
} else {
return { &std::get<0>(cpools)->super, &handler->owned, std::get<pool_type<Owned> *>(cpools)... , std::get<pool_type<Get> *>(cpools)... };
}

View File

@@ -8,7 +8,6 @@
#include <vector>
#include <memory>
#include <cstddef>
#include <numeric>
#include <type_traits>
#include "../config/config.h"
#include "../core/algorithm.hpp"