updated doc and tests
This commit is contained in:
@@ -166,7 +166,8 @@ int main() {
|
||||
std::uint64_t dt = 16;
|
||||
|
||||
for(auto i = 0; i < 10; ++i) {
|
||||
auto entity = registry.create(Position{i * 1.f, i * 1.f});
|
||||
auto entity = registry.create();
|
||||
registry.assign<Position>(entity, i * 1.f, i * 1.f);
|
||||
if(i % 2 == 0) { registry.assign<Velocity>(entity, i * .1f, i * .1f); }
|
||||
}
|
||||
|
||||
@@ -392,9 +393,6 @@ A registry can be used both to construct and to destroy entities:
|
||||
// constructs a naked entity with no components and returns its identifier
|
||||
auto entity = registry.create();
|
||||
|
||||
// constructs an entity and assigns it default-initialized components
|
||||
auto another = registry.create<Position, Velocity>();
|
||||
|
||||
// destroys an entity and all its components
|
||||
registry.destroy(entity);
|
||||
```
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
constexpr bool ptr(const char *str) {
|
||||
static constexpr bool ptr(const char *str) {
|
||||
using hash_type = entt::HashedString::hash_type;
|
||||
|
||||
return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
|
||||
@@ -12,7 +12,7 @@ constexpr bool ptr(const char *str) {
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr bool ref(const char (&str)[N]) {
|
||||
static constexpr bool ref(const char (&str)[N]) {
|
||||
using hash_type = entt::HashedString::hash_type;
|
||||
|
||||
return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
|
||||
|
||||
@@ -2,32 +2,32 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/ident.hpp>
|
||||
|
||||
struct A {};
|
||||
struct B {};
|
||||
struct AType {};
|
||||
struct AnotherType {};
|
||||
|
||||
TEST(Identifier, Uniqueness) {
|
||||
constexpr auto ID = entt::ident<A, B>;
|
||||
constexpr A a;
|
||||
constexpr B b;
|
||||
constexpr auto ID = entt::ident<AType, AnotherType>;
|
||||
constexpr AType anInstance;
|
||||
constexpr AnotherType anotherInstance;
|
||||
|
||||
ASSERT_NE(ID.get<A>(), ID.get<B>());
|
||||
ASSERT_EQ(ID.get<A>(), ID.get<decltype(a)>());
|
||||
ASSERT_NE(ID.get<A>(), ID.get<decltype(b)>());
|
||||
ASSERT_EQ(ID.get<A>(), ID.get<A>());
|
||||
ASSERT_EQ(ID.get<B>(), ID.get<B>());
|
||||
ASSERT_NE(ID.get<AType>(), ID.get<AnotherType>());
|
||||
ASSERT_EQ(ID.get<AType>(), ID.get<decltype(anInstance)>());
|
||||
ASSERT_NE(ID.get<AType>(), ID.get<decltype(anotherInstance)>());
|
||||
ASSERT_EQ(ID.get<AType>(), ID.get<AType>());
|
||||
ASSERT_EQ(ID.get<AnotherType>(), ID.get<AnotherType>());
|
||||
|
||||
// test uses in constant expressions
|
||||
switch(ID.get<B>()) {
|
||||
case ID.get<A>():
|
||||
switch(ID.get<AnotherType>()) {
|
||||
case ID.get<AType>():
|
||||
FAIL();
|
||||
break;
|
||||
case ID.get<B>():
|
||||
case ID.get<AnotherType>():
|
||||
SUCCEED();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Identifier, SingleType) {
|
||||
constexpr auto ID = entt::ident<A>;
|
||||
constexpr auto ID = entt::ident<AType>;
|
||||
std::integral_constant<decltype(ID)::identifier_type, ID.get()> ic;
|
||||
(void)ic;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ struct TestActor: entt::DefaultActor<unsigned int> {
|
||||
void update(unsigned int) {}
|
||||
};
|
||||
|
||||
struct Position final {};
|
||||
struct Velocity final {};
|
||||
struct ActorPosition final {};
|
||||
struct ActorVelocity final {};
|
||||
|
||||
TEST(Actor, Functionalities) {
|
||||
entt::DefaultRegistry registry;
|
||||
@@ -18,40 +18,40 @@ TEST(Actor, Functionalities) {
|
||||
|
||||
ASSERT_EQ(®istry, &actor->registry());
|
||||
ASSERT_EQ(®istry, &cactor.registry());
|
||||
ASSERT_TRUE(registry.empty<Position>());
|
||||
ASSERT_TRUE(registry.empty<Velocity>());
|
||||
ASSERT_TRUE(registry.empty<ActorPosition>());
|
||||
ASSERT_TRUE(registry.empty<ActorVelocity>());
|
||||
ASSERT_FALSE(registry.empty());
|
||||
ASSERT_FALSE(actor->has<Position>());
|
||||
ASSERT_FALSE(actor->has<Velocity>());
|
||||
ASSERT_FALSE(actor->has<ActorPosition>());
|
||||
ASSERT_FALSE(actor->has<ActorVelocity>());
|
||||
|
||||
const auto &position = actor->set<Position>();
|
||||
const auto &position = actor->set<ActorPosition>();
|
||||
|
||||
ASSERT_EQ(&position, &actor->get<Position>());
|
||||
ASSERT_EQ(&position, &cactor.get<Position>());
|
||||
ASSERT_FALSE(registry.empty<Position>());
|
||||
ASSERT_TRUE(registry.empty<Velocity>());
|
||||
ASSERT_EQ(&position, &actor->get<ActorPosition>());
|
||||
ASSERT_EQ(&position, &cactor.get<ActorPosition>());
|
||||
ASSERT_FALSE(registry.empty<ActorPosition>());
|
||||
ASSERT_TRUE(registry.empty<ActorVelocity>());
|
||||
ASSERT_FALSE(registry.empty());
|
||||
ASSERT_TRUE(actor->has<Position>());
|
||||
ASSERT_FALSE(actor->has<Velocity>());
|
||||
ASSERT_TRUE(actor->has<ActorPosition>());
|
||||
ASSERT_FALSE(actor->has<ActorVelocity>());
|
||||
|
||||
actor->unset<Position>();
|
||||
actor->unset<ActorPosition>();
|
||||
|
||||
ASSERT_TRUE(registry.empty<Position>());
|
||||
ASSERT_TRUE(registry.empty<Velocity>());
|
||||
ASSERT_TRUE(registry.empty<ActorPosition>());
|
||||
ASSERT_TRUE(registry.empty<ActorVelocity>());
|
||||
ASSERT_FALSE(registry.empty());
|
||||
ASSERT_FALSE(actor->has<Position>());
|
||||
ASSERT_FALSE(actor->has<Velocity>());
|
||||
ASSERT_FALSE(actor->has<ActorPosition>());
|
||||
ASSERT_FALSE(actor->has<ActorVelocity>());
|
||||
|
||||
actor->set<Position>();
|
||||
actor->set<Velocity>();
|
||||
actor->set<ActorPosition>();
|
||||
actor->set<ActorVelocity>();
|
||||
|
||||
ASSERT_FALSE(registry.empty());
|
||||
ASSERT_FALSE(registry.empty<Position>());
|
||||
ASSERT_FALSE(registry.empty<Velocity>());
|
||||
ASSERT_FALSE(registry.empty<ActorPosition>());
|
||||
ASSERT_FALSE(registry.empty<ActorVelocity>());
|
||||
|
||||
delete actor;
|
||||
|
||||
ASSERT_TRUE(registry.empty());
|
||||
ASSERT_TRUE(registry.empty<Position>());
|
||||
ASSERT_TRUE(registry.empty<Velocity>());
|
||||
ASSERT_TRUE(registry.empty<ActorPosition>());
|
||||
ASSERT_TRUE(registry.empty<ActorVelocity>());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <entt/entity/entt_traits.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
struct Listener {
|
||||
struct ComponentListener {
|
||||
void incr(entt::DefaultRegistry &, entt::DefaultRegistry::entity_type entity) {
|
||||
last = entity;
|
||||
++counter;
|
||||
@@ -570,10 +570,10 @@ TEST(DefaultRegistry, MergeTwoRegistries) {
|
||||
|
||||
TEST(DefaultRegistry, Signals) {
|
||||
entt::DefaultRegistry registry;
|
||||
Listener listener;
|
||||
ComponentListener listener;
|
||||
|
||||
registry.construction<int>().connect<Listener, &Listener::incr>(&listener);
|
||||
registry.destruction<int>().connect<Listener, &Listener::decr>(&listener);
|
||||
registry.construction<int>().connect<ComponentListener, &ComponentListener::incr>(&listener);
|
||||
registry.destruction<int>().connect<ComponentListener, &ComponentListener::decr>(&listener);
|
||||
|
||||
auto e0 = registry.create();
|
||||
auto e1 = registry.create();
|
||||
@@ -589,13 +589,13 @@ TEST(DefaultRegistry, Signals) {
|
||||
ASSERT_EQ(listener.counter, 1);
|
||||
ASSERT_EQ(listener.last, e0);
|
||||
|
||||
registry.destruction<int>().disconnect<Listener, &Listener::decr>(&listener);
|
||||
registry.destruction<int>().disconnect<ComponentListener, &ComponentListener::decr>(&listener);
|
||||
registry.remove<int>(e1);
|
||||
|
||||
ASSERT_EQ(listener.counter, 1);
|
||||
ASSERT_EQ(listener.last, e0);
|
||||
|
||||
registry.construction<int>().disconnect<Listener, &Listener::incr>(&listener);
|
||||
registry.construction<int>().disconnect<ComponentListener, &ComponentListener::incr>(&listener);
|
||||
registry.assign<int>(e0);
|
||||
registry.assign<int>(e1);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ struct AnotherComponent {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct Foo {
|
||||
struct WhatAComponent {
|
||||
entt::DefaultRegistry::entity_type bar;
|
||||
std::vector<entt::DefaultRegistry::entity_type> quux;
|
||||
};
|
||||
@@ -80,7 +80,7 @@ TEST(Snapshot, Dump) {
|
||||
std::queue<bool>,
|
||||
std::queue<AComponent>,
|
||||
std::queue<AnotherComponent>,
|
||||
std::queue<Foo>
|
||||
std::queue<WhatAComponent>
|
||||
>;
|
||||
|
||||
storage_type storage;
|
||||
@@ -168,7 +168,7 @@ TEST(Snapshot, Partial) {
|
||||
std::queue<float>,
|
||||
std::queue<bool>,
|
||||
std::queue<AComponent>,
|
||||
std::queue<Foo>
|
||||
std::queue<WhatAComponent>
|
||||
>;
|
||||
|
||||
storage_type storage;
|
||||
@@ -255,7 +255,7 @@ TEST(Snapshot, Continuous) {
|
||||
std::queue<entity_type>,
|
||||
std::queue<AComponent>,
|
||||
std::queue<AnotherComponent>,
|
||||
std::queue<Foo>,
|
||||
std::queue<WhatAComponent>,
|
||||
std::queue<double>
|
||||
>;
|
||||
|
||||
@@ -279,14 +279,14 @@ TEST(Snapshot, Continuous) {
|
||||
src.assign<AnotherComponent>(entity, i, i);
|
||||
|
||||
if(i % 2) {
|
||||
src.assign<Foo>(entity, entity);
|
||||
src.assign<WhatAComponent>(entity, entity);
|
||||
} else if(i == 2) {
|
||||
src.assign<double>(entt::tag_type_t{}, entity, .3);
|
||||
}
|
||||
}
|
||||
|
||||
src.view<Foo>().each([&entities](auto, auto &foo) {
|
||||
foo.quux.insert(foo.quux.begin(), entities.begin(), entities.end());
|
||||
src.view<WhatAComponent>().each([&entities](auto, auto &whatAComponent) {
|
||||
whatAComponent.quux.insert(whatAComponent.quux.begin(), entities.begin(), entities.end());
|
||||
});
|
||||
|
||||
entity = dst.create();
|
||||
@@ -296,19 +296,19 @@ TEST(Snapshot, Continuous) {
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans();
|
||||
|
||||
decltype(dst.size()) aComponentCnt{};
|
||||
decltype(dst.size()) anotherComponentCnt{};
|
||||
decltype(dst.size()) fooCnt{};
|
||||
decltype(dst.size()) whatAComponentCnt{};
|
||||
|
||||
dst.each([&dst, &aComponentCnt](auto entity) {
|
||||
ASSERT_TRUE(dst.has<AComponent>(entity));
|
||||
@@ -320,14 +320,14 @@ TEST(Snapshot, Continuous) {
|
||||
++anotherComponentCnt;
|
||||
});
|
||||
|
||||
dst.view<Foo>().each([&dst, &fooCnt](auto entity, const auto &component) {
|
||||
dst.view<WhatAComponent>().each([&dst, &whatAComponentCnt](auto entity, const auto &component) {
|
||||
ASSERT_EQ(entity, component.bar);
|
||||
|
||||
for(auto entity: component.quux) {
|
||||
ASSERT_TRUE(dst.valid(entity));
|
||||
}
|
||||
|
||||
++fooCnt;
|
||||
++whatAComponentCnt;
|
||||
});
|
||||
|
||||
ASSERT_TRUE(dst.has<double>());
|
||||
@@ -342,13 +342,13 @@ TEST(Snapshot, Continuous) {
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans();
|
||||
|
||||
@@ -356,7 +356,7 @@ TEST(Snapshot, Continuous) {
|
||||
|
||||
ASSERT_EQ(dst.size<AComponent>(), aComponentCnt);
|
||||
ASSERT_EQ(dst.size<AnotherComponent>(), anotherComponentCnt);
|
||||
ASSERT_EQ(dst.size<Foo>(), fooCnt);
|
||||
ASSERT_EQ(dst.size<WhatAComponent>(), whatAComponentCnt);
|
||||
ASSERT_TRUE(dst.has<double>());
|
||||
|
||||
dst.view<AnotherComponent>().each([](auto, auto &component) {
|
||||
@@ -365,24 +365,24 @@ TEST(Snapshot, Continuous) {
|
||||
|
||||
entity = src.create();
|
||||
|
||||
src.view<Foo>().each([entity](auto, auto &component) {
|
||||
src.view<WhatAComponent>().each([entity](auto, auto &component) {
|
||||
component.bar = entity;
|
||||
});
|
||||
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans();
|
||||
|
||||
dst.view<Foo>().each([&loader, entity](auto, auto &component) {
|
||||
dst.view<WhatAComponent>().each([&loader, entity](auto, auto &component) {
|
||||
ASSERT_EQ(component.bar, loader.map(entity));
|
||||
});
|
||||
|
||||
@@ -397,18 +397,18 @@ TEST(Snapshot, Continuous) {
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans()
|
||||
.shrink();
|
||||
|
||||
dst.view<Foo>().each([&dst, &loader, entity](auto, auto &component) {
|
||||
dst.view<WhatAComponent>().each([&dst, &loader, entity](auto, auto &component) {
|
||||
ASSERT_FALSE(dst.valid(component.bar));
|
||||
});
|
||||
|
||||
@@ -416,7 +416,7 @@ TEST(Snapshot, Continuous) {
|
||||
|
||||
entity = src.create();
|
||||
|
||||
src.view<Foo>().each([entity](auto, auto &component) {
|
||||
src.view<WhatAComponent>().each([entity](auto, auto &component) {
|
||||
component.bar = entity;
|
||||
});
|
||||
|
||||
@@ -426,13 +426,13 @@ TEST(Snapshot, Continuous) {
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans();
|
||||
|
||||
@@ -446,13 +446,13 @@ TEST(Snapshot, Continuous) {
|
||||
src.snapshot()
|
||||
.entities(output)
|
||||
.destroyed(output)
|
||||
.component<AComponent, AnotherComponent, Foo>(output)
|
||||
.component<AComponent, AnotherComponent, WhatAComponent>(output)
|
||||
.tag<double>(output);
|
||||
|
||||
loader.entities(input)
|
||||
.destroyed(input)
|
||||
.component<AComponent, AnotherComponent>(input)
|
||||
.component<Foo>(input, &Foo::bar, &Foo::quux)
|
||||
.component<WhatAComponent>(input, &WhatAComponent::bar, &WhatAComponent::quux)
|
||||
.tag<double>(input)
|
||||
.orphans();
|
||||
|
||||
|
||||
@@ -631,9 +631,9 @@ TEST(SparseSetWithType, RespectUnordered) {
|
||||
}
|
||||
|
||||
TEST(SparseSetWithType, ReferencesGuaranteed) {
|
||||
struct Type { int value; };
|
||||
struct InternalType { int value; };
|
||||
|
||||
entt::SparseSet<unsigned int, Type> set;
|
||||
entt::SparseSet<unsigned int, InternalType> set;
|
||||
|
||||
set.construct(0, 0);
|
||||
set.construct(1, 1);
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/locator/locator.hpp>
|
||||
|
||||
struct A {};
|
||||
struct AService {};
|
||||
|
||||
struct B {
|
||||
struct AnotherService {
|
||||
virtual void f(bool) = 0;
|
||||
bool check{false};
|
||||
};
|
||||
|
||||
struct D: B {
|
||||
D(int): B{} {}
|
||||
struct DerivedService: AnotherService {
|
||||
DerivedService(int): AnotherService{} {}
|
||||
void f(bool b) override { check = b; }
|
||||
};
|
||||
|
||||
TEST(ServiceLocator, Functionalities) {
|
||||
using entt::ServiceLocator;
|
||||
|
||||
ASSERT_TRUE(ServiceLocator<A>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<B>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AService>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AnotherService>::empty());
|
||||
|
||||
ServiceLocator<A>::set();
|
||||
ServiceLocator<AService>::set();
|
||||
|
||||
ASSERT_FALSE(ServiceLocator<A>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<B>::empty());
|
||||
ASSERT_FALSE(ServiceLocator<AService>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AnotherService>::empty());
|
||||
|
||||
ServiceLocator<A>::reset();
|
||||
ServiceLocator<AService>::reset();
|
||||
|
||||
ASSERT_TRUE(ServiceLocator<A>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<B>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AService>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AnotherService>::empty());
|
||||
|
||||
ServiceLocator<A>::set(std::make_shared<A>());
|
||||
ServiceLocator<AService>::set(std::make_shared<AService>());
|
||||
|
||||
ASSERT_FALSE(ServiceLocator<A>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<B>::empty());
|
||||
ASSERT_FALSE(ServiceLocator<AService>::empty());
|
||||
ASSERT_TRUE(ServiceLocator<AnotherService>::empty());
|
||||
|
||||
ServiceLocator<B>::set<D>(42);
|
||||
ServiceLocator<AnotherService>::set<DerivedService>(42);
|
||||
|
||||
ASSERT_FALSE(ServiceLocator<A>::empty());
|
||||
ASSERT_FALSE(ServiceLocator<B>::empty());
|
||||
ASSERT_FALSE(ServiceLocator<AService>::empty());
|
||||
ASSERT_FALSE(ServiceLocator<AnotherService>::empty());
|
||||
|
||||
ServiceLocator<B>::get().lock()->f(!ServiceLocator<B>::get().lock()->check);
|
||||
ServiceLocator<AnotherService>::get().lock()->f(!ServiceLocator<AnotherService>::get().lock()->check);
|
||||
|
||||
ASSERT_TRUE(ServiceLocator<B>::get().lock()->check);
|
||||
ASSERT_TRUE(ServiceLocator<AnotherService>::get().lock()->check);
|
||||
|
||||
ServiceLocator<B>::ref().f(!ServiceLocator<B>::get().lock()->check);
|
||||
ServiceLocator<AnotherService>::ref().f(!ServiceLocator<AnotherService>::get().lock()->check);
|
||||
|
||||
ASSERT_FALSE(ServiceLocator<B>::get().lock()->check);
|
||||
ASSERT_FALSE(ServiceLocator<AnotherService>::get().lock()->check);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/signal/delegate.hpp>
|
||||
|
||||
int f(int i) {
|
||||
int delegateFunction(int i) {
|
||||
return i*i;
|
||||
}
|
||||
|
||||
struct S {
|
||||
int f(int i) {
|
||||
struct DelegateFunctor {
|
||||
int operator()(int i) {
|
||||
return i+i;
|
||||
}
|
||||
};
|
||||
@@ -14,13 +14,13 @@ struct S {
|
||||
TEST(Delegate, Functionalities) {
|
||||
entt::Delegate<int(int)> ffdel;
|
||||
entt::Delegate<int(int)> mfdel;
|
||||
S test;
|
||||
DelegateFunctor functor;
|
||||
|
||||
ASSERT_EQ(ffdel(42), int{});
|
||||
ASSERT_EQ(mfdel(42), int{});
|
||||
|
||||
ffdel.connect<&f>();
|
||||
mfdel.connect<S, &S::f>(&test);
|
||||
ffdel.connect<&delegateFunction>();
|
||||
mfdel.connect<DelegateFunctor, &DelegateFunctor::operator()>(&functor);
|
||||
|
||||
ASSERT_EQ(ffdel(3), 9);
|
||||
ASSERT_EQ(mfdel(3), 6);
|
||||
@@ -35,7 +35,7 @@ TEST(Delegate, Functionalities) {
|
||||
TEST(Delegate, Comparison) {
|
||||
entt::Delegate<int(int)> delegate;
|
||||
entt::Delegate<int(int)> def;
|
||||
delegate.connect<&f>();
|
||||
delegate.connect<&delegateFunction>();
|
||||
|
||||
ASSERT_EQ(def, entt::Delegate<int(int)>{});
|
||||
ASSERT_NE(def, delegate);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/signal/sigh.hpp>
|
||||
|
||||
struct S {
|
||||
struct SigHListener {
|
||||
static void f(int &v) { v = 42; }
|
||||
|
||||
bool g(int) { k = !k; return true; }
|
||||
@@ -64,53 +64,53 @@ TEST(SigH, Comparison) {
|
||||
entt::SigH<void()> sig1;
|
||||
entt::SigH<void()> sig2;
|
||||
|
||||
S s1;
|
||||
S s2;
|
||||
SigHListener s1;
|
||||
SigHListener s2;
|
||||
|
||||
sig1.sink().connect<S, &S::i>(&s1);
|
||||
sig2.sink().connect<S, &S::i>(&s2);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::i>(&s2);
|
||||
|
||||
ASSERT_FALSE(sig1 == sig2);
|
||||
ASSERT_TRUE(sig1 != sig2);
|
||||
|
||||
sig1.sink().disconnect<S, &S::i>(&s1);
|
||||
sig2.sink().disconnect<S, &S::i>(&s2);
|
||||
sig1.sink().disconnect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().disconnect<SigHListener, &SigHListener::i>(&s2);
|
||||
|
||||
sig1.sink().connect<S, &S::i>(&s1);
|
||||
sig2.sink().connect<S, &S::l>(&s1);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::l>(&s1);
|
||||
|
||||
ASSERT_FALSE(sig1 == sig2);
|
||||
ASSERT_TRUE(sig1 != sig2);
|
||||
|
||||
sig1.sink().disconnect<S, &S::i>(&s1);
|
||||
sig2.sink().disconnect<S, &S::l>(&s1);
|
||||
sig1.sink().disconnect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().disconnect<SigHListener, &SigHListener::l>(&s1);
|
||||
|
||||
ASSERT_TRUE(sig1 == sig2);
|
||||
ASSERT_FALSE(sig1 != sig2);
|
||||
|
||||
sig1.sink().connect<S, &S::i>(&s1);
|
||||
sig1.sink().connect<S, &S::l>(&s1);
|
||||
sig2.sink().connect<S, &S::i>(&s1);
|
||||
sig2.sink().connect<S, &S::l>(&s1);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::l>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::l>(&s1);
|
||||
|
||||
ASSERT_TRUE(sig1 == sig2);
|
||||
|
||||
sig1.sink().disconnect<S, &S::i>(&s1);
|
||||
sig1.sink().disconnect<S, &S::l>(&s1);
|
||||
sig2.sink().disconnect<S, &S::i>(&s1);
|
||||
sig2.sink().disconnect<S, &S::l>(&s1);
|
||||
sig1.sink().disconnect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig1.sink().disconnect<SigHListener, &SigHListener::l>(&s1);
|
||||
sig2.sink().disconnect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig2.sink().disconnect<SigHListener, &SigHListener::l>(&s1);
|
||||
|
||||
sig1.sink().connect<S, &S::i>(&s1);
|
||||
sig1.sink().connect<S, &S::l>(&s1);
|
||||
sig2.sink().connect<S, &S::l>(&s1);
|
||||
sig2.sink().connect<S, &S::i>(&s1);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
sig1.sink().connect<SigHListener, &SigHListener::l>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::l>(&s1);
|
||||
sig2.sink().connect<SigHListener, &SigHListener::i>(&s1);
|
||||
|
||||
ASSERT_FALSE(sig1 == sig2);
|
||||
}
|
||||
|
||||
TEST(SigH, Clear) {
|
||||
entt::SigH<void(int &)> sigh;
|
||||
sigh.sink().connect<&S::f>();
|
||||
sigh.sink().connect<&SigHListener::f>();
|
||||
|
||||
ASSERT_FALSE(sigh.empty());
|
||||
|
||||
@@ -123,7 +123,7 @@ TEST(SigH, Swap) {
|
||||
entt::SigH<void(int &)> sigh1;
|
||||
entt::SigH<void(int &)> sigh2;
|
||||
|
||||
sigh1.sink().connect<&S::f>();
|
||||
sigh1.sink().connect<&SigHListener::f>();
|
||||
|
||||
ASSERT_FALSE(sigh1.empty());
|
||||
ASSERT_TRUE(sigh2.empty());
|
||||
@@ -138,7 +138,7 @@ TEST(SigH, Functions) {
|
||||
entt::SigH<void(int &)> sigh;
|
||||
int v = 0;
|
||||
|
||||
sigh.sink().connect<&S::f>();
|
||||
sigh.sink().connect<&SigHListener::f>();
|
||||
sigh.publish(v);
|
||||
|
||||
ASSERT_FALSE(sigh.empty());
|
||||
@@ -146,37 +146,37 @@ TEST(SigH, Functions) {
|
||||
ASSERT_EQ(42, v);
|
||||
|
||||
v = 0;
|
||||
sigh.sink().disconnect<&S::f>();
|
||||
sigh.sink().disconnect<&SigHListener::f>();
|
||||
sigh.publish(v);
|
||||
|
||||
ASSERT_TRUE(sigh.empty());
|
||||
ASSERT_EQ((entt::SigH<bool(int)>::size_type)0, sigh.size());
|
||||
ASSERT_EQ(0, v);
|
||||
|
||||
sigh.sink().connect<&S::f>();
|
||||
sigh.sink().connect<&SigHListener::f>();
|
||||
}
|
||||
|
||||
TEST(SigH, Members) {
|
||||
S s;
|
||||
S *ptr = &s;
|
||||
SigHListener s;
|
||||
SigHListener *ptr = &s;
|
||||
entt::SigH<bool(int)> sigh;
|
||||
|
||||
sigh.sink().connect<S, &S::g>(ptr);
|
||||
sigh.sink().connect<SigHListener, &SigHListener::g>(ptr);
|
||||
sigh.publish(42);
|
||||
|
||||
ASSERT_TRUE(s.k);
|
||||
ASSERT_FALSE(sigh.empty());
|
||||
ASSERT_EQ((entt::SigH<bool(int)>::size_type)1, sigh.size());
|
||||
|
||||
sigh.sink().disconnect<S, &S::g>(ptr);
|
||||
sigh.sink().disconnect<SigHListener, &SigHListener::g>(ptr);
|
||||
sigh.publish(42);
|
||||
|
||||
ASSERT_TRUE(s.k);
|
||||
ASSERT_TRUE(sigh.empty());
|
||||
ASSERT_EQ((entt::SigH<bool(int)>::size_type)0, sigh.size());
|
||||
|
||||
sigh.sink().connect<S, &S::g>(ptr);
|
||||
sigh.sink().connect<S, &S::h>(ptr);
|
||||
sigh.sink().connect<SigHListener, &SigHListener::g>(ptr);
|
||||
sigh.sink().connect<SigHListener, &SigHListener::h>(ptr);
|
||||
|
||||
ASSERT_FALSE(sigh.empty());
|
||||
ASSERT_EQ((entt::SigH<bool(int)>::size_type)2, sigh.size());
|
||||
|
||||
@@ -18,17 +18,17 @@ struct Relationship {
|
||||
entt::DefaultRegistry::entity_type parent;
|
||||
};
|
||||
|
||||
template<class Archive>
|
||||
template<typename Archive>
|
||||
void serialize(Archive &archive, Position &position) {
|
||||
archive(position.x, position.y);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
template<typename Archive>
|
||||
void serialize(Archive &archive, Timer &timer) {
|
||||
archive(timer.duration);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
template<typename Archive>
|
||||
void serialize(Archive &archive, Relationship &relationship) {
|
||||
archive(relationship.parent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user