Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix interior-window per-pane id precision loss in Float32Array (codex review)

[._.]/ Adam Eivycdf5dd3512d5
diff --git a/client/src/utils/cityInteriorWindows.js b/client/src/utils/cityInteriorWindows.js
index d980680da4..ae5ba30484 100644
--- a/client/src/utils/cityInteriorWindows.js
+++ b/client/src/utils/cityInteriorWindows.js
@@ -91,10 +91,16 @@ export function computeWindowGrid({ width, depth, height, seed = 0 }) {
? [h, y, face.sign * offset]
: [face.sign * offset, y, h];
// Deterministic, well-spread seed per pane so the shader hash varies
- // per window, per face, and per building.
+ // per window, per face, and per building. Keep every component SMALL: the
+ // IDs round-trip through a Float32Array for the instanced attribute, and
+ // float32 loses sub-integer precision past ~16.7M — a raw app-name hash
+ // (hundreds of millions) would swamp the c/r offsets and collapse every
+ // pane on a face to one room. A bounded per-building phase shifts the
+ // hash input without dominating the per-pane column/row offsets.
+ const phase = seed % 360;
const windowId = [
- c + face.index * 3.1 + seed * 0.37,
- r + face.index * 1.7 + seed * 0.21,
+ c + face.index * 2.3 + phase * 0.11,
+ r + face.index * 1.7 + phase * 0.07,
face.index + (seed % 17) * 0.13,
];
windows.push({ position, rotationY: face.rotationY, windowId });
diff --git a/client/src/utils/cityInteriorWindows.test.js b/client/src/utils/cityInteriorWindows.test.js
index 4d2e0522a9..8e2ad366ff 100644
--- a/client/src/utils/cityInteriorWindows.test.js
+++ b/client/src/utils/cityInteriorWindows.test.js
@@ -55,6 +55,19 @@ describe('computeWindowGrid', () => {
expect(a[0].windowId).not.toEqual(b[0].windowId);
});
+ it('keeps per-pane window ids distinct after the Float32Array round-trip, even for a large hash', () => {
+ // The instanced attribute stores windowId in a Float32Array, which loses
+ // sub-integer precision past ~16.7M. A raw app-name hash this large must not
+ // collapse every pane on a face to the same id (which would make every room
+ // identical). Quantize through Float32Array exactly as the GPU upload does.
+ const windows = computeWindowGrid({ width: 3, depth: 2, height: 5, seed: 1234567890 });
+ const buf = new Float32Array(windows.length * 3);
+ windows.forEach((w, i) => buf.set(w.windowId, i * 3));
+ const keys = new Set(Array.from({ length: windows.length }, (_, i) => buf.slice(i * 3, i * 3 + 3).join(',')));
+ // Distinct ids per pane (allow a tiny collision margin from the modular phase).
+ expect(keys.size).toBeGreaterThan(windows.length * 0.9);
+ });
+
it('places panes proud of the correct face plane', () => {
const { width, depth } = dims;
const offset = depth / 2 + INTERIOR_WINDOW.inset;