-
Notifications
You must be signed in to change notification settings - Fork 24
Add oam_begin() and OamFrame ref struct to neslib #429
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Context
This is Phase 2 of the using var pattern support (#427). Depends on #428 (try/finally support).
Proposed API
Add to NESLib.cs:
/// Returns an OamFrame that auto-hides remaining sprites on Dispose
public static OamFrame oam_begin() => throw null!;Add new ref struct (can live in NESLib.cs or a separate file):
/// RAII scope for OAM sprite drawing.
/// Dispose() calls oam_hide_rest(oam_off).
public ref struct OamFrame
{
public void Dispose() => throw null!;
}Why ref struct
Using ref struct instead of a regular struct is critical:
- The compiler emits a direct
calltoDispose()instead ofcallvirtthrough IDisposable - No boxing, no interface dispatch, no heap allocation
- The IL is simpler for the transpiler to recognize
Usage
using var frame = oam_begin();
oam_meta_spr_pal(x, y, pal, sprite);
oam_spr(x2, y2, tile, attr, oam_off);
// Dispose() auto-calls oam_hide_rest(oam_off) at end of scopePart of #427
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request