perf(web): eliminate putImageData via WebGL2 quad, sync frame pacing, and add PWA/Service Worker
Replaces `ctx2d.putImageData` with a WebGL2 texture quad in both 117HD and SD modes, aligns the TeaVM game loop with `requestAnimationFrame`, and adds PWA manifest and Service Worker asset caching for mobile/iOS Safari. ### WebGL2 Compositing & SD/HD Rendering - `WebHd117Renderer.java`, `WebGL2.java`: - Decoupled `ensureOverlayContext()` / `ensureOverlayReady()` so the WebGL2 2D overlay quad initializes without compiling 3D shadow/scene shaders when 117HD is off. - Added `drawHudPixels` and `drawHudCanvas` compositing onto `#gl-canvas` with `useBlend` control (disabling `GL_BLEND` for opaque SD frames). - `RSImageProducer.java`, `DesktopHooks.java`: - Routed `RSImageProducer.drawGraphics` and modern HUD draws (`drawModernMinimap`, `drawModernChat`, `drawModernTab`) through the WebGL2 quad whenever `ensureOverlayReady()` succeeds, clearing `#game-canvas` once to avoid `putImageData` overhead. ### Frame Pacing & Mobile PWA - `RSApplet.java`: - Added TeaVM `@Async` `awaitAnimationFrame()` backed by `window.requestAnimationFrame` for `delay <= 16` and capped catch-up ticks per frame (`loopTicks >= 2`). - `index.html`, `manifest.webmanifest`, `sw.js`: - Added Apple Web App meta tags, `manifest.webmanifest`, and `sw.js` Service Worker registration with shell precaching, network-first navigation, and stale-while-revalidate static asset caching.
This commit is contained in:
1 parent
3331ab745b
commit
33235cec55
8 files changed
+412
-41
No files matched your search
@@ -23,7 +23,9 @@ public final class RSImageProducer {
|
||||
|
||||
private static HTMLCanvasElement canvas;
|
||||
private static CanvasRenderingContext2D ctx2d;
|
||||
private static boolean cleared2dForGpu = false;
|
||||
private ImageData imageData;
|
||||
private org.teavm.jso.JSObject imageDataU32;
|
||||
|
||||
public RSImageProducer(int width, int height, Object component) {
|
||||
this.anInt316 = width;
|
||||
@@ -32,6 +34,7 @@ public final class RSImageProducer {
|
||||
ensureCanvas();
|
||||
if (ctx2d != null) {
|
||||
this.imageData = ctx2d.createImageData(width, height);
|
||||
this.imageDataU32 = wrapImageDataU32(this.imageData);
|
||||
}
|
||||
initDrawingArea();
|
||||
}
|
||||
@@ -46,11 +49,19 @@ public final class RSImageProducer {
|
||||
HTMLDocument doc = HTMLDocument.current();
|
||||
canvas = (HTMLCanvasElement) doc.getElementById("game-canvas");
|
||||
if (canvas != null) {
|
||||
ctx2d = (CanvasRenderingContext2D) canvas.getContext("2d");
|
||||
ctx2d = create2dContext(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = {"canvas"}, script =
|
||||
"try { return canvas.getContext('2d', { alpha: true, desynchronized: true }) || canvas.getContext('2d'); }\n" +
|
||||
"catch (_) { return canvas.getContext('2d'); }")
|
||||
private static native CanvasRenderingContext2D create2dContext(HTMLCanvasElement canvas);
|
||||
|
||||
@JSBody(params = {"imgData"}, script = "return new Uint32Array(imgData.data.buffer);")
|
||||
private static native org.teavm.jso.JSObject wrapImageDataU32(ImageData imgData);
|
||||
|
||||
public void initDrawingArea() {
|
||||
DrawingArea.initDrawingArea(anInt317, anInt316, anIntArray315);
|
||||
Texture.textureInt1 = anInt316 / 2;
|
||||
@@ -64,38 +75,47 @@ public final class RSImageProducer {
|
||||
public void drawGraphics(int y, Object graphics, int x) {
|
||||
if (anIntArray315 == null) return;
|
||||
if (ClientSettings.isDesktopModern() && !ModernLayout.inGame) {
|
||||
cleared2dForGpu = false;
|
||||
DesktopHooks.drawScaledLoginTile(graphics, anIntArray315, x, y, anInt316, anInt317);
|
||||
return;
|
||||
}
|
||||
ensureCanvas();
|
||||
if (ctx2d == null) return;
|
||||
boolean gpuViewport = HD117Pipeline.isGpuActive() && anInt316 == ClientSettings.VIEWPORT_WIDTH && anInt317 == ClientSettings.VIEWPORT_HEIGHT;
|
||||
if (WebHd117Renderer.ensureOverlayReady()) {
|
||||
if (!cleared2dForGpu && canvas != null) {
|
||||
ctx2d.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
cleared2dForGpu = true;
|
||||
}
|
||||
WebHd117Renderer.drawHudPixels(anIntArray315, x, y, anInt316, anInt317, gpuViewport);
|
||||
return;
|
||||
}
|
||||
cleared2dForGpu = false;
|
||||
if (imageData == null || imageData.getWidth() != anInt316 || imageData.getHeight() != anInt317) {
|
||||
imageData = ctx2d.createImageData(anInt316, anInt317);
|
||||
imageDataU32 = wrapImageDataU32(imageData);
|
||||
}
|
||||
boolean gpuViewport = HD117Pipeline.isGpuActive() && anInt316 == ClientSettings.VIEWPORT_WIDTH && anInt317 == ClientSettings.VIEWPORT_HEIGHT;
|
||||
if (gpuViewport) {
|
||||
blitOverlayPixelsToImageData(anIntArray315, imageData);
|
||||
blitOverlayPixelsToImageData(anIntArray315, imageDataU32);
|
||||
} else {
|
||||
blitPixelsToImageData(anIntArray315, imageData);
|
||||
blitPixelsToImageData(anIntArray315, imageDataU32);
|
||||
}
|
||||
ctx2d.putImageData(imageData, x, y);
|
||||
}
|
||||
|
||||
@JSBody(params = {"pixels", "imgData"}, script =
|
||||
"var dst = new Uint32Array(imgData.data.buffer);\n" +
|
||||
@JSBody(params = {"pixels", "dst"}, script =
|
||||
"var len = pixels.length;\n" +
|
||||
"for (var i = 0; i < len; i++) {\n" +
|
||||
" var c = pixels[i];\n" +
|
||||
" dst[i] = -16777216 | ((c & 255) << 16) | (c & 65280) | ((c >> 16) & 255);\n" +
|
||||
"}")
|
||||
private static native void blitPixelsToImageData(@JSByRef int[] pixels, ImageData imgData);
|
||||
private static native void blitPixelsToImageData(@JSByRef int[] pixels, org.teavm.jso.JSObject dst);
|
||||
|
||||
@JSBody(params = {"pixels", "imgData"}, script =
|
||||
"var dst = new Uint32Array(imgData.data.buffer);\n" +
|
||||
@JSBody(params = {"pixels", "dst"}, script =
|
||||
"var len = pixels.length;\n" +
|
||||
"for (var i = 0; i < len; i++) {\n" +
|
||||
" var c = pixels[i];\n" +
|
||||
" dst[i] = (c === 66051) ? 0 : (-16777216 | ((c & 255) << 16) | (c & 65280) | ((c >> 16) & 255));\n" +
|
||||
"}")
|
||||
private static native void blitOverlayPixelsToImageData(@JSByRef int[] pixels, ImageData imgData);
|
||||
private static native void blitOverlayPixelsToImageData(@JSByRef int[] pixels, org.teavm.jso.JSObject dst);
|
||||
}
|
||||
Reference in new issue
Block a user