Skip to content

Commit 342ee65

Browse files
committed
+ cleanup
+ WIP: MarkChanged
1 parent df3d9d6 commit 342ee65

File tree

2 files changed

+84
-21
lines changed

2 files changed

+84
-21
lines changed

src/Bevy.cs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ bool IQueryIterator<Changed<T>>.MoveNext()
10611061

10621062
if (states.IsEmpty)
10631063
{
1064-
_stateRow.Value = Unsafe.NullRef<uint>();
1064+
_stateRow.Value = ref Unsafe.NullRef<uint>();
10651065
_size = 0;
10661066
}
10671067
else
@@ -1141,7 +1141,7 @@ bool IQueryIterator<Added<T>>.MoveNext()
11411141

11421142
if (states.IsEmpty)
11431143
{
1144-
_stateRow.Value = Unsafe.NullRef<uint>();
1144+
_stateRow.Value = ref Unsafe.NullRef<uint>();
11451145
_size = 0;
11461146
}
11471147
else
@@ -1165,6 +1165,88 @@ public void SetTicks(uint lastRun, uint thisRun)
11651165
}
11661166
}
11671167

1168+
1169+
public ref struct MarkChanged<T> : IFilter<MarkChanged<T>>
1170+
where T : struct
1171+
{
1172+
private QueryIterator _iterator;
1173+
private Ptr<uint> _stateRow;
1174+
private int _row, _count;
1175+
private nint _size;
1176+
private uint _lastRun, _thisRun;
1177+
1178+
private MarkChanged(QueryIterator iterator)
1179+
{
1180+
_iterator = iterator;
1181+
_row = -1;
1182+
_count = -1;
1183+
_lastRun = 0;
1184+
_thisRun = 0;
1185+
}
1186+
1187+
[UnscopedRef]
1188+
ref MarkChanged<T> IQueryIterator<MarkChanged<T>>.Current => ref this;
1189+
1190+
public static void Build(QueryBuilder builder)
1191+
{
1192+
// builder.With<T>();
1193+
}
1194+
1195+
static MarkChanged<T> IFilter<MarkChanged<T>>.CreateIterator(QueryIterator iterator)
1196+
{
1197+
return new(iterator);
1198+
}
1199+
1200+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1201+
readonly MarkChanged<T> IQueryIterator<MarkChanged<T>>.GetEnumerator()
1202+
{
1203+
return this;
1204+
}
1205+
1206+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1207+
bool IQueryIterator<MarkChanged<T>>.MoveNext()
1208+
{
1209+
if (++_row >= _count)
1210+
{
1211+
if (!_iterator.Next())
1212+
return false;
1213+
1214+
_row = 0;
1215+
_count = _iterator.Count;
1216+
var index = _iterator.GetColumnIndexOf<T>();
1217+
var states = _iterator.GetChangedTicks(index);
1218+
1219+
if (states.IsEmpty)
1220+
{
1221+
_stateRow.Value = ref Unsafe.NullRef<uint>();
1222+
_size = 0;
1223+
}
1224+
else
1225+
{
1226+
_stateRow.Value = ref MemoryMarshal.GetReference(states);
1227+
_size = Unsafe.SizeOf<uint>();
1228+
}
1229+
}
1230+
else
1231+
{
1232+
_stateRow.Value = ref Unsafe.AddByteOffset(ref _stateRow.Value, _size);
1233+
}
1234+
1235+
if (_size > 0)
1236+
{
1237+
_stateRow.Value = _thisRun;
1238+
}
1239+
1240+
return true;
1241+
}
1242+
1243+
public void SetTicks(uint lastRun, uint thisRun)
1244+
{
1245+
_lastRun = lastRun;
1246+
_thisRun = thisRun;
1247+
}
1248+
}
1249+
11681250
public partial struct Parent { }
11691251
public partial interface IChildrenComponent { }
11701252

src/Ptr.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,13 @@
33
[SkipLocalsInit]
44
public ref struct Ptr<T> where T : struct
55
{
6-
// internal ref ComponentState State;
76
internal ref T Value;
87

98
public readonly ref T Ref
109
{
1110
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1211
get => ref Value;
1312
}
14-
// public readonly ref T Rw
15-
// {
16-
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
17-
// get
18-
// {
19-
// if (State != ComponentState.Changed)
20-
// State = ComponentState.Changed;
21-
// return ref Value;
22-
// }
23-
// }
24-
25-
// public readonly bool IsChanged => State == ComponentState.Changed;
26-
// public readonly bool IsAdded => State == ComponentState.Added;
27-
28-
// public void ClearState() => State = ComponentState.None;
29-
// public void MarkChanged() => State = ComponentState.Changed;
3013
}
3114

3215
[SkipLocalsInit]
@@ -42,12 +25,10 @@ public readonly ref T Ref
4225
{
4326
public Ptr<T> Value;
4427
public nint Size;
45-
// public nint StateSize;
4628

4729
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4830
public void Next()
4931
{
5032
Value.Value = ref Unsafe.AddByteOffset(ref Value.Ref, Size);
51-
// Value.State = ref Unsafe.AddByteOffset(ref Value.State, StateSize);
5233
}
5334
}

0 commit comments

Comments
 (0)