Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6KB

  1. using System.Collections.Generic;
  2. using Svelto.DataStructures;
  3. using Svelto.ECS.Internal;
  4. namespace Svelto.ECS
  5. {
  6. public class StructNodes<T>: IStructNodes where T:struct, IStructNodeWithID
  7. {
  8. public FasterList<T> list
  9. {
  10. get
  11. {
  12. return _internalList;
  13. }
  14. }
  15. public StructNodes()
  16. {
  17. _internalList = new FasterList<T>();
  18. }
  19. public void Add(T node)
  20. {
  21. T convert = (T)node;
  22. _internalList.Add(convert);
  23. }
  24. readonly FasterList<T> _internalList;
  25. }
  26. public class StructGroupNodes<T>: IStructGroupNodes
  27. where T : struct, IGroupedStructNodeWithID
  28. {
  29. public void Add(int groupID, T node)
  30. {
  31. T convert = (T)node;
  32. var fasterList = GetList(groupID);
  33. _indices[node.ID] = fasterList.Count;
  34. fasterList.Add(convert);
  35. }
  36. public void Remove(int groupID, T node)
  37. {
  38. var fasterList = GetList(groupID);
  39. var index = _indices[node.ID];
  40. _indices.Remove(node.ID);
  41. if (fasterList.UnorderedRemoveAt(index))
  42. _indices[fasterList[index].ID] = index;
  43. }
  44. public FasterList<T> GetList(int groupID)
  45. {
  46. return _nodes[groupID];
  47. }
  48. readonly Dictionary<int, int> _indices = new Dictionary<int, int>();
  49. Dictionary<int, FasterList<T>> _nodes = new Dictionary<int, FasterList<T>>();
  50. }
  51. }
  52. namespace Svelto.ECS.Internal
  53. {
  54. public interface IStructGroupNodes
  55. {
  56. }
  57. public interface IStructNodes
  58. {
  59. }
  60. }