2015-11-22 12:53:24 +00:00
|
|
|
#ifndef GAME_SOUND_SOUND_BUFFER_H
|
|
|
|
#define GAME_SOUND_SOUND_BUFFER_H
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <deque>
|
2015-11-22 12:53:24 +00:00
|
|
|
#include <string>
|
2020-07-18 21:56:14 +00:00
|
|
|
#include <unordered_map>
|
2015-11-22 12:53:24 +00:00
|
|
|
|
2015-11-23 09:01:20 +00:00
|
|
|
#include "sound_output.hpp"
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
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!
2022-09-25 11:17:09 +00:00
|
|
|
#include <components/esm/refid.hpp>
|
2015-11-22 12:53:24 +00:00
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
struct Sound;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
class Manager;
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:53:24 +00:00
|
|
|
namespace MWSound
|
|
|
|
{
|
2020-07-18 21:56:14 +00:00
|
|
|
class SoundBufferPool;
|
|
|
|
|
2015-11-22 12:53:24 +00:00
|
|
|
class Sound_Buffer
|
|
|
|
{
|
2020-07-18 21:56:14 +00:00
|
|
|
public:
|
2021-01-09 13:07:30 +00:00
|
|
|
template <class T>
|
|
|
|
Sound_Buffer(T&& resname, float volume, float mindist, float maxdist)
|
|
|
|
: mResourceName(std::forward<T>(resname))
|
|
|
|
, mVolume(volume)
|
|
|
|
, mMinDist(mindist)
|
|
|
|
, mMaxDist(maxdist)
|
2020-07-18 21:56:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-02-22 22:44:12 +00:00
|
|
|
const VFS::Path::Normalized& getResourceName() const noexcept { return mResourceName; }
|
2020-07-18 21:56:14 +00:00
|
|
|
|
|
|
|
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:
|
2024-02-22 22:44:12 +00:00
|
|
|
VFS::Path::Normalized mResourceName;
|
2021-01-09 13:08:54 +00:00
|
|
|
float mVolume;
|
|
|
|
float mMinDist;
|
|
|
|
float mMaxDist;
|
2020-07-18 21:56:14 +00:00
|
|
|
Sound_Handle mHandle = nullptr;
|
|
|
|
std::size_t mUses = 0;
|
|
|
|
|
|
|
|
friend class SoundBufferPool;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SoundBufferPool
|
|
|
|
{
|
|
|
|
public:
|
2023-05-31 21:11:03 +00:00
|
|
|
SoundBufferPool(Sound_Output& output);
|
2020-07-18 21:56:14 +00:00
|
|
|
|
|
|
|
SoundBufferPool(const SoundBufferPool&) = delete;
|
|
|
|
|
|
|
|
~SoundBufferPool();
|
|
|
|
|
2021-01-09 13:11:49 +00:00
|
|
|
/// Lookup a soundId for its sound data (resource name, local volume,
|
|
|
|
/// minRange, and maxRange)
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
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!
2022-09-25 11:17:09 +00:00
|
|
|
Sound_Buffer* lookup(const ESM::RefId& soundId) const;
|
2020-07-18 21:56:14 +00:00
|
|
|
|
2023-07-19 13:21:17 +00:00
|
|
|
/// Lookup a sound by file name for its sound data (resource name, local volume,
|
|
|
|
/// minRange, and maxRange)
|
|
|
|
Sound_Buffer* lookup(std::string_view fileName) const;
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
/// Lookup a soundId for its sound data (resource name, local volume,
|
|
|
|
/// minRange, and maxRange), and ensure it's ready for use.
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
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!
2022-09-25 11:17:09 +00:00
|
|
|
Sound_Buffer* load(const ESM::RefId& soundId);
|
2020-07-18 21:56:14 +00:00
|
|
|
|
2023-07-19 13:21:17 +00:00
|
|
|
// Lookup for a sound by file name, and ensure it's ready for use.
|
|
|
|
Sound_Buffer* load(std::string_view fileName);
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
void use(Sound_Buffer& sfx)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-07-18 21:56:14 +00:00
|
|
|
if (sfx.mUses++ == 0)
|
|
|
|
{
|
|
|
|
const auto it = std::find(mUnusedBuffers.begin(), mUnusedBuffers.end(), &sfx);
|
|
|
|
if (it != mUnusedBuffers.end())
|
|
|
|
mUnusedBuffers.erase(it);
|
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
void release(Sound_Buffer& sfx)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2020-07-18 21:56:14 +00:00
|
|
|
if (--sfx.mUses == 0)
|
|
|
|
mUnusedBuffers.push_front(&sfx);
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
void clear();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
private:
|
2023-07-19 13:21:17 +00:00
|
|
|
Sound_Buffer* loadSfx(Sound_Buffer* sfx);
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
Sound_Output* mOutput;
|
|
|
|
std::deque<Sound_Buffer> mSoundBuffers;
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
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!
2022-09-25 11:17:09 +00:00
|
|
|
std::unordered_map<ESM::RefId, Sound_Buffer*> mBufferNameMap;
|
2023-08-19 09:46:20 +00:00
|
|
|
std::unordered_map<std::string, Sound_Buffer*> mBufferFileNameMap;
|
2020-07-18 21:56:14 +00:00
|
|
|
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;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
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!
2022-09-25 11:17:09 +00:00
|
|
|
inline Sound_Buffer* insertSound(const ESM::RefId& soundId, const ESM::Sound& sound);
|
2023-07-19 13:21:17 +00:00
|
|
|
inline Sound_Buffer* insertSound(std::string_view fileName);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
inline void unloadUnused();
|
2015-11-22 12:53:24 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GAME_SOUND_SOUND_BUFFER_H */
|