Browse Source

Bugfix: only play a sound if it exists

Thomas Buck 10 years ago
parent
commit
299ddfb347
3 changed files with 30 additions and 12 deletions
  1. 6
    0
      include/Sound.h
  2. 19
    12
      src/OpenRaider.cpp
  3. 5
    0
      src/Sound.cpp

+ 6
- 0
include/Sound.h View File

@@ -37,6 +37,12 @@ public:
37 37
     int init();
38 38
 
39 39
     /*!
40
+     * \brief Get number of registered sources
41
+     * \returns number of registered sources
42
+     */
43
+    int registeredSources();
44
+
45
+    /*!
40 46
      * \brief Move listener and repositions them
41 47
      * \param pos New position for listener
42 48
      * \param angle New orientation for listener

+ 19
- 12
src/OpenRaider.cpp View File

@@ -625,8 +625,6 @@ void OpenRaider::handleKeyPressEvent(unsigned int key, unsigned int mod)
625 625
     switch (key)
626 626
     {
627 627
         case SYS_MOUSE_LEFT:
628
-            mSound.play(m_testSFX);
629
-
630 628
             if (LARA)
631 629
             {
632 630
                 eventAnimTest(15);
@@ -672,7 +670,11 @@ void OpenRaider::handleKeyPressEvent(unsigned int key, unsigned int mod)
672 670
             }
673 671
             break;
674 672
         case 'r':
675
-            mSound.play(m_testSFX);
673
+            if (m_flags & OpenRaider_EnableSound) {
674
+                if (m_testSFX < mSound.registeredSources()) {
675
+                    mSound.play(m_testSFX);
676
+                }
677
+            }
676 678
             break;
677 679
     }
678 680
 }
@@ -1072,7 +1074,8 @@ void OpenRaider::gameFrame()
1072 1074
                         {
1073 1075
                             if (m_flags & OpenRaider_EnableSound)
1074 1076
                             {
1075
-                                mSound.play(TR_SOUND_FOOTSTEP0);
1077
+                                if (TR_SOUND_FOOTSTEP0 < mSound.registeredSources())
1078
+                                    mSound.play(TR_SOUND_FOOTSTEP0);
1076 1079
                             }
1077 1080
                         }
1078 1081
                         else if (mdl->getAnimation() == 15)
@@ -1193,14 +1196,18 @@ void OpenRaider::processTextures()
1193 1196
 
1194 1197
 void OpenRaider::soundEvent(int type, int id, vec3_t pos, vec3_t angles)
1195 1198
 {
1196
-    switch (type)
1197
-    {
1198
-        case 0: //  Reset listener position
1199
-            mSound.listenAt(pos, angles);
1200
-            break;
1201
-        default:
1202
-            mSound.sourceAt(id, pos);
1203
-            mSound.play(id);
1199
+    if (m_flags & OpenRaider_EnableSound) {
1200
+        switch (type)
1201
+        {
1202
+            case 0: //  Reset listener position
1203
+                mSound.listenAt(pos, angles);
1204
+                break;
1205
+            default:
1206
+                if (id < mSound.registeredSources()) {
1207
+                    mSound.sourceAt(id, pos);
1208
+                    mSound.play(id);
1209
+                }
1210
+        }
1204 1211
     }
1205 1212
 }
1206 1213
 

+ 5
- 0
src/Sound.cpp View File

@@ -76,6 +76,11 @@ int Sound::init()
76 76
 }
77 77
 
78 78
 
79
+int Sound::registeredSources() {
80
+    return mNext;
81
+}
82
+
83
+
79 84
 void Sound::listenAt(float pos[3], float angle[3])
80 85
 {
81 86
     assert(mInit == true);

Loading…
Cancel
Save