1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 21:40:03 +00:00

64 lines
1.9 KiB
C++
Raw Normal View History

2012-03-17 02:45:18 -07:00
#ifndef GAME_SOUND_SOUND_H
#define GAME_SOUND_SOUND_H
#include "soundmanagerimp.hpp"
2012-03-17 02:45:18 -07:00
namespace MWSound
{
class Sound
{
Sound& operator=(const Sound &rhs);
Sound(const Sound &rhs);
protected:
2015-05-12 19:02:56 +02:00
osg::Vec3f mPos;
float mVolume; /* NOTE: Real volume = mVolume*mBaseVolume */
float mBaseVolume;
2012-03-31 10:41:12 -07:00
float mPitch;
float mMinDistance;
float mMaxDistance;
int mFlags;
2015-11-26 09:11:52 -08:00
float mFadeOutTime;
2012-03-17 02:45:18 -07:00
public:
virtual void stop() = 0;
virtual bool isPlaying() = 0;
virtual double getTimeOffset() = 0;
virtual double getStreamDelay() const { return 0.0; }
virtual void applyUpdates() = 0;
2015-05-12 19:02:56 +02:00
void setPosition(const osg::Vec3f &pos) { mPos = pos; }
void setVolume(float volume) { mVolume = volume; }
2015-11-26 09:11:52 -08:00
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); }
2015-11-26 09:11:52 -08:00
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
2015-11-26 09:33:16 -08:00
bool getIs3D() const { return mFlags&Play_3D; }
2015-05-12 19:02:56 +02:00
Sound(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
: mPos(pos)
, mVolume(vol)
, mBaseVolume(basevol)
, mPitch(pitch)
, mMinDistance(mindist)
, mMaxDistance(maxdist)
, mFlags(flags)
2015-11-26 09:11:52 -08:00
, mFadeOutTime(0.0f)
{ }
2012-03-17 02:45:18 -07:00
virtual ~Sound() { }
};
}
#endif