Last modules fixes
This commit is contained in:
parent
631aeb77a2
commit
98e20ecbb7
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
|
|
@ -20,13 +21,13 @@
|
|||
int main()
|
||||
{
|
||||
// NzKeyboard nécessite l'initialisation du module Utilitaire
|
||||
Nz::Initializer<Nz::Audio, Nz::Platform> audio;
|
||||
if (!audio)
|
||||
Nz::Modules<Nz::Audio, Nz::Platform> audio;
|
||||
/*if (!audio)
|
||||
{
|
||||
std::cout << "Failed to initialize audio module" << std::endl;
|
||||
std::getchar();
|
||||
return 1;
|
||||
}
|
||||
}*/
|
||||
|
||||
Nz::Sound sound;
|
||||
if (!sound.LoadFromFile("resources/siren.wav"))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/Joint.hpp>
|
||||
|
|
@ -14,14 +15,14 @@
|
|||
int main()
|
||||
{
|
||||
// Pour charger des ressources, il est impératif d'initialiser le module utilitaire
|
||||
Nz::Initializer<Nz::Utility> utility;
|
||||
if (!utility)
|
||||
Nz::Modules<Nz::Utility> nazara;
|
||||
/*if (!utility)
|
||||
{
|
||||
// Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log
|
||||
std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl;
|
||||
std::getchar(); // On laise le temps de voir l'erreur
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,5 +10,6 @@ EXAMPLE.Libraries = {
|
|||
"NazaraCore",
|
||||
"NazaraPlatform",
|
||||
"NazaraRenderer",
|
||||
"NazaraShader",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,7 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
Nz::Initializer<Nz::Renderer> loader;
|
||||
if (!loader)
|
||||
{
|
||||
std::cout << "Failed to initialize Vulkan" << std::endl;
|
||||
return __LINE__;
|
||||
}
|
||||
Nz::Modules<Nz::Renderer> nazara;
|
||||
|
||||
Nz::RenderWindow window;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ namespace Nz
|
|||
{
|
||||
friend ModuleBase;
|
||||
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/Shader/Shader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -23,7 +24,7 @@ namespace Nz
|
|||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Platform>;
|
||||
using Dependencies = TypeList<Platform, Shader>;
|
||||
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
|
|
|||
|
|
@ -23,11 +23,6 @@ namespace Ndk
|
|||
{
|
||||
NazaraAssert(s_application == nullptr, "You can create only one application instance per program");
|
||||
s_application = this;
|
||||
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du SDK
|
||||
Sdk::Initialize();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -42,9 +37,6 @@ namespace Ndk
|
|||
m_windows.clear();
|
||||
#endif
|
||||
|
||||
// Free of SDK
|
||||
Sdk::Uninitialize();
|
||||
|
||||
// Automatic free of modules
|
||||
s_application = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,22 +7,41 @@
|
|||
#ifndef NDK_SDK_HPP
|
||||
#define NDK_SDK_HPP
|
||||
|
||||
#include <Nazara/Core/ModuleBase.hpp>
|
||||
#include <Nazara/Core/TypeList.hpp>
|
||||
#include <NazaraSDK/Prerequisites.hpp>
|
||||
|
||||
#include <Nazara/Network/Network.hpp>
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3D.hpp>
|
||||
#include <Nazara/Shader/Shader.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Sdk
|
||||
class NDK_API Sdk : public Nz::ModuleBase<Sdk>
|
||||
{
|
||||
public:
|
||||
Sdk() = delete;
|
||||
~Sdk() = delete;
|
||||
friend ModuleBase;
|
||||
|
||||
static bool Initialize();
|
||||
static bool IsInitialized();
|
||||
static void Uninitialize();
|
||||
public:
|
||||
using CommonDependencies = Nz::TypeList<Nz::Network, Nz::Physics2D, Nz::Physics3D, Nz::Utility>;
|
||||
#ifdef NDK_SERVER
|
||||
using Dependencies = CommonDependencies;
|
||||
#else
|
||||
using ClientDependencies = Nz::TypeList<Nz::Audio, Nz::Renderer>;
|
||||
using Dependencies = Nz::TypeListConcat<CommonDependencies, ClientDependencies>;
|
||||
#endif
|
||||
|
||||
Sdk();
|
||||
~Sdk();
|
||||
|
||||
private:
|
||||
static unsigned int s_referenceCounter;
|
||||
static Sdk* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,4 @@
|
|||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Checks whether the module is initialized
|
||||
* \return true if module is initialized
|
||||
*/
|
||||
|
||||
inline bool Sdk::IsInitialized()
|
||||
{
|
||||
return s_referenceCounter != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <Nazara/Audio/Audio.hpp>
|
||||
#include <NazaraSDK/Components/ListenerComponent.hpp>
|
||||
#include <NazaraSDK/Components/NodeComponent.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -37,6 +38,9 @@ namespace Ndk
|
|||
{
|
||||
std::size_t activeListenerCount = 0;
|
||||
|
||||
Nz::Audio* audio = Nz::Audio::Instance();
|
||||
assert(audio);
|
||||
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
// Is the listener actif ?
|
||||
|
|
@ -44,18 +48,18 @@ namespace Ndk
|
|||
if (!listener.IsActive())
|
||||
continue;
|
||||
|
||||
Nz::Vector3f oldPos = Nz::Audio::GetListenerPosition();
|
||||
Nz::Vector3f oldPos = audio->GetListenerPosition();
|
||||
|
||||
// We get the position and the rotation to affect these to the listener
|
||||
const NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
Nz::Vector3f newPos = node.GetPosition(Nz::CoordSys_Global);
|
||||
|
||||
Nz::Audio::SetListenerPosition(newPos);
|
||||
Nz::Audio::SetListenerRotation(node.GetRotation(Nz::CoordSys_Global));
|
||||
audio->SetListenerPosition(newPos);
|
||||
audio->SetListenerRotation(node.GetRotation(Nz::CoordSys_Global));
|
||||
|
||||
// Compute listener velocity based on their old/new position
|
||||
Nz::Vector3f velocity = (newPos - oldPos) / elapsedTime;
|
||||
Nz::Audio::SetListenerVelocity(velocity);
|
||||
audio->SetListenerVelocity(velocity);
|
||||
|
||||
activeListenerCount++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ SCENARIO("Music", "[AUDIO][MUSIC]")
|
|||
|
||||
THEN("We can play it and get the time offset")
|
||||
{
|
||||
Nz::Audio::SetGlobalVolume(0.f);
|
||||
Nz::Audio::Instance()->SetGlobalVolume(0.f);
|
||||
|
||||
music.Play();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
|
@ -42,7 +42,7 @@ SCENARIO("Music", "[AUDIO][MUSIC]")
|
|||
music.SetPlayingOffset(3500);
|
||||
REQUIRE(music.GetPlayingOffset() >= 3500);
|
||||
|
||||
Nz::Audio::SetGlobalVolume(100.f);
|
||||
Nz::Audio::Instance()->SetGlobalVolume(100.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ SCENARIO("Sound", "[AUDIO][SOUND]")
|
|||
|
||||
THEN("We can play it and get the time offset")
|
||||
{
|
||||
Nz::Audio::SetGlobalVolume(0.f);
|
||||
Nz::Audio::Instance()->SetGlobalVolume(0.f);
|
||||
|
||||
sound.Play();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
|
@ -37,7 +37,7 @@ SCENARIO("Sound", "[AUDIO][SOUND]")
|
|||
sound.SetPlayingOffset(3500);
|
||||
REQUIRE(sound.GetPlayingOffset() >= 3500);
|
||||
|
||||
Nz::Audio::SetGlobalVolume(100.f);
|
||||
Nz::Audio::Instance()->SetGlobalVolume(100.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ SCENARIO("ListenerSystem", "[NDK][LISTENERSYSTEM]")
|
|||
|
||||
THEN("Our listener should have moved")
|
||||
{
|
||||
REQUIRE(Nz::Audio::GetListenerPosition() == position);
|
||||
REQUIRE(Nz::Audio::GetListenerRotation() == rotation);
|
||||
REQUIRE(Nz::Audio::Instance()->GetListenerPosition() == position);
|
||||
REQUIRE(Nz::Audio::Instance()->GetListenerRotation() == rotation);
|
||||
}
|
||||
|
||||
THEN("With a component of velocity")
|
||||
|
|
@ -36,8 +36,8 @@ SCENARIO("ListenerSystem", "[NDK][LISTENERSYSTEM]")
|
|||
velocityComponent.linearVelocity = velocity;
|
||||
|
||||
world.Update(1.f);
|
||||
REQUIRE(Nz::Audio::GetListenerVelocity() == velocity);
|
||||
REQUIRE(Nz::Audio::Instance()->GetListenerVelocity() == velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
#define CATCH_CONFIG_RUNNER
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <NazaraSDK/Application.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Network/Network.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <NazaraSDK/Application.hpp>
|
||||
#include <NazaraSDK/Sdk.hpp>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Ndk::Application application(argc, argv);
|
||||
Nz::Initializer<Nz::Network> modules;
|
||||
Nz::Modules<Ndk::Sdk> nazaza;
|
||||
Ndk::Application app(argc, argv);
|
||||
|
||||
Nz::Log::GetLogger()->EnableStdReplication(false);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue