Last modules fixes

This commit is contained in:
Jérôme Leclercq
2020-09-17 18:54:33 +02:00
parent 631aeb77a2
commit 98e20ecbb7
15 changed files with 95 additions and 163 deletions

View File

@@ -3,13 +3,7 @@
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NazaraSDK/Sdk.hpp>
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <NazaraSDK/Algorithm.hpp>
#include <NazaraSDK/BaseSystem.hpp>
#include <NazaraSDK/Components/CollisionComponent2D.hpp>
@@ -38,122 +32,55 @@ namespace Ndk
* \brief NDK class that represents the software development kit, a set of tools made to ease the conception of application
*/
/*!
* \brief Initializes the Sdk module
* \return true if initialization is successful
*
* \remark Produces a NazaraNotice
*/
bool Sdk::Initialize()
Sdk::Sdk() :
ModuleBase("SDK", this)
{
if (s_referenceCounter++ > 0)
return true; // Already initialized
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
try
{
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
// SDK Initialization
// Initialize the engine first
// Components
BaseComponent::Initialize();
// Shared modules
Nz::Physics2D::Initialize();
Nz::Physics3D::Initialize();
Nz::Utility::Initialize();
// Shared components
InitializeComponent<CollisionComponent2D>("NdkColl2");
InitializeComponent<CollisionComponent3D>("NdkColl3");
InitializeComponent<LifetimeComponent>("NdkLiftm");
InitializeComponent<NodeComponent>("NdkNode");
InitializeComponent<PhysicsComponent2D>("NdkPhys2");
InitializeComponent<PhysicsComponent3D>("NdkPhys3");
InitializeComponent<VelocityComponent>("NdkVeloc");
InitializeComponent<VelocityComponent>("NdkCons2");
#ifndef NDK_SERVER
// Client modules
Nz::Audio::Initialize();
#endif
#ifndef NDK_SERVER
// Client components
InitializeComponent<ListenerComponent>("NdkList");
#endif
// SDK Initialization
// Systems
// Components
BaseComponent::Initialize();
BaseSystem::Initialize();
// Shared components
InitializeComponent<CollisionComponent2D>("NdkColl2");
InitializeComponent<CollisionComponent3D>("NdkColl3");
InitializeComponent<LifetimeComponent>("NdkLiftm");
InitializeComponent<NodeComponent>("NdkNode");
InitializeComponent<PhysicsComponent2D>("NdkPhys2");
InitializeComponent<PhysicsComponent3D>("NdkPhys3");
InitializeComponent<VelocityComponent>("NdkVeloc");
InitializeComponent<VelocityComponent>("NdkCons2");
// Shared systems
InitializeSystem<LifetimeSystem>();
InitializeSystem<PhysicsSystem2D>();
InitializeSystem<PhysicsSystem3D>();
InitializeSystem<VelocitySystem>();
#ifndef NDK_SERVER
// Client components
InitializeComponent<ListenerComponent>("NdkList");
#endif
// Systems
BaseSystem::Initialize();
// Shared systems
InitializeSystem<LifetimeSystem>();
InitializeSystem<PhysicsSystem2D>();
InitializeSystem<PhysicsSystem3D>();
InitializeSystem<VelocitySystem>();
#ifndef NDK_SERVER
// Client systems
InitializeSystem<ListenerSystem>();
#endif
NazaraNotice("Initialized: SDK");
return true;
}
catch (const std::exception& e)
{
NazaraError("Failed to initialize NDK: " + Nz::String(e.what()));
return false;
}
#ifndef NDK_SERVER
// Client systems
InitializeSystem<ListenerSystem>();
#endif
}
/*!
* \brief Uninitializes the Sdk module
*
* \remark Produces a NazaraNotice
*/
void Sdk::Uninitialize()
Sdk::~Sdk()
{
if (s_referenceCounter != 1)
{
// Either the module is not initialized, either it was initialized multiple times
if (s_referenceCounter > 1)
s_referenceCounter--;
return;
}
// Uninitialize the SDK
s_referenceCounter = 0;
// Components
BaseComponent::Uninitialize();
// Systems
BaseSystem::Uninitialize();
// Uninitialize the engine
#ifndef NDK_SERVER
// Client modules
Nz::Audio::Uninitialize();
#endif
// Shared modules
Nz::Physics2D::Uninitialize();
Nz::Physics3D::Uninitialize();
Nz::Utility::Uninitialize();
#ifndef NDK_SERVER
#endif
NazaraNotice("Uninitialized: SDK");
}
unsigned int Sdk::s_referenceCounter = 0;
Sdk* Sdk::s_instance;
}