From f1252938ba24763dc5087f728a112074769c6ca1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 27 Dec 2024 12:29:24 -0800 Subject: [PATCH] Super Mario Galaxy: Minor cleanup --- src/Common/JSYSTEM/JStudio.ts | 4 ++-- src/SuperMarioGalaxy/ActorUtil.ts | 21 ++++++++++++++------- src/SuperMarioGalaxy/Actors/MiscActor.ts | 3 ++- src/SuperMarioGalaxy/Collision.ts | 7 ++++--- src/SuperMarioGalaxy/Fur.ts | 10 ++++++---- src/SuperMarioGalaxy/LiveActor.ts | 11 ++++------- src/SuperMarioGalaxy/Shadow.ts | 5 +++-- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Common/JSYSTEM/JStudio.ts b/src/Common/JSYSTEM/JStudio.ts index b495cfffa..b6ec3c08a 100644 --- a/src/Common/JSYSTEM/JStudio.ts +++ b/src/Common/JSYSTEM/JStudio.ts @@ -254,7 +254,7 @@ abstract class TAdaptor { this.variableValues[startKeyIdx + 0].setValue_immediate(data.r); this.variableValues[startKeyIdx + 1].setValue_immediate(data.g); this.variableValues[startKeyIdx + 2].setValue_immediate(data.b); - this.variableValues[startKeyIdx + 4].setValue_immediate(data.a); + this.variableValues[startKeyIdx + 3].setValue_immediate(data.a); } // Get the current value of 4 consecutive VariableValues, as a GXColor. E.g. Fog color. @@ -262,7 +262,7 @@ abstract class TAdaptor { dst.r = this.variableValues[startKeyIdx + 0].getValue(); dst.g = this.variableValues[startKeyIdx + 1].getValue(); dst.b = this.variableValues[startKeyIdx + 2].getValue(); - dst.a = this.variableValues[startKeyIdx + 2].getValue(); + dst.a = this.variableValues[startKeyIdx + 3].getValue(); } public adaptor_updateVariableValue(obj: STBObject, frameCount: number) { diff --git a/src/SuperMarioGalaxy/ActorUtil.ts b/src/SuperMarioGalaxy/ActorUtil.ts index 831d9cda9..2a6c94daf 100644 --- a/src/SuperMarioGalaxy/ActorUtil.ts +++ b/src/SuperMarioGalaxy/ActorUtil.ts @@ -352,7 +352,8 @@ export function startBva(actor: LiveActor, name: string): void { } export function startBckIfExist(actor: LiveActor, name: string): boolean { - const bck = actor.resourceHolder.getRes(actor.resourceHolder.motionTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const bck = resourceHolder.getRes(resourceHolder.motionTable, name); if (bck !== null) { actor.modelManager!.startBck(name); if (actor.effectKeeper !== null) @@ -362,35 +363,40 @@ export function startBckIfExist(actor: LiveActor, name: string): boolean { } export function startBtkIfExist(actor: LiveActor, name: string): boolean { - const btk = actor.resourceHolder.getRes(actor.resourceHolder.btkTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const btk = resourceHolder.getRes(resourceHolder.btkTable, name); if (btk !== null) actor.modelManager!.startBtk(name); return btk !== null; } export function startBrkIfExist(actor: LiveActor, name: string): boolean { - const brk = actor.resourceHolder.getRes(actor.resourceHolder.brkTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const brk = resourceHolder.getRes(resourceHolder.brkTable, name); if (brk !== null) actor.modelManager!.startBrk(name); return brk !== null; } export function startBpkIfExist(actor: LiveActor, name: string): boolean { - const bpk = actor.resourceHolder.getRes(actor.resourceHolder.bpkTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const bpk = resourceHolder.getRes(resourceHolder.bpkTable, name); if (bpk !== null) actor.modelManager!.startBpk(name); return bpk !== null; } export function startBtpIfExist(actor: LiveActor, name: string): boolean { - const btp = actor.resourceHolder.getRes(actor.resourceHolder.btpTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const btp = resourceHolder.getRes(resourceHolder.btpTable, name); if (btp !== null) actor.modelManager!.startBtp(name); return btp !== null; } export function startBvaIfExist(actor: LiveActor, name: string): boolean { - const bva = actor.resourceHolder.getRes(actor.resourceHolder.bvaTable, name); + const resourceHolder = actor.modelManager!.resourceHolder; + const bva = resourceHolder.getRes(resourceHolder.bvaTable, name); if (bva !== null) actor.modelManager!.startBva(name); return bva !== null; @@ -1316,7 +1322,8 @@ export function makeMtxFrontNoSupportPos(dst: mat4, front: ReadonlyVec3, pos: Re } export function isExistCollisionResource(actor: LiveActor, name: string): boolean { - return actor.resourceHolder.arc.findFileData(`${name.toLowerCase()}.kcl`) !== null; + const resourceHolder = actor.modelManager!.resourceHolder; + return resourceHolder.arc.findFileData(`${name.toLowerCase()}.kcl`) !== null; } export function useStageSwitchSleep(sceneObjHolder: SceneObjHolder, actor: LiveActor, infoIter: JMapInfoIter | null): void { diff --git a/src/SuperMarioGalaxy/Actors/MiscActor.ts b/src/SuperMarioGalaxy/Actors/MiscActor.ts index 232d7f8b9..2e71e32fb 100644 --- a/src/SuperMarioGalaxy/Actors/MiscActor.ts +++ b/src/SuperMarioGalaxy/Actors/MiscActor.ts @@ -4125,7 +4125,8 @@ export class WarpPod extends LiveActor { this.warpPathPoints.push(v); } - this.pathDrawer = new WarpPodPathDrawer(sceneObjHolder, this.resourceHolder.arc, this.warpPathPoints, this.color); + const resourceHolder = this.modelManager!.resourceHolder; + this.pathDrawer = new WarpPodPathDrawer(sceneObjHolder, resourceHolder.arc, this.warpPathPoints, this.color); } private lookForPair(sceneObjHolder: SceneObjHolder): WarpPod | null { diff --git a/src/SuperMarioGalaxy/Collision.ts b/src/SuperMarioGalaxy/Collision.ts index b3fb24519..4d8aed72f 100644 --- a/src/SuperMarioGalaxy/Collision.ts +++ b/src/SuperMarioGalaxy/Collision.ts @@ -890,7 +890,7 @@ export function invalidateCollisionParts(sceneObjHolder: SceneObjHolder, parts: } const scratchMatrix = mat4.create(); -export function createCollisionPartsFromLiveActor(sceneObjHolder: SceneObjHolder, actor: LiveActor, name: string, hitSensor: HitSensor, hostMtx: mat4 | null, scaleType: CollisionScaleType, resourceHolder: ResourceHolder = actor.resourceHolder!): CollisionParts { +export function createCollisionPartsFromLiveActor(sceneObjHolder: SceneObjHolder, actor: LiveActor, name: string, hitSensor: HitSensor, hostMtx: mat4 | null, scaleType: CollisionScaleType, resourceHolder: ResourceHolder = actor.modelManager!.resourceHolder): CollisionParts { let initialHostMtx: mat4; if (hostMtx !== null) { initialHostMtx = hostMtx; @@ -908,12 +908,13 @@ export function createCollisionPartsFromLiveActor(sceneObjHolder: SceneObjHolder } function tryCreateCollisionParts(sceneObjHolder: SceneObjHolder, actor: LiveActor, hitSensor: HitSensor, category: CollisionKeeperCategory, filenameBase: string): CollisionParts | null { - const res = actor.resourceHolder.arc.findFileData(`${filenameBase}.kcl`); + const resourceHolder = actor.modelManager!.resourceHolder; + const res = resourceHolder.arc.findFileData(`${filenameBase}.kcl`); if (res === null) return null; makeMtxTRSFromActor(scratchMatrix, actor); - const parts = createCollisionParts(sceneObjHolder, actor.zoneAndLayer, actor.resourceHolder, filenameBase, hitSensor, scratchMatrix, CollisionScaleType.AutoScale, category); + const parts = createCollisionParts(sceneObjHolder, actor.zoneAndLayer, resourceHolder, filenameBase, hitSensor, scratchMatrix, CollisionScaleType.AutoScale, category); if (parts !== null) validateCollisionParts(sceneObjHolder, parts); diff --git a/src/SuperMarioGalaxy/Fur.ts b/src/SuperMarioGalaxy/Fur.ts index cde060008..5e9b5450b 100644 --- a/src/SuperMarioGalaxy/Fur.ts +++ b/src/SuperMarioGalaxy/Fur.ts @@ -665,23 +665,25 @@ export function initMultiFur(sceneObjHolder: SceneObjHolder, actor: LiveActor, l if (bodyMapSamplerIndex === -1) bodyMapSamplerIndex = 0; + const resourceHolder = actor.modelManager!.resourceHolder; + const lengthMapName = `${materialName}Length.bti`; - const lengthMapData = actor.resourceHolder.arc.findFileData(lengthMapName); + const lengthMapData = resourceHolder.arc.findFileData(lengthMapName); const lengthMap = lengthMapData !== null ? BTI.parse(lengthMapData, lengthMapName).texture : null; const indirectMapName = `${materialName}Indirect.bti`; - const indirectMapData = actor.resourceHolder.arc.findFileData(indirectMapName); + const indirectMapData = resourceHolder.arc.findFileData(indirectMapName); const indirectMap = indirectMapData !== null ? BTI.parse(indirectMapData, indirectMapName).texture : null; const densityMapName = `${materialName}Density.bti`; - const densityMapData = actor.resourceHolder.arc.findFileData(densityMapName); + const densityMapData = resourceHolder.arc.findFileData(densityMapName); const densityMap = densityMapData !== null ? BTI.parse(densityMapData, densityMapName).texture : null; const furParam = Object.assign({}, defaultFurParam) as FurParam; const dynFurParam = new DynamicFurParam(); dynFurParam.lightType = lightType; - const furTxt = actor.resourceHolder.arc.findFileData(`${materialName}.fur.txt`); + const furTxt = resourceHolder.arc.findFileData(`${materialName}.fur.txt`); if (furTxt !== null) initFurParamFromDVD(furParam, dynFurParam, furTxt); diff --git a/src/SuperMarioGalaxy/LiveActor.ts b/src/SuperMarioGalaxy/LiveActor.ts index 66fafc6c6..1872bec82 100644 --- a/src/SuperMarioGalaxy/LiveActor.ts +++ b/src/SuperMarioGalaxy/LiveActor.ts @@ -78,11 +78,12 @@ class ActorAnimKeeper { } public static tryCreate(actor: LiveActor): ActorAnimKeeper | null { - let bcsv = actor.resourceHolder.arc.findFileData('ActorAnimCtrl.bcsv'); + const resourceHolder = actor.modelManager!.resourceHolder; + let bcsv = resourceHolder.arc.findFileData('ActorAnimCtrl.bcsv'); // Super Mario Galaxy 2 puts these assets in a subfolder. if (bcsv === null) - bcsv = actor.resourceHolder.arc.findFileData('ActorInfo/ActorAnimCtrl.bcsv'); + bcsv = resourceHolder.arc.findFileData('ActorInfo/ActorAnimCtrl.bcsv'); if (bcsv === null) return null; @@ -756,10 +757,6 @@ export class LiveActor extends NameObj { } // TODO(jstpierre): Remove these accessors. - public get resourceHolder(): ResourceHolder { - return this.modelManager!.resourceHolder; - } - public get modelInstance(): J3DModelInstance | null { return this.modelManager !== null ? this.modelManager.modelInstance : null; } @@ -892,7 +889,7 @@ export class LiveActor extends NameObj { public initActorCollisionParts(sceneObjHolder: SceneObjHolder, name: string, hitSensor: HitSensor, resourceHolder: ResourceHolder | null, hostMtx: mat4 | null, scaleType: CollisionScaleType): void { if (resourceHolder === null) - resourceHolder = this.resourceHolder; + resourceHolder = this.modelManager!.resourceHolder; this.collisionParts = createCollisionPartsFromLiveActor(sceneObjHolder, this, name, hitSensor, hostMtx, scaleType, resourceHolder); invalidateCollisionPartsForActor(sceneObjHolder, this); diff --git a/src/SuperMarioGalaxy/Shadow.ts b/src/SuperMarioGalaxy/Shadow.ts index fec4007e4..c7940ff79 100644 --- a/src/SuperMarioGalaxy/Shadow.ts +++ b/src/SuperMarioGalaxy/Shadow.ts @@ -1301,10 +1301,11 @@ function addShadowFromCSV(sceneObjHolder: SceneObjHolder, actor: LiveActor, info export function initShadowFromCSV(sceneObjHolder: SceneObjHolder, actor: LiveActor, filename: string = 'Shadow'): void { let shadowFile: ArrayBufferSlice | null; + const resourceHolder = actor.modelManager!.resourceHolder; if (sceneObjHolder.sceneDesc.gameBit === GameBits.SMG1) - shadowFile = actor.resourceHolder.arc.findFileData(`${filename}.bcsv`); + shadowFile = resourceHolder.arc.findFileData(`${filename}.bcsv`); else if (sceneObjHolder.sceneDesc.gameBit === GameBits.SMG2) - shadowFile = actor.resourceHolder.arc.findFileData(`ActorInfo/${filename}.bcsv`); + shadowFile = resourceHolder.arc.findFileData(`ActorInfo/${filename}.bcsv`); else throw "whoops";