Skip to content

Commit

Permalink
Super Mario Galaxy: Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Dec 27, 2024
1 parent d63648a commit f125293
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Common/JSYSTEM/JStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ 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.
public adaptor_getVariableValue_GXColor(dst: GfxColor, startKeyIdx: number) {
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) {
Expand Down
21 changes: 14 additions & 7 deletions src/SuperMarioGalaxy/ActorUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/SuperMarioGalaxy/Actors/MiscActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/SuperMarioGalaxy/Collision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions src/SuperMarioGalaxy/Fur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 4 additions & 7 deletions src/SuperMarioGalaxy/LiveActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -756,10 +757,6 @@ export class LiveActor<TNerve extends number = number> 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;
}
Expand Down Expand Up @@ -892,7 +889,7 @@ export class LiveActor<TNerve extends number = number> 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);
Expand Down
5 changes: 3 additions & 2 deletions src/SuperMarioGalaxy/Shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit f125293

Please sign in to comment.