@aethervtt/shard-runtime 0.0.1 → 0.2.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/dist/app.d.ts +145 -1
- package/dist/app.js +333 -17
- package/dist/budgets.d.ts +197 -0
- package/dist/budgets.js +256 -0
- package/dist/control.d.ts +2 -0
- package/dist/control.js +7 -1
- package/dist/demand.d.ts +47 -0
- package/dist/demand.js +68 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +55 -1
- package/dist/perf.d.ts +157 -0
- package/dist/perf.js +245 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/runners.d.ts +17 -2
- package/dist/runners.js +130 -48
- package/dist/scenario.d.ts +9 -0
- package/dist/scenario.js +9 -0
- package/dist/testing.d.ts +22 -0
- package/dist/testing.js +64 -0
- package/dist/time.d.ts +4 -0
- package/dist/time.js +5 -0
- package/dist/write-check.d.ts +22 -0
- package/dist/write-check.js +54 -0
- package/package.json +7 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { allResources, isPlainObject } from "@aethervtt/shard-core";
|
|
2
|
+
const CHECK_MS = 1e3;
|
|
3
|
+
function hashOf(value) {
|
|
4
|
+
if (!isPlainObject(value)) return void 0;
|
|
5
|
+
try {
|
|
6
|
+
return JSON.stringify(value);
|
|
7
|
+
} catch {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class ResourceWriteCheck {
|
|
12
|
+
snapshots = /* @__PURE__ */ new Map();
|
|
13
|
+
timer;
|
|
14
|
+
world;
|
|
15
|
+
log;
|
|
16
|
+
quiet;
|
|
17
|
+
/** `quiet`: still idle with no frame requested, so a change nobody announced is a bug. */
|
|
18
|
+
constructor(world, log, quiet) {
|
|
19
|
+
this.world = world;
|
|
20
|
+
this.log = log;
|
|
21
|
+
this.quiet = quiet;
|
|
22
|
+
}
|
|
23
|
+
/** The app went idle: remember what the resources hold, and check them every second. */
|
|
24
|
+
start() {
|
|
25
|
+
this.snapshots.clear();
|
|
26
|
+
for (const def of allResources()) {
|
|
27
|
+
if (!def.hostWritable) continue;
|
|
28
|
+
const hash = hashOf(this.world.tryResource(def));
|
|
29
|
+
if (hash !== void 0) this.snapshots.set(def, hash);
|
|
30
|
+
}
|
|
31
|
+
this.timer ??= setInterval(() => this.verify(), CHECK_MS);
|
|
32
|
+
}
|
|
33
|
+
/** A frame is running (or the loop stopped): writes are fine again. */
|
|
34
|
+
stop() {
|
|
35
|
+
if (this.timer !== void 0) clearInterval(this.timer);
|
|
36
|
+
this.timer = void 0;
|
|
37
|
+
}
|
|
38
|
+
verify() {
|
|
39
|
+
if (!this.quiet()) return;
|
|
40
|
+
for (const [def, before] of this.snapshots) {
|
|
41
|
+
const now = hashOf(this.world.tryResource(def)) ?? "";
|
|
42
|
+
if (now === before) continue;
|
|
43
|
+
this.snapshots.set(def, now);
|
|
44
|
+
this.log?.log("warn", `Resource "${def.name}" changed without waking the app`, {
|
|
45
|
+
code: "runtime/unmarked-resource-write",
|
|
46
|
+
path: def.name,
|
|
47
|
+
hint: "Outside a frame, write resources with world.patchResource or world.touchResource (or call app.requestFrame())."
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
ResourceWriteCheck
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aethervtt/shard-runtime",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./testing": {
|
|
13
|
+
"types": "./dist/testing.d.ts",
|
|
14
|
+
"default": "./dist/testing.js"
|
|
11
15
|
}
|
|
12
16
|
},
|
|
13
17
|
"files": [
|
|
@@ -16,7 +20,7 @@
|
|
|
16
20
|
"README.md"
|
|
17
21
|
],
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@aethervtt/shard-core": "0.0
|
|
23
|
+
"@aethervtt/shard-core": "0.2.0"
|
|
20
24
|
},
|
|
21
25
|
"repository": {
|
|
22
26
|
"type": "git",
|
|
@@ -28,6 +32,6 @@
|
|
|
28
32
|
"provenance": true
|
|
29
33
|
},
|
|
30
34
|
"shard": {
|
|
31
|
-
"buildSha": "
|
|
35
|
+
"buildSha": "32c22a3944ed23f5d1baa90bf7cc9fae724f5fd8"
|
|
32
36
|
}
|
|
33
37
|
}
|