Skip to content

Commit ea8bd69

Browse files
Finish xFFX as Equivalent (#669)
1 parent b850b35 commit ea8bd69

File tree

3 files changed

+82
-46
lines changed

3 files changed

+82
-46
lines changed

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def MatchingFor(*versions):
423423
Object(NonMatching, "SB/Core/x/xEntMotion.cpp"),
424424
Object(Matching, "SB/Core/x/xEnv.cpp"),
425425
Object(Matching, "SB/Core/x/xEvent.cpp"),
426-
Object(NonMatching, "SB/Core/x/xFFX.cpp"),
426+
Object(Equivalent, "SB/Core/x/xFFX.cpp"),
427427
Object(Matching, "SB/Core/x/xFog.cpp"),
428428
Object(NonMatching, "SB/Core/x/xFont.cpp"),
429429
Object(NonMatching, "SB/Core/x/xFX.cpp"),

src/SB/Core/x/xFFX.cpp

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
#include "xFFX.h"
22
#include "xEnt.h"
33
#include "xMemMgr.h"
4+
#include "xMathInlines.h"
45

56
#include <types.h>
67

7-
U32 psize;
8-
xFFX* pool;
9-
xFFX* alist;
10-
U32 shake_psize;
11-
void* shake_pool;
12-
xFFXShakeState* shake_alist;
13-
U32 rot_match_psize;
14-
xFFXRotMatchState* rot_match_pool;
15-
xFFXRotMatchState* rot_match_alist;
16-
17-
// Structure same as the bottom function, get that one, you get this one.
18-
//void xFFXPoolInit(U32 num_ffx);
8+
static U32 psize;
9+
static xFFX* pool;
10+
static xFFX* alist;
11+
static U32 shake_psize;
12+
static xFFXShakeState* shake_pool;
13+
static xFFXShakeState* shake_alist;
14+
static U32 rot_match_psize;
15+
static xFFXRotMatchState* rot_match_pool;
16+
static xFFXRotMatchState* rot_match_alist;
17+
18+
void xFFXPoolInit(U32 num_ffx)
19+
{
20+
psize = num_ffx;
21+
pool = (xFFX*)xMemAlloc(gActiveHeap, num_ffx * sizeof(xFFX), 0);
22+
pool[0].next = NULL;
23+
for (U32 i = 1; i < psize; i++)
24+
{
25+
pool[i].next = &pool[i - 1];
26+
}
27+
alist = &pool[psize - 1];
28+
}
1929

2030
xFFX* xFFXAlloc()
2131
{
@@ -73,32 +83,30 @@ S16 xFFXAddEffect(xEnt* ent, void (*dof)(xEnt*, xScene*, F32, void*), void* fd)
7383
return effectID;
7484
}
7585

76-
// WIP.
7786
U32 xFFXRemoveEffectByFData(xEnt* ent, void* fdata)
7887
{
79-
xFFX* ffx;
80-
xFFX** found;
88+
xFFX** ffxh = &ent->ffx;
8189

82-
found = (xFFX**)&ent->ffx;
83-
while (true)
90+
while (*ffxh != NULL)
8491
{
85-
ffx = *found;
86-
if (ffx == NULL)
92+
xFFX* next = *ffxh;
93+
if (fdata == next->fdata)
8794
{
88-
return 0;
95+
next = next->next;
96+
ent->num_ffx--;
97+
xFFXFree(*ffxh);
98+
*ffxh = next;
99+
100+
return 1;
89101
}
90-
if (fdata == ffx->fdata)
91-
break;
92-
found = &ffx->next;
102+
103+
ffxh = &(*ffxh)->next;
93104
}
94-
ffx = ffx->next;
95-
ent->num_ffx--;
96-
xFFXFree(*found);
97-
*found = ffx;
98-
return 1;
105+
106+
return 0;
99107
}
100108

101-
void xFFXApplyOne(xFFX* ffx, xEnt* ent, xScene* sc, F32 dt)
109+
static void xFFXApplyOne(xFFX* ffx, xEnt* ent, xScene* sc, F32 dt)
102110
{
103111
if (ffx->next != NULL)
104112
{
@@ -118,17 +126,49 @@ void xFFXApply(xEnt* ent, xScene* sc, F32 dt)
118126
}
119127
}
120128

121-
void xFFXShakeUpdateEnt(xEnt* ent, xScene* scene, float value, void*)
129+
// regswap
130+
void xFFXShakeUpdateEnt(xEnt* ent, xScene* sc, F32 dt, void* fdata)
122131
{
123-
}
132+
xFFXShakeState* ss = (xFFXShakeState*)fdata;
133+
F32 tnext = ss->tmr + dt;
134+
F32 mag = xexp(ss->alpha * tnext);
124135

125-
void xFFXPoolInit(U32 num)
126-
{
136+
mag *= isin(ss->freq * tnext);
137+
138+
if (ss->tmr == 0.0f)
139+
{
140+
ss->lval = 0.0f;
141+
}
142+
else
143+
{
144+
if (ss->tmr >= ss->dur)
145+
{
146+
if (ss->lval * mag < 0.0f)
147+
{
148+
xFFXRemoveEffectByFData(ent, fdata);
149+
xFFXShakeFree(ss);
150+
return;
151+
}
152+
}
153+
}
154+
155+
xVec3 dv;
156+
xVec3SMul(&dv, (xVec3*)fdata, mag - ss->lval);
157+
xVec3AddTo((xVec3*)(&ent->frame->mat.pos), &dv);
158+
ss->lval = mag;
159+
ss->tmr = tnext;
127160
}
128161

129-
// The structure of this is identical to the pool init below. Figure out that one, you get this one as well.
130162
void xFFXShakePoolInit(U32 num)
131163
{
164+
shake_psize = num;
165+
shake_pool = (xFFXShakeState*)xMemAlloc(gActiveHeap, num * sizeof(xFFXShakeState), 0);
166+
shake_pool->next = NULL;
167+
for (S32 i = 1; i < shake_psize; i++)
168+
{
169+
shake_pool[i].next = &shake_pool[i - 1];
170+
}
171+
shake_alist = &shake_pool[shake_psize - 1];
132172
}
133173

134174
xFFXShakeState* xFFXShakeAlloc()
@@ -149,22 +189,19 @@ void xFFXShakeFree(xFFXShakeState* s)
149189
shake_alist = s;
150190
}
151191

