forked from teamnwah/openmw-tes3coop
Avoid unnecessarily friending classes
This commit is contained in:
parent
7cc950ed64
commit
fc912b135f
2 changed files with 22 additions and 23 deletions
|
@ -7,8 +7,6 @@ namespace MWSound
|
|||
{
|
||||
class Sound
|
||||
{
|
||||
virtual void update() = 0;
|
||||
|
||||
Sound& operator=(const Sound &rhs);
|
||||
Sound(const Sound &rhs);
|
||||
|
||||
|
@ -20,19 +18,31 @@ namespace MWSound
|
|||
float mMinDistance;
|
||||
float mMaxDistance;
|
||||
int mFlags;
|
||||
|
||||
float mFadeOutTime;
|
||||
|
||||
public:
|
||||
virtual void stop() = 0;
|
||||
virtual bool isPlaying() = 0;
|
||||
virtual double getTimeOffset() = 0;
|
||||
virtual void update() = 0;
|
||||
void setPosition(const osg::Vec3f &pos) { mPos = pos; }
|
||||
void setVolume(float volume) { mVolume = volume; }
|
||||
void setFadeout(float duration) { mFadeOutTime=duration; }
|
||||
void setBaseVolume(float volume) { mBaseVolume = volume; }
|
||||
void setFadeout(float duration) { mFadeOutTime = duration; }
|
||||
void updateFade(float duration)
|
||||
{
|
||||
if(mFadeOutTime > 0.0f)
|
||||
{
|
||||
float soundDuration = std::min(duration, mFadeOutTime);
|
||||
mVolume *= (mFadeOutTime-soundDuration) / mFadeOutTime;
|
||||
mFadeOutTime -= soundDuration;
|
||||
}
|
||||
}
|
||||
|
||||
MWBase::SoundManager::PlayType getPlayType() const
|
||||
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
||||
|
||||
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
|
||||
|
||||
Sound(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||
: mPos(pos)
|
||||
|
@ -42,12 +52,9 @@ namespace MWSound
|
|||
, mMinDistance(mindist)
|
||||
, mMaxDistance(maxdist)
|
||||
, mFlags(flags)
|
||||
, mFadeOutTime(0)
|
||||
, mFadeOutTime(0.0f)
|
||||
{ }
|
||||
virtual ~Sound() { }
|
||||
|
||||
friend class OpenAL_Output;
|
||||
friend class SoundManager;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -828,10 +828,9 @@ namespace MWSound
|
|||
const osg::Vec3f objpos(pos.asVec3());
|
||||
sound->setPosition(objpos);
|
||||
|
||||
if((sound->mFlags&Play_RemoveAtDistance))
|
||||
if(sound->getDistanceCull())
|
||||
{
|
||||
osg::Vec3f diff = mListenerPos - ptr.getRefData().getPosition().asVec3();
|
||||
if(diff.length2() > 2000*2000)
|
||||
if((mListenerPos - objpos).length2() > 2000*2000)
|
||||
sound->stop();
|
||||
}
|
||||
}
|
||||
|
@ -839,15 +838,8 @@ namespace MWSound
|
|||
if(!sound->isPlaying())
|
||||
return false;
|
||||
|
||||
// Update fade out
|
||||
if(sound->mFadeOutTime > 0.0f)
|
||||
{
|
||||
float soundDuration = duration;
|
||||
if(soundDuration > sound->mFadeOutTime)
|
||||
soundDuration = sound->mFadeOutTime;
|
||||
sound->setVolume(sound->mVolume - soundDuration/sound->mFadeOutTime*sound->mVolume);
|
||||
sound->mFadeOutTime -= soundDuration;
|
||||
}
|
||||
sound->updateFade(duration);
|
||||
|
||||
sound->update();
|
||||
return true;
|
||||
}
|
||||
|
@ -885,7 +877,7 @@ namespace MWSound
|
|||
for(;sndidx != snditer->second.end();++sndidx)
|
||||
{
|
||||
MWBase::SoundPtr sound = sndidx->first;
|
||||
sound->mBaseVolume = volumeFromType(sound->getPlayType());
|
||||
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
||||
sound->update();
|
||||
}
|
||||
}
|
||||
|
@ -893,12 +885,12 @@ namespace MWSound
|
|||
for(;sayiter != mActiveSaySounds.end();++sayiter)
|
||||
{
|
||||
MWBase::SoundPtr sound = sayiter->second.first;
|
||||
sound->mBaseVolume = volumeFromType(sound->getPlayType());
|
||||
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
||||
sound->update();
|
||||
}
|
||||
if(mMusic)
|
||||
{
|
||||
mMusic->mBaseVolume = volumeFromType(mMusic->getPlayType());
|
||||
mMusic->setBaseVolume(volumeFromType(mMusic->getPlayType()));
|
||||
mMusic->update();
|
||||
}
|
||||
mOutput->finishUpdate();
|
||||
|
|
Loading…
Reference in a new issue