Add cAllocMem to cwasm.c which the javascript side can use to allocate memory from an opaque Arena pointer that was passed to it. Used this to implement jsGlGetParameterString, jsGlGetShaderInfoLog, and jsGlGetProgramInfoLog in gl_functions.js. Added NotNull macro and fixed bug in ScratchBegin macro. Added a bool return for App_Initialize which allows us to stop the main loop from beginning (which prevents log spew when something goes wrong)
This commit is contained in:
22
data/main.js
22
data/main.js
@@ -26,6 +26,7 @@ function AcquireCanvas(canvasWidth, canvasHeight)
|
||||
async function LoadWasmModule(wasmFilePath, initialWasmPageCount)
|
||||
{
|
||||
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;
|
||||
@@ -50,16 +51,23 @@ async function MainLoop()
|
||||
|
||||
console.log("Loading WASM Module...");
|
||||
await LoadWasmModule("app.wasm", 4);
|
||||
appGlobals.wasmModule.exports.App_Initialize();
|
||||
let initSuccess = appGlobals.wasmModule.exports.App_Initialize();
|
||||
|
||||
console.log("Running!");
|
||||
function renderFrame(currentTime)
|
||||
if (initSuccess)
|
||||
{
|
||||
let shouldContinue = appGlobals.wasmModule.exports.App_UpdateAndRender(currentTime);
|
||||
if (shouldContinue) { window.requestAnimationFrame(renderFrame); }
|
||||
else { appGlobals.wasmModule.exports.App_Close(); }
|
||||
console.log("Running!");
|
||||
function renderFrame(currentTime)
|
||||
{
|
||||
let shouldContinue = appGlobals.wasmModule.exports.App_UpdateAndRender(currentTime);
|
||||
if (shouldContinue) { window.requestAnimationFrame(renderFrame); }
|
||||
else { appGlobals.wasmModule.exports.App_Close(); }
|
||||
}
|
||||
window.requestAnimationFrame(renderFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.error("Initialization failed!");
|
||||
}
|
||||
window.requestAnimationFrame(renderFrame);
|
||||
}
|
||||
|
||||
MainLoop();
|
||||
Reference in New Issue
Block a user