Skip to content

Commit

Permalink
Refactored some code, outsourced a DestroyArchetype.
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Aug 28, 2023
1 parent 12a1d27 commit c15b2ab
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 141 deletions.
6 changes: 1 addition & 5 deletions src/Arch.Benchmarks/Benchmark.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using Arch.Core;
using Arch.Core.Extensions;

Expand All @@ -19,10 +20,5 @@ private static void Main(string[] args)
// NOTE: Is `-- --job` a typo?
// Use: dotnet run -c Release --framework net7.0 -- --job short --filter *IterationBenchmark*
BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args, config);

/*
var bc = new QueryBenchmark { Amount = 1000000 };
bc.Setup();
bc.WorldEntityQuery();*/
}
}
32 changes: 4 additions & 28 deletions src/Arch.Benchmarks/BitSetBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public void Setup()
_secondBitSet.SetBit(3);
_secondBitSet.SetBit(5);
_secondBitSet.SetBit(7);
_secondBitSet.SetBit(128);
_secondBitSet.SetBit(256);
}

[Benchmark(Baseline = true)]
Expand All @@ -32,33 +34,7 @@ public void Baseline()

[Benchmark]
public void Vectorized()
{/*
var vectorSize = Vector<uint>.Count;
var iterations = Math.Min(Length, other.Length) / vectorSize;
// Iterate the arrays, vectorize and compare them
for (var i = 0; i < iterations; i++)
{
var vector = new Vector<uint>(_bits, i * vectorSize);
var otherVector = new Vector<uint>(other._bits, i * vectorSize);
var resultVector = Vector.Equals(vector, otherVector);
if (!Vector.EqualsAll(resultVector, Vector<uint>.One))
{
return false;
}
}
// Handle extra bits on our side that might just be all zero.
var bitCount = _bits.Length;
for (var i = iterations; i < bitCount; i++)
{
if (_bits[i] != 0)
{
return false;
}
}
return true;*/
{
//_firstBitset.AllVectorized(_secondBitSet);
}
}
3 changes: 2 additions & 1 deletion src/Arch.Tests/BitSetTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Arch.Core.Utils;
using System.Numerics;
using Arch.Core.Utils;
using static NUnit.Framework.Assert;

namespace Arch.Tests;
Expand Down
2 changes: 2 additions & 0 deletions src/Arch/Arch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Archetypes with zero entities are now skipped during iteration. </PackageRelease

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;</DefineConstants>
<Optimize>false</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug-PureECS'">
Expand Down
13 changes: 9 additions & 4 deletions src/Arch/Core/Utils/BitSet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Drawing;
using System.Numerics;
using System.Text;

namespace Arch.Core.Utils;
Expand Down Expand Up @@ -27,6 +25,9 @@ public static int RequiredLength(int id)
return (int)Math.Ceiling((float)id / (float)31);
}

/// <summary>
/// The bits from the bitset.
/// </summary>
private uint[] _bits;

/// <summary>
Expand Down Expand Up @@ -126,6 +127,7 @@ public void ClearAll()
Array.Clear(_bits, 0, _bits.Length);
}


/// <summary>
/// Checks if all bits from this instance match those of the other instance.
/// </summary>
Expand Down Expand Up @@ -319,13 +321,16 @@ public override string ToString()
/// represents a non resizable collection of bits.
/// Used to set, check and clear bits on a allocated <see cref="BitSet"/> or on the stack.
/// </summary>
public ref struct SpanBitSet
public readonly ref struct SpanBitSet
{
private const int BitSize = (sizeof(uint) * 8) - 1; // 31
// NOTE: Is a byte not 8 bits?
private const int ByteSize = 5; // log_2(BitSize + 1)

private Span<uint> _bits;
/// <summary>
/// The bits from the bitset.
/// </summary>
private readonly Span<uint> _bits;

/// <summary>
/// Initializes a new instance of the <see cref="BitSet" /> class.
Expand Down
Loading

0 comments on commit c15b2ab

Please sign in to comment.