Skip to content

Commit bc16f9e

Browse files
committed
Added all of the bfbb core files into the movie repo
1 parent 6f37d8c commit bc16f9e

File tree

264 files changed

+41437
-3249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+41437
-3249
lines changed

src/SB/Core/gc/iAnim.cpp

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
#include "iAnim.h"
2+
3+
#include "iAnimSKB.h"
4+
#include "xMath.h"
5+
6+
#include <rwcore.h>
7+
#include <rtslerp.h>
8+
9+
static U8 scratchBuffer[9120];
10+
11+
U8* giAnimScratch = scratchBuffer;
12+
13+
void iAnimInit()
14+
{
15+
return;
16+
}
17+
18+
void iAnimEval(void* RawData, F32 time, U32 flags, xVec3* tran, xQuat* quat)
19+
{
20+
iAnimEvalSKB((iAnimSKBHeader*)RawData, time, flags, tran, quat);
21+
}
22+
23+
F32 iAnimDuration(void* RawData)
24+
{
25+
return iAnimDurationSKB((iAnimSKBHeader*)RawData);
26+
}
27+
28+
U32 iAnimBoneCount(void* RawData)
29+
{
30+
if (*(U32*)RawData == '1BKS')
31+
{
32+
return ((iAnimSKBHeader*)RawData)->BoneCount;
33+
}
34+
35+
return 0;
36+
}
37+
38+
// non-matching: incorrect instruction order and regalloc
39+
void iAnimBlend(F32 BlendFactor, F32 BlendRecip, U16* BlendTimeOffset,
40+
F32* BoneTable, U32 BoneCount, xVec3* Tran1, xQuat* Quat1, xVec3* Tran2,
41+
xQuat* Quat2, xVec3* TranDest, xQuat* QuatDest)
42+
{
43+
U32 i;
44+
U32 invert = 0;
45+
RtQuat* q2;
46+
RtQuat ident = { 0.0f, 0.0f, 0.0f, 1.0f };
47+
xVec3* t2;
48+
49+
if (!Quat2)
50+
{
51+
q2 = &ident;
52+
invert = 1;
53+
t2 = (xVec3*)&ident.imag;
54+
}
55+
else
56+
{
57+
q2 = (RtQuat*)Quat2;
58+
t2 = Tran2;
59+
}
60+
61+
if (BlendFactor < 0.0f)
62+
{
63+
BlendFactor = -BlendFactor;
64+
invert ^= 1;
65+
}
66+
67+
if (!BoneTable && !BlendTimeOffset)
68+
{
69+
F32 lerp = BlendFactor * BlendRecip;
70+
71+
if (lerp < 0.0f)
72+
{
73+
lerp = 0.0f;
74+
}
75+
else if (lerp > 1.0f)
76+
{
77+
lerp = 1.0f;
78+
}
79+
80+
if (invert)
81+
{
82+
lerp = 1.0f - lerp;
83+
}
84+
85+
if (Quat1)
86+
{
87+
// non-matching: 0.0f constant is loaded outside of loop
88+
89+
for (i = 0; i < BoneCount; i++)
90+
{
91+
RtQuatSlerpCache qcache;
92+
93+
RtQuatSetupSlerpCache((RtQuat*)Quat1, q2, &qcache);
94+
RtQuatSlerp((RtQuat*)QuatDest, (RtQuat*)Quat1, q2, lerp, &qcache);
95+
96+
Quat1++;
97+
98+
if (Quat2)
99+
{
100+
q2++;
101+
}
102+
103+
QuatDest++;
104+
}
105+
}
106+
107+
if (Tran1)
108+
{
109+
if (Quat2)
110+
{
111+
for (i = 0; i < BoneCount; i++, TranDest++, t2++, Tran1++)
112+
{
113+
TranDest->x = lerp * (t2->x - Tran1->x) + Tran1->x;
114+
TranDest->y = lerp * (t2->y - Tran1->y) + Tran1->y;
115+
TranDest->z = lerp * (t2->z - Tran1->z) + Tran1->z;
116+
}
117+
}
118+
else
119+
{
120+
for (i = 0; i < BoneCount; i++, TranDest++, Tran1++)
121+
{
122+
TranDest->x = lerp * (t2->x - Tran1->x) + Tran1->x;
123+
TranDest->y = lerp * (t2->y - Tran1->y) + Tran1->y;
124+
TranDest->z = lerp * (t2->z - Tran1->z) + Tran1->z;
125+
}
126+
}
127+
}
128+
}
129+
else
130+
{
131+
F32 baselerp;
132+
133+
if (!BlendTimeOffset)
134+
{
135+
baselerp = BlendFactor * BlendRecip;
136+
137+
if (baselerp < 0.0f)
138+
{
139+
baselerp = 0.0f;
140+
}
141+
else if (baselerp > 1.0f)
142+
{
143+
baselerp = 1.0f;
144+
}
145+
146+
if (invert)
147+
{
148+
baselerp = 1.0f - baselerp;
149+
}
150+
}
151+
152+
for (i = 0; i < BoneCount; i++)
153+
{
154+
F32 lerp;
155+
156+
if (BlendTimeOffset)
157+
{
158+
baselerp = -(1 / 1024.0f * BlendTimeOffset[i * 2] - BlendFactor);
159+
160+
if (BlendTimeOffset[i * 2 + 1] != 0)
161+
{
162+
baselerp *= 1 / 1024.0f * BlendTimeOffset[i * 2 + 1];
163+
164+
if (baselerp < 0.0f)
165+
{
166+
baselerp = 0.0f;
167+
}
168+
else if (baselerp > 1.0f)
169+
{
170+
baselerp = 1.0f;
171+
}
172+
}
173+
else
174+
{
175+
if (baselerp < 0.0f)
176+
{
177+
baselerp = 0.0f;
178+
}
179+
else
180+
{
181+
baselerp = 1.0f;
182+
}
183+
}
184+
185+
if (invert)
186+
{
187+
baselerp = 1.0f - baselerp;
188+
}
189+
}
190+
191+
if (BoneTable)
192+
{
193+
lerp = baselerp * BoneTable[i];
194+
}
195+
else
196+
{
197+
lerp = baselerp;
198+
}
199+
200+
if (Quat1)
201+
{
202+
RtQuatSlerpCache qcache;
203+
204+
RtQuatSetupSlerpCache((RtQuat*)Quat1, q2, &qcache);
205+
RtQuatSlerp((RtQuat*)QuatDest, (RtQuat*)Quat1, q2, lerp, &qcache);
206+
207+
Quat1++;
208+
209+
if (Quat2)
210+
{
211+
q2++;
212+
}
213+
214+
QuatDest++;
215+
}
216+
217+
if (Tran1)
218+
{
219+
TranDest->x = lerp * (t2->x - Tran1->x) + Tran1->x;
220+
TranDest->y = lerp * (t2->y - Tran1->y) + Tran1->y;
221+
TranDest->z = lerp * (t2->z - Tran1->z) + Tran1->z;
222+
223+
Tran1++;
224+
225+
if (Quat2)
226+
{
227+
t2++;
228+
}
229+
230+
TranDest++;
231+
}
232+
}
233+
}
234+
}

