Skip to content

Commit f0c2f7e

Browse files
authored
zNPCSndTable work (#671)
* zNPCSndTable work * cleanup
1 parent a2b1b2d commit f0c2f7e

File tree

4 files changed

+241
-34
lines changed

4 files changed

+241
-34
lines changed

src/SB/Core/gc/iSnd.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ struct iSndInfo
2121
S32 lastStreamBuffer;
2222
};
2323

24+
struct iSndFileInfo
25+
{
26+
U32 ID; // offset 0x0
27+
U32 assetID; // offset 0x4
28+
U16 sample_rate; // offset 0x8
29+
U8 is_streamed; // offset 0xA
30+
union
31+
{
32+
struct
33+
{
34+
U32 address; // offset 0x0
35+
U32 size; // offset 0x4
36+
} nonstream; // offset 0xC
37+
struct
38+
{
39+
S32 file_index; // offset 0x0
40+
U32 lsn; // offset 0x4
41+
U32 data_size; // offset 0x8
42+
U16 stream_interleave_size; // offset 0xC
43+
U16 stream_interleave_count; // offset 0xE
44+
} stream; // offset 0xC
45+
};
46+
};
47+
2448
// Size: 0x20
2549
// This was not in dwarf data
2650
struct vinfo
@@ -62,6 +86,7 @@ U32 SampleToNybbleAddress(U32 sample);
6286
void iSndInitSceneLoaded();
6387
S32 iSndIsPlaying(U32 assetID);
6488
S32 iSndIsPlaying(U32 assetID, U32 parid);
89+
iSndFileInfo* iSndLookup(U32 id);
6590
void iSndWaitForDeadSounds();
6691
void iSndSceneExit();
6792
void sndloadcb(tag_xFile* tag);

src/SB/Game/zNPCSndTable.cpp

Lines changed: 193 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#include "zNPCSndTable.h"
2-
#include "zNPCGoalVillager.h"
32

3+
#include "iSnd.h"
44
#include "xString.h"
5+
#include "xutil.h"
6+
#include "zGameExtras.h"
7+
#include "zNPCSndLists.h"
58

6-
#include <types.h>
9+
#define SND_COUNT 26
710

8-
static char* g_strz_sndgroup[26];
9-
static unsigned int g_hash_sndgroup[26];
10-
static float g_tmrz_sndplay[26];
11+
static U32 g_hash_sndgroup[SND_COUNT];
12+
static F32 g_tmrz_sndplay[SND_COUNT] = {};
13+
static char* g_strz_sndgroup[SND_COUNT] = {
14+
"ListEnd", "Encounter", "Clanking", "Exclaim", "Ouch", "Cheering", "Respawn",
15+
"Alert", "Dizzy", "Dance", "Laugh", "Attack", "Punch", "WepLaunch",
16+
"Lightning", "WarnBang", "Death", "DeathJelly", "Bonked", "Unbonked", "TikiStack",
17+
"TikiExplode", "TikiThunder", "XSfxTalk", "OneLiner", "OneLinerToo"
18+
};
1119

