Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
Offline Benjamin  
#1 Posted : Wednesday, July 3, 2013 1:16:38 AM(UTC)

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
We will start to talk a bit more about the internals of the Delta Engine here. Our new simplified and updated Entity system has now 2 main interfaces for entities or behaviors to use: Updateable and Drawable. Updateable adds an Update method, which is called whenever it is time to update (by default only every 200ms, but that value can easily be changed in the Settings), while Draw is called as often as possible (60 times per second if VSync is on, much more if not). Many classes will not implement Draw and quite a lot might not even need Updateable.

While updating no drawing will occur, and while drawing there is just read-only access to any entity data. This not only allows for simple networking code that works out of the box, but also makes any game using this system deterministic (as long as no randomizer is used somewhere that cannot be reproduced), which is great for physics, testing and finetuning.

Anyway, here is my first experiment using the current entity system (just spaming out the result into the console), there is tons of dummy code and this is not how it will be implemented, just a first idea:


	/// <summary>
	/// Here we experiment around with the Update and Draw threads proposed by case 4269 to be
	/// implemented into the EntitiesRunner and the AutofacStarter to be used by all apps.
	/// </summary>
	public class UpdateAndDrawThreadsTests
		//ncrunch: no coverage start
		[Test, Ignore]
		public void UpdateAndDrawInParallel()
			const float UpdateTimeStep = 0.2f; //TODO: must move to EntitiesRunners and be known there
			const float RenderTimeStep = 0.016f; // does not really matter how fast this is
			var entities = new TestEntitiesRunner<EntityTests.EmptyBehavior>();
			var state = new PositionEntity(Point.Zero);
			float drawTime = 0.0f;//old Time.Current.Delta, needs to be removed, see discussion from phil in case 4269
			float updateTime = 0.0f;//needs to go to EntitiesRunners
			float accumulator = 0.0f;//same
			while (drawTime < 10.0f)
				drawTime += RenderTimeStep;
				accumulator += RenderTimeStep;
				while (accumulator >= UpdateTimeStep)
					updateTime += UpdateTimeStep;
					accumulator -= UpdateTimeStep;

				float alpha = accumulator / UpdateTimeStep;
				var interpolatedPosition = state.GetInterpolatedPosition(alpha);
				Console.WriteLine("interpolatedPosition=" + interpolatedPosition + 
					", drawTime=" + drawTime + ", updateTime=" + updateTime + ", alpha=" + alpha);

		public class PositionEntity : Entity, Updateable
			public PositionEntity(Point pos)

			public Point Position
				get { return Get<Point>(); } // Get is returning interpolating value at render time
				set { Set(value); } // set is forbidden at render time! any entity change is forbidden

			public void Update()
				Position += Point.One;

			public Point GetInterpolatedPosition(float alpha)
				//dummy code
				return Get<Point>() * alpha + GetPrevious<Point>() * (1.0f - alpha);

And this is the output (clipped):

