Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Wrak.Objects;
  5. using System.Diagnostics;
  6.  
  7. namespace Wrak
  8. {
  9. class World
  10. {
  11. static List<GameObject> gameObjects = new List<GameObject>();
  12.  
  13. static System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
  14.  
  15. static float avgTime;
  16. static Stopwatch gameTimer;
  17.  
  18.  
  19. static public void Initialize()
  20. {
  21. gameTimer = new Stopwatch();
  22. gameTimer.Start();
  23. }
  24.  
  25. static public float GetTime()
  26. {
  27. return (float)gameTimer.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;
  28. }
  29.  
  30. static public void Add(GameObject go)
  31. {
  32. gameObjects.Add(go);
  33. }
  34.  
  35. static public void Draw()
  36. {
  37. Camera.Draw();
  38.  
  39. Stopwatch drawTimer = new Stopwatch();
  40. drawTimer.Start();
  41. foreach (IDrawable go in gameObjects)
  42. {
  43. go.Draw();
  44. }
  45. drawTimer.Stop();
  46. float dt = 1000 * (float)timer.ElapsedTicks / Stopwatch.Frequency;
  47.  
  48. avgTime = 0.95F * avgTime + 0.05F * dt;
  49.  
  50. Console.WriteLine("World draw:" + avgTime.ToString("F3") + "ms");
  51. }
  52.  
  53.  
  54. static public void Run()
  55. {
  56.  
  57. float dt; //delta time
  58. timer.Stop();
  59. dt = (float) timer.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;
  60. timer.Reset();
  61. timer.Start();
  62.  
  63.  
  64. Camera.Run(dt);
  65.  
  66. foreach (GameObject go in gameObjects)
  67. {
  68. IRunable ir = go as IRunable;
  69. if (ir!=null)
  70. ir.Run(dt);
  71. }
  72. }
  73.  
  74.  
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement