Пример #1
0
 internal override void Update(Fusion.GameTime gameTime)
 {
     if (ToRemove)
     {
         Parent.Remove(this);
     }
 }
Пример #2
0
        public override bool execute(GameTime gameTime)
        {
            _speed = Config.SPEED;

            //Stopwatch timer = new Stopwatch();
            //timer.Start();
            if (First)
            {
                StartTime = gameTime.Total.TotalSeconds;
                First = false;
            }

            //Console.WriteLine(k + " - " + StartTime + " - " + gameTime.Total.TotalSeconds);

            float factor = (gameTime.Total.TotalSeconds - StartTime) < 1.0f / _speed ? (float)(gameTime.Total.TotalSeconds - StartTime) * _speed / 1.0f : 1.0f;
            Entity.X = lerp(Entity.Cell.X - Config.OffsetX, to.X - Config.OffsetX, factor);
            Entity.Y = lerp(Entity.Cell.Y - Config.OffsetY, to.Y - Config.OffsetY, factor);
            if (factor == 1.0f)
            {
                ActionsQueue.Field.addNewNoise(Entity.Cell, Noise);
                ActionsQueue.Field.addNewNoise(to, Noise);
                Entity.Cell = to;
                //timer.Stop();
                //Console.WriteLine("Move. FrameID: " + gameTime.FrameID + ". Time: " + timer.Elapsed);
                return true;
            }
            //timer.Stop();
            //Console.WriteLine("Move. FrameID: " + gameTime.FrameID + ". Time: " + timer.Elapsed);
            return false;
        }
Пример #3
0
 internal override void Update(Fusion.GameTime gameTime)
 {
     if (!pathList.Contains(Cell))
     {
         pathList.Add(Cell);
     }
 }
Пример #4
0
        public override void Draw(GameTime gameTime)
        {
            var rs	= Game.GraphicsDevice;
            var cam = Game.GetService<Camera>();
            var ls	= Game.GetService<LayerService>();

            constBuffer.Data.ViewProj		= cam.ViewMatrix*cam.ProjMatrix;
            constBuffer.Data.Zoom			= new Vector4(ls.MapLayer.Zoom);
            constBuffer.Data.Offset			= new Vector4(ls.MapLayer.Offset, 0.0f, 0.0f);
            constBuffer.Data.ViewPosition	= new Vector4(cam.CameraMatrix.TranslationVector, 0.0f);
            constBuffer.UpdateCBuffer();

            string signature;
            drawShader.SetVertexShader((int)BuildingsFlags.BUILDINGS_DRAW, out signature);

            drawShader.SetGeometryShader(	(int)BuildingsFlags.BUILDINGS_DRAW);
            drawShader.SetPixelShader(		(int)BuildingsFlags.BUILDINGS_DRAW);
            constBuffer.SetCBufferVS(0);
            constBuffer.SetCBufferGS(0);
            constBuffer.SetCBufferPS(0);

            rs.SetupVertexInput(vertexBuffer, null, signature);

            rs.SetBlendState(BlendState.Opaque);
            rs.SetDepthStencilState(DepthStencilState.Default);
            rs.SetRasterizerState(RasterizerState.CullCCW);

            rs.Draw(Primitive.PointList, vertexBuffer.Capacity, 0);
        }
Пример #5
0
 public override void Draw(GameTime gameTime, StereoEye stereoEye)
 {
     SpriteBatch sb = Game.GetService<SpriteBatch>();
     sb.Begin();
     gameCollection.Draw(sb, Game.GetService<DebugStrings>(), stereoEye);
     sb.End();
     base.Draw(gameTime, stereoEye);
 }
Пример #6
0
 public Boom(Cell cell, GameTime gameTime, EntityCollection parent)
 {
     Texture = LogicService.boom;
     this.Cell = cell;
     startedTime = gameTime.Total.TotalSeconds;
     this.parent = parent;
     Order = 6;
 }
Пример #7
0
 public override bool execute(GameTime gameTime)
 {
     ActionsQueue.GameCollection.addToCollection(new Boom(Entity.Cell, gameTime, ActionsQueue.GameCollection));
     if (Entity is Torpedo)
         ActionsQueue.Field.addNewNoise(Entity.Cell, ((Torpedo)Entity).Noise);
     if (Entity is Mine)
         ActionsQueue.Field.addNewNoise(Entity.Cell, ((Mine)Entity).Noise);
     ActionsQueue.GameCollection.Remove(Entity);
     return true;
 }
