Skip to content

Commit

Permalink
Wind Waker: Make LegacyActor use dCamera_c for globals
Browse files Browse the repository at this point in the history
Keep around the J3DModelInstanceSimple for now, just render it using mDoExt_modelUpdateDL
  • Loading branch information
magcius committed Dec 27, 2024
1 parent da14a3c commit ea8324b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 66 deletions.
3 changes: 0 additions & 3 deletions src/Common/JSYSTEM/J3D/J3DGraphBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,6 @@ export class J3DModelInstance {
if (cullFrustum === null || disableCulling || jnt1.joints[i].bbox.isEmpty()) {
this.jointVisibility[i] = true;
} else {
// Frustum cull.
// Note to future self: joint bboxes do *not* contain their child joints (see: trees in Super Mario Sunshine).
// You *cannot* use PARTIAL_INTERSECTION to optimize frustum culling.
bboxScratch.transform(jnt1.joints[i].bbox, jointToWorldMatrix);
this.jointVisibility[i] = cullFrustum.contains(bboxScratch);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZeldaTwilightPrincess/m_do_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,6 @@ export class mDoExt_morf_c implements JointMatrixCalc {
}

public entryDL(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput, drawListSet: dDlst_list_Set | null = null): void {
mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput, drawListSet);
}
}
17 changes: 5 additions & 12 deletions src/ZeldaWindWaker/LegacyActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { dProcName_e } from './d_procname.js';
import { ResAssetType, ResEntry, ResType } from './d_resorce.js';
import { fopAcM_prm_class, fopAc_ac_c } from './f_op_actor.js';
import { cPhs__Status, fGlobals, fpcPf__RegisterFallback } from './framework.js';
import { mDoExt_McaMorf, mDoExt_modelEntryDL } from './m_do_ext.js';
import { mDoExt_McaMorf, mDoExt_modelEntryDL, mDoExt_modelUpdateDL } from './m_do_ext.js';
import { MtxTrans, calc_mtx, mDoMtx_ZXYrotM } from './m_do_mtx.js';
import { WindWakerRenderer, ZWWExtraTextures, dGlobals } from "./Main.js";

Expand Down Expand Up @@ -1813,7 +1813,7 @@ function spawnLegacyActor(globals: dGlobals, legacy: d_a_noclip_legacy, actor: f

// Special-case actors

export class BMDObjectRenderer {
class BMDObjectRenderer {
public visible = true;
public modelMatrix: mat4 = mat4.create();
public lightTevColorType = LightType.Actor;
Expand Down Expand Up @@ -1851,13 +1851,6 @@ export class BMDObjectRenderer {
this.modelInstance.setMaterialColorWriteEnabled(materialName, v);
}

private setExtraTextures(extraTextures: ZWWExtraTextures): void {
extraTextures.fillExtraTextures(this.modelInstance);

for (let i = 0; i < this.childObjects.length; i++)
this.childObjects[i].setExtraTextures(extraTextures);
}

public prepareToRender(globals: dGlobals, morf: mDoExt_McaMorf | null, device: GfxDevice, renderInstManager: GfxRenderInstManager, viewerInput: Viewer.ViewerRenderInput): void {
if (!this.visible)
return;
Expand All @@ -1879,10 +1872,10 @@ export class BMDObjectRenderer {

if (morf) {
morf.calc();
morf.entryDL(globals, renderInstManager, viewerInput);
morf.entryDL(globals, renderInstManager);
} else {
this.setExtraTextures(globals.renderer.extraTextures);
this.modelInstance.prepareToRender(device, renderInstManager, viewerInput);
this.modelInstance.animationController.setTimeInMilliseconds(viewerInput.time);
mDoExt_modelUpdateDL(globals, this.modelInstance, renderInstManager);
}

for (let i = 0; i < this.childObjects.length; i++)
Expand Down
86 changes: 42 additions & 44 deletions src/ZeldaWindWaker/d_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class d_a_ep extends fopAc_ac_c {
if (this.type === 0 || this.type === 3) {
settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr);
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);

// TODO(jstpierre): ga
}
Expand Down Expand Up @@ -512,7 +512,7 @@ class d_a_bg extends fopAc_ac_c {
settingTevStruct(globals, LightType.BG0 + i, null, this.bgTevStr[i]!);
setLightTevColorType(globals, this.bgModel[i]!, this.bgTevStr[i]!, globals.camera);
// this is actually mDoExt_modelEntryDL
mDoExt_modelUpdateDL(globals, this.bgModel[i]!, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.bgModel[i]!, renderInstManager);
}

const roomNo = this.parameters;
Expand Down Expand Up @@ -626,7 +626,7 @@ class d_a_vrbox extends fopAc_ac_c {
mat4.copy(this.model.modelMatrix, calc_mtx);

dKy_setLight__OnModelInstance(envLight, this.model, globals.camera);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput, globals.dlst.sky);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, globals.dlst.sky);
}
}

Expand Down Expand Up @@ -743,17 +743,17 @@ class d_a_vrbox2 extends fopAc_ac_c {

if (this.usoUmi !== null) {
mat4.copy(this.usoUmi.modelMatrix, calc_mtx);
mDoExt_modelUpdateDL(globals, this.usoUmi, renderInstManager, viewerInput, globals.dlst.sky);
mDoExt_modelUpdateDL(globals, this.usoUmi, renderInstManager, globals.dlst.sky);
}

if (this.kasumiMae !== null) {
mat4.copy(this.kasumiMae.modelMatrix, calc_mtx);
mDoExt_modelUpdateDL(globals, this.kasumiMae, renderInstManager, viewerInput, globals.dlst.sky);
mDoExt_modelUpdateDL(globals, this.kasumiMae, renderInstManager, globals.dlst.sky);
}

calc_mtx[13] += 100.0;
mat4.copy(this.backCloud.modelMatrix, calc_mtx);
mDoExt_modelUpdateDL(globals, this.backCloud, renderInstManager, viewerInput, globals.dlst.sky);
mDoExt_modelUpdateDL(globals, this.backCloud, renderInstManager, globals.dlst.sky);
}
}

