Skip to content

Commit 53eab5d

Browse files
committed
Camp dragon
1 parent 321b4c5 commit 53eab5d

7 files changed

Lines changed: 312 additions & 48 deletions

File tree

AzelLib/3dEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void rotateCurrentMatrixZYX_s16(const sVec3_S16_12_4& rotationVec);
117117
void multiplyCurrentMatrix(sMatrix4x3* arg4);
118118
void multiplyCurrentMatrixSaveStack(sMatrix4x3* arg4);
119119

120+
void scaleMatrixRow0(fixedPoint r4, sMatrix4x3* pMatrix);
121+
void scaleMatrixRow1(fixedPoint r4, sMatrix4x3* pMatrix);
120122
void scaleMatrixRow2(fixedPoint r4, sMatrix4x3* pMatrix);
121123

122124
void scaleCurrentMatrixRow0(s32 r4);

AzelLib/common.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
#include <array>
4+
#include <bitset>
5+
#include <bit>
46

57
enum eItems : s16;
68

@@ -417,11 +419,8 @@ extern std::vector<sBitfieldMapEntry> m_bitFieldMap;
417419

418420
struct s_mainGameState
419421
{
420-
private:
421422
u8 bitField[630];
422423

423-
public:
424-
425424
s8 getItemCount(eItems itemIndex)
426425
{
427426
if (itemIndex < 0x4D)
@@ -527,6 +526,13 @@ struct s_mainGameState
527526
return false;
528527
}
529528

529+
bool getBit(u32 byteIndex, u8 mask)
530+
{
531+
assert(std::bitset<8>(mask).count() == 1);
532+
int bit = std::countl_zero(mask);
533+
return getBit(byteIndex * 8 + bit);
534+
}
535+
530536
bool getBit566(u32 bitIndex)
531537
{
532538
if (bitIndex < 1000)
@@ -977,3 +983,5 @@ void getVdp1LocalCoordinates(std::array<s16, 2>& r4);
977983

978984
typedef std::array < sVec2_FP, 4> sScreenQuad;
979985
typedef std::array < sVec3_FP, 4> sScreenQuad3;
986+
987+
u32 readPackedBits(u8* bitField, u32 firstBitOffset, u32 numBits);

AzelLib/mainMenuDebugTasks.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,28 @@ void rotl(u32& value)
161161
u32 readPackedBits(u8* bitField, u32 firstBitOffset, u32 numBits)
162162
{
163163
u32 r0_startOfByteInBits = (firstBitOffset & ~0x1F);
164-
u32 r5_lastBitToChange = numBits + firstBitOffset - r0_startOfByteInBits ;
165-
u8* r4_targetByte = bitField + (r0_startOfByteInBits / 8);
164+
u32 lastBitToChange = numBits + firstBitOffset - r0_startOfByteInBits;
165+
u8* targetByte = bitField + (r0_startOfByteInBits / 8);
166166
u32 r6_bitMask = longBitMask[numBits];
167167
u32 r1 = 0x20;
168168

169-
if (r5_lastBitToChange > 32)
169+
if (lastBitToChange > 32)
170170
{
171-
assert(0);
171+
// we are overflowing into the next bit
172+
Unimplemented();
172173
return 0;
173174
}
174175
else
175176
{
176-
u32 value1 = (r4_targetByte[0] << 24) | (r4_targetByte[1] << 16) | (r4_targetByte[2] << 8) | (r4_targetByte[3]);
177+
u32 value1 = (targetByte[0] << 24) | (targetByte[1] << 16) | (targetByte[2] << 8) | (targetByte[3]);
177178

178-
if (r5_lastBitToChange == 32)
179+
if (lastBitToChange == 32)
179180
{
180181
return value1 & r6_bitMask;
181182
}
182183
else
183184
{
184-
r1 -= r5_lastBitToChange;
185+
r1 -= lastBitToChange;
185186
value1 >>= r1;
186187

187188
return value1 & r6_bitMask;

AzelLib/town/camp/campDragon.cpp

Lines changed: 244 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,271 @@
11
#include "PDS.h"
22
#include "campDragon.h"
33
#include "town/town.h"
4+
#include "town/townDragon.h"
5+
#include "kernel/fileBundle.h"
6+
#include "kernel/graphicalObject.h"
47

5-
struct sCampDragon : public s_workAreaTemplateWithArg<sCampDragon, sSaturnPtr>, sTownObject
8+
void initDragonForTown(sTownDragon* pThis); // TODO: Cleanup
9+
void updateTownDragon(sTownDragon* pThis); // TODO: cleanup
10+
void EdgeUpdateSub0(struct sMainLogic_74* r14_pose); // TODO cleanup
11+
12+
struct sCampDragon_F8 {
13+
sVec3_FP m4;
14+
sMainLogic_74 m10;
15+
// size 0x8C
16+
};
17+
18+
struct sCampDragon : public sTownDragon
619
{
7-
s16 m16;
8-
sSaturnPtr m48;
9-
sVec3_FP m4C;
10-
sVec3_FP m58;
11-
sVec3_FP m64;
20+
//0-E8: sTownDragon
21+
sVec3_FP mE8;
22+
s32 mF4 = 0; // count of F8
23+
std::array<sCampDragon_F8, 9> mF8;
1224
//size: 0x624
1325
};
1426

15-
void sCampDragon_Init(sCampDragon* pThis, sSaturnPtr arg) {
27+
s32 sCampDragon_InitSub1(sTownDragon* pThis) {
28+
29+
fixedPoint X = readSaturnFP(*(npcData0.m120_stack.end() - 2));
30+
fixedPoint Y = readSaturnFP(*(npcData0.m120_stack.end() - 1));
31+
32+
return atan2_FP(X - (pThis->m58).m0_X, Y - (pThis->m58).m8_Z);
33+
}
34+
35+
void increaseGameResource(int param_1, int param_2) {
36+
switch (param_1)
37+
{
38+
case 0xB:
39+
mainGameState.gameStats.m7C_overallRating = mainGameState.gameStats.m7C_overallRating + param_2;
40+
if ((int)mainGameState.gameStats.m7C_overallRating < 0) {
41+
mainGameState.gameStats.m7C_overallRating = 0;
42+
}
43+
if (0x7c < (int)mainGameState.gameStats.m7C_overallRating) {
44+
mainGameState.gameStats.m7C_overallRating = 0x7c;
45+
}
46+
break;
47+
default:
48+
assert(0);
49+
break;
50+
}
51+
}
52+
53+
s32 sCampDragon_InitSub0() {
54+
s32 uVar1;
55+
int iVar2;
56+
57+
uVar1 = mainGameState.gameStats.m7C_overallRating;
58+
iVar2 = readPackedBits(mainGameState.bitField, 0x1347, 0x20);
59+
iVar2 = uVar1 - iVar2;
60+
if (iVar2 < -0xf) {
61+
return 2;
62+
}
63+
if (iVar2 < -5) {
64+
return 3;
65+
}
66+
if (0xf < iVar2) {
67+
return 6;
68+
}
69+
if (5 < iVar2) {
70+
return 5;
71+
}
72+
return 4;
73+
}
74+
75+
void sCampDragon_InitSub2(sCampDragon* pThis) {
76+
u32 temp = updateAndInterpolateAnimation(&gDragonState->m28_dragon3dModel);
77+
if (pThis->m24) {
78+
assert(0);
79+
}
80+
}
81+
82+
void sCampDragon_Init(sTownDragon* pThisBase, sSaturnPtr arg) {
83+
sCampDragon* pThis = (sCampDragon*)pThisBase;
1684
pThis->m48 = arg;
1785
pThis->m4C = pThis->m58 = readSaturnVec3(arg + 0x8);
1886
pThis->m64 = readSaturnVec3(arg + 0x14);
87+
npcData0.m70_npcPointerArray[readSaturnU16(arg + 0x20)].workArea = pThis;
1988
pThis->m16 = 0x3C;
89+
increaseGameResource(0xb, 0);
90+
pThis->mF = sCampDragon_InitSub0();
91+
pThis->m40 = 0x8000000;
92+
pThis->m3C = 0x8000000;
93+
pThis->mD8 = 0x1000;
94+
s32 temp = 0x8000000;
95+
if (mainGameState.getBit(0x263, 0x20) == 0) {
96+
temp = 0x4000000;
97+
}
98+
else {
99+
temp += performDivision(0x19, mainGameState.gameStats.m7C_overallRating) * 0x2000000;
100+
}
101+
pThis->m64.m4_Y = sCampDragon_InitSub1(pThis) + temp;
102+
pThis->m70.m30_pPosition = &pThis->m58;
103+
pThis->m70.m34_pRotation = &pThis->m64;
104+
pThis->m70.m38_pOwner = pThis;
105+
pThis->m70.m3C_scriptEA = pThis->m20;
106+
pThis->m70.m40 = 0;
107+
mainLogicInitSub0(&pThis->m70, 3);
20108

21-
Unimplemented();
109+
static const sVec3_FP param1 = {
110+
-0x1800,
111+
-0x1800,
112+
-0x1800,
113+
};
114+
115+
static const sVec3_FP param2 = {
116+
0x1800,
117+
0x1000,
118+
0x1800,
119+
};
120+
121+
mainLogicInitSub1(&pThis->m70, param1, param2);
122+
123+
for (int i = 0; i < 9; i++) {
124+
auto* psVar3 = &pThis->mF8[i];
125+
(psVar3->m10).m30_pPosition = &psVar3->m4;
126+
(psVar3->m10).m34_pRotation = &pThis->mE8;
127+
(psVar3->m10).m38_pOwner = pThis;
128+
(psVar3->m10).m3C_scriptEA = sSaturnPtr::getNull();
129+
(psVar3->m10).m40 = nullptr;
130+
}
131+
initDragonForTown(pThis);
132+
pThis->m14 = 1;
133+
134+
playAnimation(&gDragonState->m28_dragon3dModel, pThis->m1C->m0_fileBundle->getAnimation(readSaturnU16(pThis->m20 + 2)), 0);
135+
sCampDragon_InitSub2(pThis);
22136
}
23137

24-
void sCampDragon_Update(sCampDragon* pThis) {
138+
void sCampDragon_UpdateSub0(sTownDragon* pThis) {
25139
Unimplemented();
26140
}
27141

28-
void sCampDragon_Draw(sCampDragon* pThis) {
142+
void sCampDragon_UpdateMode4(sTownDragon* pThis) {
143+
switch (pThis->m11) {
144+
case 0:
145+
pThis->m12 = 1;
146+
pThis->m11 = 1;
147+
break;
148+
case 1:
149+
Unimplemented();
150+
break;
151+
default:
152+
assert(0);
153+
break;
154+
}
155+
}
156+
157+
void sCampDragon_Update(sTownDragon* pThisBase) {
158+
sCampDragon* pThis = (sCampDragon*)pThisBase;
159+
160+
pThis->mD = 1;
161+
updateTownDragon(pThis);
162+
163+
if ((gDragonState->mC_dragonType < 0) || (7 < gDragonState->mC_dragonType)) {
164+
return;
165+
}
166+
167+
pThis->m58 = pThis->m4C;
168+
pThis->m58[1] += pThis->mD8;
169+
EdgeUpdateSub0(&pThis->m70);
170+
171+
for (int i = 0; i < pThis->mF4; i++) {
172+
assert(0);
173+
}
174+
175+
sCampDragon_UpdateSub0(pThis);
176+
177+
if (pThis->mE == 0) {
178+
switch (pThis->mF + pThis->m10) {
179+
case 4:
180+
sCampDragon_UpdateMode4(pThis);
181+
break;
182+
default:
183+
assert(0);
184+
break;
185+
}
186+
}
187+
else if ((pThis->mE & 1) == 0) {
188+
assert(0);
189+
}
190+
else {
191+
assert(0);
192+
}
193+
194+
if (pThis->m12 == 0) {
195+
Unimplemented();
196+
}
197+
29198
Unimplemented();
30199
}
31200

32-
void sCampDragon_Delete(sCampDragon* pThis) {
201+
void updateAnimationMatricesSub1WithScale(s3DModelAnimData* r4, s_3dModel* r5)
202+
{
203+
u32 r9 = r5->m12_numBones;
204+
if (r9)
205+
{
206+
std::vector<sMatrix4x3>::iterator r14 = r4->m4_boneMatrices->begin();
207+
if (r5->m48_poseDataInterpolation.size())
208+
{
209+
std::vector<sPoseDataInterpolation>::iterator r13 = r5->m48_poseDataInterpolation.begin();
210+
211+
do
212+
{
213+
initMatrixToIdentity(&(*r14));
214+
translateMatrix(&r13->m0_translation, &(*r14));
215+
rotateMatrixZYX(&r13->mC_rotation, &(*r14));
216+
//scaleMatrixRow0(r13->m18_scale[0], &(*r14));
217+
//scaleMatrixRow1(r13->m18_scale[1], &(*r14));
218+
//scaleMatrixRow2(r13->m18_scale[2], &(*r14));
219+
r13++;
220+
r14++;
221+
} while (--r9);
222+
}
223+
else
224+
{
225+
std::vector<sPoseData>::iterator r13 = r5->m2C_poseData.begin();
226+
227+
do
228+
{
229+
initMatrixToIdentity(&(*r14));
230+
translateMatrix(&r13->m0_translation, &(*r14));
231+
rotateMatrixZYX(&r13->mC_rotation, &(*r14));
232+
//scaleMatrixRow0(r13->m18_scale[0], &(*r14));
233+
//scaleMatrixRow1(r13->m18_scale[1], &(*r14));
234+
//scaleMatrixRow2(r13->m18_scale[2], &(*r14));
235+
r13++;
236+
r14++;
237+
} while (--r9);
238+
}
239+
}
240+
}
241+
242+
void updateAnimationMatricesSub2(s3DModelAnimData* r4); // todo: cleanup
243+
244+
void sCampDragon_Draw(sTownDragon* pThisBase) {
245+
sCampDragon* pThis = (sCampDragon*)pThisBase;
246+
247+
if ((-1 < gDragonState->mC_dragonType) && (gDragonState->mC_dragonType < 8))
248+
{
249+
updateAnimationMatricesSub1WithScale(&gDragonState->m78_animData, &gDragonState->m28_dragon3dModel);
250+
updateAnimationMatricesSub2(&gDragonState->m78_animData);
251+
252+
Unimplemented();
253+
submitModelAndShadowModelToRendering(&gDragonState->m28_dragon3dModel, gDragonState->m14_modelIndex, gDragonState->m18_shadowModelIndex, &pThis->m58, &pThis->m64, 0);
254+
if (pThis->mD)
255+
{
256+
Unimplemented();
257+
}
258+
if (enableDebugTask) {
259+
assert(0);
260+
}
261+
}
262+
}
263+
264+
void sCampDragon_Delete(sTownDragon* pThis) {
33265
Unimplemented();
34266
}
35267

36-
struct sTownObject* createCampDragon(p_workArea parent, sSaturnPtr arg) {
268+
sTownObject* createCampDragon(p_workArea parent, sSaturnPtr arg) {
37269
static const sCampDragon::TypedTaskDefinition definition = {
38270
&sCampDragon_Init,
39271
&sCampDragon_Update,

AzelLib/town/town.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ struct sNpcData
183183
const std::vector <sSaturnPtr>* m64_scriptList;
184184
s32 m68_numEnvLCSTargets;
185185
const std::vector<sVec3_FP>* m6C_LCSTargets;
186-
std::array<NPCProxy, 32> m70_npcPointerArray;
186+
std::array<NPCProxy, 16> m70_npcPointerArray;
187187
s32 mF0;
188188
s32 mF4;
189189
s32 mF8;
@@ -197,10 +197,12 @@ struct sNpcData
197197
s_cinematicBarTask* m164_cinematicBars;
198198
s32 m168;
199199
union {
200-
s_vdp2StringTask* m16C_displayStringTask;
200+
s_vdp2StringTask* m16C_displayStringTask; //TODO: those are likely the same and should be merged
201201
s_receivedItemTask* m16C_receivedItemTask;
202202
};
203203
struct s_multiChoiceTask* m170_multiChoiceTask;
204+
205+
//size 0x174
204206
};
205207

206208
extern sNpcData npcData0;

0 commit comments

Comments
 (0)