public GraphicsDevice(DrawQueue drawQueue) { // TODO: Complete member initialization this.drawQueue = drawQueue; viewport = new Viewport(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height); }
/// <summary> /// 响应鼠标的操作 /// </summary> public void Fire() { if (Start) { PhysicsWorld.RemoveObject(_elasticatedNet); DrawQueue.Remove(_elasticatedNet); } // 创建弹性网并加入到物理世界和绘制队列 _elasticatedNet = new ElasticatedNet( new Vector2D(40, 120).ToSimUnits(), Width, Height, GridSize, Factor ); DrawQueue.Add(_elasticatedNet); PhysicsWorld.AddObject(_elasticatedNet); // 拉扯弹性网 var net = _elasticatedNet.Net; for (int i = 0; i < Width; i++) { net[i, Height - 1].Velocity = new Vector2D(0, 0.1) * 4 * (i >= Width / 2 ? -1 : 1); net[i, Height - 1].InverseMass = 0; } Start = true; }
public void DrawBatcherTools_CombineList_DoesSoInCorrectOrder() { IDrawStageBatcherTools tools = new DrawStageBatcherTools(); var messenger = Substitute.For <IFrameworkMessenger>(); var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); var w0 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0 }; var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); var w1 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1 }; var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); var w2 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2 }; var others = new List <QueueWrap> { w1, w2 }; var combined = tools.CombinedList(w0, others); Assert.Equal(2UL, combined[2].Queue.Data.Texture0[0]); }
public ContactDemo(Image image) : base(image) { Settings.ContactIteration = 1; const int num = 5; for (int i = 0; i < num; i++) { var fB = PhysicsWorld.CreateFixedParticle((new Vector2D(160 + 40 * i, 0)).ToSimUnits()); var pB = PhysicsWorld.CreateParticle((new Vector2D(160 + 40 * i, 200)).ToSimUnits(), new Vector2D(0, 0), 2); var ball = new Ball { FixedParticle = fB, Particle = pB, R = 20 }; // 为质体绑定形状 ball.Particle.BindShape(new Circle(ball.R.ToSimUnits())); PhysicsWorld.CreateRope(200.ToSimUnits(), 0, fB, pB); DrawQueue.Add(ball); _ballList.Add(ball); } // 增加重力和空气阻力 PhysicsWorld.CreateGlobalZone(new ParticleGravity(new Vector2D(0, 40))); PhysicsWorld.CreateParticle(Vector2D.Zero, new Vector2D(1, 0), 1); Slot = 1 / 120.0; Start = true; }
public void QueueToBufferBlitter_TestUnpackAndTransfer_CorrectBufferCallsAndDataTransfered() { var messenger = Substitute.For <IFrameworkMessenger>(); IQueueToBufferBlitter blitter = new QueueToBufferBlitter(); var q = new DrawQueue(messenger, new ComparerCollection(), 36, 8, false); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); Add(q, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 0); q.Sort(); var wrap = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 16, BufferPositionOfFirstVertex = 32, Queue = q }; var buffersMock = Substitute.For <IDrawStageBuffers>(); blitter.UnpackAndTransferToGpu(wrap, buffersMock); buffersMock.Received(1).EnsureVertexBufferIsLargeEnough(Arg.Any <int>(), Arg.Any <bool>()); buffersMock.Received(1).EnsureIndexBufferIsLargeEnough(Arg.Any <int>(), Arg.Any <bool>()); buffersMock.ReceivedWithAnyArgs(21).CopyAVertexToStagingArray(default, default, default, default, default, default, default, default, default, default, default);
public void DrawImageToScreen(string imageName, int x, int y) { DrawQueue.Enqueue(() => { Drawables[imageName].X = x; Drawables[imageName].Y = y; lock (SyncObj) TextureDictionary[imageName].Apply(false); if (!IsIngameImage(imageName)) { //TODO: Avoid shifting cost. //Remove from the list and then re-add //so that freshly updated textures are forced on top. DrawablesList.Remove(Drawables[imageName]); DrawablesList.Add(Drawables[imageName]); } else { //TODO: Avoid shifting cost. //Remove from the list and then re-add //so that freshly updated textures are forced on top. InGameDrawablesList.Remove(Drawables[imageName]); InGameDrawablesList.Add(Drawables[imageName]); } }); }
public GraphicsDevice(DrawQueue drawQueue) { // TODO: Complete member initialization this.drawQueue = drawQueue; viewport = new Viewport(0,0,UnityEngine.Screen.width, UnityEngine.Screen.height); }
public FluidDemo(Image image) : base(image) { // 创建液体容器 _water = new Water((int)image.Width, (int)image.Height); // 添加到绘制队列 DrawQueue.Add(_water); }
public void DrawQueueTest_CheckBasicAdd_NumberAndContentOfRequestsOK() { var messenger = Substitute.For <IFrameworkMessenger>(); IComparerCollection comparers = new ComparerCollection(); IDrawQueue queue = new DrawQueue(messenger, comparers, 32, 4, false); for (var n = 0; n < 10; n++) { var even = n % 2 == 0; var target = even ? CoordinateSpace.Screen : CoordinateSpace.World; var fill = even ? FillType.Coloured : FillType.Textured; if (n == 1) { fill = FillType.DualTextured; } var val = 0.1f * n; var colour = new Colour(val, val, val, val); var verts = new Vertex2D[] { new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f } }; var indices = new int[] { 0, 1, 0 }; var texture0 = (ulong)n; var texture1 = (ulong)n; var texMode0 = TextureCoordinateMode.Mirror; var texMode1 = TextureCoordinateMode.Wrap; var depth = 0.05f * n; var layer = n; queue.Add( ref target, ref fill, ref colour, ref verts, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer); } Assert.Equal(10, queue.Data.NumRequests); var data = queue.Data; //Test values in single request Assert.Equal(CoordinateSpace.World, data.Targets[5]); Assert.Equal(FillType.Textured, data.Types[5]); Assert.Equal(0.5f, data.BaseColours[5].R, 5); Assert.Equal(0.9f, data.Vertices[data.FirstVertexPosition[5]].TexWeighting, 5); Assert.Equal(1, data.Indices[data.FirstIndexPosition[5] + 1]); Assert.Equal((ulong)5, data.Texture1[5]); Assert.Equal(0.25f, data.Depths[5], 5); Assert.Equal(5, data.Layers[5]); }
public void DrawQueueTest_InitialQueue_CatchSmallSizeInputs() { var messenger = Substitute.For <IFrameworkMessenger>(); IComparerCollection comparers = new ComparerCollection(); IDrawQueue queue = new DrawQueue(messenger, comparers, -10, -4, false); Assert.Equal(512, queue.Data.QueueSizeSingleProperty); Assert.Equal(4096, queue.Data.QueueSizeIndex); }
public void DrawImageToScreen(string imageName, int x, int y) { //WebGL doesn't need to defer this to a different thread. if (RsUnityPlatform.isWebGLBuild) { UpdateDrawableTexture(imageName, x, y); } else { DrawQueue.Enqueue(() => { UpdateDrawableTexture(imageName, x, y); }); } }
// Use this for initialization void Start () { Application.targetFrameRate = 60; // Add an audio source and tell the media player to use it for playing sounds Microsoft.Xna.Framework.Media.MediaPlayer.AudioSource = gameObject.AddComponent<AudioSource>(); drawQueue = new DrawQueue(); game = new PlatformerGame(); game.DrawQueue = drawQueue; game.Begin(); timeleft = updateInterval; //Application.targetFrameRate = 30; }
// Use this for initialization void Start() { Application.targetFrameRate = 60; // Add an audio source and tell the media player to use it for playing sounds Microsoft.Xna.Framework.Media.MediaPlayer.AudioSource = gameObject.AddComponent <AudioSource>(); drawQueue = new DrawQueue(); game = new PlatformerGame(); game.DrawQueue = drawQueue; game.Begin(); timeleft = updateInterval; //Application.targetFrameRate = 30; }
public void DrawQueueTest_CheckBasicClear_ConfirmZeroPostClear() { var messenger = Substitute.For <IFrameworkMessenger>(); IComparerCollection comparers = new ComparerCollection(); IDrawQueue queue = new DrawQueue(messenger, comparers, 32, 4, false); for (var n = 0; n < 10; n++) { var even = n % 2 == 0; var target = even ? CoordinateSpace.Screen : CoordinateSpace.World; var fill = even ? FillType.Coloured : FillType.Textured; if (n == 1) { fill = FillType.DualTextured; } var val = 0.1f * n; var colour = new Colour(val, val, val, val); var verts = new Vertex2D[] { new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f } }; var indices = new int[] { 0, 1, 0 }; var texture0 = (ulong)n; var texture1 = (ulong)n; var texMode0 = TextureCoordinateMode.Mirror; var texMode1 = TextureCoordinateMode.Wrap; var depth = 0.05f * n; var layer = n; queue.Add( ref target, ref fill, ref colour, ref verts, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer); } Assert.Equal(10, queue.Data.NumRequests); queue.Clear(); Assert.Equal(0, queue.Data.NumRequests); }
public CircleDemo(Image image) : base(image) { // 初始化中心点 _centerObj = PhysicsWorld.CreateFixedParticle ( new Vector2D ( 250.ToSimUnits(), 200.ToSimUnits() ) ); // 注册绘制对象 DrawQueue.Add(this); }
public void DrawBatcherTools_GenerateTheNextBatch_ConsumesOneRequestButSkipsQueueDueToInactive() { IDrawStageBatcherTools tools = new DrawStageBatcherTools(); var messenger = Substitute.For <IFrameworkMessenger>(); var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3); Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3); Add(q0, FillType.Coloured, 12UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 11); var w0 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0 }; var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 9, 1.0f); var w1 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1 }; var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 0.5f); var w2 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2 }; var others = new List <QueueWrap> { w1, w2 }; var combined = tools.CombinedList(w0, others).ToArray(); var num = 3; var pool = new DrawingBatch[] { new DrawingBatch() }; tools.GenerateTheNextBatch(pool, 1, 0, ref num, combined, new int[] { 0, 0, 0 }, 3, new bool[] { true, false, true }, new int[] { 0, 0, 0 }, new bool[] { true, false, true }); var batch = pool[0]; Assert.Equal(1UL, batch.Texture0); Assert.Equal(3, batch.NumIndices); }
[InlineData(12, 24, FillType.DualTextured, 1UL, 2UL, 1.0f, -1)] //Fails invalid layer public void DrawQueueTest_TestingAddIfValid_FailOnAllAsEachHasConfigurationIssue(int numverts, int numindices, FillType fill, ulong tex0, ulong tex1, float depth, int layer) { var messenger = Substitute.For <IFrameworkMessenger>(); IComparerCollection comparers = new ComparerCollection(); IDrawQueue queue = new DrawQueue(messenger, comparers, 32, 4, false); var target = CoordinateSpace.Screen; var colour = Colour.White; var vlist = new List <Vertex2D>(); for (var n = 0; n < numverts; n++) { vlist.Add(new Vertex2D { Colour = Colour.White, Position = Vector2.Zero, TexCoord0 = Vector2.Zero, TexCoord1 = Vector2.One, TexWeighting = 0.9f }); } var verts = vlist.ToArray(); var ilist = new List <int>(); for (var n = 0; n < numindices; n++) { ilist.Add(n); } var indices = ilist.ToArray(); var texture0 = tex0; var texture1 = tex1; var texMode0 = TextureCoordinateMode.Mirror; var texMode1 = TextureCoordinateMode.Wrap; Assert.False(queue.AddIfValid( ref target, ref fill, ref colour, ref verts, ref indices, ref texture0, ref texture1, ref texMode0, ref texMode1, ref depth, ref layer)); }
public void DrawBatcherTools_IdentifyActiveInLayer_SimpleTest() { IDrawStageBatcherTools tools = new DrawStageBatcherTools(); var messenger = Substitute.For <IFrameworkMessenger>(); var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3); var w0 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0 }; var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10); var w1 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1 }; var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10); var w2 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2 }; var others = new List <QueueWrap> { w1, w2 }; var combined = tools.CombinedList(w0, others).ToArray(); var num = 3; var activeInLayer = new bool[3]; tools.IdentifyWhichQueuesAreActiveInTheCurrentLayer(ref num, combined, new int[] { 0, 0, 0 }, 10, activeInLayer, new bool[] { true, false, true }); Assert.False(activeInLayer[0]); Assert.False(activeInLayer[1]); Assert.True(activeInLayer[2]); }
public void DrawQueueTest_TestingSort_OrderingIsCorrect() { var messenger = Substitute.For <IFrameworkMessenger>(); IComparerCollection comparers = new ComparerCollection(); IDrawQueue queue = new DrawQueue(messenger, comparers, 32, 4, false); AddItem(queue, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, FillType.Coloured, 0UL, 0UL, 0.5f, 1); //0 AddItem(queue, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, FillType.Coloured, 0UL, 0UL, 0.6f, 1); //1 AddItem(queue, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, FillType.Coloured, 0UL, 0UL, 0.8f, 1); //2 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.7f, 0); //3 AddItem(queue, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.7f, 0); //4 AddItem(queue, TextureCoordinateMode.Mirror, TextureCoordinateMode.Wrap, FillType.DualTextured, 0UL, 1UL, 0.7f, 0); //5 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Wrap, FillType.Textured, 0UL, 0UL, 0.8f, 0); //6 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Wrap, FillType.Textured, 2UL, 0UL, 0.8f, 0); //7 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Wrap, FillType.Textured, 1UL, 0UL, 0.8f, 0); //8 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.3f, 3); //9 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.3f, 4); //10 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.3f, 5); //11 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 3UL, 0.7f, 6); //12 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 2UL, 0.7f, 6); //13 AddItem(queue, TextureCoordinateMode.Wrap, TextureCoordinateMode.Mirror, FillType.DualTextured, 0UL, 1UL, 0.7f, 6); //14 queue.Sort(); /* * 6, 8, 7 -> Ordered by Texture0 * 3, 5, 4 -> Ordered by Tex0 and Tex1 wrap modes * 2, 1, 0 -> ordered by depth * 9, 10, 11 -> ordered by layer * 14, 13, 12 -> ordered by Texture1 in Dual Textured */ var order = new int[] { 6, 8, 7, 3, 5, 4, 2, 1, 0, 9, 10, 11, 14, 13, 12 }; for (var n = 0; n < order.Length; n++) { Assert.Equal(order[n], queue.Data.Ordering[n]); } }
public void DrawBatcherTools_FindDeepestAtLowestLayer_SimpleTest() { IDrawStageBatcherTools tools = new DrawStageBatcherTools(); var messenger = Substitute.For <IFrameworkMessenger>(); var q0 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q0, FillType.Coloured, 0UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 3); var w0 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q0 }; var q1 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q1, FillType.Coloured, 1UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 1.0f); var w1 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q1 }; var q2 = new DrawQueue(messenger, new ComparerCollection(), 12, 4, false); Add(q2, FillType.Coloured, 2UL, 0UL, TextureCoordinateMode.Mirror, TextureCoordinateMode.Mirror, 10, 0.5f); var w2 = new QueueWrap { Id = 0, BufferPositionOfFirstIndex = 0, BufferPositionOfFirstVertex = 0, Queue = q2 }; var others = new List <QueueWrap> { w1, w2 }; var combined = tools.CombinedList(w0, others).ToArray(); var num = 3; var index = tools.FindDeepestQueueAtLowestLayer(ref num, combined, new int[] { 0, 0, 0 }, 10, new bool[] { true, false, true }); Assert.Equal(2, index); }
public RobDemo(Image image) : base(image) { Settings.ContactIteration = 20; _combinedParticle = new CombinedParticle(_vertexs, 3, 1, true); PhysicsWorld.AddObject(_combinedParticle); // 为顶点绑定形状 foreach (var vertex in _combinedParticle.Vertexs) { vertex.BindShape(new Circle(4.ToSimUnits())); } // 增加边缘 PhysicsWorld.CreatePolygonEdge(_edgePoints.ToArray()); // 增加重力 PhysicsWorld.CreateGravity(9.8); DrawQueue.Add(this); Start = true; }
public FireworksDemo(Image image) : base(image) { DrawQueue.Add(this); _dragZone = new RectangleZone ( 0.ToSimUnits(), (WorldHeight * 2 / 3.0).ToSimUnits(), 500.ToSimUnits(), 400.ToSimUnits() ); _dragZone.Add(_drag); _windZone = new RectangleZone ( 0.ToSimUnits(), (WorldHeight * 1 / 3.0).ToSimUnits(), 500.ToSimUnits(), (WorldHeight * 2 / 3.0).ToSimUnits() ); _windZone.Add(_wind); }
public abstract void Render(ref DrawQueue queueOut);
public override void Render(ref DrawQueue queueOut) { queueOut = drawQueue; }