56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
#ifndef GAME_SOUND_WARMQUEUE_H
|
|
#define GAME_SOUND_WARMQUEUE_H
|
|
|
|
#include <condition_variable>
|
|
#include <functional>
|
|
#include <list>
|
|
#include <mutex>
|
|
#include <thread>
|
|
#include <unordered_map>
|
|
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
namespace VFS
|
|
{
|
|
class Manager;
|
|
}
|
|
|
|
namespace MWSound
|
|
{
|
|
class HeadCache;
|
|
|
|
// Warms likely sounds off the frame thread.
|
|
class WarmQueue
|
|
{
|
|
public:
|
|
WarmQueue(const VFS::Manager& vfs, HeadCache& cache);
|
|
~WarmQueue();
|
|
|
|
void enqueue(VFS::Path::Normalized path, bool urgent = false);
|
|
|
|
void enqueueStreamed(VFS::Path::Normalized path);
|
|
|
|
private:
|
|
struct Item
|
|
{
|
|
VFS::Path::Normalized mPath;
|
|
bool mUrgent;
|
|
bool mWholeFile;
|
|
};
|
|
|
|
void push(VFS::Path::Normalized path, bool urgent, bool wholeFile);
|
|
void run() noexcept;
|
|
|
|
const VFS::Manager& mVfs;
|
|
HeadCache& mCache;
|
|
std::mutex mMutex;
|
|
std::condition_variable mCV;
|
|
std::list<Item> mQueue;
|
|
std::unordered_map<VFS::Path::Normalized, std::list<Item>::iterator, VFS::Path::Hash, std::equal_to<>> mQueued;
|
|
bool mQuit = false;
|
|
std::thread mThread;
|
|
};
|
|
}
|
|
|
|
#endif
|