Rework modules

This commit is contained in:
Jérôme Leclercq 2020-09-10 20:12:09 +02:00
parent 385927b05a
commit a7fac3beb8
31 changed files with 568 additions and 787 deletions

View File

@ -10,46 +10,45 @@
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Config.hpp> #include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/Enums.hpp> #include <Nazara/Audio/Enums.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Math/Quaternion.hpp> #include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_AUDIO_API Audio class NAZARA_AUDIO_API Audio : public Module<Audio>
{ {
friend Module;
using Dependencies = TypeList<Core>;
public: public:
Audio() = delete; Audio();
~Audio() = delete; ~Audio();
static AudioFormat GetAudioFormat(unsigned int channelCount); AudioFormat GetAudioFormat(unsigned int channelCount);
static float GetDopplerFactor(); float GetDopplerFactor();
static float GetGlobalVolume(); float GetGlobalVolume();
static Vector3f GetListenerDirection(); Vector3f GetListenerDirection();
static Vector3f GetListenerPosition(); Vector3f GetListenerPosition();
static Quaternionf GetListenerRotation(); Quaternionf GetListenerRotation();
static Vector3f GetListenerVelocity(); Vector3f GetListenerVelocity();
static float GetSpeedOfSound(); float GetSpeedOfSound();
static bool Initialize(); bool IsFormatSupported(AudioFormat format);
void SetDopplerFactor(float dopplerFactor);
static bool IsFormatSupported(AudioFormat format); void SetGlobalVolume(float volume);
static bool IsInitialized(); void SetListenerDirection(const Vector3f& direction);
void SetListenerDirection(float dirX, float dirY, float dirZ);
static void SetDopplerFactor(float dopplerFactor); void SetListenerPosition(const Vector3f& position);
static void SetGlobalVolume(float volume); void SetListenerPosition(float x, float y, float z);
static void SetListenerDirection(const Vector3f& direction); void SetListenerRotation(const Quaternionf& rotation);
static void SetListenerDirection(float dirX, float dirY, float dirZ); void SetListenerVelocity(const Vector3f& velocity);
static void SetListenerPosition(const Vector3f& position); void SetListenerVelocity(float velX, float velY, float velZ);
static void SetListenerPosition(float x, float y, float z); void SetSpeedOfSound(float speed);
static void SetListenerRotation(const Quaternionf& rotation);
static void SetListenerVelocity(const Vector3f& velocity);
static void SetListenerVelocity(float velX, float velY, float velZ);
static void SetSpeedOfSound(float speed);
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Audio* s_instance;
}; };
} }

View File

@ -8,24 +8,26 @@
#define NAZARA_CORE_HPP #define NAZARA_CORE_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Module.hpp>
#include <Nazara/Core/TypeList.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_CORE_API Core class NAZARA_CORE_API Core : public Module<Core>
{ {
friend Module;
public: public:
Core() = delete; using Dependencies = TypeList<>;
~Core() = delete;
static bool Initialize(); Core();
~Core();
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Core* s_instance;
}; };
} }
#include <Nazara/Core/Core.inl>
#endif // NAZARA_CORE_HPP #endif // NAZARA_CORE_HPP

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -0,0 +1,40 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MODULE_HPP
#define NAZARA_MODULE_HPP
#include <Nazara/Prerequisites.hpp>
#include <string>
namespace Nz
{
template<typename T>
class Module
{
friend class Core;
public:
static T* Instance();
protected:
Module(std::string moduleName, T* pointer);
~Module();
private:
struct NoLog {};
Module(std::string moduleName, T* pointer, NoLog);
void LogInit();
std::string m_moduleName;
};
}
#include <Nazara/Core/Module.inl>
#endif // NAZARA_MODULE_HPP

View File

