@typeonce/oxlint-plugin-ritmo 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +8 -4
- package/dist/rules/handle-tick-result.d.ts +3 -3
- package/dist/rules/handle-tick-result.js +8 -7
- package/dist/rules/handle-tick-result.js.map +1 -1
- package/dist/rules/keep-simulation-headless.d.ts.map +1 -1
- package/dist/rules/keep-simulation-headless.js +6 -3
- package/dist/rules/keep-simulation-headless.js.map +1 -1
- package/package.json +1 -1
- package/src/rules/handle-tick-result.ts +9 -7
- package/src/rules/keep-simulation-headless.ts +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# @typeonce/oxlint-plugin-ritmo
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 70d054e: **Rewind a runtime in memory, for rollback netcode and client prediction.** `runtime.checkpoint(simulate)` marks the world between ticks, and `runtime.rewind(checkpoint)` puts it back exactly: ticking `simulate` again gives the same results, bit for bit, as a runtime that never rewound (entity ids, values and their change ticks, relations, scopes, resources, machines, queued commands, unread events, and the read positions of `simulate`'s systems). See the `Checkpoint` module, and the skill's new `playbooks/netcode.md`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const history = new Map<number, Checkpoint.Checkpoint<typeof Root>>();
|
|
11
|
+
history.set(tick, runtime.checkpoint(simulate));
|
|
12
|
+
runtime.tick(simulate);
|
|
13
|
+
|
|
14
|
+
// Real input for an earlier tick differs from the guess: go back and run again.
|
|
15
|
+
const rewound = runtime.rewind(history.get(wrongTick)!);
|
|
16
|
+
if (!rewound.ok) resync(rewound.error); // Released: older than the window
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Taking a checkpoint copies only resources, machines, and queues; the first change to a page of values, an entity, a relation, or a scope after it keeps what it replaced. The runtime keeps the last `checkpoints` (a new option of `Game.Runtime.make`, `Checkpoint.defaultWindow` = 16 by default); an older one, one newer than a checkpoint rewound to, and every one taken before a `restore` fail with `Released`. A checkpoint of another runtime fails with `OtherRuntime`.
|
|
20
|
+
- A schedule that would not rewind does not compile, and the error (`__fixCheckpoint__`) names the fix: a service that is neither an input source (`snapshot()`) nor plain data, a system with `local` state (in its state transitions too), or a schedule widened to a schedule type.
|
|
21
|
+
- Systems and inspectors outside the rewound schedule, like renderers, see a rewind as ordinary changes. An entity the rewind took away and the ticks after it brought back under the same id is seen as changed, never as despawned and spawned again, so `RenderSync` keeps its node.
|
|
22
|
+
- **`runtime.checksum()`**: a fingerprint of what `snapshot()` saves, as 16 hex digits, that does not depend on how the world was built (component order, object key order). Peers compare it to catch a desync; gated like `snapshot`, and returns a `Result`.
|
|
23
|
+
- `Schedule.Source<Data>` and `Schedule.IsPlain<T>`: the input-source shape and the plain-data check that replays and checkpoints share. `Schedule.SystemsIn` is exported.
|
|
24
|
+
|
|
25
|
+
**Devtools:**
|
|
26
|
+
|
|
27
|
+
- **Breaking: `Replay.Source` and `Replay.IsPlain` moved to core**, as `Schedule.Source` and `Schedule.IsPlain`.
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
-const Controls = Descriptor.Service<Replay.Source<Input>>()("Game/Controls")
|
|
31
|
+
+import type * as Schedule from "@typeonce/ritmo/Schedule"
|
|
32
|
+
+const Controls = Descriptor.Service<Schedule.Source<Input>>()("Game/Controls")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- **Breaking: replay checkpoint hashes are `runtime.checksum()`.** Replays recorded with an earlier version report every checkpoint as diverged; record them again. A runtime passed to `Replay.recorder` or `Replay.session` needs `checksum`, which every runtime with `snapshot` has.
|
|
36
|
+
|
|
37
|
+
**Lint:** `handle-tick-result` also reports a dropped `runtime.rewind(...)` result: a released checkpoint changes nothing, and the ticks meant to run again would run on top of the present.
|
|
38
|
+
|
|
39
|
+
- dbfbd9d: **New package: `@typeonce/ritmo-netcode`, online multiplayer.** A session per peer exchanges inputs over a `NetworkLink` and ticks the simulation with every seat's input: `Netcode.rollback` runs at once on guesses and rolls back with the runtime's checkpoints when real input contradicts one; `Netcode.lockstep` waits for every seat. Seat 0 starts the match and every resync from one save that every peer restores at the same tick; `session.rate` slows the peer that runs ahead; peers compare checksums of confirmed ticks, and a mismatch stops the session with `Desynced` until `resync()`.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const seats = Netcode.seats(PlayerInput, { count: 2, idle }) // the simulation's input source
|
|
43
|
+
const session = Netcode.rollback(runtime, { simulate, seats: seats.value, seat, links: [WebSocketNetworkLink.make(socket)], hostClock, step })
|
|
44
|
+
FixedLoop.start({ ..., rate: session.value.rate, update: session.value.update({ input: readInput, onHalted: report }) })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- Transports: `WebSocketNetworkLink.make(socket)` (a relay; the browser's, Node's, Deno's, or Bun's WebSocket), `WebRtcNetworkLink.make(channel)` (between peers), `MemoryNetworkLink.make(...)` (seeded latency, jitter, and loss, for headless tests), or any `{ send, receive, status }`.
|
|
48
|
+
- What does not compile: a rollback simulation that cannot be rewound, one whose requirements the runtime does not provide, and a runtime that cannot save. What fails at construction, as a typed `Result`: a seat out of range, seats another session took or the runtime does not provide, and a `maxRollback` beyond the checkpoints the runtime keeps.
|
|
49
|
+
- The skill's `playbooks/netcode.md` now drives the package instead of a hand-written loop.
|
|
50
|
+
|
|
51
|
+
**Core:**
|
|
52
|
+
|
|
53
|
+
- `FixedLoop.start` takes `rate`, read once per frame, within `FixedLoop.rateRange` (0.9 to 1.1): how fast host time runs into the accumulator, for a networked session's pacing. A value outside the range stops the loop with an `InvalidRate` failure, a new member of `FixedLoop.Failure`.
|
|
54
|
+
- **`runtime.restore` sets the next entity id to the save's**, where it used to keep the higher of the save's and the runtime's own. The same save restored in two runtimes now allocates the same ids afterwards, whatever each held before; peers of a networked game need it. A handle kept from before a restore may now name an entity spawned after it: drop handles across a restore, as their ids could already name restored entities.
|
|
55
|
+
|
|
56
|
+
**Lint:** `keep-simulation-headless` reports `WebSocket`, `RTCPeerConnection`, and `RTCDataChannel` with their own message: online play runs the simulation under a netcode session, and remote input goes through `Netcode.seats`, never `runtime.send(...)`.
|
|
57
|
+
|
|
58
|
+
**Devtools:** `Desync.compare(mine, theirs)` lists every difference between two saves of a tick, entities by id and values by path: the report for a `Desynced` session made with `keepSnapshots: true`.
|
|
59
|
+
|
|
3
60
|
## 0.13.0
|
|
4
61
|
|
|
5
62
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ const started = performance.now()
|
|
|
62
62
|
| [`use-ops-for-math`](#ritmouse-ops-for-math) | simulation | `Math.sin`, `Math.hypot`, `a ** b`, ... | `Ops` |
|
|
63
63
|
| [`keep-simulation-headless`](#ritmokeep-simulation-headless) | simulation | page globals, host I/O, renderer imports | input and data from the host, drawing in a render schedule |
|
|
64
64
|
| [`no-infinity-in-simulation-data`](#ritmono-infinity-in-simulation-data) | simulation | `Infinity` / `NaN` in object literals | `null` |
|
|
65
|
-
| [`handle-tick-result`](#ritmohandle-tick-result) | everywhere | a dropped `runtime.tick(...)` / `restore(...)` result | check `.ok` |
|
|
65
|
+
| [`handle-tick-result`](#ritmohandle-tick-result) | everywhere | a dropped `runtime.tick(...)` / `restore(...)` / `rewind(...)` result | check `.ok` |
|
|
66
66
|
| [`prefix-descriptor-and-system-names`](#ritmoprefix-descriptor-and-system-names) | everywhere | `"Position"`, `Game.System("Move", ...)` | `"Game/Position"` |
|
|
67
67
|
| [`use-cell-value`](#ritmouse-cell-value) | everywhere | `cell.present ? cell.get() : undefined` | `cell.value()` |
|
|
68
68
|
| [`no-state-spread`](#ritmono-state-spread) | everywhere | `{ ...ground, _tag: "air", vy }` | `cell.transition({ from, to, data })`, `nextMachines.x.set({ _tag, ...fields })`, or the new state's fields written out |
|
|
@@ -124,7 +124,8 @@ The simulation runs in tests, bots, replays, and on servers, where there is no p
|
|
|
124
124
|
| Reported | Setup instead |
|
|
125
125
|
|---|---|
|
|
126
126
|
| Page globals: `window`, `document`, `navigator`, `matchMedia`, ... | Capture input in the host with `Keyboard`, `Gamepad`, `Pointer`, or `Touch` (merged with `Controls`) from `@typeonce/ritmo-browser` and `InputCapture` into a resource that systems read. Pass page state (size, settings) in with `runtime.send(...)` or a resource. |
|
|
127
|
-
| Host I/O: `localStorage`, `fetch`, `
|
|
127
|
+
| Host I/O: `localStorage`, `fetch`, `location`, ... | Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource. Save and load the world in the host with `runtime.snapshot()` and `runtime.restore(...)`. |
|
|
128
|
+
| Connections to other peers: `WebSocket`, `RTCPeerConnection`, `RTCDataChannel` | For online play, run the simulation under a [`@typeonce/ritmo-netcode`](https://github.com/typeonce-dev/ritmo/blob/main/packages/netcode/README.md) session: host code opens the connection and wraps it in a link, and remote input reaches the simulation through `Netcode.seats`, never `runtime.send(...)`. |
|
|
128
129
|
| Renderer and UI imports, types included: `pixi.js`, `three`, `@typeonce/ritmo-render`, `react`, `preact`, ... | Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare renderer services (a node registry) and their types there; renderer nodes stay in the registry, never in components. The schema and simulation systems name no renderer type, so another renderer can replace this one. |
|
|
129
130
|
|
|
130
131
|
Locals and fields with these names (`term.window`, a `location` parameter) are not globals and are not reported.
|
|
@@ -150,21 +151,24 @@ Catches `Infinity`, `-Infinity`, `NaN`, and `Number.POSITIVE_INFINITY` / `NEGATI
|
|
|
150
151
|
|
|
151
152
|
### `ritmo/handle-tick-result`
|
|
152
153
|
|
|
153
|
-
`runtime.tick(...)` returns a `Result`: a system that fails stops the tick, and the failure comes back here. `runtime.restore(...)` returns one too: an invalid save leaves the previous world in place. Dropping
|
|
154
|
+
`runtime.tick(...)` returns a `Result`: a system that fails stops the tick, and the failure comes back here. `runtime.restore(...)` returns one too: an invalid save leaves the previous world in place. So does `runtime.rewind(...)`: a checkpoint the runtime let go of changes nothing, and the ticks meant to run again run on top of the present. Dropping any of them hides the failure.
|
|
154
155
|
|
|
155
156
|
```ts
|
|
156
157
|
runtime.tick(update) // reported
|
|
157
158
|
runtime.restore(save) // reported
|
|
159
|
+
runtime.rewind(checkpoint) // reported
|
|
158
160
|
|
|
159
161
|
// instead
|
|
160
162
|
const ran = runtime.tick(update)
|
|
161
163
|
if (!ran.ok) console.error(ran.error) // names the system and why
|
|
162
164
|
const restored = runtime.restore(save)
|
|
163
165
|
if (!restored.ok) showLoadError(restored.error)
|
|
166
|
+
const rewound = runtime.rewind(checkpoint)
|
|
167
|
+
if (!rewound.ok) resync(rewound.error) // Released or OtherRuntime
|
|
164
168
|
void runtime.tick(render) // ignored on purpose
|
|
165
169
|
```
|
|
166
170
|
|
|
167
|
-
Catches `tick(...)`, `tryTick(...)`, and `
|
|
171
|
+
Catches `tick(...)`, `tryTick(...)`, `restore(...)`, and `rewind(...)` used as a statement on a receiver named like a runtime (`runtime`, `game.runtime`, `worldRuntime`). Game wrappers with other names (`town.restore(...)`) are not reported. Option: `{ "runtimePattern": "^(runtime|world)$" }` (a case-insensitive regular expression for the receiver's name; default `runtime$`).
|
|
168
172
|
|
|
169
173
|
### `ritmo/prefix-descriptor-and-system-names`
|
|
170
174
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The result of `runtime.tick(...)`, `tryTick(...)`,
|
|
3
|
-
* failed system
|
|
4
|
-
* the failure.
|
|
2
|
+
* The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
|
|
3
|
+
* `rewind(...)` is read: a failed system, an invalid save, or a released
|
|
4
|
+
* checkpoint comes back as data, and dropping it hides the failure.
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: import("@oxlint/plugins").Rule;
|
|
7
7
|
export default _default;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { calledMethod, docsUrl, receiverName } from "../internal/ast.js";
|
|
3
3
|
/**
|
|
4
|
-
* The result of `runtime.tick(...)`, `tryTick(...)`,
|
|
5
|
-
* failed system
|
|
6
|
-
* the failure.
|
|
4
|
+
* The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
|
|
5
|
+
* `rewind(...)` is read: a failed system, an invalid save, or a released
|
|
6
|
+
* checkpoint comes back as data, and dropping it hides the failure.
|
|
7
7
|
*/
|
|
8
8
|
export default defineRule({
|
|
9
9
|
meta: {
|
|
10
10
|
type: "problem",
|
|
11
11
|
docs: {
|
|
12
|
-
description: "Check the Result of runtime.tick(...), tryTick(...), and
|
|
12
|
+
description: "Check the Result of runtime.tick(...), tryTick(...), restore(...), and rewind(...) instead of dropping it.",
|
|
13
13
|
url: docsUrl("handle-tick-result")
|
|
14
14
|
},
|
|
15
15
|
messages: {
|
|
16
16
|
tick: "The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
|
|
17
|
-
restore: "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose."
|
|
17
|
+
restore: "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
|
|
18
|
+
rewind: "The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose."
|
|
18
19
|
},
|
|
19
20
|
schema: [
|
|
20
21
|
{
|
|
@@ -38,14 +39,14 @@ export default defineRule({
|
|
|
38
39
|
if (call.type !== "CallExpression" || call.callee.type !== "MemberExpression" || call.arguments.length === 0)
|
|
39
40
|
return;
|
|
40
41
|
const method = calledMethod(call);
|
|
41
|
-
if (method !== "tick" && method !== "tryTick" && method !== "restore")
|
|
42
|
+
if (method !== "tick" && method !== "tryTick" && method !== "restore" && method !== "rewind")
|
|
42
43
|
return;
|
|
43
44
|
const receiver = receiverName(call.callee.object);
|
|
44
45
|
if (receiver === undefined || !runtime.test(receiver))
|
|
45
46
|
return;
|
|
46
47
|
context.report({
|
|
47
48
|
node,
|
|
48
|
-
messageId: method === "restore"
|
|
49
|
+
messageId: method === "restore" || method === "rewind" ? method : "tick",
|
|
49
50
|
data: { call: context.sourceCode.getText(call.callee) }
|
|
50
51
|
});
|
|
51
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-tick-result.js","sourceRoot":"","sources":["../../src/rules/handle-tick-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMxE;;;;GAIG;AACH,eAAe,UAAU,CAAC;IACxB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE
|
|
1
|
+
{"version":3,"file":"handle-tick-result.js","sourceRoot":"","sources":["../../src/rules/handle-tick-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMxE;;;;GAIG;AACH,eAAe,UAAU,CAAC;IACxB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YAC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E,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;oBACxE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;iBACxD,CAAC,CAAA;YACJ,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keep-simulation-headless.d.ts","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keep-simulation-headless.d.ts","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AAgCA;;;;;GAKG"}
|
|
@@ -5,10 +5,12 @@ const page = new Set([
|
|
|
5
5
|
"window", "document", "navigator", "screen", "matchMedia", "getComputedStyle", "devicePixelRatio",
|
|
6
6
|
"innerWidth", "innerHeight", "addEventListener", "removeEventListener", "alert", "confirm", "prompt"
|
|
7
7
|
]);
|
|
8
|
-
/** Globals that do host I/O: storage,
|
|
8
|
+
/** Globals that do host I/O: storage, requests, navigation. */
|
|
9
9
|
const io = new Set([
|
|
10
|
-
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "
|
|
10
|
+
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "EventSource", "location", "history"
|
|
11
11
|
]);
|
|
12
|
+
/** Globals that connect to other peers: what online play goes through a netcode session for. */
|
|
13
|
+
const network = new Set(["WebSocket", "RTCPeerConnection", "RTCDataChannel"]);
|
|
12
14
|
/** Renderer and UI packages, by exact name. */
|
|
13
15
|
const renderers = new Set([
|
|
14
16
|
"@typeonce/ritmo-render", "@typeonce/ritmo-pixi", "pixi.js", "three", "react", "react-dom", "preact",
|
|
@@ -32,6 +34,7 @@ export default defineRule({
|
|
|
32
34
|
messages: {
|
|
33
35
|
page: "`{{name}}` is the page, which tests, bots, and replays do not have. Capture input in the host with `Keyboard`, `Pointer`, or `Touch` from `@typeonce/ritmo-browser` and `InputCapture` into a resource, and read that resource in systems. Pass other page state (size, settings) in from host code with `runtime.send(...)` or a resource.",
|
|
34
36
|
io: "`{{name}}` is host I/O, which tests, bots, and replays do not have and cannot reproduce. Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource; save and load the world in host code with `runtime.snapshot()` and `runtime.restore(...)`.",
|
|
37
|
+
network: "`{{name}}` is a connection to other peers, which tests, bots, and replays do not have. For other players' input, run the simulation under a session of `@typeonce/ritmo-netcode` (`Netcode.rollback` or `Netcode.lockstep`): host code opens the connection and wraps it in a link (`WebSocketNetworkLink`, `WebRtcNetworkLink`), and remote input reaches the simulation through `Netcode.seats`, never `runtime.send(...)`, which a rollback would read on the wrong tick.",
|
|
35
38
|
renderer: "The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare its services (a node registry) there. Renderer nodes stay in the registry, never in components.",
|
|
36
39
|
rendererType: "The simulation names a type from `{{source}}`, a renderer or UI package, so it is tied to that renderer and another one cannot replace it. Declare renderer services (a node registry) and their types in render code; services are not registered in the schema. Renderer nodes stay in the registry, never in components."
|
|
37
40
|
},
|
|
@@ -74,7 +77,7 @@ export default defineRule({
|
|
|
74
77
|
checkSource(node, stringValue(node.source));
|
|
75
78
|
},
|
|
76
79
|
Identifier(node) {
|
|
77
|
-
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : undefined;
|
|
80
|
+
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : network.has(node.name) ? "network" : undefined;
|
|
78
81
|
if (kind === undefined)
|
|
79
82
|
return;
|
|
80
83
|
// `typeof window` in a type runs nothing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keep-simulation-headless.js","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAE9F,mDAAmD;AACnD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB;IACjG,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ;CACrG,CAAC,CAAA;AAEF
|
|
1
|
+
{"version":3,"file":"keep-simulation-headless.js","sourceRoot":"","sources":["../../src/rules/keep-simulation-headless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAE9F,mDAAmD;AACnD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB;IACjG,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ;CACrG,CAAC,CAAA;AAEF,+DAA+D;AAC/D,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC;IACjB,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS;CACzH,CAAC,CAAA;AAEF,gGAAgG;AAChG,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,CA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AAU,KAAK,MAAM,CAAC,CAAA;YAClE,CAAC;YACD,gBAAgB,CAAC,IAAI;gBACnB,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YAC7C,CAAC;YACD,UAAU,CAAC,IAAI;gBACb,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;gBACrH,IAAI,IAAI,KAAK,SAAS;oBAAE,OAAM;gBAC9B,0CAA0C;gBAC1C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB;oBAAE,OAAM;gBACxF,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC;oBAAE,OAAM;gBAC7C,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YACtE,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -7,22 +7,24 @@ interface Options {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The result of `runtime.tick(...)`, `tryTick(...)`,
|
|
11
|
-
* failed system
|
|
12
|
-
* the failure.
|
|
10
|
+
* The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
|
|
11
|
+
* `rewind(...)` is read: a failed system, an invalid save, or a released
|
|
12
|
+
* checkpoint comes back as data, and dropping it hides the failure.
|
|
13
13
|
*/
|
|
14
14
|
export default defineRule({
|
|
15
15
|
meta: {
|
|
16
16
|
type: "problem",
|
|
17
17
|
docs: {
|
|
18
|
-
description: "Check the Result of runtime.tick(...), tryTick(...), and
|
|
18
|
+
description: "Check the Result of runtime.tick(...), tryTick(...), restore(...), and rewind(...) instead of dropping it.",
|
|
19
19
|
url: docsUrl("handle-tick-result")
|
|
20
20
|
},
|
|
21
21
|
messages: {
|
|
22
22
|
tick:
|
|
23
23
|
"The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
|
|
24
24
|
restore:
|
|
25
|
-
"The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose."
|
|
25
|
+
"The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
|
|
26
|
+
rewind:
|
|
27
|
+
"The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose."
|
|
26
28
|
},
|
|
27
29
|
schema: [
|
|
28
30
|
{
|
|
@@ -45,12 +47,12 @@ export default defineRule({
|
|
|
45
47
|
const call = node.expression
|
|
46
48
|
if (call.type !== "CallExpression" || call.callee.type !== "MemberExpression" || call.arguments.length === 0) return
|
|
47
49
|
const method = calledMethod(call)
|
|
48
|
-
if (method !== "tick" && method !== "tryTick" && method !== "restore") return
|
|
50
|
+
if (method !== "tick" && method !== "tryTick" && method !== "restore" && method !== "rewind") return
|
|
49
51
|
const receiver = receiverName(call.callee.object)
|
|
50
52
|
if (receiver === undefined || !runtime.test(receiver)) return
|
|
51
53
|
context.report({
|
|
52
54
|
node,
|
|
53
|
-
messageId: method === "restore"
|
|
55
|
+
messageId: method === "restore" || method === "rewind" ? method : "tick",
|
|
54
56
|
data: { call: context.sourceCode.getText(call.callee) }
|
|
55
57
|
})
|
|
56
58
|
}
|
|
@@ -9,11 +9,14 @@ const page = new Set([
|
|
|
9
9
|
"innerWidth", "innerHeight", "addEventListener", "removeEventListener", "alert", "confirm", "prompt"
|
|
10
10
|
])
|
|
11
11
|
|
|
12
|
-
/** Globals that do host I/O: storage,
|
|
12
|
+
/** Globals that do host I/O: storage, requests, navigation. */
|
|
13
13
|
const io = new Set([
|
|
14
|
-
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "
|
|
14
|
+
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "EventSource", "location", "history"
|
|
15
15
|
])
|
|
16
16
|
|
|
17
|
+
/** Globals that connect to other peers: what online play goes through a netcode session for. */
|
|
18
|
+
const network = new Set(["WebSocket", "RTCPeerConnection", "RTCDataChannel"])
|
|
19
|
+
|
|
17
20
|
/** Renderer and UI packages, by exact name. */
|
|
18
21
|
const renderers = new Set([
|
|
19
22
|
"@typeonce/ritmo-render", "@typeonce/ritmo-pixi", "pixi.js", "three", "react", "react-dom", "preact",
|
|
@@ -45,6 +48,8 @@ export default defineRule({
|
|
|
45
48
|
"`{{name}}` is the page, which tests, bots, and replays do not have. Capture input in the host with `Keyboard`, `Pointer`, or `Touch` from `@typeonce/ritmo-browser` and `InputCapture` into a resource, and read that resource in systems. Pass other page state (size, settings) in from host code with `runtime.send(...)` or a resource.",
|
|
46
49
|
io:
|
|
47
50
|
"`{{name}}` is host I/O, which tests, bots, and replays do not have and cannot reproduce. Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource; save and load the world in host code with `runtime.snapshot()` and `runtime.restore(...)`.",
|
|
51
|
+
network:
|
|
52
|
+
"`{{name}}` is a connection to other peers, which tests, bots, and replays do not have. For other players' input, run the simulation under a session of `@typeonce/ritmo-netcode` (`Netcode.rollback` or `Netcode.lockstep`): host code opens the connection and wraps it in a link (`WebSocketNetworkLink`, `WebRtcNetworkLink`), and remote input reaches the simulation through `Netcode.seats`, never `runtime.send(...)`, which a rollback would read on the wrong tick.",
|
|
48
53
|
renderer:
|
|
49
54
|
"The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare its services (a node registry) there. Renderer nodes stay in the registry, never in components.",
|
|
50
55
|
rendererType:
|
|
@@ -88,7 +93,7 @@ export default defineRule({
|
|
|
88
93
|
checkSource(node, stringValue(node.source))
|
|
89
94
|
},
|
|
90
95
|
Identifier(node) {
|
|
91
|
-
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : undefined
|
|
96
|
+
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : network.has(node.name) ? "network" : undefined
|
|
92
97
|
if (kind === undefined) return
|
|
93
98
|
// `typeof window` in a type runs nothing.
|
|
94
99
|
if (node.parent.type === "TSTypeQuery" || node.parent.type === "TSQualifiedName") return
|