Пример #8
0
 public override bool execute(GameTime gameTime)
 {
     Submarine sub = Entity as Submarine;
     if ((sub.Cell.Type == CellType.SHALLOW) && (sub.placeMine()))
     {
         sub.Team.placedMines++;
         Mine mine = new Mine(sub);
         sub.Parent.addToCollection(mine);
         ActivateMine act = new ActivateMine(mine, ActionsQueue);
         act.setSubs(((EntityCollection)sub.Team.Parent).getSubmarines());
         ActionsQueue.addAction(act);
     }
     return true;
 }
Пример #9
0
 public override bool execute(GameTime gameTime)
 {
     if (Entity != null)
     {
         Mine mine = Entity as Mine;
         mine.activate();
         foreach (Submarine sub in submarines)
             if (mine.Cell == sub.Cell)
             {
                 ActionsQueue.addAction(new Bang(mine, ActionsQueue));
                 ActionsQueue.addAction(new MineDamage(sub, ActionsQueue));
             }
     }
     return true;
 }
Пример #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update( GameTime gameTime )
        {
            var ds = GetService<DebugStrings>();

            var dr = GetService<DebugRender>();
            var cam = GetService<Camera>();

            dr.View			=	cam.GetViewMatrix( StereoEye.Mono );
            dr.Projection	=	cam.GetProjectionMatrix( StereoEye.Mono );;
            dr.DrawGrid(20);
            dr.DrawRing( Vector3.Zero, 15, Color.Orange, 64 );

            angle	+= 0.1f;

            if (emitter!=null) {
                emitter.DopplerScale	=	1;
                emitter.Position		=	GetPosition(angle);
                emitter.Velocity		=	(GetPosition(angle) - GetPosition(angle-0.1f)) * (1/gameTime.ElapsedSec);
                emitter.DistanceScale	=	2;
                //emitter.VolumeCurve		=	Enumerable.Range(0, 11).Select( i => new CurvePoint{ Distance = i, DspSetting = (float)Math.Pow((10-i)/10.0f,2) } ).ToArray();
                dr.DrawPoint( GetPosition(angle), 0.5f, Color.Yellow );
                dr.DrawRing( GetPosition(angle), 10, Color.Orange, 64 );
            }

            //AudioDevice.SetupListener( cam.GetCameraMatrix( stereoEye ).TranslationVector, cam.GetCameraMatrix( stereoEye ).Forward, cam.GetCameraMatrix( stereoEye ).Up, cam.FreeCameraVelocity );*/
            listener	=	cam.Listener;

            if (soundInstance!=null) {
                soundInstance.Apply3D( listener, emitter );
            }

            base.Update(gameTime);

            ds.Add( Color.Orange, "FPS {0}", gameTime.Fps );
            ds.Add( "F1   - show developer console" );
            ds.Add( "F2   - toggle vsync" );
            ds.Add( "F5   - build content and reload textures" );
            ds.Add( "F12  - make screenshot" );
            ds.Add( "ESC  - exit" );
            ds.Add("");

            ds.Add("B - break glass");
            ds.Add("P - play 3D sound");
            ds.Add("O - pause/unpause 3D sound");
            ds.Add("I - stop");
            ds.Add("U - immediate stop");
            ds.Add(Color.Orange, "See Camera config for controls");
        }
Пример #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            var sb		=	GetService<SpriteBatch>();
            var tp		=	GetService<TexturePump>();
            var w		=	GraphicsDevice.DisplayBounds.Width;
            var h		=	GraphicsDevice.DisplayBounds.Height;

            int imgWidth	= 128;
            int imgHeight	= 128;

            int cols	=	w / imgWidth;
            int rows	=	h / imgHeight;

            offset		=	Math.Max( 0, offset );
            offset		=	Math.Min( offset, cols * imgWidth );

            sb.Begin();

                for (int i = 0; i < images.Length; i++) {

                    int x = ( i / rows ) * imgWidth - offset * 10;
                    int y = ( i % rows ) * imgHeight;

                    if (x<-128 || x>w) {
                        continue;
                    }

                    Texture2D	tex;
                    var status	=	tp.Load(images[i], out tex);

                    if (status == TexturePumpStatus.Loading) {
                        sb.Draw( texLoading, x, y, imgWidth, imgHeight, Color.Blue );
                    }
                    if (status == TexturePumpStatus.Failed) {
                        sb.Draw( texFailed, x, y, imgWidth, imgHeight, Color.Red );
                    }
                    if (status == TexturePumpStatus.Ready) {
                        sb.Draw( tex, x+2, y+2, imgWidth-4, imgHeight-4, Color.White );
                    }
                }

            sb.End();

            base.Draw( gameTime, stereoEye );
        }
