]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Slight change to unit tests, docs
authorStephen Seo <seo.disparate@gmail.com>
Mon, 14 Mar 2016 11:36:05 +0000 (20:36 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 14 Mar 2016 11:36:05 +0000 (20:36 +0900)
Unit test now creates Component with
Manager::addComponent.

src/EC/Manager.hpp
src/test/ECTest.cpp

index 0095a5157eb70453e671b5a8aed6213006755a26..94b6781c29df6dddbd2c5dabde3f83c4a176fd39 100644 (file)
@@ -253,6 +253,8 @@ namespace EC
 
     EC::Manager must be created with a list of all used Components and all used tags.
 
+    Note that all components must have a default constructor.
+
     Example:
     \code{.cpp}
         EC::Manager<TypeList<C0, C1, C2>, TypeList<T0, T1>> manager;
@@ -349,7 +351,9 @@ namespace EC
     \code{.cpp}
         struct C0
         {
-            C0(int a, char b) : a(a), b(b)
+            // constructor is compatible as a default constructor
+            C0(int a = 0, char b = 'b') :
+            a(a), b(b)
             {}
 
             int a;
index 08f7f8ae136edc416381fe93a5fd6674a4e25b5d..3fd03cd32a061b497a40aef23f6234d0d62edfbd 100644 (file)
@@ -8,6 +8,11 @@
 #include <EC/EC.hpp>
 
 struct C0 {
+    C0(int x = 0, int y = 0) :
+    x(x),
+    y(y)
+    {}
+
     int x, y;
 };
 struct C1 {
@@ -60,19 +65,13 @@ TEST(EC, Manager)
     std::size_t e0 = manager.addEntity();
     std::size_t e1 = manager.addEntity();
 
-    manager.addComponent<C0>(e0);
+    manager.addComponent<C0>(e0, 5, 5);
     manager.addComponent<C1>(e0);
 
     manager.addComponent<C0>(e1);
     manager.addComponent<C1>(e1);
     manager.addTag<T0>(e1);
 
-    {
-        auto& pos = manager.getEntityData<C0>(e0);
-        pos.x = 5;
-        pos.y = 5;
-    }
-
     {
         auto& vel = manager.getEntityData<C1>(e0);
         vel.vx = 1;