@ -0,0 +1,46 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Module.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
template<typename T>
Module<T>::Module(std::string moduleName, T* pointer) :
Module(std::move(moduleName), pointer, NoLog{})
{
LogInit();
}
template<typename T>
Module<T>::Module(std::string moduleName, T* pointer, NoLog) :
m_moduleName(std::move(moduleName))
{
NazaraAssert(T::s_instance == nullptr, "only one instance of " + m_moduleName + " must exist at a given time");
T::s_instance = pointer;
}
template<typename T>
Module<T>::~Module()
{
NazaraNotice("Uninitializing " + m_moduleName + "...");
T::s_instance = nullptr;
}
template<typename T>
T* Module<T>::Instance()
{
return T::s_instance;
}
template<typename T>
void Module<T>::LogInit()
{
NazaraNotice("Initializing " + m_moduleName + "...");
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -0,0 +1,48 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MODULES_HPP
#define NAZARA_MODULES_HPP
#include <Nazara/Core/TypeList.hpp>
namespace Nz
{
namespace Detail
{
template<typename>
struct BuildDepList;
template<typename Module, typename... Modules>
struct ModuleTuple : ModuleTuple<Module>, ModuleTuple<Modules...>
{
};
template<typename Module>
struct ModuleTuple<Module>
{
Module m;
};
}
template<typename... ModuleList>
class Modules
{
public:
Modules() = default;
~Modules() = default;
private:
using OrderedModuleList = TypeListUnique<typename Detail::BuildDepList<TypeList<ModuleList...>>::Result>;
using Tuple = TypeListInstantiate<OrderedModuleList, Detail::ModuleTuple>;
Tuple m_modules;
};
}
#include <Nazara/Core/Modules.inl>
#endif

View File

@ -0,0 +1,26 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Modules.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz::Detail
{
template<>
struct BuildDepList<TypeList<>>
{
using Result = TypeList<>;
};
template<typename Module, typename... ModuleList>
struct BuildDepList<TypeList<Module, ModuleList...>>
{
using ModuleDependencies = typename BuildDepList<typename Module::Dependencies>::Result;
using ModuleDependenciesIncModule = TypeListAppend<ModuleDependencies, Module>;
using RestDependencies = typename BuildDepList<TypeList<ModuleList...>>::Result;
using Result = TypeListConcat<ModuleDependenciesIncModule, RestDependencies>;
};
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -0,0 +1,64 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_TYPELIST_HPP
#define NAZARA_TYPELIST_HPP
#include <cstddef>
namespace Nz
{
template<typename...> struct TypeList {};
namespace Detail
{
template<typename, typename>
struct ListAppend;
template<typename, std::size_t>
struct ListAt;
template<typename, typename>
struct ListConcat;
template<typename, typename>
struct ListFind;
template<typename, template<typename...> typename>
struct ListInstantiate;
template<typename, typename>
struct ListPrepend;
template<typename, typename>
struct ListUnique;
}
template<typename List, typename NewType>
using TypeListAppend = typename Detail::ListAppend<List, NewType>::Result;
template<typename List, std::size_t Index>
using TypeListAt = typename Detail::ListAt<List, Index>::Type;
template<typename FirstList, typename SecondList>
using TypeListConcat = typename Detail::ListConcat<FirstList, SecondList>::Result;
template<typename List, typename Type>
constexpr bool TypeListFind = Detail::ListFind<List, Type>::Find();
template<typename List, template<typename...> typename Class>
using TypeListInstantiate = typename Detail::ListInstantiate<List, Class>::Result;
template<typename List, typename NewType>
using TypeListPrepend = typename Detail::ListPrepend<List, NewType>::Result;
template<typename List>
using TypeListUnique = typename Detail::ListUnique<TypeList<>, List>::Result;
}
#include <Nazara/Core/TypeList.inl>
#endif // NAZARA_TYPELIST_HPP

View File

@ -0,0 +1,112 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/TypeList.hpp>
#include <type_traits>
#include <Nazara/Core/Debug.hpp>
namespace Nz::Detail
{
template<typename NewType, typename... ListTypes>
struct ListAppend<TypeList<ListTypes...>, NewType>
{
using Result = TypeList<ListTypes..., NewType>;
};
template<typename T, typename... ListTypes>
struct ListAt<TypeList<T, ListTypes...>, 0>
{
using Type = T;
};
template<std::size_t Index, typename T, typename... ListTypes>
struct ListAt<TypeList<T, ListTypes...>, Index>
{
static_assert(Index <= sizeof...(ListTypes), "Index out of range");
using Type = typename ListAt<TypeList<ListTypes...>, Index - 1>::Type;
};
template<typename... First>
struct ListConcat<TypeList<First...>, TypeList<>>
{
using Result = TypeList<First...>;
};
template<typename... Second>
struct ListConcat<TypeList<>, TypeList<Second...>>
{
using Result = TypeList<Second...>;
};
template<typename... First, typename T>
struct ListConcat<TypeList<First...>, TypeList<T>>
{
using Result = TypeList<First..., T>;
};
template<typename... First, typename T1, typename T2, typename... Second>
struct ListConcat<TypeList<First...>, TypeList<T1, T2, Second...>>
{
using Result = typename ListConcat<TypeList<First..., T1>, TypeList<T2, Second...>>::Result;
};
struct ListFindHelper
{
template<typename ToFind, typename Type, typename... Rest> static constexpr bool Find()
{
if constexpr (std::is_same_v<ToFind, Type>)
return true;
else
return Find<ToFind, Rest...>();
}
template<typename ToFind> static constexpr bool Find()
{
return false;
}
};
template<typename TypeToFind, typename... ListTypes>
struct ListFind<TypeList<ListTypes...>, TypeToFind>
{
static constexpr bool Find()
{
return ListFindHelper::Find<TypeToFind, ListTypes...>();
}
};
template<template<typename...> typename Class, typename... ListTypes>
struct ListInstantiate<TypeList<ListTypes...>, Class>
{
using Result = Class<ListTypes...>;
};
template<typename NewType, typename... ListTypes>
struct ListPrepend<TypeList<ListTypes...>, NewType>
{
using Result = TypeList<NewType, ListTypes...>;
};
template<typename... Types, typename T1>
struct ListUnique<TypeList<Types...>, TypeList<T1>>
{
static constexpr bool IsTypePresent = ListFind<TypeList<Types...>, T1>::Find();
using Result = std::conditional_t<!IsTypePresent, TypeList<Types..., T1>, TypeList<Types...>>;
};
template<typename... Types, typename T1, typename T2, typename... Rest>
struct ListUnique<TypeList<Types...>, TypeList<T1, T2, Rest...>>
{
using Result = typename ListUnique<typename ListUnique<TypeList<Types...>, TypeList<T1>>::Result, TypeList<T2, Rest...>>::Result;
};
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -8,25 +8,24 @@
#define NAZARA_MODULENAME_HPP #define NAZARA_MODULENAME_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Network/Config.hpp> #include <Nazara/Network/Config.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_NETWORK_API Network class NAZARA_NETWORK_API Network : public Module<Network>
{ {
friend Module;
public: public:
Network() = delete; using Dependencies = TypeList<Core>;
~Network() = delete;
static bool Initialize(); Network();
~Network();
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Network* s_instance;
}; };
} }
#endif // NAZARA_MODULENAME_HPP #endif // NAZARA_MODULENAME_HPP

View File

@ -8,24 +8,23 @@
#define NAZARA_PHYSICS2D_HPP #define NAZARA_PHYSICS2D_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Physics2D/Config.hpp> #include <Nazara/Physics2D/Config.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_PHYSICS2D_API Physics2D class NAZARA_PHYSICS2D_API Physics2D : public Module<Physics2D>
{ {
friend Module;
public: public:
Physics2D() = delete; using Dependencies = TypeList<Core>;
~Physics2D() = delete;
static bool Initialize(); Physics2D();
~Physics2D() = default;
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Physics2D* s_instance;
}; };
} }

View File

@ -8,26 +8,25 @@
#define NAZARA_PHYSICS3D_HPP #define NAZARA_PHYSICS3D_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Physics3D/Config.hpp> #include <Nazara/Physics3D/Config.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_PHYSICS3D_API Physics3D class NAZARA_PHYSICS3D_API Physics3D : public Module<Physics3D>
{ {
friend Module;
public: public:
Physics3D() = delete; using Dependencies = TypeList<Core>;
~Physics3D() = delete;
static unsigned int GetMemoryUsed(); Physics3D();
~Physics3D();
static bool Initialize(); unsigned int GetMemoryUsed();
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Physics3D* s_instance;
}; };
} }

View File

@ -8,24 +8,23 @@
#define NAZARA_PLATFORM_HPP #define NAZARA_PLATFORM_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Platform/Config.hpp> #include <Nazara/Platform/Config.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_PLATFORM_API Platform class NAZARA_PLATFORM_API Platform : public Module<Platform>
{ {
friend Module;
public: public:
Platform() = delete; using Dependencies = TypeList<Utility>;
~Platform() = delete;
static bool Initialize(); Platform();
~Platform();
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Platform* s_instance;
}; };
} }

View File

@ -119,8 +119,6 @@
#define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_LINUX
#define NAZARA_PLATFORM_POSIX #define NAZARA_PLATFORM_POSIX
#define NAZARA_PLATFORM_GLX
#define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_EXPORT __attribute__((visibility ("default")))
#define NAZARA_IMPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default")))
/*#elif defined(__APPLE__) && defined(__MACH__) /*#elif defined(__APPLE__) && defined(__MACH__)

View File

@ -9,38 +9,32 @@
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp> #include <Nazara/Core/DynLib.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Renderer/Config.hpp> #include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/RendererImpl.hpp> #include <Nazara/Renderer/RendererImpl.hpp>
#include <Nazara/Utility/Enums.hpp>
namespace Nz namespace Nz
{ {
class AbstractBuffer; class AbstractBuffer;
class Buffer; class Buffer;
class NAZARA_RENDERER_API Renderer class NAZARA_RENDERER_API Renderer : public Module<Renderer>
{ {
friend Module;
public: public:
Renderer() = delete; using Dependencies = TypeList<Platform>;
~Renderer() = delete;
static inline RendererImpl* GetRendererImpl(); Renderer();
~Renderer();
static bool Initialize(); inline RendererImpl* GetRendererImpl();
static inline bool IsInitialized();
static inline void SetParameters(const ParameterList& parameters);
static void Uninitialize();
private: private:
static AbstractBuffer* CreateHardwareBufferImpl(Buffer* parent, BufferType type); std::unique_ptr<RendererImpl> m_rendererImpl;
DynLib m_rendererLib;
static std::unique_ptr<RendererImpl> s_rendererImpl; static Renderer* s_instance;
static DynLib s_rendererLib;
static ParameterList s_initializationParameters;
static unsigned int s_moduleReferenceCounter;
}; };
} }

View File

@ -9,17 +9,7 @@ namespace Nz
{ {
inline RendererImpl* Renderer::GetRendererImpl() inline RendererImpl* Renderer::GetRendererImpl()
{ {
return s_rendererImpl.get(); return m_rendererImpl.get();
}
inline bool Renderer::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
void Renderer::SetParameters(const ParameterList& parameters)
{
s_initializationParameters = parameters;
} }
} }

View File

@ -8,25 +8,23 @@
#define NAZARA_SHADER_HPP #define NAZARA_SHADER_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Initializer.hpp> #include <Nazara/Core/Core.hpp>
#include <Nazara/Shader/Config.hpp> #include <Nazara/Shader/Config.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_SHADER_API Shader class NAZARA_SHADER_API Shader : public Module<Shader>
{ {
friend Module;
public: public:
Shader() = delete; using Dependencies = TypeList<Core>;
~Shader() = delete;
static bool Initialize(); Shader();
~Shader() = default;
static bool IsInitialized();
static void Uninitialize();
private: private:
static unsigned int s_moduleReferenceCounter; static Shader* s_instance;
}; };
} }

View File

@ -8,28 +8,23 @@
#define NAZARA_UTILITY_HPP #define NAZARA_UTILITY_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
namespace Nz namespace Nz
{ {
class NAZARA_UTILITY_API Utility class NAZARA_UTILITY_API Utility : public Module<Utility>
{ {
friend Module;
public: public:
Utility() = delete; using Dependencies = TypeList<Core>;
~Utility() = delete;
static bool Initialize(); Utility();
~Utility();
static bool IsInitialized();
static void Uninitialize();
static unsigned int ComponentCount[ComponentType_Max+1];
static std::size_t ComponentStride[ComponentType_Max+1];
private: private:
static unsigned int s_moduleReferenceCounter; static Utility* s_instance;
}; };
} }

View File

@ -12,6 +12,7 @@
#include <Nazara/Core/Core.hpp> #include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <stdexcept>
#include <Nazara/Audio/Debug.hpp> #include <Nazara/Audio/Debug.hpp>
namespace Nz namespace Nz
@ -22,6 +23,32 @@ namespace Nz
* \brief Audio class that represents the module initializer of Audio * \brief Audio class that represents the module initializer of Audio
*/ */
Audio::Audio() :
Module("Audio", this)
{
// Initialisation of OpenAL
if (!OpenAL::Initialize())
throw std::runtime_error("failed to initialize OpenAL");
if (!SoundBuffer::Initialize())
throw std::runtime_error("failed to initialize sound buffers");
// Definition of the orientation by default
SetListenerDirection(Vector3f::Forward());
// Loaders
Loaders::Register_sndfile();
}
Audio::~Audio()
{
// Loaders
Loaders::Unregister_sndfile();
SoundBuffer::Uninitialize();
OpenAL::Uninitialize();
}
/*! /*!
* \brief Gets the format of the audio * \brief Gets the format of the audio
* \return AudioFormat Enumeration type for the format * \return AudioFormat Enumeration type for the format
@ -142,59 +169,6 @@ namespace Nz
return alGetFloat(AL_SPEED_OF_SOUND); return alGetFloat(AL_SPEED_OF_SOUND);
} }
/*!
* \brief Initializes the Audio module
* \return true if initialization is successful
*
* \remark Produces a NazaraError if initialization of modules Core, OpenAL or SoundBuffer failed
* \remark Produces a NazaraNotice
*/
bool Audio::Initialize()
{
if (IsInitialized())
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialisation of dependencies
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
// Initialisation of the module
CallOnExit onExit(Audio::Uninitialize);
// Initialisation of OpenAL
if (!OpenAL::Initialize())
{
NazaraError("Failed to initialize OpenAL");
return false;
}
if (!SoundBuffer::Initialize())
{
NazaraError("Failed to initialize sound buffers");
return false;
}
// Definition of the orientation by default
SetListenerDirection(Vector3f::Forward());
// Loaders
Loaders::Register_sndfile();
onExit.Reset();
NazaraNotice("Initialized: Audio module");
return true;
}
/*! /*!
* \brief Checks whether the format is supported by the engine * \brief Checks whether the format is supported by the engine
* \return true if it is the case * \return true if it is the case
@ -210,16 +184,6 @@ namespace Nz
return OpenAL::AudioFormat[format] != 0; return OpenAL::AudioFormat[format] != 0;
} }
/*!
* \brief Checks whether the module is initialized
* \return true if module is initialized
*/
bool Audio::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
/*! /*!
* \brief Sets the factor of the doppler effect * \brief Sets the factor of the doppler effect
* *
@ -367,37 +331,5 @@ namespace Nz
alSpeedOfSound(speed); alSpeedOfSound(speed);
} }
/*! Audio* Audio::s_instance = nullptr;
* \brief Uninitializes the Audio module
*
* \remark Produces a NazaraNotice
*/
void Audio::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// The module is still in use, or can not be uninitialized
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Free of module
s_moduleReferenceCounter = 0;
// Loaders
Loaders::Unregister_sndfile();
SoundBuffer::Uninitialize();
OpenAL::Uninitialize();
NazaraNotice("Uninitialized: Audio module");
// Free of dependencies
Core::Uninitialize();
}
unsigned int Audio::s_moduleReferenceCounter = 0;
} }