Пример #12
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		public override void Update ( GameTime gameTime )
		{
			if (Config.ShowStatistics) {

				var ds = Game.GetService<DebugStrings>();

				ds.Add("Texture pump statistics:");
				ds.Add("Textures ready     - " + items.Count(x => x.Value.Status == TexturePumpStatus.Ready));
				ds.Add("Textures loading   - " + items.Count(x => x.Value.Status == TexturePumpStatus.Loading));
				ds.Add("Textures failed    - " + items.Count(x => x.Value.Status == TexturePumpStatus.Failed));
				ds.Add("Size in memory, mb - " + SizeInMb);
			}


			if (SizeInMb > Config.MemoryCacheSize) {
				RemoveOldTextures();
			}
		}
Пример #13
0
        /// <summary>
        /// Draw stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            //	Clear back buffer :
            GraphicsDevice.ClearBackbuffer( new Color4(0,0,0,0) );

            //	Fill vertex buffer :
            var v0	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v1	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };
            var v2	=	new Vertex{ Position = new Vector3( -1.0f,  1.0f, 0 ), Color = Color.Blue,  TexCoord = new Vector2(0,0) };
            var v3	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v4	=	new Vertex{ Position = new Vector3(  1.0f, -1.0f, 0 ), Color = Color.Lime,  TexCoord = new Vector2(1,1) };
            var v5	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };//*/

            var data = new Vertex[]{ v0, v1, v2, v3, v4, v5 };

            vertexBuffer.SetData( data, 0, 6 );

            var tex = texture;

            UberFlags flags = UberFlags.NONE;
            if (InputDevice.IsKeyDown(Keys.D1) ) flags |= UberFlags.USE_TEXTURE;
            if (InputDevice.IsKeyDown(Keys.D2) ) flags |= UberFlags.USE_VERTEX_COLOR;
            if (InputDevice.IsKeyDown(Keys.D3) ) tex = textureSRgb;

            //	Update constant buffer and bound it to pipeline:
            cbData.Transform	=	Matrix.OrthoRH( 4, 3, -2, 2 );
            constBuffer.SetData(cbData);

            GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            GraphicsDevice.PixelShaderConstants[0]	= constBuffer;

            //	Setup device state :
            GraphicsDevice.PipelineState			= factory[ (int)flags ];
            GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap ;

            //	Setup texture :
            GraphicsDevice.PixelShaderResources[0]	= tex ;

            //	Setup vertex data and draw :
            GraphicsDevice.SetupVertexInput( vertexBuffer, null );
            GraphicsDevice.Draw( 6, 0 );

            base.Draw( gameTime, stereoEye );
        }
Пример #14
0
        public override void Update(GameTime gameTime)
        {
            if (!pause)
            {
                if (IsFirst)
                {
                    gameCollection = (EntityCollection)rm.ReadInitPos(Game.GetService<GameFieldService>().GameField).Copy(null);
                    stepList = rm.ReadGame(Game.GetService<GameFieldService>().GameField);
                    gameCollection = (EntityCollection)stepList.Find(x => x.stepNumb == k).collection.Copy(null);
                    queue = new ActionsQueue(gameCollection, Game.GetService<GameFieldService>().GameField);

                    IsFirst = false;
                }
                else
                {
                    gameCollection.Update(gameTime);
                    if (queue.Size == 0)
                    {
                        if (k <= stepList.Count)
                        {
                            gameCollection.GlobalUpdate();
                            ReplayStep step = stepList.Find(x => x.stepNumb == k);
                            k++;
                            if (step.action != null)
                                step.action.action.execute(gameCollection.getSubmarines().Find(x => x.Number == step.action.subNumb), queue);
                        }
                    }
                    else
                    {
                        queue.nextAction(gameTime);
                        if (queue.Size == 0)
                        {
                            Game.GetService<GameFieldService>().GameField.coolNoise();
                            Game.GetService<GameFieldService>().GameField.calculateNoise();
                        }
                    }

                }
            }
            base.Update(gameTime);
        }
Пример #15
0
        public override bool execute(GameTime gameTime)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            if (!checkPath())
                return true;

            List<Action> actionList = new List<Action>();
            for (int i = 0; i < path.Count - 1; i++)
                if (!new Check(Entity, ActionsQueue, Noise, path[i+1], path[i], _speed).CheckState(ref actionList))
                    break;

            for (int i = 0; i < actionList.Count; i++)
                ActionsQueue.addAction(actionList[i], i + 1);
            if (Entity is Torpedo)
                ActionsQueue.addAction(new Bang(Entity, ActionsQueue));

            timer.Stop();
            //Console.WriteLine("ParsePath. FrameID: " + gameTime.FrameID + ". Time: " + timer.Elapsed);
            return true;
        }
