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