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.

77 lines
1.7KB

  1. using System;
  2. using Svelto.DataStructures;
  3. using Svelto.ECS.Internal;
  4. namespace Svelto.ECS
  5. {
  6. public interface INodeBuilder
  7. {
  8. INode BuildAndAddToList(ref ITypeSafeList list, int entityID);
  9. Type GetNodeType();
  10. FillNodeMode reflects { get; }
  11. }
  12. public class NodeBuilder<NodeType> : INodeBuilder where NodeType : NodeWithID, new()
  13. {
  14. public INode BuildAndAddToList(ref ITypeSafeList list, int entityID)
  15. {
  16. if (list == null)
  17. list = new TypeSafeFasterList<NodeType>();
  18. var castedList = list as FasterList<NodeType>;
  19. var node = NodeWithID.BuildNode<NodeType>(entityID);
  20. castedList.Add(node);
  21. return node;
  22. }
  23. public FillNodeMode reflects
  24. {
  25. get { return FillNodeMode.Strict; }
  26. }
  27. public Type GetNodeType()
  28. {
  29. return typeof(NodeType);
  30. }
  31. }
  32. public class StructNodeBuilder<NodeType> : INodeBuilder where NodeType : struct, IStructNodeWithID
  33. {
  34. public INode BuildAndAddToList(ref ITypeSafeList list, int entityID)
  35. {
  36. var node = default(NodeType);
  37. node.ID = entityID;
  38. if (list == null)
  39. list = new TypeSafeFasterList<NodeType>();
  40. var castedList = list as FasterList<NodeType>;
  41. castedList.Add(node);
  42. return null;
  43. }
  44. public Type GetNodeType()
  45. {
  46. return typeof(NodeType);
  47. }
  48. public virtual FillNodeMode reflects
  49. {
  50. get { return FillNodeMode.None; }
  51. }
  52. }
  53. public enum FillNodeMode
  54. {
  55. Strict,
  56. None
  57. }
  58. }