Skip to content

Commit 17277e9

Browse files
docs(plugin): clarify ReadOnlySpan vs array usage in async/sync methods
- Add sync version of wave spawner using ReadOnlySpan<T> with ref readonly - Clarify that async methods cannot use ReadOnlySpan (ref struct limitation) - Note ReadOnlyMemory<T> as alternative for async with .Span access Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net>
1 parent 5fc58ee commit 17277e9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

.claude-plugin/skills/game-patterns/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ public sealed class ComboSystem : IDisposable
149149

150150
## Spawning Patterns
151151

152-
### Wave Spawner (Async, Span)
152+
### Wave Spawner (Async)
153153
```csharp
154154
public sealed class WaveSpawner
155155
{
156156
private readonly EnemySpawner _spawner;
157157

158+
// Use ReadOnlyMemory<T> for async (ReadOnlySpan<T> is a ref struct, invalid in async)
159+
// Access .Span inside the loop for zero-allocation iteration
158160
public async UniTask RunWaves(ReadOnlyMemory<WaveConfig> waves, CancellationToken ct = default)
159161
{
160162
foreach (var wave in waves.Span)

.claude-plugin/skills/jaction/SKILL.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public static async UniTaskVoid ApplyDoT(IDamageable target, float damage, int t
182182

183183
### Wave Spawner (Async)
184184
```csharp
185+
// Async methods cannot use ReadOnlySpan (ref struct), use array instead
185186
public async UniTask RunWaves(WaveConfig[] waves)
186187
{
187188
foreach (var wave in waves)
@@ -197,6 +198,23 @@ public async UniTask RunWaves(WaveConfig[] waves)
197198
if (action.Cancelled) break;
198199
}
199200
}
201+
202+
// Sync methods can use ReadOnlySpan for zero-allocation iteration
203+
public void RunWavesSync(ReadOnlySpan<WaveConfig> waves)
204+
{
205+
foreach (ref readonly var wave in waves)
206+
{
207+
using var action = JAction.Create()
208+
.Do(() => UI.ShowWaveStart(wave.Number))
209+
.Delay(2f)
210+
.Do(() => SpawnWave(wave))
211+
.WaitUntil(() => ActiveEnemyCount == 0, timeout: 120f)
212+
.Delay(wave.DelayAfter);
213+
action.Execute();
214+
215+
if (action.Cancelled) break;
216+
}
217+
}
200218
```
201219

202220
### Health Regeneration (Zero-GC)

0 commit comments

Comments
 (0)