xonecas.ioDon't click! Sean Caetano Martin Sign in

space-browser / commits / b21f8a5

feat: galaxy map

xonecas5 weeks agob21f8a5ae73f97f415d97b3bf13268c095246741parent 40cee9b15 files changed

client/src/dev.ts+10-1
@@ -38,6 +38,7 @@ const canvasBox = () => boxOf(rect());
3838
3939 const targets = (): Target[] => {
4040 const me = ships.get(state?.you ?? 0);
41+ const galaxy = cam.scene === 'galaxy';
4142 const r = rect();
4243 const box = boxOf(r);
4344 const out: Target[] = [];
@@ -59,12 +60,20 @@ const targets = (): Target[] => {
5960 });
6061 };
6162 for (const s of ships.values()) {
63+ if (galaxy && s.ai) continue; // the map draws players only
6264 add(s.id, s.id === state?.you ? 'me' : s.ai ? 'ai' : 'ship', 0, s.x, s.y);
65+ if (galaxy) continue; // and one dot per ship, not its hull
6366 for (const p of s.pieces) {
6467 const w = toWorld(s, p);
6568 add(p.id, 'piece', s.id, w.x, w.y);
6669 }
6770 }
71+ if (galaxy) {
72+ // The map draws systems and nothing else: a body, an ore or a round is not a
73+ // glyph at this scale, so it is not a target either.
74+ for (const s of state?.systems ?? []) add(s.id, 'system', 0, s.x, s.y);
75+ return out.sort((a, b) => a.d - b.d);
76+ }
6877 for (const l of loose.values()) add(l.id, 'loose', 0, l.x, l.y);
6978 for (const o of ore.values()) add(o.id, 'ore', 0, o.x, o.y);
7079 for (const b of state?.bodies ?? []) add(b.id, b.kind, 0, b.x, b.y);
@@ -77,7 +86,7 @@ const label = dev ? document.createElement('pre') : null;
7786
7887 const game = {
7988 get cam() {
80- return { x: cam.x, y: cam.y, zoom: cam.zoom, follow: cam.follow };
89+ return { x: cam.x, y: cam.y, zoom: cam.zoom, follow: cam.follow, scene: cam.scene };
8190 },
8291 get state() {
8392 return state;
client/src/input.ts+19-1
@@ -2,7 +2,7 @@
22 // server decides what happened. The only local decisions are the camera's.
33 import { aim } from './dev';
44 import { pull } from './pull';
5-import { at, cam, pan, wpc, wpp, zoomAt } from './stage';
5+import { at, cam, pan, switchScene, wpc, wpp, zoomAt } from './stage';
66 import { send } from './world';
77
88 const keys = new Set<string>();
@@ -16,6 +16,17 @@ let hover: { clientX: number; clientY: number } | null = null; // the pointer on
1616 // re-read every frame because panning moves the cell under a still pointer.
1717 export const pointer = () => hover;
1818
19+// Whatever is in hand goes back to the server where it was let go, so a piece can
20+// never ride a scene change out to a galaxy-scale coordinate.
21+const release = () => {
22+ if (!pulling) return;
23+ pulling = false;
24+ const p = pull.to;
25+ pullTo = null;
26+ pull.to = null;
27+ if (p) send({ t: 'drop', x: p.x, y: p.y });
28+};
29+
1930 export function bind(): void {
2031 addEventListener('pointerdown', (e) => {
2132 hover = e;
@@ -24,6 +35,7 @@ export function bind(): void {
2435 pan0 = { x: e.clientX, y: e.clientY };
2536 return;
2637 }
38+ if (cam.scene === 'galaxy') return; // the map has nothing to pick up yet
2739 const p = at(e);
2840 pulling = true;
2941 pull.to = p; // the piece in hand sits under the pointer, not a tick behind it
@@ -62,6 +74,12 @@ export function bind(): void {
6274 addEventListener('keydown', (e) => {
6375 keys.add(e.code);
6476 if (e.code === 'Space') cam.follow = true;
77+ // The map is a map: it opens on the galaxy as a whole, and whatever you panned
78+ // and zoomed it to the last time is exactly where it still is.
79+ if (e.code === 'KeyM') {
80+ release();
81+ switchScene(cam.scene === 'local' ? 'galaxy' : 'local');
82+ }
6583 });
6684 addEventListener('keyup', (e) => keys.delete(e.code));
6785 }
client/src/main.ts+23-11
@@ -3,7 +3,7 @@
33 import { install } from './dev';
44 import { bind, pointer, step } from './input';
55 import { toWorld } from './sim';
6-import { at, cam, canvas, cellOf } from './stage';
6+import { at, cam, canvas, cellOf, wpc } from './stage';
77 import { PIECE_R, TONE, View } from './view';
88 import { apply, follow, loose, ore, own, shots, ships, state } from './world';
99
@@ -16,7 +16,15 @@ bind();
1616 // as round as it is drawn. Nothing here decides anything, it only names the cell.
1717 const over = (x: number, y: number, p: { x: number; y: number }, r: number) =>
1818 (x - p.x) ** 2 + (y - p.y) ** 2 <= r * r;
19+// On the map every mark is exactly one cell wide, so it is hit as one cell.
20+const tile = (x: number, y: number) => {
21+ const r = wpc();
22+ for (const s of ships.values()) if (s.id !== state?.you && !s.ai && over(x, y, s, r)) return TONE.hull;
23+ for (const s of state?.systems ?? []) if (over(x, y, s, r)) return TONE.body;
24+ return TONE.space;
25+};
1926 const spot = (x: number, y: number) => {
27+ if (cam.scene === 'galaxy') return tile(x, y);
2028 for (const s of ships.values()) {
2129 if (s.id === state?.you) continue; // your own hull is not a target
2230 if (s.pieces.some((p) => over(x, y, toWorld(s, p), PIECE_R))) return TONE.hull;
@@ -44,16 +52,20 @@ function frame(): void {
4452
4553 // The marker is the order the server is flying: never a click of our own.
4654 const me = own();
47- view.draw(
48- cam,
49- state?.bodies ?? [],
50- [...ships.values()],
51- state?.you ?? 0,
52- [...shots.values()],
53- [...loose.values()],
54- [...ore.values()],
55- me && !state?.held ? { x: me.tx, y: me.ty } : null,
56- );
55+ if (cam.scene === 'galaxy') {
56+ view.drawGalaxy(cam, state?.systems ?? [], [...ships.values()], state?.you ?? 0);
57+ } else {
58+ view.draw(
59+ cam,
60+ state?.bodies ?? [],
61+ [...ships.values()],
62+ state?.you ?? 0,
63+ [...shots.values()],
64+ [...loose.values()],
65+ [...ore.values()],
66+ me && !state?.held ? { x: me.tx, y: me.ty } : null,
67+ );
68+ }
5769 requestAnimationFrame(frame);
5870 }
5971 requestAnimationFrame(frame);
client/src/net.ts+2-1
@@ -1,11 +1,12 @@
11 // One socket is one player. The server owns the world; we send intents and are
22 // handed back the state to draw.
3-import type { Body, Loose, Ore, Ship, Shot } from './sim';
3+import type { Body, Loose, Ore, Ship, Shot, System } from './sim';
44
55 export type State = {
66 you: number;
77 held: number;
88 bodies: Body[];
9+ systems: System[];
910 loose: Loose[];
1011 ore: Ore[];
1112 shots: Shot[];
client/src/sim.ts+2-0
@@ -26,6 +26,8 @@ export type Loose = {
2626 export type Ore = { id: number; x: number; y: number; h: number; towed: number };
2727 export type Shot = { id: number; x: number; y: number; h: number };
2828 export type Body = { id: number; kind: 'star' | 'shipyard' | 'barren'; r: number; x: number; y: number };
29+// The centre a system's bodies circle: one mark on the galaxy map.
30+export type System = { id: number; x: number; y: number };
2931
3032 export type Ship = {
3133 id: number;
client/src/stage.ts+19-4
@@ -1,10 +1,23 @@
11 // The stage: the canvas the game is drawn on, and the camera over it. Anything that
22 // has to turn a world point into a screen pixel, or back, asks here and nowhere else.
3-import { CELL, CELL_WORLD, ZOOM_MAX, ZOOM_MIN, type Camera } from './view';
3+import { CELL, CELL_WORLD, GALAXY_MAX, GALAXY_MIN, ZOOM_MAX, ZOOM_MIN, type Camera } from './view';
44
55 export const canvas = document.getElementById('view') as HTMLCanvasElement;
66
7-export const cam: Camera & { follow: boolean } = { x: 0, y: 0, zoom: ZOOM_MIN, follow: true };
7+export type Scene = 'local' | 'galaxy';
8+type Cam = Camera & { follow: boolean; scene: Scene };
9+
10+// Two scenes, two cameras: the map keeps the pan and zoom you left it at, and
11+// coming back to local space finds that camera exactly where it was, following or
12+// not.
13+const cams: Record<Scene, Cam> = {
14+ local: { x: 0, y: 0, zoom: ZOOM_MIN, follow: true, scene: 'local' },
15+ galaxy: { x: 0, y: 0, zoom: GALAXY_MIN, follow: false, scene: 'galaxy' },
16+};
17+export let cam: Cam = cams.local;
18+export const switchScene = (s: Scene): void => {
19+ cam = cams[s];
20+};
821
922 export const wpc = () => CELL_WORLD / cam.zoom; // world units per character cell
1023 export const wpp = () => wpc() / CELL; // world units per css px
@@ -39,10 +52,12 @@ export const cellOf = (px: number, py: number, r = rect()) => ({
3952 cellY: Math.floor((py - r.top) / CELL),
4053 });
4154
42-// Zoom is multiplicative and anchored on the world point under the cursor.
55+// Zoom is multiplicative and anchored on the world point under the cursor, and it
56+// stops at the range of the scene it is in.
4357 export const zoomAt = (e: { clientX: number; clientY: number; deltaY: number }) => {
4458 const a = at(e);
45- const z = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, cam.zoom * Math.exp(-e.deltaY * 0.0015)));
59+ const [lo, hi] = cam.scene === 'galaxy' ? [GALAXY_MIN, GALAXY_MAX] : [ZOOM_MIN, ZOOM_MAX];
60+ const z = Math.min(hi, Math.max(lo, cam.zoom * Math.exp(-e.deltaY * 0.0015)));
4661 if (z === cam.zoom) return;
4762 cam.zoom = z;
4863 const b = at(e);
client/src/view/galaxy.ts+80-0
@@ -0,0 +1,80 @@
1+// Scene 2: the galaxy map. One mark per star system and one per living player,
2+// drawn in cells rather than in world units, so a dot is a glyph at every map
3+// zoom instead of a sub-cell smudge the raster averages away. The systems are the
4+// rings the generator lays out; nothing here adds a shape the galaxy does not have.
5+import * as THREE from 'three';
6+import type { Ship, System } from '../sim';
7+import { snapCell } from './grid';
8+import type { Camera } from './index';
9+import { lum } from './ink';
10+import type { Part } from './pieces';
11+import { free, plate } from './shapes';
12+
13+// A system is the one bright thing in its space: a gold core with four dim rays,
14+// which is also the only mark that is more than a single cell, so a system is
15+// never read as a player. Ships are one white cell each, yours included.
16+const CORE = lum(0.95, 6);
17+const RAY = lum(0.45, 6);
18+const PLAYER = lum(1, 12);
19+
20+const systemMark = (): THREE.Group => {
21+ const g = new THREE.Group();
22+ for (const [dx, dy] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) {
23+ const p = plate(1, 1, 1);
24+ p.material.color.copy(dx || dy ? RAY : CORE);
25+ p.position.set(dx, dy, 0);
26+ g.add(p);
27+ }
28+ return g;
29+};
30+
31+export class Galaxy {
32+ readonly scene = new THREE.Scene();
33+ private stars = new Map<number, THREE.Group>();
34+ private ships = new Map<number, Part>();
35+
36+ // Marks are placed from the camera, like the order marker: a pan slides the map
37+ // under glyphs that never move, and a dot never straddles four of them.
38+ show(cam: Camera, systems: System[], ships: Ship[], wpc: number): void {
39+ const stars = new Set<number>();
40+ for (const s of systems) {
41+ stars.add(s.id);
42+ let g = this.stars.get(s.id);
43+ if (!g) {
44+ g = systemMark();
45+ this.stars.set(s.id, g);
46+ this.scene.add(g);
47+ }
48+ g.scale.setScalar(wpc); // the mark is built in cells, the map is in world units
49+ g.position.set(snapCell(s.x, cam.x, wpc), snapCell(s.y, cam.y, wpc), 0);
50+ }
51+ for (const [id, g] of this.stars) {
52+ if (stars.has(id)) continue;
53+ free(g);
54+ this.scene.remove(g);
55+ this.stars.delete(id);
56+ }
57+ // Only real players: an AI hull never leaves its system, so it says nothing
58+ // about where the population is.
59+ const live = new Set<number>();
60+ for (const s of ships) {
61+ if (s.ai) continue;
62+ live.add(s.id);
63+ let m = this.ships.get(s.id);
64+ if (!m) {
65+ m = plate(1, 1, 1);
66+ m.material.color.copy(PLAYER);
67+ this.ships.set(s.id, m);
68+ this.scene.add(m);
69+ }
70+ m.scale.setScalar(wpc);
71+ m.position.set(snapCell(s.x, cam.x, wpc), snapCell(s.y, cam.y, wpc), 0);
72+ }
73+ for (const [id, m] of this.ships) {
74+ if (live.has(id)) continue;
75+ free(m);
76+ this.scene.remove(m);
77+ this.ships.delete(id);
78+ }
79+ }
80+}
client/src/view/grid.ts+7-0
@@ -4,6 +4,13 @@ export const CELL = 12; // css px per character cell
44 export const CELL_WORLD = 2; // world units per character cell at zoom 1
55 export const ZOOM_MIN = 0.5; // furthest out: far enough to frame a whole system
66 export const ZOOM_MAX = 1.8; // closest in
7+// The galaxy map is the same camera over a much wider frame: a whole galaxy of
8+// ~6100 world units fits even a short window at ~167 world units to the cell, and
9+// the closest it goes still holds a third of the galaxy in view, so the map never
10+// zooms into the empty space between its own marks. The two ranges do not meet, so
11+// no zoom level drifts between the scenes.
12+export const GALAXY_MIN = 0.012;
13+export const GALAXY_MAX = 0.05;
714
815 // Snap a world point to the centre of the cell that holds it: a one-cell mark has
916 // to land on a glyph, not straddle four of them.
client/src/view/index.ts+50-14
@@ -2,15 +2,16 @@
22 // fullscreen pass that turns it into glyphs. It draws what it is handed and keeps
33 // only the meshes that belong to an id, so a piece keeps its mesh for its whole life.
44 import * as THREE from 'three';
5-import { toWorld, type Body, type Kind, type Loose, type Ore, type Ship, type Shot } from '../sim';
5+import { toWorld, type Body, type Kind, type Loose, type Ore, type Ship, type Shot, type System } from '../sim';
66 import { barrenMesh, shipyardMesh, starMesh } from './bodies';
7+import { Galaxy } from './galaxy';
78 import { CELL, CELL_WORLD, snapCell } from './grid';
89 import { FRAG, GLYPHS, PALETTE, VERT, lum, paletteTexture, textAtlas } from './ink';
910 import { crosshair, reticle, TONE } from './marks';
1011 import { oreChunk, paint, piece, shade, type Part, type Role, type Wear } from './pieces';
1112 import { free, plate } from './shapes';
1213
13-export { CELL, CELL_WORLD, ZOOM_MAX, ZOOM_MIN } from './grid';
14+export { CELL, CELL_WORLD, GALAXY_MAX, GALAXY_MIN, ZOOM_MAX, ZOOM_MIN } from './grid';
1415 export { TONE } from './marks';
1516 export { PIECE_R } from './shapes';
1617
@@ -18,6 +19,7 @@ const SHOT_LEN = 13; // world units of laser line behind a round
1819 const SHOT_W = 1.6; // world units thick: one bright cell wide
1920 const FUEL_CELLS = 12; // the fuel gauge is this many cells wide at any zoom
2021 const FUEL_WORD = 'FUEL'; // a word, not glyphs: letters are spelled out per cell
22+const MAP_WORD = '[M]AP'; // the hint that there is a second scene, under the bar
2123
2224 export type Camera = { x: number; y: number; zoom: number };
2325 export class View {
@@ -35,6 +37,7 @@ export class View {
3537 private cursor = reticle();
3638 private hud = new THREE.Scene();
3739 private hudCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
40+ private galaxy = new Galaxy();
3841 private fuelBar = new THREE.Group();
3942 private fuelCells: Part[] = [];
4043 private cols = 0;
@@ -78,6 +81,9 @@ export class View {
7881 uWord: { value: textAtlas(FUEL_WORD) },
7982 uWordCell: { value: new THREE.Vector4() },
8083 uWordCol: { value: new THREE.Color(PALETTE[5]) },
84+ uWord2: { value: textAtlas(MAP_WORD) },
85+ uWord2Cell: { value: new THREE.Vector4() },
86+ uWord2Col: { value: new THREE.Color(PALETTE[4]) },
8187 },
8288 });
8389 const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this.pass);
@@ -170,10 +176,12 @@ export class View {
170176
171177 // The fuel gauge is a row of cells two rows off the bottom of the screen, in a
172178 // layer that only knows about cells. Gold while there is plenty, and a red pulse
173- // that quickens as the tank empties.
174- private fuel(own: Ship | undefined, t: number): void {
179+ // that quickens as the tank empties. To its right, the map hint, which is a
180+ // reminder of a control and not a control of its own.
181+ private fuel(own: Ship | undefined, t: number, hint = true): void {
175182 this.fuelBar.visible = !!own && own.fuelmax > 0;
176183 this.pass.uniforms.uWordCell.value.set(0, 0, 0, 0); // no tank, no word
184+ this.pass.uniforms.uWord2Cell.value.set(0, 0, 0, 0);
177185 if (!own || own.fuelmax <= 0) return;
178186 const start = Math.floor((this.cols - FUEL_CELLS) / 2);
179187 const ratio = Math.max(0, Math.min(1, own.fuel / own.fuelmax));
@@ -185,9 +193,14 @@ export class View {
185193 // A cell t is centred on t+0.5 measured from the edge, so this lands on glyphs.
186194 const x = start - this.cols / 2 + 0.5;
187195 const y = 2 - this.rows / 2 + 0.5;
188- // The label sits on the same row, one cell clear of the bar.
196+ // The label sits on the same row, one cell clear of the bar, and the hint sits
197+ // one cell clear of the bar's other end.
189198 const w = Math.max(0, start - 1 - FUEL_WORD.length);
190199 this.pass.uniforms.uWordCell.value.set(w, 2, FUEL_WORD.length, 1);
200+ if (hint) {
201+ const h = Math.min(start + FUEL_CELLS + 1, this.cols - MAP_WORD.length);
202+ this.pass.uniforms.uWord2Cell.value.set(h, 2, MAP_WORD.length, 1);
203+ }
191204 for (let i = 0; i < FUEL_CELLS; i++) {
192205 const m = this.fuelCells[i];
193206 m.position.set(x + i, y, 0);
@@ -208,14 +221,7 @@ export class View {
208221 ): void {
209222 // Zoom is world units per character cell: the raster keeps one texel per
210223 // cell, so zooming only changes how much world a cell covers.
211- const wpc = CELL_WORLD / cam.zoom;
212- const hw = (this.cols / 2) * wpc;
213- const hh = (this.rows / 2) * wpc;
214- this.camera.left = -hw;
215- this.camera.right = hw;
216- this.camera.top = hh;
217- this.camera.bottom = -hh;
218- this.camera.updateProjectionMatrix();
224+ const wpc = this.frame(cam);
219225 // Bodies sit behind the ships: the server says where, we only draw them.
220226 this.bodies(bodies, performance.now() / 1000);
221227
@@ -287,10 +293,40 @@ export class View {
287293 }
288294 this.fuel(ships.find((s) => s.id === ownId), performance.now() / 1000);
289295
296+ this.present(this.scene);
297+ }
298+
299+ // Scene 2: the map. Nothing of local space is drawn: at a hundred world units to
300+ // the cell a hull, an ore or a round is not a glyph, it is noise.
301+ drawGalaxy(cam: Camera, systems: System[], ships: Ship[], ownId: number): void {
302+ const wpc = this.frame(cam);
303+ this.galaxy.show(cam, systems, ships, wpc);
304+ // No map hint on the map itself: you are already there.
305+ this.fuel(ships.find((s) => s.id === ownId), performance.now() / 1000, false);
306+ this.present(this.galaxy.scene);
307+ }
308+
309+ // The frustum is one rectangle of whole cells in either scene: only how much
310+ // world a cell covers changes.
311+ private frame(cam: Camera): number {
312+ const wpc = CELL_WORLD / cam.zoom;
313+ const hw = (this.cols / 2) * wpc;
314+ const hh = (this.rows / 2) * wpc;
315+ this.camera.left = -hw;
316+ this.camera.right = hw;
317+ this.camera.top = hh;
318+ this.camera.bottom = -hh;
319+ this.camera.updateProjectionMatrix();
290320 this.camera.position.set(cam.x, cam.y, 10);
321+ return wpc;
322+ }
323+
324+ // Down to one texel per cell, the HUD over it, then the pass that turns every
325+ // texel into a glyph. Both scenes end here.
326+ private present(scene: THREE.Scene): void {
291327 this.renderer.setRenderTarget(this.rt);
292328 this.renderer.clear();
293- this.renderer.render(this.scene, this.camera);
329+ this.renderer.render(scene, this.camera);
294330 this.renderer.autoClear = false; // the HUD draws over the world, cell for cell
295331 this.renderer.render(this.hud, this.hudCam);
296332 this.renderer.autoClear = true;
client/src/view/ink.ts+14-4
@@ -58,6 +58,18 @@ uniform float uCellPx;
5858 uniform sampler2D uWord; // hud ink, in cells, drawn over the glyphs
5959 uniform vec4 uWordCell; // x, y, width, height of the word, in cells from the corner
6060 uniform vec3 uWordCol;
61+uniform sampler2D uWord2; // a second word, on the same row as the first
62+uniform vec4 uWord2Cell;
63+uniform vec3 uWord2Col;
64+
65+// One word, spelled from its own atlas and placed in cells. A zero-sized rect
66+// covers nothing, which is also how a word is hidden.
67+vec3 spell(vec3 col, vec2 uv, sampler2D atlas, vec4 cell, vec3 ink) {
68+ vec2 w = (uv - cell.xy) / cell.zw;
69+ return (w.x >= 0.0 && w.x < 1.0 && w.y >= 0.0 && w.y < 1.0)
70+ ? mix(col, ink, texture2D(atlas, w).a)
71+ : col;
72+}
6173
6274 void main() {
6375 vec2 uv = gl_FragCoord.xy / uCellPx;
@@ -67,10 +79,8 @@ void main() {
6779 vec2 local = clamp(fract(uv), 0.02, 0.98);
6880 float ink = texture2D(uAtlas, vec2((band + local.x) / ${GLYPHS.length}.0, local.y)).a;
6981 vec3 outCol = mix(uBg, col, ink);
70- vec2 w = (uv - uWordCell.xy) / uWordCell.zw;
71- if (w.x >= 0.0 && w.x < 1.0 && w.y >= 0.0 && w.y < 1.0) {
72- outCol = mix(outCol, uWordCol, texture2D(uWord, w).a);
73- }
82+ outCol = spell(outCol, uv, uWord, uWordCell, uWordCol);
83+ outCol = spell(outCol, uv, uWord2, uWord2Cell, uWord2Col);
7484 gl_FragColor = vec4(outCol, 1.0);
7585 }
7686 `;
client/src/world.ts+3-2
@@ -95,10 +95,11 @@ export function apply(dt: number): void {
9595 }
9696 }
9797
98-// Keep our ship on screen, unless the player has panned away from it.
98+// Keep our ship on screen, unless the player has panned away from it. The map is
99+// a still picture of the whole galaxy: nothing to follow there.
99100 export function follow(dt: number): void {
100101 const me = own();
101- if (!cam.follow || !me) return;
102+ if (cam.scene !== 'local' || !cam.follow || !me) return;
102103 const c = 1 - Math.exp(-dt * 8);
103104 cam.x = ease(cam.x, me.x, c);
104105 cam.y = ease(cam.y, me.y, c);
server/galaxy.go+9-0
@@ -24,6 +24,14 @@ const (
2424 yardRim = 0.12 // and the same chance out at the rim
2525 )
2626
27+// A star system is the point its bodies circle. The map draws one mark per
28+// system, so that centre is the whole of what it needs to know.
29+type system struct {
30+ ID int `json:"id"`
31+ X float64 `json:"x"`
32+ Y float64 `json:"y"`
33+}
34+
2735 func (h *hub) galaxy() {
2836 for _, ring := range []struct {
2937 r float64
@@ -45,6 +53,7 @@ func (h *hub) galaxy() {
4553 // that systems exist.
4654 func (h *hub) system(cx, cy, r float64) {
4755 core := r == 0 // the only system at the very centre is the one a run starts in
56+ h.systems = append(h.systems, &system{ID: len(h.systems) + 1, X: cx, Y: cy})
4857 star := &body{Kind: "star", R: starMin + rand.Float64()*starVar, cx: cx, cy: cy}
4958 star.ID = len(h.bodies) + 1 // bodies are numbered as they are built
5059 h.bodies = append(h.bodies, star)
server/main.go+1-1
@@ -110,7 +110,7 @@ func (h *hub) handle(w http.ResponseWriter, r *http.Request) {
110110 // client, so you and held are zero. The socket stays the only way to act.
111111 func (h *hub) debugState(w http.ResponseWriter, r *http.Request) {
112112 h.mu.Lock()
113- b, err := json.Marshal(state{T: "state", Bodies: h.bodies, Loose: h.loose, Ore: h.ore, Shots: h.shots, Players: h.players()})
113+ b, err := json.Marshal(state{T: "state", Bodies: h.bodies, Systems: h.systems, Loose: h.loose, Ore: h.ore, Shots: h.shots, Players: h.players()})
114114 h.mu.Unlock()
115115 if err != nil {
116116 http.Error(w, err.Error(), http.StatusInternalServerError)
server/sim.go+1-1
@@ -113,7 +113,7 @@ func (h *hub) tick() {
113113 for c := range h.clients {
114114 b, err := json.Marshal(state{
115115 T: "state", You: c.p.ID, Held: c.p.held,
116- Bodies: h.bodies, Loose: h.loose, Ore: h.ore, Shots: h.shots, Players: players,
116+ Bodies: h.bodies, Systems: h.systems, Loose: h.loose, Ore: h.ore, Shots: h.shots, Players: players,
117117 })
118118 if err == nil {
119119 out[c] = b
server/world.go+2-0
@@ -189,6 +189,7 @@ type hub struct {
189189 clients map[*client]bool
190190 nextID int
191191 bodies []*body
192+ systems []*system
192193 spawns []int // shipyard bodies a new run may be born in orbit of, never at the rim
193194 loose []*loose
194195 ore []*ore
@@ -204,6 +205,7 @@ type state struct {
204205 You int `json:"you"`
205206 Held int `json:"held"`
206207 Bodies []*body `json:"bodies"`
208+ Systems []*system `json:"systems"`
207209 Loose []*loose `json:"loose"`
208210 Ore []*ore `json:"ore"`
209211 Shots []*shot `json:"shots"`