88using Collections . Pooled ;
99using CommunityToolkit . HighPerformance ;
1010using Array = System . Array ;
11+ using System . Runtime . InteropServices ;
1112
1213namespace Arch . Core ;
1314
@@ -44,7 +45,6 @@ public Slot(int index, int chunkIndex)
4445 /// <param name="first">The first <see cref="Slot"/>.</param>
4546 /// <param name="second">The second <see cref="Slot"/>.</param>
4647 /// <returns>The result <see cref="Slot"/>.</returns>
47-
4848 public static Slot operator + ( Slot first , Slot second )
4949 {
5050 return new Slot ( first . Index + second . Index , first . ChunkIndex + second . ChunkIndex ) ;
@@ -55,7 +55,6 @@ public Slot(int index, int chunkIndex)
5555 /// </summary>
5656 /// <param name="slot">The <see cref="Slot"/>.</param>
5757 /// <returns>The <see cref="Slot"/> with index increased by one..</returns>
58-
5958 public static Slot operator ++ ( Slot slot )
6059 {
6160 slot . Index ++ ;
@@ -66,7 +65,6 @@ public Slot(int index, int chunkIndex)
6665 /// Validates the <see cref="Slot"/>, moves the <see cref="Slot"/> if it is outside a <see cref="Chunk.Capacity"/> to match it.
6766 /// </summary>
6867 /// <returns></returns>
69-
7068 public void Wrap ( int capacity )
7169 {
7270 // Result outside valid chunk, wrap into next one
@@ -90,7 +88,6 @@ public void Wrap(int capacity)
9088 /// <param name="source">The <see cref="Slot"/> to shift by one.</param>
9189 /// <param name="sourceCapacity">The capacity of the chunk the slot is in.</param>
9290 /// <returns></returns>
93-
9491 public static Slot Shift ( ref Slot source , int sourceCapacity )
9592 {
9693 source . Index ++ ;
@@ -106,7 +103,6 @@ public static Slot Shift(ref Slot source, int sourceCapacity)
106103 /// <param name="destination">The destination <see cref="Slot"/>, a reference point at which the copy or shift operation starts.</param>
107104 /// <param name="sourceCapacity">The source <see cref="Chunk.Capacity"/>.</param>
108105 /// <param name="destinationCapacity">The destination <see cref="Chunk.Capacity"/></param>
109-
110106 public static Slot Shift ( in Slot source , int sourceCapacity , in Slot destination , int destinationCapacity )
111107 {
112108 var freeSpot = destination ;
@@ -136,14 +132,14 @@ public class Archetypes : IDisposable
136132 /// </summary>
137133 public Archetypes ( int capacity )
138134 {
139- Items = new PooledList < Archetype > ( capacity , ClearMode . Never ) ;
135+ Items = new NetStandardList < Archetype > ( capacity ) ;
140136 _hashCode = - 1 ;
141137 }
142138
143139 /// <summary>
144140 /// The <see cref="PooledList{T}"/> that contains all <see cref="Archetype"/>s.
145141 /// </summary>
146- public PooledList < Archetype > Items { get ; }
142+ public NetStandardList < Archetype > Items { get ; }
147143
148144 /// <summary>
149145 /// The count of this instance.
@@ -184,7 +180,7 @@ public void Remove(Archetype archetype)
184180 /// <returns>The <see cref="Span{T}"/>.</returns>
185181 public Span < Archetype > AsSpan ( )
186182 {
187- return Items . Span ;
183+ return Items . AsSpan ( ) ;
188184 }
189185
190186 /// <summary>
@@ -253,7 +249,7 @@ public void Clear()
253249 /// </summary>
254250 public void Dispose ( )
255251 {
256- Items . Dispose ( ) ;
252+ Items . Clear ( ) ;
257253 }
258254}
259255
@@ -264,7 +260,6 @@ public void Dispose()
264260/// </summary>
265261public sealed partial class Archetype
266262{
267-
268263 /// <summary>
269264 /// A lookup array that maps the component id to an index within the component array of a <see cref="Chunk"/> to quickly find the correct array for the component type.
270265 /// Is being stored here since all <see cref="Chunks"/> share the same instance to reduce allocations.
@@ -298,46 +293,6 @@ internal Archetype(Signature signature, int baseChunkSize, int baseChunkEntityCo
298293 _removeEdges = new SparseJaggedArray < Archetype > ( BucketSize ) ;
299294 }
300295
301- /// <summary>
302- /// Try get the index of a component within this archetype. Returns false if the archetype does not have this
303- /// component.
304- /// </summary>
305- [ Pure ]
306- internal bool TryIndex < T > ( out int i )
307- {
308- var id = Component < T > . ComponentType . Id ;
309- Debug . Assert ( id != - 1 , $ "Supplied component index is invalid") ;
310-
311- if ( id >= _componentIdToArrayIndex . Length )
312- {
313- i = - 1 ;
314- return false ;
315- }
316-
317- i = _componentIdToArrayIndex . DangerousGetReferenceAt ( id ) ;
318- return i != - 1 ;
319- }
320-
321- /// <summary>
322- /// Try get the index of a component within this archetype. Returns false if the archetype does not have this
323- /// component.
324- /// </summary>
325- [ Pure ]
326- internal bool TryIndex ( ComponentType type , out int i )
327- {
328- var id = type . Id ;
329- Debug . Assert ( id != - 1 , $ "Supplied component index is invalid") ;
330-
331- if ( id >= _componentIdToArrayIndex . Length )
332- {
333- i = - 1 ;
334- return false ;
335- }
336-
337- i = _componentIdToArrayIndex . DangerousGetReferenceAt ( id ) ;
338- return i != - 1 ;
339- }
340-
341296 /// <summary>
342297 /// The component types that the <see cref="Arch.Core.Entity"/>'s stored here have.
343298 /// The base size of a <see cref="Chunk"/> within the <see cref="Chunks"/> in KB.
@@ -616,6 +571,52 @@ public bool Has<T>()
616571 return BitSet . IsSet ( id ) ;
617572 }
618573
574+ /// <summary>
575+ /// Try get the index of a component within this archetype. Returns false if the archetype does not have this
576+ /// component.
577+ /// </summary>
578+ /// <param name="i">The index.</param>
579+ /// <typeparam name="T">The type.</typeparam>
580+ /// <returns>True if it was successfully.</returns>
581+ [ Pure ]
582+ internal bool TryIndex < T > ( out int i )
583+ {
584+ var id = Component < T > . ComponentType . Id ;
585+ Debug . Assert ( id != - 1 , $ "Supplied component index is invalid") ;
586+
587+ if ( id >= _componentIdToArrayIndex . Length )
588+ {
589+ i = - 1 ;
590+ return false ;
591+ }
592+
593+ i = _componentIdToArrayIndex . DangerousGetReferenceAt ( id ) ;
594+ return i != - 1 ;
595+ }
596+
597+ /// <summary>
598+ /// Try get the index of a component within this archetype. Returns false if the archetype does not have this
599+ /// component.
600+ /// </summary>
601+ /// <param name="type">The <see cref="ComponentType"/>.</param>
602+ /// <param name="i">The index.</param>
603+ /// <returns>True if it was successfully.</returns>
604+ [ Pure ]
605+ internal bool TryIndex ( ComponentType type , out int i )
606+ {
607+ var id = type . Id ;
608+ Debug . Assert ( id != - 1 , $ "Supplied component index is invalid") ;
609+
610+ if ( id >= _componentIdToArrayIndex . Length )
611+ {
612+ i = - 1 ;
613+ return false ;
614+ }
615+
616+ i = _componentIdToArrayIndex . DangerousGetReferenceAt ( id ) ;
617+ return i != - 1 ;
618+ }
619+
619620 /// <summary>
620621 /// Returns a reference of the component of an <see cref="Arch.Core.Entity"/> at a given <see cref="Slot"/>.
621622 /// </summary>
@@ -786,7 +787,7 @@ internal void EnsureEntityCapacity(int newCapacity)
786787 /// </summary>
787788 internal void TrimExcess ( )
788789 {
789- Chunks . Count = Count ; // By setting the Count we will assure that unnecessary chunks are trimmed.
790+ Chunks . Count = Count + 1 ; // By setting the Count we will assure that unnecessary chunks are trimmed.
790791 Chunks . TrimExcess ( ) ;
791792 }
792793}
0 commit comments