Expand Down Expand Up @@ -1086,7 +1086,7 @@ class d_a_obj_Ygush00 extends fopAc_ac_c {

this.btkAnm.entry(this.model);
this.bckAnm.entry(this.model);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
}
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ class d_a_obj_lpalm extends fopAc_ac_c {

settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr);
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
}
}

Expand Down Expand Up @@ -1260,7 +1260,7 @@ class d_a_obj_zouK extends fopAc_ac_c {
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
this.setEffectMtx(globals, this.pos, 0.5);
this.bckAnm.entry(this.model);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
}
}

Expand Down Expand Up @@ -1314,7 +1314,7 @@ class d_a_swhit0 extends fopAc_ac_c {
this.model.setColorOverride(ColorKind.C2, d_a_swhit0.color2Normal);
this.bckAnm.entry(this.model);
this.btkAnm.entry(this.model);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
}
}

Expand Down Expand Up @@ -1511,8 +1511,7 @@ class dDlst_2DObject_c extends dDlst_2DBase_c {
super();
}

public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
const device = globals.modelCache.device;
public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void {
const renderInst = renderInstManager.newRenderInst();

globals.quadStatic.setOnRenderInst(renderInst);
Expand Down Expand Up @@ -1552,8 +1551,7 @@ class dDlst_2DNumber_c extends dDlst_2DBase_c {
return cPhs__Status.Complete;
}

public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
const device = globals.modelCache.device;
public draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void {
const template = renderInstManager.pushTemplate();

globals.quadStatic.setOnRenderInst(template);
Expand Down Expand Up @@ -1967,44 +1965,44 @@ class d_a_mgameboard extends fopAc_ac_c {

settingTevStruct(globals, LightType.Actor, this.pos, this.tevStr);
setLightTevColorType(globals, this.boardModel, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.boardModel, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.boardModel, renderInstManager);

if (!this.minigameActive)
return;

setLightTevColorType(globals, this.cursorModel, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.cursorModel, renderInstManager, viewerInput, globals.dlst.ui);
mDoExt_modelUpdateDL(globals, this.cursorModel, renderInstManager, globals.dlst.ui);

for (let i = 0; i < this.hitModelCount; i++) {
const model = this.hitModels[i];
setLightTevColorType(globals, model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui);
mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui);
}

for (let i = 0; i < this.missModelCount; i++) {
const model = this.missModels[i];
setLightTevColorType(globals, model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui);
mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui);
}

// Show ships after the game ends.
if (this.minigame.bulletNum === 0) {
for (let i = 0; i < this.minigame.ships.length; i++) {
const model = this.shipModels[i];
setLightTevColorType(globals, model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, model, renderInstManager, viewerInput, globals.dlst.ui);
mDoExt_modelUpdateDL(globals, model, renderInstManager, globals.dlst.ui);
}
}

renderInstManager.setCurrentList(globals.dlst.ui[1]);
for (let i = 0; i < this.bullet.length; i++)
this.bullet[i].draw(globals, renderInstManager, viewerInput);
this.bullet[i].draw(globals, renderInstManager);
for (let i = 0; i < this.squid.length; i++)
this.squid[i].draw(globals, renderInstManager, viewerInput);
this.scoreNum.draw(globals, renderInstManager, viewerInput);
this.highscoreNum.draw(globals, renderInstManager, viewerInput);
this.highscoreLabel.draw(globals, renderInstManager, viewerInput);
this.highscorePad.draw(globals, renderInstManager, viewerInput);
this.squid[i].draw(globals, renderInstManager);
this.scoreNum.draw(globals, renderInstManager);
this.highscoreNum.draw(globals, renderInstManager);
this.highscoreLabel.draw(globals, renderInstManager);
this.highscorePad.draw(globals, renderInstManager);
}
}

