]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_mix.c
restructured parts of explosion code
[xonotic/darkplaces.git] / snd_mix.c
index 6bb065894c898ebc17ada67d17f4b75043bec8b6..29e319f890d56932444e5c06cb44c7d054889df2 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -21,6 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
+typedef struct
+{
+       int left;
+       int right;
+} portable_samplepair_t;
+
 // LordHavoc: was 512, expanded to 2048
 #define        PAINTBUFFER_SIZE 2048
 portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
@@ -290,8 +296,44 @@ void S_PaintChannels(int endtime)
                        if (!S_LoadSound (sfx, true))
                                continue;
 
-                       ltime = paintedtime;
+                       // if the channel is paused
+                       if (ch->flags & CHANNELFLAG_PAUSED)
+                       {
+                               size_t pausedtime;
+
+                               pausedtime = end - paintedtime;
+                               ch->lastptime += pausedtime;
+                               ch->end += pausedtime;
+                               continue;
+                       }
+
+                       // if the sound hasn't been painted last time, update his position
+                       if (ch->lastptime < paintedtime)
+                       {
+                               ch->pos += paintedtime - ch->lastptime;
 
+                               // If the sound should have ended by then
+                               if ((unsigned int)ch->pos > sfx->total_length)
+                               {
+                                       int loopstart;
+
+                                       if (ch->flags & CHANNELFLAG_FORCELOOP)
+                                               loopstart = 0;
+                                       else
+                                               loopstart = -1;
+                                       if (sfx->loopstart >= 0)
+                                               loopstart = sfx->loopstart;
+
+                                       // If the sound is looped
+                                       if (loopstart >= 0)
+                                               ch->pos = (ch->pos - sfx->total_length) % (sfx->total_length - loopstart) + loopstart;
+                                       else 
+                                               ch->pos = sfx->total_length;
+                                       ch->end = paintedtime + sfx->total_length - ch->pos;
+                               }
+                       }
+
+                       ltime = paintedtime;
                        while (ltime < end)
                        {
                                qboolean stop_paint;
@@ -309,7 +351,11 @@ void S_PaintChannels(int endtime)
                                        else
                                                stop_paint = !SND_PaintChannelFrom16(ch, count);
 
-                                       ltime += count;
+                                       if (!stop_paint)
+                                       {
+                                               ltime += count;
+                                               ch->lastptime = ltime;
+                                       }
                                }
                                else
                                        stop_paint = false;
@@ -317,7 +363,7 @@ void S_PaintChannels(int endtime)
                                if (ltime >= ch->end)
                                {
                                        // if at end of loop, restart
-                                       if ((sfx->loopstart >= 0 || ch->forceloop) && !stop_paint)
+                                       if ((sfx->loopstart >= 0 || (ch->flags & CHANNELFLAG_FORCELOOP)) && !stop_paint)
                                        {
                                                ch->pos = bound(0, sfx->loopstart, (int)sfx->total_length - 1);
                                                ch->end = ltime + sfx->total_length - ch->pos;
@@ -329,9 +375,7 @@ void S_PaintChannels(int endtime)
 
                                if (stop_paint)
                                {
-                                       if (ch->sfx->fetcher->end != NULL)
-                                               ch->sfx->fetcher->end (ch);
-                                       ch->sfx = NULL;
+                                       S_StopChannel (ch - channels);
                                        break;
                                }
                        }