Пример #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update( GameTime gameTime )
        {
            var ds	=	GetService<DebugStrings>();

            ds.Add( Color.Orange, "FPS {0}", gameTime.Fps );
            ds.Add( "F1   - show developer console" );
            ds.Add( "F2   - toggle vsync" );
            ds.Add( "F5   - build content and reload textures" );
            ds.Add( "F12  - make screenshot" );
            ds.Add( "ESC  - exit" );

            var ps = GetService<ParticleSystemGS>();

            var vp = GraphicsDevice.DisplayBounds;

            Vector2 target = InputDevice.MousePosition;
            var vel = (lastPoint - target);

            if (InputDevice.IsKeyDown(Keys.LeftButton)) {

                float len = (lastPoint - target).Length() + 0.001f;

                for ( float t=0; t<=len; t+=0.15f) {
                    ps.AddParticle( Vector2.Lerp( lastPoint, target, t/len ), Vector2.Lerp( lastVel,vel,t/len) * Gauss(10,1), Gauss(5,3), 3, Gauss(50,50), 0.2f );
                }
            }

            if (InputDevice.IsKeyDown(Keys.Space)) {
                for (int i=0; i<100; i++) {
                    ps.AddParticle( rand.NextVector2( Vector2.Zero, new Vector2(vp.Width, vp.Height) ), Vector2.Zero, Gauss(10,3), Gauss(40,30),Gauss(40,30), 0.1f );
                }
            }

            lastPoint = InputDevice.MousePosition;
            lastVel = vel;

            base.Update( gameTime );
        }
Пример #17
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            base.Draw(gameTime, stereoEye);

            //		time += gameTime.Elapsed.Milliseconds;

            var cam = GetService<GreatCircleCamera>();
            var dr = GetService<DebugRender>();
            var pSys = GetService<GraphSystem>();
            dr.View = cam.GetViewMatrix(stereoEye);
            dr.Projection = cam.GetProjectionMatrix(stereoEye);

            //		dr.DrawGrid(20);
            var ds = GetService<DebugStrings>();
            if (isSelected)
            {
                ds.Add(Color.Orange, "Selected node # " + selectedNodeIndex);
                pSys.Select(selectedNodeIndex);
            }
            else
            {
                //ds.Add(Color.Orange, "No selection");
                pSys.Deselect();
            }
            DrawNames();
        }
Пример #18
0
        /// <summary>
        /// Updates game
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            var ds = GetService<DebugStrings>();
            var debRen = GetService<DebugRender>();

            var graphSys = GetService<GraphSystem>();

            if(InputDevice.IsKeyDown(Keys.X)) {
                Graph graph = Graph.MakeTree( 4096, 40 );
            //		Graph<BaseNode> graph = Graph<BaseNode>.MakeRing( 512 );
                graphSys.AddGraph(graph);
            }

            if(InputDevice.IsKeyDown(Keys.Z)) {
            //				StanfordNetwork graph = new StanfordNetwork();
                stNet = new StanfordNetwork();

            //			stNet.ReadFromFile("../../../../p2p_networks/p2p-Gnutella25.txt");

                //stNet.ReadFromFile("../../../../medicine/edgeList.txt");
                stNet.ReadFromFile("../../../../medicine/edge.txt");
                //stNet.ReadFromFile("D:/Graphs/collab_networks/CA-GrQc.txt");
            //			stNet.ReadFromFile("../../../../collab_networks/CA-HepTh.txt");
            //			stNet.ReadFromFile("../../../../collab_networks/CA-CondMat.txt");

            //			stNet.ReadFromFile("../../../../cit_networks/Cit-HepTh.txt");

                graphSys.AddGraph(stNet);
                // graph file names:
                // CA-GrQc small
                // CA-HepTh middle
                // CA-CondMat large

                //CitationGraph graph = new CitationGraph();
                //graph.ReadFromFile("../../../../articles_data/idx_edges.txt");
                //graphSys.AddGraph(graph);
            }

            if (InputDevice.IsKeyDown(Keys.V))
            {
                var protGraph = new ProteinGraph();
                protGraph.ReadFromFile("../../../../signalling_table.csv");

                // add categories of nodes with different localization:
                // category 1 (membrane):
                graphSys.AddCategory(new List<int> { 0, 1, 2, 20 }, new Vector3(0, 0, 0), 700);

                // category 2 (cytoplasma):
                graphSys.AddCategory(new List<int> { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, new Vector3(0, 0, 0), 300);

                // category 3 (nucleus):
                graphSys.AddCategory(new List<int> { 8, 12, 13, 14, 15, 16, 17, 18, 19 }, new Vector3(0, 0, 0), 100);

                graphSys.AddGraph(protGraph);

            }

            //ds.Add(Color.Orange, "FPS {0}", gameTime.Fps);
            //ds.Add(Color.Orange, "F1   - show developer console");
            //ds.Add(Color.Orange, "F5   - build content and reload textures");
            //ds.Add(Color.Orange, "F12  - make screenshot");
            //ds.Add(Color.Orange, "ESC  - exit");
            //ds.Add(Color.Orange, "Press Z or X to load graph");
            //ds.Add(Color.Orange, "Press M to load painted graph (SLOW!)");
            //ds.Add(Color.Orange, "Press P to pause/unpause");
            //			ds.Add(Color.Orange, "Press I to switch to manual mode");

            base.Update(gameTime);
        }
