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
2030xFFX* 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.
7786U32 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.
130162void 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
134174xFFXShakeState* xFFXShakeAlloc ()
@@ -149,22 +189,19 @@ void xFFXShakeFree(xFFXShakeState* s)
149189 shake_alist = s;
150190}
151191
152- // Some instructions are in the wrong order.
153192void 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
170207xFFXRotMatchState* xFFXRotMatchAlloc ()
0 commit comments