src/SB/Core/gc/iAnim.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef IANIM_H
2+
#define IANIM_H
3+
4+
#include "xMath3.h"
5+
6+
extern U8* giAnimScratch;
7+
8+
void iAnimInit();
9+
F32 iAnimDuration(void* RawData);
10+
U32 iAnimBoneCount(void* RawData);
11+
void iAnimBlend(F32 BlendFactor, F32 BlendRecip, U16* BlendTimeOffset, F32* BoneTable,
12+
U32 BoneCount, xVec3* Tran1, xQuat* Quat1, xVec3* Tran2, xQuat* Quat2,
13+
xVec3* TranDest, xQuat* QuatDest);
14+
void iAnimEval(void* RawData, float time, unsigned int flags, class xVec3* tran, class xQuat* quat);
15+
16+
#endif

src/SB/Core/gc/iAnimSKB.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#include "iAnimSKB.h"
2+
3+
#include <rwcore.h>
4+
#include <rtslerp.h>
5+
6+
#include <limits.h>
7+
8+
void iAnimEvalSKB(iAnimSKBHeader* data, F32 time, U32 flags, xVec3* tran, xQuat* quat)
9+
{
10+
U32 i, tidx, bcount, tcount;
11+
iAnimSKBKey* keys;
12+
F32* times;
13+
U16* offsets;
14+
S32 asdf; // unused
15+
F32 scalex, scaley, scalez;
16+
17+
tcount = data->TimeCount;
18+
bcount = data->BoneCount;
19+
20+
keys = (iAnimSKBKey*)(data + 1);
21+
times = (F32*)(keys + data->KeyCount);
22+
offsets = (U16*)(times + tcount);
23+
24+
if (time < 0.0f)
25+
{
26+
time = 0.0f;
27+
}
28+
29+
if (time > times[tcount - 1])
30+
{
31+
time = times[tcount - 1];
32+
}
33+
34+
tidx = (tcount - 1) % 4;
35+
36+
while (times[tidx] < time)
37+
{
38+
tidx += 4;
39+
}
40+
41+
while (tidx && time <= times[tidx])
42+
{
43+
tidx--;
44+
}
45+
46+
offsets += tidx * bcount;
47+
48+
if (flags & 0x1)
49+
{
50+
bcount = 1;
51+
}
52+
53+
if (flags & 0x2)
54+
{
55+
bcount--;
56+
offsets++;
57+
}
58+
59+
if (tcount == 1)
60+
{
61+
// non-matching: float constants are loaded outside of loop
62+
63+
scalex = data->Scale[0];
64+
scaley = data->Scale[1];
65+
scalez = data->Scale[2];
66+
67+
for (i = 0; i < bcount; i++, quat++, tran++)
68+
{
69+
iAnimSKBKey* k = &keys[i];
70+
71+
quat->v.x = k->Quat[0] * (1.0f / SHRT_MAX);
72+
quat->v.y = k->Quat[1] * (1.0f / SHRT_MAX);
73+
quat->v.z = k->Quat[2] * (1.0f / SHRT_MAX);
74+
quat->s = k->Quat[3] * (1.0f / SHRT_MAX);
75+
76+
tran->x = k->Tran[0] * scalex;
77+
tran->y = k->Tran[1] * scaley;
78+
tran->z = k->Tran[2] * scalez;
79+
}
80+
}
81+
else
82+
{
83+
// non-matching: float constants are loaded outside of loop
84+
85+
scalex = data->Scale[0];
86+
scaley = data->Scale[1];
87+
scalez = data->Scale[2];
88+
89+
for (i = 0; i < bcount; i++, quat++, tran++)
90+
{
91+
// no idea if this part even functionally matches.
92+
// come back to this when not lazy
93+
94+
RtQuatSlerpCache qcache;
95+
RtQuat q1, q2;
96+
RwReal time1, time2, lerp;
97+
iAnimSKBKey* k = &keys[*offsets];
98+
U32 costheta, theta; // unused
99+
100+
offsets++;
101+
102+
time1 = time - times[k->TimeIndex];
103+
time2 = times[k[1].TimeIndex] - times[k[0].TimeIndex];
104+
lerp = time1 / time2;
105+
106+
q1.imag.x = k[0].Quat[0] * (1.0f / SHRT_MAX);
107+
q1.imag.y = k[0].Quat[1] * (1.0f / SHRT_MAX);
108+
q1.imag.z = k[0].Quat[2] * (1.0f / SHRT_MAX);
109+
q1.real = k[0].Quat[3] * (1.0f / SHRT_MAX);
110+
111+
q2.imag.x = k[1].Quat[0] * (1.0f / SHRT_MAX);
112+
q2.imag.y = k[1].Quat[1] * (1.0f / SHRT_MAX);
113+
q2.imag.z = k[1].Quat[2] * (1.0f / SHRT_MAX);
114+
q2.real = k[1].Quat[3] * (1.0f / SHRT_MAX);
115+
116+
RtQuatSetupSlerpCache(&q1, &q2, &qcache);
117+
RtQuatSlerp((RtQuat*)quat, &q1, &q2, lerp, &qcache);
118+
119+
tran->x =
120+
lerp * (scalex * k[1].Tran[0] - scalex * k[0].Tran[0]) + scalex * k[0].Tran[0];
121+
tran->y =
122+
lerp * (scaley * k[1].Tran[1] - scaley * k[0].Tran[1]) + scaley * k[1].Tran[1];
123+
tran->z =
124+
lerp * (scalez * k[1].Tran[2] - scalez * k[0].Tran[2]) + scalez * k[1].Tran[2];
125+
}
126+
}
127+
}
128+
129+
F32 iAnimDurationSKB(iAnimSKBHeader* data)
130+
{
131+
return ((F32*)((iAnimSKBKey*)(data + 1) + data->KeyCount))[data->TimeCount - 1];
132+
}

0 commit comments

Comments
 (0)