Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Wrak.Objects;
- using System.Diagnostics;
- namespace Wrak
- {
- class World
- {
- static List<GameObject> gameObjects = new List<GameObject>();
- static System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
- static float avgTime;
- static Stopwatch gameTimer;
- static public void Initialize()
- {
- gameTimer = new Stopwatch();
- gameTimer.Start();
- }
- static public float GetTime()
- {
- return (float)gameTimer.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;
- }
- static public void Add(GameObject go)
- {
- gameObjects.Add(go);
- }
- static public void Draw()
- {
- Camera.Draw();
- Stopwatch drawTimer = new Stopwatch();
- drawTimer.Start();
- foreach (IDrawable go in gameObjects)
- {
- go.Draw();
- }
- drawTimer.Stop();
- float dt = 1000 * (float)timer.ElapsedTicks / Stopwatch.Frequency;
- avgTime = 0.95F * avgTime + 0.05F * dt;
- Console.WriteLine("World draw:" + avgTime.ToString("F3") + "ms");
- }
- static public void Run()
- {
- float dt; //delta time
- timer.Stop();
- dt = (float) timer.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;
- timer.Reset();
- timer.Start();
- Camera.Run(dt);
- foreach (GameObject go in gameObjects)
- {
- IRunable ir = go as IRunable;
- if (ir!=null)
- ir.Run(dt);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement