ClockContainer.cs 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. namespace XGame.Framework.Time
  4. {
  5. public class ClockContainer : IClockContainer, IDisposable
  6. {
  7. private readonly List<Clock> _clockList = new List<Clock>();
  8. public IClock AddClock(long timestamp)
  9. {
  10. Clock clock = new Clock(timestamp);
  11. _clockList.Add(clock);
  12. return clock;
  13. }
  14. public void Dispose()
  15. {
  16. _clockList.Clear();
  17. }
  18. public bool RemoveClock(IClock clock)
  19. {
  20. Clock node = (Clock)clock;
  21. if (_clockList.Contains(node))
  22. {
  23. _clockList.Remove(node);
  24. return true;
  25. }
  26. return false;
  27. }
  28. public void Update(int millisecond)
  29. {
  30. for (int i = 0; i < _clockList.Count; i++)
  31. {
  32. _clockList[i].Update(millisecond);
  33. }
  34. }
  35. }
  36. }