Pushing current web edits

This commit is contained in:
Guy Perfect 2025-03-23 07:26:43 -05:00
parent ecbd103917
commit 483714c0d6
2 changed files with 37 additions and 12 deletions

View File

@ -293,6 +293,12 @@ new class Core {
}, [ output.buffer ]); }, [ output.buffer ]);
} }
// Reset simulation state
reset(message) {
this.vbReset(message.sim);
this.dom.postMessage({ promised: true });
}
// Specify anaglyph colors // Specify anaglyph colors
setAnaglyph(message) { setAnaglyph(message) {
this.SetAnaglyph(message.sim, message.left, message.right); this.SetAnaglyph(message.sim, message.left, message.right);

View File

@ -436,8 +436,17 @@ class Sim extends HTMLElement {
response.lines.map(l=>new DasmLine(GUARD, l)); response.lines.map(l=>new DasmLine(GUARD, l));
} }
// Reset simulation state
reset() {
return this.#core.toCore({
command : "reset",
promised: true,
sim : this.#pointer
});
}
// Specify anaglyph colors // Specify anaglyph colors
async setAnaglyph(left, right) { setAnaglyph(left, right) {
// Error checking // Error checking
if (!Number.isSafeInteger(left ) || left < 0 || left > 0xFFFFFF) if (!Number.isSafeInteger(left ) || left < 0 || left > 0xFFFFFF)
@ -455,7 +464,7 @@ class Sim extends HTMLElement {
this.#anaglyph[1] = right; this.#anaglyph[1] = right;
// Send the colors to the core // Send the colors to the core
await this.#core.toCore({ return this.#core.toCore({
command : "setAnaglyph", command : "setAnaglyph",
promised: true, promised: true,
sim : this.#pointer, sim : this.#pointer,
@ -475,7 +484,7 @@ class Sim extends HTMLElement {
} }
// Specify new game pad keys // Specify new game pad keys
async setKeys(keys) { setKeys(keys) {
// Error checking // Error checking
if (!Number.isSafeInteger(keys) || keys < 0 || keys > 0xFFFF) if (!Number.isSafeInteger(keys) || keys < 0 || keys > 0xFFFF)
@ -487,7 +496,7 @@ class Sim extends HTMLElement {
this.#keys = keys; this.#keys = keys;
// Send the keys to the core // Send the keys to the core
await this.#core.toCore({ return this.#core.toCore({
command : "setKeys", command : "setKeys",
promised: true, promised: true,
sim : this.#pointer, sim : this.#pointer,
@ -496,7 +505,7 @@ class Sim extends HTMLElement {
} }
// Specify audio panning // Specify audio panning
async setPanning(panning) { setPanning(panning) {
// Error checking // Error checking
if (!Number.isFinite(panning) ||panning < -1 || panning > +1) { if (!Number.isFinite(panning) ||panning < -1 || panning > +1) {
@ -508,7 +517,7 @@ class Sim extends HTMLElement {
this.#panning = panning; this.#panning = panning;
// Send the panning to the core // Send the panning to the core
await this.#core.toCore({ return this.#core.toCore({
command : "setPanning", command : "setPanning",
promised: true, promised: true,
sim : this.#pointer, sim : this.#pointer,
@ -529,7 +538,7 @@ class Sim extends HTMLElement {
} }
// Specify audio volume // Specify audio volume
async setVolume(volume) { setVolume(volume) {
// Error checking // Error checking
if (!Number.isFinite(volume) ||volume < 0 || volume > 10) { if (!Number.isFinite(volume) ||volume < 0 || volume > 10) {
@ -541,7 +550,7 @@ class Sim extends HTMLElement {
this.#volume = volume; this.#volume = volume;
// Send the volume to the core // Send the volume to the core
await this.#core.toCore({ return this.#core.toCore({
command : "setVolume", command : "setVolume",
promised: true, promised: true,
sim : this.#pointer, sim : this.#pointer,
@ -596,7 +605,7 @@ class VB {
#commands; // Computed method table #commands; // Computed method table
#core; // Core worker #core; // Core worker
#proxy; // Self proxy for sim access #proxy; // Self proxy for sim access
#sims; // All sims #sims; // Mapping of Sim|pointer -> proxy
#state; // Operations state #state; // Operations state
@ -683,8 +692,8 @@ class VB {
///////////////////////////// Static Methods ////////////////////////////// ///////////////////////////// Static Methods //////////////////////////////
// Create a core instance // Create a core instance
static async create(options) { static create(options) {
return await new VB(GUARD).#construct(options); return new VB(GUARD).#construct(options);
} }
@ -769,6 +778,16 @@ class VB {
/////////////////////////////// Properties ////////////////////////////////
// Number of managed simulations
get size() { return this.#sims.size / 2; }
// Managed simulations
get sims() { return [... this.#sims.keys()].filter(s=>s instanceof Sim); }
///////////////////////////// Public Methods ////////////////////////////// ///////////////////////////// Public Methods //////////////////////////////
// Create one or more sims // Create one or more sims
@ -809,7 +828,7 @@ class VB {
if ( if (
!Array.isArray(sims) || !Array.isArray(sims) ||
sims.length == 0 || sims.length == 0 ||
sims.find(s=>!this.#sims.has(s)) sims.some(s=>!this.#sims.has(s))
) { ) {
throw new TypeError("Must specify a Sim or array of Sims " + throw new TypeError("Must specify a Sim or array of Sims " +
"that belong to this core."); "that belong to this core.");