View File

@ -152,7 +152,7 @@ namespace Nz
m_handle = nullptr; m_handle = nullptr;
}); });
m_format = Audio::GetAudioFormat(infos.channels); m_format = Audio::Instance()->GetAudioFormat(infos.channels);
if (m_format == AudioFormat_Unknown) if (m_format == AudioFormat_Unknown)
{ {
NazaraError("Channel count not handled"); NazaraError("Channel count not handled");
@ -327,7 +327,7 @@ namespace Nz
sf_close(file); sf_close(file);
}); });
AudioFormat format = Audio::GetAudioFormat(info.channels); AudioFormat format = Audio::Instance()->GetAudioFormat(info.channels);
if (format == AudioFormat_Unknown) if (format == AudioFormat_Unknown)
{ {
NazaraError("Channel count not handled"); NazaraError("Channel count not handled");

View File

@ -259,7 +259,7 @@ namespace Nz
*/ */
bool SoundBuffer::IsFormatSupported(AudioFormat format) bool SoundBuffer::IsFormatSupported(AudioFormat format)
{ {
return Audio::IsFormatSupported(format); return Audio::Instance()->IsFormatSupported(format);
} }
/*! /*!

View File

@ -4,6 +4,7 @@
#include <Nazara/Core/Core.hpp> #include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Config.hpp> #include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/HardwareInfo.hpp> #include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <Nazara/Core/PluginManager.hpp> #include <Nazara/Core/PluginManager.hpp>
@ -15,69 +16,24 @@ namespace Nz
/*! /*!
* \ingroup core * \ingroup core
* \class Nz::Core * \class Nz::Core
* \brief Core class that represents the module initializer of Core * \brief Core class that represents the Core module
*/ */
/*! Core::Core() :
* \brief Initializes the Core module Module("Core", this, Module::NoLog{})
* \return true if initialization is successful
*
* \remark Produces a NazaraNotice
*/
bool Core::Initialize()
{ {
if (IsInitialized())
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
s_moduleReferenceCounter++;
Log::Initialize(); Log::Initialize();
NazaraNotice("Initialized: Core"); LogInit();
return true;
} }
/*! Core::~Core()
* \brief Checks whether the module is initialized
* \return true if module is initialized
*/
bool Core::IsInitialized()
{ {
return s_moduleReferenceCounter != 0;
}
/*!
* \brief Uninitializes the Core module
*
* \remark Produces a NazaraNotice
*/
void Core::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// The module is still in use, or can not be uninitialized
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Free of module
s_moduleReferenceCounter = 0;
HardwareInfo::Uninitialize(); HardwareInfo::Uninitialize();
Log::Uninitialize(); Log::Uninitialize();
PluginManager::Uninitialize(); PluginManager::Uninitialize();
TaskScheduler::Uninitialize(); TaskScheduler::Uninitialize();
NazaraNotice("Uninitialized: Core");
} }
unsigned int Core::s_moduleReferenceCounter = 0; Core* Core::s_instance = nullptr;
} }

