LSUpdater.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. public class LSUpdater
  6. {
  7. private readonly SortedSet<long> updateIds = new();
  8. private readonly Dictionary<long, EntityRef<LSEntity>> lsEntities = new();
  9. private readonly Queue<long> addUpdateIds = new();
  10. private readonly Queue<long> removeUpdateIds = new();
  11. public void Update()
  12. {
  13. while (this.addUpdateIds.Count > 0)
  14. {
  15. this.updateIds.Add(this.addUpdateIds.Dequeue());
  16. }
  17. foreach (long id in this.updateIds)
  18. {
  19. LSEntity entity = lsEntities[id];
  20. if (entity == null)
  21. {
  22. this.removeUpdateIds.Enqueue(id);
  23. continue;
  24. }
  25. LSSington.Instance.LSUpdate(entity);
  26. }
  27. while (this.removeUpdateIds.Count > 0)
  28. {
  29. long id = this.removeUpdateIds.Dequeue();
  30. this.updateIds.Remove(id);
  31. this.lsEntities.Remove(id);
  32. }
  33. }
  34. public void Add(LSEntity entity)
  35. {
  36. this.addUpdateIds.Enqueue(entity.Id);
  37. this.lsEntities.Add(entity.Id, entity);
  38. }
  39. }
  40. }