Пример #19
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw ( GameTime gameTime, Fusion.Graphics.StereoEye stereoEye )
		{
			base.Draw(gameTime, stereoEye);
		}
Пример #20
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw ( GameTime gameTime, StereoEye stereoEye )
		{
			base.Draw( gameTime, stereoEye );
		}
Пример #21
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		protected override void Update ( GameTime gameTime )
		{
			var ds	=	GetService<DebugStrings>();

			ds.Add( Color.Orange, "FPS {0}", gameTime.Fps );
			ds.Add( "F1   - show developer console" );
			ds.Add( "F5   - build content and reload textures" );
			ds.Add( "F12  - make screenshot" );
			ds.Add( "ESC  - exit" );

			base.Update( gameTime );


		    //	First sort the rows for the levels <= to the block size
			for( uint level=2; level<=BitonicBlockSize; level = level * 2 ) {

				SetConstants( level, level, MatrixWidth, MatrixHeight );

				// Sort the row data
				GraphicsDevice.SetCSRWBuffer( 0, buffer1 );
				GraphicsDevice.PipelineState	=	factory[ (int)ShaderFlags.BITONIC_SORT ];
				GraphicsDevice.Dispatch( NumberOfElements / BitonicBlockSize, 1, 1 );
			}


			for( uint level = (BitonicBlockSize * 2); level <= NumberOfElements; level = level * 2 ){

				SetConstants( (level / BitonicBlockSize), (uint)(level & ~NumberOfElements) / BitonicBlockSize, MatrixWidth, MatrixHeight );

				// Transpose the data from buffer 1 into buffer 2
				GraphicsDevice.ComputeShaderResources[0]	=	null;
				GraphicsDevice.SetCSRWBuffer( 0, buffer2 );
				GraphicsDevice.ComputeShaderResources[0]	=	buffer1;
				GraphicsDevice.PipelineState				=	factory[ (int)ShaderFlags.TRANSPOSE ];
				GraphicsDevice.Dispatch( MatrixWidth / TransposeBlockSize, MatrixHeight / TransposeBlockSize, 1 );

				// Sort the transposed column data
				GraphicsDevice.PipelineState	=	factory[ (int)ShaderFlags.BITONIC_SORT ];
				GraphicsDevice.Dispatch( NumberOfElements / BitonicBlockSize, 1, 1 );


				SetConstants( BitonicBlockSize, level, MatrixWidth, MatrixHeight );

				// Transpose the data from buffer 2 back into buffer 1
				GraphicsDevice.ComputeShaderResources[0]	=	null;
				GraphicsDevice.SetCSRWBuffer( 0, buffer1 );
				GraphicsDevice.ComputeShaderResources[0]	=	buffer2;
				GraphicsDevice.PipelineState				=	factory[ (int)ShaderFlags.TRANSPOSE ];
				GraphicsDevice.Dispatch( MatrixHeight / TransposeBlockSize, MatrixHeight / TransposeBlockSize, 1 );

				// Sort the row data
				GraphicsDevice.PipelineState	=	factory[ (int)ShaderFlags.BITONIC_SORT ];
				GraphicsDevice.Dispatch( NumberOfElements / BitonicBlockSize, 1, 1 );
			}



			//
			//	Check results 
			//
			if (InputDevice.IsKeyDown(Keys.S)) {

				var output = new Vector2[NumberOfElements];

				buffer1.GetData( output );
	
				Log.Message("--------------------");

				for (int i=0; i<NumberOfElements; i++) {
					
					bool error = (i < NumberOfElements-1) ? output[i].X>output[i+1].X : false;
					//bool error = (i < BufferSize-1) ? output[i&0xFFFFFFFE]>output[i&0xFFFFFFFE+1] : false;

					//if (error) {
						Log.Message("{0,4} : {1,6:0.00} - {2,6:0.00} {3}", i, output[i].X, output[i].Y, error?"<- Error":"" );
					//}
				}
			}
		}
