refactor: simplify iterator usage and improve command execution
- Replace manual `while (iter.MoveNext())` loops with `foreach` loops in tests - Implement batching and mutation flushing in `CommandQueue.ExecuteAll` to ensure chained commands see each other's changes
This commit is contained in:
@@ -41,11 +41,18 @@ public class CommandQueue
|
||||
/// <summary>
|
||||
/// Executes all queued commands in FIFO order against the given world.
|
||||
///
|
||||
/// Commands run inside a batching scope — structural mutations are
|
||||
/// deferred and <see cref="World.GetComponent{T}"/> calls are
|
||||
/// auto-tracked for modification until the drain completes.
|
||||
/// Pending mutations are flushed after each command, so chained
|
||||
/// commands see each other's changes within the same drain cycle.
|
||||
///
|
||||
/// The queue is fully drained — commands enqueued by other commands during
|
||||
/// this call are also executed before the method returns.
|
||||
/// </summary>
|
||||
public void ExecuteAll(World world)
|
||||
{
|
||||
world.BeginBatching();
|
||||
int index = 0;
|
||||
while (index < _commands.Count)
|
||||
{
|
||||
@@ -60,9 +67,13 @@ public class CommandQueue
|
||||
{
|
||||
_errors.Add(ex);
|
||||
}
|
||||
|
||||
// Flush after each command so chained commands see mutations.
|
||||
world.FlushPendingMutations();
|
||||
}
|
||||
|
||||
_commands.Clear();
|
||||
world.EndBatching();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user