Skip to content

Commit 46c75a0

Browse files
committed
v0.73.0
1 parent 5b39084 commit 46c75a0

File tree

6 files changed

+96
-23
lines changed

6 files changed

+96
-23
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emulators-ui",
3-
"version": "0.72.9",
3+
"version": "0.73.0",
44
"description": "Emulators UI",
55
"main": "dist/emulators-ui.js",
66
"types": "dist/types/emulators-ui.d.ts",
@@ -45,14 +45,14 @@
4545
"@types/vinyl-source-stream": "0.0.30",
4646
"@typescript-eslint/eslint-plugin": "^4.33.0",
4747
"@typescript-eslint/parser": "^4.33.0",
48-
"eslint-config-google": "^0.14.0",
4948
"babelify": "^10.0.0",
5049
"browserify": "^17.0.0",
5150
"core-js": "^3.19.1",
5251
"del": "^5.1.0",
5352
"element-resize-detector": "^1.2.1",
54-
"emulators": "^0.72.0",
53+
"emulators": "^0.73.0",
5554
"eslint": "^7.30.0",
55+
"eslint-config-google": "^0.14.0",
5656
"git-repo-info": "^2.1.1",
5757
"gulp": "^4.0.2",
5858
"gulp-rename": "^2.0.0",

src/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// gulpfile.ts/wasm.ts --> generateBuildInfo
55

66
export const Build = {
7-
short: "0.72.8",
8-
version: "0.72.8 (c66a0cae039c95fbe9b493b296a2ca84)",
9-
buildSeed: 1642744632714,
7+
short: "0.72.9",
8+
version: "0.72.9 (abdf90a98a4f9ed382c5b722a42cb87d)",
9+
buildSeed: 1646465611403,
1010
};