Пример #22
0
        /// <summary>
        /// Draw stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            //	Clear back buffer :
            GraphicsDevice.ClearBackbuffer( new Color4(0,0,0,1) );

            //	Update constant buffer and bound it to pipeline:
            cbData.Transform	=	Matrix.OrthoRH( 4, 3, -2, 2 );
            cbData.Time = 0.001f * (float)gameTime.Total.TotalMilliseconds;
            cb.SetData( cbData );

            GraphicsDevice.VertexShaderConstants[0]	= cb ;
            GraphicsDevice.PixelShaderConstants[0]	= cb ;

            //	Fill vertex buffer :
            var v0	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v1	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };
            var v2	=	new Vertex{ Position = new Vector3( -1.0f,  1.0f, 0 ), Color = Color.Blue,  TexCoord = new Vector2(0,0) };
            var v3	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v4	=	new Vertex{ Position = new Vector3(  1.0f, -1.0f, 0 ), Color = Color.Lime,  TexCoord = new Vector2(1,1) };
            var v5	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };//*/

            var data = new Vertex[]{ v0, v1, v2, v3, v4, v5 };

            vb.SetData( data, 0, 6 );

            //	Set required ubershader :

            //	Set device states :
            GraphicsDevice.PipelineState		= factory[0];
            GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap ;

            //	Setup texture :
            GraphicsDevice.PixelShaderResources[0]	= tex ;
            GraphicsDevice.VertexShaderResources[1]	= instDataGpu ;

            //	Setup vertex data and draw :
            GraphicsDevice.SetupVertexInput( vb, null );

            GraphicsDevice.DrawInstanced( 6, InstanceCount, 0, 0 );

            base.Draw( gameTime, stereoEye );
        }
Пример #23
0
        /// <summary>
        /// Update stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update( GameTime gameTime )
        {
            var ds = GetService<DebugStrings>();

            ds.Add( Color.Orange, "FPS {0}", gameTime.Fps );
            ds.Add( "F1   - show developer console" );
            ds.Add( "F2   - toggle vsync" );
            ds.Add( "F5   - build content and reload textures" );
            ds.Add( "F12  - make screenshot" );
            ds.Add( "ESC  - exit" );
            ds.Add("");

            base.Update( gameTime );

            var rand = new Random();
            for (int i=0; i<InstanceCount; i++) {
                instDataCpu[ i ].Scale		=	0.2f * (0.5f + 0.4f*(float)Math.Cos( 0.17*i + gameTime.Total.TotalSeconds * 2 ));
                instDataCpu[ i ].Rotation	+= (MathUtil.IsOdd(i) ? 0.01f : -0.01f);
                instDataCpu[ i ].Offset.Y	+= (MathUtil.IsOdd(i) ? 0.001f : -0.001f);

                if (instDataCpu[ i ].Offset.Y > 2) {
                    instDataCpu[ i ].Offset.Y = -2;
                }
                if (instDataCpu[ i ].Offset.Y < -2) {
                    instDataCpu[ i ].Offset.Y = 2;
                }
                /*float c = (1 - (instDataCpu[ i ].Offset.Y + 2)/4);
                c *= c * 0.5f;
                instDataCpu[ i ].Color = new Vector4(c,c,c,c);*/
            }

            instDataGpu.SetData( instDataCpu );
        }
