(NDK) Added explicit initialisation
Components and systems just can't be initialized at startup, so we need some kind of explicit initialisation. I followed the same layout as the others modules by adding a core class (Ndk::Sdk) which will initialize components and systems, and Nazara's modules. This is starting to get serious, I like it. Former-commit-id: 263500e8d16db70ef7f92047b8a7e3235c08bcd0
This commit is contained in:
89
SDK/src/NDK/Sdk.cpp
Normal file
89
SDK/src/NDK/Sdk.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Sdk.hpp>
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Lua/Lua.hpp>
|
||||
#include <Nazara/Noise/Noise.hpp>
|
||||
#include <Nazara/Physics/Physics.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Sdk::Initialize()
|
||||
{
|
||||
if (s_referenceCounter++ > 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
try
|
||||
{
|
||||
NzErrorFlags errFlags(nzErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du moteur
|
||||
|
||||
// Modules clients
|
||||
NzAudio::Initialize();
|
||||
NzGraphics::Initialize();
|
||||
|
||||
// Modules serveurs
|
||||
NzLua::Initialize();
|
||||
NzNoise::Initialize();
|
||||
NzPhysics::Initialize();
|
||||
NzUtility::Initialize();
|
||||
|
||||
// Initialisation du SDK
|
||||
|
||||
// Initialisation des composants et systèmes
|
||||
BaseComponent::Initialize();
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Composants
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to initialize NDK: " + NzString(e.what()));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Sdk::Uninitialize()
|
||||
{
|
||||
if (s_referenceCounter != 1)
|
||||
{
|
||||
// Le module est soit encore utilisé, soit pas initialisé
|
||||
if (s_referenceCounter > 1)
|
||||
s_referenceCounter--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Libération du SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Libération du moteur
|
||||
|
||||
// Modules clients
|
||||
NzAudio::Uninitialize();
|
||||
NzGraphics::Uninitialize();
|
||||
|
||||
// Modules serveurs
|
||||
NzLua::Uninitialize();
|
||||
NzNoise::Uninitialize();
|
||||
NzPhysics::Uninitialize();
|
||||
NzUtility::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: SDK");
|
||||
}
|
||||
|
||||
unsigned int Sdk::s_referenceCounter = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user