Browse Source

add get_null_sound()

David Rose 23 years ago
parent
commit
f32b59b92d

+ 16 - 2
panda/src/audio/audioManager.cxx

@@ -83,9 +83,23 @@ create_AudioManager() {
   return am;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AudioManager::get_null_sound
+//       Access: Public
+//  Description: Returns a special NullAudioSound object that has all
+//               the interface of a normal sound object, but plays no
+//               sound.  This same object may also be returned by
+//               get_sound() if it fails.
+////////////////////////////////////////////////////////////////////
+PT(AudioSound) AudioManager::
+get_null_sound() {
+  if (_null_sound == (AudioSound *)NULL) {
+    _null_sound = new NullAudioSound;
+  }
+  return _null_sound;
+}
+
 void AudioManager::
 set_mutually_exclusive(bool bExclusive) {
   _bExclusive = bExclusive;
 }
-
-

+ 2 - 0
panda/src/audio/audioManager.h

@@ -42,6 +42,7 @@ PUBLISHED:
   
   // Get a sound:
   virtual PT(AudioSound) get_sound(const string& file_name) = 0;
+  PT(AudioSound) get_null_sound();
 
   // Tell the AudioManager there is no need to keep this one cached.
   // This doesn't break any connection between AudioSounds that have
@@ -83,6 +84,7 @@ public:
 protected:
   static Create_AudioManager_proc* _create_AudioManager;
   bool _bExclusive;
+  PT(AudioSound) _null_sound;
 
   AudioManager() {
     // intentionally blank.

+ 2 - 2
panda/src/audiotraits/milesAudioManager.cxx

@@ -265,7 +265,7 @@ get_sound(const string& file_name) {
 
   if(!is_valid()) {
      audio_debug("invalid MilesAudioManager returning NullSound");
-     return new NullAudioSound();
+     return get_null_sound();
   }
 
   assert(is_valid());
@@ -303,7 +303,7 @@ get_sound(const string& file_name) {
         // The insert failed.
         audio_debug("  failed map insert of "<<path);
         assert(is_valid());
-        return 0;
+        return get_null_sound();
       }
       // Set si, so that we can get a reference to the path
       // for the MilesAudioSound.