Пример #1
0
 /// <summary>
 /// Add your game logic here.
 /// </summary>
 /// <param name="e">Contains timing information.</param>
 /// <remarks>There is no need to call the base implementation.</remarks>
 public static void OnUpdateFrame(EventArgs e)
 {
     if (renderer.TextCacheSize > 1000)            // each cached string is an allocated texture, flush the cache once in a while in your real project
     {
         renderer.FlushTextCache();
     }
 }
        /// <summary>
        /// Add your game logic here.
        /// </summary>
        /// <param name="e">Contains timing information.</param>
        /// <remarks>There is no need to call the base implementation.</remarks>
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            totalTime += (float)e.Time;
            if (ftime.Count == fps_frames)
            {
                ftime.RemoveAt(0);
            }

            ftime.Add(stopwatch.ElapsedMilliseconds - lastTime);
            lastTime = stopwatch.ElapsedMilliseconds;


            if (stopwatch.ElapsedMilliseconds > 1000)
            {
                //Debug.WriteLine (String.Format ("String Cache size: {0} Draw Calls: {1} Vertex Count: {2}", renderer.TextCacheSize, renderer.DrawCallCount, renderer.VertexCount));
                test.Note = string.Format("String Cache size: {0} Draw Calls: {1} Vertex Count: {2}", renderer.TextCacheSize, renderer.DrawCallCount, renderer.VertexCount);
                test.Fps  = 1000f * ftime.Count / ftime.Sum();

                float ft = 1000 * (float)e.Time;

                stopwatch.Restart();

                if (renderer.TextCacheSize > 1000) // each cached string is an allocated texture, flush the cache once in a while in your real project
                {
                    renderer.FlushTextCache();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Add your game logic here.
        /// </summary>
        /// <param name="e">Contains timing information.</param>
        /// <remarks>There is no need to call the base implementation.</remarks>
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (ftime.Count == fps_frames)
            {
                ftime.RemoveAt(0);
            }

            ftime.Add(stopwatch.ElapsedMilliseconds - lastTime);
            lastTime = stopwatch.ElapsedMilliseconds;

            if (stopwatch.ElapsedMilliseconds > 1000)
            {
                stopwatch.Restart();

                if (renderer.TextCacheSize > 1000) // each cached string is an allocated texture, flush the cache once in a while in your real project
                {
                    renderer.FlushTextCache();
                }
            }
        }
Пример #4
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 10f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();
            if (crowd != null)
            {
                crowd.Update((float)e.Time);
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }
Пример #5
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 5f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();

            if (hasGenerated && displayMode == DisplayMode.Crowd)
            {
                crowd.Update((float)e.Time);

                //Iterate through each crowd agent

                /*for (int j = 0; j < numActiveAgents; j++)
                 * {
                 *      Crowd.CrowdAgent ag = crowd.GetAgent(j);
                 *      if (!ag.Active)
                 *              continue;
                 *
                 *      //update agent movement trail
                 *      trails[j].HTrail = (trails[j].HTrail + 1) % AGENT_MAX_TRAIL;
                 *      trails[j].Trail[trails[j].HTrail] = ag.NPos;
                 * }*/
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }