Skip to content

Commit

Permalink
Implement d_wood (bushes) for Wind Waker (#712)
Browse files Browse the repository at this point in the history
* Update zww_extractor.ts to create the output directory if it does not already exist

Without this change, the script will fail if data/ZeldaWindWaker does not already exist

* zww_extractor.ts now copies the res/* into the output directory

NoClip expects these files to be present in the output directory.

* Add d_wood.o symbols to zww_extractor.ts

This should be everything we need to render bushes

* Added d_wood.ts. Basic bush rendering.

This is the start of one of the remaining missing d_s_play components, Wood (which is the TWW misnomer for bushes).

Instead of following the old Grass.ts pattern, this is architected as similar to the d_wood.cpp as possible. This makes it simpler to compare to the decompiled results.

A few functions are implemented, and the rendering is based heavily off of d_tree so it may not be completely correct. But basic model rendering and drop shadows are present.

* Add cLib_chaseS() function to SComponent

This is used by d_wood's animation functions

* Add mDoMtx_copy() to m_do_mtx

Since the src and dst parameters are switched from usual, I think it's worth adding this so that it's easy to copy paste from decomp

* Update d_wood.ts to about 70%

Idle animation fully implemented

* d_wood alpha improvements

* Enable alpha testing on bushes (greatly improves aliasing on leaf edges)
* Render to the XLU BG display list. This fixes an ordering issue. We must render after most bg objects because of the alpha testing.
* Disable alpha test when fading out after a bush has been cut

* Add frustum culling to d_wood

* d_wood: const enum fixup

* Revert "zww_extractor.ts now copies the res/* into the output directory"

This reverts commit a28b3f5.

* d_wood: Cleanup sway attribute data and naming

Also name the last of the unknown variables

* Remove cLib_chaseS implementation, use cLib_chaseF instead

The implementation is identical in JS (in C++ it's the short version vs float)

* d_wood: Add public/private to all member functions

* d_wood: don't cache globals, pass it as a param everywhere it's needed

* d_wood: Fix shadow scale. Use math helpers for simpler matrix calculations.

* d_wood: Correctly use the g_dTree_shadowTexCoord

Removes old hardcoded texcoord hack

* d_wood: Remove unnecessary transpose

* d_wood: Replace Room_c linked list with a 2D array

This differes from the cpp, but suits JS better

* d_wood: Remove byte offset comments from classes

* d_wood: Remove some unused animations

* d_wood: Whoops. Fix some build errors related to extra params
  • Loading branch information
themikelester authored Oct 24, 2024
1 parent bf27038 commit d1c23ff
Show file tree
Hide file tree
Showing 7 changed files with 867 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { GfxrAttachmentSlot, GfxrRenderTargetDescription } from '../gfx/render/G
import { GfxRenderInstList, GfxRenderInstManager } from '../gfx/render/GfxRenderInstManager.js';
import { GXRenderHelperGfx, fillSceneParamsDataOnTemplate } from '../gx/gx_render.js';
import { FlowerPacket, GrassPacket, TreePacket } from './Grass.js';
import { Packet_c as WoodPacket } from './d_wood.js';
import { LegacyActor__RegisterFallbackConstructor } from './LegacyActor.js';
import { dDlst_2DStatic_c, d_a__RegisterConstructors } from './d_a.js';
import { d_a_sea } from './d_a_sea.js';
Expand Down Expand Up @@ -739,6 +740,7 @@ class d_s_play extends fopScn {
public flowerPacket: FlowerPacket;
public treePacket: TreePacket;
public grassPacket: GrassPacket;
public woodPacket: WoodPacket;

public vrboxLoaded: boolean = false;

Expand All @@ -748,6 +750,7 @@ class d_s_play extends fopScn {
this.treePacket = new TreePacket(globals);
this.flowerPacket = new FlowerPacket(globals);
this.grassPacket = new GrassPacket(globals);
this.woodPacket = new WoodPacket(globals);

globals.scnPlay = this;

Expand All @@ -757,22 +760,25 @@ class d_s_play extends fopScn {
public override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: Viewer.ViewerRenderInput): void {
super.draw(globals, renderInstManager, viewerInput);

// Grass/Flowers/Trees
// Magma/Grass/Trees/Bushes/Flowers
const frameCount = viewerInput.time / 1000.0 * 30;

this.flowerPacket.calc(frameCount);
this.treePacket.calc(frameCount);
this.grassPacket.calc(frameCount);
this.woodPacket.calc(globals, frameCount);

this.flowerPacket.update(globals);
this.treePacket.update(globals);
this.grassPacket.update(globals);
this.woodPacket.update(globals);

fopDw_Draw(globals.frameworkGlobals, globals, renderInstManager, viewerInput);

this.flowerPacket.draw(globals, renderInstManager, viewerInput);
this.treePacket.draw(globals, renderInstManager, viewerInput);
this.grassPacket.draw(globals, renderInstManager, viewerInput);
this.woodPacket.draw(globals, renderInstManager, viewerInput);
}

public override delete(globals: dGlobals): void {
Expand All @@ -782,6 +788,7 @@ class d_s_play extends fopScn {
this.flowerPacket.destroy(device);
this.treePacket.destroy(device);
this.grassPacket.destroy(device);
this.woodPacket.destroy(device);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/ZeldaWindWaker/SComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export function cLib_chasePosXZ(dst: vec3, target: ReadonlyVec3, maxVel: number)
}
}

// Move `value` closer to `target` by the amount specified in `step`.
// If `value` would cross `target`, it is set to `target`. Returns 1 if value has reached the target, 0 otherwise.
export function cLib_chaseF(dst: number, target: number, step: number): number {
if (step !== 0) {
if (dst > target) {
Expand Down
11 changes: 11 additions & 0 deletions src/ZeldaWindWaker/d_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,16 @@ class d_a_oship extends fopAc_ac_c implements ModeFuncExec<d_a_oship_mode> {
}
}

class d_a_obj_wood extends fopAc_ac_c {
public static PROCESS_NAME = fpc__ProcessName.d_a_obj_wood;

public override subload(globals: dGlobals): cPhs__Status {
globals.scnPlay.woodPacket.put_unit(globals, this.pos, this.roomNo);
// globals.scnPlay.treePacket.newData(this.pos, 0, this.roomNo);
return cPhs__Status.Next;
}
}

const enum d_a_obj_flame_mode { wait, wait2, l_before, l_u, u, u_l, l_after }
const enum d_a_obj_em_state { Off, TurnOn, On, TurnOff }
class d_a_obj_flame extends fopAc_ac_c {
Expand Down Expand Up @@ -4711,6 +4721,7 @@ export function d_a__RegisterConstructors(globals: fGlobals): void {
}

R(d_a_grass);
R(d_a_obj_wood);
R(d_a_ep);
R(d_a_bg);
R(d_a_vrbox);
Expand Down
Loading

0 comments on commit d1c23ff

Please sign in to comment.