feat(docs): Add interrupt system documentation
This commit is contained in:
@@ -248,3 +248,55 @@ tracking. Outside a batching scope, call `MarkModified` after mutating.
|
||||
`WorldSerializer.Save/Load` uses the source-generated `ComponentRegistry`.
|
||||
All component types used with `World` generic methods are automatically
|
||||
discovered. Serialization round-trips must be tested — see `testing-games` skill.
|
||||
|
||||
## Interrupts
|
||||
|
||||
Interrupts pause system execution until an external response arrives. A system
|
||||
issues an interrupt, the next tick is skipped, and a handler command resolves it.
|
||||
|
||||
### Issuing an Interrupt
|
||||
|
||||
```csharp
|
||||
[MessagePackObject]
|
||||
public record struct ConfirmInterrupt : IInterrupt
|
||||
{
|
||||
[Key(0)] public string Message;
|
||||
}
|
||||
|
||||
// In a system:
|
||||
world.Interrupt(new ConfirmInterrupt { Message = "Are you sure?" });
|
||||
```
|
||||
|
||||
The current tick completes normally. The **next** tick is blocked — `SystemGroup`
|
||||
skips all systems but still drains commands and posts changes.
|
||||
|
||||
### Handling an Interrupt
|
||||
|
||||
Handler commands implement `IInterruptHandlerCommand<T>`. The default `Execute`
|
||||
calls `TryResolve` with the pending interrupt. Return `true` to resolve it,
|
||||
`false` to leave it pending for another handler:
|
||||
|
||||
```csharp
|
||||
[MessagePackObject]
|
||||
public struct ConfirmHandler : IInterruptHandlerCommand<ConfirmInterrupt>
|
||||
{
|
||||
[Key(0)] public bool Confirmed;
|
||||
|
||||
public bool TryResolve(ConfirmInterrupt interrupt)
|
||||
{
|
||||
// Do work here. The interrupt is just a signal.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// External code (e.g., UI button) enqueues the handler:
|
||||
world.Commands.Enqueue(new ConfirmHandler { Confirmed = true });
|
||||
```
|
||||
|
||||
### Key Rules
|
||||
|
||||
- Only one interrupt of a given type may be pending at a time. A second call
|
||||
to `Interrupt<T>` with the same type throws.
|
||||
- Interrupts are transient — they are not serialized and do not survive save/load.
|
||||
- If no `SystemGroup` manages the world, `Interrupt<T>()` is a no-op.
|
||||
- Check pending interrupts with `world.HasInterrupt<T>()`.
|
||||
|
||||
Reference in New Issue
Block a user