rearranging TypedReferenceCount and ReferenceCount
This commit is contained in:
parent
b20bb1fd1e
commit
235585bfb3
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
#include "load_dso.h"
|
||||
|
||||
TypeHandle AudioManager::_type_handle;
|
||||
|
||||
namespace {
|
||||
PT(AudioManager) create_NullAudioManger() {
|
||||
audio_debug("create_NullAudioManger()");
|
||||
|
|
@ -33,7 +31,8 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
Create_AudioManager_proc* AudioManager::_create_AudioManager=create_NullAudioManger;
|
||||
Create_AudioManager_proc* AudioManager::_create_AudioManager
|
||||
=create_NullAudioManger;
|
||||
|
||||
void AudioManager::
|
||||
register_AudioManager_creator(Create_AudioManager_proc* proc) {
|
||||
|
|
@ -51,7 +50,8 @@ create_AudioManager() {
|
|||
if (!lib_load) {
|
||||
lib_load=1;
|
||||
if (!audio_library_name->empty() && *audio_library_name != "null") {
|
||||
Filename dl_name = Filename::dso_filename("lib"+*audio_library_name+".so");
|
||||
Filename dl_name = Filename::dso_filename(
|
||||
"lib"+*audio_library_name+".so");
|
||||
dl_name.to_os_specific();
|
||||
audio_debug(" dl_name=\""<<dl_name<<"\"");
|
||||
void* lib = load_dso(dl_name);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
typedef PT(AudioManager) Create_AudioManager_proc();
|
||||
|
||||
|
||||
class EXPCL_PANDA AudioManager : public TypedReferenceCount {
|
||||
class EXPCL_PANDA AudioManager : public ReferenceCount {
|
||||
PUBLISHED:
|
||||
// Create an AudioManager for each category of sounds you have.
|
||||
// E.g.
|
||||
|
|
@ -35,33 +35,35 @@ PUBLISHED:
|
|||
// ...
|
||||
// my_sound = MySoundEffects.get_sound("neatSfx.mp3");
|
||||
// my_music = MyMusicManager.get_sound("introTheme.mid");
|
||||
//
|
||||
// You own the AudioManager*, please delete it when you're done with it.
|
||||
// Do not delete the AudioManager (i.e. you're not done with it), until
|
||||
// you have deleted all the associated AudioSounds.
|
||||
static PT(AudioManager) create_AudioManager();
|
||||
virtual ~AudioManager() {}
|
||||
|
||||
// Get a sound:
|
||||
// You own this sound. Be sure to delete it when you're done.
|
||||
virtual PT(AudioSound) get_sound(const string& file_name) = 0;
|
||||
// Tell the AudioManager there is no need to keep this one cached.
|
||||
// This doesn't break any connection between AudioSounds that have
|
||||
// already given by get_sound() from this manager. It's
|
||||
// only affecting whether the AudioManager keeps a copy of the sound
|
||||
// in its pool/cache.
|
||||
virtual void drop_sound(const string& file_name) = 0;
|
||||
|
||||
// Control volume:
|
||||
// FYI:
|
||||
// If you start a sound with the volume off and turn the volume
|
||||
// up later, you'll hear the sound playing at that late point.
|
||||
// 0 = minimum; 1.0 = maximum.
|
||||
// inits to 1.0.
|
||||
virtual void set_volume(float volume) = 0;
|
||||
virtual float get_volume() = 0;
|
||||
|
||||
// Turn the manager on an off.
|
||||
// Turn the manager on or off.
|
||||
// If you play a sound while the manager is inactive, it won't start.
|
||||
// If you deactivate the manager while sounds are playing, they'll
|
||||
// stop.
|
||||
// If you activate the manager while looping sounds are playing
|
||||
// (those that have a loop_count of zero),
|
||||
// they will start playing from the begining of their loop.
|
||||
// inits to true.
|
||||
virtual void set_active(bool flag) = 0;
|
||||
virtual bool get_active() = 0;
|
||||
|
||||
|
|
@ -74,26 +76,6 @@ protected:
|
|||
AudioManager() {
|
||||
// intentionally blank.
|
||||
}
|
||||
|
||||
public:
|
||||
// type stuff
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
TypedReferenceCount::init_type();
|
||||
register_type(_type_handle, "AudioManager",
|
||||
TypedReferenceCount::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "audioManager.I"
|
||||
|
|
|
|||
|
|
@ -18,5 +18,3 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "audioSound.h"
|
||||
|
||||
TypeHandle AudioSound::_type_handle;
|
||||
|
|
|
|||
|
|
@ -21,15 +21,14 @@
|
|||
#define __AUDIOSOUND_H__
|
||||
|
||||
#include "config_audio.h"
|
||||
#include <typedReferenceCount.h>
|
||||
#include <typedObject.h>
|
||||
#include <ReferenceCount.h>
|
||||
#include <namable.h>
|
||||
#include <pointerTo.h>
|
||||
|
||||
|
||||
class AudioManager;
|
||||
|
||||
class EXPCL_PANDA AudioSound : public TypedReferenceCount, public Namable {
|
||||
class EXPCL_PANDA AudioSound : public ReferenceCount {
|
||||
PUBLISHED:
|
||||
virtual ~AudioSound() {}
|
||||
|
||||
|
|
@ -86,26 +85,6 @@ protected:
|
|||
}
|
||||
|
||||
friend class AudioManager;
|
||||
|
||||
public:
|
||||
// type stuff
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
TypedReferenceCount::init_type();
|
||||
register_type(_type_handle, "AudioSound",
|
||||
TypedReferenceCount::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {
|
||||
init_type();
|
||||
return get_class_type();
|
||||
}
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#endif /* __AUDIOSOUND_H__ */
|
||||
|
|
|
|||
|
|
@ -17,11 +17,8 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "config_audio.h"
|
||||
#include "audioSound.h"
|
||||
#include "audio_gui_functor.h"
|
||||
#include <dconfig.h>
|
||||
#include <filename.h>
|
||||
#include <load_dso.h>
|
||||
|
||||
Configure(config_audio);
|
||||
NotifyCategoryDef(audio, "");
|
||||
|
|
@ -60,7 +57,6 @@ string* audio_library_name;
|
|||
|
||||
|
||||
ConfigureFn(config_audio) {
|
||||
AudioSound::init_type();
|
||||
AudioGuiFunctor::init_type();
|
||||
|
||||
audio_dls_file = new string(
|
||||
|
|
|
|||
|
|
@ -27,18 +27,6 @@ NotifyCategoryDef(milesAudio, "");
|
|||
ConfigureFn(config_milesAudio) {
|
||||
init_libMilesAudio();
|
||||
}
|
||||
/*
|
||||
const float LinearIntegrator::_max_linear_dt =
|
||||
config_milesAudio.GetFloat("default_max_linear_dt", 1.0f / 30.0f);
|
||||
|
||||
const float AngularIntegrator::_max_angular_dt =
|
||||
config_milesAudio.GetFloat("default_max_angular_dt", 1.0f / 30.0f);
|
||||
|
||||
int LinearNoiseForce::_random_seed =
|
||||
config_milesAudio.GetInt("default_noise_force_seed", 665);
|
||||
|
||||
const float milesAudioObject::_default_terminal_velocity =
|
||||
config_milesAudio.GetFloat("default_terminal_velocity", 400.0f);*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: init_libMilesAudio
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "pandabase.h"
|
||||
#ifdef HAVE_RAD_MSS //[
|
||||
|
||||
#include "milesAudioSound.h"
|
||||
#include "milesAudioManager.h"
|
||||
#include "config_audio.h"
|
||||
#include "config_util.h"
|
||||
|
|
@ -179,8 +180,8 @@ get_sound(const string& file_name) {
|
|||
// Create an AudioSound from the sound:
|
||||
PT(AudioSound) audioSound = 0;
|
||||
if (audio) {
|
||||
MilesAudioSound* milesAudioSound
|
||||
=new MilesAudioSound(*this, audio, (*si).first);
|
||||
PT(MilesAudioSound) milesAudioSound
|
||||
=new MilesAudioSound(this, audio, (*si).first);
|
||||
nassertr(milesAudioSound, 0);
|
||||
milesAudioSound->set_active(_active);
|
||||
_soundsOnLoan.insert(milesAudioSound);
|
||||
|
|
|
|||
|
|
@ -24,10 +24,14 @@
|
|||
#ifdef HAVE_RAD_MSS //[
|
||||
|
||||
#include "audioManager.h"
|
||||
#include "milesAudioSound.h"
|
||||
#include "mss.h"
|
||||
|
||||
class MilesAudioSound;
|
||||
|
||||
class EXPCL_MILES_AUDIO MilesAudioManager: public AudioManager {
|
||||
public:
|
||||
// See AudioManager.h for documentation.
|
||||
|
||||
MilesAudioManager();
|
||||
~MilesAudioManager();
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
|
||||
MilesAudioSound::
|
||||
MilesAudioSound(MilesAudioManager& manager,
|
||||
MilesAudioSound(MilesAudioManager* manager,
|
||||
HAUDIO audio, string file_name)
|
||||
: _manager(manager), _file_name(file_name),
|
||||
_start_time(0), _volume(1.0), _balance(0),
|
||||
|
|
@ -42,7 +42,7 @@ MilesAudioSound(MilesAudioManager& manager,
|
|||
MilesAudioSound::
|
||||
~MilesAudioSound() {
|
||||
audio_debug("MilesAudioSound::~MilesAudioSound() "<<get_name());
|
||||
_manager.release_sound(this);
|
||||
_manager->release_sound(this);
|
||||
AIL_quick_unload(_audio);
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ set_volume(float volume) {
|
|||
// Set the volume:
|
||||
_volume=volume;
|
||||
// Account for the category of sound:
|
||||
volume*=_manager.get_volume();
|
||||
volume*=_manager->get_volume();
|
||||
// Change to Miles volume, range 0 to 127:
|
||||
S32 milesVolume=(S32(127*volume))%128;
|
||||
// Account for type:
|
||||
|
|
|
|||
|
|
@ -24,11 +24,10 @@
|
|||
#ifdef HAVE_RAD_MSS //[
|
||||
|
||||
#include "audioSound.h"
|
||||
#include "milesAudioManager.h"
|
||||
#include "mss.h"
|
||||
|
||||
|
||||
class MilesAudioManager;
|
||||
|
||||
class EXPCL_MILES_AUDIO MilesAudioSound : public AudioSound {
|
||||
public:
|
||||
~MilesAudioSound();
|
||||
|
|
@ -80,7 +79,7 @@ public:
|
|||
|
||||
private:
|
||||
HAUDIO _audio;
|
||||
MilesAudioManager& _manager;
|
||||
PT(MilesAudioManager) _manager;
|
||||
float _start_time; // 0..length()
|
||||
float _volume; // 0..1.0
|
||||
float _balance; // -1..1
|
||||
|
|
@ -89,7 +88,7 @@ private:
|
|||
bool _active;
|
||||
bool _paused;
|
||||
|
||||
MilesAudioSound(MilesAudioManager& manager,
|
||||
MilesAudioSound(MilesAudioManager* manager,
|
||||
HAUDIO audio, string file_name);
|
||||
|
||||
friend class MilesAudioManager;
|
||||
|
|
|
|||
Loading…
Reference in New Issue