return;
}
- Component component(args...);
+ Component component(std::forward<Args>(args)...);
std::get<BitsetType>(entities[entityID]).template getComponentBit<Component>() = true;
- std::get<std::vector<Component> >(componentsStorage)[std::get<std::size_t>(entities[entityID])] = component;
+ std::get<std::vector<Component> >(componentsStorage)[std::get<std::size_t>(entities[entityID])] = std::move(component);
}
template <typename Component>
template <typename Function, typename TTuple, std::size_t... Indices>
constexpr void forEachHelper(Function&& function, TTuple tuple, std::index_sequence<Indices...>)
{
- return (void)std::initializer_list<int>{(function(std::get<Indices>(tuple)), 0)...};
+ return (void)std::initializer_list<int>{(function(std::move(std::get<Indices>(tuple))), 0)...};
}
template <typename TTypeList, typename Function>
#include <gtest/gtest.h>
#include <iostream>
-
#include <tuple>
+#include <memory>
+
#include <EC/Meta/Meta.hpp>
#include <EC/EC.hpp>
using MixedList = EC::Meta::TypeList<C2, T1>;
+typedef std::unique_ptr<C0> C0Ptr;
+
+struct Base
+{
+ virtual int getInt()
+ {
+ return 0;
+ }
+};
+
+struct Derived : public Base
+{
+ virtual int getInt() override
+ {
+ return 1;
+ }
+};
+
+typedef std::unique_ptr<Base> TestPtr;
+
TEST(EC, Bitset)
{
{
manager.cleanup();
}
+TEST(EC, MoveComponentWithUniquePtr)
+{
+ {
+ EC::Manager<EC::Meta::TypeList<C0Ptr>, EC::Meta::TypeList<> > manager;
+
+ std::size_t e = manager.addEntity();
+
+ {
+ C0Ptr ptr = std::make_unique<C0>(5, 10);
+ manager.addComponent<C0Ptr>(e, std::move(ptr));
+ }
+
+ int x = 0;
+ int y = 0;
+ manager.forMatchingSignature<EC::Meta::TypeList<C0Ptr> >([&x, &y] (std::size_t eID, C0Ptr& ptr) {
+ x = ptr->x;
+ y = ptr->y;
+ });
+ EXPECT_EQ(5, x);
+ EXPECT_EQ(10, y);
+ }
+ {
+ EC::Manager<EC::Meta::TypeList<TestPtr>, EC::Meta::TypeList<> > manager;
+
+ std::size_t e = manager.addEntity();
+
+ {
+ TestPtr ptrBase = std::make_unique<Base>();
+ manager.addComponent<TestPtr>(e, std::move(ptrBase));
+ }
+
+ int result = 0;
+
+ auto getResultFunction = [&result] (std::size_t eID, TestPtr& ptr) {
+ result = ptr->getInt();
+ };
+
+ manager.forMatchingSignature<EC::Meta::TypeList<TestPtr> >(getResultFunction);
+
+ EXPECT_EQ(0, result);
+
+ {
+ TestPtr ptrDerived = std::make_unique<Derived>();
+ manager.addComponent<TestPtr>(e, std::move(ptrDerived));
+ }
+
+ manager.forMatchingSignature<EC::Meta::TypeList<TestPtr> >(getResultFunction);
+
+ EXPECT_EQ(1, result);
+ }
+}
+