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:
@@ -22,7 +22,7 @@ typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction
|
||||
|
||||
class NzDynLib : NzNonCopyable
|
||||
{
|
||||
friend class NzDynLibImpl;
|
||||
friend NzDynLibImpl;
|
||||
|
||||
public:
|
||||
NzDynLib(const NzString& libraryPath);
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
|
||||
enum nzEndianness
|
||||
{
|
||||
nzEndianness_Unknown = -1,
|
||||
|
||||
nzEndianness_BigEndian,
|
||||
nzEndianness_LittleEndian,
|
||||
nzEndianness_Unknown
|
||||
nzEndianness_LittleEndian
|
||||
};
|
||||
|
||||
enum nzErrorType
|
||||
|
||||
@@ -38,11 +38,11 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
|
||||
{
|
||||
Current = 0x00, // Utilise le mode d'ouverture actuel
|
||||
|
||||
Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
ReadOnly = 0x04, // Ouvre uniquement en lecture
|
||||
ReadWrite = 0x08, // Ouvre en lecture/écriture
|
||||
Text = 0x10, // Ouvre en mode texte
|
||||
Text = 0x10, // Ouvre en mode texte
|
||||
Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
|
||||
WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
|
||||
};
|
||||
|
||||
@@ -18,27 +18,40 @@ struct NzFunctor
|
||||
virtual void Run() = 0;
|
||||
};
|
||||
|
||||
template<typename F> struct NzFunctorWithoutArgs : NzFunctor
|
||||
template<typename F>
|
||||
struct NzFunctorWithoutArgs : NzFunctor
|
||||
{
|
||||
NzFunctorWithoutArgs(F func);
|
||||
|
||||
void Run();
|
||||
|
||||
F function;
|
||||
private:
|
||||
F m_func;
|
||||
};
|
||||
|
||||
template<typename F, typename... Args> struct NzFunctorWithArgs : NzFunctor
|
||||
template<typename F, typename... Args>
|
||||
struct NzFunctorWithArgs : NzFunctor
|
||||
{
|
||||
NzFunctorWithArgs(F func, Args&... args);
|
||||
|
||||
void Run();
|
||||
|
||||
F function;
|
||||
std::tuple<Args...> arguments;
|
||||
private:
|
||||
F m_func;
|
||||
std::tuple<Args...> m_args;
|
||||
};
|
||||
|
||||
template<typename F> struct NzFunctorWithoutArgs;
|
||||
template<typename F, typename... Args> struct NzFunctorWithArgs;
|
||||
template<typename C>
|
||||
struct NzMemberWithoutArgs : NzFunctor
|
||||
{
|
||||
NzMemberWithoutArgs(void (C::*func)(), C* object);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
void (C::*m_func)();
|
||||
C* m_object;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/Functor.inl>
|
||||
|
||||
|
||||
@@ -2,23 +2,41 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
template<typename F> NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) :
|
||||
function(func)
|
||||
template<typename F>
|
||||
NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) :
|
||||
m_func(func)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename F> void NzFunctorWithoutArgs<F>::Run()
|
||||
template<typename F>
|
||||
void NzFunctorWithoutArgs<F>::Run()
|
||||
{
|
||||
function();
|
||||
m_func();
|
||||
}
|
||||
|
||||
template<typename F, typename... Args> NzFunctorWithArgs<F, Args...>::NzFunctorWithArgs(F func, Args&... args) :
|
||||
function(func),
|
||||
arguments(args...)
|
||||
template<typename F, typename... Args>
|
||||
NzFunctorWithArgs<F, Args...>::NzFunctorWithArgs(F func, Args&... args) :
|
||||
m_func(func),
|
||||
m_args(args...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename F, typename... Args> void NzFunctorWithArgs<F, Args...>::Run()
|
||||
template<typename F, typename... Args>
|
||||
void NzFunctorWithArgs<F, Args...>::Run()
|
||||
{
|
||||
NzUnpackTuple(function, arguments);
|
||||
NzUnpackTuple(m_func, m_args);
|
||||
}
|
||||
|
||||
|
||||
template<typename C>
|
||||
NzMemberWithoutArgs<C>::NzMemberWithoutArgs(void (C::*func)(), C* object) :
|
||||
m_func(func),
|
||||
m_object(object)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
void NzMemberWithoutArgs<C>::Run()
|
||||
{
|
||||
(m_object->*m_func)();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ enum nzHash
|
||||
nzHash_Whirlpool
|
||||
};
|
||||
|
||||
class NzHash;
|
||||
class NzHashDigest;
|
||||
class NzHashImpl;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzMutexImpl;
|
||||
class NzConditionVariable;
|
||||
|
||||
class NAZARA_API NzMutex : NzNonCopyable
|
||||
{
|
||||
|
||||
36
include/Nazara/Core/ResourceLoader.hpp
Normal file
36
include/Nazara/Core/ResourceLoader.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// 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 <set>
|
||||
#include <tuple>
|
||||
|
||||
class NzInputStream;
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
class NzResourceLoader
|
||||
{
|
||||
public:
|
||||
using CheckFunction = bool (*)(NzInputStream& stream, const Parameters& parameters);
|
||||
using LoadFunction = 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 RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadfunc);
|
||||
static void UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadfunc);
|
||||
|
||||
using Loader = std::tuple<std::set<NzString>, CheckFunction, LoadFunction>;
|
||||
using LoaderList = std::set<Loader>;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/ResourceLoader.inl>
|
||||
|
||||
#endif // NAZARA_RESOURCELOADER_HPP
|
||||
142
include/Nazara/Core/ResourceLoader.inl
Normal file
142
include/Nazara/Core/ResourceLoader.inl
Normal file
@@ -0,0 +1,142 @@
|
||||
// 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/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_CORE_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;
|
||||
}
|
||||
|
||||
NzFile file(path, NzFile::ReadOnly);
|
||||
if (!file.IsOpen())
|
||||
{
|
||||
NazaraError("Failed to open file");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader)
|
||||
{
|
||||
for (const NzString& loaderExt : std::get<0>(*loader))
|
||||
{
|
||||
int cmp = NzString::Compare(loaderExt, ext);
|
||||
if (cmp == 0)
|
||||
{
|
||||
if (!std::get<1>(*loader)(file, parameters))
|
||||
continue;
|
||||
|
||||
file.SetCursorPos(0);
|
||||
|
||||
// Chargement de la ressource
|
||||
if (std::get<2>(*loader)(resource, file, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
|
||||
file.SetCursorPos(0);
|
||||
}
|
||||
else if (cmp < 0) // S'il est encore possible que l'extension se situe après
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: no loader");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
|
||||
{
|
||||
NzMemoryStream stream(data, size);
|
||||
|
||||
return LoadFromStream(resource, stream, parameters);
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_CORE_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_loaders.begin(); loader != Type::s_loaders.end(); ++loader)
|
||||
{
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!std::get<1>(*loader)(stream, parameters))
|
||||
continue;
|
||||
|
||||
// On repositionne le stream au début
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Chargement de la ressource
|
||||
if (std::get<2>(*loader)(resource, stream, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
stream.SetCursorPos(streamPos); // On repositionne au début
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: no loader");
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc)
|
||||
{
|
||||
/// Trouver une alternative à ce code monstrueux
|
||||
std::vector<NzString> exts;
|
||||
fileExtensions.SplitAny(exts, " /\\.,;|-_");
|
||||
|
||||
std::set<NzString> extensions;
|
||||
std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin()));
|
||||
|
||||
Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc)
|
||||
{
|
||||
std::vector<NzString> exts;
|
||||
fileExtensions.SplitAny(exts, " /\\.,;|-_");
|
||||
|
||||
std::set<NzString> extensions;
|
||||
std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin()));
|
||||
|
||||
Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc));
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -17,13 +17,13 @@ class NzThreadImpl;
|
||||
|
||||
class NAZARA_API NzThread : NzNonCopyable
|
||||
{
|
||||
friend class NzThreadImpl;
|
||||
friend NzThreadImpl;
|
||||
|
||||
public:
|
||||
class NAZARA_API Id
|
||||
{
|
||||
friend class NzThread;
|
||||
friend class NzThreadImpl;
|
||||
friend NzThread;
|
||||
friend NzThreadImpl;
|
||||
|
||||
public:
|
||||
Id() = default;
|
||||
@@ -43,6 +43,7 @@ class NAZARA_API NzThread : NzNonCopyable
|
||||
|
||||
template<typename F> NzThread(F function);
|
||||
template<typename F, typename... Args> NzThread(F function, Args... args);
|
||||
template<typename C> NzThread(void (C::*function)(), C* object);
|
||||
~NzThread();
|
||||
|
||||
Id GetId() const;
|
||||
@@ -56,7 +57,7 @@ class NAZARA_API NzThread : NzNonCopyable
|
||||
|
||||
private:
|
||||
NzFunctor* m_func;
|
||||
NzThreadImpl* m_impl;
|
||||
NzThreadImpl* m_impl = nullptr;
|
||||
bool m_independent;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,15 +4,21 @@
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename F> NzThread::NzThread(F function) :
|
||||
m_func(new NzFunctorWithoutArgs<F>(function)),
|
||||
m_impl(nullptr)
|
||||
template<typename F>
|
||||
NzThread::NzThread(F function) :
|
||||
m_func(new NzFunctorWithoutArgs<F>(function))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename F, typename... Args> NzThread::NzThread(F function, Args... args) :
|
||||
m_func(new NzFunctorWithArgs<F, Args...>(function, args...)),
|
||||
m_impl(nullptr)
|
||||
template<typename F, typename... Args>
|
||||
NzThread::NzThread(F function, Args... args) :
|
||||
m_func(new NzFunctorWithArgs<F, Args...>(function, args...))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
NzThread::NzThread(void (C::*function)(), C* object) :
|
||||
m_func(new NzMemberWithoutArgs<C>(function, object))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
template<unsigned int N> struct NzTupleUnpack
|
||||
template<unsigned int N>
|
||||
struct NzTupleUnpack
|
||||
{
|
||||
template <typename F, typename... ArgsT, typename... Args>
|
||||
void operator()(F func, const std::tuple<ArgsT...>& t, Args&... args)
|
||||
@@ -17,7 +18,8 @@ template<unsigned int N> struct NzTupleUnpack
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct NzTupleUnpack<0>
|
||||
template<>
|
||||
struct NzTupleUnpack<0>
|
||||
{
|
||||
template <typename F, typename... ArgsT, typename... Args>
|
||||
void operator()(F func, const std::tuple<ArgsT...>&, Args&... args)
|
||||
@@ -27,7 +29,7 @@ template<> struct NzTupleUnpack<0>
|
||||
};
|
||||
|
||||
template<typename F, typename... ArgsT>
|
||||
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t )
|
||||
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t)
|
||||
{
|
||||
NzTupleUnpack<sizeof...(ArgsT)>()(func, t);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class NzContextImpl;
|
||||
|
||||
class NAZARA_API NzContext
|
||||
{
|
||||
friend class NzContextImpl;
|
||||
friend NzContextImpl;
|
||||
|
||||
public:
|
||||
NzContext();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <GL3/glxext.h>
|
||||
#endif
|
||||
|
||||
typedef void (*NzOpenGLFunc)();
|
||||
using NzOpenGLFunc = void (*)();
|
||||
|
||||
class NAZARA_API NzOpenGL
|
||||
{
|
||||
@@ -77,9 +77,9 @@ NAZARA_API extern PFNGLCOLORMASKPROC glColorMask;
|
||||
NAZARA_API extern PFNGLCULLFACEPROC glCullFace;
|
||||
NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader;
|
||||
NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback;
|
||||
NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
|
||||
NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
|
||||
NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
class NzRenderer;
|
||||
class NzShaderImpl;
|
||||
class NzTexture;
|
||||
|
||||
@@ -26,7 +25,7 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
NzShader();
|
||||
NzShader() = default;
|
||||
NzShader(nzShaderLanguage language);
|
||||
~NzShader();
|
||||
|
||||
@@ -70,8 +69,8 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
static bool IsTypeSupported(nzShaderType type);
|
||||
|
||||
private:
|
||||
NzShaderImpl* m_impl;
|
||||
bool m_compiled;
|
||||
NzShaderImpl* m_impl = nullptr;
|
||||
bool m_compiled = false;
|
||||
};
|
||||
|
||||
#endif // NAZARA_SHADER_HPP
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
|
||||
class NzShader;
|
||||
struct NzTextureImpl;
|
||||
|
||||
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
|
||||
@@ -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