feat: add partial update support with caller-declared dirty tracking

- Add PartialUpdate dataclass and supports_partial_updates to EffectPlugin
- Add dirty region tracking to Canvas (mark_dirty, get_dirty_rows, etc.)
- Canvas auto-marks dirty on put_region, put_text, fill
- CanvasStage exposes dirty rows via pipeline context
- EffectChain creates PartialUpdate and calls process_partial() for optimized effects
- HudEffect implements process_partial() to skip processing when rows 0-2 not dirty
- This enables effects to skip work when canvas regions haven't changed
This commit is contained in:
2026-03-16 16:56:45 -07:00
parent f638fb7597
commit 3a3d0c0607
5 changed files with 132 additions and 3 deletions

View File

@@ -1,9 +1,35 @@
from engine.effects.types import EffectConfig, EffectContext, EffectPlugin
from engine.effects.types import (
EffectConfig,
EffectContext,
EffectPlugin,
PartialUpdate,
)
class HudEffect(EffectPlugin):
name = "hud"
config = EffectConfig(enabled=True, intensity=1.0)
supports_partial_updates = True # Enable partial update optimization
# Cache last HUD content to detect changes
_last_hud_content: tuple | None = None
def process_partial(
self, buf: list[str], ctx: EffectContext, partial: PartialUpdate
) -> list[str]:
# If full buffer requested, process normally
if partial.full_buffer:
return self.process(buf, ctx)
# If HUD rows (0, 1, 2) aren't dirty, skip processing
if partial.dirty:
hud_rows = {0, 1, 2}
dirty_hud_rows = partial.dirty & hud_rows
if not dirty_hud_rows:
return buf # Nothing for HUD to do
# Proceed with full processing
return self.process(buf, ctx)
def process(self, buf: list[str], ctx: EffectContext) -> list[str]:
result = list(buf)