Fix 5: iOS Safari scoped asset loading and memory management

- New Platform.gd autoload: is_ios_safari() detects iPhone/iPad Safari
  via JavaScriptBridge UA check (no Chrome/CriOS), gating all iOS memory paths
- ModelCache.release_model(url, etag): evicts a model from in-memory cache
  on iOS Safari when a unit leaves the board; no-op on other platforms so
  disk cache is always preserved for fast reload
- unit_mesh_builder: stores resolved model URL+ETag per unit (_unit_model_urls,
  _unit_model_etags); calls ModelCache.release_model in the to_remove loop so
  PackedScene refs are freed as soon as the unit is pooled or freed
- ContentCache.get_model_url_for_definition: stub for looking up a card's
  Model3D CDN URL without a loaded unit dict (foundation for future eviction paths)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-05-20 22:35:05 -04:00
co-authored by Claude Happy
parent 93e3c8b0db
commit c8c3666d26
5 changed files with 64 additions and 0 deletions
@@ -82,6 +82,22 @@ func _migrate_cache() -> void:
f.close()
## Release a model from the in-memory cache without touching disk.
## On iOS Safari this immediately frees resident memory when a unit leaves the board.
## On other platforms this is a no-op — the OS manages heap pressure.
## Disk cache (.bin) is intentionally kept so the model reloads instantly if the same
## unit type is played again in the same session.
func release_model(url: String, etag: String = "") -> void:
if url.is_empty():
return
if not Platform.is_ios_safari():
return
var key := _cache_key(url, etag)
_mem.erase(key)
if OS.is_debug_build():
print("ModelCache: released %s (mem_entries=%d)" % [url, _mem.size()])
## Remove a cached entry (memory + disk) so the next load_model call re-downloads it.
## Use before retrying a previously-failed URL.
func evict(url: String, etag: String = "") -> void: