Rewritted ResourceLoader and moved it to core
Added creation constructor to NzImage Added member function functor Added option to build Nazara as one library (instead of many) Fixed some 2011 copyrights Made use of "using def = T" C++11 feature instead of some illigible typedefs Removed unused premake file
This commit is contained in:
@@ -9,11 +9,9 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
struct NzAnimationParams
|
||||
{
|
||||
@@ -33,13 +31,13 @@ struct NzSequence
|
||||
|
||||
class NzAnimation;
|
||||
|
||||
typedef NzResourceLoader<NzAnimation, NzAnimationParams> NzAnimationLoader;
|
||||
using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>;
|
||||
|
||||
struct NzAnimationImpl;
|
||||
|
||||
class NAZARA_API NzAnimation : public NzResource
|
||||
{
|
||||
friend class NzResourceLoader<NzAnimation, NzAnimationParams>;
|
||||
friend NzAnimationLoader;
|
||||
|
||||
public:
|
||||
NzAnimation() = default;
|
||||
@@ -73,9 +71,7 @@ class NAZARA_API NzAnimation : public NzResource
|
||||
private:
|
||||
NzAnimationImpl* m_impl = nullptr;
|
||||
|
||||
static std::list<NzAnimationLoader::MemoryLoader> s_memoryLoaders;
|
||||
static std::list<NzAnimationLoader::StreamLoader> s_streamLoaders;
|
||||
static std::multimap<NzString, NzAnimationLoader::LoadFileFunction> s_fileLoaders;
|
||||
static NzAnimationLoader::LoaderList s_loaders;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ANIMATION_HPP
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2011 Jérôme Leclercq
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
||||
@@ -13,16 +13,13 @@
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
class NzBufferImpl;
|
||||
class NzRenderer;
|
||||
class NzUtility;
|
||||
|
||||
class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
|
||||
{
|
||||
friend class NzRenderer;
|
||||
friend class NzUtility;
|
||||
|
||||
public:
|
||||
typedef NzBufferImpl* (*BufferFunction)(NzBuffer* parent, nzBufferType type);
|
||||
using BufferFunction = NzBufferImpl* (*)(NzBuffer* parent, nzBufferType type);
|
||||
|
||||
NzBuffer(nzBufferType type);
|
||||
NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
class NzCursorImpl;
|
||||
class NzImage;
|
||||
class NzWindowImpl;
|
||||
|
||||
class NAZARA_API NzCursor
|
||||
{
|
||||
|
||||
@@ -127,7 +127,7 @@ enum nzImageType
|
||||
|
||||
enum nzPixelFormat
|
||||
{
|
||||
nzPixelFormat_Undefined,
|
||||
nzPixelFormat_Undefined = -1,
|
||||
|
||||
nzPixelFormat_BGR8, // 3*nzUInt8
|
||||
nzPixelFormat_BGRA8, // 4*nzUInt8
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
class NzImage;
|
||||
class NzIconImpl;
|
||||
class NzWindowImpl;
|
||||
|
||||
class NAZARA_API NzIcon
|
||||
{
|
||||
|
||||
@@ -11,14 +11,12 @@
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
@@ -26,6 +24,8 @@
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
///TODO: Filtres
|
||||
|
||||
struct NzImageParams
|
||||
{
|
||||
nzPixelFormat loadFormat = nzPixelFormat_Undefined;
|
||||
@@ -34,20 +34,19 @@ struct NzImageParams
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
///TODO: Filtres
|
||||
|
||||
class NzImage;
|
||||
|
||||
typedef NzResourceLoader<NzImage, NzImageParams> NzImageLoader;
|
||||
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
|
||||
|
||||
class NAZARA_API NzImage : public NzResource
|
||||
{
|
||||
friend class NzResourceLoader<NzImage, NzImageParams>;
|
||||
friend NzImageLoader;
|
||||
|
||||
public:
|
||||
struct SharedImage;
|
||||
|
||||
NzImage();
|
||||
NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
|
||||
NzImage(const NzImage& image);
|
||||
NzImage(NzImage&& image) noexcept;
|
||||
NzImage(SharedImage* sharedImage);
|
||||
@@ -135,9 +134,7 @@ class NAZARA_API NzImage : public NzResource
|
||||
|
||||
SharedImage* m_sharedImage;
|
||||
|
||||
static std::list<NzImageLoader::MemoryLoader> s_memoryLoaders;
|
||||
static std::list<NzImageLoader::StreamLoader> s_streamLoaders;
|
||||
static std::multimap<NzString, NzImageLoader::LoadFileFunction> s_fileLoaders;
|
||||
static NzImageLoader::LoaderList s_loaders;
|
||||
};
|
||||
|
||||
#endif // NAZARA_IMAGE_HPP
|
||||
|
||||
@@ -10,13 +10,11 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
class NzVertexDeclaration;
|
||||
|
||||
@@ -32,13 +30,13 @@ struct NzMeshParams
|
||||
|
||||
class NzMesh;
|
||||
|
||||
typedef NzResourceLoader<NzMesh, NzMeshParams> NzMeshLoader;
|
||||
using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>;
|
||||
|
||||
struct NzMeshImpl;
|
||||
|
||||
class NAZARA_API NzMesh : public NzResource
|
||||
{
|
||||
friend class NzResourceLoader<NzMesh, NzMeshParams>;
|
||||
friend NzMeshLoader;
|
||||
|
||||
public:
|
||||
NzMesh() = default;
|
||||
@@ -89,9 +87,7 @@ class NAZARA_API NzMesh : public NzResource
|
||||
private:
|
||||
NzMeshImpl* m_impl = nullptr;
|
||||
|
||||
static std::list<NzMeshLoader::MemoryLoader> s_memoryLoaders;
|
||||
static std::list<NzMeshLoader::StreamLoader> s_streamLoaders;
|
||||
static std::multimap<NzString, NzMeshLoader::LoadFileFunction> s_fileLoaders;
|
||||
static NzMeshLoader::LoaderList s_loaders;
|
||||
};
|
||||
|
||||
#endif // NAZARA_MESH_HPP
|
||||
|
||||
@@ -19,8 +19,8 @@ class NzPixelFormat
|
||||
friend class NzUtility;
|
||||
|
||||
public:
|
||||
typedef nzUInt8* (*ConvertFunction)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst);
|
||||
typedef void (*FlipFunction)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst);
|
||||
using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst);
|
||||
using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst);
|
||||
|
||||
static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst);
|
||||
static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RESOURCELOADER_HPP
|
||||
#define NAZARA_RESOURCELOADER_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <utility>
|
||||
|
||||
class NzInputStream;
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
class NzResourceLoader
|
||||
{
|
||||
public:
|
||||
using IdentifyMemoryFunction = bool (*)(const void* data, unsigned int size, const Parameters& parameters);
|
||||
using IdentifyStreamFunction = bool (*)(NzInputStream& stream, const Parameters& parameters);
|
||||
using LoadFileFunction = bool (*)(Type* resource, const NzString& filePath, const Parameters& parameters);
|
||||
using LoadMemoryFunction = bool (*)(Type* resource, const void* data, unsigned int size, const Parameters& parameters);
|
||||
using LoadStreamFunction = bool (*)(Type* resource, NzInputStream& stream, const Parameters& parameters);
|
||||
|
||||
static bool LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters = Parameters());
|
||||
static bool LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters = Parameters());
|
||||
static bool LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters = Parameters());
|
||||
|
||||
static void RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
|
||||
static void RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory);
|
||||
static void RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream);
|
||||
|
||||
static void UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
|
||||
static void UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory);
|
||||
static void UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream);
|
||||
|
||||
typedef std::pair<IdentifyMemoryFunction, LoadMemoryFunction> MemoryLoader;
|
||||
typedef std::pair<IdentifyStreamFunction, LoadStreamFunction> StreamLoader;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/ResourceLoader.inl>
|
||||
|
||||
#endif // NAZARA_RESOURCELOADER_HPP
|
||||
@@ -1,187 +0,0 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString path = NzFile::NormalizePath(filePath);
|
||||
NzString ext = path.SubstrFrom('.', -1, true);
|
||||
if (ext.IsEmpty())
|
||||
{
|
||||
NazaraError("Failed to get file extension");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Récupération de tous les loaders de cette extension
|
||||
auto range = Type::s_fileLoaders.equal_range(ext);
|
||||
if (range.first == range.second)
|
||||
{
|
||||
NazaraError("No loader found for extension \"" + ext + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
// range.second est un itérateur vers l'élément après le dernier élémént du range
|
||||
auto it = range.second;
|
||||
|
||||
do
|
||||
{
|
||||
it--;
|
||||
|
||||
// Chargement de la ressource
|
||||
if (it->second(resource, filePath, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
while (it != range.first);
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data || size == 0)
|
||||
{
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto loader = Type::s_memoryLoaders.rbegin(); loader != Type::s_memoryLoaders.rend(); ++loader)
|
||||
{
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!loader->first(data, size, parameters))
|
||||
continue;
|
||||
|
||||
// Chargement de la ressource
|
||||
if (loader->second(resource, data, size, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize())
|
||||
{
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
nzUInt64 streamPos = stream.GetCursorPos();
|
||||
for (auto loader = Type::s_streamLoaders.rbegin(); loader != Type::s_streamLoaders.rend(); ++loader)
|
||||
{
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!loader->first(stream, parameters))
|
||||
continue;
|
||||
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Chargement de la ressource
|
||||
if (loader->second(resource, stream, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
|
||||
{
|
||||
std::vector<NzString> exts;
|
||||
extensions.SplitAny(exts, " /\\*.,;|-_");
|
||||
|
||||
for (const NzString& ext : exts)
|
||||
Type::s_fileLoaders.insert(std::make_pair(ext, loadFile));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
Type::s_memoryLoaders.push_back(std::make_pair(identifyMemory, loadMemory));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream)
|
||||
{
|
||||
Type::s_streamLoaders.push_back(std::make_pair(identifyStream, loadStream));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
|
||||
{
|
||||
std::vector<NzString> exts;
|
||||
extensions.SplitAny(exts, " /\\*.,;|-_");
|
||||
|
||||
for (const NzString& ext : exts)
|
||||
{
|
||||
// Récupération de tous les loaders de cette extension
|
||||
auto range = Type::s_fileLoaders.equal_range(ext);
|
||||
|
||||
for (auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
if (it->second == loadFile)
|
||||
{
|
||||
Type::s_fileLoaders.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
Type::s_memoryLoaders.remove(std::make_pair(identifyMemory, loadMemory));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream)
|
||||
{
|
||||
Type::s_streamLoaders.remove(std::make_pair(identifyStream, loadStream));
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
@@ -28,15 +28,13 @@
|
||||
class NzCursor;
|
||||
class NzImage;
|
||||
class NzIcon;
|
||||
class NzMouse;
|
||||
class NzUtility;
|
||||
class NzWindowImpl;
|
||||
|
||||
class NAZARA_API NzWindow : NzNonCopyable
|
||||
{
|
||||
friend NzWindowImpl;
|
||||
friend class NzMouse;
|
||||
friend class NzUtility;
|
||||
friend class NzWindowImpl;
|
||||
|
||||
public:
|
||||
NzWindow();
|
||||
|
||||
Reference in New Issue
Block a user