Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

test(residency): the source that breathes across a boundary is asked to prove it moved

esengine11558f180565
diff --git a/tools/launchers/residency-run.mjs b/tools/launchers/residency-run.mjs
index 0f64cd3da..bae62eb81 100644
--- a/tools/launchers/residency-run.mjs
+++ b/tools/launchers/residency-run.mjs
@@ -47,7 +47,7 @@ const LOG = flag('log', '');
const logRe = LOG ? new RegExp(LOG, 'i') : null;
/** Everything a read asks the game about, in one round trip. */
-const NAMES = ['Player', 'Enemy', 'RockA', 'Wall', 'Arch', 'ArchTop', 'Beacon', 'Canary', 'Scout'];
+const NAMES = ['Player', 'Enemy', 'RockA', 'Wall', 'Arch', 'ArchTop', 'Beacon', 'Canary', 'Scout', 'Bobber'];
const MIME = {
'.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
@@ -216,6 +216,22 @@ async function main() {
continue;
}
if (step.do === 'step') { await exec(holdScript([], step.frames ?? 30)); continue; }
+ if (step.do === 'watch') {
+ // Sample while it runs, so a claim about a source CROSSING a threshold can
+ // say it crossed. One reading at the end cannot: a source that never moved
+ // and one that came to rest where it started look the same.
+ const every = step.every ?? 20;
+ const swept = { min: Infinity, max: -Infinity };
+ let counts = null;
+ for (let done = 0; done < (step.frames ?? 200); done += every) {
+ await exec(holdScript([], every));
+ const at = (await exec(`window.__estellaCooked.probe(${JSON.stringify([step.name])})`)).at[step.name];
+ if (at) { swept.min = Math.min(swept.min, at[step.axis ?? 'z']); swept.max = Math.max(swept.max, at[step.axis ?? 'z']); }
+ counts = await exec('window.__estellaCooked.streaming()');
+ }
+ console.log(`watching ${step.as}: ${JSON.stringify({ swept, streaming: counts })}`);
+ continue;
+ }
if (step.do === 'tap') { await exec(tapScript(step.key, step.frames ?? 10)); continue; }
if (step.do === 'hold') { await exec(holdScript(step.keys ?? [], step.frames ?? 30)); continue; }
if (step.do === 'walkTo') {
diff --git a/tools/verify-world-residency.mjs b/tools/verify-world-residency.mjs
index 2a43cf55d..e4a201c4a 100644
--- a/tools/verify-world-residency.mjs
+++ b/tools/verify-world-residency.mjs
@@ -59,9 +59,9 @@ function drive(dir, name, steps) {
], { encoding: 'utf8', cwd: ROOT });
const readings = {};
for (const line of (r.stdout || '').split('\n')) {
- const at = line.indexOf('reading ');
+ const at = Math.max(line.indexOf('reading '), line.indexOf('watching '));
if (at < 0) continue;
- const label = line.slice(at + 8, line.indexOf(':', at));
+ const label = line.slice(line.indexOf(' ', at) + 1, line.indexOf(':', at));
try {
readings[label] = JSON.parse(line.slice(line.indexOf('{', at)));
} catch { /* a truncated line is a missing reading, reported below */ }
@@ -96,8 +96,8 @@ function main() {
{ do: 'read', as: 'scoutOn' },
{ do: 'tap', key: 'KeyL', frames: 30 },
{ do: 'read', as: 'scoutOff' },
- { do: 'tap', key: 'KeyM', frames: 420 },
- { do: 'read', as: 'bobbed' },
+ { do: 'tap', key: 'KeyM', frames: 20 },
+ { do: 'watch', as: 'bobbed', name: 'Bobber', axis: 'z', frames: 400, every: 20 },
]);
const initial = start.initial;
@@ -127,9 +127,15 @@ function main() {
const bobbed = start.bobbed;
const loads = bobbed.streaming.loadCount - scoutOff.streaming.loadCount;
const unloads = bobbed.streaming.unloadCount - scoutOff.streaming.unloadCount;
+ // The threshold the bobber is meant to breathe across. Asserted, because a
+ // source that never moved would satisfy every count below for no reason.
+ const CROSSES_AT = 2750;
+ claim(bobbed.swept.min < CROSSES_AT && bobbed.swept.max > CROSSES_AT,
+ 'the source really did cross the load threshold, both ways',
+ `swept z ${bobbed.swept.min.toFixed(0)}..${bobbed.swept.max.toFixed(0)} across ${CROSSES_AT}`);
claim(resident(bobbed, D) && loads === 1 && unloads === 0,
- 'a source breathing across a boundary loads the place once and keeps it',
- `${loads} load(s), ${unloads} unload(s) over 420 frames`);
+ 'and a boundary it breathes across loads the place once and keeps it',
+ `${loads} load(s), ${unloads} unload(s) over 400 frames`);
// ---- 2/3/4/7/8. The journey ------------------------------------------
const trip = drive(dir, 'journey', [