2
0
Эх сурвалжийг харах

audio: Add positional property getter to AudioSound

Fixes #1257
Closes #1282

Co-authored-by: morganmliang <[email protected]>
rdb 3 жил өмнө
parent
commit
2ec147f3b0

+ 8 - 0
panda/src/audio/audioSound.I

@@ -10,3 +10,11 @@
  * @author jyelon
  * @date 2007-08-01
  */
+
+/**
+ * Returns true if this was created as a positional sound.
+ */
+INLINE bool AudioSound::
+is_positional() const {
+  return _positional;
+}

+ 1 - 1
panda/src/audio/audioSound.cxx

@@ -29,7 +29,7 @@ AudioSound::
  *
  */
 AudioSound::
-AudioSound() {
+AudioSound(bool positional) : _positional(positional) {
   // Intentionally blank.
 }
 

+ 6 - 1
panda/src/audio/audioSound.h

@@ -88,6 +88,8 @@ PUBLISHED:
   // There is no set_name(), this is intentional.
   virtual const std::string& get_name() const = 0;
 
+  INLINE bool is_positional() const;
+
   // return: playing time in seconds.
   virtual PN_stdfloat length() const = 0;
 
@@ -134,9 +136,12 @@ PUBLISHED:
   MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
   MAKE_PROPERTY(active, get_active, set_active);
   MAKE_PROPERTY(name, get_name);
+  MAKE_PROPERTY(positional, is_positional);
 
 protected:
-  AudioSound();
+  AudioSound(bool positional);
+
+  const bool _positional = false;
 
   friend class AudioManager;
 

+ 1 - 1
panda/src/audio/nullAudioSound.cxx

@@ -26,7 +26,7 @@ namespace {
 /**
  * All of these functions are just stubs.
  */
-NullAudioSound::NullAudioSound() {
+NullAudioSound::NullAudioSound() : AudioSound(false) {
   // Intentionally blank.
 }
 

+ 1 - 2
panda/src/audiotraits/fmodAudioSound.cxx

@@ -37,9 +37,8 @@ TypeHandle FmodAudioSound::_type_handle;
  * Constructor All sound will DEFAULT load as a 2D sound unless otherwise
  * specified.
  */
-
 FmodAudioSound::
-FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional) {
+FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional) : AudioSound(positional) {
   ReMutexHolder holder(FmodAudioManager::_lock);
   audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: "
               << file->get_original_filename());

+ 1 - 1
panda/src/audiotraits/openalAudioSound.cxx

@@ -37,6 +37,7 @@ OpenALAudioSound(OpenALAudioManager* manager,
                  MovieAudio *movie,
                  bool positional,
                  int mode) :
+  AudioSound(positional),
   _movie(movie),
   _sd(nullptr),
   _playing_loops(0),
@@ -47,7 +48,6 @@ OpenALAudioSound(OpenALAudioManager* manager,
   _volume(1.0f),
   _balance(0),
   _play_rate(1.0),
-  _positional(positional),
   _min_dist(1.0f),
   _max_dist(1000000000.0f),
   _drop_off_factor(1.0f),

+ 0 - 1
panda/src/audiotraits/openalAudioSound.h

@@ -152,7 +152,6 @@ private:
   PN_stdfloat _balance; // -1..1
   PN_stdfloat _play_rate; // 0..1.0
 
-  bool _positional;
   ALfloat _location[3];
   ALfloat _velocity[3];