Rework modules
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user