Skip to content

Commit 1a189d3

Browse files
authored
Work on d_a_obj_flag3 (#2485)
* Work on d_a_obj_flag3 * Fix JASBasicWaveBank::incWaveTable * Match JASBNKParser::Ver0::createBasicBank
1 parent 9b50fd5 commit 1a189d3

File tree

6 files changed

+627
-502
lines changed

6 files changed

+627
-502
lines changed

include/JSystem/JAudio2/JASBNKParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class JKRHeap;
1010

1111
namespace JASBNKParser {
1212
struct TFileHeader {
13-
/* 0x0 */ u8 _00[4];
13+
/* 0x0 */ int id;
1414
/* 0x4 */ u32 mSize;
1515
/* 0x8 */ u8 _08[4];
1616
/* 0xC */ u32 mVersion;

include/JSystem/JAudio2/JASWaveArcLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct JASWaveArc : JASDisposer {
6464
/* 0xC */ u32 _c;
6565
};
6666

67-
/* 0x04 */ JASHeap mHeap;
67+
/* 0x04 */ mutable JASHeap mHeap;
6868
/* 0x48 */ u32 _48;
6969
/* 0x4C */ volatile s32 mStatus;
7070
/* 0x50 */ int mEntryNum;

include/d/actor/d_a_obj_flag3.h

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
11
#ifndef D_A_OBJ_FLAG3_H
22
#define D_A_OBJ_FLAG3_H
33

4+
#include "d/d_cc_d.h"
45
#include "f_op/f_op_actor_mng.h"
56

7+
struct daObjFlag3_Attr_c {
8+
/* 0x00 */ f32 mGravity;
9+
/* 0x04 */ f32 mSpringCoeeficient;
10+
/* 0x08 */ f32 mDecayRate;
11+
/* 0x0C */ f32 mWindCoefficient;
12+
/* 0x10 */ f32 mTornado;
13+
};
14+
15+
class FlagCloth2_c : public J3DPacket {
16+
public:
17+
/* 80BEEDE4 */ void execute();
18+
/* 80BEEF74 */ inline void calcFlagNormal(cXyz*, int);
19+
/* 80BEF278 */ inline cXyz calcFlagFactor(cXyz*, cXyz*, cXyz*, int);
20+
/* 80BEF790 */ virtual ~FlagCloth2_c();
21+
/* 80BEFD08 */ void initFlagPos(cXyz*, fopAc_ac_c*);
22+
/* 80BF00A0 */ virtual void draw();
23+
/* 80BF0434 */ cXyz getTargetPos() { return mPositions[4]; }
24+
25+
inline void calcFlagNormalBack();
26+
cXyz* getPos() { return mPositions; }
27+
cXyz* getVec() { return mVecs; }
28+
cXyz* getNormal() { return mNormals; }
29+
cXyz* getNormalBack() { return mNormalBacks; }
30+
GXTexObj* getImageTexObj() { return &mTexObj; }
31+
void setSpringRate(f32 rate) { mSpringRate = rate; }
32+
void setWindRate(f32 rate) { mWindRate = rate; }
33+
void setDecayRate(f32 rate) { mDecayRate = rate; }
34+
void setGravity(f32 rate) { mGravity = rate; }
35+
void setTornado(f32 tornado) { mTornado = tornado; }
36+
37+
void initTexCoord() {
38+
for (int i = 0; i < 6; i++) {
39+
for (int j = 0; j < 6; j++) {
40+
mTexCoord[i* 6 + j][0] = j / 5.0f;
41+
mTexCoord[i* 6 + j][1] = (5 - i) / 5.0f;
42+
}
43+
}
44+
}
45+
46+
void calcFlagFactorSub(cXyz* param_1, cXyz* param_2, cXyz* param_3, f32 param_4) {
47+
cXyz acStack_2c = *param_2 - *param_1;
48+
param_4 = acStack_2c.abs() - param_4;
49+
cXyz cStack_38 = acStack_2c.normZC();
50+
param_4 *= mSpringRate;
51+
cStack_38 *= param_4;
52+
*param_3 += cStack_38;
53+
}
54+
55+
/* 0x010 */ GXTexObj mTexObj;
56+
/* 0x030 */ dKy_tevstr_c mTevStr;
57+
/* 0x3B8 */ dCcD_Stts mStts;
58+
/* 0x3F4 */ dCcD_Sph mSph;
59+
/* 0x52C */ u8 field_0x52c[0x540 - 0x52c];
60+
/* 0x540 */ cXyz mPositions[36];
61+
/* 0x6F0 */ u8 field_0x6f0[0x700 - 0x6f0];
62+
/* 0x700 */ cXyz mNormals[36];
63+
/* 0x8B0 */ u8 field_0x8b0[0x8c0 - 0x8b0];
64+
/* 0x8C0 */ cXyz mNormalBacks[36];
65+
/* 0xA70 */ u8 field_0xa70[0xa80 - 0xa70];
66+
/* 0xA70 */ f32 mTexCoord[36][2];
67+
/* 0xBA0 */ cXyz mVecs[36];
68+
/* 0xD50 */ cXyz* mpFlagPosition;
69+
/* 0xD54 */ Mtx mModelMtx;
70+
// /* 0xD8C */ void* mpTexCoord;
71+
/* 0xD84 */ f32 mSpringRate;
72+
/* 0xD88 */ f32 mWindRate;
73+
/* 0xD8C */ f32 mDecayRate;
74+
/* 0xD90 */ f32 mGravity;
75+
/* 0xD94 */ f32 mTornado;
76+
};
77+
678
/**
779
* @ingroup actors-objects
880
* @class daObjFlag3_c
@@ -13,30 +85,29 @@
1385
*/
1486
class daObjFlag3_c : public fopAc_ac_c {
1587
public:
16-
/* 80BEEA78 */ void createHeap();
17-
/* 80BEED3C */ void execute();
88+
/* 80BEEA78 */ int createHeap();
89+
/* 80BEED3C */ int execute();
1890
/* 80BEF700 */ ~daObjFlag3_c();
19-
/* 80BEF95C */ void create();
91+
/* 80BEF95C */ int create();
2092
/* 80BEFBC4 */ void create_init();
93+
inline int draw();
94+
inline void initBaseMtx();
2195

22-
static u8 const M_attr[20];
96+
static daObjFlag3_Attr_c const M_attr;
97+
const daObjFlag3_Attr_c& attr() const { return M_attr; }
2398

2499
private:
25-
/* 0x568 */ u8 field_0x568[0x1340 - 0x568];
100+
/* 0x0568 */ J3DModel* mModel;
101+
/* 0x056C */ request_of_phase_process_class mFlagPhase;
102+
/* 0x0574 */ request_of_phase_process_class mArcPhase;
103+
/* 0x057c */ int field_0x57c;
104+
/* 0x0580 */ FlagCloth2_c mFlagCloth;
105+
/* 0x1318 */ u8 field_0x1318[0x1320 - 0x1318];
106+
/* 0x1320 */ cXyz field_0x1320;
107+
/* 0x132C */ bool mFlagValid;
108+
/* 0x132D */ char mFlagName[19];
26109
};
27110

28111
STATIC_ASSERT(sizeof(daObjFlag3_c) == 0x1340);
29112

30-
class FlagCloth2_c {
31-
public:
32-
/* 80BEEDE4 */ void execute();
33-
/* 80BEEF74 */ void calcFlagNormal(cXyz*, int);
34-
/* 80BEF278 */ void calcFlagFactor(cXyz*, cXyz*, cXyz*, int);
35-
/* 80BEF790 */ ~FlagCloth2_c();
36-
/* 80BEFD08 */ void initFlagPos(cXyz*, fopAc_ac_c*);
37-
/* 80BF00A0 */ void draw();
38-
/* 80BF0434 */ void getTargetPos();
39-
};
40-
41-
42113
#endif /* D_A_OBJ_FLAG3_H */

src/JSystem/JAudio2/JASBNKParser.cpp

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "JSystem/JAudio2/JASCalc.h"
99
#include "JSystem/JAudio2/JASDrumSet.h"
1010
#include "JSystem/JAudio2/JASHeapCtrl.h"
11+
#include "JSystem/JAudio2/JASChannel.h"
1112
#include "JSystem/JKernel/JKRSolidHeap.h"
1213
#include "JSystem/JSupport/JSupport.h"
1314

@@ -27,10 +28,11 @@ JASBasicBank* JASBNKParser::createBasicBank(void const* stream, JKRHeap* heap) {
2728
}
2829

2930
u32 free_size = heap->getFreeSize();
31+
32+
TFileHeader* filep = (TFileHeader*)stream;
33+
JUT_ASSERT(59, filep->id == 'IBNK');
3034
JASBasicBank* bank = NULL;
31-
32-
TFileHeader* header = (TFileHeader*)stream;
33-
switch (header->mVersion) {
35+
switch (filep->mVersion) {
3436
case 0:
3537
bank = Ver0::createBasicBank(stream, heap);
3638
break;
@@ -165,14 +167,12 @@ JASBasicBank* JASBNKParser::Ver1::createBasicBank(void const* stream, JKRHeap* h
165167

166168
/* 80299A3C-80299E68 29437C 042C+00 1/1 0/0 0/0 .text
167169
* createBasicBank__Q212JASBNKParser4Ver0FPCvP7JKRHeap */
168-
// NONMATCHING
169170
JASBasicBank* JASBNKParser::Ver0::createBasicBank(void const* stream, JKRHeap* heap) {
170-
THeader const* header = (THeader*)stream;
171-
172171
if (heap == NULL) {
173172
heap = JASDram;
174173
}
175-
174+
175+
THeader const* header = (THeader*)stream;
176176
JASBasicBank* bank = new (heap, 0) JASBasicBank();
177177
if (bank == NULL) {
178178
return NULL;
@@ -181,94 +181,101 @@ JASBasicBank* JASBNKParser::Ver0::createBasicBank(void const* stream, JKRHeap* h
181181
bank->newInstTable(0x80, heap);
182182

183183
for (int i = 0; i < 0x80; i++) {
184-
TInst* tinst = header->mOffsets.mInstOffset[i].ptr(stream);
184+
TInst* tinst = header->mOffsets.mInstOffset[i].ptr(header);
185185
if (tinst != NULL) {
186-
JASBasicInst* inst = new (heap, 0) JASBasicInst();
187-
inst->setVolume(tinst->mVolume);
188-
inst->setPitch(tinst->mPitch);
186+
JASBasicInst* instp = new (heap, 0) JASBasicInst();
187+
JUT_ASSERT(368, instp != 0);
188+
instp->setVolume(tinst->mVolume);
189+
instp->setPitch(tinst->mPitch);
189190

190191
int osc_idx = 0;
191192
for (int j = 0; j < 2; j++) {
192-
TOsc* tosc = tinst->mOscOffset[j].ptr(stream);
193+
TOsc* tosc = tinst->mOscOffset[j].ptr(header);
193194
if (tosc != NULL) {
194-
JASOscillator::Data* osc_data = findOscPtr(bank, header, tosc);
195-
if (osc_data != NULL) {
196-
inst->setOsc(osc_idx, osc_data);
195+
JASOscillator::Data* osc = findOscPtr(bank, header, tosc);
196+
if (osc != NULL) {
197+
instp->setOsc(osc_idx, osc);
197198
} else {
198-
osc_data = new (heap, 0) JASOscillator::Data();
199-
osc_data->mTarget = tosc->mTarget;
200-
osc_data->_04 = tosc->field_0x4;
201-
u32 size;
199+
osc = new (heap, 0) JASOscillator::Data();
200+
JUT_ASSERT(386, osc != 0);
201+
osc->mTarget = tosc->mTarget;
202+
osc->_04 = tosc->field_0x4;
202203

203-
JASOscillator::Point* points = tosc->mPointOffset.ptr(stream);
204+
JASOscillator::Point* points = tosc->mPointOffset.ptr(header);
204205
if (points != NULL) {
205-
size = getOscTableEndPtr(points) - points;
206+
const JASOscillator::Point* endPtr = getOscTableEndPtr(points);
207+
int size = endPtr - points;
206208
JASOscillator::Point* table = new (heap, 0) JASOscillator::Point[size];
209+
JUT_ASSERT(396, table != 0);
207210
JASCalc::bcopy(points, table, size * sizeof(JASOscillator::Point));
208-
osc_data->mTable = table;
211+
osc->mTable = table;
209212
} else {
210-
osc_data->mTable = NULL;
213+
osc->mTable = NULL;
211214
}
212215

213-
points = tosc->field_0xc.ptr(stream);
216+
points = tosc->field_0xc.ptr(header);
214217
if (points != NULL) {
215-
size = getOscTableEndPtr(points) - points;
218+
const JASOscillator::Point* endPtr = getOscTableEndPtr(points);
219+
int size = endPtr - points;
216220
JASOscillator::Point* table = new (heap, 0) JASOscillator::Point[size];
221+
JUT_ASSERT(409, table != 0);
217222
JASCalc::bcopy(points, table, size * sizeof(JASOscillator::Point));
218-
osc_data->_0C = table;
223+
osc->_0C = table;
219224
} else {
220-
osc_data->_0C = NULL;
225+
osc->_0C = NULL;
221226
}
222227

223-
osc_data->mScale = tosc->mScale;
224-
osc_data->_14 = tosc->field_0x14;
225-
inst->setOsc(osc_idx, osc_data);
228+
osc->mScale = tosc->mScale;
229+
osc->_14 = tosc->field_0x14;
230+
instp->setOsc(osc_idx, osc);
226231
}
227232

228233
osc_idx++;
229234
}
230235
}
231236

232-
inst->setKeyRegionCount(tinst->mKeyRegionCount, heap);
237+
instp->setKeyRegionCount(tinst->mKeyRegionCount, heap);
233238
for (int j = 0; j < tinst->mKeyRegionCount; j++) {
234-
JASBasicInst::TKeymap* keymap = inst->getKeyRegion(j);
235-
TKeymap* tkeymap = tinst->mKeymapOffset[j].ptr(stream);
239+
JASBasicInst::TKeymap* keymap = instp->getKeyRegion(j);
240+
TKeymap* tkeymap = tinst->mKeymapOffset[j].ptr(header);
236241
keymap->setHighKey(tkeymap->mHighKey);
237-
TVmap* tvmap = tkeymap->mVmapOffset.ptr(stream);
242+
TVmap* tvmap = tkeymap->mVmapOffset.ptr(header);
238243
keymap->field_0x4 = JSULoHalf(tvmap->field_0x4);
239244
keymap->field_0x8 = tvmap->field_0x8;
240245
keymap->field_0xc = tvmap->field_0xc;
241246
}
242247

243-
bank->setInst(i, inst);
248+
bank->setInst(i, instp);
244249
}
245250
}
246251

247252
for (int i = 0; i < 12; i++) {
248-
TPerc* tperc = header->mOffsets.mPercOffset[i].ptr(stream);
253+
TPerc* tperc = header->mOffsets.mPercOffset[i].ptr(header);
249254
if (tperc != NULL) {
250-
JASDrumSet* drumset = new (heap, 0) JASDrumSet();
251-
drumset->newPercArray(0x80, heap);
255+
JASDrumSet* setp = new (heap, 0) JASDrumSet();
256+
JUT_ASSERT(509, setp != 0);
257+
setp->newPercArray(0x80, heap);
252258

253259
for (int j = 0; j < 0x80; j++) {
254-
TPmap* tpmap = tperc->mPmapOffset[j].ptr(stream);
260+
TPmap* tpmap = tperc->mPmapOffset[j].ptr(header);
255261
if (tpmap != NULL) {
256-
JASDrumSet::TPerc* perc = new (heap, 0) JASDrumSet::TPerc();
257-
perc->setVolume(tpmap->mVolume);
258-
perc->setPitch(tpmap->mPitch);
262+
JASDrumSet::TPerc* percp = new (heap, 0) JASDrumSet::TPerc();
263+
JUT_ASSERT(519, percp);
264+
percp->setVolume(tpmap->mVolume);
265+
percp->setPitch(tpmap->mPitch);
259266
if (tperc->mMagic == 'PER2') {
260-
perc->setPan(tperc->mPan[j] / 127.0f);
261-
perc->setRelease(tperc->mRelease[j]);
267+
percp->setPan(tperc->mPan[j] / 127.0f);
268+
percp->setRelease(tperc->mRelease[j]);
262269
}
263-
TVmap* vmap = tpmap->mVmapOffset.ptr(stream);
264-
perc->field_0xe = JSULoHalf(vmap->field_0x4);
265-
perc->field_0x10 = vmap->field_0x8;
266-
perc->field_0x14 = vmap->field_0xc;
267-
drumset->setPerc(j, perc);
270+
TVmap* vmap = tpmap->mVmapOffset.ptr(header);
271+
percp->field_0xe = JSULoHalf(vmap->field_0x4);
272+
percp->field_0x10 = vmap->field_0x8;
273+
percp->field_0x14 = vmap->field_0xc;
274+
setp->setPerc(j, percp);
268275
}
269276
}
270277

271-
bank->setInst(i + 0xe4, drumset);
278+
bank->setInst(i + 0xe4, setp);
272279
}
273280
}
274281

src/JSystem/JAudio2/JASBasicWaveBank.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ void JASBasicWaveBank::setWaveTableSize(u32 param_0, JKRHeap* param_1) {
5555

5656
/* 80298790-8029883C 2930D0 00AC+00 1/1 0/0 0/0 .text
5757
* incWaveTable__16JASBasicWaveBankFPCQ216JASBasicWaveBank10TWaveGroup */
58-
// NONMATCHING instruction order
59-
// This works if argument type is changed to non const
6058
void JASBasicWaveBank::incWaveTable(JASBasicWaveBank::TWaveGroup const* param_0) {
6159
JASMutexLock lock(&field_0x4);
6260
for (u32 i = 0; i < param_0->getWaveCount(); i++) {
6361
TWaveHandle* handle = mWaveTable + param_0->getWaveID(i);
6462
if (!handle->mHeap) {
65-
handle->mHeap = const_cast<JASHeap*>(&param_0->mHeap);
63+
handle->mHeap = &param_0->mHeap;
6664
handle->field_0x4.field_0x20 = &param_0->_48;
6765
handle->field_0x4.field_0x08 = param_0->mCtrlWaveArray[i].field_0x4;
6866
}

0 commit comments

Comments
 (0)