Skip to content

Commit 77d2110

Browse files
committed
Reorganise and rename config constants etc
1 parent 1e80789 commit 77d2110

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** True if the runtime is in Game Developer mode, with access to the devtools window. */
2+
// WASM4_GAMEDEV_MODE is defined in vite.config.ts
3+
export const GAMEDEV_MODE = WASM4_GAMEDEV_MODE;
4+
5+
/** True if we're developers of the WASM4 runtime itself, and are running the runtime
6+
using `npm start` or `vite` etc. */
7+
export const PLATFORM_DEVELOPER_MODE = import.meta.env.MODE === "development";

runtimes/web/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export const GAMEDEV_MODE = WASM4_GAMEDEV_MODE;
21
export const WIDTH = 160;
32
export const HEIGHT = 160;
43

runtimes/web/src/devkit.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as constants from "./constants";
2-
// True if we're developers of the WASM4 runtime itself, and are running the runtime
3-
// using `npm start` or `vite` etc. In this case, there's no wasm4 CLI web socket to
4-
// connect to, but we might be fighting for the Vite websocket.
5-
const PLATFORM_DEVELOPER_MODE = import.meta.env.MODE === "development";
1+
import { GAMEDEV_MODE, PLATFORM_DEVELOPER_MODE } from "./config-constants";
62

7-
export const websocket = constants.GAMEDEV_MODE && !PLATFORM_DEVELOPER_MODE
3+
// The w4 CLI web socket only exists for gamedev mode.
4+
// But if we're running `npm start` or `vite` there is no w4 CLI to connect to,
5+
// but there is a vite websocket we may be fighting for, causing issues with vite.
6+
export const cli_websocket = GAMEDEV_MODE && !PLATFORM_DEVELOPER_MODE
87
? new WebSocket((location.protocol == "https:" ? "wss" : "ws") + "://" + location.host)
98
: null;

runtimes/web/src/runtime.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Framebuffer } from "./framebuffer";
55
import { WebGLCompositor } from "./compositor";
66
import * as devkit from "./devkit";
77
import { wasmPatchExportGlobals } from "./wasm-patch";
8+
import * as configConstants from "./config-constants";
89

910
export class Runtime {
1011
canvas: HTMLCanvasElement;
@@ -120,7 +121,7 @@ export class Runtime {
120121
this.wasm = null;
121122

122123
if (wasmBuffer.byteLength > limit) {
123-
if (constants.GAMEDEV_MODE) {
124+
if (configConstants.GAMEDEV_MODE) {
124125
if (!this.warnedFileSize) {
125126
this.warnedFileSize = true;
126127
this.print(`Warning: Cart is larger than ${limit} bytes. Ensure the release build of your cart is small enough to be bundled.`);
@@ -262,8 +263,8 @@ export class Runtime {
262263
}
263264

264265
printToServer (str: string) {
265-
if (devkit.websocket != null && devkit.websocket.readyState == 1) {
266-
devkit.websocket.send(str);
266+
if (devkit.cli_websocket != null && devkit.cli_websocket.readyState == 1) {
267+
devkit.cli_websocket.send(str);
267268
}
268269
}
269270

runtimes/web/src/ui/app.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LitElement, html, css } from "lit";
22
import { customElement, state, query } from 'lit/decorators.js';
33

44
import * as constants from "../constants";
5+
import * as configConstants from "../config-constants";
56
import * as devkit from "../devkit";
67
import * as utils from "./utils";
78
import * as z85 from "../z85";
@@ -141,7 +142,7 @@ export class App extends LitElement {
141142
// Nothing
142143
},
143144
};
144-
if (constants.GAMEDEV_MODE) {
145+
if (configConstants.GAMEDEV_MODE) {
145146
devtoolsManager = await import('@wasm4/web-devtools').then(({ DevtoolsManager}) => new DevtoolsManager());
146147
}
147148

@@ -153,8 +154,8 @@ export class App extends LitElement {
153154
this.copyNetplayLink();
154155
}
155156

156-
if (constants.GAMEDEV_MODE) {
157-
devkit.websocket?.addEventListener("message", async event => {
157+
if (configConstants.GAMEDEV_MODE) {
158+
devkit.cli_websocket?.addEventListener("message", async event => {
158159
switch (event.data) {
159160
case "reload":
160161
this.resetCart(await loadCartWasm());
@@ -481,8 +482,7 @@ export class App extends LitElement {
481482

482483
runtime.composite();
483484

484-
if (constants.GAMEDEV_MODE) {
485-
// FIXED(2023-12-13): Pass the correct FPS for display
485+
if (configConstants.GAMEDEV_MODE) {
486486
devtoolsManager.updateCompleted(runtime, timeFrameStart - lastTimeFrameStart);
487487
lastTimeFrameStart = timeFrameStart;
488488
}

0 commit comments

Comments
 (0)