src/graphics/_2d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,25 @@ export function _2d(layers: Layers, ci: CommandInterface) {
4848
onResize();
4949
};
5050
ci.events().onFrameSize(onResizeFrame);
51-
ci.events().onFrame((rgb) => {
52-
let rgbOffset = 0;
51+
ci.events().onFrame((frameRgb, frameRgba) => {
52+
if (frameRgb === null && frameRgba === null) {
53+
return;
54+
}
55+
56+
const frame = (frameRgb !== null ? frameRgb : frameRgba) as Uint8Array;
57+
58+
let frameOffset = 0;
5359
let rgbaOffset = 0;
5460

5561
while (rgbaOffset < rgba.length) {
56-
rgba[rgbaOffset++] = rgb[rgbOffset++];
57-
rgba[rgbaOffset++] = rgb[rgbOffset++];
58-
rgba[rgbaOffset++] = rgb[rgbOffset++];
62+
rgba[rgbaOffset++] = frame[frameOffset++];
63+
rgba[rgbaOffset++] = frame[frameOffset++];
64+
rgba[rgbaOffset++] = frame[frameOffset++];
5965
rgba[rgbaOffset++] = 255;
66+
67+
if (frame.length === rgba.length) {
68+
frameOffset++;
69+
}
6070
}
6171

6272
context.putImageData(new ImageData(rgba, frameWidth, frameHeight), 0, 0);

src/graphics/webgl.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,29 @@ export function webGl(layers: Layers, ci: CommandInterface) {
9393
onResize();
9494
};
9595
ci.events().onFrameSize(onResizeFrame);
96-
ci.events().onFrame((rgb) => {
97-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB,
98-
frameWidth, frameHeight, 0, gl.RGB, gl.UNSIGNED_BYTE,
99-
rgb);
100-
gl.drawArrays(gl.TRIANGLES, 0, 6);
96+
onResizeFrame(ci.width(), ci.height());
97+
98+
let requestAnimationFrameId: number | null = null;
99+
let frame: Uint8Array | null = null;
100+
let frameFormat: number = 0;
101+
102+
ci.events().onFrame((rgb, rgba) => {
103+
frame = rgb != null ? rgb : rgba;
104+
frameFormat = rgb != null ? gl.RGB : gl.RGBA;
105+
if (requestAnimationFrameId === null) {
106+
requestAnimationFrameId = requestAnimationFrame(updateTexture);
107+
}
101108
});
102109

103-
onResizeFrame(ci.width(), ci.height());
110+
const updateTexture = () => {
111+
gl.texImage2D(gl.TEXTURE_2D, 0, frameFormat,
112+
frameWidth, frameHeight, 0, frameFormat, gl.UNSIGNED_BYTE,
113+
frame);
114+
gl.drawArrays(gl.TRIANGLES, 0, 6);
115+
116+
requestAnimationFrameId = null;
117+
frame = null;
118+
};
104119

105120
ci.events().onExit(() => {
106121
layers.removeOnResize(onResizeLayer);

src/sound/audio-node.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommandInterface } from "emulators";
1+
import { CommandInterface, DirectSound } from "emulators";
22

33
class SamplesQueue {
44
private samplesQueue: Float32Array[] = [];
@@ -81,7 +81,54 @@ export function audioNode(ci: CommandInterface) {
8181

8282
const audioNode = audioContext.createScriptProcessor(bufferSize, 0, channels);
8383
let started = false;
84-
audioNode.onaudioprocess = (event) => {
84+
85+
let active = 0;
86+
const directSound = ci.directSound as DirectSound;
87+
const onDirectProcess = (event: AudioProcessingEvent) => {
88+
if (!started) {
89+
const buffer = directSound.buffer[0];
90+
started = Math.ceil(buffer[buffer.length - 1]) > 0;
91+
}
92+
93+
if (!started) {
94+
return;
95+
}
96+
97+
let offset = 0;
98+
let numFrames = event.outputBuffer.length;
99+
const numChannels = event.outputBuffer.numberOfChannels;
100+
101+
let numSamples;
102+
let buffer = directSound.buffer[active];
103+
while (numFrames > 0 && (numSamples = Math.ceil(buffer[buffer.length - 1])) > 0) {
104+
if (numFrames >= numSamples) {
105+
const source = buffer.subarray(0, numSamples);
106+
for (let channel = 0; channel < numChannels; ++channel) {
107+
const channelData = event.outputBuffer.getChannelData(channel);
108+
channelData.set(source, offset);
109+
}
110+
111+
offset += numSamples;
112+
numFrames -= numSamples;
113+
114+
buffer[buffer.length - 1] = 0;
115+
active = (active + 1) % directSound.ringSize;
116+
buffer = directSound.buffer[active];
117+
} else {
118+
const source = buffer.subarray(0, numFrames);
119+
for (let channel = 0; channel < numChannels; ++channel) {
120+
const channelData = event.outputBuffer.getChannelData(channel);
121+
channelData.set(source, offset);
122+
}
123+
124+
buffer[buffer.length - 1] = numSamples - numFrames;
125+
buffer.set(buffer.subarray(numFrames, numFrames + buffer[buffer.length - 1]));
126+
numFrames = 0;
127+
}
128+
}
129+
};
130+
131+
const onQueueProcess = (event: AudioProcessingEvent) => {
85132
const numFrames = event.outputBuffer.length;
86133
const numChannels = event.outputBuffer.numberOfChannels;
87134
const samplesCount = samplesQueue.length();
@@ -100,6 +147,7 @@ export function audioNode(ci: CommandInterface) {
100147
}
101148
};
102149

150+
audioNode.onaudioprocess = ci.directSound !== undefined ? onDirectProcess : onQueueProcess;
103151
audioNode.connect(audioContext.destination);
104152

105153
const resumeWebAudio = () => {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,10 +2457,10 @@ emoji-regex@^8.0.0:
24572457
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
24582458
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
24592459

2460-
emulators@^0.72.0:
2461-
version "0.72.0"
2462-
resolved "https://registry.yarnpkg.com/emulators/-/emulators-0.72.0.tgz#86f301421e0ca9aaa43a9e14d73e0ee61ebde35d"
2463-
integrity sha512-tTln9/LbHQqRD+0PPYapazZK8eqm0OhSRJ/zg7kXgugS/xVTMFnRX+Rc7RacRobFohecRLOufcV7HhpNPLHDbQ==
2460+
emulators@^0.73.0:
2461+
version "0.73.0"
2462+
resolved "https://registry.yarnpkg.com/emulators/-/emulators-0.73.0.tgz#e3cef51700aaac1495a7656ab02009749c84bf17"
2463+
integrity sha512-gxUtw1KkgNZOXoPdt5dVDQZMakxC+iBZ2pgrGjZYa10kph08Yn4A7+6IdB69HNn2UxiPwr1JZ516viUIdCjGUw==
24642464

24652465
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
24662466
version "1.4.4"

0 commit comments

Comments
 (0)