Skip to content

Commit da85903

Browse files
David Engelhartclaude
andcommitted
lumopolis: a building's latency shows as heat
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 92af238 commit da85903

6 files changed

Lines changed: 45 additions & 7 deletions

File tree

‎e2e/world-engine.spec.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const WORLD_B = JSON.parse(fs.readFileSync(path.resolve('tests/shared/fixtures/w
9292
type Visual = { ringAngle: number; fogDrift: number; wirePulse: number; selectionRingAngle: number }
9393
interface Harness {
9494
load(doc: unknown, opts?: { animateFrom?: unknown }): void
95-
drawn(): { changing: number; visual: Visual }
95+
drawn(): { changing: number; visual: Visual; hot: string[] }
9696
project(id: string): Promise<{ x: number; y: number }>
9797
screenPoint(id: string): { x: number; y: number } | null
9898
}
@@ -163,6 +163,19 @@ test('reduced motion freezes the ring, fog drift, wireframe pulse and selection
163163
expect(d.fogDrift).not.toBe(c.fogDrift)
164164
})
165165

166+
test('a building with live latency is drawn hot, and one without is not', async () => {
167+
await page.goto(page.url().split('?')[0])
168+
await page.waitForSelector('body[data-ready="1"]', { timeout: 30_000 })
169+
const hot = await page.evaluate((a) => {
170+
const t = (window as unknown as HarnessWindow).__worldTest
171+
const doc = JSON.parse(JSON.stringify(a)) as { layers: { live?: unknown } }
172+
doc.layers.live = { b2: { latencyMs: 600 } }
173+
t.load(doc)
174+
return t.drawn().hot
175+
}, WORLD_A)
176+
expect(hot).toEqual(['b2'])
177+
})
178+
166179
test('logs no console errors', async () => {
167180
expect(consoleErrors).toEqual([])
168181
// The harness's own early collector also sees errors raised before the spec's listeners attached.

‎src/renderer/src/world/engine/createWorldViewer.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export interface WorldDrawn {
9898
outlined: string[]
9999
/** Ids of the buildings drawn fading: parts the shown proposal takes away (always empty in 2D). */
100100
fading: string[]
101+
/** Ids of the buildings drawn hot: their live latency is above 0 (always empty in 2D). */
102+
hot: string[]
101103
/** Ids an answer fogged (the evidence does not support them) until the next reset. */
102104
fogged: string[]
103105
/** Ids lit now (the buildings and lines a selection, a tech chip or an action asked for); empty when nothing is. */
@@ -338,6 +340,7 @@ export function createWorldViewer(container: HTMLElement, opts: WorldViewerOptio
338340
let wireframes: string[] = []
339341
let outlined: string[] = []
340342
let fading: string[] = []
343+
let hot: string[] = []
341344
function redraw(): void {
342345
const d = doc
343346
if (!d) return
@@ -346,6 +349,7 @@ export function createWorldViewer(container: HTMLElement, opts: WorldViewerOptio
346349
wireframes = model.buildings.filter((b) => b.look === 'wire').map((b) => b.id)
347350
outlined = model.buildings.filter((b) => b.outline).map((b) => b.id)
348351
fading = model.buildings.filter((b) => b.look === 'fading').map((b) => b.id)
352+
hot = model.buildings.filter((b) => b.heat > 0).map((b) => b.id)
349353
r3.draw(model, sceneText(d), layers.allLineLabels)
350354
r3.setExploded(exploded)
351355
if (selection && kindOf(selection.id)) {
@@ -638,7 +642,7 @@ export function createWorldViewer(container: HTMLElement, opts: WorldViewerOptio
638642
pickAt: (x, y) => (r3 ? r3.pick(x, y) : null),
639643
cameraState: () => (r3 ? r3.getCamera() : null),
640644
setCamera: (s, instant) => (r3 && !disposed ? r3.flyTo(s, instant || reduced) : Promise.resolve()),
641-
drawn: () => ({ layers: { ...layers }, ...(r3 ? r3.drawnCounts() : { processShells: 0, conduits: 0, changing: 0 }), wireframes: r3 ? [...wireframes] : [], outlined: r3 ? [...outlined] : [], fading: r3 ? [...fading] : [], fogged: [...fogged], highlighted: baseFocus ? [...baseFocus.ids, ...baseFocus.edgeIds] : [], visual: r3 ? r3.motionState() : { ringAngle: 0, fogDrift: 0, wirePulse: 0, selectionRingAngle: 0 } }),
645+
drawn: () => ({ layers: { ...layers }, ...(r3 ? r3.drawnCounts() : { processShells: 0, conduits: 0, changing: 0 }), wireframes: r3 ? [...wireframes] : [], outlined: r3 ? [...outlined] : [], fading: r3 ? [...fading] : [], hot: r3 ? [...hot] : [], fogged: [...fogged], highlighted: baseFocus ? [...baseFocus.ids, ...baseFocus.edgeIds] : [], visual: r3 ? r3.motionState() : { ringAngle: 0, fogDrift: 0, wirePulse: 0, selectionRingAngle: 0 } }),
642646
resetView() {
643647
cancelActions()
644648
deselect()

‎src/renderer/src/world/engine/sceneModel.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export function isMostlyInferred(b: Pick<Building, 'how' | 'why'>): boolean {
8686
return claims.filter((c) => c.state === 'inferred').length * 2 > claims.length
8787
}
8888

89+
/** The warm colour a building's glow moves toward as its latency rises. */
90+
export const HEAT_COLOR = '#ff6a2b'
91+
/** How far the glow colour moves toward HEAT_COLOR (0..0.75) and how much brighter it burns (1..1.8) at heat 0..1. Heat 0 changes nothing. */
92+
export function heatMix(heat: number): { toward: number; glow: number } {
93+
const h = Math.min(1, Math.max(0, heat))
94+
return { toward: h * 0.75, glow: 1 + h * 0.8 }
95+
}
96+
8997
/** Status to look. Precedence: proposed, mostly inferred, gap, built, then verified (solid plus ring). */
9098
export function lookOf(b: Building): { look: Look; ring: boolean } {
9199
if (b.status === 'proposed') return { look: 'wire', ring: false }

‎src/renderer/src/world/engine/threeRenderer.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { createCameraRig, type Vec3 as RigVec } from './cameraRig'
1414
import { createChangeAnimator } from './changeAnimation'
1515
import { focusOpacity } from './interaction'
1616
import { backOffs, busyness, clamp, clampIntoView, districtNameHalf, easeArea, edgeLabelSize, fitDistance, fitView, fogDensity, freeArea, inFreeArea, nameBudget, overviewDir, placeLabels, sameArea, toleratedPick, turnAcross, turnGround, viewFrame, type FreeArea, type LabelCandidate, type Nudge, type ScreenBox, type V3 } from './viewMath'
17-
import type { SceneBuilding, SceneConduit, SceneDistrict, SceneModel, SceneOrb, Vec3 } from './sceneModel'
17+
import { HEAT_COLOR, heatMix, type SceneBuilding, SceneConduit, SceneDistrict, SceneModel, SceneOrb, Vec3 } from './sceneModel'
1818
import type { Theme, ThemeName } from './themes'
1919

2020
/** Label strings and presentation lookups. The viewer derives these from the doc; the renderer only prints them. */
@@ -662,11 +662,13 @@ function buildThreeRenderer(host: HTMLElement, opts: RendererOptions, undo: Arra
662662
// A guessed-at building keeps its district's hue, washed toward the fog tint: still a building
663663
// of that district, only less certain.
664664
const lineColor = b.look === 'amber' ? extras.amber : ghost ? extras.ghost : b.look === 'fog' ? col.clone().lerp(new THREE.Color(extras.fogTint), 0.4) : col
665+
const heat = heatMix(b.heat)
666+
const glowColor = col.clone().lerp(new THREE.Color(HEAT_COLOR), heat.toward) // heat 0: the district colour itself
665667
const captions = text.floors[b.id] ?? []
666668
for (let k = 0; k < b.floors; k++) {
667669
const geo = new THREE.BoxGeometry(FLOOR_W, fh * 0.85, FLOOR_W)
668670
const mat = trackBase(new THREE.MeshStandardMaterial({
669-
color: extras.fill, emissive: col, emissiveIntensity: ghost ? 0.05 : extras.fillGlow, metalness: 0.5, roughness: 0.3,
671+
color: extras.fill, emissive: glowColor, emissiveIntensity: ghost ? 0.05 : extras.fillGlow * heat.glow, metalness: 0.5, roughness: 0.3,
670672
transparent: true, opacity: ghost ? 0.07 : b.look === 'fog' ? extras.fillOpacity * 0.6 : extras.fillOpacity, depthWrite: !ghost,
671673
}))
672674
n.mats.push(mat)

‎tests/renderer/world/createWorldViewer.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ describe('2D fallback: Esc, resetView, layers, theme', () => {
353353
expect(viewer.screenPoint('b1')).toBeNull()
354354
expect(viewer.linePoints('e1')).toEqual([])
355355
expect(viewer.pickAt(1, 2)).toBeNull()
356-
expect(viewer.drawn()).toEqual({ layers: { ...DEFAULT_LAYERS, processes: true }, processShells: 0, conduits: 0, changing: 0, wireframes: [], outlined: [], fading: [], fogged: [], highlighted: [], visual: { ringAngle: 0, fogDrift: 0, wirePulse: 0, selectionRingAngle: 0 } })
356+
expect(viewer.drawn()).toEqual({ layers: { ...DEFAULT_LAYERS, processes: true }, processShells: 0, conduits: 0, changing: 0, wireframes: [], outlined: [], fading: [], hot: [], fogged: [], highlighted: [], visual: { ringAngle: 0, fogDrift: 0, wirePulse: 0, selectionRingAngle: 0 } })
357357
})
358358

359359
it('keeps an existing tabindex and positioning', () => {
@@ -717,7 +717,7 @@ describe('WebGL path (stand-in renderer)', () => {
717717
aim({ kind: 'edge', id: 'e1' })
718718
expect(viewer.pickAt(3, 4)).toEqual({ kind: 'edge', id: 'e1' })
719719
expect(r.pick).toHaveBeenLastCalledWith(3, 4)
720-
expect(viewer.drawn()).toEqual({ layers: DEFAULT_LAYERS, processShells: 2, conduits: 3, changing: 1, wireframes: ['b4'], outlined: [], fading: [], fogged: [], highlighted: [], visual: { ringAngle: 1, fogDrift: 2, wirePulse: 3, selectionRingAngle: 4 } })
720+
expect(viewer.drawn()).toEqual({ layers: DEFAULT_LAYERS, processShells: 2, conduits: 3, changing: 1, wireframes: ['b4'], outlined: [], fading: [], hot: [], fogged: [], highlighted: [], visual: { ringAngle: 1, fogDrift: 2, wirePulse: 3, selectionRingAngle: 4 } })
721721
})
722722

723723
it('viewer.apply(fog) fogs the ids until the next reset; a highlight keeps the fog; resetView, load and an empty fog lift it', async () => {

‎tests/renderer/world/sceneModel.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest'
2-
import { buildSceneModel, conduitStyle, DEFAULT_LAYERS, isMostlyInferred, lookOf } from '../../../src/renderer/src/world/engine/sceneModel'
2+
import { buildSceneModel, conduitStyle, DEFAULT_LAYERS, heatMix, HEAT_COLOR, isMostlyInferred, lookOf } from '../../../src/renderer/src/world/engine/sceneModel'
33
import { NOT_IN_DESIGN } from '../../../src/shared/world/reconcile'
44
import { building, claim, edge, minimal, rich } from './helpers'
55

@@ -289,3 +289,14 @@ describe('linked design overlay', () => {
289289
expect(both.buildings.map((b) => b.id)).toEqual(['b1', 'b2', 'pm', 'q1'])
290290
})
291291
})
292+
293+
describe('heatMix', () => {
294+
it('changes nothing at heat 0, and warms and brightens as heat rises, within bounds', () => {
295+
expect(heatMix(0)).toEqual({ toward: 0, glow: 1 })
296+
expect(heatMix(1)).toEqual({ toward: 0.75, glow: 1.8 })
297+
expect(heatMix(0.5).toward).toBeCloseTo(0.375)
298+
expect(heatMix(7)).toEqual(heatMix(1))
299+
expect(heatMix(-3)).toEqual(heatMix(0))
300+
expect(HEAT_COLOR).toMatch(/^#[0-9a-f]{6}$/)
301+
})
302+
})

0 commit comments

Comments
 (0)