LSUpdater.cs 1.2 KB

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