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

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ vsxmake*/*
# Nazara binaries
bin/*
!bin/resources
!bin/resources/*
# Build files

View File

@ -1,9 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_COMPONENTS_GLOBAL_HPP
#define NDK_COMPONENTS_GLOBAL_HPP
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@ -1,9 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_SYSTEMS_GLOBAL_HPP
#define NDK_SYSTEMS_GLOBAL_HPP
#endif // NDK_SYSTEMS_GLOBAL_HPP

View File

@ -1,9 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_WIDGETS_GLOBAL_HPP
#define NDK_WIDGETS_GLOBAL_HPP
#endif // NDK_WIDGETS_GLOBAL_HPP

View File

@ -16,8 +16,8 @@
namespace Nz
{
NAZARA_NETWORK_API const char* ErrorToString(Nz::ResolveError resolveError);
NAZARA_NETWORK_API const char* ErrorToString(Nz::SocketError socketError);
NAZARA_NETWORK_API const char* ErrorToString(ResolveError resolveError);
NAZARA_NETWORK_API const char* ErrorToString(SocketError socketError);
NAZARA_NETWORK_API bool ParseIPAddress(const char* addressPtr, UInt8 result[16], UInt16* port = nullptr, bool* isIPv6 = nullptr, const char** endOfRead = nullptr);

View File

@ -15,11 +15,6 @@
#include <set>
#include <string>
#ifndef NDK_SERVER
#include <Nazara/Core/Log.hpp>
#include <Nazara/Platform/Window.hpp>
#endif
namespace Ndk
{
class NDK_API Application
@ -31,9 +26,6 @@ namespace Ndk
Application(Application&&) = delete;
inline ~Application();
#ifndef NDK_SERVER
template<typename T, typename... Args> T& AddWindow(Args&&... args);
#endif
template<typename... Args> World& AddWorld(Args&&... args);
inline const std::set<std::string>& GetOptions() const;
@ -44,17 +36,8 @@ namespace Ndk
inline bool HasOption(const std::string& option) const;
inline bool HasParameter(const std::string& key, std::string* value) const;
#ifndef NDK_SERVER
inline bool IsConsoleEnabled() const;
inline bool IsFPSCounterEnabled() const;
#endif
bool Run();
#ifndef NDK_SERVER
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
#endif
inline void Quit();
Application& operator=(const Application&) = delete;
@ -62,26 +45,16 @@ namespace Ndk
inline static Application* Instance();
protected:
void ClearWorlds();
void ParseCommandline(int argc, char* argv[]);
private:
#ifndef NDK_SERVER
struct WindowInfo
{
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
std::unique_ptr<Nz::Window> window;
};
std::vector<WindowInfo> m_windows;
#endif
std::map<std::string, std::string> m_parameters;
std::set<std::string> m_options;
std::list<World> m_worlds;
Nz::Clock m_updateClock;
#ifndef NDK_SERVER
bool m_exitOnClosedWindows;
#endif
bool m_shouldQuit;
float m_updateTime;

View File

@ -15,9 +15,6 @@ namespace Ndk
* \remark Only one Application instance can exist at a time
*/
inline Application::Application() :
#ifndef NDK_SERVER
m_exitOnClosedWindows(true),
#endif
m_shouldQuit(false),
m_updateTime(0.f)
{
@ -33,33 +30,11 @@ namespace Ndk
inline Application::~Application()
{
m_worlds.clear();
#ifndef NDK_SERVER
m_windows.clear();
#endif
// Automatic free of modules
s_application = nullptr;
}
/*!
* \brief Adds a window to the application
* \return A reference to the newly created windows
*
* \param args Arguments used to create the window
*/
#ifndef NDK_SERVER
template<typename T, typename... Args>
T& Application::AddWindow(Args&&... args)
{
static_assert(std::is_base_of<Nz::Window, T>::value, "Type must inherit Window");
m_windows.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
WindowInfo& info = m_windows.back();
return static_cast<T&>(*info.window.get()); //< Warning: ugly
}
#endif
/*!
* \brief Adds a world to the application
* \return A reference to the newly created world
@ -147,18 +122,6 @@ namespace Ndk
return true;
}
/*!
* \brief Makes the application exit when there's no more open window
*
* \param exitOnClosedWindows Should exit be called when no more window is open
*/
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
/*!
* \brief Quits the application
*/
@ -177,11 +140,4 @@ namespace Ndk
{
return s_application;
}
#ifndef NDK_SERVER
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& windowPtr) :
window(std::move(windowPtr))
{
}
#endif
}

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
#pragma once
#ifndef NDK_CLIENTAPPLICATION_HPP
#define NDK_CLIENTAPPLICATION_HPP
#include <NazaraSDK/ClientPrerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Platform/Window.hpp>
#include <NazaraSDK/Application.hpp>
#include <NazaraSDK/World.hpp>
#include <map>
#include <list>
#include <set>
namespace Ndk
{
class NDK_CLIENT_API ClientApplication : public Application
{
public:
struct ConsoleOverlay;
struct FPSCounterOverlay;
inline ClientApplication();
ClientApplication(int argc, char* argv[]);
ClientApplication(const ClientApplication&) = delete;
ClientApplication(ClientApplication&&) = delete;
inline ~ClientApplication();
template<typename T, typename... Args> T& AddWindow(Args&&... args);
bool Run();
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
ClientApplication& operator=(const ClientApplication&) = delete;
ClientApplication& operator=(ClientApplication&&) = delete;
inline static ClientApplication* Instance();
private:
enum OverlayFlags
{
OverlayFlags_Console = 0x1,
OverlayFlags_FPSCounter = 0x2
};
struct WindowInfo
{
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
std::unique_ptr<Nz::Window> window;
};
std::vector<WindowInfo> m_windows;
Nz::UInt32 m_overlayFlags;
bool m_exitOnClosedWindows;
static ClientApplication* s_clientApplication;
};
}
#include <NazaraSDK/ClientApplication.inl>
#endif // NDK_CLIENTAPPLICATION_HPP

