|
- using System;
- using Svelto.DataStructures;
- using Svelto.ECS;
- using Svelto.ECS.Hybrid;
- using Svelto.ECS.Internal;
-
- namespace TechbloxModdingAPI.Utility
- {
- public readonly ref struct RefCollection<T> where T : struct, IBaseEntityComponent
- {
- private readonly bool managed;
- private readonly int count;
- private readonly NB<T> nativeArray;
- private readonly MB<T> managedArray;
- private readonly NativeEntityIDs nativeIDs;
- private readonly ManagedEntityIDs managedIDs;
- private readonly ExclusiveGroupStruct group;
-
- public RefCollection(int count, MB<T> managedArray, ManagedEntityIDs managedIDs, ExclusiveGroupStruct group)
- {
- this.count = count;
- this.managedArray = managedArray;
- this.managedIDs = managedIDs;
- this.group = group;
- managed = true;
- nativeArray = default;
- nativeIDs = default;
- }
-
- public RefCollection(int count, NB<T> nativeArray, NativeEntityIDs nativeIDs, ExclusiveGroupStruct group)
- {
- this.count = count;
- this.nativeArray = nativeArray;
- this.nativeIDs = nativeIDs;
- this.group = group;
- managed = false;
- }
-
- public Enumerator GetEnumerator() => new(this);
-
- public ref struct Enumerator
- {
- private RefCollection<T> coll;
- private int index;
-
- public Enumerator(RefCollection<T> collection)
- {
- index = -1;
- coll = collection;
- }
-
- public OptionalRef<T> Current
- {
- get
- {
- if (coll.count <= index && index >= 0) return default;
- if (coll.managed)
- return new OptionalRef<T>(coll.managedArray, (uint)index,
- new EGID(coll.managedIDs[index], coll.group));
- return new OptionalRef<T>(coll.nativeArray, (uint)index,
- new EGID(coll.nativeIDs[index], coll.group));
- }
- }
-
- public bool MoveNext()
- {
- return ++index < coll.count;
- }
- }
- }
- }
|