TimeCalculator.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Diagnostics;
  3. namespace IFramework
  4. {
  5. class TimeCalculator : Unit, ITimeCalculator
  6. {
  7. private Stopwatch sw_init;
  8. private Stopwatch sw_delta;
  9. public TimeCalculator()
  10. {
  11. deltaTime = TimeSpan.Zero;
  12. sw_delta = new Stopwatch();
  13. sw_init = new Stopwatch();
  14. sw_init.Start();
  15. }
  16. public TimeSpan deltaTime { get; private set; }
  17. public TimeSpan timeSinceInit
  18. {
  19. get
  20. {
  21. if (sw_init == null) return TimeSpan.Zero;
  22. sw_init.Stop();
  23. var span = sw_init.Elapsed;
  24. sw_init.Start();
  25. return span;
  26. }
  27. }
  28. public void BeginDelta()
  29. {
  30. sw_delta.Reset();
  31. sw_delta.Start();
  32. }
  33. public void EndDelta()
  34. {
  35. sw_delta.Stop();
  36. deltaTime = sw_delta.Elapsed;
  37. }
  38. protected override void OnDispose()
  39. {
  40. }
  41. }
  42. }