152-
// Some instructions are in the wrong order.
153192
void xFFXRotMatchPoolInit(U32 num)
154193
{
155194
rot_match_psize = num;
156-
rot_match_pool = (xFFXRotMatchState*)xMemAllocSize(num * sizeof(xFFXRotMatchState));
157-
U32 i = 1;
195+
196+
rot_match_pool = (xFFXRotMatchState*)xMemAlloc(gActiveHeap, num * sizeof(xFFXRotMatchState), 0);
197+
158198
rot_match_pool->next = NULL;
159-
S32 ind = sizeof(xFFXRotMatchState);
160-
while (i < rot_match_psize)
199+
for (U32 i = 1; i < rot_match_psize; ++i)
161200
{
162-
S32 nextAddr = ind - 1;
163-
i++;
164-
*(xFFXRotMatchState**)((S32)&rot_match_pool->next + ind) = rot_match_pool + nextAddr;
165-
ind += sizeof(xFFXRotMatchState);
201+
rot_match_pool[i].next = &rot_match_pool[i - 1];
166202
}
167-
rot_match_alist = rot_match_pool + (rot_match_psize - 1);
203+
204+
rot_match_alist = &rot_match_pool[rot_match_psize - 1];
168205
}
169206

170207
xFFXRotMatchState* xFFXRotMatchAlloc()

src/SB/Core/x/xFFX.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void xFFXTurnOff(xFFX* f);
4848
S16 xFFXAddEffect(xEnt* ent, xFFX* f);
4949
S16 xFFXAddEffect(xEnt* ent, void (*dof)(xEnt*, xScene*, F32, void*), void* fd);
5050
U32 xFFXRemoveEffectByFData(xEnt* ent, void* fdata);
51-
void xFFXApplyOne(xFFX* ffx, xEnt* ent, xScene* sc, F32 dt);
5251
void xFFXApply(xEnt* ent, xScene* sc, F32 dt);
5352
void xFFXShakeUpdateEnt(xEnt* ent, xScene* sc, F32 dt, void* fdata);
5453
void xFFXShakePoolInit(U32 num);

0 commit comments

Comments
 (0)