View File

@ -19,6 +19,8 @@
#error Missing implementation: Network #error Missing implementation: Network
#endif #endif
#include <stdexcept>
#include <Nazara/Network/Debug.hpp> #include <Nazara/Network/Debug.hpp>
namespace Nz namespace Nz
@ -29,98 +31,28 @@ namespace Nz
* \brief Network class that represents the module initializer of Network * \brief Network class that represents the module initializer of Network
*/ */
/*! Network::Network() :
* \brief Initializes the Network module Module("Network", this)
* \return true if initialization is successful
*
* \remark Produces a NazaraNotice
* \remark Produces a NazaraError if one submodule failed
*/
bool Network::Initialize()
{ {
if (IsInitialized())
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialize module dependencies
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
CallOnExit onExit(Network::Uninitialize);
// Initialize module here // Initialize module here
if (!SocketImpl::Initialize()) if (!SocketImpl::Initialize())
{ throw std::runtime_error("failed to initialize socket implementation");
NazaraError("Failed to initialize socket implementation");
return false;
}
if (!NetPacket::Initialize()) if (!NetPacket::Initialize())
{ throw std::runtime_error("failed to initialize packets");
NazaraError("Failed to initialize packets");
return false;
}
if (!RUdpConnection::Initialize()) if (!RUdpConnection::Initialize())
{ throw std::runtime_error("failed to initialize RUDP protocol");
NazaraError("Failed to initialize RUdp");
return false;
}
onExit.Reset();
NazaraNotice("Initialized: Network module");
return true;
} }
/*! Network::~Network()
* \brief Checks whether the module is initialized
* \return true if module is initialized
*/
bool Network::IsInitialized()
{ {
return s_moduleReferenceCounter != 0;
}
/*!
* \brief Uninitializes the Network module
*
* \remark Produces a NazaraNotice
*/
void Network::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Either the module is not initialized, either it was initialized multiple times
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
s_moduleReferenceCounter = 0;
// Uninitialize module here // Uninitialize module here
RUdpConnection::Uninitialize(); RUdpConnection::Uninitialize();
NetPacket::Uninitialize(); NetPacket::Uninitialize();
SocketImpl::Uninitialize(); SocketImpl::Uninitialize();
NazaraNotice("Uninitialized: Network module");
// Free module dependencies
Core::Uninitialize();
} }
unsigned int Network::s_moduleReferenceCounter = 0; Network* Network::s_instance = nullptr;
} }

View File

@ -3,57 +3,14 @@
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Physics2D.hpp> #include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Physics2D/Debug.hpp> #include <Nazara/Physics2D/Debug.hpp>
namespace Nz namespace Nz
{ {
bool Physics2D::Initialize() Physics2D::Physics2D() :
Module("Physics2D", this)
{ {
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Déjà initialisé
}
// Initialisation des dépendances
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
NazaraNotice("Initialized: Physics2D module");
return true;
} }
bool Physics2D::IsInitialized() Physics2D* Physics2D::s_instance = nullptr;
{
return s_moduleReferenceCounter != 0;
}
void Physics2D::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Libération du module
s_moduleReferenceCounter = 0;
NazaraNotice("Uninitialized: Physics2D module");
// Libération des dépendances
Core::Uninitialize();
}
unsigned int Physics2D::s_moduleReferenceCounter = 0;
} }

