diff --git a/web/Core.js b/web/Core.js index bd1b13b..92b75b9 100644 --- a/web/Core.js +++ b/web/Core.js @@ -87,11 +87,8 @@ new class Core { this.sims.set(sim.pointer, sim); // Video - sim.pixels = this.#noalloc( - this.GetExtPixels(sim.pointer), - 384*224*4, sim, "pixels", Uint8ClampedArray - ); - sim.image = new ImageData(sim.pixels, 384, 224); + sim.pixels = this.#getPixels(sim); + sim.image = new ImageData(sim.pixels, 384, 224); // Audio sim.samples = this.#noalloc( @@ -364,8 +361,10 @@ new class Core { this.mallocs.set(buffer.pointer, buffer); this.#updateTarget(buffer); } - for (let sim of this.sims) - sim.image = new ImageData(sim.pixels, 384, 224); + for (let sim of this.sims.values()) { + sim.pixels = this.#getPixels(sim); + sim.image = new ImageData(sim.pixels, 384, 224); + } } @@ -436,6 +435,14 @@ new class Core { this.Realloc(buffer.pointer, 0); } + // Register a sim's pixel buffer + #getPixels(sim) { + return this.#noalloc( + this.GetExtPixels(sim.pointer), + 384*224*4, sim, "pixels", Uint8ClampedArray + ); + } + // Allocate memory in WebAssembly and register the buffer #malloc(count, target = null, assign = null, type = Uint8ClampedArray) { return this.#noalloc(