I didnt have time to look too much at the source code yet, but here is a
small one on increasing the maximum number of precached sounds, as well
as a small related bugfix.
All changes are contained between
//KS
and
//END KS
////////////////////
In CL_Parse.c
///////////////////
void CL_ParseStartSoundPacket(void)
{
vec3_t pos;
int channel, ent;
int sound_num;
int volume;
int field_mask;
float attenuation;
int i;
field_mask = MSG_ReadByte();
if (field_mask & SND_VOLUME)
volume = MSG_ReadByte ();
else
volume = DEFAULT_SOUND_PACKET_VOLUME;
if (field_mask & SND_ATTENUATION)
attenuation = MSG_ReadByte () / 64.0;
else
attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
channel = MSG_ReadShort ();
sound_num = MSG_ReadByte ();
//KS Increase max sounds
if (field_mask & SND_OVERFLOW)
sound_num += 256;//was 255
if (field_mask & SND_OVERFLOW2)
sound_num += 512;
//KS This gets replace by the above code
/*if (field_mask & SND_OVERFLOW)
sound_num += 255;*/
//END KS
ent = channel >> 3;
channel &= 7;
if (ent > MAX_EDICTS)
Host_Error ("CL_ParseStartSoundPacket: ent = %i", ent);
for (i=0 ; i<3 ; i++)
pos[i] = MSG_ReadCoord ();
S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
}
////////////////////
In SV_Main.c
////////////////////
void SV_StartSound (edict_t *entity, int channel, char *sample, int volume,
float attenuation)
{
int sound_num;
int field_mask;
int i;
int ent;
#if RJNET
sizebuf_t cm;
byte datagram_buf[MAX_DATAGRAM];
client_t *client;
vec_t distance;
vec3_t diff;
cm.data = datagram_buf;
cm.maxsize = sizeof(datagram_buf);
cm.cursize = 0;
#endif
if (strcmpi(sample,"misc/null.wav") == 0)
{
SV_StopSound(entity,channel);
return;
}
if (volume < 0 || volume > 255)
Sys_Error ("SV_StartSound: volume = %i", volume);
if (attenuation < 0 || attenuation > 4)
Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
if (channel < 0 || channel > 7)
Sys_Error ("SV_StartSound: channel = %i", channel);
if (sv.datagram.cursize > MAX_DATAGRAM-16)
return;
// find precache number for sound
for (sound_num=1 ; sound_num511)
{
field_mask |= SND_OVERFLOW2;
sound_num -= 512;
}
if (sound_num>255)
{
field_mask |= SND_OVERFLOW;
sound_num -= 256;//KS Was 255
}
//KS this code has been replaced by the above code.
//BUG here! first, why set the SND_ATTENUATION bitflag
//when it is supposed to be SND_OVERFLOW? Client checks for SND_OVERFLOW!!!
//Second bug, its 256 that should be substracted, not 255. Same thing when adding
//it back on client side
/*if (sound_num>255)
{
field_mask |= SND_ATTENUATION;
sound_num -= 255;
}*/
//END KS
#if RJNETa
MSG_WriteByte (&cm, svc_sound);
MSG_WriteByte (&cm, field_mask);
if (field_mask & SND_VOLUME)
MSG_WriteByte (&cm, volume);
if (field_mask & SND_ATTENUATION)
MSG_WriteByte (&cm, attenuation*64);
MSG_WriteShort (&cm, channel);
MSG_WriteByte (&cm, sound_num);
for (i=0 ; i<3 ; i++)
MSG_WriteCoord (&cm, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]));
for (i=0, client = svs.clients ; iactive)
continue;
VectorAdd(entity->v.absmax,entity->v.absmin,diff);
diff[0] /= 2;
diff[1] /= 2;
diff[2] /= 2;
VectorSubtract(client->edict->v.origin,diff,diff);
distance = Length(diff);
if (!sv_sound_distance.value || distance < sv_sound_distance.value)
{ // rjr this gets put in a reliable packet - should be unreliable
SZ_Write (&client->message, cm.data, cm.cursize);
}
}
#else
// directed messages go only to the entity the are targeted on
MSG_WriteByte (&sv.datagram, svc_sound);
MSG_WriteByte (&sv.datagram, field_mask);
if (field_mask & SND_VOLUME)
MSG_WriteByte (&sv.datagram, volume);
if (field_mask & SND_ATTENUATION)
MSG_WriteByte (&sv.datagram, attenuation*64);
MSG_WriteShort (&sv.datagram, channel);
MSG_WriteByte (&sv.datagram, sound_num);
for (i=0 ; i<3 ; i++)
MSG_WriteCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]));
#endif
}
////////////////////
In Quakedefs.h
////////////////////
//KS change the MAX_SOUND define from 512 to 1024
#define MAX_SOUNDS 1024 // Sent over the net as a byte
//#define MAX_SOUNDS 1024 // Sent over the net as a byte
//END KS
////////////////////
In Protocol.h
////////////////////
//KS increased max_sounds
//Just add the SND_OVERFLOW2 define after SND_OVERFLOW
// a sound with no channel is a local only sound
#define SND_VOLUME (1<<0) // a byte
#define SND_ATTENUATION (1<<1) // a byte
#define SND_OVERFLOW (1<<2) // add 255 to snd num
#define SND_OVERFLOW2 (1<<3) // add 512 to snd num
//gonna use the rest of the bits to pack the ent+channel
//END KS
|