瀏覽代碼

Added method to remove loaded sound

Thomas Buck 10 年之前
父節點
當前提交
b3f067cf83
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 6
    0
      include/Sound.h
  2. 12
    0
      src/Sound.cpp

+ 6
- 0
include/Sound.h 查看文件

@@ -76,6 +76,12 @@ public:
76 76
     int addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags);
77 77
 
78 78
     /*!
79
+     * \brief Remove a loaded sound
80
+     * \param source valid source id
81
+     */
82
+    void remove(int source);
83
+
84
+    /*!
79 85
      * \brief Play sound source
80 86
      * \param source sound source to play
81 87
      */

+ 12
- 0
src/Sound.cpp 查看文件

@@ -229,6 +229,18 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
229 229
 }
230 230
 
231 231
 
232
+void Sound::remove(int source) {
233
+    assert(source >= 0);
234
+    assert(source < mNext);
235
+
236
+    alDeleteSources(1, &mSource[source]);
237
+    alDeleteBuffers(1, &mBuffer[source]);
238
+
239
+    if (source == (mNext - 1))
240
+        mNext--;
241
+}
242
+
243
+
232 244
 void Sound::play(int source)
233 245
 {
234 246
     assert(mInit == true);

Loading…
取消
儲存