Esempio n. 1
0
	public void ensures_same_deterministic_order_when_getting_entities_after_DestroyAllEntities() {
		var pool = new Pool(1);

		const int numEntities = 10;
		for (int i = 0; i < numEntities; i++) {
			pool.CreateEntity();
		}

		var order1 = new int[numEntities];
		var entities1 = pool.GetEntities();
		for (int i = 0; i < numEntities; i++) {
			order1[i] = entities1[i].creationIndex;
		}

		pool.DestroyAllEntities();
		pool.ResetCreationIndex();

		for (int i = 0; i < numEntities; i++) {
			pool.CreateEntity();
		}

		var order2 = new int[numEntities];
		var entities2 = pool.GetEntities();
		for (int i = 0; i < numEntities; i++) {
			order2[i] = entities2[i].creationIndex;
		}

		for (int i = 0; i < numEntities; i++) {
			var index1 = order1[i];
			var index2 = order2[i];

			Assert.AreEqual(index1, index2);
		}
	}
 static void moveSystem(Pool pool) {
     var entities = pool.GetEntities(Matcher.AllOf(Matcher.Move, Matcher.Position));
     foreach (var entity in entities) {
         var move = entity.move;
         var pos = entity.position;
         entity.ReplacePosition(pos.x, pos.y + move.speed);
     }
 }
Esempio n. 3
0
        static void poolExample()
        {
            // Total components is kindly generated for you by the code generator
            var pool = new Pool(ComponentIds.TotalComponents);
            var entity = pool.CreateEntity();
            entity.isMovable = true;

            // Returns all entities having MovableComponent and PositionComponent.
            // Matchers are also generated for you.
            var entities = pool.GetEntities(Matcher.AllOf(Matcher.Movable, Matcher.Position));
            foreach (var e in entities) {
                // do something
            }
        }