2026-07-18 19:33:05 +08:00
|
|
|
namespace OECS;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A system that runs on every tick.
|
2026-07-21 09:45:49 +08:00
|
|
|
/// Implement <see cref="RunImpl"/> with the system logic.
|
|
|
|
|
/// Call <see cref="ISystem.Run"/> to execute with batching.
|
2026-07-18 19:33:05 +08:00
|
|
|
/// </summary>
|
|
|
|
|
public interface ISystem
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2026-07-21 09:45:49 +08:00
|
|
|
/// Implement this with the system's logic for this tick.
|
|
|
|
|
/// The caller (e.g., <see cref="ISystem.Run"/>) wraps this
|
|
|
|
|
/// in a batching scope so mutations and component accesses
|
|
|
|
|
/// are automatically tracked.
|
2026-07-18 19:33:05 +08:00
|
|
|
/// </summary>
|
2026-07-21 09:45:49 +08:00
|
|
|
void RunImpl(World world);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extension methods for running systems with proper batching.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class SystemExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs a system with a batching scope. Structural mutations are
|
|
|
|
|
/// buffered, and <see cref="World.GetComponent{T}"/> calls are
|
|
|
|
|
/// auto-tracked for modification until the system returns.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void Run(this ISystem system, World world)
|
|
|
|
|
{
|
|
|
|
|
world.BeginBatching();
|
|
|
|
|
system.RunImpl(world);
|
|
|
|
|
world.EndBatching();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs a ticked system with a batching scope.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void Run(this ITickedSystem system, World world, Tick tick)
|
|
|
|
|
{
|
|
|
|
|
world.BeginBatching();
|
|
|
|
|
system.RunImpl(world, tick);
|
|
|
|
|
world.EndBatching();
|
|
|
|
|
}
|
2026-07-18 19:33:05 +08:00
|
|
|
}
|