forked from genewildish/Mainline
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user