interpolatedPosition=0, 0, drawTime=0.176, updateTime=0, alpha=0.8800001
interpolatedPosition=0, 0, drawTime=0.192, updateTime=0, alpha=0.9600001
interpolatedPosition=0.04000008, 0.04000008, drawTime=0.208, updateTime=0.2, alpha=0.04000008
interpolatedPosition=0.1200001, 0.1200001, drawTime=0.224, updateTime=0.2, alpha=0.1200001
interpolatedPosition=0.2000001, 0.2000001, drawTime=0.24, updateTime=0.2, alpha=0.2000001
interpolatedPosition=0.2800001, 0.2800001, drawTime=0.256, updateTime=0.2, alpha=0.2800001
interpolatedPosition=0.3600001, 0.3600001, drawTime=0.272, updateTime=0.2, alpha=0.3600001
interpolatedPosition=0.4400001, 0.4400001, drawTime=0.288, updateTime=0.2, alpha=0.4400001
interpolatedPosition=0.5200001, 0.5200001, drawTime=0.304, updateTime=0.2, alpha=0.5200001
interpolatedPosition=0.6000001, 0.6000001, drawTime=0.32, updateTime=0.2, alpha=0.6000001
interpolatedPosition=0.6800001, 0.6800001, drawTime=0.336, updateTime=0.2, alpha=0.6800001
interpolatedPosition=0.7600001, 0.7600001, drawTime=0.352, updateTime=0.2, alpha=0.7600001
interpolatedPosition=0.8400002, 0.8400002, drawTime=0.368, updateTime=0.2, alpha=0.8400002
interpolatedPosition=0.9200001, 0.9200001, drawTime=0.384, updateTime=0.2, alpha=0.9200001
interpolatedPosition=1, 1, drawTime=0.4, updateTime=0.4, alpha=1.490116E-07
interpolatedPosition=1.08, 1.08, drawTime=0.416, updateTime=0.4, alpha=0.08000015
interpolatedPosition=1.16, 1.16, drawTime=0.432, updateTime=0.4, alpha=0.1600002
interpolatedPosition=1.24, 1.24, drawTime=0.448, updateTime=0.4, alpha=0.2400001
interpolatedPosition=1.32, 1.32, drawTime=0.464, updateTime=0.4, alpha=0.3200002
interpolatedPosition=1.4, 1.4, drawTime=0.48, updateTime=0.4, alpha=0.4000002
interpolatedPosition=1.48, 1.48, drawTime=0.4960001, updateTime=0.4, alpha=0.4800002
interpolatedPosition=1.56, 1.56, drawTime=0.512, updateTime=0.4, alpha=0.5600002
interpolatedPosition=1.64, 1.64, drawTime=0.528, updateTime=0.4, alpha=0.6400002
interpolatedPosition=1.72, 1.72, drawTime=0.544, updateTime=0.4, alpha=0.7200002
interpolatedPosition=1.8, 1.8, drawTime=0.5599999, updateTime=0.4, alpha=0.8000002
interpolatedPosition=1.88, 1.88, drawTime=0.5759999, updateTime=0.4, alpha=0.8800002
interpolatedPosition=1.96, 1.96, drawTime=0.5919999, updateTime=0.4, alpha=0.9600002
interpolatedPosition=2.04, 2.04, drawTime=0.6079999, updateTime=0.6, alpha=0.04000023
interpolatedPosition=2.12, 2.12, drawTime=0.6239998, updateTime=0.6, alpha=0.1200002
interpolatedPosition=2.2, 2.2, drawTime=0.6399998, updateTime=0.6, alpha=0.2000002
interpolatedPosition=2.28, 2.28, drawTime=0.6559998, updateTime=0.6, alpha=0.2800002
interpolatedPosition=2.36, 2.36, drawTime=0.6719998, updateTime=0.6, alpha=0.3600003
interpolatedPosition=2.44, 2.44, drawTime=0.6879997, updateTime=0.6, alpha=0.4400003
interpolatedPosition=2.52, 2.52, drawTime=0.7039997, updateTime=0.6, alpha=0.5200003
interpolatedPosition=2.6, 2.6, drawTime=0.7199997, updateTime=0.6, alpha=0.6000003
interpolatedPosition=2.68, 2.68, drawTime=0.7359996, updateTime=0.6, alpha=0.6800002
interpolatedPosition=2.76, 2.76, drawTime=0.7519996, updateTime=0.6, alpha=0.7600003
interpolatedPosition=2.84, 2.84, drawTime=0.7679996, updateTime=0.6, alpha=0.8400003
interpolatedPosition=2.92, 2.92, drawTime=0.7839996, updateTime=0.6, alpha=0.9200003
interpolatedPosition=3, 3, drawTime=0.7999995, updateTime=0.8, alpha=2.980232E-07
interpolatedPosition=3.08, 3.08, drawTime=0.8159995, updateTime=0.8, alpha=0.0800003
interpolatedPosition=3.16, 3.16, drawTime=0.8319995, updateTime=0.8, alpha=0.1600003
interpolatedPosition=3.24, 3.24, drawTime=0.8479995, updateTime=0.8, alpha=0.2400003
interpolatedPosition=3.32, 3.32, drawTime=0.8639994, updateTime=0.8, alpha=0.3200003
interpolatedPosition=3.4, 3.4, drawTime=0.8799994, updateTime=0.8, alpha=0.4000003
interpolatedPosition=3.48, 3.48, drawTime=0.8959994, updateTime=0.8, alpha=0.4800003
interpolatedPosition=3.56, 3.56, drawTime=0.9119993, updateTime=0.8, alpha=0.5600004
interpolatedPosition=3.64, 3.64, drawTime=0.9279993, updateTime=0.8, alpha=0.6400003
interpolatedPosition=3.72, 3.72, drawTime=0.9439993, updateTime=0.8, alpha=0.7200003
interpolatedPosition=3.8, 3.8, drawTime=0.9599993, updateTime=0.8, alpha=0.8000004
interpolatedPosition=3.88, 3.88, drawTime=0.9759992, updateTime=0.8, alpha=0.8800004
interpolatedPosition=3.960001, 3.960001, drawTime=0.9919992, updateTime=0.8, alpha=0.9600004
interpolatedPosition=4.04, 4.04, drawTime=1.007999, updateTime=1, alpha=0.04000038
interpolatedPosition=4.12, 4.12, drawTime=1.023999, updateTime=1, alpha=0.1200004
interpolatedPosition=4.2, 4.2, drawTime=1.039999, updateTime=1, alpha=0.2000004
thanks 1 user thanked Benjamin for this useful post.
fg_garda on 7/3/2013(UTC)

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.041 seconds.