1220
void NPCS_Startup()
1321
{
14-
for (int i = 0; i < (int)(sizeof(g_strz_sndgroup) / sizeof(char*)); i++)
22+
for (S32 i = 0; i < (S32)(sizeof(g_strz_sndgroup) / sizeof(char*)); i++)
1523
{
1624
g_hash_sndgroup[i] = xStrHash(g_strz_sndgroup[i]);
1725
}
@@ -21,22 +29,27 @@ void NPCS_Shutdown()
2129
{
2230
}
2331

24-
int NPCS_SndOkToPlay(en_NPC_SOUND sndtype)
32+
void NPCS_SndTimersUpdate(F32 dt)
2533
{
26-
if (sndtype == NPC_STYP_BOGUS)
34+
// non-matching: only producing one lfs instruction for -1.0f
35+
for (S32 i = 0; i < SND_COUNT; i++)
2736
{
28-
return 1;
37+
g_tmrz_sndplay[i] = MAX(g_tmrz_sndplay[i] - dt, -1.0f);
2938
}
30-
if (sndtype == NPC_STYP_LISTEND)
39+
}
40+
41+
void NPCS_SndTimersReset()
42+
{
43+
// non-matching: missing lfs for -1.0f
44+
for (S32 i = 0; i < SND_COUNT; i++)
3145
{
32-
return 0;
46+
g_tmrz_sndplay[i] = -1.0f;
3347
}
34-
return g_tmrz_sndplay[sndtype] < 0.0f;
3548
}
3649

37-
void NPCS_SndTypePlayed(en_NPC_SOUND sndtype, float delayNext)
50+
void NPCS_SndTypePlayed(en_NPC_SOUND sndtype, F32 delayNext)
3851
{
39-
float tym = 2.0f;
52+
F32 tym = 2.0f;
4053

4154
switch (sndtype)
4255
{
@@ -58,3 +71,169 @@ void NPCS_SndTypePlayed(en_NPC_SOUND sndtype, float delayNext)
5871

5972
g_tmrz_sndplay[sndtype] = tym;
6073
}
74+
75+
S32 NPCS_SndOkToPlay(en_NPC_SOUND sndtype)
76+
{
77+
if (sndtype == NPC_STYP_BOGUS)
78+
{
79+
return 1;
80+
}
81+
if (sndtype == NPC_STYP_LISTEND)
82+
{
83+
return 0;
84+
}
85+
return g_tmrz_sndplay[sndtype] < 0.0f;
86+
}
87+
88+
void NPCS_SndTablePrepare(NPCSndTrax* trax)
89+
{
90+
while (trax->typ_sound != NPC_STYP_LISTEND)
91+
{
92+
U32 sound_hash = xStrHash(trax->nam_sound);
93+
if (sound_hash != 0 && iSndLookup(sound_hash) != NULL)
94+
{
95+
trax->aid_sound = sound_hash;
96+
}
97+
else
98+
{
99+
trax->aid_sound = 0;
100+
}
101+
trax++;
102+
}
103+
}
104+
105+
NPCSndProp* NPCS_SndFindProps(en_NPC_SOUND sndtype)
106+
{
107+
NPCSndProp* sprop = g_sndProps;
108+
while (sprop->sndtype != NPC_STYP_LISTEND)
109+
{
110+
if (sprop->sndtype == sndtype)
111+
{
112+
break;
113+
}
114+
sprop++;
115+
}
116+
return sprop;
117+
}
118+
119+
en_NPC_SOUND NPCS_SndTypeFromHash(U32 aid_snd, NPCSndTrax* cust, NPCSndTrax* share)
120+
{
121+
// non-matching
122+
en_NPC_SOUND da_type = NPC_STYP_BOGUS;
123+
NPCSndTrax* trax;
124+
125+
for (S32 i = 0; i <= 3; i++)
126+
{
127+
if (i == 0)
128+
{
129+
trax = cust;
130+
}
131+
else if (i == 1)
132+
{
133+
trax = share;
134+
}
135+
else if (i == 2)
136+
{
137+
trax = g_sndTrax_General;
138+
}
139+
else
140+
{
141+
trax = g_sndTrax_Universal;
142+
}
143+
144+
if (trax != NULL)
145+
{
146+
for (; trax->typ_sound != NPC_STYP_LISTEND; trax = trax + 1)
147+
{
148+
if (trax->aid_sound == aid_snd)
149+
{
150+
da_type = trax->typ_sound;
151+
152+
return da_type;
153+
}
154+
}
155+
}
156+
}
157+
158+
return da_type;
159+
}
160+
161+
// WIP
162+
U32 NPCS_SndPickSimilar(en_NPC_SOUND sndtype, NPCSndTrax* cust, NPCSndTrax* share)
163+
{
164+
S32 cnt = 0;
165+
S32 list[32] = {};
166+
F32 wts[32] = { 1.0f };
167+
168+
for (S32 si = 0; si < 4; si++)
169+
{
170+
NPCSndTrax* trax;
171+
F32 weight;
172+
173+
if (si == 0)
174+
{
175+
trax = cust;
176+
weight = 2.0f;
177+
}
178+
else if (si == 1)
179+
{
180+
trax = share;
181+
weight = 1.5f;
182+
}
183+
else
184+
{
185+
if (cnt >= 5)
186+
{
187+
trax = NULL;
188+
weight = 0.0f;
189+
}
190+
else if (si == 2)
191+
{
192+
trax = g_sndTrax_General;
193+
weight = 1.0f;
194+
}
195+
else
196+
{
197+
trax = g_sndTrax_Universal;
198+
weight = 1.0f;
199+
}
200+
}
201+
202+
if (trax == NULL)
203+
{
204+
continue;
205+
}
206+
207+
bool in_group = false;
208+
for (; trax->typ_sound != NPC_STYP_LISTEND; trax++)
209+
{
210+
if (trax->typ_sound == sndtype)
211+
{
212+
in_group = true;
213+
if (trax->aid_sound != 0 && cnt < 32)
214+
{
215+
wts[cnt] = weight;
216+
list[cnt] = trax->aid_sound;
217+
cnt++;
218+
}
219+
}
220+
else if (in_group)
221+
{
222+
break;
223+
}
224+
225+
if (cnt >= 32)
226+
{
227+
break;
228+
}
229+
}
230+
}
231+
232+
if (cnt > 0)
233+
{
234+
xUtil_wtadjust(wts, cnt, 1.0f);
235+
return xUtil_choose(list, cnt, wts);
236+
}
237+
238+
return 0;
239+
}

src/SB/Game/zNPCSndTable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ struct NPCSndQueue //0x14
1515
};
1616

1717
void NPCS_Startup();
18-
void NPCS_SndTimersReset();
1918
void NPCS_SndTimersUpdate(F32 dt);
19+
void NPCS_SndTimersReset();
20+
void NPCS_SndTypePlayed(en_NPC_SOUND sndtype, F32 delayNext);
21+
S32 NPCS_SndOkToPlay(en_NPC_SOUND sndtype);
2022
void NPCS_SndTablePrepare(NPCSndTrax* trax);
23+
NPCSndProp* NPCS_SndFindProps(en_NPC_SOUND sndtype);
24+
en_NPC_SOUND NPCS_SndTypeFromHash(U32 aid_snd, NPCSndTrax* cust, NPCSndTrax* share);
2125
void NPCS_Shutdown();
2226

2327
#endif

src/SB/Game/zNPCTypeBossSandy.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "xMarkerAsset.h"
1818
#include "zCamera.h"
1919
#include "zGrid.h"
20-
#include "zAssetTypes.h"
2120

2221
extern const char bossSandyStrings[];
2322

@@ -146,30 +145,30 @@ xAnimTable* ZNPC_AnimTable_BossSandy()
146145
{
147146
// clang-format off
148147
S32 ourAnims[25] = {
149-
Idle01,
150-
Idle02,
151-
Taunt01,
152-
Run01,
153-
Walk01,
154-
Melee01,
155-
Hit01,
156-
Hit02,
148+
Idle01,
149+
Idle02,
150+
Taunt01,
151+
Run01,
152+
Walk01,
153+
Melee01,
154+
Hit01,
155+
Hit02,
157156
GetUp01,
158-
Dizzy01,
159-
ElbowDrop01,
160-
Leap01,
161-
Leap02,
157+
Dizzy01,
158+
ElbowDrop01,
159+
Leap01,
160+
Leap02,
162161
Leap03 ,
163-
Leap04,
164-
Sit01,
162+
Leap04,
163+
Sit01,
165164
SitShock01,
166-
CLBegin01,
167-
CLLoop01,
165+
CLBegin01,
166+
CLLoop01,
168167
CLEnd01,
169168
NoHeadIdle01,
170-
NoHeadWaving01,
169+
NoHeadWaving01,
171170
NoHeadGetUp01,
172-
NoHeadShotUp01,
171+
NoHeadShotUp01,
173172
NoHeadShock01,
174173
};
175174
// clang-format on

0 commit comments

Comments
 (0)