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.

fix(minigame): the loading notice comes down on vivo's quick game

esengine295ea4a8aa04
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2671632bd..702e5374d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ published separately; it ships inside the editor.
### Fixed
+- On vivo's quick game the loading notice comes down once the game starts; it could stay over the running game.
- A quick tap on a slow frame still clicks a button: a finger that landed and lifted between two frames was seen only lifting, so the button never saw a press.
- A tap on vivo's quick game lands where the finger is: the host reports touches in physical pixels, and every tap landed off the screen.
- Games on vivo's quick game run past their first frame: the frame loop now hands requestAnimationFrame a handler the runtime accepts.
diff --git a/sdk/src/runtime/miniGameRuntime.ts b/sdk/src/runtime/miniGameRuntime.ts
index ada1f91f4..787b96f30 100644
--- a/sdk/src/runtime/miniGameRuntime.ts
+++ b/sdk/src/runtime/miniGameRuntime.ts
@@ -176,11 +176,24 @@ export interface MiniGameRuntimeConfig {
* canvas is the GL surface, so nothing 2D can be drawn over it. Every call is
* optional — an indicator is something a boot SHOWS, never something it fails on.
*/
-function hostProgress(global: { showLoading?: (o: { title: string; mask?: boolean }) => void; hideLoading?: () => void }) {
+export function hostProgress(global: {
+ showLoading?: (o: { title: string; mask?: boolean; complete?: () => void }) => void;
+ hideLoading?: () => void;
+}) {
const done: BootStage[] = [];
+ let unsettled = 0;
+ let hideWhenSettled = false;
+ const hide = (): void => {
+ try { global.hideLoading?.(); } catch { /* as above */ }
+ };
const say = (): void => {
try {
- global.showLoading?.({ title: `${bootSays(done)} ${bootPercent(done)}%`, mask: true });
+ unsettled++;
+ global.showLoading?.({
+ title: `${bootSays(done)} ${bootPercent(done)}%`,
+ mask: true,
+ complete: () => { if (--unsettled === 0 && hideWhenSettled) hide(); },
+ });
} catch { /* an indicator must not take the boot down with it */ }
};
say();
@@ -190,8 +203,13 @@ function hostProgress(global: { showLoading?: (o: { title: string; mask?: boolea
done.push(stage);
say();
},
+ /** vivo runs these calls asynchronously and out of order: a hide issued
+ * right after a show landed first, leaving the show up for good. So the
+ * hide goes once every show has landed, and once now for a host that
+ * never reports one landing. */
finish(): void {
- try { global.hideLoading?.(); } catch { /* as above */ }
+ hideWhenSettled = true;
+ hide();
},
};
}
diff --git a/sdk/tests/minigame-loading-indicator.test.ts b/sdk/tests/minigame-loading-indicator.test.ts
new file mode 100644
index 000000000..0e45658bf
--- /dev/null
+++ b/sdk/tests/minigame-loading-indicator.test.ts
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The host's loading indicator comes down once the game starts, even on a
+ * host that carries out its calls later and in another order (vivo).
+ */
+import { describe, it, expect } from 'vitest';
+import { hostProgress } from '../src/runtime/miniGameRuntime';
+
+/** A host that queues each call and carries it out when told, in any order. */
+function deferredHost() {
+ let showing: string | null = null;
+ const queue: Array<{ kind: 'show' | 'hide'; run: () => void }> = [];
+ return {
+ host: {
+ showLoading: (o: { title: string; complete?: () => void }) =>
+ queue.push({ kind: 'show', run: () => { showing = o.title; o.complete?.(); } }),
+ hideLoading: () => queue.push({ kind: 'hide', run: () => { showing = null; } }),
+ },
+ queue,
+ showing: () => showing,
+ };
+}
+
+describe('the loading indicator', () => {
+ it('is gone after a hide that the host carried out before the last show', () => {
+ const h = deferredHost();
+ const progress = hostProgress(h.host);
+ progress.reach('config');
+ progress.finish();
+ // What vivo did: the hide first, then the shows queued before it.
+ const issued = h.queue.splice(0);
+ for (const c of [...issued.filter((c) => c.kind === 'hide'), ...issued.filter((c) => c.kind === 'show')]) c.run();
+ for (const c of h.queue.splice(0)) c.run();
+ expect(h.showing()).toBeNull();
+ });
+
+ it('is gone on a host that never says a show landed', () => {
+ let hidden = false;
+ const progress = hostProgress({ showLoading: () => {}, hideLoading: () => { hidden = true; } });
+ progress.finish();
+ expect(hidden).toBe(true);
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 99be9ad32..9745cb931 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1092,4 +1092,6 @@ export const NOTED = {
{ note: 'A tap on vivo\'s quick game lands where the finger is: the host reports touches in physical pixels, and every tap landed off the screen.' },
'fix(ui): a quick tap on a slow frame still clicks':
{ note: 'A quick tap on a slow frame still clicks a button: a finger that landed and lifted between two frames was seen only lifting, so the button never saw a press.' },
+ 'fix(minigame): the loading notice comes down on vivo\'s quick game':
+ { note: 'On vivo\'s quick game the loading notice comes down once the game starts; it could stay over the running game.' },
};