Cache generated building meshes per type #41
Labels
No labels
assets
bug
duplicate
enhancement
help wanted
invalid
question
testing
ui
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
liamjd/UntitledColonyBuilder#41
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
BuildingMeshes.build()currently generates a freshPrimitiveMeshand a freshStandardMaterial3Don every call. Deferred deliberately from #36: at the time therewere no callers at all, and the cache key is the entire design decision — it depends on
how #39's ghost and the real placer actually invoke it.
Do not pick this up until #39 and a real building placer exist. The point of waiting
is to key the cache against real call sites rather than imagined ones.
Why cache
Not for generation speed — building a
PrimitiveMeshis just setting properties, and thesurface arrays are built lazily by the engine. The win is resource sharing: without a
cache, twenty ore mines are twenty distinct
Meshresources and twenty distinctmaterials, rather than one of each shared by twenty
MeshInstance3Ds.The ghost and the real buildings can share the same cached mesh, because tinting happens
via
MeshInstance3D.material_override, which replaces the bakedPrimitiveMesh.materialat the instance. Nothing should give the ghost its own copy.Shape
build()'s signature does not change, so this is entirely internal.Key on all three inputs. A cache keyed on
type.idalone silently returns a meshbuilt for a previous
tile_size— andtile_sizeis an@exportonTerrainGrid, not aconstant. Never invalidate on a
tile_sizechange: a stale entry under a key nobody asksfor again is harmless, a wrong-sized mesh under the right key is not.
Three things that will bite
@toolscript reloads in the editor. Edit
placeholder_colorin a.tresand you keep gettingthe old mesh until restart. Either guard with
Engine.is_editor_hint()or callclear_cache()where terrain regenerates.clear_cache()inbefore_each, or a test that mutates aBuildingTypeand rebuilds gets the previous test's mesh. That alone is why
clear_cache()is publicrather than private.
as
BuildingFootprint.rotated()returning a copy and the shared-preset warning onTerrainGrid.next_shape(). Note this constraint is already live on the authored path —build()returnstype.meshby reference today — so the doc comment stating it belongson
build()regardless of whether this issue is ever done.Acceptance
build()calls with identical arguments return the sameMeshinstance.tile_sizeorlevel_heightreturn different instances, each correctly sized.type.meshstill short-circuits and is never cached.clear_cache()empties it, and the GUT suite passes with it wired intobefore_each.