Пример #24
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw (GameTime gameTime, StereoEye stereoEye)
		{
			CBData cbData = new CBData();

			var cam = GetService<Camera>();

			GraphicsDevice.ClearBackbuffer(Color.CornflowerBlue, 1, 0);


			foreach ( var e in space.Entities ) {
				Box box = e as Box;
				if ( box != null ) // this won't create any graphics for an entity that isn't a box
				{
					if ( box.IsDynamic ) // draw only dynamic boxes
					{
						// fill world matrix
						Fusion.Mathematics.Matrix matrix = new Fusion.Mathematics.Matrix(box.WorldTransform.M11, box.WorldTransform.M12, box.WorldTransform.M13, box.WorldTransform.M14,
																									box.WorldTransform.M21, box.WorldTransform.M22, box.WorldTransform.M23, box.WorldTransform.M24,
																									box.WorldTransform.M31, box.WorldTransform.M32, box.WorldTransform.M33, box.WorldTransform.M34,
																									box.WorldTransform.M41, box.WorldTransform.M42, box.WorldTransform.M43, box.WorldTransform.M44);
						cbData.Projection = cam.GetProjectionMatrix(stereoEye);
						cbData.View = cam.GetViewMatrix(stereoEye);
						cbData.World = matrix;
						cbData.ViewPos = new Vector4Fusion(cam.GetCameraMatrix(stereoEye).TranslationVector, 1);
						Color c = (Color) box.Tag;
						cbData.Color =  c.ToVector4();

						constBuffer.SetData(cbData);
						
						GraphicsDevice.PipelineState = factory[0];

						GraphicsDevice.PixelShaderConstants[0] = constBuffer;
						GraphicsDevice.VertexShaderConstants[0] = constBuffer;
						GraphicsDevice.PixelShaderSamplers[0] = SamplerState.AnisotropicWrap;
						GraphicsDevice.PixelShaderResources[0] = texture;

						// setup data and draw box
						GraphicsDevice.SetupVertexInput(vb, ib);
						GraphicsDevice.DrawIndexed( 36, 0, 0);
					}
				}
			}

			base.Draw(gameTime, stereoEye);
		}
Пример #25
0
 public override bool execute(GameTime gameTime)
 {
     if (Entity != null)
         ActionsQueue.addAction(new ParsePath(Entity, path, ActionsQueue), 1);
     return true;
 }
Пример #26
0
        public override void Update(GameTime gameTime)
        {
            Config.FreeCamEnabled	= false;
            var ds		= Game.GetService<DebugStrings>();

            angularVelocity	= 0.25f;
            upDownVelocity	= 0.0007f * altitude;

            if ( Game.InputDevice.IsKeyDown( Keys.LeftShift ) ) {
                angularVelocity *= 3;
                upDownVelocity	*= 3;
            }

            latVelocity = angularVelocity;
            lonVelocity = angularVelocity;

            if ( Game.InputDevice.IsKeyDown( Keys.W ) ) {
                latitude += latVelocity * gameTime.Elapsed.Milliseconds;
            }
            if ( Game.InputDevice.IsKeyDown( Keys.S ) ) {
                latitude -= latVelocity * gameTime.Elapsed.Milliseconds;
            }
            if ( Game.InputDevice.IsKeyDown( Keys.A ) ) {
                longitude -= lonVelocity * gameTime.Elapsed.Milliseconds;
            }
            if ( Game.InputDevice.IsKeyDown( Keys.D ) ) {
                longitude += lonVelocity * gameTime.Elapsed.Milliseconds;
            }

            if ( Game.InputDevice.IsKeyDown( Keys.Space ) ) {
                altitude += upDownVelocity * gameTime.Elapsed.Milliseconds;
            }

            if ( Game.InputDevice.IsKeyDown( Keys.C ) ) {
                altitude -= upDownVelocity * gameTime.Elapsed.Milliseconds;
            }

            if ( altitude < 0.0f ) {
                altitude = 0.0f;
            }

            if ( latitude > 89.9f ) latitude = 89.9f;
            if ( latitude < -89.9f ) latitude = -89.9f;

            Vector3 cameraLocation = anglesToCoords(latitude, longitude, (ZeroRadius + altitude));
            base.SetupCamera( cameraLocation, CenterOfOrbit, new Vector3( 0, 1, 0), new Vector3(0, 0, 0),
                PI180*70.0f, base.Config.FreeCamZNear, base.Config.FreeCamZFar, 0, 0);

            //ds.Add( "Altitude = " + altitude + " m" );
            //ds.Add( "Longitude = " + longitude );
            //ds.Add( "Latitude = " + latitude );

            base.Update(gameTime);
        }
Пример #27
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		protected override void Update (GameTime gameTime)
		{
			var ds = GetService<DebugStrings>();

			ds.Add(Color.Orange, "FPS {0}", gameTime.Fps);
			ds.Add("F1   - show developer console");
			ds.Add("F2   - toggle vsync");
			ds.Add("F5   - build content and reload textures");
			ds.Add("F12  - make screenshot");
			ds.Add("ESC  - exit");


			var cam = GetService<Camera>();
			var dr = GetService<DebugRender>();
			dr.View = cam.GetViewMatrix(StereoEye.Mono);
			dr.Projection = cam.GetProjectionMatrix(StereoEye.Mono);

			dr.DrawGrid(10);

			// physics updates here
			if ( flag ) {
				space.Update(gameTime.ElapsedSec);
			}

			base.Update(gameTime);
		}
