]> git.jsancho.org Git - lugaru.git/commitdiff
Cleaned up handling of envsounds array through a function
authorCôme Chilliet <come@chilliet.eu>
Mon, 28 Nov 2016 12:43:59 +0000 (19:43 +0700)
committerCôme Chilliet <come@chilliet.eu>
Tue, 29 Nov 2016 03:39:51 +0000 (10:39 +0700)
Source/GameTick.cpp
Source/Person.cpp
Source/Skeleton.cpp
Source/Sounds.cpp
Source/Sounds.h

index 592d0e3bb3c51793bd9f2c3d96a86735736cb15f..fda1df59f2bf38045dcdcaca38a3eaad382305ba 100644 (file)
@@ -2932,12 +2932,8 @@ void doAerialAcrobatics()
                                 Person::players[k]->animTarget = Person::players[k]->getLanding();
                                 emit_sound_at(landsound, Person::players[k]->coords, 128.);
                                 if (k == 0) {
-                                    envsound[numenvsounds] = Person::players[k]->coords;
-                                    envsoundvol[numenvsounds] = 16;
-                                    envsoundlife[numenvsounds] = .4;
-                                    numenvsounds++;
+                                    addEnvSound(Person::players[k]->coords);
                                 }
-
                             }
                         }
                     }
index 8a3579e4b5e58ed17b2108ebbe9c96c03bd62925..a95794520d7684204181c46ac80fc39693509209 100644 (file)
@@ -57,10 +57,6 @@ extern float flashamount, flashr, flashg, flashb;
 extern int flashdelay;
 extern bool showpoints;
 extern bool immediate;
-extern XYZ envsound[30];
-extern float envsoundvol[30];
-extern float envsoundlife[30];
-extern int numenvsounds;
 extern int tutoriallevel;
 extern float smoketex;
 extern int tutorialstage;
@@ -625,17 +621,12 @@ void Person::DoBloodBig(float howmuch, int which)
             // play pain sounds
             int whichsound = -1;
 
-            // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
             if (creature == wolftype) {
                 int i = abs(Random() % 2);
                 if (i == 0)
                     whichsound = snarlsound;
                 if (i == 1)
                     whichsound = snarl2sound;
-                envsound[numenvsounds] = coords;
-                envsoundvol[numenvsounds] = 16;
-                envsoundlife[numenvsounds] = .4;
-                numenvsounds++;
             }
             if (creature == rabbittype) {
                 int i = abs(Random() % 2);
@@ -643,14 +634,12 @@ void Person::DoBloodBig(float howmuch, int which)
                     whichsound = rabbitpainsound;
                 if (i == 1 && howmuch >= 2)
                     whichsound = rabbitpain1sound;
-                envsound[numenvsounds] = coords;
-                envsoundvol[numenvsounds] = 16;
-                envsoundlife[numenvsounds] = .4;
-                numenvsounds++;
             }
 
-            if (whichsound != -1)
+            if (whichsound != -1) {
                 emit_sound_at(whichsound, coords);
+                addEnvSound(coords);
+            }
         }
 
     if (id == 0 && howmuch > 0) {
@@ -1441,10 +1430,6 @@ void Person::DoDamage(float howmuch)
                     whichsound = snarlsound;
                 if (i == 1)
                     whichsound = snarl2sound;
-                envsound[numenvsounds] = coords;
-                envsoundvol[numenvsounds] = 16;
-                envsoundlife[numenvsounds] = .4;
-                numenvsounds++;
             }
             if (creature == rabbittype) {
                 int i = abs(Random() % 2);
@@ -1452,14 +1437,11 @@ void Person::DoDamage(float howmuch)
                     whichsound = rabbitpainsound;
                 if (i == 1 && damage > damagetolerance)
                     whichsound = rabbitpain1sound;
-                envsound[numenvsounds] = coords;
-                envsoundvol[numenvsounds] = 16;
-                envsoundlife[numenvsounds] = .4;
-                numenvsounds++;
             }
 
             if (whichsound != -1) {
                 emit_sound_at(whichsound, coords);
+                addEnvSound(coords);
             }
         }
     speechdelay = .3;
@@ -1987,13 +1969,11 @@ void Person::DoAnimations()
 
                     if (id == 0)
                         if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
-                            envsound[numenvsounds] = coords;
-                            if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
-                                envsoundvol[numenvsounds] = 15;
-                            else
-                                envsoundvol[numenvsounds] = 6;
-                            envsoundlife[numenvsounds] = .4;
-                            numenvsounds++;
+                            if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) {
+                                addEnvSound(coords, 15);
+                            } else {
+                                addEnvSound(coords, 6);
+                            }
                         }
 
                     if (animation[animTarget].label[frameTarget] == 3) {
@@ -5229,10 +5209,7 @@ void Person::DoStuff()
                             emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
 
                             if (id == 0) {
-                                envsound[numenvsounds] = coords;
-                                envsoundvol[numenvsounds] = 4 * findLength(&velocity);
-                                envsoundlife[numenvsounds] = .4;
-                                numenvsounds++;
+                                addEnvSound(coords, 4 * findLength(&velocity));
                             }
 
                             int howmany;
@@ -5292,10 +5269,7 @@ void Person::DoStuff()
                             emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
 
                             if (id == 0) {
-                                envsound[numenvsounds] = coords;
-                                envsoundvol[numenvsounds] = 4 * findLength(&velocity);
-                                envsoundlife[numenvsounds] = .4;
-                                numenvsounds++;
+                                addEnvSound(coords, 4 * findLength(&velocity));
                             }
 
                             int howmany;
@@ -5784,10 +5758,7 @@ void Person::DoStuff()
                 emit_sound_at(landsound, coords, 128.);
 
                 if (id == 0) {
-                    envsound[numenvsounds] = coords;
-                    envsoundvol[numenvsounds] = 16;
-                    envsoundlife[numenvsounds] = .4;
-                    numenvsounds++;
+                    addEnvSound(coords);
                 }
             }
         }
