]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.h
gave names to nearly all structs and enums which should make for better C++ error...
[xonotic/darkplaces.git] / snd_main.h
index aa36d0154381f954cd57fc86e7b6fe83c8bf3e86..4c674daa90706cb349191e6b1bacfab385070d41 100644 (file)
@@ -24,14 +24,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "sound.h"
 
 
-typedef struct
+typedef struct sfxbuffer_s
 {
-       size_t  length;
-       size_t  offset;
+       unsigned int    length;
+       unsigned int    offset;
        qbyte   data[4];        // variable sized
 } sfxbuffer_t;
 
-typedef struct
+typedef struct snd_format_s
 {
        unsigned int    speed;
        unsigned int    width;
@@ -43,26 +43,28 @@ typedef struct
 #define SFXFLAG_FILEMISSING            (1 << 0) // wasn't able to load the associated sound file
 #define SFXFLAG_SERVERSOUND            (1 << 1) // the sfx is part of the server precache list
 #define SFXFLAG_STREAMED               (1 << 2) // informative only. You shouldn't need to know that
-#define SFXFLAG_PERMANENT              (1 << 3) // the sfx is used by the client code and should not be purged (even if it is also in the server precache list)
+#define SFXFLAG_PERMANENTLOCK  (1 << 3) // can never be freed (ex: used by the client code)
 
 typedef struct snd_fetcher_s snd_fetcher_t;
 struct sfx_s
 {
        char                            name[MAX_QPATH];
        sfx_t                           *next;
-       mempool_t                       *mempool;
-       unsigned int            locks;                  // A locked sfx_t must not be freed.
-                                                                               // Locks are added by S_PrecacheSound and S_ServerSounds.
-                                                                               // SFX can be freed by S_UnlockSfx or S_ServerSounds.
+       size_t                          memsize;                // total memory used (including sfx_t and fetcher data)
+       int                                     locks;                  // One lock is automatically granted while the sfx is
+                                                                               // playing (and removed when stopped). Locks can also be
+                                                                               // added by S_PrecacheSound and S_ServerSounds.
+                                                                               // A SFX with no lock and no SFXFLAG_PERMANENTLOCK is
+                                                                               // freed at level change by S_ServerSounds.
        unsigned int            flags;                  // cf SFXFLAG_* defines
        snd_format_t            format;
        int                                     loopstart;
-       size_t                          total_length;
+       unsigned int            total_length;
        const snd_fetcher_t     *fetcher;
        void                            *fetcher_data;  // Per-sfx data for the sound fetching functions
 };
 
-typedef struct
+typedef struct dma_s
 {
        snd_format_t    format;
        int                             samples;                // mono samples in buffer
@@ -71,7 +73,7 @@ typedef struct
        int                             bufferlength;   // used only by certain drivers
 } dma_t;
 
-typedef struct
+typedef struct channel_s
 {
        sfx_t                   *sfx;                   // sfx number
        unsigned int    flags;                  // cf CHANNELFLAG_* defines
@@ -89,11 +91,13 @@ typedef struct
 } channel_t;
 
 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
-typedef void (*snd_fetcher_end_t) (channel_t* ch);
+typedef void (*snd_fetcher_endsb_t) (channel_t* ch);
+typedef void (*snd_fetcher_free_t) (sfx_t* sfx);
 struct snd_fetcher_s
 {
        snd_fetcher_getsb_t             getsb;
-       snd_fetcher_end_t               end;
+       snd_fetcher_endsb_t             endsb;
+       snd_fetcher_free_t              free;
 };
 
 void S_PaintChannels(int endtime);
@@ -110,15 +114,15 @@ void SNDDMA_Submit(void);
 void SNDDMA_Shutdown(void);
 
 qboolean S_LoadSound (sfx_t *s, qboolean complain);
-void S_UnloadSound(sfx_t *s);
+
+void S_LockSfx (sfx_t *sfx);
+void S_UnlockSfx (sfx_t *sfx);
 
 void *S_LockBuffer(void);
 void S_UnlockBuffer(void);
 
 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
 
-// ====================================================================
-// User-setable variables
 // ====================================================================
 
 // 0 to NUM_AMBIENTS - 1 = water, etc
@@ -140,5 +144,7 @@ extern cvar_t snd_streaming;
 
 extern int snd_blocked;
 
+extern mempool_t *snd_mempool;
+
 
 #endif