]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_dma.c
added Print versions of Printf functions and made all calls that do not need formatin...
[xonotic/darkplaces.git] / snd_dma.c
index 5fa7234f0d5bb7d5194b7f79b735d8eb09daf629..cb9e11cf6bf08ef8084b27baf2bc7b1fac28ed38 100644 (file)
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -22,7 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 
 #ifdef _WIN32
-#include "winquake.h"
+#include <windows.h>
+#include <dsound.h>
+extern DWORD gSndBufSize;
+extern LPDIRECTSOUND pDS;
+extern LPDIRECTSOUNDBUFFER pDSBuf;
 #endif
 
 #include "ogg.h"
@@ -118,7 +122,7 @@ void S_SoundInfo_f(void)
 {
        if (!sound_started || !shm)
        {
-               Con_Print("sound system not started\n");
+               Con_Print("sound system not started\n");
                return;
        }
 
@@ -168,7 +172,7 @@ void S_Startup(void)
        {
                if (!SNDDMA_Init())
                {
-                       Con_Printf("S_Startup: SNDDMA_Init failed.\n");
+                       Con_Print("S_Startup: SNDDMA_Init failed.\n");
                        sound_started = 0;
                        shm = NULL;
                        return;
@@ -213,7 +217,7 @@ S_Init
 */
 void S_Init(void)
 {
-       Con_DPrintf("\nSound Initialization\n");
+       Con_DPrint("\nSound Initialization\n");
 
        S_RawSamples_ClearQueue();
 
@@ -271,7 +275,7 @@ void S_Init(void)
 
 /*
 =========
-S_IsCached
+S_GetCached
 
 =========
 */
@@ -325,7 +329,7 @@ sfx_t *S_FindName (char *name)
 
        sfx = &known_sfx[num_sfx++];
        memset(sfx, 0, sizeof(*sfx));
-       snprintf(sfx->name, sizeof(sfx->name), "%s", name);
+       strncpy(sfx->name, name, sizeof(sfx->name));
        return sfx;
 }
 
@@ -338,9 +342,53 @@ S_TouchSound
 */
 void S_TouchSound (char *name)
 {
-       S_FindName(name);
+       sfx_t *sfx;
+
+       sfx = S_FindName (name);
+
+       // Set the "used" flag for this sound
+       if (sfx != NULL)
+               sfx->flags |= SFXFLAG_USED;
 }
 
+
+/*
+==================
+S_ClearUsed
+
+Reset the "used" flag of all precached sounds
+==================
+*/
+void S_ClearUsed (void)
+{
+       int i;
+
+       for (i = 0; i < num_sfx; i++)
+               known_sfx[i].flags &= ~SFXFLAG_USED;
+}
+
+
+/*
+==================
+S_PurgeUnused
+
+Free all precached sounds without the "used" flag
+==================
+*/
+void S_PurgeUnused (void)
+{
+       int i;
+       sfx_t *sfx;
+
+       for (i = 0; i < num_sfx; i++)
+       {
+               sfx = &known_sfx[i];
+               if (! (sfx->flags & SFXFLAG_USED))
+                       S_UnloadSound (sfx);
+       }
+}
+
+
 /*
 ==================
 S_PrecacheSound
@@ -587,14 +635,14 @@ void S_ClearBuffer(void)
                {
                        if (hresult != DSERR_BUFFERLOST)
                        {
-                               Con_Print("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
+                               Con_Print("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
                                S_Shutdown ();
                                return;
                        }
 
                        if (++reps > 10000)
                        {
-                               Con_Print("S_ClearBuffer: DS: couldn't restore buffer\n");
+                               Con_Print("S_ClearBuffer: DS: couldn't restore buffer\n");
                                S_Shutdown ();
                                return;
                        }
@@ -638,7 +686,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
 
        if (total_channels == MAX_CHANNELS)
        {
-               Con_Print("total_channels == MAX_CHANNELS\n");
+               Con_Print("total_channels == MAX_CHANNELS\n");
                return;
        }
 
@@ -688,7 +736,8 @@ void S_UpdateAmbientSounds (void)
 // calc ambient sound levels
        for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
        {
-               if (ambient_sfx[ambient_channel] && ambient_sfx[ambient_channel]->silentlymissing)
+               if (ambient_sfx[ambient_channel] &&
+                       (ambient_sfx[ambient_channel]->flags & SFXFLAG_SILENTLYMISSING))
                        continue;
                chan = &channels[ambient_channel];
                chan->forceloop = true;
@@ -799,7 +848,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up)
                        if (ch->sfx && (ch->leftvol || ch->rightvol) )
                                total++;
 
-               Con_Printf ("----(%i)----\n", total);
+               Con_Printf("----(%i)----\n", total);
        }
 
 // mix some sound
@@ -877,8 +926,8 @@ void S_Update_(void)
 
                if (pDSBuf)
                {
-                       if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
-                               Con_Print("Couldn't get sound buffer status\n");
+                       if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DS_OK)
+                               Con_Print("Couldn't get sound buffer status\n");
 
                        if (dwStatus & DSBSTATUS_BUFFERLOST)
                                pDSBuf->lpVtbl->Restore (pDSBuf);
@@ -977,28 +1026,13 @@ void S_LocalSound (char *sound)
        sfx = S_PrecacheSound (sound, true);
        if (!sfx)
        {
-               Con_Printf ("S_LocalSound: can't precache %s\n", sound);
+               Con_Printf("S_LocalSound: can't precache %s\n", sound);
                return;
        }
        S_StartSound (cl.viewentity, -1, sfx, vec3_origin, 1, 1);
 }
 
 
-void S_ClearPrecache (void)
-{
-}
-
-
-void S_BeginPrecaching (void)
-{
-}
-
-
-void S_EndPrecaching (void)
-{
-}
-
-
 #define RAWSAMPLESBUFFER 32768
 short s_rawsamplesbuffer[RAWSAMPLESBUFFER * 2];
 int s_rawsamplesbuffer_start;