Refactor the way resources are loaded (#191)

* WIP

* WIP

* Font works

* WIP: Only Music remains

* Looks like it's working

* Fix oopsie

* Core/ObjectRef: Add cast functions

* Update ChangeLog.md

* Audio/SoundStream: Make sound stream thread-safe
This commit is contained in:
Jérôme Leclercq
2018-10-28 01:53:11 +02:00
committed by GitHub
parent fa7cbc21e5
commit ed46c87781
64 changed files with 1058 additions and 1071 deletions

View File

@@ -10,31 +10,15 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/SoundEmitter.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
namespace Nz
{
struct MusicParams : ResourceParameters
{
bool forceMono = false;
bool IsValid() const;
};
class Music;
class SoundStream;
using MusicLoader = ResourceLoader<Music, MusicParams>;
struct MusicImpl;
class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
{
friend MusicLoader;
public:
Music() = default;
Music(const Music&) = delete;
@@ -55,9 +39,9 @@ namespace Nz
bool IsLooping() const override;
bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
bool OpenFromStream(Stream& stream, const MusicParams& params = MusicParams());
bool OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());
void Pause() override;
void Play() override;
@@ -75,8 +59,6 @@ namespace Nz
bool FillAndQueueBuffer(unsigned int buffer);
void MusicThread();
void StopThread();
static MusicLoader::LoaderList s_loaders;
};
}

View File

@@ -66,16 +66,17 @@ namespace Nz
bool IsValid() const;
bool LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
static bool IsFormatSupported(AudioFormat format);
template<typename... Args> static SoundBufferRef New(Args&&... args);
SoundBuffer& operator=(const SoundBuffer&) = delete;
SoundBuffer& operator=(SoundBuffer&&) = delete;
static bool IsFormatSupported(AudioFormat format);
static SoundBufferRef LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
static SoundBufferRef LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
static SoundBufferRef LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
template<typename... Args> static SoundBufferRef New(Args&&... args);
// Signals:
NazaraSignal(OnSoundBufferDestroy, const SoundBuffer* /*soundBuffer*/);
NazaraSignal(OnSoundBufferRelease, const SoundBuffer* /*soundBuffer*/);

View File

@@ -10,22 +10,50 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
namespace Nz
{
class NAZARA_AUDIO_API SoundStream
struct SoundStreamParams : public ResourceParameters
{
bool forceMono = false;
bool IsValid() const;
};
class Mutex;
class SoundStream;
using SoundStreamLoader = ResourceLoader<SoundStream, SoundStreamParams>;
using SoundStreamRef = Nz::ObjectRef<SoundStream>;
class NAZARA_AUDIO_API SoundStream : public RefCounted, public Resource
{
friend SoundStreamLoader;
public:
SoundStream() = default;
virtual ~SoundStream();
virtual UInt32 GetDuration() const = 0;
virtual AudioFormat GetFormat() const = 0;
virtual Mutex& GetMutex() = 0;
virtual UInt64 GetSampleCount() const = 0;
virtual UInt32 GetSampleRate() const = 0;
virtual UInt64 Read(void* buffer, UInt64 sampleCount) = 0;
virtual void Seek(UInt64 offset) = 0;
virtual UInt64 Tell() = 0;
static SoundStreamRef OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
static SoundStreamRef OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
static SoundStreamRef OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());
private:
static SoundStreamLoader::LoaderList s_loaders;
};
}