ref: ea4e1fcf59d9478e20a4cec471ef6d34bb37eadb
parent: 53fa8e084ce1b677eca86b96727cc067656372b2
author: Simon Howard <[email protected]>
date: Fri Oct 10 19:41:03 EDT 2008
Fix crash at Hexen title screen. Subversion-branch: /branches/raven-branch Subversion-revision: 1351
--- a/src/hexen/s_sound.c
+++ b/src/hexen/s_sound.c
@@ -69,12 +69,10 @@
static byte *Mus_SndPtr;
static byte *SoundCurve;
-static char ArchivePath[128];
+int snd_MaxVolume = 10; // maximum volume for sound
+int snd_MusicVolume = 10; // maximum volume for music
+int snd_Channels = 16;
-int snd_MaxVolume; // maximum volume for sound
-int snd_MusicVolume; // maximum volume for music
-int snd_Channels = 3;
-
extern int startepisode;
extern int startmap;
@@ -279,6 +277,27 @@
S_StartSoundAtVolume(origin, sound_id, 127);
}
+static mobj_t *GetSoundListener(void)
+{
+ static degenmobj_t dummy_listener;
+
+ // If we are at the title screen, the console player doesn't have an
+ // object yet, so return a pointer to a static dummy listener instead.
+
+ if (players[displayplayer].mo != NULL)
+ {
+ return players[displayplayer].mo;
+ }
+ else
+ {
+ dummy_listener.x = 0;
+ dummy_listener.y = 0;
+ dummy_listener.z = 0;
+
+ return (mobj_t *) &dummy_listener;
+ }
+}
+
//==========================================================================
//
// S_StartSoundAtVolume
@@ -287,6 +306,7 @@
void S_StartSoundAtVolume(mobj_t * origin, int sound_id, int volume)
{
+ mobj_t *listener;
int dist, vol;
int i;
int priority;
@@ -300,9 +320,12 @@
if (sound_id == 0 || snd_MaxVolume == 0)
return;
+
+ listener = GetSoundListener();
+
if (origin == NULL)
{
- origin = players[displayplayer].mo;
+ origin = listener;
}
if (volume == 0)
{
@@ -311,8 +334,8 @@
// calculate the distance before other stuff so that we can throw out
// sounds that are beyond the hearing range.
- absx = abs(origin->x - players[displayplayer].mo->x);
- absy = abs(origin->y - players[displayplayer].mo->y);
+ absx = abs(origin->x - listener->x);
+ absy = abs(origin->y - listener->y);
dist = absx + absy - (absx > absy ? absy >> 1 : absx >> 1);
dist >>= FRACBITS;
if (dist >= MAX_SND_DIST)
@@ -395,7 +418,7 @@
Channel[i].mo = origin;
vol = (SoundCurve[dist] * (snd_MaxVolume * 8) * volume) >> 14;
- if (origin == players[displayplayer].mo)
+ if (origin == listener)
{
sep = 128;
// vol = (volume*(snd_MaxVolume+1)*8)>>7;
@@ -402,8 +425,8 @@
}
else
{
- angle = R_PointToAngle2(players[displayplayer].mo->x,
- players[displayplayer].mo->y,
+ angle = R_PointToAngle2(listener->x,
+ listener->y,
Channel[i].mo->x, Channel[i].mo->y);
angle = (angle - viewangle) >> 24;
sep = angle * 2 - 128;
@@ -845,11 +868,8 @@
void S_InitScript(void)
{
- int p;
int i;
- strcpy(ArchivePath, DEFAULT_ARCHIVEPATH);
-
SC_OpenLump("sndinfo");
while (SC_GetString())
@@ -859,7 +879,6 @@
if (!strcasecmp(sc_String, "$ARCHIVEPATH"))
{
SC_MustGetString();
- strcpy(ArchivePath, sc_String);
}
else if (!strcasecmp(sc_String, "$MAP"))
{