Core: Rewrite plugin system

This commit is contained in:
SirLynix
2022-08-18 23:23:00 +02:00
committed by Jérôme Leclercq
parent d7ad5cc846
commit 3a366cc1e4
22 changed files with 596 additions and 434 deletions

View File

@@ -40,6 +40,7 @@ SOFTWARE.
#include <Nazara/Utility/StaticMesh.hpp>
#include <Nazara/Utility/VertexMapper.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/Plugins/AssimpPlugin.hpp>
#include <assimp/cfileio.h>
#include <assimp/cimport.h>
#include <assimp/config.h>
@@ -888,49 +889,80 @@ std::shared_ptr<Nz::Mesh> LoadMesh(Nz::Stream& stream, const Nz::MeshParams& par
namespace
{
const Nz::AnimationLoader::Entry* animationLoaderEntry = nullptr;
const Nz::MeshLoader::Entry* meshLoaderEntry = nullptr;
class AssimpPluginImpl final : public Nz::AssimpPlugin
{
public:
bool Activate() override
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::AnimationLoader& animationLoader = utility->GetAnimationLoader();
m_animationLoaderEntry = animationLoader.RegisterLoader({
IsSupported,
nullptr,
nullptr,
CheckAnimation,
LoadAnimation
});
Nz::MeshLoader& meshLoader = utility->GetMeshLoader();
m_meshLoaderEntry = meshLoader.RegisterLoader({
IsSupported,
nullptr,
nullptr,
CheckMesh,
LoadMesh
});
return true;
}
void Deactivate() override
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::AnimationLoader& animationLoader = utility->GetAnimationLoader();
animationLoader.UnregisterLoader(m_animationLoaderEntry);
Nz::MeshLoader& meshLoader = utility->GetMeshLoader();
meshLoader.UnregisterLoader(m_meshLoaderEntry);
}
std::string_view GetDescription() const
{
return "Adds supports to load meshes and animations using Assimp";
}
std::string_view GetName() const override
{
return "Assimp loader";
}
Nz::UInt32 GetVersion() const override
{
return 100;
}
private:
const Nz::AnimationLoader::Entry* m_animationLoaderEntry = nullptr;
const Nz::MeshLoader::Entry* m_meshLoaderEntry = nullptr;
};
}
extern "C"
{
NAZARA_EXPORT int PluginLoad()
NAZARA_EXPORT Nz::PluginInterface* PluginLoad()
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
if (!utility)
{
NazaraError("Utility module must be initialized");
return nullptr;
}
Nz::AnimationLoader& animationLoader = utility->GetAnimationLoader();
animationLoaderEntry = animationLoader.RegisterLoader({
IsSupported,
nullptr,
nullptr,
CheckAnimation,
LoadAnimation
});
Nz::MeshLoader& meshLoader = utility->GetMeshLoader();
meshLoaderEntry = meshLoader.RegisterLoader({
IsSupported,
nullptr,
nullptr,
CheckMesh,
LoadMesh
});
return 1;
}
NAZARA_EXPORT void PluginUnload()
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::AnimationLoader& animationLoader = utility->GetAnimationLoader();
animationLoader.UnregisterLoader(animationLoaderEntry);
animationLoaderEntry = nullptr;
Nz::MeshLoader& meshLoader = utility->GetMeshLoader();
meshLoader.UnregisterLoader(meshLoaderEntry);
meshLoaderEntry = nullptr;
std::unique_ptr<AssimpPluginImpl> plugin = std::make_unique<AssimpPluginImpl>();
return plugin.release();
}
}

View File

@@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with thi
#include <Nazara/Core/ByteStream.hpp>
#include <Nazara/Utility/ImageStream.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/Plugins/FFmpegPlugin.hpp>
extern "C"
{
@@ -28,8 +29,6 @@ extern "C"
namespace
{
const Nz::ImageStreamLoader::Entry* ffmpegLoaderEntry = nullptr;
class FFmpegStream : public Nz::ImageStream
{
public:
@@ -448,35 +447,70 @@ namespace
return ffmpegStream;
}
class FFmpegPluginImpl final : public Nz::FFmpegPlugin
{
public:
bool Activate() override
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::ImageStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = CheckVideoExtension;
loaderEntry.streamChecker = CheckVideo;
loaderEntry.fileLoader = LoadFile;
loaderEntry.memoryLoader = LoadMemory;
loaderEntry.streamLoader = LoadStream;
Nz::ImageStreamLoader& imageStreamLoader = utility->GetImageStreamLoader();
m_ffmpegLoaderEntry = imageStreamLoader.RegisterLoader(loaderEntry);
return true;
}
void Deactivate() override
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::ImageStreamLoader& imageStreamLoader = utility->GetImageStreamLoader();
imageStreamLoader.UnregisterLoader(m_ffmpegLoaderEntry);
m_ffmpegLoaderEntry = nullptr;
}
std::string_view GetDescription() const
{
return "Adds supports to load and decode videos streams";
}
std::string_view GetName() const override
{
return "FFMpeg loader";
}
Nz::UInt32 GetVersion() const override
{
return 100;
}
private:
const Nz::ImageStreamLoader::Entry* m_ffmpegLoaderEntry = nullptr;
};
}
extern "C"
{
NAZARA_EXPORT int PluginLoad()
NAZARA_EXPORT Nz::PluginInterface* PluginLoad()
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
if (!utility)
{
NazaraError("Utility module must be initialized");
return nullptr;
}
Nz::ImageStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = CheckVideoExtension;
loaderEntry.streamChecker = CheckVideo;
loaderEntry.fileLoader = LoadFile;
loaderEntry.memoryLoader = LoadMemory;
loaderEntry.streamLoader = LoadStream;
Nz::ImageStreamLoader& imageStreamLoader = utility->GetImageStreamLoader();
ffmpegLoaderEntry = imageStreamLoader.RegisterLoader(loaderEntry);
return 1;
}
NAZARA_EXPORT void PluginUnload()
{
Nz::Utility* utility = Nz::Utility::Instance();
NazaraAssert(utility, "utility module is not instancied");
Nz::ImageStreamLoader& imageStreamLoader = utility->GetImageStreamLoader();
imageStreamLoader.UnregisterLoader(ffmpegLoaderEntry);
ffmpegLoaderEntry = nullptr;
std::unique_ptr<FFmpegPluginImpl> plugin = std::make_unique<FFmpegPluginImpl>();
return plugin.release();
}
}