mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-01 03:21:41 +00:00
125b21de20
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
112 lines
2.8 KiB
C++
112 lines
2.8 KiB
C++
#ifndef GAME_SOUND_SOUND_BUFFER_H
|
|
#define GAME_SOUND_SOUND_BUFFER_H
|
|
|
|
#include <algorithm>
|
|
#include <deque>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include "sound_output.hpp"
|
|
#include <components/esm/refid.hpp>
|
|
|
|
namespace ESM
|
|
{
|
|
struct Sound;
|
|
}
|
|
|
|
namespace VFS
|
|
{
|
|
class Manager;
|
|
}
|
|
|
|
namespace MWSound
|
|
{
|
|
class SoundBufferPool;
|
|
|
|
class Sound_Buffer
|
|
{
|
|
public:
|
|
template <class T>
|
|
Sound_Buffer(T&& resname, float volume, float mindist, float maxdist)
|
|
: mResourceName(std::forward<T>(resname))
|
|
, mVolume(volume)
|
|
, mMinDist(mindist)
|
|
, mMaxDist(maxdist)
|
|
{
|
|
}
|
|
|
|
const std::string& getResourceName() const noexcept { return mResourceName; }
|
|
|
|
Sound_Handle getHandle() const noexcept { return mHandle; }
|
|
|
|
float getVolume() const noexcept { return mVolume; }
|
|
|
|
float getMinDist() const noexcept { return mMinDist; }
|
|
|
|
float getMaxDist() const noexcept { return mMaxDist; }
|
|
|
|
private:
|
|
std::string mResourceName;
|
|
float mVolume;
|
|
float mMinDist;
|
|
float mMaxDist;
|
|
Sound_Handle mHandle = nullptr;
|
|
std::size_t mUses = 0;
|
|
|
|
friend class SoundBufferPool;
|
|
};
|
|
|
|
class SoundBufferPool
|
|
{
|
|
public:
|
|
SoundBufferPool(const VFS::Manager& vfs, Sound_Output& output);
|
|
|
|
SoundBufferPool(const SoundBufferPool&) = delete;
|
|
|
|
~SoundBufferPool();
|
|
|
|
/// Lookup a soundId for its sound data (resource name, local volume,
|
|
/// minRange, and maxRange)
|
|
Sound_Buffer* lookup(const ESM::RefId& soundId) const;
|
|
|
|
/// Lookup a soundId for its sound data (resource name, local volume,
|
|
/// minRange, and maxRange), and ensure it's ready for use.
|
|
Sound_Buffer* load(const ESM::RefId& soundId);
|
|
|
|
void use(Sound_Buffer& sfx)
|
|
{
|
|
if (sfx.mUses++ == 0)
|
|
{
|
|
const auto it = std::find(mUnusedBuffers.begin(), mUnusedBuffers.end(), &sfx);
|
|
if (it != mUnusedBuffers.end())
|
|
mUnusedBuffers.erase(it);
|
|
}
|
|
}
|
|
|
|
void release(Sound_Buffer& sfx)
|
|
{
|
|
if (--sfx.mUses == 0)
|
|
mUnusedBuffers.push_front(&sfx);
|
|
}
|
|
|
|
void clear();
|
|
|
|
private:
|
|
const VFS::Manager* const mVfs;
|
|
Sound_Output* mOutput;
|
|
std::deque<Sound_Buffer> mSoundBuffers;
|
|
std::unordered_map<ESM::RefId, Sound_Buffer*> mBufferNameMap;
|
|
std::size_t mBufferCacheMax;
|
|
std::size_t mBufferCacheMin;
|
|
std::size_t mBufferCacheSize = 0;
|
|
// NOTE: unused buffers are stored in front-newest order.
|
|
std::deque<Sound_Buffer*> mUnusedBuffers;
|
|
|
|
inline Sound_Buffer* insertSound(const ESM::RefId& soundId, const ESM::Sound& sound);
|
|
|
|
inline void unloadUnused();
|
|
};
|
|
}
|
|
|
|
#endif /* GAME_SOUND_SOUND_BUFFER_H */
|