Skip to content

Commit

Permalink
Wind Waker: housi destroy fix, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Oct 8, 2023
1 parent f4e7726 commit 530991b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/TwilightPrincess/d_kankyo_wether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ function dKyr_sun_move(globals: dGlobals, deltaTimeInFrames: number): void {
const envLight = globals.g_env_light;
const pkt = envLight.sunPacket!;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (envLight.baseLight.color.r === 0.0 && roomType !== 2) {
dKyr_get_vectle_calc(globals.cameraPosition, envLight.baseLight.pos, scratchVec3);
} else {
Expand Down Expand Up @@ -1687,7 +1687,7 @@ function wether_move_rain(globals: dGlobals, deltaTimeInFrames: number): void {
let fadeMaxXZDist = 0;
let fadeMaxY = 0;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (roomType === 2 && globals.stageName !== 'Ocrogh' && globals.stageName !== 'Omori') {
if (globals.stageName === 'Orichh')
fadeMaxXZDist = 2300.0;
Expand Down
4 changes: 2 additions & 2 deletions src/TwilightPrincess/d_stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ export class stage_stag_info_class {
}

export function dStage_stagInfo_GetSTType(stagInfo: stage_stag_info_class): number {
return (stagInfo.roomTypeAndSchBit >> 16) & 0x07;
return (stagInfo.roomTypeAndSchBit >>> 16) & 0x07;
}

export function dStage_stagInfo_GetArg0(stagInfo: stage_stag_info_class): number {
return (stagInfo.roomTypeAndSchBit >> 20) & 0xFF;
return (stagInfo.roomTypeAndSchBit >>> 20) & 0xFF;
}

export class dStage_Multi_c {
Expand Down
27 changes: 14 additions & 13 deletions src/WindWaker/d_a.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ReadonlyVec3, mat4, quat, vec2, vec3 } from "gl-matrix";
import { Green, Red, TransparentBlack, colorCopy, colorFromRGBA8, colorNewCopy, colorNewFromRGBA8 } from "../Color.js";
import { Green, Magenta, Red, TransparentBlack, colorCopy, colorFromRGBA8, colorNewCopy, colorNewFromRGBA8 } from "../Color.js";
import { J3DModelData, J3DModelInstance, buildEnvMtx } from "../Common/JSYSTEM/J3D/J3DGraphBase.js";
import { LoopMode, TRK1, TTK1 } from "../Common/JSYSTEM/J3D/J3DLoader.js";
import { JPABaseEmitter, JPASetRMtxSTVecFromMtx } from "../Common/JSYSTEM/JPA.js";
Expand All @@ -17,22 +17,23 @@ 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 { assert, assertExists, nArray } from "../util.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__Short2Rad, cM_atan2s, cM_rndF, cM_rndFX } 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 { PeekZResult } from "./d_dlst_peekZ.js";
import { LIGHT_INFLUENCE, LightType, WAVE_INFLUENCE, dKy__waveinfl_cut, dKy__waveinfl_set, 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 { 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 { ResType, dComIfG_resLoad } from "./d_resorce.js";
import { dPath, dPath_GetRoomPath, dPath__Point, dStage_Multi_c } from "./d_stage.js";
import { dPath, dPath_GetRoomPath, dPath__Point, dStage_Multi_c, dStage_stagInfo_GetSTType } from "./d_stage.js";
import { cPhs__Status, fGlobals, fopAcIt_JudgeByID, fopAcM_create, fopAcM_prm_class, fopAc_ac_c, fpcPf__Register, fpcSCtRq_Request, fpc__ProcessName, fpc_bs__Constructor } from "./framework.js";
import { mDoExt_McaMorf, mDoExt_bckAnm, mDoExt_brkAnm, mDoExt_btkAnm, mDoExt_modelEntryDL, mDoExt_modelUpdateDL, mDoLib_project } 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 { dDlst_alphaModel__Type, dGlobals } from "./zww_scenes.js";
import { drawWorldSpacePoint, drawWorldSpaceText, getDebugOverlayCanvas2D } from "../DebugJunk.js";
import { drawWorldSpaceAABB, drawWorldSpacePoint, drawWorldSpaceText, getDebugOverlayCanvas2D } from "../DebugJunk.js";
import { AABB } from "../Geometry.js";

// Framework'd actors

Expand Down Expand Up @@ -661,7 +662,7 @@ class d_a_vrbox2 extends fopAc_ac_c {
let windX = windVec[0];
let windZ = windVec[2];

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (roomType === 2) {
// TODO(jstpierre): #TACT_WIND. Overwrite with tact wind. LinkRM / Orichh / Ojhous2 / Omasao / Onobuta
}
Expand Down Expand Up @@ -751,7 +752,7 @@ class d_a_vrbox2 extends fopAc_ac_c {
const enum Kytag00EffectMode {
None = 0x00,
Rain = 0x01,
Moya2 = 0x02,
Snow = 0x02,
Moya3 = 0x03,
Moya4 = 0x04,
Moya5 = 0x05,
Expand Down Expand Up @@ -949,14 +950,14 @@ class d_a_kytag00 extends fopAc_ac_c {
class d_a_kytag01 extends fopAc_ac_c {
public static PROCESS_NAME = fpc__ProcessName.d_a_kytag01;

private influence = new WAVE_INFLUENCE();
private info = new WAVE_INFO();

public override subload(globals: dGlobals): cPhs__Status {
vec3.copy(this.influence.pos, this.pos);
vec3.copy(this.info.pos, this.pos);

this.influence.innerRadius = this.scale[0] * 5000.0;
this.influence.outerRadius = Math.max(this.scale[2] * 5000.0, this.influence.innerRadius + 500.0);
dKy__waveinfl_set(globals.g_env_light, this.influence);
this.info.innerRadius = this.scale[0] * 5000.0;
this.info.outerRadius = Math.max(this.scale[2] * 5000.0, this.info.innerRadius + 500.0);
globals.g_env_light.waveInfo.push(this.info);

// TODO(jstpierre): Need a Create/Destroy hook that happens on room load / unload for this to work on sea stage.
if (globals.stageName !== 'sea')
Expand Down Expand Up @@ -995,7 +996,7 @@ class d_a_kytag01 extends fopAc_ac_c {
}

public override delete(globals: dGlobals): void {
dKy__waveinfl_cut(globals.g_env_light, this.influence);
arrayRemove(globals.g_env_light.waveInfo, this.info);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/WindWaker/d_a_sea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { colorLerp, OpaqueBlack } from '../Color.js';
import { dKy_usonami_set } from './d_kankyo_wether.js';
import { Plane } from '../Geometry.js';
import { cLib_addCalcAngleS2, cM_atan2s, cM_rndF, cM__Short2Rad } from './SComponent.js';
import { dStage_stagInfo_GetSTType } from './d_stage.js';

const scratchVec2a = vec2.create();
const scratchVec2b = vec2.create();
Expand Down Expand Up @@ -124,7 +125,7 @@ class daSea_WaterHeightInfo_Mng {
if (x < 0 || x > 8 || z < 0 || z > 8)
return 10;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);

if (roomType === 7) {
return this.height[z*9 + x];
Expand Down
12 changes: 2 additions & 10 deletions src/WindWaker/d_kankyo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class dScnKy_env_light_c {
public baseLight = new LIGHT_INFLUENCE();
public plights: LIGHT_INFLUENCE[] = [];
public eflights: LIGHT_INFLUENCE[] = [];
public waveInfluences: WAVE_INFLUENCE[] = [];
public waveInfo: WAVE_INFO[] = [];
// The game records this in a separate struct with a bunch of extra data, but we don't need it lol.
public lightStatus = nArray(2, () => new Light());

Expand Down Expand Up @@ -174,7 +174,7 @@ export class LIGHT_INFLUENCE {
public priority: boolean = false;
}

export class WAVE_INFLUENCE {
export class WAVE_INFO {
public pos = vec3.create();
public outerRadius: number = 0.0;
public innerRadius: number = 0.0;
Expand Down Expand Up @@ -1281,14 +1281,6 @@ export function dKy_efplight_cut(envLight: dScnKy_env_light_c, plight: LIGHT_INF
envLight.playerEflightIdx = -1;
}

export function dKy__waveinfl_set(envLight: dScnKy_env_light_c, infl: WAVE_INFLUENCE): void {
envLight.waveInfluences.push(infl);
}

export function dKy__waveinfl_cut(envLight: dScnKy_env_light_c, infl: WAVE_INFLUENCE): void {
arrayRemove(envLight.waveInfluences, infl);
}

export function dKy_get_dayofweek(envLight: dScnKy_env_light_c): number {
return envLight.calendarDay % 7;
}
Expand Down
16 changes: 8 additions & 8 deletions src/WindWaker/d_kankyo_wether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { cLib_addCalc, cLib_addCalcAngleRad, cM__Short2Rad, cM_rndF, cM_rndFX }
import { PeekZManager, PeekZResult } from "./d_dlst_peekZ.js";
import { dKy_GxFog_sea_set, dKy_actor_addcol_amb_set, dKy_actor_addcol_dif_set, dKy_addcol_fog_set, dKy_bg1_addcol_amb_set, dKy_bg1_addcol_dif_set, dKy_bg_addcol_amb_set, dKy_bg_addcol_dif_set, dKy_checkEventNightStop, dKy_efplight_cut, dKy_efplight_set, dKy_get_dayofweek, dKy_get_seacolor, dKy_set_actcol_ratio, dKy_set_bgcol_ratio, dKy_set_fogcol_ratio, dKy_set_vrboxcol_ratio, dKy_vrbox_addcol_kasumi_set, dKy_vrbox_addcol_sky0_set, dScnKy_env_light_c } from "./d_kankyo.js";
import { ResType } from "./d_resorce.js";
import { dStage_FileList_dt_c } from "./d_stage.js";
import { dStage_FileList_dt_c, dStage_stagInfo_GetSTType } from "./d_stage.js";
import { cPhs__Status, fGlobals, fopKyM_Delete, fopKyM_create, fpcPf__Register, fpc__ProcessName, 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 { MtxTrans, calc_mtx, mDoMtx_XrotM, mDoMtx_ZrotM } from "./m_do_mtx.js";
Expand Down Expand Up @@ -301,7 +301,7 @@ export class dKankyo_sun_Packet {
let drawSun = this.sunAlpha > 0.0;
let drawMoon = this.moonAlpha > 0.0;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (envLight.baseLight.color.r === 0.0 && roomType !== 2) {
if (envLight.curTime > 285 || envLight.curTime < 105)
drawMoon = false;
Expand Down Expand Up @@ -1422,7 +1422,7 @@ export class dKankyo_housi_Packet {
}

public destroy(device: GfxDevice): void {
this.texData.destroy(device);
this.ddraw.destroy(device);
}
}

Expand Down Expand Up @@ -1466,7 +1466,7 @@ function dKyr_sun_move(globals: dGlobals): void {
const envLight = globals.g_env_light;
const pkt = envLight.sunPacket!;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (envLight.baseLight.color.r === 0.0 && roomType !== 2) {
dKyr_get_vectle_calc(globals.cameraPosition, envLight.baseLight.pos, scratchVec3);
} else {
Expand Down Expand Up @@ -1846,7 +1846,7 @@ function wether_move_rain(globals: dGlobals, deltaTimeInFrames: number): void {
let fadeMaxXZDist = 0;
let fadeMaxY = 0;

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (roomType === 2 && globals.stageName !== 'Ocrogh' && globals.stageName !== 'Omori') {
if (globals.stageName === 'Orichh')
fadeMaxXZDist = 2300.0;
Expand Down Expand Up @@ -2100,7 +2100,7 @@ function wether_move_wave(globals: dGlobals, deltaTimeInFrames: number): void {
let windY = windVec[1];
let windZ = windVec[2];

const roomType = (globals.dStage_dt.stag.roomTypeAndSchBit >>> 16) & 0x07;
const roomType = dStage_stagInfo_GetSTType(globals.dStage_dt.stag);
if (roomType === 2) {
// TODO(jstpierre): #TACT_WIND. Overwrite with tact wind. LinkRM / Orichh / Ojhous2 / Omasao / Onobuta
}
Expand Down Expand Up @@ -2168,8 +2168,8 @@ function wether_move_wave(globals: dGlobals, deltaTimeInFrames: number): void {
wave.strengthEnv = 1.0;

// Wave influence fade.
for (let i = 0; i < envLight.waveInfluences.length; i++) {
const infl = envLight.waveInfluences[i];
for (let i = 0; i < envLight.waveInfo.length; i++) {
const infl = envLight.waveInfo[i];
const dist = Math.hypot(infl.pos[0] - scratchVec3d[0], infl.pos[2] - scratchVec3d[2]);
wether_move_wave__FadeStrengthEnv(wave, dist, infl.innerRadius, infl.outerRadius);
}
Expand Down
4 changes: 4 additions & 0 deletions src/WindWaker/d_stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export class stage_stag_info_class {
}
}

export function dStage_stagInfo_GetSTType(stagInfo: stage_stag_info_class): number {
return (stagInfo.roomTypeAndSchBit >>> 16) & 0x07;
}

export class dStage_Multi_c {
public transX: number;
public transZ: number;
Expand Down
4 changes: 3 additions & 1 deletion src/WindWaker/zww_scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ const sceneDescs = [
new SceneDesc("Ebesso", "Island with House"),
new SceneDesc("KATA_HB", "Bridge Room"),
new SceneDesc("KATA_RM", "Large Empty Room"),
// new SceneDesc("kazan", "Fire Mountain"),
new SceneDesc("kazan", "Fire Mountain"),
new SceneDesc("Msmoke", "Smoke Test Room", [0, 1]),
new SceneDesc("Mukao", "Early Headstone Island"),
new SceneDesc("tincle", "Tingle's Room"),
Expand Down Expand Up @@ -1300,6 +1300,8 @@ const sceneDescs = [
new SceneDesc("DmSpot0", "DmSpot0"),
new SceneDesc("Amos_T", "Amos_T"),
new SceneDesc("A_umikz", "A_umikz"),
new SceneDesc("I_TestM", "I_TestM"),
new SceneDesc("I_TestR", "I_TestR"),
];

const id = "zww";
Expand Down

0 comments on commit 530991b

Please sign in to comment.