32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
|
|
namespace OECS;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// A command that resolves a pending interrupt of type <typeparamref name="TInterrupt"/>.
|
||
|
|
///
|
||
|
|
/// The default <see cref="ICommand.Execute"/> implementation looks up the pending
|
||
|
|
/// interrupt, calls <see cref="TryResolve"/> to let the handler inspect it, and
|
||
|
|
/// resolves the interrupt if the handler returns <c>true</c>.
|
||
|
|
/// </summary>
|
||
|
|
/// <typeparam name="TInterrupt">The interrupt type this handler resolves.</typeparam>
|
||
|
|
public interface IInterruptHandlerCommand<TInterrupt> : ICommand
|
||
|
|
where TInterrupt : struct, IInterrupt
|
||
|
|
{
|
||
|
|
void ICommand.Execute(World world)
|
||
|
|
{
|
||
|
|
if (world.TryGetPendingInterrupt<TInterrupt>(out var interrupt))
|
||
|
|
{
|
||
|
|
if (TryResolve(interrupt))
|
||
|
|
{
|
||
|
|
world.ResolveInterrupt<TInterrupt>();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Called by the default <see cref="ICommand.Execute"/> with the pending interrupt.
|
||
|
|
/// Return <c>true</c> to resolve and remove the interrupt; <c>false</c> to leave it
|
||
|
|
/// pending for another handler.
|
||
|
|
/// </summary>
|
||
|
|
bool TryResolve(TInterrupt interrupt);
|
||
|
|
}
|