Пример #28
0
 public override void Update( GameTime gameTime )
 {
     Misc.Swap( ref linesAccum, ref linesDraw );
     linesAccum.Clear();
 }
Пример #29
0
 internal override void Update(GameTime gameTime)
 {
     //throw new NotImplementedException();
 }
Пример #30
0
        /// <summary>
        /// DrawGatheredStrings
        /// </summary>
        public override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            var x = 8;
            int y = 8;

            if (Config.SuppressDebugString) {
                linesAccum.Clear();
                return;
            }

            if (!linesDraw.Any()) {
                return;
            }

            var sb = Game.GetService<SpriteBatch>();

            sb.Begin();

                int w = linesDraw.Max( line => line.text.Length ) * 8 + 16;
                int h = linesDraw.Count * 8 + 16;

                maxWidth	=	Math.Max( w, maxWidth );

                sb.Draw( sb.TextureWhite, new Rectangle(0,0, maxWidth, h), Config.BackgroundColor );

                foreach ( var line in linesDraw ) {
                    //font.DrawString( rs.SpriteBatch, line.text, x, y, line.color );
                    sb.DrawDebugString( x+1, y+1, line.text, Color.Black );
                    sb.DrawDebugString( x+0, y+0, line.text, line.color );
                    y += 8;
                }

            sb.End();
        }
Пример #31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="stereoEye"></param>
 public override void Draw( GameTime gameTime, StereoEye stereoEye )
 {
 }
Пример #32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        public override void Draw( GameTime gameTime, Fusion.Graphics.StereoEye stereoEye )
        {
            var ds		=	Game.GetService<DebugStrings>();
            ds.Add("{0}", injectionCount );

            var device	=	Game.GraphicsDevice;
            device.ResetStates();

            device.SetTargets( null, device.BackbufferColor );

            int	w	=	device.DisplayBounds.Width;
            int h	=	device.DisplayBounds.Height;

            //var map	=	"SV_POSITION.xyzw;COLOR0.xyzw;COLOR1.xyzw;TEXCOORD0.xyzw;TEXCOORD1.xyzw;TEXCOORD2.xyzw";

            Params param = new Params();
            param.View			=	Matrix.Identity;
            param.Projection	=	Matrix.OrthoOffCenterRH(0, w, h, 0, -9999, 9999);
            param.MaxParticles	=	100;
            param.DeltaTime		=	gameTime.ElapsedSec;

            paramsCB.SetData( param );

            device.VertexShaderConstants[0]		= paramsCB ;
            device.GeometryShaderConstants[0]	= paramsCB ;
            device.PixelShaderConstants[0]		= paramsCB ;

            device.PixelShaderSamplers[0]		= SamplerState.LinearWrap ;

            //
            //	Simulate :
            //
            device.PipelineState	=	factory[ (int)Flags.SIMULATION ];

            device.SetupVertexInput( simulationSrcVB, null );
            device.SetupVertexOutput( simulationDstVB, 0 );

            device.DrawAuto();

            //
            //	Inject :
            //
            injectionVB.SetData( injectionBufferCPU );

            device.PipelineState	=	factory[ (int)Flags.INJECTION ];

            device.SetupVertexInput( injectionVB, null );
            device.SetupVertexOutput( simulationDstVB, -1 );

            device.Draw(injectionCount, 0 );

            SwapParticleBuffers();

            //
            //	Render
            //
            paramsCB.SetData( param );
            device.VertexShaderConstants[0]		= paramsCB ;
            device.GeometryShaderConstants[0]	= paramsCB ;
            device.PixelShaderConstants[0]		= paramsCB ;

            device.PipelineState	=	factory[ (int)Flags.RENDER ];

            device.PixelShaderResources[0]	=	texture ;

            device.SetupVertexOutput( null, 0 );
            device.SetupVertexInput( simulationSrcVB, null );

            //device.Draw( Primitive.PointList, injectionCount, 0 );

            device.DrawAuto();
            //device.Draw( Primitive.PointList, MaxSimulatedParticles, 0 );

            ClearParticleBuffer();

            base.Draw( gameTime, stereoEye );
        }