Time.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. namespace BansheeEngine
  7. {
  8. /// <summary>
  9. /// Manages all time related functionality.
  10. /// </summary>
  11. public static class Time
  12. {
  13. /// <summary>
  14. /// Gets the time elapsed since application start, in seconds. Only gets updated once per frame and keeps ticking
  15. /// even if the game is not running.
  16. /// </summary>
  17. public static float RealElapsed
  18. {
  19. get { return Internal_GetRealElapsed(); }
  20. }
  21. /// <summary>
  22. /// Gets the time elapsed since game start, in seconds. This value gets reset any time the game is started, and
  23. /// will not be updated while the game is paused.
  24. /// </summary>
  25. public static float Elapsed
  26. {
  27. get { return Internal_GetElapsed(); }
  28. }
  29. /// <summary>
  30. /// Gets the time since last frame was executed, in seconds. Only gets updated once per frame.
  31. /// </summary>
  32. public static float FrameDelta
  33. {
  34. get { return Internal_GetFrameDelta(); }
  35. }
  36. /// <summary>
  37. /// Returns the sequential index of the current frame. First frame is 0.
  38. /// </summary>
  39. public static UInt64 FrameIdx
  40. {
  41. get { return Internal_GetFrameNumber(); }
  42. }
  43. /// <summary>
  44. /// Returns the precise time since application start, in microseconds. Unlike other time methods this is
  45. /// not only updated every frame, but will return exact time at the moment it is called.
  46. /// </summary>
  47. public static UInt64 Precise
  48. {
  49. get { return Internal_GetPrecise(); }
  50. }
  51. /// <summary>
  52. /// Multiply to convert microseconds to seconds.
  53. /// </summary>
  54. public const float MicroToSecond = 1.0f/1000000.0f;
  55. /// <summary>
  56. /// Multiply to convert seconds to microseconds.
  57. /// </summary>
  58. public const float SecondToMicro = 1000000.0f;
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern float Internal_GetRealElapsed();
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern float Internal_GetElapsed();
  63. [MethodImpl(MethodImplOptions.InternalCall)]
  64. private static extern float Internal_GetFrameDelta();
  65. [MethodImpl(MethodImplOptions.InternalCall)]
  66. private static extern UInt64 Internal_GetFrameNumber();
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern UInt64 Internal_GetPrecise();
  69. }
  70. }