Memory Model
Memory Model
cpyvn uses a deterministic, scene-scoped memory model.
Layers
Parse cache
Parsed script AST + labels, keyed by absolute script path.Asset caches
- image cache (
bg,sprites) - sound cache (
audio)
- image cache (
Runtime scene state
Current background, visible sprites, hotspots, transitions, active waits, video state.HUD state
Persistent HUD buttons (self.hud_buttons). Unlike hotspots, these survive scene changes andcache clear. Only cleared by explicithud remove/hud clear.Variable state
Runtime variables fromset/track(self.variables), persisted in save files.Pins
Pinned assets are never evicted by scene/script pruning.
Scene Manifest
Every loaded script builds a scene manifest (vn/runtime/scene_manifest.pyx) that records:
- background images
- sprite images (including
charactersprite mappings) - audio paths (
music,sound,echo,voice) - called scripts (
call ...) - referenced videos
This manifest is used to prefetch and prune safely.
What Happens On call
When switching scripts with call:
- Next script is parsed/loaded (from cache if available).
- Next manifest assets are prefetched.
- Cache is pruned to next-scene needs:
- keep next-scene assets
- keep pinned assets
- keep currently active echo/voice
- keep current music path
- Runtime moves to target label in next script.
Result: old script assets are dropped when no longer needed.
Call Loading Overlay
call does not require loading { ... }.
Runtime can auto-show loading overlay for:
- cold calls (script not in parse cache)
- scripts previously measured as slow
Project knobs:
ui.call_auto_loading(defaulttrue)ui.call_loading_text(default"Loading scene...")ui.call_loading_threshold_ms(default120)ui.call_loading_min_show_ms(default120)
loading And preload
loading "text" { ... }; is a script-level loading phase.
loading startshows loading overlay.preloadcommands inside it load assets into cache immediately.loading endhides overlay.
preload loads cache entries, but does not make them immutable.
Use cache pin ... or prefetch.json if you need guaranteed retention.
Cache Commands
cache clear images;
Drop non-pinned image cache entries.cache clear sounds;
Drop non-pinned sound cache entries.cache clear scripts;
Clear parse cache and prune assets back to current-scene needs.cache clear script "path.vn";
Clear one parsed script entry.
If it is the current script, runtime scene state is reset.cache clear runtime;(cache clear scene;alias)
Full runtime reset + non-pinned cache clear + GC. Variables are kept (not cleared).
Prefetch
prefetch.json is startup-level pinning/warming:
- scripts are parsed and kept in script cache
- images/audio are preloaded and pinned
- duplicates are ignored
- missing files only warn
Use prefetch for always-hot assets (map, UI sounds, common characters).
Practical Rules
- Pin only assets that are truly global.
- Use scene-local assets for chapter-specific content.
- Use
callboundaries as cleanup boundaries. - Use
cache clear runtimeonly for hard reset/debug, not normal flow.