public void UpdateAndDrawInParallel()
 {
     const float UpdateTimeStep = 0.2f;
     const float RenderTimeStep = 0.016f;
     var entities = new MockEntitiesRunner(typeof(MockUpdateBehavior));
     var state = new PositionEntity(Vector2D.Zero);
     float drawTime = 0.0f;
     float updateTime = 0.0f;
     float accumulator = 0.0f;
     while (drawTime < 10.0f)
     {
         drawTime += RenderTimeStep;
         accumulator += RenderTimeStep;
         while (accumulator >= UpdateTimeStep)
         {
             state.InvokeNextUpdateStarted();
             state.Update();
             updateTime += UpdateTimeStep;
             accumulator -= UpdateTimeStep;
         }
         float interpolation = accumulator / UpdateTimeStep;
         var interpolatedPosition = state.Position;
         Console.WriteLine("interpolatedPosition=" + interpolatedPosition +
             ", drawTime=" + drawTime +
             ", updateTime=" + updateTime +
             ", interpolation=" + interpolation);
     }
     entities.Dispose();
 }
Esempio n. 2
0
		public void InitializeEntitiesRunner()
		{
			entities = new MockEntitiesRunner(typeof(MockUpdateBehavior), typeof(ComponentTests.Rotate),
				typeof(CreateEntityStartAndStopBehavior));
			entityWithTags = new MockEntity();
			entityWithTags.AddTag(Tag1);
			entityWithTags.AddTag(Tag2);
		}
Esempio n. 3
0
		public void CreateEntityWithRotationComponent()
		{
			var entities = new MockEntitiesRunner(typeof(Rotate));
			var entity = new MockEntity().Add(0.5f).Start<Rotate>();
			Assert.AreEqual(0.5f, entity.Get<float>());
			entities.RunEntities();
			Assert.AreEqual(0.55f, entity.Get<float>());
		}
		public void SelectingEntityHandlerProcessesEntitiesThatPassTheSelectionCriteria()
		{
			var entities = new MockEntitiesRunner(typeof(IncludeOnlyEntitiesWithPositiveFloats));
			var first = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(3.0f);
			var excluded = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(-1.0f);
			var second = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(2.0f);
			entities.RunEntities();
			var start = first.Get<int>();
			Assert.IsFalse(excluded.Contains<int>());
			Assert.AreEqual(start + 1, second.Get<int>());
		}
Esempio n. 5
0
		public void PauseTimeShouldNotUpdateAnyEntityAnymore()
		{
			var entities = new MockEntitiesRunner(typeof(EntitiesRunnerTests.IncrementCounter));
			var entity = new MockEntity().Add(0).Start<EntitiesRunnerTests.IncrementCounter>();
			Assert.AreEqual(0, entity.Get<int>());
			entities.RunEntities();
			Assert.AreEqual(1, entity.Get<int>());
			Time.SpeedFactor = 0;
			entities.RunEntities();
			Assert.AreEqual(1, entity.Get<int>());
			Time.SpeedFactor = 1;
		}
		public void SelectingEntitiesWithDifferentRenderLayer()
		{
			var entities = new MockEntitiesRunner(typeof(SortByRenderLayer));
			var last = new MockDrawableEntity { RenderLayer = 13 };
			last.OnDraw<SortByRenderLayer>();
			var first = new MockDrawableEntity { RenderLayer = -1 };
			first.OnDraw<SortByRenderLayer>();
			var middle = new MockDrawableEntity { RenderLayer = 5 };
			middle.OnDraw<SortByRenderLayer>();
			SortedResult.Clear();
			entities.RunEntities();
			Assert.AreEqual(first, SortedResult[0]);
			Assert.AreEqual(middle, SortedResult[1]);
			Assert.AreEqual(last, SortedResult[2]);
		}
		public void SelectingMultipleDifferentEntitiesWithDifferentRenderLayer()
		{
			var entities = new MockEntitiesRunner(typeof(SortByRenderLayer),
				typeof(AnotherSortByRenderLayer));
			var last = new MockDrawableEntity();
			last.OnDraw<SortByRenderLayer>();
			last.RenderLayer = 13;
			var first = new MockDrawableEntity { RenderLayer = -1 };
			first.OnDraw<AnotherSortByRenderLayer>();
			var middle1 = new MockDrawableEntity { RenderLayer = 5 };
			middle1.OnDraw<SortByRenderLayer>();
			var middle2 = new MockDrawableEntity { RenderLayer = 5 };
			middle2.OnDraw<AnotherSortByRenderLayer>();
			SortedResult.Clear();
			entities.RunEntities();
			Assert.AreEqual(first, SortedResult[0]);
			Assert.AreEqual(middle1, SortedResult[1]);
			Assert.AreEqual(middle2, SortedResult[2]);
			Assert.AreEqual(last, SortedResult[3]);
		}
		public void CreateSystem()
		{
			entities = new MockEntitiesRunner(typeof(EntityCreator), typeof(EntitiesRunnerTests.IncrementCounter),
				typeof(EntityCreatorInDraw));
		}
Esempio n. 9
0
		public void InitializeResolver()
		{
			ContentLoader.Use<FakeContentLoader>();
			entities = new MockEntitiesRunner(typeof(MockUpdateBehavior));
		}
Esempio n. 10
0
		public void GetDrawBehaviorFromNegativeRenderLayerEntity()
		{
			var entities = new MockEntitiesRunner(typeof(SortByRenderLayer),
				typeof(AnotherSortByRenderLayer));
			var first = new MockDrawableEntity { RenderLayer = -1 };
			first.OnDraw<SortByRenderLayer>();
			var middle1 = new MockDrawableEntity { RenderLayer = -1 };
			middle1.OnDraw<SortByRenderLayer>();
			entities.RunEntities();
		}
Esempio n. 11
0
 public void CreateSystem()
 {
     entities = new MockEntitiesRunner(typeof(MockUpdateBehavior), typeof(IncrementCounter),
         typeof(DerivedBehavior), typeof(DrawTest), typeof(LowPriorityBehavior),
         typeof(AddNewUpdateBehaviorTwice), typeof(MockNonPauseableUpdateBehavior));
 }
Esempio n. 12
0
		public void CanCheckEntityHandlersPriority()
		{
			EntitiesRunner entities = new MockEntitiesRunner(typeof(Rotate));
			Assert.AreEqual(Priority.First, entities.GetUpdateBehavior<Rotate>().priority);
		}