Time.cs 2.9 KB

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