View File

@ -0,0 +1,79 @@
// 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/ErrorFlags.hpp>
#include <NazaraSDK/ClientSdk.hpp>
namespace Ndk
{
/*!
* \brief Constructs an Application object without passing command-line arguments
*
* This calls Sdk::Initialize()
*
* \remark Only one Application instance can exist at a time
*/
inline ClientApplication::ClientApplication() :
m_overlayFlags(0U),
m_exitOnClosedWindows(true)
{
NazaraAssert(s_clientApplication == nullptr, "You can create only one application instance per program");
s_clientApplication = this;
}
/*!
* \brief Destructs the application object
*
* This destroy all worlds and windows and then calls Sdk::Uninitialize
*/
inline ClientApplication::~ClientApplication()
{
ClearWorlds();
m_windows.clear();
s_clientApplication = nullptr;
}
/*!
* \brief Adds a window to the application
* \return A reference to the newly created windows
*
* \param args Arguments used to create the window
*/
template<typename T, typename... Args>
T& ClientApplication::AddWindow(Args&&... args)
{
static_assert(std::is_base_of<Nz::Window, T>::value, "Type must inherit Window");
m_windows.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
WindowInfo& info = m_windows.back();
return static_cast<T&>(*info.window.get()); //< Warning: ugly
}
/*!
* \brief Makes the application exit when there's no more open window
*
* \param exitOnClosedWindows Should exit be called when no more window is open
*/
inline void ClientApplication::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
/*!
* \brief Gets the singleton instance of the application
* \return Singleton application
*/
inline ClientApplication* ClientApplication::Instance()
{
return s_clientApplication;
}
inline ClientApplication::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& windowPtr) :
window(std::move(windowPtr))
{
}
}

View File

@ -0,0 +1,46 @@
/*
Nazara Development Kit ("NDK"), also called Nazara Engine - SDK ("Software Development Kit")
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef NDK_CLIENT_PREREQUISITES_HPP
#define NDK_CLIENT_PREREQUISITES_HPP
/*!
* \defgroup NDK (NazaraSDK) Nazara Development Kit
* A library grouping every modules of Nazara into multiple higher-level features suchs as scene management (handled by an ECS), application, lua binding, etc.
*/
#include <NazaraSDK/Prerequisites.hpp>
// Importation/Exportation of the API
#if defined(NAZARA_STATIC)
#define NDK_CLIENT_API
#else
#ifdef NDK_CLIENT_BUILD
#define NDK_CLIENT_API NAZARA_EXPORT
#else
#define NDK_CLIENT_API NAZARA_IMPORT
#endif
#endif
#endif // NDK_CLIENT_PREREQUISITES_HPP

View File

