space-browser / commits / ee5468a
fix: sampling and easing.
This really changed the look of the game!
@@ -6,7 +6,7 @@
66 import { CELL } from './view';
77 import { toWorld } from './sim';
88 import { at, cam, cellOf, rect, screen, screenOf } from './stage';
9-import { loose, ore, ships, state } from './world';
9+import { bodies, loose, ore, ships, state } from './world';
1010
1111 type Target = {
1212 id: number;
@@ -76,7 +76,7 @@ const targets = (): Target[] => {
7676 }
7777 for (const l of loose.values()) add(l.id, 'loose', 0, l.x, l.y);
7878 for (const o of ore.values()) add(o.id, 'ore', 0, o.x, o.y);
79- for (const b of state?.bodies ?? []) add(b.id, b.kind, 0, b.x, b.y);
79+ for (const b of bodies.values()) add(b.id, b.kind, 0, b.x, b.y);
8080 return out.sort((a, b) => a.d - b.d);
8181 };
8282
@@ -5,7 +5,7 @@ import { bind, pointer, step } from './input';
55 import { toWorld } from './sim';
66 import { at, cam, canvas, cellOf, wpc } from './stage';
77 import { PIECE_R, TONE, View } from './view';
8-import { apply, follow, loose, ore, own, shots, ships, state } from './world';
8+import { apply, bodies, follow, loose, ore, own, shots, ships, state } from './world';
99
1010 const view = new View(canvas);
1111 addEventListener('resize', () => view.resize());
@@ -29,7 +29,7 @@ const spot = (x: number, y: number) => {
2929 if (s.id === state?.you) continue; // your own hull is not a target
3030 if (s.pieces.some((p) => over(x, y, toWorld(s, p), PIECE_R))) return TONE.hull;
3131 }
32- for (const b of state?.bodies ?? []) if (over(x, y, b, b.r)) return TONE.body;
32+ for (const b of bodies.values()) if (over(x, y, b, b.r)) return TONE.body;
3333 return TONE.space;
3434 };
3535
@@ -58,7 +58,7 @@ function frame(): void {
5858 } else {
5959 view.draw(
6060 cam,
61- state?.bodies ?? [],
61+ [...bodies.values()],
6262 [...ships.values()],
6363 state?.you ?? 0,
6464 [...shots.values()],
@@ -12,10 +12,12 @@ import { free, plate } from './shapes';
1212
1313 // A system is the one bright thing in its space: a gold core with four dim rays,
1414 // 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.
15+// never read as a player. Every ship is one white cell, and yours is the only one
16+// at full brightness: on a map of the population you have to find yourself first.
1617 const CORE = lum(0.95, 6);
1718 const RAY = lum(0.45, 6);
18-const PLAYER = lum(1, 12);
19+const OWN = lum(1, 12);
20+const OTHER = lum(0.7, 12);
1921
2022 const systemMark = (): THREE.Group => {
2123 const g = new THREE.Group();
@@ -35,7 +37,7 @@ export class Galaxy {
3537
3638 // Marks are placed from the camera, like the order marker: a pan slides the map
3739 // under glyphs that never move, and a dot never straddles four of them.
38- show(cam: Camera, systems: System[], ships: Ship[], wpc: number, cols: number, rows: number): void {
40+ show(cam: Camera, systems: System[], ships: Ship[], ownId: number, wpc: number, cols: number, rows: number): void {
3941 const stars = new Set<number>();
4042 for (const s of systems) {
4143 stars.add(s.id);
@@ -63,10 +65,10 @@ export class Galaxy {
6365 let m = this.ships.get(s.id);
6466 if (!m) {
6567 m = plate(1, 1, 1);
66- m.material.color.copy(PLAYER);
6768 this.ships.set(s.id, m);
6869 this.scene.add(m);
6970 }
71+ m.material.color.copy(s.id === ownId ? OWN : OTHER);
7072 m.scale.setScalar(wpc);
7173 m.position.set(snapCell(s.x, cam.x, wpc, cols), snapCell(s.y, cam.y, wpc, rows, -1), 0);
7274 }
@@ -62,7 +62,6 @@ export class View {
6262 this.fuelBar.add(m);
6363 }
6464 this.rt = new THREE.WebGLRenderTarget(1, 1, {
65- samples: 4,
6665 depthBuffer: false,
6766 stencilBuffer: false,
6867 minFilter: THREE.LinearFilter,
@@ -322,7 +321,7 @@ export class View {
322321 // the cell a hull, an ore or a round is not a glyph, it is noise.
323322 drawGalaxy(cam: Camera, systems: System[], ships: Ship[], ownId: number): void {
324323 const wpc = this.frame(cam);
325- this.galaxy.show(cam, systems, ships, wpc, this.cols, this.rows);
324+ this.galaxy.show(cam, systems, ships, ownId, wpc, this.cols, this.rows);
326325 // No map hint on the map itself: you are already there.
327326 this.fuel(ships.find((s) => s.id === ownId), performance.now() / 1000, false);
328327 this.present(this.galaxy.scene);
@@ -3,13 +3,14 @@
33 // anything, and the camera that follows our ship rides along with it.
44 import { connect, type State } from './net';
55 import { pull } from './pull';
6-import type { Loose, Ore, Ship, Shot } from './sim';
6+import type { Body, Loose, Ore, Ship, Shot } from './sim';
77 import { cam, snap } from './stage';
88
99 export let state: State | null = null;
1010 export const ships = new Map<number, Ship>();
1111 export const loose = new Map<number, Loose>();
1212 export const ore = new Map<number, Ore>();
13+export const bodies = new Map<number, Body>();
1314 export const shots = new Map<number, Shot>();
1415
1516 const ease = (a: number, b: number, k: number) => a + (b - a) * k;
@@ -88,6 +89,16 @@ export function apply(dt: number): void {
8889 }
8990 for (const id of ore.keys()) if (!oreLive.has(id)) ore.delete(id);
9091
92+ // A planet revolves at tick rate too, so its drawn copy is eased just like a
93+ // hull: a body that jumped a whole tick would step its limb across cells.
94+ const bodyLive = new Set<number>();
95+ for (const b of state.bodies) {
96+ bodyLive.add(b.id);
97+ const d = bodies.get(b.id);
98+ bodies.set(b.id, d ? { ...b, x: ease(d.x, b.x, k), y: ease(d.y, b.y, k) } : { ...b });
99+ }
100+ for (const id of bodies.keys()) if (!bodyLive.has(id)) bodies.delete(id);
101+
91102 const shotLive = new Set<number>();
92103 for (const s of state.shots ?? []) {
93104 shotLive.add(s.id);