Skip to content

Commit

Permalink
Wind Waker: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Dec 27, 2024
1 parent 456dd20 commit 4a53221
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 60 deletions.
12 changes: 3 additions & 9 deletions src/Common/JSYSTEM/J2Dv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import ArrayBufferSlice from "../../ArrayBufferSlice.js";
import { JSystemFileReaderHelper } from "./J3D/J3DLoader.js";
import { align, assert, readString } from "../../util.js";
import { align, assert, assertExists, readString } from "../../util.js";
import { Color, colorNewFromRGBA8 } from "../../Color.js";
import { GfxRenderInst, GfxRenderInstManager } from "../../gfx/render/GfxRenderInstManager.js";
import * as GX_Material from '../../gx/gx_material.js';
Expand Down Expand Up @@ -451,20 +451,14 @@ export class J2DPicture extends J2DPane {
//#region J2DScreen
export class J2DScreen extends J2DPane {
public color: Color
private defaultCtx: J2DGrafContext;

constructor(data: SCRN, cache: GfxRenderCache) {
super(data.panes[0], cache, null);
this.defaultCtx = new J2DGrafContext(cache.device, 0.0, 0.0, 640.0, 480.0, -1.0, 0.0);
this.color = data.inf1.color;
}

override draw(renderInstManager: GfxRenderInstManager, viewerRenderInput: ViewerRenderInput, ctx2D: J2DGrafContext | null, offsetX?: number, offsetY?: number): void {
if (ctx2D !== null) {
super.draw(renderInstManager, viewerRenderInput, ctx2D, offsetX, offsetY);
} else {
super.draw(renderInstManager, viewerRenderInput, this.defaultCtx, offsetX, offsetY);
}
public override draw(renderInstManager: GfxRenderInstManager, viewerRenderInput: ViewerRenderInput, ctx2D: J2DGrafContext, offsetX?: number, offsetY?: number): void {
super.draw(renderInstManager, viewerRenderInput, ctx2D, offsetX, offsetY);
}
}

Expand Down
27 changes: 13 additions & 14 deletions src/SuperMarioGalaxy/Actors/LensFlare.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@

import { NameObj } from "../NameObj.js";
import { SceneObjHolder, SceneObj } from "../Main.js";
import { connectToSceneMapObjMovement, getPlayerPos, getAreaObj, connectToScene3DModelFor2D, showModel, hideModel, startBrk, setBrkFrameAndStop, getBrkFrameMax, startBtk, startBckWithInterpole, isBckStopped, setBckFrameAndStop, getBckFrameMax, setMtxAxisXYZ, getCamYdir } from "../ActorUtil.js";
import { ViewerRenderInput } from "../../viewer.js";
import { vec3, vec2, vec4, mat4, ReadonlyVec3, ReadonlyVec4 } from "gl-matrix";
import { AreaObj, AreaFormType } from "../AreaObj.js";
import { JMapInfoIter, getJMapInfoArg0 } from "../JMapInfo.js";
import { fallback } from "../../util.js";
import { LiveActor, ZoneAndLayer, isDead, dynamicSpawnZoneAndLayer } from "../LiveActor.js";
import { isFirstStep } from "../Spine.js";
import { saturate, MathConstants, setMatrixTranslation, transformVec3Mat4w1, vec3SetAll } from "../../MathHelpers.js";
import { divideByW } from "../../Camera.js";
import { ReadonlyVec3, mat4, vec2, vec3 } from "gl-matrix";
import { MathConstants, saturate, setMatrixTranslation, transformVec3Mat4w1, vec3SetAll } from "../../MathHelpers.js";
import { PeekZManager, PeekZResult } from "../../ZeldaWindWaker/d_dlst_peekZ.js";
import { GfxDevice, GfxCompareMode, GfxClipSpaceNearZ } from "../../gfx/platform/GfxPlatform.js";
import { gfxDeviceNeedsFlipY } from "../../gfx/helpers/GfxDeviceHelpers.js";
import { compareDepthValues } from "../../gfx/helpers/ReversedDepthHelpers.js";
import { GfxClipSpaceNearZ, GfxCompareMode, GfxDevice } from "../../gfx/platform/GfxPlatform.js";
import { GfxrGraphBuilder, GfxrRenderTargetID } from "../../gfx/render/GfxRenderGraph.js";
import { GfxRenderInstManager } from "../../gfx/render/GfxRenderInstManager.js";
import { gfxDeviceNeedsFlipY } from "../../gfx/helpers/GfxDeviceHelpers.js";
import { fallback } from "../../util.js";
import { ViewerRenderInput } from "../../viewer.js";
import { connectToScene3DModelFor2D, connectToSceneMapObjMovement, getAreaObj, getBckFrameMax, getBrkFrameMax, getCamYdir, getPlayerPos, hideModel, isBckStopped, setBckFrameAndStop, setBrkFrameAndStop, setMtxAxisXYZ, showModel, startBckWithInterpole, startBrk, startBtk } from "../ActorUtil.js";
import { AreaFormType, AreaObj } from "../AreaObj.js";
import { JMapInfoIter, getJMapInfoArg0 } from "../JMapInfo.js";
import { LiveActor, ZoneAndLayer, dynamicSpawnZoneAndLayer, isDead } from "../LiveActor.js";
import { SceneObj, SceneObjHolder } from "../Main.js";
import { NameObj } from "../NameObj.js";
import { isFirstStep } from "../Spine.js";

function calcRotateY(x: number, y: number): number {
return (MathConstants.TAU / 4) + Math.atan2(-y, x);
Expand Down
4 changes: 2 additions & 2 deletions src/ZeldaTwilightPrincess/d_kankyo_wether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TDDraw } from "../SuperMarioGalaxy/DDraw.js";
import { TextureMapping } from "../TextureHolder.js";
import { cLib_addCalc, cM_s2rad, cM_rndF, cM_rndFX } from "../ZeldaWindWaker/SComponent.js";
import { PeekZManager, PeekZResult } from "../ZeldaWindWaker/d_dlst_peekZ.js";
import { mDoLib_project, mDoLib_projectFB } from "../ZeldaWindWaker/m_do_ext.js";
import { mDoLib_projectFB } from "../ZeldaWindWaker/m_do_ext.js";
import { MtxTrans, calc_mtx, mDoMtx_XrotM, mDoMtx_ZrotM } from "../ZeldaWindWaker/m_do_mtx.js";
import { fullscreenMegaState, setAttachmentStateSimple } from "../gfx/helpers/GfxMegaStateDescriptorHelpers.js";
import { GfxShaderLibrary } from "../gfx/helpers/GfxShaderLibrary.js";
Expand Down Expand Up @@ -1533,7 +1533,7 @@ function dKyr_sun_move(globals: dGlobals, deltaTimeFrames: number): void {

if (sunCanGlare) {
// Original game projects the vector into viewport space, and gets distance to 320, 240.
mDoLib_project(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);
vec3.transformMat4(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);

const peekZ = globals.dlst.peekZ;

Expand Down
5 changes: 5 additions & 0 deletions src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { dStage_dt_c_roomLoader, dStage_dt_c_roomReLoader, dStage_dt_c_stageInit
import { WoodPacket } from './d_wood.js';
import { fopAcM_create, fopAcM_searchFromName, fopAc_ac_c } from './f_op_actor.js';
import { cPhs__Status, fGlobals, fopDw_Draw, fopScn, fpcCt_Handler, fpcLy_SetCurrentLayer, fpcM_Management, fpcPf__Register, fpcSCtRq_Request, fpc_pc__ProfileList } from './framework.js';
import { J2DGrafContext } from '../Common/JSYSTEM/J2Dv1.js';

type SymbolData = { Filename: string, SymbolName: string, Data: ArrayBufferSlice };
type SymbolMapData = { SymbolData: SymbolData[] };
Expand Down Expand Up @@ -864,6 +865,8 @@ class d_s_play extends fopScn {
public placenameIndex: Placename;
public placenameState: PlacenameState;

public orthoGraf2D: J2DGrafContext;

public override load(globals: dGlobals, userData: any): cPhs__Status {
super.load(globals, userData);

Expand All @@ -874,6 +877,8 @@ class d_s_play extends fopScn {
this.grassPacket = new GrassPacket(globals);
this.woodPacket = new WoodPacket(globals);

this.orthoGraf2D = new J2DGrafContext(globals.modelCache.device, 0.0, 0.0, 608.0, 448.0, -1.0, 0.0);

globals.scnPlay = this;

return cPhs__Status.Complete;
Expand Down
24 changes: 12 additions & 12 deletions src/ZeldaWindWaker/d_a.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@

import { ReadonlyMat4, ReadonlyVec3, mat4, quat, vec2, vec3 } from "gl-matrix";
import { TransparentBlack, colorCopy, colorFromRGBA8, colorNewCopy, colorNewFromRGBA8 } from "../Color.js";
import { calcANK1JointAnimationTransform } from "../Common/JSYSTEM/J3D/J3DGraphAnimator.js";
import { J3DModelData, J3DModelInstance, buildEnvMtx } from "../Common/JSYSTEM/J3D/J3DGraphBase.js";
import { JointTransformInfo, LoopMode, TRK1, TTK1 } from "../Common/JSYSTEM/J3D/J3DLoader.js";
import { JPABaseEmitter, JPASetRMtxSTVecFromMtx } from "../Common/JSYSTEM/JPA.js";
import { BTIData } from "../Common/JSYSTEM/JUTTexture.js";
import { Vec3One, Vec3UnitY, Vec3UnitZ, Vec3Zero, clamp, computeMatrixWithoutTranslation, computeModelMatrixR, computeModelMatrixS, lerp, saturate, scaleMatrix, transformVec3Mat4w0, transformVec3Mat4w1 } from "../MathHelpers.js";
import { GlobalSaveManager } from "../SaveManager.js";
import { TDDraw, TSDraw } from "../SuperMarioGalaxy/DDraw.js";
import { TextureMapping } from "../TextureHolder.js";
import { Endianness } from "../endian.js";
import { compareDepthValues } from "../gfx/helpers/ReversedDepthHelpers.js";
import { GfxClipSpaceNearZ, GfxCompareMode, GfxDevice, GfxTexture } from "../gfx/platform/GfxPlatform.js";
import { GfxClipSpaceNearZ, GfxCompareMode, GfxDevice } from "../gfx/platform/GfxPlatform.js";
import { GfxRenderCache } from "../gfx/render/GfxRenderCache.js";
import { GfxRendererLayer, GfxRenderInst, GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { GfxRenderInst, GfxRenderInstManager, GfxRendererLayer } from "../gfx/render/GfxRenderInstManager.js";
import { GXMaterialBuilder } from "../gx/GXMaterialBuilder.js";
import * as GX from '../gx/gx_enum.js';
import { TevDefaultSwapTables } from "../gx/gx_material.js";
import { ColorKind, DrawParams, GXMaterialHelperGfx, MaterialParams } from "../gx/gx_render.js";
import { arrayRemove, assert, assertExists, nArray } from "../util.js";
import { ViewerRenderInput } from "../viewer.js";
import { cLib_addCalc, cLib_addCalc2, cLib_addCalcAngleRad2, cLib_addCalcAngleS, cLib_addCalcAngleS2, cLib_addCalcPosXZ2, cLib_chasePosXZ, cLib_distanceSqXZ, cLib_distanceXZ, cLib_targetAngleX, cLib_targetAngleY, cM_s2rad, cM_atan2s, cM_rndF, cM_rndFX } from "./SComponent.js";
import { dGlobals } from "./Main.js";
import { cLib_addCalc, cLib_addCalc2, cLib_addCalcAngleRad2, cLib_addCalcAngleS, cLib_addCalcAngleS2, cLib_addCalcPosXZ2, cLib_chasePosXZ, cLib_distanceSqXZ, cLib_distanceXZ, cLib_targetAngleX, cLib_targetAngleY, cM_atan2s, cM_rndF, cM_rndFX, cM_s2rad } from "./SComponent.js";
import { dLib_getWaterY, dLib_waveInit, dLib_waveRot, dLib_wave_c, d_a_sea } from "./d_a_sea.js";
import { cBgW_Flags, dBgS_GndChk, dBgW } from "./d_bg.js";
import { EDemoActorFlags, dDemo_setDemoData } from "./d_demo.js";
import { PeekZResult } from "./d_dlst_peekZ.js";
import { dDlst_alphaModel__Type } from "./d_drawlist.js";
import { LIGHT_INFLUENCE, LightType, WAVE_INFO, dKy_change_colpat, dKy_checkEventNightStop, dKy_plight_cut, dKy_plight_set, dKy_setLight__OnMaterialParams, dKy_setLight__OnModelInstance, dKy_tevstr_c, dKy_tevstr_init, setLightTevColorType, settingTevStruct } from "./d_kankyo.js";
import { ThunderMode, dKyr_get_vectle_calc, dKyw_get_AllWind_vecpow, dKyw_get_wind_pow, dKyw_get_wind_vec, dKyw_rain_set, loadRawTexture } from "./d_kankyo_wether.js";
import { dPa_splashEcallBack, dPa_trackEcallBack, dPa_waveEcallBack } from "./d_particle.js";
import { dProcName_e } from "./d_procname.js";
import { ResType, dComIfG_resLoad } from "./d_resorce.js";
import { dPath, dPath_GetRoomPath, dPath__Point, dStage_Multi_c, dStage_stagInfo_GetSTType } from "./d_stage.js";
import { fopAcIt_JudgeByID, fopAcM_create, fopAcM_prm_class, fopAc_ac_c } from "./f_op_actor.js";
import { cPhs__Status, fGlobals, fpcPf__Register, fpcSCtRq_Request, fpc_bs__Constructor } from "./framework.js";
import { mDoExt_McaMorf, mDoExt_bckAnm, mDoExt_brkAnm, mDoExt_btkAnm, mDoExt_btpAnm, mDoExt_modelEntryDL, mDoExt_modelUpdateDL, mDoLib_project } from "./m_do_ext.js";
import { mDoExt_McaMorf, mDoExt_bckAnm, mDoExt_brkAnm, mDoExt_btkAnm, mDoExt_btpAnm, mDoExt_modelEntryDL, mDoExt_modelUpdateDL } from "./m_do_ext.js";
import { MtxPosition, MtxTrans, calc_mtx, mDoMtx_XYZrotM, mDoMtx_XrotM, mDoMtx_YrotM, mDoMtx_YrotS, mDoMtx_ZXYrotM, mDoMtx_ZrotM, mDoMtx_ZrotS, quatM } from "./m_do_mtx.js";
import { dGlobals } from "./Main.js";
import { dDlst_alphaModel__Type } from "./d_drawlist.js";
import { dDemo_setDemoData, EDemoActorFlags } from "./d_demo.js";
import { fopAc_ac_c, fopAcIt_JudgeByID, fopAcM_create, fopAcM_prm_class } from "./f_op_actor.js";
import { dProcName_e } from "./d_procname.js";
import { TextureMapping } from "../TextureHolder.js";
import { calcANK1JointAnimationTransform } from "../Common/JSYSTEM/J3D/J3DGraphAnimator.js";

// Framework'd actors

Expand Down Expand Up @@ -4573,7 +4573,7 @@ export class d_a_ff extends fopAc_ac_c {
const peekZ = globals.dlst.peekZ;
const dst = this.peekZResult;

mDoLib_project(scratchVec3a, this.pos, globals.camera.clipFromWorldMatrix);
vec3.transformMat4(scratchVec3a, this.pos, globals.camera.clipFromWorldMatrix);
if (globals.camera.clipSpaceNearZ === GfxClipSpaceNearZ.NegativeOne)
scratchVec3a[2] = scratchVec3a[2] * 0.5 + 0.5;

Expand Down
6 changes: 3 additions & 3 deletions src/ZeldaWindWaker/d_kankyo_wether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { dKy_GxFog_sea_set, dKy_actor_addcol_amb_set, dKy_actor_addcol_dif_set,
import { ResType } from "./d_resorce.js";
import { dStage_FileList_dt_c, dStage_stagInfo_GetSTType } from "./d_stage.js";
import { cPhs__Status, fGlobals, fopKyM_Delete, fopKyM_create, fpcPf__Register, fpc_bs__Constructor, kankyo_class } from "./framework.js";
import { mDoExt_brkAnm, mDoExt_btkAnm, mDoExt_modelUpdateDL, mDoLib_project, mDoLib_projectFB } from "./m_do_ext.js";
import { mDoExt_brkAnm, mDoExt_btkAnm, mDoExt_modelUpdateDL, mDoLib_projectFB } from "./m_do_ext.js";
import { MtxTrans, calc_mtx, mDoMtx_XrotM, mDoMtx_ZrotM } from "./m_do_mtx.js";
import { dGlobals } from "./Main.js";
import { dProcName_e } from "./d_procname.js";
Expand Down Expand Up @@ -1618,7 +1618,7 @@ function dKyr_sun_move(globals: dGlobals): void {

if (sunCanGlare) {
// Original game projects the vector into viewport space, and gets distance to 320, 240.
mDoLib_project(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);
vec3.transformMat4(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);

const peekZ = globals.dlst.peekZ;

Expand Down Expand Up @@ -1716,7 +1716,7 @@ function dKyr_lenzflare_move(globals: dGlobals): void {
vec3.scaleAndAdd(pkt.lensflarePos[i], pkt.sunPos, scratchVec3, -intensity * whichLenz);
}

mDoLib_project(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);
vec3.transformMat4(scratchVec3, pkt.sunPos, globals.camera.clipFromWorldMatrix);
pkt.lensflareAngle = Math.atan2(scratchVec3[1], scratchVec3[0]) + Math.PI / 2;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZeldaWindWaker/d_place_name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { J2DGrafContext, J2DPicture, J2DScreen } from "../Common/JSYSTEM/J2Dv1.js";
import { J2DPicture, J2DScreen } from "../Common/JSYSTEM/J2Dv1.js";
import { BTI, BTIData } from "../Common/JSYSTEM/JUTTexture.js";
import { GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { ViewerRenderInput } from "../viewer.js";
Expand Down Expand Up @@ -114,7 +114,7 @@ export class d_place_name extends msg_class {

public override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
renderInstManager.setCurrentList(globals.dlst.ui[0]);
this.screen.draw(renderInstManager, viewerInput, null);
this.screen.draw(renderInstManager, viewerInput, globals.scnPlay.orthoGraf2D);
}

public override execute(globals: dGlobals, deltaTimeFrames: number): void {
Expand Down
23 changes: 7 additions & 16 deletions src/ZeldaWindWaker/m_do_ext.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import { J3DFrameCtrl, J3DFrameCtrl__UpdateFlags, entryTexMtxAnimator, entryTevRegAnimator, entryTexNoAnimator, VAF1_getVisibility, entryJointAnimator, calcJointMatrixFromTransform, calcANK1JointAnimationTransform } from "../Common/JSYSTEM/J3D/J3DGraphAnimator.js";
import { TTK1, LoopMode, TRK1, AnimationBase, TPT1, VAF1, ANK1, JointTransformInfo } from "../Common/JSYSTEM/J3D/J3DLoader.js";
import { J3DModelInstance, J3DModelData, JointMatrixCalc, ShapeInstanceState } from "../Common/JSYSTEM/J3D/J3DGraphBase.js";
import { mat4, ReadonlyMat4, ReadonlyVec3, vec3 } from "gl-matrix";
import { calcANK1JointAnimationTransform, calcJointMatrixFromTransform, entryJointAnimator, entryTevRegAnimator, entryTexMtxAnimator, entryTexNoAnimator, J3DFrameCtrl, J3DFrameCtrl__UpdateFlags, VAF1_getVisibility } from "../Common/JSYSTEM/J3D/J3DGraphAnimator.js";
import { J3DModelData, J3DModelInstance, JointMatrixCalc, ShapeInstanceState } from "../Common/JSYSTEM/J3D/J3DGraphBase.js";
import { AnimationBase, ANK1, JointTransformInfo, LoopMode, TPT1, TRK1, TTK1, VAF1 } from "../Common/JSYSTEM/J3D/J3DLoader.js";
import { GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { ViewerRenderInput } from "../viewer.js";
import { dCamera_c, dGlobals } from "./Main.js";
import { mat4, ReadonlyMat4, vec3, vec4 } from "gl-matrix";
import { Camera, divideByW } from "../Camera.js";
import { dDlst_list_Set } from "./d_drawlist.js";
import { dGlobals } from "./Main.js";

abstract class mDoExt_baseAnm<T extends AnimationBase> {
public frameCtrl = new J3DFrameCtrl(0);
Expand Down Expand Up @@ -236,16 +235,8 @@ export class mDoExt_McaMorf implements JointMatrixCalc {
}
}

const scratchVec4 = vec4.create();
export function mDoLib_project(dst: vec3, v: vec3, clipFromWorldMatrix: ReadonlyMat4, v4 = scratchVec4): void {
vec4.set(v4, v[0], v[1], v[2], 1.0);
vec4.transformMat4(v4, v4, clipFromWorldMatrix);
divideByW(v4, v4);
vec3.set(dst, v4[0], v4[1], v4[2]);
}

export function mDoLib_projectFB(dst: vec3, v: vec3, viewerInput: ViewerRenderInput, clipFromWorldMatrix: ReadonlyMat4 = viewerInput.camera.clipFromWorldMatrix): void {
mDoLib_project(dst, v, clipFromWorldMatrix);
export function mDoLib_projectFB(dst: vec3, v: ReadonlyVec3, viewerInput: ViewerRenderInput, clipFromWorldMatrix: ReadonlyMat4 = viewerInput.camera.clipFromWorldMatrix): void {
vec3.transformMat4(dst, v, clipFromWorldMatrix);
// Put in viewport framebuffer space.
dst[0] = (dst[0] * 0.5 + 0.5) * viewerInput.backbufferWidth;
dst[1] = (dst[1] * 0.5 + 0.5) * viewerInput.backbufferHeight;
Expand Down
2 changes: 0 additions & 2 deletions src/gx/gx_material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,6 @@ export function lightSetWorldPosition(light: Light, viewMatrix: ReadonlyMat4, v:
}

export function lightSetWorldDirection(light: Light, viewMatrix: ReadonlyMat4, v: ReadonlyVec3): void {
// TODO(jstpierre): In theory, we should multiply by the inverse-transpose of the view matrix.
// However, I don't want to calculate that right now, and it shouldn't matter too much...
transformVec3Mat4w0(light.Direction, viewMatrix, v);
vec3.normalize(light.Direction, v);
}
Expand Down

0 comments on commit 4a53221

Please sign in to comment.