View File

@ -13,65 +13,22 @@
namespace Nz namespace Nz
{ {
Physics3D::Physics3D() :
Module("Physics3D", this)
{
if (!Collider3D::Initialize())
throw std::runtime_error("failed to initialize colliders");
}
Physics3D::~Physics3D()
{
Collider3D::Uninitialize();
}
unsigned int Physics3D::GetMemoryUsed() unsigned int Physics3D::GetMemoryUsed()
{ {
return NewtonGetMemoryUsed(); return NewtonGetMemoryUsed();
} }
bool Physics3D::Initialize() Physics3D* Physics3D::s_instance;
{
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Déjà initialisé
}
// Initialisation des dépendances
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
// Initialisation du module
if (!Collider3D::Initialize())
{
NazaraError("Failed to initialize geoms");
return false;
}
NazaraNotice("Initialized: Physics3D module");
return true;
}
bool Physics3D::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
void Physics3D::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Libération du module
Collider3D::Uninitialize();
s_moduleReferenceCounter = 0;
NazaraNotice("Uninitialized: Physics3D module");
// Libération des dépendances
Core::Uninitialize();
}
unsigned int Physics3D::s_moduleReferenceCounter = 0;
} }

View File

@ -7,7 +7,6 @@
#include <Nazara/Platform/Config.hpp> #include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp> #include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Window.hpp> #include <Nazara/Platform/Window.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Platform/Debug.hpp> #include <Nazara/Platform/Debug.hpp>
namespace Nz namespace Nz
@ -18,91 +17,22 @@ namespace Nz
* \brief Platform class that represents the module initializer of Platform * \brief Platform class that represents the module initializer of Platform
*/ */
/*! Platform::Platform() :
* \brief Initializes the Platform module Module("Platform", this)
* \return true if initialization is successful
*
* \remark Produces a NazaraNotice
* \remark Produces a NazaraError if one submodule failed
*/
bool Platform::Initialize()
{ {
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialize module dependencies
if (!Utility::Initialize())
{
NazaraError("Failed to initialize utility module");
return false;
}
s_moduleReferenceCounter++;
// Initialisation of the module
CallOnExit onExit(Platform::Uninitialize);
if (!Window::Initialize()) if (!Window::Initialize())
{ throw std::runtime_error("failed to initialize window system");
NazaraError("Failed to initialize window's system");
return false;
}
// Must be initialized after Window // Must be initialized after Window
if (!Cursor::Initialize()) if (!Cursor::Initialize())
{ throw std::runtime_error("failed to initialize cursors");
NazaraError("Failed to initialize cursors");
return false;
}
onExit.Reset();
NazaraNotice("Initialized: Platform module");
return true;
} }
/*! Platform::~Platform()
* \brief Checks whether the module is initialized
* \return true if module is initialized
*/
bool Platform::IsInitialized()
{ {
return s_moduleReferenceCounter != 0;
}
/*!
* \brief Uninitializes the Platform module
*
* \remark Produces a NazaraNotice
*/
void Platform::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// The module is still in use, or can not be uninitialized
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Free of module
s_moduleReferenceCounter = 0;
Cursor::Uninitialize(); //< Must be done before Window Cursor::Uninitialize(); //< Must be done before Window
Window::Uninitialize(); Window::Uninitialize();
NazaraNotice("Uninitialized: Platform module");
// Free of dependances
Utility::Uninitialize();
} }
unsigned int Platform::s_moduleReferenceCounter = 0; Platform* Platform::s_instance;
} }

View File