@@ -6684,10 +6655,7 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                                     emit_sound_at(landsound, coords, 128.);
 
                                     if (id == 0) {
-                                        envsound[numenvsounds] = coords;
-                                        envsoundvol[numenvsounds] = 16;
-                                        envsoundlife[numenvsounds] = .4;
-                                        numenvsounds++;
+                                        addEnvSound(coords);
                                     }
                                 }
                             }
index 1abc95930804838e2d0a5378053b0fcf0e5297aa..af343d6b3261b3a405f876f877e665a7a6813c85 100644 (file)
@@ -32,10 +32,6 @@ extern int environment;
 extern float camerashake;
 extern bool freeze;
 extern int detail;
-extern XYZ envsound[30];
-extern float envsoundvol[30];
-extern int numenvsounds;
-extern float envsoundlife[30];
 extern int tutoriallevel;
 
 extern int whichjointstartarray[26];
@@ -350,10 +346,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale)
 
                             emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
 
-                            envsound[numenvsounds] = *coords;
-                            envsoundvol[numenvsounds] = 64;
-                            envsoundlife[numenvsounds] = .4;
-                            numenvsounds++;
+                            addEnvSound(*coords, 64);
                         }
 
                     if (findLengthfast(&bounceness) > 2500) {
@@ -438,10 +431,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale)
 
                                             emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
 
-                                            envsound[numenvsounds] = *coords;
-                                            envsoundvol[numenvsounds] = 64;
-                                            envsoundlife[numenvsounds] = .4;
-                                            numenvsounds++;
+                                            addEnvSound(*coords, 64);
                                         }
                                     if (objects.type[k] == treetrunktype) {
                                         objects.rotx[k] += joints[i].velocity.x * multiplier * .4;
index 6bb69700acfa31ee5a6146aba3ab32e4d8b8ad17..c2d4eb714863b86e334d5a86aa51e0b94318f843 100644 (file)
@@ -23,6 +23,11 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 
 struct OPENAL_SAMPLE *samp[sounds_count];
 
+extern XYZ envsound[30];
+extern float envsoundvol[30];
+extern int numenvsounds;
+extern float envsoundlife[30];
+
 int footstepsound, footstepsound2, footstepsound3, footstepsound4;
 
 int channels[100];
@@ -69,8 +74,15 @@ void loadAllSounds()
         OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL);
 }
 
-void
-emit_sound_at(int soundid, const XYZ &pos, float vol)
+void addEnvSound(XYZ coords, float vol, float life)
+{
+    envsound[numenvsounds] = coords;
+    envsoundvol[numenvsounds] = vol;
+    envsoundlife[numenvsounds] = life;
+    numenvsounds++;
+}
+
+void emit_sound_at(int soundid, const XYZ &pos, float vol)
 {
     PlaySoundEx (soundid, samp[soundid], NULL, true);
     OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL);
@@ -78,16 +90,14 @@ emit_sound_at(int soundid, const XYZ &pos, float vol)
     OPENAL_SetPaused (channels[soundid], false);
 }
 
-void
-emit_sound_np(int soundid, float vol)
+void emit_sound_np(int soundid, float vol)
 {
     PlaySoundEx (soundid, samp[soundid], NULL, true);
     OPENAL_SetVolume (channels[soundid], vol);
     OPENAL_SetPaused (channels[soundid], false);
 }
 
-void
-emit_stream_at(int soundid, const XYZ &pos, float vol)
+void emit_stream_at(int soundid, const XYZ &pos, float vol)
 {
     PlayStreamEx (soundid, samp[soundid], NULL, true);
     OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL);
@@ -95,23 +105,19 @@ emit_stream_at(int soundid, const XYZ &pos, float vol)
     OPENAL_SetPaused (channels[soundid], false);
 }
 
-void
-emit_stream_np(int soundid, float vol)
+void emit_stream_np(int soundid, float vol)
 {
     PlayStreamEx (soundid, samp[soundid], NULL, true);
     OPENAL_SetVolume (channels[soundid], vol);
     OPENAL_SetPaused (channels[soundid], false);
 }
 
-void
-resume_stream(int soundid)
+void resume_stream(int soundid)
 {
     OPENAL_SetPaused (channels[soundid], false);
 }
 
-void
-pause_sound(int soundid)
+void pause_sound(int soundid)
 {
     OPENAL_SetPaused (channels[soundid], true);
 }
-
index 0ef5f3e9ac4b0a601796bb89a0f815b00db07f1a..7557993e83a16e2472f360fd71273ca6e535cba8 100644 (file)
@@ -32,6 +32,8 @@ extern int channels[];
 
 extern void loadAllSounds();
 
+extern void addEnvSound(XYZ coords, float vol = 16, float life = .4);
+
 extern void emit_sound_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f);
 extern void emit_sound_np(int soundid, float vol = 256.f);
 extern void emit_stream_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f);