Decompile the Bolt and MBarrier overlays - #146
Conversation
The two renderers share a footprint and nothing else, so the unions had no discriminator in the data. Names the flag bits, and updates barrier, brizad and lv5deth to match. Field readings cross-checked against Akari's q-gears_reverse notes.
Both overlays match in full.
Xeeynamo
left a comment
There was a problem hiding this comment.
Good work so far. I left a non exhausting review for things I'd like to see before geting this in. A few patterns I found while reviewing:
- Avoid verbose comments in code. Especially LLM ones that just describes how the code reads. Those are generally more harmful than helpful.
- A few
field = field + 1that could be simplified. - Try removing casts when possible. If a cast can't be removed, evaluate if the function/variable type could be changed.
- I see a mix of local var declarations and assignments. For the sake of consistency with the rest of the code base, keep them separate.
| // Quad pass over ThunderRenderDesc1, 8 frames, mirrored per instance by the | ||
| // random bits in unk1A. Not renamed: what it draws is not established. |
| nextFrame = (u16)effect->AnimationFrame + 1; | ||
| effect->AnimationFrame = nextFrame; | ||
| if (nextFrame == 8) { |
There was a problem hiding this comment.
| nextFrame = (u16)effect->AnimationFrame + 1; | |
| effect->AnimationFrame = nextFrame; | |
| if (nextFrame == 8) { | |
| effect->AnimationFrame++; | |
| if (effect->AnimationFrame == 8) { |
This can be simplified, and you couild even get rid of s16 nextFrame;. The same comment applies in other spots you're submitting.
| extern void* ThunderBufferPtr; | ||
| extern ThunderData D_80162978[]; | ||
| extern ThunderPrimPage ThunderPrimBuffer[]; | ||
| extern u_long ThunderTexture[]; // 8bpp TIM + CLUT, uploaded on setup | ||
| extern SpriteRenderDesc ThunderRenderDesc0; | ||
| extern SpriteRenderDesc ThunderRenderDesc1; | ||
| extern MATRIX ThunderModelMatrix; | ||
| extern ModelRenderDesc ThunderModelDesc; |
There was a problem hiding this comment.
These should follow one of the two conventions for global or private vars: https://github.com/Xeeynamo/ff7-decomp/blob/main/STYLE.md
what I advise is using g_ThunderRenderDesc1 for now. Once the data comes fully imported, we could start renaminng these as render_desc1 (no need for thunder_ as prefix, as those vars would be private to the thunder overlay anyway)
| // Draws the embedded model through the model path, growing it by 0x200 a | ||
| // frame from 1.0x to 2.875x across the 16 frames and dimming it over the | ||
| // last 8. | ||
| // | ||
| // Flags 0x08 leave MODEL_DEPTH_CUE clear, so color is a grey level: it | ||
| // steps from 0x80 down to 0x10, dimming the model from grey 128 to 16. | ||
| // | ||
| // The matrix holds a fixed orientation scaled by Scale -- m[0][0] and | ||
| // m[2][1] take Scale, m[1][2] takes -Scale. Confirmed live: the other six | ||
| // entries hold zero on all 16 frames. |
There was a problem hiding this comment.
I find these kind of comments hard to follow. The actual function is easier to read 😅 . Sometimes less is better.
| MATRIX matrix; | ||
| ThunderData* effect = &D_80162978[D_8015169C]; | ||
| s16 frame = effect->AnimationFrame; | ||
| u16* scale; // read through a pointer; a plain field read does not match |
There was a problem hiding this comment.
| u16* scale; // read through a pointer; a plain field read does not match | |
| s16* scale; |
type change, also no need to justify decisions with comment in the source base.
| ThunderModelMatrix.m[1][2] = -(s16)*scale; | ||
| ThunderModelMatrix.t[0] = (s32)effect->Pos.vx; | ||
| ThunderModelMatrix.t[1] = (s32)effect->Pos.vy; | ||
| ThunderModelMatrix.t[2] = (s32)effect->Pos.vz; |
There was a problem hiding this comment.
| ThunderModelMatrix.m[1][2] = -(s16)*scale; | |
| ThunderModelMatrix.t[0] = (s32)effect->Pos.vx; | |
| ThunderModelMatrix.t[1] = (s32)effect->Pos.vy; | |
| ThunderModelMatrix.t[2] = (s32)effect->Pos.vz; | |
| ThunderModelMatrix.m[1][2] = -*scale; | |
| ThunderModelMatrix.t[0] = effect->Pos.vx; | |
| ThunderModelMatrix.t[1] = effect->Pos.vy; | |
| ThunderModelMatrix.t[2] = effect->Pos.vz; |
| SetTransMatrix(&matrix); | ||
| ThunderBufferPtr = func_800D29D4(&ThunderModelDesc, g_cDb->unk70, 0xC, ThunderBufferPtr); | ||
| if (D_80062D98 == 0) { | ||
| effect->AnimationFrame = (u16)effect->AnimationFrame + 1; |
There was a problem hiding this comment.
| effect->AnimationFrame = (u16)effect->AnimationFrame + 1; | |
| effect->AnimationFrame++; |
| ThunderData* next; | ||
| ThunderData* effect = &D_80162978[D_8015169C]; | ||
| s16 nextFrame; | ||
|
|
There was a problem hiding this comment.
| ThunderData* next; | |
| ThunderData* effect = &D_80162978[D_8015169C]; | |
| s16 nextFrame; | |
| ThunderData* next; | |
| ThunderData* effect; | |
| s16 nextFrame; | |
| effect = &D_80162978[D_8015169C] |
split declarations and assignments. This allows us to move things around more easily without affecting the match.
| // PSX fixed point: 1.0 == 1 << FIXED_SHIFT. Angles: FIXED_ONE == a full turn. | ||
| #define FIXED_SHIFT 12 | ||
| #define FIXED_ONE (1 << FIXED_SHIFT) |
There was a problem hiding this comment.
12 is a well known constant when dealing with rotations and GTE APIs on PS1. I don't think the macro belongs to the magic headers alone. And I don't think hiding these behind a macro is helpful at all. Reason is for these kind of math operations the operand must be explicit instead of the developer having to jump around the codebase to find what's the value of a specific macro.
More info here: https://psx.arthus.net/sdk/Psy-Q/DOCS/LIBREF46.PDF if you search for 4096.
If you want to go ahead and making a macro out of this, I may suggest as follow: https://github.com/Xeeynamo/sotn-decomp/blob/master/include/common.h#L125
| // back the next write position. Every magic overlay declares it this way. | ||
| extern void* ThunderBufferPtr; | ||
| extern ThunderData D_80162978[]; | ||
| extern ThunderPrimPage ThunderPrimBuffer[]; |
There was a problem hiding this comment.
I noticed you have char BarrierPrimBuffer on the other overlay. This should probably have some consistency between magic overlays.
Simpler increments, fewer casts, split declarations, trimmed comments, and STYLE.md naming.
Thanks for the review @Xeeynamo. I've pushed some changes to address your concerns, let me know if I missed anything. |
Two more magic overlays: BOLT (thunder) and MBARRIER (mabaria).
Also some renaming and restructuring as the magic overlays get better
understood. barrier, brizad and lv5deth are updated to follow.
Some of the variables were figured out from q-gears, others by poking
around in an emulator.