@ -38,7 +38,7 @@ namespace Nz
bool RenderWindow::OnWindowCreated() bool RenderWindow::OnWindowCreated()
{ {
RendererImpl *rendererImpl = Renderer::GetRendererImpl(); RendererImpl *rendererImpl = Renderer::Instance()->GetRendererImpl();
auto surface = rendererImpl->CreateRenderSurfaceImpl(); auto surface = rendererImpl->CreateRenderSurfaceImpl();
if (!surface->Create(GetSystemHandle())) if (!surface->Create(GetSystemHandle()))
{ {

View File

@ -13,6 +13,7 @@
#include <Nazara/Utility/Buffer.hpp> #include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Utility.hpp> #include <Nazara/Utility/Utility.hpp>
#include <filesystem> #include <filesystem>
#include <stdexcept>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
#ifdef NAZARA_PLATFORM_WINDOWS #ifdef NAZARA_PLATFORM_WINDOWS
@ -29,31 +30,9 @@
namespace Nz namespace Nz
{ {
bool Renderer::Initialize() Renderer::Renderer() :
Module("Renderer", this)
{ {
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialize module dependencies
if (!Utility::Initialize())
{
NazaraError("Failed to initialize Utility module");
return false;
}
if (!Platform::Initialize())
{
NazaraError("Failed to initialize Platform module");
return false;
}
s_moduleReferenceCounter++;
CallOnExit onExit(Renderer::Uninitialize);
struct RendererImplementations struct RendererImplementations
{ {
std::filesystem::path fileName; std::filesystem::path fileName;
@ -106,7 +85,7 @@ namespace Nz
} }
std::unique_ptr<RendererImpl> impl(createRenderer()); std::unique_ptr<RendererImpl> impl(createRenderer());
if (!impl || !impl->Prepare(s_initializationParameters)) if (!impl || !impl->Prepare({}))
{ {
NazaraError("Failed to create renderer implementation"); NazaraError("Failed to create renderer implementation");
continue; continue;
@ -120,57 +99,23 @@ namespace Nz
} }
if (!chosenImpl) if (!chosenImpl)
{ throw std::runtime_error("no renderer found");
NazaraError("No renderer found");
return false;
}
s_rendererImpl = std::move(chosenImpl); m_rendererImpl = std::move(chosenImpl);
s_rendererLib = std::move(chosenLib); m_rendererLib = std::move(chosenLib);
NazaraDebug("Using " + s_rendererImpl->QueryAPIString() + " as renderer"); NazaraDebug("Using " + m_rendererImpl->QueryAPIString() + " as renderer");
Buffer::SetBufferFactory(DataStorage_Hardware, CreateHardwareBufferImpl); Buffer::SetBufferFactory(DataStorage_Hardware, [](Buffer* parent, BufferType type) -> AbstractBuffer* { return new RenderBuffer(parent, type); });
onExit.Reset();
NazaraNotice("Initialized: Renderer module");
return true;
} }
void Renderer::Uninitialize() Renderer::~Renderer()
{ {
if (s_moduleReferenceCounter != 1)
{
// Either the module is not initialized, either it was initialized multiple times
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
s_moduleReferenceCounter = 0;
// Uninitialize module here // Uninitialize module here
Buffer::SetBufferFactory(DataStorage_Hardware, nullptr); Buffer::SetBufferFactory(DataStorage_Hardware, nullptr);
s_rendererImpl.reset(); m_rendererImpl.reset();
s_rendererLib.Unload();
NazaraNotice("Uninitialized: Renderer module");
// Free module dependencies
Platform::Uninitialize();
Utility::Uninitialize();
} }
AbstractBuffer* Renderer::CreateHardwareBufferImpl(Buffer* parent, BufferType type) Renderer* Renderer::s_instance = nullptr;
{
return new RenderBuffer(parent, type);
}
std::unique_ptr<RendererImpl> Renderer::s_rendererImpl;
DynLib Renderer::s_rendererLib;
ParameterList Renderer::s_initializationParameters;
unsigned int Renderer::s_moduleReferenceCounter = 0;
} }

View File

@ -3,68 +3,15 @@
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Shader.hpp> #include <Nazara/Shader/Shader.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Shader/Config.hpp>
#include <Nazara/Shader/Debug.hpp> #include <Nazara/Shader/Debug.hpp>
namespace Nz namespace Nz
{ {
bool Shader::Initialize() Shader::Shader() :
Module("Shader", this)
{ {
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialize module dependencies
if (!Core::Initialize())
{
NazaraError("Failed to initialize shader module");
return false;
}
s_moduleReferenceCounter++;
CallOnExit onExit(Shader::Uninitialize);
// Initialize module here
onExit.Reset();
NazaraNotice("Initialized: Shader module");
return true;
} }
bool Shader::IsInitialized() Shader* Shader::s_instance = nullptr;
{
return s_moduleReferenceCounter != 0;
}
void Shader::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Either the module is not initialized, either it was initialized multiple times
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
s_moduleReferenceCounter = 0;
// Uninitialize module here
NazaraNotice("Uninitialized: Shader module");
// Free module dependencies
Core::Uninitialize();
}
unsigned int Shader::s_moduleReferenceCounter = 0;
} }

View File

@ -25,6 +25,7 @@
#include <Nazara/Utility/Formats/PCXLoader.hpp> #include <Nazara/Utility/Formats/PCXLoader.hpp>
#include <Nazara/Utility/Formats/STBLoader.hpp> #include <Nazara/Utility/Formats/STBLoader.hpp>
#include <Nazara/Utility/Formats/STBSaver.hpp> #include <Nazara/Utility/Formats/STBSaver.hpp>
#include <stdexcept>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
namespace Nz namespace Nz
@ -35,81 +36,32 @@ namespace Nz
* \brief Utility class that represents the module initializer of Utility * \brief Utility class that represents the module initializer of Utility
*/ */
/*! Utility::Utility() :
* \brief Initializes the Utility module Module("Utility", this)
* \return true if initialization is successful
*
* \remark Produces a NazaraNotice
* \remark Produces a NazaraError if one submodule failed
*/
bool Utility::Initialize()
{ {
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Already initialized
}
// Initialisation of dependencies
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
// Initialisation du module
CallOnExit onExit(Utility::Uninitialize);
if (!Animation::Initialize()) if (!Animation::Initialize())
{ throw std::runtime_error("failed to initialize animations");
NazaraError("Failed to initialize animations");
return false;
}
if (!Buffer::Initialize()) if (!Buffer::Initialize())
{ throw std::runtime_error("failed to initialize buffers");
NazaraError("Failed to initialize buffers");
return false;
}
if (!Font::Initialize()) if (!Font::Initialize())
{ throw std::runtime_error("failed to initialize fonts");
NazaraError("Failed to initialize fonts");
return false;
}
if (!Image::Initialize()) if (!Image::Initialize())
{ throw std::runtime_error("failed to initialize images");
NazaraError("Failed to initialize images");
return false;
}
if (!Mesh::Initialize()) if (!Mesh::Initialize())
{ throw std::runtime_error("failed to initialize meshes");
NazaraError("Failed to initialize meshes");
return false;
}
if (!PixelFormatInfo::Initialize()) if (!PixelFormatInfo::Initialize())
{ throw std::runtime_error("failed to initialize pixel formats");
NazaraError("Failed to initialize pixel formats");
return false;
}
if (!Skeleton::Initialize()) if (!Skeleton::Initialize())
{ throw std::runtime_error("failed to initialize skeletons");
NazaraError("Failed to initialize skeletons");
return false;
}
if (!VertexDeclaration::Initialize()) if (!VertexDeclaration::Initialize())
{ throw std::runtime_error("failed to initialize vertex declarations");
NazaraError("Failed to initialize vertex declarations");
return false;
}
// On enregistre les loaders pour les extensions // On enregistre les loaders pour les extensions
// Il s'agit ici d'une liste LIFO, le dernier loader enregistré possède la priorité // Il s'agit ici d'une liste LIFO, le dernier loader enregistré possède la priorité
@ -138,32 +90,10 @@ namespace Nz
// Image // Image
Loaders::RegisterPCX(); // Loader de fichiers .pcx (1, 4, 8, 24 bits) Loaders::RegisterPCX(); // Loader de fichiers .pcx (1, 4, 8, 24 bits)
onExit.Reset();
NazaraNotice("Initialized: Utility module");
return true;
} }
bool Utility::IsInitialized() Utility::~Utility()
{ {
return s_moduleReferenceCounter != 0;
}
void Utility::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Libération du module
s_moduleReferenceCounter = 0;
Loaders::UnregisterFreeType(); Loaders::UnregisterFreeType();
Loaders::UnregisterMD2(); Loaders::UnregisterMD2();
Loaders::UnregisterMD5Anim(); Loaders::UnregisterMD5Anim();
@ -182,52 +112,7 @@ namespace Nz
Font::Uninitialize(); Font::Uninitialize();
Buffer::Uninitialize(); Buffer::Uninitialize();
Animation::Uninitialize(); Animation::Uninitialize();
NazaraNotice("Uninitialized: Utility module");
// Libération des dépendances
Core::Uninitialize();
} }
unsigned int Utility::ComponentCount[ComponentType_Max+1] = Utility* Utility::s_instance = nullptr;
{
4, // ComponentType_Color
1, // ComponentType_Double1
2, // ComponentType_Double2
3, // ComponentType_Double3
4, // ComponentType_Double4
1, // ComponentType_Float1
2, // ComponentType_Float2
3, // ComponentType_Float3
4, // ComponentType_Float4
1, // ComponentType_Int1
2, // ComponentType_Int2
3, // ComponentType_Int3
4, // ComponentType_Int4
4 // ComponentType_Quaternion
};
static_assert(ComponentType_Max+1 == 14, "Component count array is incomplete");
std::size_t Utility::ComponentStride[ComponentType_Max+1] =
{
4*sizeof(UInt8), // ComponentType_Color
1*sizeof(double), // ComponentType_Double1
2*sizeof(double), // ComponentType_Double2
3*sizeof(double), // ComponentType_Double3
4*sizeof(double), // ComponentType_Double4
1*sizeof(float), // ComponentType_Float1
2*sizeof(float), // ComponentType_Float2
3*sizeof(float), // ComponentType_Float3
4*sizeof(float), // ComponentType_Float4
1*sizeof(UInt32), // ComponentType_Int1
2*sizeof(UInt32), // ComponentType_Int2
3*sizeof(UInt32), // ComponentType_Int3
4*sizeof(UInt32), // ComponentType_Int4
4*sizeof(float) // ComponentType_Quaternion
};
static_assert(ComponentType_Max+1 == 14, "Component stride array is incomplete");
unsigned int Utility::s_moduleReferenceCounter = 0;
} }

