Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Oct 15, 2024
1 parent 203832b commit 742ca00
Show file tree
Hide file tree
Showing 19 changed files with 428 additions and 273 deletions.
12 changes: 6 additions & 6 deletions src/Arch.Benchmarks/ArchetypeIterationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Setup()
// jobScheduler = new JobScheduler();

_globalArchetype = new Archetype(_group);
_globalArchetype.Reserve(Amount);
_globalArchetype.EnsureEntityCapacity(Amount);

for (var index = 0; index < Amount; index++)
{
Expand All @@ -45,7 +45,7 @@ public void IterationNormalTwoComponents()
for (var chunkIndex = 0; chunkIndex < size; chunkIndex++)
{
ref readonly var chunk = ref chunks[chunkIndex];
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
var transforms = chunk.GetArray<Transform>();
var rotations = chunk.GetArray<Rotation>();

Expand All @@ -69,7 +69,7 @@ public void IterationUnsafeAddTwoComponents()
for (var chunkIndex = 0; chunkIndex < size; chunkIndex++)
{
ref readonly var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;

var transforms = currentChunk.GetArray<Transform>();
var rotations = currentChunk.GetArray<Rotation>();
Expand Down Expand Up @@ -103,7 +103,7 @@ public void IterationParallelUnsafeAdd()
for (var chunkIndex = 0; chunkIndex < end - start; chunkIndex++)
{
ref readonly var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
var transforms = currentChunk.GetArray<Transform>();
var rotations = currentChunk.GetArray<Rotation>();
Expand Down Expand Up @@ -132,7 +132,7 @@ public void IterationNormalEntityTwoComponents()
for (var chunkIndex = 0; chunkIndex < size; chunkIndex++)
{
ref readonly var chunk = ref chunks[chunkIndex];
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;

var entities = chunk.Entities;
var transforms = chunk.GetArray<Transform>();
Expand Down Expand Up @@ -160,7 +160,7 @@ public void IterationUnsafeAddEntityTwoComponents()
for (var chunkIndex = 0; chunkIndex < size; chunkIndex++)
{
ref readonly var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;

var entities = currentChunk.Entities;
var transforms = currentChunk.GetArray<Transform>();
Expand Down
16 changes: 8 additions & 8 deletions src/Arch.Benchmarks/ArchetypeIterationTechnqiquesBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Setup()
_consumer = new Consumer();

_globalArchetype = new Archetype(_group);
_globalArchetype.Reserve(Amount);
_globalArchetype.EnsureEntityCapacity(Amount);

for (var index = 0; index < Amount; index++)
{
Expand All @@ -51,7 +51,7 @@ public void IterationNormalTwoComponents()
var transforms = chunk.GetArray<Transform>();
var rotations = chunk.GetArray<Rotation>();

for (var index = 0; index < chunk.Size; index++)
for (var index = 0; index < chunk.Count; index++)
{
ref var transform = ref transforms[index];
ref var rotation = ref rotations[index];
Expand All @@ -76,7 +76,7 @@ public void IterationUnsafeAddTwoComponents()
ref var transform = ref transforms[0];
ref var rotation = ref rotations[0];

for (var index = 0; index < currentChunk.Size; index++)
for (var index = 0; index < currentChunk.Count; index++)
{
ref var currentTransform = ref Unsafe.Add(ref transform, index);
ref var currentRotation = ref Unsafe.Add(ref rotation, index);
Expand All @@ -98,7 +98,7 @@ public void IterationNormalTwoComponentsSpan()
var transforms = chunk.GetSpan<Transform>();
var rotations = chunk.GetSpan<Rotation>();

for (var index = 0; index < chunk.Size; index++)
for (var index = 0; index < chunk.Count; index++)
{
ref var transform = ref transforms[index];
ref var rotation = ref rotations[index];
Expand All @@ -123,7 +123,7 @@ public void IterationUnsafeAddTwoComponentsSpan()
ref var transform = ref transforms[0];
ref var rotation = ref rotations[0];

for (var index = 0; index < currentChunk.Size; index++)
for (var index = 0; index < currentChunk.Count; index++)
{
ref var currentTransform = ref Unsafe.Add(ref transform, index);
ref var currentRotation = ref Unsafe.Add(ref rotation, index);
Expand All @@ -142,7 +142,7 @@ public void IterationBackwardsUnsafeAdd()
for (var chunkIndex = 0; chunkIndex < _globalArchetype.ChunkCount; chunkIndex++)
{
ref var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = currentChunk.Size;
var chunkSize = currentChunk.Count;
ref var entityFirstElement = ref ArrayExtensions.DangerousGetReference(currentChunk.Entities);

for (var entityIndex = chunkSize - 1; entityIndex >= 0; --entityIndex)
Expand All @@ -160,7 +160,7 @@ public void IterationBackwardsUnsafeSubstract()
for (var chunkIndex = 0; chunkIndex < _globalArchetype.ChunkCount; chunkIndex++)
{
ref var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = currentChunk.Size;
var chunkSize = currentChunk.Count;
ref var entityLastElement = ref ArrayExtensions.DangerousGetReferenceAt(currentChunk.Entities, chunkSize - 1);

for (var entityIndex = 0; entityIndex < chunkSize; ++entityIndex)
Expand All @@ -178,7 +178,7 @@ public void IterationBackwardsLoop()
for (var chunkIndex = 0; chunkIndex < _globalArchetype.ChunkCount; chunkIndex++)
{
ref var currentChunk = ref Unsafe.Add(ref chunk, chunkIndex);
var chunkSize = currentChunk.Size;
var chunkSize = currentChunk.Count;

ref var entityFirstElement = ref ArrayExtensions.DangerousGetReference(currentChunk.Entities);
ref var entityLastElement = ref ArrayExtensions.DangerousGetReferenceAt(currentChunk.Entities, chunkSize - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Arch.Benchmarks/QueryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class QueryBenchmark
public void Setup()
{
_world = World.Create();
_world.Reserve(_group, Amount);
_world.EnsureCapacity(_group, Amount);

for (var index = 0; index < Amount; index++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Arch.SourceGen/Fundamentals/Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static StringBuilder AppendArchetypeSetRange(this StringBuilder sb, int a
var isStart = chunkIndex == from.ChunkIndex;
var isEnd = chunkIndex == to.ChunkIndex;

var upper = isStart ? from.Index : chunk.Size-1;
var upper = isStart ? from.Index : chunk.Count-1;
var lower = isEnd ? to.Index : 0;

for (var entityIndex = upper; entityIndex >= lower; --entityIndex)
Expand Down
6 changes: 3 additions & 3 deletions src/Arch.SourceGen/Queries/InlineQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static StringBuilder AppendQueryInterfaceMethods(this StringBuilder build
var query = Query(in description);
foreach (ref var chunk in query)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
{{getFirstElement}}

foreach(var entityIndex in chunk)
Expand Down Expand Up @@ -160,7 +160,7 @@ public static StringBuilder AppendEntityQueryInterfaceMethods(this StringBuilder
var query = Query(in description);
foreach (ref var chunk in query)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
ref var entityFirstElement = ref chunk.Entity(0);
{{getFirstElement}}

Expand Down Expand Up @@ -195,7 +195,7 @@ public static StringBuilder AppendEntityQueryInterfaceMethods(this StringBuilder
var query = Query(in description);
foreach (ref var chunk in query)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
ref var entityFirstElement = ref chunk.Entity(0);
{{getFirstElement}}

Expand Down
6 changes: 3 additions & 3 deletions src/Arch.SourceGen/Queries/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ForEachJob<{{generics}}> : IChunkJob

public void Execute(ref Chunk chunk)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
{{getFirstElement}}

foreach(var entityIndex in chunk)
Expand Down Expand Up @@ -106,7 +106,7 @@ public struct IForEachJob<T,{{generics}}> : IChunkJob where T : struct, IForEach

public void Execute(ref Chunk chunk)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
{{getFirstElement}}

foreach(var entityIndex in chunk)
Expand Down Expand Up @@ -145,7 +145,7 @@ public struct IForEachWithEntityJob<T,{{generics}}> : IChunkJob where T : struct

public void Execute(ref Chunk chunk)
{
var chunkSize = chunk.Size;
var chunkSize = chunk.Count;
ref var entityFirstElement = ref chunk.Entity(0);
{{getFirstElement}}

Expand Down
Loading

0 comments on commit 742ca00

Please sign in to comment.