From 7ca9dfe7fe18e6dc627c45fa197b6622c4cdd4ed Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 3 Jan 2025 16:22:24 -0800 Subject: [PATCH] Wind Waker: Fix some render inst template leaks --- src/Common/JSYSTEM/J2Dv1.ts | 2 -- src/ZeldaWindWaker/Main.ts | 18 ++++++++++-------- src/ZeldaWindWaker/d_a.ts | 8 +++----- src/ZeldaWindWaker/d_camera.ts | 16 +++++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Common/JSYSTEM/J2Dv1.ts b/src/Common/JSYSTEM/J2Dv1.ts index 576fb1b5f..09df5fb04 100644 --- a/src/Common/JSYSTEM/J2Dv1.ts +++ b/src/Common/JSYSTEM/J2Dv1.ts @@ -432,7 +432,6 @@ export class J2DPicture extends J2DPane { if (this.tex === null || this.sdraw === null) return; - renderInstManager.pushTemplate(); const renderInst = renderInstManager.newRenderInst(); ctx2D.setOnRenderInst(renderInst); @@ -452,7 +451,6 @@ export class J2DPicture extends J2DPane { this.materialHelper.allocateDrawParamsDataOnInst(renderInst, drawParams); renderInstManager.submitRenderInst(renderInst); - renderInstManager.popTemplate(); } public override destroy(device: GfxDevice): void { diff --git a/src/ZeldaWindWaker/Main.ts b/src/ZeldaWindWaker/Main.ts index 8e8e7b4b7..27d750ec8 100644 --- a/src/ZeldaWindWaker/Main.ts +++ b/src/ZeldaWindWaker/Main.ts @@ -415,7 +415,7 @@ export class WindWakerRenderer implements Viewer.SceneGfx { globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, group); } - // From mDoGph_Painter(). Draw the 2D particle groups with different view/proj matrices. + // From mDoGph_Painter(). Draw the 2D particle groups with different view/proj matrices. { const orthoCtx = this.globals.scnPlay.currentGrafPort; const template = renderInstManager.pushTemplate(); @@ -424,7 +424,7 @@ export class WindWakerRenderer implements Viewer.SceneGfx { const viewMtx = scratchMatrix; computeModelMatrixT(viewMtx, orthoCtx.aspectRatioCorrection * 320, 240, 0); globals.particleCtrl.setDrawInfo(viewMtx, orthoCtx.sceneParams.u_Projection, null, null); - + renderInstManager.setCurrentList(dlst.particle2DBack); globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDback); globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDmenuBack); @@ -432,6 +432,8 @@ export class WindWakerRenderer implements Viewer.SceneGfx { renderInstManager.setCurrentList(dlst.particle2DFore); globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDfore); globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDmenuFore); + + renderInstManager.popTemplate(); } } @@ -452,7 +454,7 @@ export class WindWakerRenderer implements Viewer.SceneGfx { const dlst = this.globals.dlst; dlst.peekZ.beginFrame(device); - // From mDoGph_Painter, + // From mDoGph_Painter, this.globals.scnPlay.currentGrafPort.setOrtho(-9.0, -21.0, 650.0, 503.0, 100000.0, -100000.0); this.globals.scnPlay.currentGrafPort.setPort(viewerInput.backbufferWidth, viewerInput.backbufferHeight); @@ -902,8 +904,8 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc { super(stageDir, name, roomList); assert(this.roomList.length === 1); - // Use a distinct ID for demos so that we don't conflict with the non-demo version of this stage. - // Without this, going to a scene like Outset Island and reloading will select the first Outset Island demo. + // Use a distinct ID for demos so that we don't conflict with the non-demo version of this stage. + // Without this, going to a scene like Outset Island and reloading will select the first Outset Island demo. this.id = this.stbFilename.slice(0, -4); } @@ -918,7 +920,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc { // TODO: Don't render until the camera has been placed for this demo. The cuts are jarring. - // noclip modification: This normally happens on room load. Do it here instead so that we don't waste time + // noclip modification: This normally happens on room load. Do it here instead so that we don't waste time // loading .arcs for cutscenes that aren't going to be played const lbnk = globals.roomCtrl.status[this.roomList[0]].data.lbnk; if (lbnk) { @@ -979,7 +981,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc { // Most of this data comes from the PLAY action of the PACKAGE actor in an event from a Stage's event_list.dat. This // action has properties for the room and layer that these cutscenes are designed for. HOWEVER, this data is often missing. // It has been reconstructed by cross-referencing each Room's lbnk section (which points to a Demo*.arc file for each layer), -// the .stb files contained in each of those Objects/Demo*.arc files, and the FileName attribute from the event action. +// the .stb files contained in each of those Objects/Demo*.arc files, and the FileName attribute from the event action. const demoDescs = [ new DemoDesc("sea", "Pirate Zelda Fly", [44], "kaizoku_zelda_fly.stb", 0, [-200000.0, 0.0, 320000.0], 180.0, 0, 0), new DemoDesc("sea", "Zola Awakens", [13], "awake_zola.stb", 8, [200000.0, 0.0, -200000.0], 0, 227, 0), @@ -1030,7 +1032,7 @@ const demoDescs = [ new DemoDesc("sea_T", "Departure", [0xFF], "departure.stb", 0, [-200000.0, 0.0, 320000.0], 0.0, 0, 0), new DemoDesc("sea_T", "PirateZeldaFly", [0xFF], "kaizoku_zelda_fly.stb", 0, [-200000.0, 0.0, 320000.0], 180.0, 0, 0), - // The game expects this STB file to be in Stage/Ocean/Stage.arc, but it is not. Must be a leftover. + // The game expects this STB file to be in Stage/Ocean/Stage.arc, but it is not. Must be a leftover. new DemoDesc("Ocean", "counter.stb", [-1], "counter.stb", 0, [0, 0, 0], 0, 0, 0), ] diff --git a/src/ZeldaWindWaker/d_a.ts b/src/ZeldaWindWaker/d_a.ts index e9d959a8d..596221ed8 100644 --- a/src/ZeldaWindWaker/d_a.ts +++ b/src/ZeldaWindWaker/d_a.ts @@ -6058,11 +6058,9 @@ class d_a_title extends fopAc_ac_c { this.btkSubtitle.frameCtrl.setFrame(this.btkSubtitle.frameCtrl.endFrame); this.panes[TitlePane.Nintendo].setAlpha(1.0); - if (this.blinkFrameCounter >= 100) { - this.blinkFrameCounter = 0; - } else { - this.blinkFrameCounter += deltaTimeFrames; - } + this.blinkFrameCounter += deltaTimeFrames; + while (this.blinkFrameCounter >= 100) + this.blinkFrameCounter -= 100; if (this.blinkFrameCounter >= 50) { this.panes[TitlePane.PressStart].setAlpha((this.blinkFrameCounter - 50) / 50.0); diff --git a/src/ZeldaWindWaker/d_camera.ts b/src/ZeldaWindWaker/d_camera.ts index 6bee01c6f..b7468b803 100644 --- a/src/ZeldaWindWaker/d_camera.ts +++ b/src/ZeldaWindWaker/d_camera.ts @@ -9,7 +9,7 @@ import { dGlobals } from "./Main.js"; import { EDemoCamFlags } from "./d_demo.js"; import { projectionMatrixReverseDepth } from "../gfx/helpers/ReversedDepthHelpers.js"; import { projectionMatrixConvertClipSpaceNearZ } from "../gfx/helpers/ProjectionHelpers.js"; -import { GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js"; +import { GfxRenderInst, GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js"; import { calcLODBias, fillSceneParamsData, SceneParams, ub_SceneParamsBufferSize } from "../gx/gx_render.js"; import { GX_Program } from "../gx/gx_material.js"; import { ViewerRenderInput } from "../viewer.js"; @@ -167,16 +167,18 @@ export class dCamera_c extends leafdraw_class { } } - // Executes before any other draw in other systems - override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { - const template = renderInstManager.pushTemplate(); - - mat4.copy(sceneParams.u_Projection, globals.camera.clipFromViewMatrix); + public setOnRenderInst(globals: dGlobals, renderInst: GfxRenderInst, viewerInput: ViewerRenderInput): void { + mat4.copy(sceneParams.u_Projection, this.clipFromViewMatrix); sceneParams.u_SceneTextureLODBias = calcLODBias(viewerInput.backbufferWidth, viewerInput.backbufferHeight); - const d = template.allocateUniformBufferF32(GX_Program.ub_SceneParams, ub_SceneParamsBufferSize); + const d = renderInst.allocateUniformBufferF32(GX_Program.ub_SceneParams, ub_SceneParamsBufferSize); fillSceneParamsData(d, 0, sceneParams); } + public override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { + const template = renderInstManager.getCurrentTemplate(); + this.setOnRenderInst(globals, template, viewerInput); + } + public applyScissor(pass: GfxRenderPass) { if (this.enableLetterboxing) { pass.setScissor(this.scissor[0], this.scissor[1], this.scissor[2], this.scissor[3]);