Skip to content

Commit

Permalink
Wind Waker: Fix black bar issue when title demo ends
Browse files Browse the repository at this point in the history
Previously, as soon as the Title demo ended the camera would reset to cinematic trimming mode (because `globals.scnPlay.demo.getName()` is null), then immediately transition back to default trimming.

Now the camera stores its trim height via `setTrimHeight()` which is reset on scene creation. This is closer to the game logic.
  • Loading branch information
themikelester committed Jan 4, 2025
1 parent 8bb2037 commit e51b903
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { LegacyActor__RegisterFallbackConstructor } from './LegacyActor.js';
import { dDlst_2DStatic_c, d_a__RegisterConstructors } from './d_a.js';
import { d_a_sea } from './d_a_sea.js';
import { dBgS } from './d_bg.js';
import { dCamera_c } from './d_camera.js';
import { CameraTrimHeight, dCamera_c } from './d_camera.js';
import { EDemoMode, dDemo_manager_c } from './d_demo.js';
import { dDlst_list_Set, dDlst_list_c } from './d_drawlist.js';
import { dKankyo_create, dKy__RegisterConstructors, dKy_setLight, dScnKy_env_light_c } from './d_kankyo.js';
Expand Down Expand Up @@ -968,6 +968,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc {

if (demoData !== null) {
globals.scnPlay.demo.create(this.id, demoData, this.offsetPos, this.rotY / 180.0 * Math.PI, this.startFrame);
globals.camera.setTrimHeight(this.id != 'title' ? CameraTrimHeight.Cinematic : CameraTrimHeight.Default)
globals.camera.snapToCinematic();
} else {
console.warn('Failed to load demo data:', this.stbFilename);
Expand Down
22 changes: 18 additions & 4 deletions src/ZeldaWindWaker/d_camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const enum CameraMode {
Cinematic
}

export const enum CameraTrimHeight {
Default,
Cinematic,
Vista,
}

export class dCamera_c extends leafdraw_class {
public static PROCESS_NAME = dProcName_e.d_camera;

Expand Down Expand Up @@ -55,10 +61,9 @@ export class dCamera_c extends leafdraw_class {
private demoFov = 0;
private demoRoll = 0;
private trimHeight = 0;
private trimMode = CameraTrimHeight.Default;
private scissor = vec4.create();

private static trimHeightCinematic = 65.0;

public finishSetup(): void {
mat4.invert(this.viewFromWorldMatrix, this.worldFromViewMatrix);
mat4.mul(this.clipFromWorldMatrix, this.clipFromViewMatrix, this.viewFromWorldMatrix);
Expand Down Expand Up @@ -89,6 +94,10 @@ export class dCamera_c extends leafdraw_class {
this.cameraModeBlendVal = 1.0;
}

public setTrimHeight(trimMode: CameraTrimHeight) {
this.trimMode = trimMode;
}

public override load(globals: dGlobals, userData: any): cPhs__Status {
globals.camera = this;
fopDwTg_ToDrawQ(globals.frameworkGlobals, this, this.drawPriority);
Expand Down Expand Up @@ -132,8 +141,13 @@ export class dCamera_c extends leafdraw_class {
globals.sceneContext.inputManager.isMouseEnabled = true;
}

// From dCamera_c::SetTrimSize() and defaultTriming()
const trimSize = globals.scnPlay.demo.getName() != 'title' ? dCamera_c.trimHeightCinematic : 0;
// From dCamera_c::CalcTrimSize()
let trimSize = 0;
switch (this.trimMode) {
case CameraTrimHeight.Cinematic: trimSize = 65.0; break;
case CameraTrimHeight.Vista: trimSize = 35.0; break;
case CameraTrimHeight.Default: trimSize = 0.0; break;
}

// Adapted from dCamera_c::CalcTrimSize()
// When switching between Cinematic and Regular camera modes (e.g. when pausing a cutscene),
Expand Down

0 comments on commit e51b903

Please sign in to comment.