|
I noticed
that, since there were quite a few sounds happening in the game all over the
place, that many many repeated calls to the game engine using gi.soundindex()
were made (just to get the index to the sound) then, after the engine
returned that information, the sound index was immediately passed back into
the engine inside of a gi.sound() call. So, in essence, you made 2 round
trips to the engine just to get a single sound played inside the game. In my
further efforts to make the gamex86.dll run faster, I implemented the follow
to minimize repeated calls to gi.soundindex.
Try this out..
Open you g_local.h header file and add this:
extern int snd[81]; // this number may change depending on your mod.
Add this to the top of your g_spawn.c file:
int snd[81];
//=====================================================
void InitSoundArray(void) {
snd[0]=gi.soundindex("player/fry.wav");
snd[1]=gi.soundindex("player/burn1.wav");
snd[2]=gi.soundindex("player/burn2.wav");
snd[3]=gi.soundindex("player/lava1.wav");
snd[4]=gi.soundindex("player/lava2.wav");
snd[5]=gi.soundindex("player/gasp1.wav");
snd[6]=gi.soundindex("player/gasp2.wav");
snd[7]=gi.soundindex("*fall1.wav");
snd[8]=gi.soundindex("*fall2.wav");
snd[9]=gi.soundindex("*gurp1.wav");
snd[10]=gi.soundindex("*gurp2.wav");
snd[11]=gi.soundindex("*jump1.wav");
snd[12]=gi.soundindex("*drown1.wav");
snd[13]=gi.soundindex("*death1.wav");
snd[14]=gi.soundindex("*death2.wav");
snd[15]=gi.soundindex("*death3.wav");
snd[16]=gi.soundindex("*death4.wav");
snd[17]=gi.soundindex("*lava_in.wav");
snd[18]=gi.soundindex("player/watr_in.wav");
snd[19]=gi.soundindex("player/watr_un.wav");
snd[20]=gi.soundindex("player/watr_out.wav");
snd[21]=gi.soundindex("*pain25_1.wav");
snd[22]=gi.soundindex("*pain25_2.wav");
snd[23]=gi.soundindex("*pain50_1.wav");
snd[24]=gi.soundindex("*pain50_2.wav");
snd[25]=gi.soundindex("*pain75_1.wav");
snd[26]=gi.soundindex("*pain75_2.wav");
snd[27]=gi.soundindex("*pain100_1.wav");
snd[28]=gi.soundindex("*pain100_2.wav");
snd[29]=gi.soundindex("player/u_breath1.wav");
snd[30]=gi.soundindex("player/u_breath2.wav");
snd[31]=gi.soundindex("items/damage.wav");
snd[32]=gi.soundindex("items/damage2.wav");
snd[33]=gi.soundindex("items/damage3.wav");
snd[34]=gi.soundindex("items/protect.wav");
snd[35]=gi.soundindex("items/protect4.wav");
snd[36]=gi.soundindex("items/airout.wav");
snd[80]=gi.soundindex("items/protect2.wav"); // I added this one after the fact!!!
snd[37]=gi.soundindex("plats/pt1_strt.wav");
snd[38]=gi.soundindex("plats/pt1_mid.wav");
snd[39]=gi.soundindex("plats/pt1_end.wav");
snd[40]=gi.soundindex("switches/butn2.wav");
snd[41]=gi.soundindex("doors/dr1_strt.wav");
snd[42]=gi.soundindex("doors/dr1_mid.wav");
snd[43]=gi.soundindex("doors/dr1_end.wav");
snd[44]=gi.soundindex("weapons/noammo.wav");
snd[45]=gi.soundindex("weapons/rg_hum.wav");
snd[46]=gi.soundindex("weapons/bfg_hum.wav");
snd[47]=gi.soundindex("weapons/laser2.wav");
snd[48]=gi.soundindex("weapons/rockfly.wav");
snd[49]=gi.soundindex("weapons/hyprbl1a.wav");
snd[50]=gi.soundindex("weapons/hyprbd1a.wav");
snd[51]=gi.soundindex("weapons/chngnu1a.wav");
snd[52]=gi.soundindex("weapons/chngnd1a.wav");
snd[53]=gi.soundindex("weapons/chngnl1a.wav");
snd[54]=gi.soundindex("weapons/hgrenb1a.wav");
snd[55]=gi.soundindex("weapons/hgrenb2a.wav");
snd[56]=gi.soundindex("weapons/grenlb1b.wav");
snd[57]=gi.soundindex("weapons/hgrena1b.wav");
snd[58]=gi.soundindex("weapons/hgrenc1b.wav");
snd[59]=gi.soundindex("weapons/hgrent1a.wav");
snd[60]=gi.soundindex("weapons/bfg__x1b.wav");
snd[61]=gi.soundindex("weapons/bfg__l1a.wav");
snd[62]=gi.soundindex("world/electro.wav");
snd[63]=gi.soundindex("world/quake.wav");
snd[64]=gi.soundindex("world/amb10.wav");
snd[65]=gi.soundindex("world/land.wav");
snd[66]=gi.soundindex("world/mov_watr.wav");
snd[67]=gi.soundindex("world/stp_watr.wav");
snd[68]=gi.soundindex("misc/lasfly.wav");
snd[69]=gi.soundindex("misc/windfly.wav");
snd[70]=gi.soundindex("misc/h2ohit1.wav");
snd[71]=gi.soundindex("misc/power1.wav");
snd[72]=gi.soundindex("misc/power2.wav");
snd[73]=gi.soundindex("misc/udeath.wav");
snd[74]=gi.soundindex("misc/talk.wav");
snd[75]=gi.soundindex("misc/talk1.wav");
snd[76]=gi.soundindex("misc/secret.wav");
snd[77]=gi.soundindex("misc/trigger1.wav");
snd[78]=gi.soundindex("misc/keytry.wav");
snd[79]=gi.soundindex("misc/keyuse.wav");
}
If there are other sounds in your mod that are not listed here, then simply enlarge the
array definition in g_local.h and here as well, then add the sounds to the list.
Now, make the indicated change to your SP_WorldSpawn() function (or just substitute this function for you old one)..
//=====================================================
void SP_worldspawn(edict_t *ent) {
ent->movetype=MOVETYPE_PUSH;
ent->solid=SOLID_BSP;
ent->inuse=true;
ent->s.modelindex=1;
for (int i=1; i<ga.num_items; i++) {
gitem_t *item=&itemlist[i];
gi.configstring(1056+i,item->pickup_name); }
InitItemTypes(); // YOU MAY ALREADY HAVE THIS HERE (else delete it)..
if (st.nextmap)
strcpy(level.nextmap,st.nextmap);
if (ent->message) {
gi.configstring(0,ent->message);
strncpy(level.level_name,ent->message,sizeof(level.level_name)); }
else
strncpy(level.level_name,level.mapname,sizeof(level.level_name));
if (st.sky)
gi.configstring(2,st.sky);
else
gi.configstring(2,"unit1_");
if (!st.gravity)
gi.cvar_set("sv_gravity","800");
else
gi.cvar_set("sv_gravity",st.gravity);
gi.configstring(4,va("%f",st.skyrotate));
gi.configstring(3,va("%f %f %f",st.skyaxis[0],st.skyaxis[1],st.skyaxis[2]));
gi.configstring(1,va("%i",ent->sounds));
gi.configstring(30,va("%i",ga.maxclients));
gi.configstring(5,dm_statusbar);
InitSoundArray(); // ADD THIS LINE RIGHT HERE
// Only need these models precached
gi.modelindex("#w_blaster.md2");
gi.modelindex("#w_shotgun.md2");
gi.modelindex("#w_sshotgun.md2");
gi.modelindex("#w_machinegun.md2");
gi.modelindex("#w_chaingun.md2");
gi.modelindex("#a_grenades.md2");
gi.modelindex("#w_glauncher.md2");
gi.modelindex("#w_rlauncher.md2");
gi.modelindex("#w_hyperblaster.md2");
gi.modelindex("#w_railgun.md2");
gi.modelindex("#w_bfg.md2");
// I simplified these strings!!
gi.configstring(800,"m");
gi.configstring(801,"mmnmmommommnonmmonqnmmo");
gi.configstring(802,"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
gi.configstring(803,"mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
gi.configstring(804,"mamamamamama");
gi.configstring(805,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
gi.configstring(806,"nmonqnmomnmomomno");
gi.configstring(807,"mmmaaaabcdefgmmmmaaaammmaamm");
gi.configstring(808,"mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
gi.configstring(809,"aaaaaaaazzzzzzzz");
gi.configstring(810,"mmamammmmammamamaaamammma");
gi.configstring(811,"abcdefghijklmnopqrrqponmlkjihgfedcba");
gi.configstring(863,"a");
}
What this does is to not only precache ALL the soundindexes used throughout the
game but to also capture the index number returned by gi.soundindex(), so that
we don't have to ask the engine to give is the same information over and over again!
Now.. you have to systematically do global search and replaces throughout your entire
source individually replacing every call to gi.soundindex() with the appropriate
corresponding snd[] index. For example...
wherever you see gi.soundindex("weapons/noammo.wav"), you replace it with snd[44]...
NOTE: There ARE A FEW EXCEPTIONS where we DO NOT want to make the substitution.. these are
where we need a sound index but don't know the sound's name so we can't precached and
index it at the start of the game.
Such as, indexing an item's pickup sound like so:
gi.sound(other,3,gi.soundindex(ent->item->pickup_sound),1,1,0);
Or, where we are indexing st.noise like so:
func_train->moveinfo.sound_middle=gi.soundindex(st.noise);
(Actually, you could use a snd[] index for st.noise because st.noise remains the
same for each level)... But, I didn't bother with this one..
Or, where we are indexing a death sound in player_die() or a pain sound like in
P_DamageFeedback:
gi.sound(self,2,gi.soundindex(va("*death%i.wav",(rand()%3)+1)),1,1,0); }
gi.sound(player,2,gi.soundindex(va("*pain%i_%i.wav",l,(int)(1+(rand()&1)))),1,1,0); }
With these two, we use a random variable to select a death or pain sound to play...
NOTE: You can use a switch() statement with a random selector to get the appropriate
random sound.. (Hmmm... I think I'll go ahead and make that change also to my source!)..
That's it!! No more repeatedly asking the game engine for the sound indexes over and
over again (especially when we can easily grab each one at the start of each level!)..
If you come up with a clever way if indexing the item pickup sounds, please post..
Have Fun!!
Maj.Bitch
|