Rework modules
This commit is contained in:
parent
385927b05a
commit
a7fac3beb8
|
|
@ -10,46 +10,45 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Audio/Config.hpp>
|
||||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_AUDIO_API Audio
|
||||
class NAZARA_AUDIO_API Audio : public Module<Audio>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
public:
|
||||
Audio() = delete;
|
||||
~Audio() = delete;
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
static AudioFormat GetAudioFormat(unsigned int channelCount);
|
||||
static float GetDopplerFactor();
|
||||
static float GetGlobalVolume();
|
||||
static Vector3f GetListenerDirection();
|
||||
static Vector3f GetListenerPosition();
|
||||
static Quaternionf GetListenerRotation();
|
||||
static Vector3f GetListenerVelocity();
|
||||
static float GetSpeedOfSound();
|
||||
AudioFormat GetAudioFormat(unsigned int channelCount);
|
||||
float GetDopplerFactor();
|
||||
float GetGlobalVolume();
|
||||
Vector3f GetListenerDirection();
|
||||
Vector3f GetListenerPosition();
|
||||
Quaternionf GetListenerRotation();
|
||||
Vector3f GetListenerVelocity();
|
||||
float GetSpeedOfSound();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsFormatSupported(AudioFormat format);
|
||||
static bool IsInitialized();
|
||||
|
||||
static void SetDopplerFactor(float dopplerFactor);
|
||||
static void SetGlobalVolume(float volume);
|
||||
static void SetListenerDirection(const Vector3f& direction);
|
||||
static void SetListenerDirection(float dirX, float dirY, float dirZ);
|
||||
static void SetListenerPosition(const Vector3f& position);
|
||||
static void SetListenerPosition(float x, float y, float z);
|
||||
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();
|
||||
bool IsFormatSupported(AudioFormat format);
|
||||
void SetDopplerFactor(float dopplerFactor);
|
||||
void SetGlobalVolume(float volume);
|
||||
void SetListenerDirection(const Vector3f& direction);
|
||||
void SetListenerDirection(float dirX, float dirY, float dirZ);
|
||||
void SetListenerPosition(const Vector3f& position);
|
||||
void SetListenerPosition(float x, float y, float z);
|
||||
void SetListenerRotation(const Quaternionf& rotation);
|
||||
void SetListenerVelocity(const Vector3f& velocity);
|
||||
void SetListenerVelocity(float velX, float velY, float velZ);
|
||||
void SetSpeedOfSound(float speed);
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Audio* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,24 +8,26 @@
|
|||
#define NAZARA_CORE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Module.hpp>
|
||||
#include <Nazara/Core/TypeList.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API Core
|
||||
class NAZARA_CORE_API Core : public Module<Core>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Core() = delete;
|
||||
~Core() = delete;
|
||||
using Dependencies = TypeList<>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
Core();
|
||||
~Core();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Core* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Core.inl>
|
||||
|
||||
#endif // NAZARA_CORE_HPP
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
@ -8,25 +8,24 @@
|
|||
#define NAZARA_MODULENAME_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Network/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_NETWORK_API Network
|
||||
class NAZARA_NETWORK_API Network : public Module<Network>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Network() = delete;
|
||||
~Network() = delete;
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
Network();
|
||||
~Network();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
static Network* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_MODULENAME_HPP
|
||||
|
|
|
|||
|
|
@ -8,24 +8,23 @@
|
|||
#define NAZARA_PHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API Physics2D
|
||||
class NAZARA_PHYSICS2D_API Physics2D : public Module<Physics2D>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Physics2D() = delete;
|
||||
~Physics2D() = delete;
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
Physics2D();
|
||||
~Physics2D() = default;
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Physics2D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,26 +8,25 @@
|
|||
#define NAZARA_PHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physics3D
|
||||
class NAZARA_PHYSICS3D_API Physics3D : public Module<Physics3D>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Physics3D() = delete;
|
||||
~Physics3D() = delete;
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
static unsigned int GetMemoryUsed();
|
||||
Physics3D();
|
||||
~Physics3D();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
unsigned int GetMemoryUsed();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Physics3D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,24 +8,23 @@
|
|||
#define NAZARA_PLATFORM_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PLATFORM_API Platform
|
||||
class NAZARA_PLATFORM_API Platform : public Module<Platform>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Platform() = delete;
|
||||
~Platform() = delete;
|
||||
using Dependencies = TypeList<Utility>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
Platform();
|
||||
~Platform();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Platform* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,8 +119,6 @@
|
|||
#define NAZARA_PLATFORM_LINUX
|
||||
#define NAZARA_PLATFORM_POSIX
|
||||
|
||||
#define NAZARA_PLATFORM_GLX
|
||||
|
||||
#define NAZARA_EXPORT __attribute__((visibility ("default")))
|
||||
#define NAZARA_IMPORT __attribute__((visibility ("default")))
|
||||
/*#elif defined(__APPLE__) && defined(__MACH__)
|
||||
|
|
|
|||
|
|
@ -9,38 +9,32 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractBuffer;
|
||||
class Buffer;
|
||||
|
||||
class NAZARA_RENDERER_API Renderer
|
||||
class NAZARA_RENDERER_API Renderer : public Module<Renderer>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Renderer() = delete;
|
||||
~Renderer() = delete;
|
||||
using Dependencies = TypeList<Platform>;
|
||||
|
||||
static inline RendererImpl* GetRendererImpl();
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static inline bool IsInitialized();
|
||||
|
||||
static inline void SetParameters(const ParameterList& parameters);
|
||||
|
||||
static void Uninitialize();
|
||||
inline RendererImpl* GetRendererImpl();
|
||||
|
||||
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 DynLib s_rendererLib;
|
||||
static ParameterList s_initializationParameters;
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Renderer* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,7 @@ namespace Nz
|
|||
{
|
||||
inline RendererImpl* Renderer::GetRendererImpl()
|
||||
{
|
||||
return s_rendererImpl.get();
|
||||
}
|
||||
|
||||
inline bool Renderer::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCounter != 0;
|
||||
}
|
||||
|
||||
void Renderer::SetParameters(const ParameterList& parameters)
|
||||
{
|
||||
s_initializationParameters = parameters;
|
||||
return m_rendererImpl.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,25 +8,23 @@
|
|||
#define NAZARA_SHADER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_SHADER_API Shader
|
||||
class NAZARA_SHADER_API Shader : public Module<Shader>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Shader() = delete;
|
||||
~Shader() = delete;
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
Shader();
|
||||
~Shader() = default;
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Shader* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,28 +8,23 @@
|
|||
#define NAZARA_UTILITY_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_UTILITY_API Utility
|
||||
class NAZARA_UTILITY_API Utility : public Module<Utility>
|
||||
{
|
||||
friend Module;
|
||||
|
||||
public:
|
||||
Utility() = delete;
|
||||
~Utility() = delete;
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
static unsigned int ComponentCount[ComponentType_Max+1];
|
||||
static std::size_t ComponentStride[ComponentType_Max+1];
|
||||
Utility();
|
||||
~Utility();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
static Utility* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Audio/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -22,6 +23,32 @@ namespace Nz
|
|||
* \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
|
||||
* \return AudioFormat Enumeration type for the format
|
||||
|
|
@ -142,59 +169,6 @@ namespace Nz
|
|||
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
|
||||
* \return true if it is the case
|
||||
|
|
@ -210,16 +184,6 @@ namespace Nz
|
|||
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
|
||||
*
|
||||
|
|
@ -367,37 +331,5 @@ namespace Nz
|
|||
alSpeedOfSound(speed);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \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;
|
||||
Audio* Audio::s_instance = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ namespace Nz
|
|||
m_handle = nullptr;
|
||||
});
|
||||
|
||||
m_format = Audio::GetAudioFormat(infos.channels);
|
||||
m_format = Audio::Instance()->GetAudioFormat(infos.channels);
|
||||
if (m_format == AudioFormat_Unknown)
|
||||
{
|
||||
NazaraError("Channel count not handled");
|
||||
|
|
@ -327,7 +327,7 @@ namespace Nz
|
|||
sf_close(file);
|
||||
});
|
||||
|
||||
AudioFormat format = Audio::GetAudioFormat(info.channels);
|
||||
AudioFormat format = Audio::Instance()->GetAudioFormat(info.channels);
|
||||
if (format == AudioFormat_Unknown)
|
||||
{
|
||||
NazaraError("Channel count not handled");
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ namespace Nz
|
|||
*/
|
||||
bool SoundBuffer::IsFormatSupported(AudioFormat format)
|
||||
{
|
||||
return Audio::IsFormatSupported(format);
|
||||
return Audio::Instance()->IsFormatSupported(format);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/PluginManager.hpp>
|
||||
|
|
@ -15,69 +16,24 @@ namespace Nz
|
|||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::Core
|
||||
* \brief Core class that represents the module initializer of Core
|
||||
* \brief Core class that represents the Core module
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Initializes the Core module
|
||||
* \return true if initialization is successful
|
||||
*
|
||||
* \remark Produces a NazaraNotice
|
||||
*/
|
||||
|
||||
bool Core::Initialize()
|
||||
Core::Core() :
|
||||
Module("Core", this, Module::NoLog{})
|
||||
{
|
||||
if (IsInitialized())
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
return true; // Already initialized
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
Log::Initialize();
|
||||
|
||||
NazaraNotice("Initialized: Core");
|
||||
return true;
|
||||
LogInit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the module is initialized
|
||||
* \return true if module is initialized
|
||||
*/
|
||||
|
||||
bool Core::IsInitialized()
|
||||
Core::~Core()
|
||||
{
|
||||
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();
|
||||
Log::Uninitialize();
|
||||
PluginManager::Uninitialize();
|
||||
TaskScheduler::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Core");
|
||||
}
|
||||
|
||||
unsigned int Core::s_moduleReferenceCounter = 0;
|
||||
Core* Core::s_instance = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
#error Missing implementation: Network
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <Nazara/Network/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -29,98 +31,28 @@ namespace Nz
|
|||
* \brief Network class that represents the module initializer of Network
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Initializes the Network module
|
||||
* \return true if initialization is successful
|
||||
*
|
||||
* \remark Produces a NazaraNotice
|
||||
* \remark Produces a NazaraError if one submodule failed
|
||||
*/
|
||||
|
||||
bool Network::Initialize()
|
||||
Network::Network() :
|
||||
Module("Network", this)
|
||||
{
|
||||
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
|
||||
if (!SocketImpl::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize socket implementation");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize socket implementation");
|
||||
|
||||
if (!NetPacket::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize packets");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize packets");
|
||||
|
||||
if (!RUdpConnection::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize RUdp");
|
||||
return false;
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Network module");
|
||||
return true;
|
||||
throw std::runtime_error("failed to initialize RUDP protocol");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the module is initialized
|
||||
* \return true if module is initialized
|
||||
*/
|
||||
|
||||
bool Network::IsInitialized()
|
||||
Network::~Network()
|
||||
{
|
||||
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
|
||||
RUdpConnection::Uninitialize();
|
||||
NetPacket::Uninitialize();
|
||||
SocketImpl::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Network module");
|
||||
|
||||
// Free module dependencies
|
||||
Core::Uninitialize();
|
||||
}
|
||||
|
||||
unsigned int Network::s_moduleReferenceCounter = 0;
|
||||
Network* Network::s_instance = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,57 +3,14 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
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()
|
||||
{
|
||||
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;
|
||||
Physics2D* Physics2D::s_instance = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,65 +13,22 @@
|
|||
|
||||
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()
|
||||
{
|
||||
return NewtonGetMemoryUsed();
|
||||
}
|
||||
|
||||
bool Physics3D::Initialize()
|
||||
{
|
||||
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;
|
||||
Physics3D* Physics3D::s_instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include <Nazara/Platform/Config.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -18,91 +17,22 @@ namespace Nz
|
|||
* \brief Platform class that represents the module initializer of Platform
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Initializes the Platform module
|
||||
* \return true if initialization is successful
|
||||
*
|
||||
* \remark Produces a NazaraNotice
|
||||
* \remark Produces a NazaraError if one submodule failed
|
||||
*/
|
||||
|
||||
bool Platform::Initialize()
|
||||
Platform::Platform() :
|
||||
Module("Platform", 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;
|
||||
}
|
||||
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation of the module
|
||||
CallOnExit onExit(Platform::Uninitialize);
|
||||
|
||||
if (!Window::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize window's system");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize window system");
|
||||
|
||||
// Must be initialized after Window
|
||||
if (!Cursor::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize cursors");
|
||||
return false;
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Platform module");
|
||||
return true;
|
||||
throw std::runtime_error("failed to initialize cursors");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the module is initialized
|
||||
* \return true if module is initialized
|
||||
*/
|
||||
|
||||
bool Platform::IsInitialized()
|
||||
Platform::~Platform()
|
||||
{
|
||||
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
|
||||
Window::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Platform module");
|
||||
|
||||
// Free of dependances
|
||||
Utility::Uninitialize();
|
||||
}
|
||||
|
||||
unsigned int Platform::s_moduleReferenceCounter = 0;
|
||||
Platform* Platform::s_instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Nz
|
|||
|
||||
bool RenderWindow::OnWindowCreated()
|
||||
{
|
||||
RendererImpl *rendererImpl = Renderer::GetRendererImpl();
|
||||
RendererImpl *rendererImpl = Renderer::Instance()->GetRendererImpl();
|
||||
auto surface = rendererImpl->CreateRenderSurfaceImpl();
|
||||
if (!surface->Create(GetSystemHandle()))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <Nazara/Utility/Buffer.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
|
|
@ -29,31 +30,9 @@
|
|||
|
||||
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
|
||||
{
|
||||
std::filesystem::path fileName;
|
||||
|
|
@ -106,7 +85,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
std::unique_ptr<RendererImpl> impl(createRenderer());
|
||||
if (!impl || !impl->Prepare(s_initializationParameters))
|
||||
if (!impl || !impl->Prepare({}))
|
||||
{
|
||||
NazaraError("Failed to create renderer implementation");
|
||||
continue;
|
||||
|
|
@ -120,57 +99,23 @@ namespace Nz
|
|||
}
|
||||
|
||||
if (!chosenImpl)
|
||||
{
|
||||
NazaraError("No renderer found");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("no renderer found");
|
||||
|
||||
s_rendererImpl = std::move(chosenImpl);
|
||||
s_rendererLib = std::move(chosenLib);
|
||||
m_rendererImpl = std::move(chosenImpl);
|
||||
m_rendererLib = std::move(chosenLib);
|
||||
|
||||
NazaraDebug("Using " + s_rendererImpl->QueryAPIString() + " as renderer");
|
||||
NazaraDebug("Using " + m_rendererImpl->QueryAPIString() + " as renderer");
|
||||
|
||||
Buffer::SetBufferFactory(DataStorage_Hardware, CreateHardwareBufferImpl);
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
NazaraNotice("Initialized: Renderer module");
|
||||
return true;
|
||||
Buffer::SetBufferFactory(DataStorage_Hardware, [](Buffer* parent, BufferType type) -> AbstractBuffer* { return new RenderBuffer(parent, type); });
|
||||
}
|
||||
|
||||
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
|
||||
Buffer::SetBufferFactory(DataStorage_Hardware, nullptr);
|
||||
|
||||
s_rendererImpl.reset();
|
||||
s_rendererLib.Unload();
|
||||
|
||||
NazaraNotice("Uninitialized: Renderer module");
|
||||
|
||||
// Free module dependencies
|
||||
Platform::Uninitialize();
|
||||
Utility::Uninitialize();
|
||||
m_rendererImpl.reset();
|
||||
}
|
||||
|
||||
AbstractBuffer* Renderer::CreateHardwareBufferImpl(Buffer* parent, BufferType type)
|
||||
{
|
||||
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;
|
||||
Renderer* Renderer::s_instance = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,68 +3,15 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.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>
|
||||
|
||||
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()
|
||||
{
|
||||
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;
|
||||
Shader* Shader::s_instance = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <Nazara/Utility/Formats/PCXLoader.hpp>
|
||||
#include <Nazara/Utility/Formats/STBLoader.hpp>
|
||||
#include <Nazara/Utility/Formats/STBSaver.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -35,81 +36,32 @@ namespace Nz
|
|||
* \brief Utility class that represents the module initializer of Utility
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Initializes the Utility module
|
||||
* \return true if initialization is successful
|
||||
*
|
||||
* \remark Produces a NazaraNotice
|
||||
* \remark Produces a NazaraError if one submodule failed
|
||||
*/
|
||||
|
||||
bool Utility::Initialize()
|
||||
Utility::Utility() :
|
||||
Module("Utility", this)
|
||||
{
|
||||
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())
|
||||
{
|
||||
NazaraError("Failed to initialize animations");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize animations");
|
||||
|
||||
if (!Buffer::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize buffers");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize buffers");
|
||||
|
||||
if (!Font::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize fonts");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize fonts");
|
||||
|
||||
if (!Image::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize images");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize images");
|
||||
|
||||
if (!Mesh::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize meshes");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize meshes");
|
||||
|
||||
if (!PixelFormatInfo::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize pixel formats");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize pixel formats");
|
||||
|
||||
if (!Skeleton::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize skeletons");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize skeletons");
|
||||
|
||||
if (!VertexDeclaration::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize vertex declarations");
|
||||
return false;
|
||||
}
|
||||
throw std::runtime_error("failed to initialize vertex declarations");
|
||||
|
||||
// On enregistre les loaders pour les extensions
|
||||
// Il s'agit ici d'une liste LIFO, le dernier loader enregistré possède la priorité
|
||||
|
|
@ -138,32 +90,10 @@ namespace Nz
|
|||
|
||||
// Image
|
||||
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::UnregisterMD2();
|
||||
Loaders::UnregisterMD5Anim();
|
||||
|
|
@ -182,52 +112,7 @@ namespace Nz
|
|||
Font::Uninitialize();
|
||||
Buffer::Uninitialize();
|
||||
Animation::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Utility module");
|
||||
|
||||
// Libération des dépendances
|
||||
Core::Uninitialize();
|
||||
}
|
||||
|
||||
unsigned int Utility::ComponentCount[ComponentType_Max+1] =
|
||||
{
|
||||
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;
|
||||
Utility* Utility::s_instance = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,26 @@
|
|||
|
||||
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) :
|
||||
m_inputRate(inputRate)
|
||||
{
|
||||
|
|
@ -42,7 +62,7 @@ namespace Nz
|
|||
component.offset = offset;
|
||||
component.type = entry.type;
|
||||
|
||||
offset += Utility::ComponentStride[component.type];
|
||||
offset += s_componentStride[component.type];
|
||||
}
|
||||
|
||||
m_stride = offset;
|
||||
|
|
|
|||
Loading…
Reference in New Issue