entt::component no longer exists

This commit is contained in:
Michele Caini
2019-12-16 23:44:37 +01:00
parent 83bea8b654
commit ed8eea12bd
6 changed files with 42 additions and 49 deletions

6
TODO
View File

@@ -26,11 +26,7 @@
* Mission: get rid of named types
- make it possible to use custom generators (eg for plugins)
* registry
* remove entt::component
* clean-up superfluous to_integer
* ENTT_ID_TYPE id() (eg dispatcher) can be a data member rather than a virtual function
* define a kind of assure also for context variables
* meta: use type_id, remove import, everything should work transparently
* type_id_enabled and fallback on old-fashioned families otherwise
* add discard pool functionality (+ test)
@@ -38,6 +34,6 @@
- reintroduce old-fashion family and add a new family-like thing with generators
- families should be defined as out-of-class to guarantee the same identifiers for the same types
- update doc: family, dispatcher, emitter, registry, meta, across boundaries
- update tests
- update/improve/review tests
- review and suppress warnings, if any
- remove ENTT_API from OPAQUE_TYPE

View File

@@ -47,9 +47,6 @@ class basic_continuous_loader;
/*! @brief Alias declaration for the most common use case. */
ENTT_OPAQUE_TYPE(entity, ENTT_ID_TYPE);
/*! @brief Alias declaration for the most common use case. */
ENTT_OPAQUE_TYPE(component, ENTT_ID_TYPE);
/*! @brief Alias declaration for the most common use case. */
using registry = basic_registry<entity>;

View File

