Skip to content
简体中文

Run Arch ECS systems ​

Direct construction ​

cs
// Direct construction borrows the World/system; their using declarations are the sole final owners.
using var world = World.Create();
using var movement = new NativeMovement(world);
var runtime = new ArchRuntime(world, [movement], new ArchOptions { EnableStatistics = true });
try
{
    runtime.Initialize();
    var entity = world.Create(new Position(0, 0), new Velocity(10, 5));
    runtime.Update(0.5f);
    var position = world.Get<Position>(entity);
    if (position.X != 5 || position.Y != 2.5f || movement.BeforeCalls != 1 || movement.AfterCalls != 1)
        throw new InvalidOperationException("Native phases or entity movement failed.");
    var statistics = runtime.GetStatistics()!;
    Console.WriteLine(string.Create(CultureInfo.InvariantCulture,
        $"ARCH_RUNTIME_PASS entities={statistics.EntityCount} frames={statistics.CompletedFrames} systems={statistics.SystemCount}"));
}
finally
{
    runtime.Stop();
}
bash
dotnet run --project Samples/ArchRuntimeDemo -c Release

ARCH_RUNTIME_PASS confirms that the native system ran and the entity moved as expected. The runtime borrows the supplied World and systems. Stop the runtime, then dispose the systems and finally the World.

Use DI ​

Call AddArch in the composition root to configure the runtime and options, then register systems. Call Update with the host loop's actual timestep. Enable EnableStatistics for per-instance metrics and measure the cost in your own workload.

Apache License 2.0