LSUpdater.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. public class LSUpdater: Object
  6. {
  7. private readonly NativeCollection.SortedSet<long> updateIds = new();
  8. private readonly NativeCollection.SortedSet<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.newUpdateIds.Clear();
  19. }
  20. foreach (long id in this.updateIds)
  21. {
  22. LSEntity entity = lsEntities[id];
  23. if (entity == null)
  24. {
  25. this.lsEntities.Remove(id);
  26. continue;
  27. }
  28. LSEntitySystemSingleton.Instance.LSUpdate(entity);
  29. }
  30. }
  31. public void Add(LSEntity entity)
  32. {
  33. this.newUpdateIds.Add(entity.Id);
  34. this.lsEntities.Add(entity.Id, entity);
  35. }
  36. }
  37. }