@ -0,0 +1,36 @@
// 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
#pragma once
#ifndef NDK_CLIENTSDK_HPP
#define NDK_CLIENTSDK_HPP
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <NazaraSDK/ClientPrerequisites.hpp>
#include <NazaraSDK/Sdk.hpp>
namespace Ndk
{
class NDK_CLIENT_API ClientSdk : public Nz::ModuleBase<ClientSdk>
{
friend ModuleBase;
public:
using Dependencies = Nz::TypeList<Ndk::Sdk, Nz::Audio, Nz::Graphics>;
struct Config {};
ClientSdk(Config /*config*/);
~ClientSdk();
private:
static ClientSdk* s_instance;
};
}
#include <NazaraSDK/ClientSdk.inl>
#endif // NDK_CLIENTSDK_HPP

View File

@ -0,0 +1,7 @@
// 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
namespace Ndk
{
}

View File

@ -4,10 +4,10 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#define NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#include <NazaraSDK/ClientPrerequisites.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
@ -16,7 +16,7 @@ namespace Ndk
using ListenerComponentHandle = Nz::ObjectHandle<ListenerComponent>;
class NDK_API ListenerComponent : public Component<ListenerComponent>
class NDK_CLIENT_API ListenerComponent : public Component<ListenerComponent>
{
public:
inline ListenerComponent();
@ -35,4 +35,3 @@ namespace Ndk
#include <NazaraSDK/Components/ListenerComponent.inl>
#endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/EntityList.hpp>
#include <NazaraSDK/EntityList.hpp>
#include <Nazara/Core/Error.hpp>
#include <algorithm>

View File

@ -17,11 +17,6 @@
#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 : public Nz::ModuleBase<Sdk>
@ -29,13 +24,7 @@ namespace Ndk
friend ModuleBase;
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
using Dependencies = Nz::TypeList<Nz::Network, Nz::Physics2D, Nz::Physics3D, Nz::Utility>;
struct Config {};

View File

@ -4,15 +4,15 @@
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP
#define NDK_SYSTEMS_LISTENERSYSTEM_HPP
#include <NazaraSDK/System.hpp>
#include <NazaraSDK/ClientPrerequisites.hpp>
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API ListenerSystem : public System<ListenerSystem>
class NDK_CLIENT_API ListenerSystem : public System<ListenerSystem>
{
public:
ListenerSystem();
@ -28,4 +28,3 @@ namespace Ndk
#include <NazaraSDK/Systems/ListenerSystem.inl>
#endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP
#endif // NDK_SERVER

View File

@ -32,13 +32,11 @@ namespace Ndk
using EntityVector = std::vector<EntityHandle>;
struct ProfilerData;
inline World(bool addDefaultSystems = true);
inline World();
World(const World&) = delete;
inline World(World&& world) noexcept;
~World() noexcept;
void AddDefaultSystems();
inline BaseSystem& AddSystem(std::unique_ptr<BaseSystem>&& system);
template<typename SystemType, typename... Args> SystemType& AddSystem(Args&&... args);

View File

@ -10,16 +10,12 @@ namespace Ndk
{
/*!
* \brief Constructs a World object
*
* \param addDefaultSystems Should default provided systems be used
*/
inline World::World(bool addDefaultSystems) :
inline World::World() :
m_orderedSystemsUpdated(false),
m_isProfilerEnabled(false)
{
if (addDefaultSystems)
AddDefaultSystems();
}
/*!

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

View File

@ -4,6 +4,8 @@
#include <chrono>
#include <thread>
std::filesystem::path GetResourceDir();
SCENARIO("Music", "[AUDIO][MUSIC]")
{
GIVEN("A music")
@ -12,7 +14,7 @@ SCENARIO("Music", "[AUDIO][MUSIC]")
WHEN("We load our music")
{
REQUIRE(music.OpenFromFile("resources/Engine/Audio/The_Brabanconne.ogg"));
REQUIRE(music.OpenFromFile(GetResourceDir() / "Engine/Audio/The_Brabanconne.ogg"));
THEN("We can ask the informations of the file")
{

View File

@ -4,6 +4,8 @@
#include <chrono>
#include <thread>
std::filesystem::path GetResourceDir();
SCENARIO("Sound", "[AUDIO][SOUND]")
{
GIVEN("A sound")
@ -12,7 +14,7 @@ SCENARIO("Sound", "[AUDIO][SOUND]")
WHEN("We load our sound")
{
REQUIRE(sound.LoadFromFile("resources/Engine/Audio/Cat.flac"));
REQUIRE(sound.LoadFromFile(GetResourceDir() / "Engine/Audio/Cat.flac"));
THEN("We can ask the informations of the file")
{

View File

@ -1,13 +1,15 @@
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Catch/catch.hpp>
std::filesystem::path GetResourceDir();
SCENARIO("SoundBuffer", "[AUDIO][SOUNDBUFFER]")
{
GIVEN("A sound buffer")
{
WHEN("We load our sound")
{
Nz::SoundBufferRef soundBuffer = Nz::SoundBuffer::LoadFromFile("resources/Engine/Audio/Cat.flac");
Nz::SoundBufferRef soundBuffer = Nz::SoundBuffer::LoadFromFile(GetResourceDir() / "Engine/Audio/Cat.flac");
REQUIRE(soundBuffer.IsValid());
THEN("We can ask the informations of the file")

View File

@ -1,6 +1,8 @@
#include <Nazara/Audio/Sound.hpp>
#include <Catch/catch.hpp>
std::filesystem::path GetResourceDir();
SCENARIO("SoundEmitter", "[AUDIO][SOUNDEMITTER]")
{
GIVEN("A sound emitter")
@ -9,7 +11,7 @@ SCENARIO("SoundEmitter", "[AUDIO][SOUNDEMITTER]")
WHEN("We load our sound")
{
REQUIRE(sound.LoadFromFile("resources/Engine/Audio/Cat.flac"));
REQUIRE(sound.LoadFromFile(GetResourceDir() / "Engine/Audio/Cat.flac"));
THEN("We can ask information about position and velocity")
{

View File

@ -1,6 +1,8 @@
#include <Nazara/Core/File.hpp>
#include <Catch/catch.hpp>
std::filesystem::path GetResourceDir();
SCENARIO("File", "[CORE][FILE]")
{
GIVEN("One file")
@ -63,9 +65,9 @@ SCENARIO("File", "[CORE][FILE]")
GIVEN("The test file")
{
REQUIRE(std::filesystem::exists("resources/Engine/Core/FileTest.txt"));
REQUIRE(std::filesystem::exists(GetResourceDir() / "Engine/Core/FileTest.txt"));
Nz::File fileTest("resources/Engine/Core/FileTest.txt", Nz::OpenMode_ReadOnly | Nz::OpenMode_Text);
Nz::File fileTest(GetResourceDir() / "Engine/Core/FileTest.txt", Nz::OpenMode_ReadOnly | Nz::OpenMode_Text);
WHEN("We read the first line of the file")
{

View File

@ -1,11 +1,11 @@
#include <NazaraSDK/Application.hpp>
#include <NazaraSDK/ClientApplication.hpp>
#include <Catch/catch.hpp>
SCENARIO("Application", "[NDK][APPLICATION]")
{
GIVEN("An application")
{
Nz::Window& window = Ndk::Application::Instance()->AddWindow<Nz::Window>();
Nz::Window& window = Ndk::ClientApplication::Instance()->AddWindow<Nz::Window>();
WHEN("We open a window")
{

View File

@ -32,7 +32,7 @@ SCENARIO("BaseSystem", "[NDK][BASESYSTEM]")
{
GIVEN("Our TestSystem")
{
Ndk::World world(false);
Ndk::World world;
Ndk::BaseSystem& system = world.AddSystem<TestSystem>();
REQUIRE(&system.GetWorld() == &world);

View File

@ -55,7 +55,7 @@ SCENARIO("Entity", "[NDK][ENTITY]")
{
GIVEN("A world & an entity")
{
Ndk::World world(false);
Ndk::World world;
Ndk::BaseSystem& system = world.AddSystem<UpdateSystem>();
Ndk::EntityHandle entity = world.CreateEntity();

View File

@ -6,7 +6,7 @@ SCENARIO("EntityList", "[NDK][ENTITYLIST]")
{
GIVEN("A world & a set of entities")
{
Ndk::World world(false);
Ndk::World world;
const Ndk::EntityHandle& entity = world.CreateEntity();
Ndk::EntityList entityList;

View File

@ -6,7 +6,7 @@ SCENARIO("EntityOwner", "[NDK][ENTITYOWNER]")
{
GIVEN("A world & an entity")
{
Ndk::World world(false);
Ndk::World world;
Ndk::EntityHandle entity = world.CreateEntity();
WHEN("We set the ownership of the entity to our owner")
@ -108,7 +108,7 @@ SCENARIO("EntityOwner", "[NDK][ENTITYOWNER]")
GIVEN("A vector of EntityOwner")
{
Ndk::World world(false);
Ndk::World world;
std::vector<Ndk::EntityOwner> entityOwners;
for (std::size_t i = 1; i <= 10; ++i)

View File

@ -3,6 +3,7 @@
#include <NazaraSDK/Components/CollisionComponent2D.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#include <NazaraSDK/Components/PhysicsComponent2D.hpp>
#include <NazaraSDK/Systems/PhysicsSystem2D.hpp>
#include <Catch/catch.hpp>
#include <limits>
@ -13,6 +14,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
GIVEN("A world and an entity")
{
Ndk::World world;
world.AddSystem<Ndk::PhysicsSystem2D>();
Nz::Vector2f position(2.f, 3.f);
Nz::Rectf movingAABB(0.f, 0.f, 16.f, 18.f);
@ -74,6 +76,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
GIVEN("A world and a simple entity")
{
Ndk::World world;
world.AddSystem<Ndk::PhysicsSystem2D>();
Nz::Vector2f position(0.f, 0.f);
Nz::Rectf movingAABB(0.f, 0.f, 1.f, 2.f);
@ -120,6 +123,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
GIVEN("A world and a simple entity not at the origin")
{
Ndk::World world;
world.AddSystem<Ndk::PhysicsSystem2D>();
Nz::Vector2f position(3.f, 4.f);
Nz::Rectf movingAABB(0.f, 0.f, 1.f, 2.f);

View File

@ -3,6 +3,7 @@
#include <NazaraSDK/Components/CollisionComponent3D.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#include <NazaraSDK/Components/PhysicsComponent3D.hpp>
#include <NazaraSDK/Systems/PhysicsSystem3D.hpp>
#include <Catch/catch.hpp>
SCENARIO("PhysicsSystem3D", "[NDK][PHYSICSSYSTEM3D]")
@ -10,6 +11,8 @@ SCENARIO("PhysicsSystem3D", "[NDK][PHYSICSSYSTEM3D]")
GIVEN("A world and a static entity & a dynamic entity")
{
Ndk::World world;
world.AddSystem<Ndk::PhysicsSystem3D>();
const Ndk::EntityHandle& staticEntity = world.CreateEntity();
Ndk::CollisionComponent3D& collisionComponentStatic = staticEntity->AddComponent<Ndk::CollisionComponent3D>();
Ndk::NodeComponent& nodeComponentStatic = staticEntity->AddComponent<Ndk::NodeComponent>();

View File

@ -13,7 +13,7 @@ SCENARIO("VelocitySystem", "[NDK][VELOCITYSYSTEM]")
Ndk::VelocityComponent& velocityComponent = entity->AddComponent<Ndk::VelocityComponent>();
Ndk::NodeComponent& nodeComponent = entity->AddComponent<Ndk::NodeComponent>();
world.GetSystem<Ndk::VelocitySystem>().SetFixedUpdateRate(30.f);
world.AddSystem<Ndk::VelocitySystem>().SetFixedUpdateRate(30.f);
WHEN("We give a speed to our entity")
{

View File

@ -55,7 +55,7 @@ SCENARIO("World", "[NDK][WORLD]")
{
GIVEN("A brave new world and the update system")
{
Ndk::World world(false);
Ndk::World world;
Ndk::BaseSystem& system = world.AddSystem<UpdateSystem>();
WHEN("We had a new entity with an updatable component and a system")
@ -103,7 +103,7 @@ SCENARIO("World", "[NDK][WORLD]")
GIVEN("A newly created entity")
{
Ndk::World world(false);
Ndk::World world;
Ndk::EntityHandle entity = world.CreateEntity();
REQUIRE(entity.IsValid());
@ -129,7 +129,7 @@ SCENARIO("World", "[NDK][WORLD]")
GIVEN("An empty world")
{
Ndk::World world(false);
Ndk::World world;
WHEN("We create two entities")
{

20
tests/main_client.cpp Normal file
View File

@ -0,0 +1,20 @@
#define CATCH_CONFIG_RUNNER
#include <Catch/catch.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/AbstractLogger.hpp>
#include <Nazara/Core/Modules.hpp>
#include <NazaraSDK/ClientApplication.hpp>
#include <NazaraSDK/ClientSdk.hpp>
int main(int argc, char* argv[])
{
Nz::Modules<Ndk::ClientSdk> nazaza;
Ndk::ClientApplication app(argc, argv);
Nz::Log::GetLogger()->EnableStdReplication(false);
int result = Catch::Session().run(argc, argv);
return result;
}

15
tests/resources.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <filesystem>
std::filesystem::path GetResourceDir()
{
static std::filesystem::path resourceDir = []
{
std::filesystem::path resourceDir = "resources";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
return ".." / resourceDir;
else
return resourceDir;
}();
return resourceDir;
}

View File

@ -1,24 +0,0 @@
function test_Test()
local test = Test(1)
local i = test:GetI()
local result = Test.StaticMethodWithArguments(i, i)
local finalTest = Test(result + test:GetDefault(), true)
CheckTest(test)
CheckStatic(result)
CheckFinalTest(finalTest)
end
function test_InheritTest()
local test = InheritTest()
CheckInheritTest(test)
end
function test_TestHandle()
local test = TestHandle()
CheckTestHandle()
end

View File

@ -1,15 +0,0 @@
function even (x)
coroutine.yield(1)
end
function odd (x)
coroutine.yield(0)
end
function infinite (x)
for i=1,x do
if i==3 then coroutine.yield(-1) end
if i % 2 == 0 then even(i) else odd(i) end
end
end

22
tests/xmake.lua Normal file
View File

@ -0,0 +1,22 @@
target("NazaraClientUnitTests")
set_group("Tests")
set_kind("binary")
add_deps("NazaraClientSDK")
add_files("main_client.cpp")
add_files("resources.cpp")
add_files("Engine/**.cpp")
target("NazaraUnitTests")
set_group("Tests")
set_kind("binary")
add_deps("NazaraSDK")
add_files("main.cpp")
add_files("resources.cpp")
add_files("Engine/**.cpp")
add_files("SDK/**.cpp")
del_files("Engine/Audio/**")
del_files("SDK/NDK/Application.cpp")
del_files("SDK/NDK/Systems/ListenerSystem.cpp")

View File

@ -1,6 +1,42 @@
add_requires("nodeeditor", {debug = is_mode("debug"), optional = true})
target("NazaraSDK")
set_group("SDK")
set_kind("shared")
add_deps("NazaraCore", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraNetwork", "NazaraShader", "NazaraUtility", { public = true })
add_defines("NDK_BUILD")
add_defines("NDK_SERVER", { public = true })
add_includedirs("../src")
add_headerfiles("../include/NazaraSDK/**.hpp", "../include/NazaraSDK/**.inl", "../src/NazaraSDK/**.hpp", "../src/NazaraSDK/**.inl")
add_files("../src/NazaraSDK/**.cpp")
--del_headerfiles("../*/NazaraSDK/Client*.*")
--del_headerfiles("../*/NazaraSDK/*/ListenerComponent*.*")
--del_headerfiles("../*/NazaraSDK/*/ListenerSystem*.*")
del_files("../*/NazaraSDK/Client*.*")
del_files("../*/NazaraSDK/*/ListenerComponent*.*")
del_files("../*/NazaraSDK/*/ListenerSystem*.*")
target("NazaraClientSDK")
set_group("SDK")
set_kind("shared")
add_deps("NazaraSDK", "NazaraAudio", "NazaraGraphics", "NazaraRenderer", { public = true })
add_defines("NDK_CLIENT_BUILD")
add_includedirs("../src")
add_headerfiles("../include/NazaraSDK/Client*.hpp")
add_headerfiles("../include/NazaraSDK/Client*.inl")
add_headerfiles("../include/NazaraSDK/Components/ListenerComponent.hpp")
add_headerfiles("../include/NazaraSDK/Components/ListenerComponent.inl")
add_headerfiles("../include/NazaraSDK/Systems/ListenerSystem.hpp")
add_headerfiles("../include/NazaraSDK/Systems/ListenerSystem.inl")
add_files("../src/NazaraSDK/Client*.cpp")
add_files("../src/NazaraSDK/Components/ListenerComponent.cpp")
add_files("../src/NazaraSDK/Systems/ListenerSystem.cpp")
target("NazaraShaderNodes")
set_group("Tools")
set_kind("binary")

View File

@ -175,6 +175,7 @@ end
includes("xmake/actions/*.lua")
includes("tools/xmake.lua")
includes("tests/xmake.lua")
includes("plugins/*/xmake.lua")
includes("examples/*/xmake.lua")