예제 #1
0
        public unsafe void Container_child_w_type_w_childof()
        {
            var posTypeId = ECS_COMPONENT <Position>(world);
            var parent    = ECS_ENTITY(world, "parent", "");

            var(_, typeId) = ECS_TYPE(world, "Type", "Position, CHILDOF | parent");

            var child = ecs.new_child(world, parent, typeId);

            Assert.NotZero((UInt64)child);

            var childType = ecs.get_type(world, child);

            Assert.AreNotEqual(childType, default(TypeId));
            Assert.IsTrue(ecs.vector_count(childType) == 2);

            var array = ecs.vector_first(childType);

            Assert.IsFalse(array == IntPtr.Zero);

            EntityId *eArr = (EntityId *)array.ToPointer();

            Assert.IsTrue(eArr[0].Equals(ecs.type_to_entity(world, posTypeId)));
            Assert.AreEqual(eArr[1].Value, parent.Value | ecs.ECS_CHILDOF.Value);
        }
예제 #2
0
        public void Set_w_data_1_column_3_rows_stackalloc()
        {
            var posTypeId = ECS_COMPONENT <Position>(world);

            EntityId *components = stackalloc[] { ecs.type_to_entity(world, posTypeId) };
            void *    positions  = stackalloc[] { new Position {
                                                      x = 10, y = 20
                                                  }, new Position {
                                                      x = 11, y = 21
                                                  }, new Position {
                                                      x = 12, y = 22
                                                  } };
            var columns = stackalloc[] { (IntPtr)positions };

            var tableData = new TableData
            {
                columnCount = 1,
                rowCount    = 3,
                entities    = null,
                components  = components,
                columns     = columns
            };

            var e = ecs.set_w_data(world, ref tableData);

            Assert.IsTrue((UInt64)e != 0);
            Assert.IsTrue(ecs.count(world, posTypeId) == 3);

            for (var i = 0; i < 3; i++)
            {
                var entity = (EntityId)(e.Value + (UInt64)i);
                Assert.IsTrue(ecs.has(world, entity, posTypeId));

                var p = ecs.get_ptr <Position>(world, entity);
                Assert.IsTrue(p != null);
                Assert.IsTrue(p->x == 10 + i);
                Assert.IsTrue(p->y == 20 + i);
            }
        }