Expand Down Expand Up @@ -2280,7 +2278,7 @@ class dCloth_packet_c {
renderInstManager.submitRenderInst(renderInst);
}

public cloth_draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
public cloth_draw(globals: dGlobals, renderInstManager: GfxRenderInstManager): void {
/*
const ctx = getDebugOverlayCanvas2D();
Expand Down Expand Up @@ -2382,8 +2380,8 @@ class d_a_sie_flag extends fopAc_ac_c {
settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr);
settingTevStruct(globals, LightType.Actor, this.pos, this.clothTevStr);
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
this.cloth.cloth_draw(globals, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
this.cloth.cloth_draw(globals, renderInstManager);
}

public override execute(globals: dGlobals, deltaTimeFrames: number): void {
Expand Down Expand Up @@ -2468,8 +2466,8 @@ class d_a_tori_flag extends fopAc_ac_c {
settingTevStruct(globals, LightType.BG0, this.pos, this.tevStr);
settingTevStruct(globals, LightType.Actor, this.pos, this.clothTevStr);
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
this.cloth.cloth_draw(globals, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
this.cloth.cloth_draw(globals, renderInstManager);
}

public override execute(globals: dGlobals, deltaTimeFrames: number): void {
Expand Down Expand Up @@ -3188,7 +3186,7 @@ class d_a_kamome extends fopAc_ac_c {

settingTevStruct(globals, LightType.Actor, this.pos, this.tevStr);
setLightTevColorType(globals, this.morf.model, this.tevStr, globals.camera);
this.morf.entryDL(globals, renderInstManager, viewerInput);
this.morf.entryDL(globals, renderInstManager);

// drawWorldSpaceLine(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, this.targetPos, Green, 2);
// drawWorldSpacePoint(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, Magenta, 8);
Expand Down Expand Up @@ -3447,7 +3445,7 @@ class d_a_obj_ikada extends fopAc_ac_c implements ModeFuncExec<d_a_obj_ikada_mod
// update bck
}

mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);

if (this.isSv()) {
// rope, rope end
Expand Down Expand Up @@ -3975,7 +3973,7 @@ class d_a_oship extends fopAc_ac_c implements ModeFuncExec<d_a_oship_mode> {
setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
const specScale = 0.75;
dDlst_texSpecmapST(this.effectMtx, globals, this.pos, this.tevStr, specScale);
mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.model, renderInstManager);

/*
drawWorldSpaceText(getDebugOverlayCanvas2D(), globals.camera.clipFromWorldMatrix, this.pos, `PId: ${this.processId}`, 0, White, { outline: 2 });
Expand Down Expand Up @@ -4251,7 +4249,7 @@ class d_a_obj_flame extends fopAc_ac_c {
if (this.brkAnm !== null)
this.brkAnm.entry(this.model);

mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput, globals.dlst.wetherEffectSet);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, globals.dlst.wetherEffectSet);
}

private mode_wait(globals: dGlobals): void {
Expand Down Expand Up @@ -4707,13 +4705,13 @@ export class d_a_ff extends fopAc_ac_c {
MtxTrans(this.pos, false);
scaleMatrix(calc_mtx, calc_mtx, this.flyScale);
mat4.copy(this.model[0].modelMatrix, calc_mtx);
mDoExt_modelUpdateDL(globals, this.model[0], renderInstManager, viewerInput, globals.dlst.effect);
mDoExt_modelUpdateDL(globals, this.model[0], renderInstManager, globals.dlst.effect);

if (this.glowScale > 0.01) {
mDoMtx_YrotM(calc_mtx, this.liveTimer * 0x0100);
scaleMatrix(calc_mtx, calc_mtx, this.glowScale, this.glowScale * this.glowScaleY, this.glowScale);
mat4.copy(this.model[1].modelMatrix, calc_mtx);
mDoExt_modelUpdateDL(globals, this.model[1], renderInstManager, viewerInput, globals.dlst.effect);
mDoExt_modelUpdateDL(globals, this.model[1], renderInstManager, globals.dlst.effect);
}
}
}
Expand Down Expand Up @@ -4803,13 +4801,13 @@ class d_a_npc_ls1 extends fopNpc_npc_c {
// this.btkAnim.entry(this.morf.model, this.btkFrame);
// this.btpAnim.entry(this.morf.model, this.btpFrame);

this.morf.entryDL(globals, renderInstManager, viewerInput);
this.morf.entryDL(globals, renderInstManager);

mDoExt_modelEntryDL(globals, this.handModel, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.handModel, renderInstManager);

if (this.itemModel) {
setLightTevColorType(globals, this.itemModel, this.tevStr, globals.camera);
mDoExt_modelEntryDL(globals, this.itemModel, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.itemModel, renderInstManager);
}

this.drawShadow();
Expand Down Expand Up @@ -5036,7 +5034,7 @@ class d_a_npc_zl1 extends fopNpc_npc_c {
if (this.btpAnim.anm) this.btpAnim.entry(this.morf.model);
if (this.btkAnim.anm) this.btkAnim.entry(this.morf.model);

this.morf.entryDL(globals, renderInstManager, viewerInput);
this.morf.entryDL(globals, renderInstManager);
}

public override execute(globals: dGlobals, deltaTimeFrames: number): void {
Expand Down Expand Up @@ -5303,15 +5301,15 @@ class d_a_py_lk extends fopAc_ac_c implements ModeFuncExec<d_a_py_lk_mode> {
this.model.setShapeVisible(LkModelShape.Buckle, false);

setLightTevColorType(globals, this.modelKatsura, this.tevStr, globals.camera);
mDoExt_modelEntryDL(globals, this.modelKatsura, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.modelKatsura, renderInstManager);
}

if (this.equippedItem === LkEquipItem.Sword) {
setLightTevColorType(globals, this.equippedItemModel!, this.tevStr, globals.camera);
mDoExt_modelEntryDL(globals, this.equippedItemModel!, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.equippedItemModel!, renderInstManager);

setLightTevColorType(globals, this.modelSwordHilt, this.tevStr, globals.camera);
mDoExt_modelEntryDL(globals, this.modelSwordHilt, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.modelSwordHilt, renderInstManager);
}

// TODO:
Expand All @@ -5326,7 +5324,7 @@ class d_a_py_lk extends fopAc_ac_c implements ModeFuncExec<d_a_py_lk_mode> {
if (this.anmBtk.anm) this.anmBtk.entry(this.model);

setLightTevColorType(globals, this.model, this.tevStr, globals.camera);
mDoExt_modelEntryDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelEntryDL(globals, this.model, renderInstManager);
}

private playerInit(globals: dGlobals) {
Expand Down
2 changes: 1 addition & 1 deletion src/ZeldaWindWaker/d_kankyo_wether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2812,7 +2812,7 @@ export class d_thunder extends kankyo_class {

this.btkAnm.entry(this.model, this.btkTime);
this.brkAnm.entry(this.model);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager, viewerInput);
mDoExt_modelUpdateDL(globals, this.model, renderInstManager);
}

public override execute(globals: dGlobals, deltaTimeFrames: number): void {
Expand Down
Loading

0 comments on commit ea8324b

Please sign in to comment.