View File

@ -14,6 +14,26 @@
namespace Nz namespace Nz
{ {
namespace
{
std::size_t s_componentStride[ComponentType_Max + 1] =
{
4 * sizeof(UInt8), // ComponentType_Color
1 * sizeof(double), // ComponentType_Double1
2 * sizeof(double), // ComponentType_Double2
3 * sizeof(double), // ComponentType_Double3
4 * sizeof(double), // ComponentType_Double4
1 * sizeof(float), // ComponentType_Float1
2 * sizeof(float), // ComponentType_Float2
3 * sizeof(float), // ComponentType_Float3
4 * sizeof(float), // ComponentType_Float4
1 * sizeof(UInt32), // ComponentType_Int1
2 * sizeof(UInt32), // ComponentType_Int2
3 * sizeof(UInt32), // ComponentType_Int3
4 * sizeof(UInt32), // ComponentType_Int4
4 * sizeof(float) // ComponentType_Quaternion
};
}
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) : VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
m_inputRate(inputRate) m_inputRate(inputRate)
{ {
@ -42,7 +62,7 @@ namespace Nz
component.offset = offset; component.offset = offset;
component.type = entry.type; component.type = entry.type;
offset += Utility::ComponentStride[component.type]; offset += s_componentStride[component.type];
} }
m_stride = offset; m_stride = offset;