Used __builtin_wasm_memory_size(0) instead of having the Javascript code call init_mem with the initial page count. Added a simple <div> below the canvas that can hold any number of labels that can be filled/updated through jsSetLabel which lives in a new file misc_functions.js.
This commit is contained in:
21
data/main.js
21
data/main.js
@@ -3,6 +3,7 @@ import { WASM_MEMORY_PAGE_SIZE, appGlobals } from './globals.js'
|
||||
import { loadWasmModule, wasmPntrToJsString, wasmPntrAndLengthToJsString } from './wasm_functions.js'
|
||||
import { jsStdFunctions } from './std_functions.js'
|
||||
import { jsGlFunctions } from './gl_functions.js'
|
||||
import { jsMiscFunctions } from './misc_functions.js'
|
||||
|
||||
function AcquireCanvas(canvasWidth, canvasHeight)
|
||||
{
|
||||
@@ -23,24 +24,11 @@ function AcquireCanvas(canvasWidth, canvasHeight)
|
||||
appGlobals.canvas = canvas;
|
||||
}
|
||||
|
||||
async function LoadWasmModule(wasmFilePath, initialWasmPageCount)
|
||||
async function MainLoop()
|
||||
{
|
||||
appGlobals.textDecoder = new TextDecoder("utf-8");
|
||||
appGlobals.textEncoder = new TextEncoder("utf-8");
|
||||
appGlobals.wasmModule = await loadWasmModule(wasmFilePath, { ...jsStdFunctions, ...jsGlFunctions });
|
||||
appGlobals.memDataView = new DataView(new Uint8Array(appGlobals.wasmModule.exports.memory.buffer).buffer);
|
||||
let memorySize = appGlobals.wasmModule.exports.memory.buffer.byteLength;
|
||||
let numMemoryPagesAfterLoad = memorySize / WASM_MEMORY_PAGE_SIZE;
|
||||
if ((memorySize % WASM_MEMORY_PAGE_SIZE) != 0)
|
||||
{
|
||||
console.warn("memorySize (" + memorySize + ") is not a multiple of WASM_MEMORY_PAGE_SIZE (" + WASM_MEMORY_PAGE_SIZE + ")");
|
||||
numMemoryPagesAfterLoad++;
|
||||
}
|
||||
appGlobals.wasmModule.exports.init_mem(numMemoryPagesAfterLoad);
|
||||
}
|
||||
|
||||
async function MainLoop()
|
||||
{
|
||||
|
||||
console.log("Initializing WebGL Canvas...");
|
||||
AcquireCanvas(600, 400);
|
||||
|
||||
@@ -50,7 +38,8 @@ async function MainLoop()
|
||||
appGlobals.glContext = canvasContextGl;
|
||||
|
||||
console.log("Loading WASM Module...");
|
||||
await LoadWasmModule("app.wasm", 4);
|
||||
appGlobals.wasmModule = await loadWasmModule("app.wasm", { ...jsStdFunctions, ...jsGlFunctions, ...jsMiscFunctions });
|
||||
appGlobals.memDataView = new DataView(new Uint8Array(appGlobals.wasmModule.exports.memory.buffer).buffer);
|
||||
|
||||
let initSuccess = appGlobals.wasmModule.exports.App_Initialize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user