Esempio n. 1
0
        protected override void Draw()
        {
            try
            {
                Counter.AddTick("fps");
                //Counter.AddTick("average_fps", Counter.GetAveragePerSecond("fps"));

                Matrix proj = Matrix.Identity;
                GraphicsDevice.Clear(Color.SkyBlue);

                DrawObjects();



                // SpriteBatch drawing!

                spriteBatch.Begin();

                game.Draw(spriteBatch);

                if (Debug)
                {
                    double  time           = tmrDrawElapsed.ElapsedMilliseconds;
                    Vector2 position       = new Vector2(5, 50);
                    Color   debugfontColor = Color.LightGray;
                    spriteBatch.DrawString(debugFont, "FPS: " + String.Format("{0:0}", Counter.GetAveragePerSecond("fps")), position, debugfontColor);
                    position.Y += debugFont.LineSpacing;

                    spriteBatch.DrawString(debugFont, "Physics Updates PS: " + String.Format("{0:0}", Counter.GetAveragePerSecond("pups")), position, debugfontColor); // physics Ticks Per Second
                    position.Y += debugFont.LineSpacing;

                    spriteBatch.DrawString(debugFont, "Packets PS Out: " + String.Format("{0:0.0}", Counter.GetAveragePerSecond("pps_out")), position, debugfontColor); // physics Ticks Per Second
                    position.Y += debugFont.LineSpacing;
                    spriteBatch.DrawString(debugFont, "Packets PS In: " + String.Format("{0:0.0}", Counter.GetAveragePerSecond("pps_in")), position, debugfontColor);   // physics Ticks Per Second
                    position.Y += debugFont.LineSpacing;

                    position = DebugShowVector(spriteBatch, debugFont, position, "CameraPosition", cam.TargetPosition);
                    position = DebugShowVector(spriteBatch, debugFont, position, "CameraOrientation", Matrix.CreateFromQuaternion(cam.Orientation).Forward);

                    spriteBatch.DrawString(debugFont, "Objects Drawn: " + ObjectsDrawn + "/" + gameObjects.Count, position, debugfontColor);
                    position.Y += debugFont.LineSpacing;

                    tmrDrawElapsed.Restart();
                }

                spriteBatch.End();


                // Following 3 lines are to reset changes to graphics device made by spritebatch
                GraphicsDevice.BlendState        = BlendState.Opaque;
                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap; // Described as "may not be needed"
            }
            catch (Exception e)
            {
                //System.Console.WriteLine(e.Message);
                System.Diagnostics.Debug.WriteLine(e.StackTrace);
            }
        }
Esempio n. 2
0
        public void Send(Packet packet)
        {
            Counter.AddTick("pps_out");

            if (socket == null)
            {
                return;
            }

            socket.Send(packet.Serialize());
        }
Esempio n. 3
0
        public void Send(Packet packet)
        {
            Counter.AddTick("pps_out");
            //Counter.AddTick("average_pps_out", Counter.GetAverageValue("pps_out"));

            if (socket == null)
            {
                return;
            }

            socket.Send(packet.Serialize());
        }
Esempio n. 4
0
        void tmrPhysicsUpdate_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Counter.AddTick("pups");
            //Counter.AddTick("average_pups", Counter.GetAverageValue("pups"));
            //Add our new objects
            FinalizeNewObjects();
            RemoveDeletedObjects();

            CallPreIntegrate();
            // Should use a variable timerate to keep up a steady "feel" if we bog down?
            if (PhysicsEnabled)
            {
                float step = (float)TIME_STEP * SimFactor;
                lock (PhysicsSystem)
                {
                    PhysicsSystem.CurrentPhysicsSystem.Integrate(step);
                }
            }
            CallPostIntegrate();

            lastPhysicsElapsed = tmrPhysicsElapsed.ElapsedMilliseconds;

            ResetTimer();
        }