1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 20:19:56 +00:00
openmw-tes3mp/apps/openmw/mwsound/soundmanagerimp.hpp

258 lines
9.3 KiB
C++
Raw Normal View History

#ifndef GAME_SOUND_SOUNDMANAGER_H
#define GAME_SOUND_SOUNDMANAGER_H
#include <memory>
#include <string>
#include <utility>
#include <map>
2017-08-25 20:08:49 +00:00
#include <unordered_map>
2012-05-24 02:34:53 +00:00
#include <components/settings/settings.hpp>
#include <components/misc/objectpool.hpp>
2016-11-27 20:19:52 +00:00
#include <components/fallback/fallback.hpp>
#include "../mwbase/soundmanager.hpp"
#include "regionsoundselector.hpp"
#include "watersoundupdater.hpp"
2020-07-01 16:37:31 +00:00
#include "type.hpp"
#include "volumesettings.hpp"
#include "sound_buffer.hpp"
2015-04-13 20:48:37 +00:00
namespace VFS
{
class Manager;
}
namespace ESM
{
struct Sound;
struct Cell;
}
namespace MWSound
{
class Sound_Output;
struct Sound_Decoder;
2012-03-17 09:45:18 +00:00
class Sound;
class Stream;
2020-06-28 16:25:23 +00:00
using SoundPtr = Misc::ObjectPtr<Sound>;
using StreamPtr = Misc::ObjectPtr<Stream>;
class SoundManager : public MWBase::SoundManager
{
2015-04-13 20:48:37 +00:00
const VFS::Manager* mVFS;
std::unique_ptr<Sound_Output> mOutput;
// Caches available music tracks by <playlist name, (sound files) >
std::unordered_map<std::string, std::vector<std::string>> mMusicFiles;
2017-08-25 20:08:49 +00:00
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
std::string mLastPlayedMusic; // The music file that was last played
2020-07-01 16:37:31 +00:00
VolumeSettings mVolumeSettings;
2012-04-07 23:00:30 +00:00
WaterSoundUpdater mWaterSoundUpdater;
SoundBufferPool mSoundBuffers;
2015-11-23 14:35:01 +00:00
Misc::ObjectPool<Sound> mSounds;
Misc::ObjectPool<Stream> mStreams;
2020-06-28 16:25:23 +00:00
typedef std::pair<SoundPtr, Sound_Buffer*> SoundBufferRefPair;
typedef std::vector<SoundBufferRefPair> SoundBufferRefPairList;
2015-12-18 17:11:30 +00:00
typedef std::map<MWWorld::ConstPtr,SoundBufferRefPairList> SoundMap;
SoundMap mActiveSounds;
2012-03-17 15:02:46 +00:00
2020-06-28 16:25:23 +00:00
typedef std::map<MWWorld::ConstPtr, StreamPtr> SaySoundMap;
SaySoundMap mSaySoundsQueue;
SaySoundMap mActiveSaySounds;
2020-06-28 16:25:23 +00:00
typedef std::vector<StreamPtr> TrackList;
2015-12-01 19:28:37 +00:00
TrackList mActiveTracks;
2020-06-28 16:25:23 +00:00
StreamPtr mMusic;
2015-12-01 19:28:37 +00:00
std::string mCurrentPlaylist;
bool mListenerUnderwater;
2015-05-12 17:02:56 +00:00
osg::Vec3f mListenerPos;
osg::Vec3f mListenerDir;
osg::Vec3f mListenerUp;
int mPausedSoundTypes[BlockerType::MaxCount] = {};
Sound *mUnderwaterSound;
Sound *mNearWaterSound;
2015-12-01 19:28:37 +00:00
std::string mNextMusic;
bool mPlaybackPaused;
RegionSoundSelector mRegionSoundSelector;
2020-10-28 14:02:31 +00:00
float mTimePassed;
2020-06-28 11:49:05 +00:00
2020-10-28 14:02:31 +00:00
const ESM::Cell *mLastCell;
2020-10-25 11:20:14 +00:00
Sound* mCurrentRegionSound;
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
Sound_Buffer *lookupSound(const std::string &soundId) const;
Sound_Buffer *loadSound(const std::string &soundId);
// returns a decoder to start streaming, or nullptr if the sound was not found
DecoderPtr loadVoice(const std::string &voicefile);
2020-06-28 16:25:23 +00:00
SoundPtr getSoundRef();
StreamPtr getStreamRef();
2020-06-28 16:25:23 +00:00
StreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal);
2012-03-20 19:39:49 +00:00
void streamMusicFull(const std::string& filename);
2017-08-06 18:10:56 +00:00
void advanceMusic(const std::string& filename);
void startRandomTitle();
2017-08-06 18:10:56 +00:00
void updateSounds(float duration);
void updateRegionSound(float duration);
void updateWaterSound();
2017-08-06 18:10:56 +00:00
void updateMusic(float duration);
float volumeFromType(Type type) const;
enum class WaterSoundAction
{
DoNothing,
SetVolume,
FinishSound,
PlaySound,
};
std::pair<WaterSoundAction, Sound_Buffer*> getWaterSoundAction(const WaterSoundUpdate& update,
const ESM::Cell* cell) const;
SoundManager(const SoundManager &rhs);
SoundManager& operator=(const SoundManager &rhs);
protected:
DecoderPtr getDecoder();
friend class OpenAL_Output;
2018-05-07 16:40:53 +00:00
void stopSound(Sound_Buffer *sfx, const MWWorld::ConstPtr &ptr);
///< Stop the given object from playing given sound buffer.
public:
SoundManager(const VFS::Manager* vfs, bool useSound);
virtual ~SoundManager();
void processChangedSettings(const Settings::CategorySettingVector& settings) override;
2012-05-24 02:34:53 +00:00
void stopMusic() override;
///< Stops music if it's playing
void streamMusic(const std::string& filename) override;
///< Play a soundifle
/// \param filename name of a sound file in "Music/" in the data directory.
bool isMusicPlaying() override;
///< Returns true if music is playing
2011-06-12 00:01:21 +00:00
void playPlaylist(const std::string &playlist) override;
///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist
void playTitleMusic() override;
2019-03-03 22:31:51 +00:00
///< Start playing title music
void say(const MWWorld::ConstPtr &reference, const std::string& filename) override;
///< Make an actor say some text.
/// \param filename name of a sound file in "Sound/" in the data directory.
2011-06-15 20:33:31 +00:00
void say(const std::string& filename) override;
///< Say some text, without an actor ref
/// \param filename name of a sound file in "Sound/" in the data directory.
bool sayActive(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const override;
///< Is actor not speaking?
2011-06-15 20:33:31 +00:00
bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const override;
///< For scripting backward compatibility
void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) override;
///< Stop an actor speaking
float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const override;
///< Check the currently playing say sound for this actor
/// and get an average loudness value (scale [0,1]) at the current time position.
/// If the actor is not saying anything, returns 0.
Stream *playTrack(const DecoderPtr& decoder, Type type) override;
///< Play a 2D audio track, using a custom decoder
void stopTrack(Stream *stream) override;
///< Stop the given audio track from playing
double getTrackTimeDelay(Stream *stream) override;
///< Retives the time delay, in seconds, of the audio track (must be a sound
/// returned by \ref playTrack). Only intended to be called by the track
/// decoder's read method.
Sound *playSound(const std::string& soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) override;
///< Play a sound, independently of 3D-position
///< @param offset Number of seconds into the sound to start playback.
2010-10-31 16:23:03 +00:00
Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
float volume, float pitch, Type type=Type::Sfx,
PlayMode mode=PlayMode::Normal, float offset=0) override;
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
///< @param offset Number of seconds into the sound to start playback.
Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
float volume, float pitch, Type type, PlayMode mode, float offset=0) override;
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
///< @param offset Number of seconds into the sound to start playback.
void stopSound(Sound *sound) override;
///< Stop the given sound from playing
2015-12-05 00:54:16 +00:00
/// @note no-op if \a sound is null
void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) override;
///< Stop the given object from playing the given sound,
void stopSound3D(const MWWorld::ConstPtr &reference) override;
///< Stop the given object from playing all sounds.
void stopSound(const MWWorld::CellStore *cell) override;
///< Stop all sounds for the given cell.
2010-08-14 05:54:51 +00:00
void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) override;
///< Fade out given sound (that is already playing) of given object
///< @param reference Reference to object, whose sound is faded out
///< @param soundId ID of the sound to fade out.
///< @param duration Time until volume reaches 0.
bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const override;
///< Is the given sound currently playing on the given object?
2010-08-14 05:54:51 +00:00
void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) override;
///< Pauses all currently playing sounds, including music.
void resumeSounds(MWSound::BlockerType blocker) override;
///< Resumes all previously paused sounds.
void pausePlayback() override;
void resumePlayback() override;
void update(float duration) override;
void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) override;
void updatePtr (const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated) override;
void clear() override;
};
}
#endif