Time.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.
  15. /// </summary>
  16. public static float Elapsed
  17. {
  18. get { return Internal_GetElapsed(); }
  19. }
  20. /// <summary>
  21. /// Gets the time since last frame was executed, in seconds. Only gets updated once per frame.
  22. /// </summary>
  23. public static float FrameDelta
  24. {
  25. get { return Internal_GetFrameDelta(); }
  26. }
  27. /// <summary>
  28. /// Returns the sequential index of the current frame. First frame is 0.
  29. /// </summary>
  30. public static UInt64 FrameIdx
  31. {
  32. get { return Internal_GetFrameNumber(); }
  33. }
  34. /// <summary>
  35. /// Returns the precise time since application start, in microseconds. Unlike other time methods this is
  36. /// not only updated every frame, but will return exact time at the moment it is called.
  37. /// </summary>
  38. public static UInt64 Precise
  39. {
  40. get { return Internal_GetPrecise(); }
  41. }
  42. /// <summary>
  43. /// Multiply to convert microseconds to seconds.
  44. /// </summary>
  45. public const float MicroToSecond = 1.0f/1000000.0f;
  46. /// <summary>
  47. /// Multiply to convert seconds to microseconds.
  48. /// </summary>
  49. public const float SecondToMicro = 1000000.0f;
  50. [MethodImpl(MethodImplOptions.InternalCall)]
  51. private static extern float Internal_GetElapsed();
  52. [MethodImpl(MethodImplOptions.InternalCall)]
  53. private static extern float Internal_GetFrameDelta();
  54. [MethodImpl(MethodImplOptions.InternalCall)]
  55. private static extern UInt64 Internal_GetFrameNumber();
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern UInt64 Internal_GetPrecise();
  58. }
  59. }