Skip to content

Commit

Permalink
removed test code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Jul 8, 2024
1 parent 3966f87 commit 68c2087
Showing 1 changed file with 0 additions and 330 deletions.
330 changes: 0 additions & 330 deletions src/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,333 +432,3 @@ public bool MoveNext()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly QueryArchetypeChunkIterator GetEnumerator() => this;
}




public partial class Query
{
public RefEnumeratorTest<T0, T1> IterTest<T0, T1>() where T0 : struct where T1 : struct
{
return new (GetEnumerator());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RefEnumeratorTest2<T0, T1> IterTest2<T0, T1>() where T0 : struct where T1 : struct
{
return new (GetEnumerator());
}

// public void EachJob2<T0>(QueryFilterDelegate<T0> fn)
// where T0 : struct
// {
// var query = this;
// EcsAssert.Panic(query.TermsAccess.Length == 1, "mismatched sign");
// World.BeginDeferred();
// var cde = query.ThreadCounter;
// cde.Reset();

// foreach (var (_, t0AA) in query.Iter<T0>())
// {
// cde.AddCount(1);
// var inc0 = t0AA.IsEmpty ? 0 : 1;

// System.Threading.ThreadPool.QueueUserWorkItem(state =>
// {
// ref var index = ref Unsafe.Unbox<int>(state!);

// cde.Signal();
// }, t0AA);
// }

// foreach (var arch in query)
// {
// var column0 = arch.GetComponentIndex<T0>();
// var inc0 = column0 < 0 ? 0 : 1;
// var chunks = arch.MemChunks;
// cde.AddCount(chunks.Length);
// for (var i = 0; i < chunks.Length; ++i)
// {
// System.Threading.ThreadPool.QueueUserWorkItem(state =>
// {
// ref var index = ref Unsafe.Unbox<int>(state!);
// ref readonly var chunk = ref chunks.Span[index];
// var done = 0;
// ref var t0A = ref chunk.GetReference<T0>(column0);
// while (done <= chunk.Count - 4)
// {
// fn(ref t0A);
// t0A = ref Unsafe.Add(ref t0A, inc0);
// fn(ref t0A);
// t0A = ref Unsafe.Add(ref t0A, inc0);
// fn(ref t0A);
// t0A = ref Unsafe.Add(ref t0A, inc0);
// fn(ref t0A);
// t0A = ref Unsafe.Add(ref t0A, inc0);
// done += 4;
// }

// while (done < chunk.Count)
// {
// fn(ref t0A);
// t0A = ref Unsafe.Add(ref t0A, inc0);
// done += 1;
// }

// cde.Signal();
// }, i);
// }
// }

// cde.Signal();
// cde.Wait();
// World.EndDeferred();
// }

public void Each2<T0, T1, T2>(QueryFilterDelegate<T0, T1, T2> fn)
where T0 : struct where T1 : struct where T2 : struct
{
var query = this;
EcsAssert.Panic(query.TermsAccess.Length == 3, "mismatched sign");
EcsAssert.Panic(query.TermsAccess[0].Id == query.World.Entity<T0>().ID, $"'{typeof(T0)}' doesn't match the QueryData sign");
EcsAssert.Panic(query.TermsAccess[1].Id == query.World.Entity<T1>().ID, $"'{typeof(T1)}' doesn't match the QueryData sign");
EcsAssert.Panic(query.TermsAccess[2].Id == query.World.Entity<T2>().ID, $"'{typeof(T2)}' doesn't match the QueryData sign");

World.BeginDeferred();

foreach ((var entities, var t0AA, var t1AA, var t2AA) in query.Iter<T0, T1, T2>())
{
var count = entities.Length;
var inc0 = t0AA.IsEmpty ? 0 : 1;
var inc1 = t1AA.IsEmpty ? 0 : 1;
var inc2 = t2AA.IsEmpty ? 0 : 1;

ref var t0A = ref MemoryMarshal.GetReference(t0AA);
ref var t1A = ref MemoryMarshal.GetReference(t1AA);
ref var t2A = ref MemoryMarshal.GetReference(t2AA);

while (count - 4 > 0)
{
fn(ref t0A, ref t1A, ref t2A);
t0A = ref Unsafe.Add(ref t0A, inc0);
t1A = ref Unsafe.Add(ref t1A, inc1);
t2A = ref Unsafe.Add(ref t2A, inc2);
fn(ref t0A, ref t1A, ref t2A);
t0A = ref Unsafe.Add(ref t0A, inc0);
t1A = ref Unsafe.Add(ref t1A, inc1);
t2A = ref Unsafe.Add(ref t2A, inc2);
fn(ref t0A, ref t1A, ref t2A);
t0A = ref Unsafe.Add(ref t0A, inc0);
t1A = ref Unsafe.Add(ref t1A, inc1);
t2A = ref Unsafe.Add(ref t2A, inc2);
fn(ref t0A, ref t1A, ref t2A);
t0A = ref Unsafe.Add(ref t0A, inc0);
t1A = ref Unsafe.Add(ref t1A, inc1);
t2A = ref Unsafe.Add(ref t2A, inc2);

count -= 4;
}

while (count > 0)
{
fn(ref t0A, ref t1A, ref t2A);
t0A = ref Unsafe.Add(ref t0A, inc0);
t1A = ref Unsafe.Add(ref t1A, inc1);
t2A = ref Unsafe.Add(ref t2A, inc2);

count -= 1;
}
}

World.EndDeferred();
}
}

[SkipLocalsInit]
public ref struct RefEnumeratorTest<T0, T1> where T0 : struct where T1 : struct
{
private QueryInternal _queryIt;
private QueryChunkIterator _chunkIt;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal RefEnumeratorTest(QueryInternal queryit)
{
_queryIt = queryit;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void Deconstruct(out Span<T0> val0, out Span<T1> val1)
{
ref var arch = ref _queryIt.Current;
ref var chunk = ref _chunkIt.Current;

val0 = chunk.GetSpan<T0>(arch.GetComponentIndex<T0>());
val1 = chunk.GetSpan<T1>(arch.GetComponentIndex<T1>());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void Deconstruct(out Span<EntityView> entities, out Span<T0> val0, out Span<T1> val1)
{
ref var arch = ref _queryIt.Current;
ref var chunk = ref _chunkIt.Current;

entities = chunk.Entities.AsSpan(0, chunk.Count);
val0 = chunk.GetSpan<T0>(arch.GetComponentIndex<T0>());
val1 = chunk.GetSpan<T1>(arch.GetComponentIndex<T1>());
}

[UnscopedRef]
public ref RefEnumeratorTest<T0, T1> Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref this;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
while (true)
{
if (_chunkIt.MoveNext())
return true;

if (_queryIt.MoveNext())
{
_chunkIt = new QueryChunkIterator(_queryIt.Current.Chunks);
continue;
}

return false;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly RefEnumeratorTest<T0, T1> GetEnumerator() => this;
}

[SkipLocalsInit]
public unsafe ref struct RefEnumeratorTest2<T0, T1> where T0 : struct where T1 : struct
{
private RefEnumerator<T0, T1> _refEnum;
private int _count;
// private T0* _span0;
// private T1* _span1;

private Span<T0> _span0;
private Span<T1> _span1;


[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal RefEnumeratorTest2(QueryInternal queryIt)
{
_refEnum = new (queryIt);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void Deconstruct(out T0* val0, out T1* val1)
{
fixed (T0* v0 = &_span0[_count])
fixed (T1* t0 = &_span1[_count])
{
val0 = v0;
val1 = t0;
}
}

[UnscopedRef]
public ref RefEnumeratorTest2<T0, T1> Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref this;
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
while (true)
{
if (_count-- > 0)
{
// _span0 -= 1;
// _span1 -= 1;

return true;
}

if (_refEnum.MoveNext())
{
(var entities, var ref0, var ref1) = _refEnum.Current;
_count = entities.Length;

_span0 = ref0;
_span1 = ref1;

// ref var a = ref Unsafe.Add(ref MemoryMarshal.GetReference(ref0), _count);
// ref var b = ref Unsafe.Add(ref MemoryMarshal.GetReference(ref1), _count);

// _span0 = (T0*) Unsafe.AsPointer(ref a);
// _span1 = (T1*) Unsafe.AsPointer(ref b);

continue;
}

return false;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly RefEnumeratorTest2<T0, T1> GetEnumerator() => this;
}

// [SkipLocalsInit]
// public unsafe ref struct Row<T> where T : struct
// {
// #if NET
// public ref T Val0;
// #else
// private IntPtr _val0;
// public ref T Val0 => ref Unsafe.AsRef<T>(_val0.ToPointer());
// #endif


// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// internal void Set(ref T value0)
// {
// #if NET
// Val0 = ref value0;
// #else
// _val0 = (IntPtr)Unsafe.AsPointer(ref value0);
// #endif
// }

// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// internal void Advance()
// {
// #if NET
// Val0 = ref Unsafe.Add(ref Val0, 1);
// #else
// _val0 = (IntPtr)(((T*)_val0.ToPointer()) + 1);
// #endif
// }
// }


[SkipLocalsInit]
public unsafe struct Row<T> where T : struct
{
private void* _val0;
public ref T Val0 => ref *(T*)_val0;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void Set(ref T value0)
{
_val0 = Unsafe.AsPointer(ref value0);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void Advance()
{
_val0 = ((T*)_val0) + 1;
}
}

0 comments on commit 68c2087

Please sign in to comment.