diff --git a/NazaraModuleTemplate/build/scripts/module/modulename.lua b/NazaraModuleTemplate/build/scripts/module/modulename.lua index 31847eb8c..c1d8d7d12 100644 --- a/NazaraModuleTemplate/build/scripts/module/modulename.lua +++ b/NazaraModuleTemplate/build/scripts/module/modulename.lua @@ -1,4 +1,6 @@ -project "NazaraModuleName" +if (not _OPTIONS["one-library"]) then + project "NazaraModuleName" +end files { @@ -14,18 +16,22 @@ else excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraModuleNamed" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Audio/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraModuleNamed" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraModuleName" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraModuleName" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraModuleNamed" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraModuleNamed" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraModuleName" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraModuleName" +end \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index c531d7c52..797db69d4 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -19,6 +19,13 @@ includedirs } libdirs "../lib" + +if (_OPTIONS["x64"]) then + libdirs "../extlibs/lib/x64" +end + +libdirs "../extlibs/lib/x86" + targetdir "../lib" configuration "Debug*" diff --git a/build/scripts/common_examples.lua b/build/scripts/common_examples.lua index 0ef097298..03b087a3d 100644 --- a/build/scripts/common_examples.lua +++ b/build/scripts/common_examples.lua @@ -10,10 +10,7 @@ configurations language "C++" location("../examples/build/" .. _ACTION) -includedirs -{ - "../include" -} +includedirs "../include" debugdir "../examples/bin" libdirs "../lib" diff --git a/build/scripts/module/core.lua b/build/scripts/module/core.lua index 4efb6b578..fcd8efb4d 100644 --- a/build/scripts/module/core.lua +++ b/build/scripts/module/core.lua @@ -1,4 +1,6 @@ -project "NazaraCore" +if (not _OPTIONS["one-library"]) then + project "NazaraCore" +end files { @@ -17,8 +19,10 @@ else excludes { "../src/Nazara/Core/Win32/**.hpp", "../src/Nazara/Core/Win32/**.cpp" } end -configuration "Debug*" - targetname "NazaraCored" +if (not _OPTIONS["one-library"]) then + configuration "Debug*" + targetname "NazaraCored" -configuration "Release*" - targetname "NazaraCore" + configuration "Release*" + targetname "NazaraCore" +end \ No newline at end of file diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua index 55f21fc76..0d9cc325e 100644 --- a/build/scripts/module/noise.lua +++ b/build/scripts/module/noise.lua @@ -1,11 +1,13 @@ -project "NazaraNoise" +if (not _OPTIONS["one-library"]) then + project "NazaraNoise" +end files { - "../include/Nazara/Noise/**.hpp", - "../include/Nazara/Noise/**.inl", - "../src/Nazara/Noise/**.hpp", - "../src/Nazara/Noise/**.cpp" + "../include/Nazara/Noise/**.hpp", + "../include/Nazara/Noise/**.inl", + "../src/Nazara/Noise/**.hpp", + "../src/Nazara/Noise/**.cpp" } if (os.is("windows")) then @@ -14,18 +16,22 @@ else excludes { "../src/Nazara/Noise/Win32/*.hpp", "../src/Nazara/Noise/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraNoised" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Noise/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraNoised" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraNoise" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraNoise" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraNoised" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraNoised" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraNoise" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraNoise" +end \ No newline at end of file diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index 9529919f7..7419c05b0 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -1,4 +1,6 @@ -project "NazaraRenderer" +if (not _OPTIONS["one-library"]) then + project "NazaraRenderer" +end files { @@ -17,22 +19,26 @@ else excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" - targetname "NazaraRendererd" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraUtilityd-s" + targetname "NazaraRendererd" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" - targetname "NazaraRenderer" + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + targetname "NazaraRenderer" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" - targetname "NazaraRendererd" + configuration "DebugDLL" + links "NazaraCored" + links "NazaraUtilityd" + targetname "NazaraRendererd" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" - targetname "NazaraRenderer" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" + targetname "NazaraRenderer" +end \ No newline at end of file diff --git a/build/scripts/module/utility.lua b/build/scripts/module/utility.lua index 183abe974..81091bcef 100644 --- a/build/scripts/module/utility.lua +++ b/build/scripts/module/utility.lua @@ -1,4 +1,6 @@ -project "NazaraUtility" +if (not _OPTIONS["one-library"]) then + project "NazaraUtility" +end defines "STBI_NO_STDIO" @@ -18,18 +20,22 @@ else excludes { "../src/Nazara/Utility/Win32/*.hpp", "../src/Nazara/Utility/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraUtilityd" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Utility/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraUtilityd" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraUtility" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraUtility" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraUtilityd" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraUtilityd" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraUtility" +end \ No newline at end of file diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua index 4d93b53c9..d45cb5983 100644 --- a/examples/AnimatedMesh/build.lua +++ b/examples/AnimatedMesh/build.lua @@ -2,22 +2,36 @@ kind "ConsoleApp" files "main.cpp" -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraRendererd-s" - links "NazaraUtilityd-s" +if (_OPTIONS["one-library"]) then + configuration "DebugStatic" + links "Nazarad-s" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraRenderer-s" - links "NazaraUtility-s" + configuration "ReleaseStatic" + links "Nazara-s" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraRendererd" - links "NazaraUtilityd" + configuration "DebugDLL" + links "Nazarad" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraRenderer" - links "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "Nazara" +else + configuration "DebugStatic" + links "NazaraRendererd-s" + links "NazaraUtilityd-s" + links "NazaraCored-s" + + configuration "ReleaseStatic" + links "NazaraRenderer-s" + links "NazaraUtility-s" + links "NazaraCore-s" + + configuration "DebugDLL" + links "NazaraRendererd" + links "NazaraCored" + links "NazaraUtilityd" + + configuration "ReleaseDLL" + links "NazaraRenderer" + links "NazaraUtility" + links "NazaraCore" +end diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index 022a86bc8..a522b53f6 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -2,18 +2,32 @@ kind "ConsoleApp" files "main.cpp" -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" +if (_OPTIONS["one-library"]) then + configuration "DebugStatic" + links "Nazarad-s" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" + configuration "ReleaseStatic" + links "Nazara-s" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" + configuration "DebugDLL" + links "Nazarad" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "Nazara" +else + configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraUtilityd-s" + + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + + configuration "DebugDLL" + links "NazaraCored" + links "NazaraUtilityd" + + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" +end diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index dc95e616a..7359bca5f 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -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); diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index f97348afc..38f06d8de 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -9,9 +9,10 @@ enum nzEndianness { + nzEndianness_Unknown = -1, + nzEndianness_BigEndian, - nzEndianness_LittleEndian, - nzEndianness_Unknown + nzEndianness_LittleEndian }; enum nzErrorType diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index aa84ec68e..3bb64342e 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -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 }; diff --git a/include/Nazara/Core/Functor.hpp b/include/Nazara/Core/Functor.hpp index 656b6a866..6429452f8 100644 --- a/include/Nazara/Core/Functor.hpp +++ b/include/Nazara/Core/Functor.hpp @@ -18,27 +18,40 @@ struct NzFunctor virtual void Run() = 0; }; -template struct NzFunctorWithoutArgs : NzFunctor +template +struct NzFunctorWithoutArgs : NzFunctor { NzFunctorWithoutArgs(F func); void Run(); - F function; + private: + F m_func; }; -template struct NzFunctorWithArgs : NzFunctor +template +struct NzFunctorWithArgs : NzFunctor { NzFunctorWithArgs(F func, Args&... args); void Run(); - F function; - std::tuple arguments; + private: + F m_func; + std::tuple m_args; }; -template struct NzFunctorWithoutArgs; -template struct NzFunctorWithArgs; +template +struct NzMemberWithoutArgs : NzFunctor +{ + NzMemberWithoutArgs(void (C::*func)(), C* object); + + void Run(); + + private: + void (C::*m_func)(); + C* m_object; +}; #include diff --git a/include/Nazara/Core/Functor.inl b/include/Nazara/Core/Functor.inl index e867f79ef..38f0a4fc5 100644 --- a/include/Nazara/Core/Functor.inl +++ b/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 NzFunctorWithoutArgs::NzFunctorWithoutArgs(F func) : -function(func) +template +NzFunctorWithoutArgs::NzFunctorWithoutArgs(F func) : +m_func(func) { } -template void NzFunctorWithoutArgs::Run() +template +void NzFunctorWithoutArgs::Run() { - function(); + m_func(); } -template NzFunctorWithArgs::NzFunctorWithArgs(F func, Args&... args) : -function(func), -arguments(args...) +template +NzFunctorWithArgs::NzFunctorWithArgs(F func, Args&... args) : +m_func(func), +m_args(args...) { } -template void NzFunctorWithArgs::Run() +template +void NzFunctorWithArgs::Run() { - NzUnpackTuple(function, arguments); + NzUnpackTuple(m_func, m_args); +} + + +template +NzMemberWithoutArgs::NzMemberWithoutArgs(void (C::*func)(), C* object) : +m_func(func), +m_object(object) +{ +} + +template +void NzMemberWithoutArgs::Run() +{ + (m_object->*m_func)(); } diff --git a/include/Nazara/Core/Hashable.hpp b/include/Nazara/Core/Hashable.hpp index 4b9395bb3..9dad8a771 100644 --- a/include/Nazara/Core/Hashable.hpp +++ b/include/Nazara/Core/Hashable.hpp @@ -22,7 +22,6 @@ enum nzHash nzHash_Whirlpool }; -class NzHash; class NzHashDigest; class NzHashImpl; diff --git a/include/Nazara/Core/Mutex.hpp b/include/Nazara/Core/Mutex.hpp index 6ca9d91d4..9e5fb3147 100644 --- a/include/Nazara/Core/Mutex.hpp +++ b/include/Nazara/Core/Mutex.hpp @@ -11,7 +11,6 @@ #include class NzMutexImpl; -class NzConditionVariable; class NAZARA_API NzMutex : NzNonCopyable { diff --git a/include/Nazara/Core/ResourceLoader.hpp b/include/Nazara/Core/ResourceLoader.hpp new file mode 100644 index 000000000..3d2d23117 --- /dev/null +++ b/include/Nazara/Core/ResourceLoader.hpp @@ -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 +#include +#include + +class NzInputStream; + +template +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, CheckFunction, LoadFunction>; + using LoaderList = std::set; +}; + +#include + +#endif // NAZARA_RESOURCELOADER_HPP diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl new file mode 100644 index 000000000..321279ed6 --- /dev/null +++ b/include/Nazara/Core/ResourceLoader.inl @@ -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 +#include +#include +#include +#include +#include + +template +bool NzResourceLoader::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 +bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) +{ + NzMemoryStream stream(data, size); + + return LoadFromStream(resource, stream, parameters); +} + +template +bool NzResourceLoader::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 +void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + /// Trouver une alternative à ce code monstrueux + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set 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 +void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set 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 diff --git a/include/Nazara/Core/Thread.hpp b/include/Nazara/Core/Thread.hpp index aa67e0beb..0b2744533 100644 --- a/include/Nazara/Core/Thread.hpp +++ b/include/Nazara/Core/Thread.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 NzThread(F function); template NzThread(F function, Args... args); + template 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; }; diff --git a/include/Nazara/Core/Thread.inl b/include/Nazara/Core/Thread.inl index 301a32240..80b1ead60 100644 --- a/include/Nazara/Core/Thread.inl +++ b/include/Nazara/Core/Thread.inl @@ -4,15 +4,21 @@ #include -template NzThread::NzThread(F function) : -m_func(new NzFunctorWithoutArgs(function)), -m_impl(nullptr) +template +NzThread::NzThread(F function) : +m_func(new NzFunctorWithoutArgs(function)) { } -template NzThread::NzThread(F function, Args... args) : -m_func(new NzFunctorWithArgs(function, args...)), -m_impl(nullptr) +template +NzThread::NzThread(F function, Args... args) : +m_func(new NzFunctorWithArgs(function, args...)) +{ +} + +template +NzThread::NzThread(void (C::*function)(), C* object) : +m_func(new NzMemberWithoutArgs(function, object)) { } diff --git a/include/Nazara/Core/Tuple.inl b/include/Nazara/Core/Tuple.inl index 326ca5d97..b4d4e801c 100644 --- a/include/Nazara/Core/Tuple.inl +++ b/include/Nazara/Core/Tuple.inl @@ -8,7 +8,8 @@ #include -template struct NzTupleUnpack +template +struct NzTupleUnpack { template void operator()(F func, const std::tuple& t, Args&... args) @@ -17,7 +18,8 @@ template struct NzTupleUnpack } }; -template<> struct NzTupleUnpack<0> +template<> +struct NzTupleUnpack<0> { template void operator()(F func, const std::tuple&, Args&... args) @@ -27,7 +29,7 @@ template<> struct NzTupleUnpack<0> }; template -void NzUnpackTuple(F func, const std::tuple& t ) +void NzUnpackTuple(F func, const std::tuple& t) { NzTupleUnpack()(func, t); } diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index 9aaf37304..b24f1e106 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -17,7 +17,7 @@ class NzContextImpl; class NAZARA_API NzContext { - friend class NzContextImpl; + friend NzContextImpl; public: NzContext(); diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 72bd906a4..1944054e6 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -24,7 +24,7 @@ #include #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; diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index bf270b63c..4b9e56454 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -17,7 +17,6 @@ #include #include -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 diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index d0e1b8856..0d9611865 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -13,7 +13,6 @@ #include #include -class NzShader; struct NzTextureImpl; class NAZARA_API NzTexture : public NzResource, NzNonCopyable diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index 15ecd6b78..cc13bc7b2 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -9,11 +9,9 @@ #include #include +#include #include #include -#include -#include -#include struct NzAnimationParams { @@ -33,13 +31,13 @@ struct NzSequence class NzAnimation; -typedef NzResourceLoader NzAnimationLoader; +using NzAnimationLoader = NzResourceLoader; struct NzAnimationImpl; class NAZARA_API NzAnimation : public NzResource { - friend class NzResourceLoader; + friend NzAnimationLoader; public: NzAnimation() = default; @@ -73,9 +71,7 @@ class NAZARA_API NzAnimation : public NzResource private: NzAnimationImpl* m_impl = nullptr; - static std::list s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzAnimationLoader::LoaderList s_loaders; }; #endif // NAZARA_ANIMATION_HPP diff --git a/include/Nazara/Utility/AxisAlignedBox.hpp b/include/Nazara/Utility/AxisAlignedBox.hpp index 174ff5fc8..47934cda1 100644 --- a/include/Nazara/Utility/AxisAlignedBox.hpp +++ b/include/Nazara/Utility/AxisAlignedBox.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 diff --git a/include/Nazara/Utility/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp index db03d85f6..96a47c522 100644 --- a/include/Nazara/Utility/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -13,16 +13,13 @@ #include 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); diff --git a/include/Nazara/Utility/Cursor.hpp b/include/Nazara/Utility/Cursor.hpp index 46ba6a940..d95f34718 100644 --- a/include/Nazara/Utility/Cursor.hpp +++ b/include/Nazara/Utility/Cursor.hpp @@ -12,7 +12,6 @@ class NzCursorImpl; class NzImage; -class NzWindowImpl; class NAZARA_API NzCursor { diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 71e5418c0..9d044c7c1 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -127,7 +127,7 @@ enum nzImageType enum nzPixelFormat { - nzPixelFormat_Undefined, + nzPixelFormat_Undefined = -1, nzPixelFormat_BGR8, // 3*nzUInt8 nzPixelFormat_BGRA8, // 4*nzUInt8 diff --git a/include/Nazara/Utility/Icon.hpp b/include/Nazara/Utility/Icon.hpp index d2797517a..d734d6e85 100644 --- a/include/Nazara/Utility/Icon.hpp +++ b/include/Nazara/Utility/Icon.hpp @@ -12,7 +12,6 @@ class NzImage; class NzIconImpl; -class NzWindowImpl; class NAZARA_API NzIcon { diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 7c682b7cb..d58ff1736 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -11,14 +11,12 @@ #include #include #include +#include #include #include #include #include -#include #include -#include -#include #if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE #include @@ -26,6 +24,8 @@ #include #endif +///TODO: Filtres + struct NzImageParams { nzPixelFormat loadFormat = nzPixelFormat_Undefined; @@ -34,20 +34,19 @@ struct NzImageParams bool IsValid() const; }; -///TODO: Filtres - class NzImage; -typedef NzResourceLoader NzImageLoader; +using NzImageLoader = NzResourceLoader; class NAZARA_API NzImage : public NzResource { - friend class NzResourceLoader; + 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 s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzImageLoader::LoaderList s_loaders; }; #endif // NAZARA_IMAGE_HPP diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 8fb29dbd5..c8ca8b814 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -10,13 +10,11 @@ #include #include #include +#include #include #include #include -#include #include -#include -#include class NzVertexDeclaration; @@ -32,13 +30,13 @@ struct NzMeshParams class NzMesh; -typedef NzResourceLoader NzMeshLoader; +using NzMeshLoader = NzResourceLoader; struct NzMeshImpl; class NAZARA_API NzMesh : public NzResource { - friend class NzResourceLoader; + friend NzMeshLoader; public: NzMesh() = default; @@ -89,9 +87,7 @@ class NAZARA_API NzMesh : public NzResource private: NzMeshImpl* m_impl = nullptr; - static std::list s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzMeshLoader::LoaderList s_loaders; }; #endif // NAZARA_MESH_HPP diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 611819d27..396fa8056 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.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); diff --git a/include/Nazara/Utility/ResourceLoader.hpp b/include/Nazara/Utility/ResourceLoader.hpp deleted file mode 100644 index 6cc1a08e1..000000000 --- a/include/Nazara/Utility/ResourceLoader.hpp +++ /dev/null @@ -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 -#include - -class NzInputStream; - -template -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 MemoryLoader; - typedef std::pair StreamLoader; -}; - -#include - -#endif // NAZARA_RESOURCELOADER_HPP diff --git a/include/Nazara/Utility/ResourceLoader.inl b/include/Nazara/Utility/ResourceLoader.inl deleted file mode 100644 index ee004d32e..000000000 --- a/include/Nazara/Utility/ResourceLoader.inl +++ /dev/null @@ -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 -#include -#include -#include -#include - -template -bool NzResourceLoader::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 -bool NzResourceLoader::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 -bool NzResourceLoader::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 -void NzResourceLoader::RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile) -{ - std::vector exts; - extensions.SplitAny(exts, " /\\*.,;|-_"); - - for (const NzString& ext : exts) - Type::s_fileLoaders.insert(std::make_pair(ext, loadFile)); -} - -template -void NzResourceLoader::RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory) -{ - Type::s_memoryLoaders.push_back(std::make_pair(identifyMemory, loadMemory)); -} - -template -void NzResourceLoader::RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream) -{ - Type::s_streamLoaders.push_back(std::make_pair(identifyStream, loadStream)); -} - -template -void NzResourceLoader::UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile) -{ - std::vector 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 -void NzResourceLoader::UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory) -{ - Type::s_memoryLoaders.remove(std::make_pair(identifyMemory, loadMemory)); -} - -template -void NzResourceLoader::UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream) -{ - Type::s_streamLoaders.remove(std::make_pair(identifyStream, loadStream)); -} - -#include diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index e7f070300..2e14e3913 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.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(); diff --git a/src/Nazara/Core/Win32/MutexImpl.hpp b/src/Nazara/Core/Win32/MutexImpl.hpp index cb02f4e07..d8f7ea461 100644 --- a/src/Nazara/Core/Win32/MutexImpl.hpp +++ b/src/Nazara/Core/Win32/MutexImpl.hpp @@ -9,8 +9,6 @@ #include -class NzConditionVariableImpl; - class NzMutexImpl { friend class NzConditionVariableImpl; diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index 4549a46c8..ce3f2c7e7 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -44,7 +44,7 @@ namespace GL_STATIC_DRAW // nzBufferUsage_Static }; - typedef nzUInt8* (*LockRoutine)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) { diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 992c58d05..3871b7169 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -354,9 +354,9 @@ bool NzOpenGL::Initialize() { try { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); openGLextensions[NzOpenGL::DebugOutput] = true; @@ -371,9 +371,9 @@ bool NzOpenGL::Initialize() { try { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); openGLextensions[NzOpenGL::DebugOutput] = true; @@ -590,9 +590,9 @@ PFNGLCOLORMASKPROC glColorMask = nullptr; PFNGLCULLFACEPROC glCullFace = nullptr; PFNGLCOMPILESHADERPROC glCompileShader = nullptr; PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; +PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; -PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 01ec4afca..a186fe518 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -147,10 +147,10 @@ namespace return new NzHardwareBuffer(parent, type); } - typedef std::tuple VAO_Key; - constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; + using VAO_Key = std::tuple; + std::map s_vaos; NzMatrix4f s_matrix[totalMatrixCount]; int s_matrixLocation[totalMatrixCount]; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index 51f0f89db..fff9f9fd7 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -14,15 +14,7 @@ #include #include -NzShader::NzShader() : -m_impl(nullptr), -m_compiled(false) -{ -} - -NzShader::NzShader(nzShaderLanguage language) : -m_impl(nullptr), -m_compiled(false) +NzShader::NzShader(nzShaderLanguage language) { Create(language); diff --git a/src/Nazara/Renderer/ShaderImpl.hpp b/src/Nazara/Renderer/ShaderImpl.hpp index c47e526c8..cc826788e 100644 --- a/src/Nazara/Renderer/ShaderImpl.hpp +++ b/src/Nazara/Renderer/ShaderImpl.hpp @@ -9,7 +9,6 @@ #include -class NzRenderer; class NzTexture; class NzVertexBuffer; class NzVertexDeclaration; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 9c362d2f6..7c829ff44 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -517,7 +517,7 @@ void NzTexture::Destroy() bool NzTexture::Download(NzImage* image) const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -576,7 +576,7 @@ bool NzTexture::Download(NzImage* image) const bool NzTexture::EnableMipmapping(bool enable) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -603,7 +603,7 @@ bool NzTexture::EnableMipmapping(bool enable) unsigned int NzTexture::GetAnisotropyLevel() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -626,7 +626,7 @@ unsigned int NzTexture::GetAnisotropyLevel() const nzUInt8 NzTexture::GetBPP() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -639,7 +639,7 @@ nzUInt8 NzTexture::GetBPP() const unsigned int NzTexture::GetDepth() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -652,7 +652,7 @@ unsigned int NzTexture::GetDepth() const nzTextureFilter NzTexture::GetFilterMode() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzTextureFilter_Unknown; @@ -689,7 +689,7 @@ nzTextureFilter NzTexture::GetFilterMode() const nzPixelFormat NzTexture::GetFormat() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzPixelFormat_Undefined; @@ -702,7 +702,7 @@ nzPixelFormat NzTexture::GetFormat() const unsigned int NzTexture::GetHeight() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -715,7 +715,7 @@ unsigned int NzTexture::GetHeight() const nzImageType NzTexture::GetType() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzImageType_2D; @@ -728,7 +728,7 @@ nzImageType NzTexture::GetType() const unsigned int NzTexture::GetWidth() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -741,7 +741,7 @@ unsigned int NzTexture::GetWidth() const nzTextureWrap NzTexture::GetWrapMode() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzTextureWrap_Unknown; @@ -773,7 +773,7 @@ nzTextureWrap NzTexture::GetWrapMode() const bool NzTexture::IsCompressed() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -786,7 +786,7 @@ bool NzTexture::IsCompressed() const bool NzTexture::IsCubemap() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -799,7 +799,7 @@ bool NzTexture::IsCubemap() const bool NzTexture::IsTarget() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -915,7 +915,7 @@ bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& param bool NzTexture::Lock() { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -930,7 +930,7 @@ bool NzTexture::Lock() bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -955,7 +955,7 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) bool NzTexture::SetFilterMode(nzTextureFilter filter) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1008,7 +1008,7 @@ bool NzTexture::SetFilterMode(nzTextureFilter filter) bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1038,7 +1038,7 @@ bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) bool NzTexture::SetWrapMode(nzTextureWrap wrap) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1175,7 +1175,7 @@ bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1191,7 +1191,7 @@ bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1292,7 +1292,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1436,7 +1436,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRec bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1449,7 +1449,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 le bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1527,7 +1527,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe void NzTexture::Unlock() { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return; @@ -1619,7 +1619,7 @@ bool NzTexture::IsTypeSupported(nzImageType type) void NzTexture::SetTarget(bool isTarget) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraInternalError("Texture must be valid"); return; diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index eb4dcf3ca..48bad22f2 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -313,6 +314,4 @@ void NzAnimation::RemoveSequence(unsigned int index) m_impl->sequences.erase(it); } -std::list NzAnimation::s_memoryLoaders; -std::list NzAnimation::s_streamLoaders; -std::multimap NzAnimation::s_fileLoaders; +NzAnimationLoader::LoaderList NzAnimation::s_loaders; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 3e6986677..ebcfa716a 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace @@ -31,6 +32,20 @@ m_sharedImage(&emptyImage) { } +NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : +m_sharedImage(&emptyImage) +{ + Create(type, format, width, height, depth, levelCount); + + #ifdef NAZARA_DEBUG + if (!m_sharedImage) + { + NazaraError("Failed to create image"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + NzImage::NzImage(const NzImage& image) : NzResource(image), m_sharedImage(image.m_sharedImage) @@ -57,7 +72,7 @@ NzImage::~NzImage() bool NzImage::Convert(nzPixelFormat format) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -162,7 +177,7 @@ bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto Correctif temporaire : Update veut de la mémoire contigüe Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour - FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) + ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) (Appliquer l'interface à NzTexture également) */ nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); @@ -311,7 +326,7 @@ void NzImage::Destroy() bool NzImage::Fill(const NzColor& color) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -369,7 +384,7 @@ bool NzImage::Fill(const NzColor& color) bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -432,7 +447,7 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -495,7 +510,7 @@ bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) bool NzImage::FlipHorizontally() { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -534,7 +549,7 @@ bool NzImage::FlipHorizontally() bool NzImage::FlipVertically() { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -577,7 +592,7 @@ nzUInt8 NzImage::GetBPP() const const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return nullptr; @@ -656,7 +671,7 @@ nzUInt8 NzImage::GetMaxLevel() const NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return NzColor(); @@ -700,7 +715,7 @@ NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) c nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return nullptr; @@ -832,7 +847,7 @@ bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) bool NzImage::SetLevelCount(nzUInt8 levelCount) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -877,7 +892,7 @@ bool NzImage::SetLevelCount(nzUInt8 levelCount) bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -923,7 +938,7 @@ bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -952,7 +967,7 @@ bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -990,7 +1005,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); if (z >= depth) { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); return false; } #endif @@ -1015,7 +1030,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) { ///FIXME: Vérifier que ça fonctionne correctement #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -1152,6 +1167,4 @@ void NzImage::ReleaseImage() } NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); -std::list NzImage::s_memoryLoaders; -std::list NzImage::s_streamLoaders; -std::multimap NzImage::s_fileLoaders; +NzImageLoader::LoaderList NzImage::s_loaders; diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index d2fa86371..bb30b5832 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -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 @@ -18,27 +18,23 @@ namespace { - bool NzLoader_MD2_LoadStream(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters); - - bool NzLoader_MD2_LoadFile(NzMesh* mesh, const NzString& filePath, const NzMeshParams& parameters) + bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); + NazaraUnused(parameters); + + nzUInt32 magic[2]; + if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) return false; - } - return NzLoader_MD2_LoadStream(mesh, file, parameters); + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&magic[0], sizeof(nzUInt32)); + NzByteSwap(&magic[1], sizeof(nzUInt32)); + #endif + + return magic[0] == md2Ident && magic[1] == 8; } - bool NzLoader_MD2_LoadMemory(NzMesh* mesh, const void* data, unsigned int size, const NzMeshParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_MD2_LoadStream(mesh, stream, parameters); - } - - bool NzLoader_MD2_LoadStream(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) + bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) { md2_header header; if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) @@ -208,60 +204,18 @@ namespace return true; } - - bool NzLoader_MD2_IdentifyMemory(const void* data, unsigned int size, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - if (size < sizeof(md2_header)) - return false; - - const md2_header* header = reinterpret_cast(data); - - #if defined(NAZARA_BIG_ENDIAN) - nzUInt32 ident = header->ident; - nzUInt32 version = header->version; - - NzByteSwap(&ident, sizeof(nzUInt32)); - NzByteSwap(&version, sizeof(nzUInt32)); - - return ident == md2Ident && version == 8; - #else - return header->ident == md2Ident && header->version == 8; - #endif - } - - bool NzLoader_MD2_IdentifyStream(NzInputStream& stream, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - nzUInt32 magic[2]; - if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) - return false; - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&magic[0], sizeof(nzUInt32)); - NzByteSwap(&magic[1], sizeof(nzUInt32)); - #endif - - return magic[0] == md2Ident && magic[1] == 8; - } } void NzLoaders_MD2_Register() { NzMD2Mesh::Initialize(); - NzMeshLoader::RegisterFileLoader("md2", NzLoader_MD2_LoadFile); - NzMeshLoader::RegisterMemoryLoader(NzLoader_MD2_IdentifyMemory, NzLoader_MD2_LoadMemory); - NzMeshLoader::RegisterStreamLoader(NzLoader_MD2_IdentifyStream, NzLoader_MD2_LoadStream); + NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); } void NzLoaders_MD2_Unregister() { - NzMeshLoader::UnregisterStreamLoader(NzLoader_MD2_IdentifyStream, NzLoader_MD2_LoadStream); - NzMeshLoader::UnregisterMemoryLoader(NzLoader_MD2_IdentifyMemory, NzLoader_MD2_LoadMemory); - NzMeshLoader::UnregisterFileLoader("md2", NzLoader_MD2_LoadFile); + NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); NzMD2Mesh::Uninitialize(); } diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index 63db23e6b..2d25e0db7 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -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 diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index 6240461e3..74fc38725 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -37,27 +37,18 @@ namespace nzUInt8 padding[54]; }; - bool NzLoader_PCX_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters); - - bool NzLoader_PCX_LoadFile(NzImage* image, const NzString& filePath, const NzImageParams& parameters) + bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); + NazaraUnused(parameters); + + nzUInt8 manufacturer; + if (stream.Read(&manufacturer, 1) != 1) return false; - } - return NzLoader_PCX_LoadStream(image, file, parameters); + return manufacturer == 0x0a; } - bool NzLoader_PCX_LoadMemory(NzImage* image, const void* data, unsigned int size, const NzImageParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_PCX_LoadStream(image, stream, parameters); - } - - bool NzLoader_PCX_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) { NazaraUnused(parameters); @@ -348,39 +339,14 @@ namespace return true; } - - bool NzLoader_PCX_IdentifyMemory(const void* data, unsigned int size, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - if (size < sizeof(pcx_header)) - return false; - - return *reinterpret_cast(data) == 0x0a; - } - - bool NzLoader_PCX_IdentifyStream(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - nzUInt8 manufacturer; - if (stream.Read(&manufacturer, 1) != 1) - return false; - - return manufacturer == 0x0a; - } } void NzLoaders_PCX_Register() { - NzImageLoader::RegisterFileLoader("pcx", NzLoader_PCX_LoadFile); - NzImageLoader::RegisterMemoryLoader(NzLoader_PCX_IdentifyMemory, NzLoader_PCX_LoadMemory); - NzImageLoader::RegisterStreamLoader(NzLoader_PCX_IdentifyStream, NzLoader_PCX_LoadStream); + NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); } void NzLoaders_PCX_Unregister() { - NzImageLoader::UnregisterStreamLoader(NzLoader_PCX_IdentifyStream, NzLoader_PCX_LoadStream); - NzImageLoader::UnregisterMemoryLoader(NzLoader_PCX_IdentifyMemory, NzLoader_PCX_LoadMemory); - NzImageLoader::UnregisterFileLoader("pcx", NzLoader_PCX_LoadFile); + NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); } diff --git a/src/Nazara/Utility/Loaders/STB/Loader.cpp b/src/Nazara/Utility/Loaders/STB/Loader.cpp index ebdbac78f..86047d350 100644 --- a/src/Nazara/Utility/Loaders/STB/Loader.cpp +++ b/src/Nazara/Utility/Loaders/STB/Loader.cpp @@ -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 @@ -37,30 +37,16 @@ namespace static stbi_io_callbacks callbacks = {Read, Skip, Eof}; - bool NzLoader_STB_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters); - - bool NzLoader_STB_LoadFile(NzImage* image, const NzString& filePath, const NzImageParams& parameters) - { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); - return false; - } - - return NzLoader_STB_LoadStream(image, file, parameters); - } - - bool NzLoader_STB_LoadMemory(NzImage* image, const void* data, unsigned int size, const NzImageParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_STB_LoadStream(image, stream, parameters); - } - - bool NzLoader_STB_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + bool NzLoader_STB_Check(NzInputStream& stream, const NzImageParams& parameters) { NazaraUnused(parameters); + int width, height, bpp; + return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp); + } + + bool NzLoader_STB_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + { static const nzPixelFormat formats[4] = { nzPixelFormat_L8, @@ -127,34 +113,14 @@ namespace return true; } - - bool NzLoader_STB_IdentifyMemory(const void* data, unsigned int size, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - int width, height, bpp; - return stbi_info_from_memory(reinterpret_cast(data), size, &width, &height, &bpp); - } - - bool NzLoader_STB_IdentifyStream(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - int width, height, bpp; - return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp); - } } void NzLoaders_STB_Register() { - NzImageLoader::RegisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile); - NzImageLoader::RegisterMemoryLoader(NzLoader_STB_IdentifyMemory, NzLoader_STB_LoadMemory); - NzImageLoader::RegisterStreamLoader(NzLoader_STB_IdentifyStream, NzLoader_STB_LoadStream); + NzImageLoader::RegisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load); } void NzLoaders_STB_Unregister() { - NzImageLoader::UnregisterStreamLoader(NzLoader_STB_IdentifyStream, NzLoader_STB_LoadStream); - NzImageLoader::UnregisterMemoryLoader(NzLoader_STB_IdentifyMemory, NzLoader_STB_LoadMemory); - NzImageLoader::UnregisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile); + NzImageLoader::UnregisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load); } diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index f082517da..797c0bcf9 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include bool NzMeshParams::IsValid() const @@ -619,6 +620,4 @@ bool NzMesh::SetAnimation(const NzAnimation* animation) return true; } -std::list NzMesh::s_memoryLoaders; -std::list NzMesh::s_streamLoaders; -std::multimap NzMesh::s_fileLoaders; +NzMeshLoader::LoaderList NzMesh::s_loaders;