Add tests and SDK

This commit is contained in:
Jérôme Leclercq
2021-05-17 23:08:37 +02:00
parent 26de5872eb
commit e716b44aa3
52 changed files with 539 additions and 276 deletions

View File

@@ -480,7 +480,7 @@ namespace Nz
return SocketState_Connected;
else
{
NazaraWarning("Socket " + String::Number(handle) + " was returned by poll without POLLOUT nor error events (events: 0x" + String::Number(descriptor.revents, 16) + ')');
NazaraWarning("Socket " + std::to_string(handle) + " was returned by poll without POLLOUT nor error events (events: 0x" + NumberToString(descriptor.revents, 16) + ')');
return SocketState_NotConnected;
}
}

View File

@@ -7,11 +7,6 @@
#include <Nazara/Core/StringExt.hpp>
#include <regex>
#ifndef NDK_SERVER
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#endif
namespace Ndk
{
/*!
@@ -33,6 +28,32 @@ namespace Ndk
*/
Application::Application(int argc, char* argv[]) :
Application()
{
ParseCommandline(argc, argv);
}
/*!
* \brief Runs the application by updating worlds, taking care about windows, ...
*/
bool Application::Run()
{
if (m_shouldQuit)
return false;
m_updateTime = m_updateClock.Restart() / 1'000'000.f;
for (World& world : m_worlds)
world.Update(m_updateTime);
return true;
}
void Application::ClearWorlds()
{
m_worlds.clear();
}
void Application::ParseCommandline(int argc, char* argv[])
{
std::regex optionRegex(R"(-(\w+))");
std::regex valueRegex(R"(-(\w+)\s*=\s*(.+))");
@@ -62,46 +83,5 @@ namespace Ndk
}
}
/*!
* \brief Runs the application by updating worlds, taking care about windows, ...
*/
bool Application::Run()
{
#ifndef NDK_SERVER
bool hasAtLeastOneActiveWindow = false;
auto it = m_windows.begin();
while (it != m_windows.end())
{
Nz::Window& window = *it->window;
window.ProcessEvents();
if (!window.IsOpen(true))
{
it = m_windows.erase(it);
continue;
}
hasAtLeastOneActiveWindow = true;
++it;
}
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
return false;
#endif
if (m_shouldQuit)
return false;
m_updateTime = m_updateClock.Restart() / 1'000'000.f;
for (World& world : m_worlds)
world.Update(m_updateTime);
return true;
}
Application* Application::s_application = nullptr;
}

View File

@@ -0,0 +1,69 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NazaraSDK/ClientApplication.hpp>
#include <Nazara/Core/Log.hpp>
#include <regex>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::ClientApplication
* \brief NDK class that represents a client-side application, it offers a set of tools to ease the development
*/
/*!
* \brief Constructs an ClientApplication object with command-line arguments
*
* Pass the argc and argv arguments from the main function.
*
* Command-line arguments can be retrieved by application methods
*
* This calls Sdk::Initialize()
*
* \remark Only one Application instance can exist at a time
*/
ClientApplication::ClientApplication(int argc, char* argv[]) :
ClientApplication()
{
ParseCommandline(argc, argv);
}
/*!
* \brief Runs the application by updating worlds, taking care about windows, ...
*/
bool ClientApplication::Run()
{
if (!Application::Run())
return false;
bool hasAtLeastOneActiveWindow = false;
auto it = m_windows.begin();
while (it != m_windows.end())
{
Nz::Window& window = *it->window;
window.ProcessEvents();
if (!window.IsOpen(true))
{
it = m_windows.erase(it);
continue;
}
hasAtLeastOneActiveWindow = true;
++it;
}
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
return false;
return true;
}
ClientApplication* ClientApplication::s_clientApplication = nullptr;
}

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NazaraSDK/ClientSdk.hpp>
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Graphics/Graphics.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/Sdk.hpp>
#include <NazaraSDK/Components/ListenerComponent.hpp>
#include <NazaraSDK/Systems/ListenerSystem.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::Sdk
* \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
*/
ClientSdk::ClientSdk(Config /*config*/) :
ModuleBase("ClientSDK", this)
{
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
// Client components
InitializeComponent<ListenerComponent>("NdkList");
// Systems
// Client systems
InitializeSystem<ListenerSystem>();
}
/*!
* \brief Uninitializes the Sdk module
*
* \remark Produces a NazaraNotice
*/
ClientSdk::~ClientSdk() = default;
ClientSdk* ClientSdk::s_instance = nullptr;
}

View File

@@ -19,11 +19,6 @@
#include <NazaraSDK/Systems/PhysicsSystem3D.hpp>
#include <NazaraSDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
#include <NazaraSDK/Components/ListenerComponent.hpp>
#include <NazaraSDK/Systems/ListenerSystem.hpp>
#endif
namespace Ndk
{
/*!
@@ -52,11 +47,6 @@ namespace Ndk
InitializeComponent<VelocityComponent>("NdkVeloc");
InitializeComponent<VelocityComponent>("NdkCons2");
#ifndef NDK_SERVER
// Client components
InitializeComponent<ListenerComponent>("NdkList");
#endif
// Systems
BaseSystem::Initialize();
@@ -66,11 +56,6 @@ namespace Ndk
InitializeSystem<PhysicsSystem2D>();
InitializeSystem<PhysicsSystem3D>();
InitializeSystem<VelocitySystem>();
#ifndef NDK_SERVER
// Client systems
InitializeSystem<ListenerSystem>();
#endif
}
Sdk::~Sdk()

View File

@@ -11,10 +11,6 @@
#include <NazaraSDK/Systems/PhysicsSystem3D.hpp>
#include <NazaraSDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
#include <NazaraSDK/Systems/ListenerSystem.hpp>
#endif
namespace Ndk
{
/*!
@@ -35,22 +31,6 @@ namespace Ndk
Clear();
}
/*!
* \brief Adds default systems to the world
*/
void World::AddDefaultSystems()
{
AddSystem<LifetimeSystem>();
AddSystem<PhysicsSystem2D>();
AddSystem<PhysicsSystem3D>();
AddSystem<VelocitySystem>();
#ifndef NDK_SERVER
AddSystem<ListenerSystem>();
#endif
}
/*!
* \brief Creates an entity in the world
* \return The entity created