Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddlingbits committed Mar 16, 2024
1 parent 6dba5f5 commit 8fc0728
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/index.f12184ae.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/twrmodworker.73a2aefb.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions source/twr-wasm-ts/twrdiv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { twrSharedCircularBuffer } from "./twrcircular.js";
import { IModParams } from "./twrmodbase.js";
import {twrWasmModuleBase} from "./twrmodbase.js";

export type TDivProxyParams = [SharedArrayBuffer];

Expand All @@ -13,15 +14,20 @@ export interface IDiv {

export class twrDiv implements IDiv {
div:HTMLDivElement|null|undefined;
divKeys:twrSharedCircularBuffer;
divKeys?:twrSharedCircularBuffer;
CURSOR=String.fromCharCode(9611); // ▋ see https://daniel-hug.github.io/characters/#k_70
cursorOn:boolean=false;
lastChar:number=0;
extraBR:boolean=false;
owner:twrWasmModuleBase;

constructor(element:HTMLDivElement|null|undefined, modParams:IModParams) {
constructor(element:HTMLDivElement|null|undefined, modParams:IModParams, modbase:twrWasmModuleBase) {
this.div=element;
this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher
this.owner=modbase;
if (!this.owner.isWasmModule) { // twrWasmModule doesn't use shared memory
this.divKeys = new twrSharedCircularBuffer(); // tsconfig, lib must be set to 2017 or higher
}

if (this.div && !modParams.styleIsDefault) { // don't let default colors override divStyle
this.div.style.backgroundColor = modParams.backcolor;
this.div.style.color = modParams.forecolor;
Expand All @@ -34,6 +40,7 @@ export class twrDiv implements IDiv {
}

getProxyParams() : TDivProxyParams {
if (!this.divKeys) throw new Error("internal error in getProxyParams.");
return [ this.divKeys.sharedArray];
}

Expand Down
4 changes: 1 addition & 3 deletions source/twr-wasm-ts/twrmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ export class twrWasmModule extends twrWasmModuleInJSMain {


constructor(opts:IModOpts={}) {
super(opts);
super(opts, true);
this.malloc=(size:number)=>{throw new Error("error - un-init malloc called")};

this.isWasmModule=true;

let canvas:twrCanvas;
if (this.d2dcanvas.isValid()) canvas=this.d2dcanvas;
else canvas=this.iocanvas;
Expand Down
5 changes: 3 additions & 2 deletions source/twr-wasm-ts/twrmodbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ export abstract class twrWasmModuleBase {
abstract modParams:IModParams;
exports?:WebAssembly.Exports;
isWorker=false;
isWasmModule=false; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)
isWasmModule:boolean; // twrWasmModule? (eg. could be twrWasmModuleAsync, twrWasmModuleInWorker, twrWasmModuleInJSMain)
floatUtil:twrFloatUtil;

constructor() {
constructor(isWasmModule=false) {
this.isWasmModule=isWasmModule; // as opposed to twrWasmModuleAsync, twrWasmModuleInWorker
this.mem8=new Uint8Array(); // avoid type errors
this.mem32=new Uint32Array(); // avoid type errors
this.memD=new Float64Array(); // avoid type errors
Expand Down
6 changes: 3 additions & 3 deletions source/twr-wasm-ts/twrmodjsmain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {
iodiv:twrDiv;
modParams:IModParams;

constructor(opts:IModOpts={}) {
super();
constructor(opts:IModOpts={}, isWasmModule=false) {
super(isWasmModule);
if (typeof document === 'undefined')
throw new Error ("twrWasmModuleJSMain should only be created in JavaScript Main.");

Expand Down Expand Up @@ -66,7 +66,7 @@ export abstract class twrWasmModuleInJSMain extends twrWasmModuleBase {
isd2dcanvas:opts.isd2dcanvas
};

this.iodiv=new twrDiv(eiodiv, this.modParams);
this.iodiv=new twrDiv(eiodiv, this.modParams, this);
this.iocanvas=new twrCanvas(eiocanvas, this.modParams, this);
this.d2dcanvas=new twrCanvas(ed2dcanvas, this.modParams, this);

Expand Down

0 comments on commit 8fc0728

Please sign in to comment.