@@ -1423,9 +1423,9 @@ public:
entt::basic_runtime_view<Entity> runtime_view(It first, It last) const {
std::vector<const sparse_set<Entity> *> selected(std::distance(first, last));
std::transform(first, last, selected.begin(), [this](const component ctype) {
std::transform(first, last, selected.begin(), [this](const auto ctype) {
const auto it = std::find_if(pools.cbegin(), pools.cend(), [ctype](auto &&pdata) {
return pdata.id == to_integer(ctype);
return pdata.id == ctype;
});
return it == pools.cend() ? nullptr : it->pool.get();

View File

@@ -168,7 +168,7 @@ TEST(Benchmark, IterateSingleComponentRuntime1M) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -333,7 +333,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1M) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -361,7 +361,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MHalf) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -389,7 +389,7 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MOne) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -562,7 +562,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1M) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>}, entt::component{entt::type_id_v<comp<0>>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity>, entt::type_id_v<comp<0>> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -592,7 +592,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MHalf) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>}, entt::component{entt::type_id_v<comp<0>>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity>, entt::type_id_v<comp<0>> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -622,7 +622,7 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MOne) {
}
auto test = [&registry](auto func) {
entt::component types[] = { entt::component{entt::type_id_v<position>}, entt::component{entt::type_id_v<velocity>}, entt::component{entt::type_id_v<comp<0>>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<position>, entt::type_id_v<velocity>, entt::type_id_v<comp<0>> };
timer timer;
registry.runtime_view(std::begin(types), std::end(types)).each(func);
@@ -836,12 +836,12 @@ TEST(Benchmark, IterateFiveComponentsRuntime1M) {
}
auto test = [&registry](auto func) {
entt::component types[] = {
entt::component{entt::type_id_v<position>},
entt::component{entt::type_id_v<velocity>},
entt::component{entt::type_id_v<comp<0>>},
entt::component{entt::type_id_v<comp<1>>},
entt::component{entt::type_id_v<comp<2>>}
ENTT_ID_TYPE types[] = {
entt::type_id_v<position>,
entt::type_id_v<velocity>,
entt::type_id_v<comp<0>>,
entt::type_id_v<comp<1>>,
entt::type_id_v<comp<2>>
};
timer timer;
@@ -876,12 +876,12 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MHalf) {
}
auto test = [&registry](auto func) {
entt::component types[] = {
entt::component{entt::type_id_v<position>},
entt::component{entt::type_id_v<velocity>},
entt::component{entt::type_id_v<comp<0>>},
entt::component{entt::type_id_v<comp<1>>},
entt::component{entt::type_id_v<comp<2>>}
ENTT_ID_TYPE types[] = {
entt::type_id_v<position>,
entt::type_id_v<velocity>,
entt::type_id_v<comp<0>>,
entt::type_id_v<comp<1>>,
entt::type_id_v<comp<2>>
};
timer timer;
@@ -916,12 +916,12 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MOne) {
}
auto test = [&registry](auto func) {
entt::component types[] = {
entt::component{entt::type_id_v<position>},
entt::component{entt::type_id_v<velocity>},
entt::component{entt::type_id_v<comp<0>>},
entt::component{entt::type_id_v<comp<1>>},
entt::component{entt::type_id_v<comp<2>>}
ENTT_ID_TYPE types[] = {
entt::type_id_v<position>,
entt::type_id_v<velocity>,
entt::type_id_v<comp<0>>,
entt::type_id_v<comp<1>>,
entt::type_id_v<comp<2>>
};
timer timer;

View File

@@ -11,7 +11,7 @@ TEST(RuntimeView, Functionalities) {
registry.reserve<int>(0);
registry.reserve<char>(0);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
ASSERT_TRUE(view.empty());
@@ -54,7 +54,7 @@ TEST(RuntimeView, Iterator) {
registry.assign<int>(entity);
registry.assign<char>(entity);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
using iterator_type = typename decltype(view)::iterator_type;
@@ -90,7 +90,7 @@ TEST(RuntimeView, Contains) {
registry.destroy(e0);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
ASSERT_FALSE(view.contains(e0));
@@ -109,7 +109,7 @@ TEST(RuntimeView, Empty) {
registry.assign<char>(e1);
registry.assign<float>(e1);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>}, entt::component{entt::type_id_v<float>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char>, entt::type_id_v<float> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
view.each([](auto) { FAIL(); });
@@ -129,7 +129,7 @@ TEST(RuntimeView, Each) {
registry.assign<int>(e1);
registry.assign<char>(e1);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
std::size_t cnt = 0;
@@ -151,7 +151,7 @@ TEST(RuntimeView, EachWithHoles) {
registry.assign<int>(e0, 0);
registry.assign<int>(e2, 2);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
view.each([e0](auto entity) {
@@ -165,7 +165,7 @@ TEST(RuntimeView, MissingPool) {
const auto e0 = registry.create();
registry.assign<int>(e0);
entt::component types[] = { entt::component{entt::type_id_v<int>}, entt::component{entt::type_id_v<char>} };
ENTT_ID_TYPE types[] = { entt::type_id_v<int>, entt::type_id_v<char> };
auto view = registry.runtime_view(std::begin(types), std::end(types));
ASSERT_TRUE(view.empty());
@@ -188,7 +188,7 @@ TEST(RuntimeView, EmptyRange) {
const auto e0 = registry.create();
registry.assign<int>(e0);
const entt::component *ptr = nullptr;
const ENTT_ID_TYPE *ptr = nullptr;
auto view = registry.runtime_view(ptr, ptr);
ASSERT_TRUE(view.empty());

View File

@@ -209,20 +209,20 @@ public:
duk_push_array(ctx);
std::vector<entt::component> components;
std::vector<entt::component> runtime;
std::vector<ENTT_ID_TYPE> components;
std::vector<ENTT_ID_TYPE> runtime;
for(duk_idx_t arg = 0; arg < nargs; arg++) {
auto type = duk_require_uint(ctx, arg);
if(dreg.func.find(type) == dreg.func.cend()) {
if(runtime.empty()) {
components.push_back(entt::component{entt::type_id_v<duktape_runtime>});
components.push_back(entt::type_id_v<duktape_runtime>);
}
runtime.push_back(entt::component{type});
runtime.push_back(type);
} else {
components.push_back(entt::component{type});
components.push_back(type);
}
}
@@ -236,7 +236,7 @@ public:
} else {
const auto &others = dreg.registry.get<duktape_runtime>(entity).components;
const auto match = std::all_of(runtime.cbegin(), runtime.cend(), [&others](const auto type) {
return others.find(to_integer(type)) != others.cend();
return others.find(type) != others.cend();
});
if(match) {