]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / snd_main.c
index 09a132926145c3e7734188b16be3b3ee710253aa..53e63d5202eb4344b138c639231a32385fdb7f92 100644 (file)
@@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "snd_main.h"
 #include "snd_ogg.h"
-#include "snd_modplug.h"
 #include "csprogs.h"
 #include "cl_collision.h"
 #include "cdaudio.h"
@@ -50,24 +49,24 @@ static const speakerlayout_t snd_speakerlayouts[] =
        {
                "surround71", 8,
                {
-                       {0, 45, 0.2, 0.2, 0.5}, // front left
-                       {1, 315, 0.2, 0.2, 0.5}, // front right
-                       {2, 135, 0.2, 0.2, 0.5}, // rear left
-                       {3, 225, 0.2, 0.2, 0.5}, // rear right
-                       {4, 0, 0.2, 0.2, 0.5}, // front center
+                       {0, 45, 0.2f, 0.2f, 0.5f}, // front left
+                       {1, 315, 0.2f, 0.2f, 0.5f}, // front right
+                       {2, 135, 0.2f, 0.2f, 0.5f}, // rear left
+                       {3, 225, 0.2f, 0.2f, 0.5f}, // rear right
+                       {4, 0, 0.2f, 0.2f, 0.5f}, // front center
                        {5, 0, 0, 0, 0}, // lfe (we don't have any good lfe sound sources and it would take some filtering work to generate them (and they'd probably still be wrong), so...  no lfe)
-                       {6, 90, 0.2, 0.2, 0.5}, // side left
-                       {7, 180, 0.2, 0.2, 0.5}, // side right
+                       {6, 90, 0.2f, 0.2f, 0.5f}, // side left
+                       {7, 180, 0.2f, 0.2f, 0.5f}, // side right
                }
        },
        {
                "surround51", 6,
                {
-                       {0, 45, 0.2, 0.2, 0.5}, // front left
-                       {1, 315, 0.2, 0.2, 0.5}, // front right
-                       {2, 135, 0.2, 0.2, 0.5}, // rear left
-                       {3, 225, 0.2, 0.2, 0.5}, // rear right
-                       {4, 0, 0.2, 0.2, 0.5}, // front center
+                       {0, 45, 0.2f, 0.2f, 0.5f}, // front left
+                       {1, 315, 0.2f, 0.2f, 0.5f}, // front right
+                       {2, 135, 0.2f, 0.2f, 0.5f}, // rear left
+                       {3, 225, 0.2f, 0.2f, 0.5f}, // rear right
+                       {4, 0, 0.2f, 0.2f, 0.5f}, // front center
                        {5, 0, 0, 0, 0}, // lfe (we don't have any good lfe sound sources and it would take some filtering work to generate them (and they'd probably still be wrong), so...  no lfe)
                        {0, 0, 0, 0, 0},
                        {0, 0, 0, 0, 0},
@@ -78,10 +77,10 @@ static const speakerlayout_t snd_speakerlayouts[] =
                // channel of its own
                "surround40", 4,
                {
-                       {0, 45, 0.3, 0.3, 0.8}, // front left
-                       {1, 315, 0.3, 0.3, 0.8}, // front right
-                       {2, 135, 0.3, 0.3, 0.8}, // rear left
-                       {3, 225, 0.3, 0.3, 0.8}, // rear right
+                       {0, 45, 0.3f, 0.3f, 0.8f}, // front left
+                       {1, 315, 0.3f, 0.3f, 0.8f}, // front right
+                       {2, 135, 0.3f, 0.3f, 0.8f}, // rear left
+                       {3, 225, 0.3f, 0.3f, 0.8f}, // rear right
                        {0, 0, 0, 0, 0},
                        {0, 0, 0, 0, 0},
                        {0, 0, 0, 0, 0},
@@ -93,8 +92,8 @@ static const speakerlayout_t snd_speakerlayouts[] =
                // channel of its own
                "stereo", 2,
                {
-                       {0, 90, 0.5, 0.5, 1}, // side left
-                       {1, 270, 0.5, 0.5, 1}, // side right
+                       {0, 90, 0.5f, 0.5f, 1}, // side left
+                       {1, 270, 0.5f, 0.5f, 1}, // side right
                        {0, 0, 0, 0, 0},
                        {0, 0, 0, 0, 0},
                        {0, 0, 0, 0, 0},
@@ -326,7 +325,7 @@ static void S_SoundList_f (void)
                {
                        unsigned int size;
 
-                       size = sfx->memsize;
+                       size = (unsigned int)sfx->memsize;
                        Con_Printf ("%c%c%c(%5iHz %2db %6s) %8i : %s\n",
                                                (sfx->loopstart < sfx->total_length) ? 'L' : ' ',
                                                (sfx->flags & SFXFLAG_STREAMED) ? 'S' : ' ',
@@ -915,7 +914,6 @@ void S_Init(void)
        memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
 
        OGG_OpenLibrary ();
-       ModPlug_OpenLibrary ();
 }
 
 
@@ -929,7 +927,6 @@ Shutdown and free all resources
 void S_Terminate (void)
 {
        S_Shutdown ();
-       ModPlug_CloseLibrary ();
        OGG_CloseLibrary ();
 
        // Free all SFXs
@@ -1262,7 +1259,7 @@ static channel_t *SND_PickChannel(int entnum, int entchannel)
                }
 
                // don't let monster sounds override player sounds
-               if (ch->entnum == cl.viewentity && entnum != cl.viewentity)
+               if ((ch->entnum == cl.viewentity || ch->entnum == CL_VM_GetViewEntity()) && !(entnum == cl.viewentity || entnum == CL_VM_GetViewEntity()))
                        continue;
 
                // don't override looped sounds
@@ -1324,6 +1321,13 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
                        else
                                Matrix4x4_OriginFromMatrix(&cl.entities[ch->entnum].render.matrix, ch->origin);
                }
+               else if (cl.csqc_server2csqcentitynumber[ch->entnum])
+               {
+                       //Con_Printf("-- entnum %i (client %i) origin %f %f %f neworigin %f %f %f\n", ch->entnum, cl.csqc_server2csqcentitynumber[ch->entnum], ch->origin[0], ch->origin[1], ch->origin[2], cl.entities[ch->entnum].state_current.origin[0], cl.entities[ch->entnum].state_current.origin[1], cl.entities[ch->entnum].state_current.origin[2]);
+
+                       if (!CL_VM_GetEntitySoundOrigin(cl.csqc_server2csqcentitynumber[ch->entnum] + MAX_EDICTS, ch->origin))
+                               ch->entnum = MAX_EDICTS; // entity was removed, disown sound
+               }
        }
 
        mastervol = ch->basevolume;
@@ -1452,7 +1456,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
 
        // anything coming from the view entity will always be full volume
        // LordHavoc: make sounds with ATTN_NONE have no spatialization
-       if (ch->entnum == cl.viewentity || ch->distfade == 0)
+       if (ch->entnum == cl.viewentity || ch->entnum == CL_VM_GetViewEntity() || ch->distfade == 0)
        {
                ch->prologic_invert = 1;
                if (snd_spatialization_prologic.integer != 0)
@@ -1476,7 +1480,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
                f = dist * ch->distfade;
 
                f =
-                       ((snd_attenuation_exponent.value == 0) ? 1.0 : pow(1.0 - min(1.0, f), snd_attenuation_exponent.value))
+                       ((snd_attenuation_exponent.value == 0) ? 1.0 : pow(1.0 - min(1.0, f), (double)snd_attenuation_exponent.value))
                        *
                        ((snd_attenuation_decibel.value == 0) ? 1.0 : pow(0.1, 0.1 * snd_attenuation_decibel.value * f));
 
@@ -1487,7 +1491,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
                        if (snd_spatialization_occlusion.integer)
                        {
                                if(snd_spatialization_occlusion.integer & 1)
-                                       if(listener_pvs)
+                                       if(listener_pvs && cl.worldmodel)
                                        {
                                                int cluster = cl.worldmodel->brush.PointInLeaf(cl.worldmodel, ch->origin)->clusterindex;
                                                if(cluster >= 0 && cluster < 8 * listener_pvsbytes && !CHECKPVSBIT(listener_pvs, cluster))
@@ -1496,7 +1500,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx)
 
                                if(snd_spatialization_occlusion.integer & 2)
                                        if(!occluded)
-                                               if(cl.worldmodel && cl.worldmodel->brush.TraceLineOfSight && !cl.worldmodel->brush.TraceLineOfSight(cl.worldmodel, listener_origin, ch->origin))
+                                               if(cl.worldmodel && cl.worldmodel->brush.TraceLineOfSight && !cl.worldmodel->brush.TraceLineOfSight(cl.worldmodel, listener_origin, ch->origin, ch->origin, ch->origin))
                                                        occluded = true;
                        }
                        if(occluded)
@@ -1670,7 +1674,7 @@ static void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int
 int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition, int flags, float fspeed)
 {
        channel_t *target_chan, *check, *ch;
-       int             ch_idx, startpos;
+       int             ch_idx, startpos, i;
 
        if (snd_renderbuffer == NULL || sfx == NULL || nosound.integer)
                return -1;
@@ -1686,6 +1690,9 @@ int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, ve
                        {
                                S_SetChannelVolume(ch_idx, fvol);
                                S_SetChannelSpeed(ch_idx, fspeed);
+                               for(i = 1; i > 0 && (i <= flags || i <= (int) channels[ch_idx].flags); i <<= 1)
+                                       if((flags ^ channels[ch_idx].flags) & i)
+                                               S_SetChannelFlag(ch_idx, i, (flags & i) != 0);
                                ch->distfade = attenuation / snd_soundradius.value;
                                SND_Spatialize(ch, false);
                                return ch_idx;
@@ -1758,17 +1765,17 @@ void S_StopChannel (unsigned int channel_ind, qboolean lockmutex, qboolean frees
        
        ch = &channels[channel_ind];
        sfx = ch->sfx;
-       if (ch->sfx != NULL)
+       if (sfx != NULL)
        {
                if (sfx->fetcher != NULL && sfx->fetcher->stopchannel != NULL)
                        sfx->fetcher->stopchannel(ch);
                ch->fetcher_data = NULL;
                ch->sfx = NULL;
+               if (freesfx)
+                       S_FreeSfx(sfx, true);
        }
        if (lockmutex && !simsound)
                SndSys_UnlockRenderBuffer();
-       if (freesfx)
-               S_FreeSfx(sfx, true);
 }