diff --git a/.gitignore b/.gitignore index cc3e70c52..1b9a63d4e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ vsxmake*/* # Nazara binaries bin/* +!bin/resources !bin/resources/* # Build files diff --git a/SDK/include/NDK/Components.hpp b/SDK/include/NDK/Components.hpp deleted file mode 100644 index 97f597990..000000000 --- a/SDK/include/NDK/Components.hpp +++ /dev/null @@ -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 diff --git a/SDK/include/NDK/Systems.hpp b/SDK/include/NDK/Systems.hpp deleted file mode 100644 index 33edfc17a..000000000 --- a/SDK/include/NDK/Systems.hpp +++ /dev/null @@ -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 diff --git a/SDK/include/NDK/Widgets.hpp b/SDK/include/NDK/Widgets.hpp deleted file mode 100644 index b009f3a17..000000000 --- a/SDK/include/NDK/Widgets.hpp +++ /dev/null @@ -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 diff --git a/tests/resources/Engine/Audio/Cat.flac.REMOVED.git-id b/bin/resources/Engine/Audio/Cat.flac.REMOVED.git-id similarity index 100% rename from tests/resources/Engine/Audio/Cat.flac.REMOVED.git-id rename to bin/resources/Engine/Audio/Cat.flac.REMOVED.git-id diff --git a/tests/resources/Engine/Audio/The_Brabanconne.ogg.REMOVED.git-id b/bin/resources/Engine/Audio/The_Brabanconne.ogg.REMOVED.git-id similarity index 100% rename from tests/resources/Engine/Audio/The_Brabanconne.ogg.REMOVED.git-id rename to bin/resources/Engine/Audio/The_Brabanconne.ogg.REMOVED.git-id diff --git a/tests/resources/Engine/Audio/copyrights.txt b/bin/resources/Engine/Audio/copyrights.txt similarity index 100% rename from tests/resources/Engine/Audio/copyrights.txt rename to bin/resources/Engine/Audio/copyrights.txt diff --git a/tests/resources/Engine/Core/FileTest.txt b/bin/resources/Engine/Core/FileTest.txt similarity index 100% rename from tests/resources/Engine/Core/FileTest.txt rename to bin/resources/Engine/Core/FileTest.txt diff --git a/tests/resources/Engine/Graphics/Bob lamp/Readme.txt b/bin/resources/Engine/Graphics/Bob lamp/Readme.txt similarity index 100% rename from tests/resources/Engine/Graphics/Bob lamp/Readme.txt rename to bin/resources/Engine/Graphics/Bob lamp/Readme.txt diff --git a/tests/resources/Engine/Graphics/copyrights.txt b/bin/resources/Engine/Graphics/copyrights.txt similarity index 100% rename from tests/resources/Engine/Graphics/copyrights.txt rename to bin/resources/Engine/Graphics/copyrights.txt diff --git a/tests/resources/Engine/Graphics/dragon_recon/README b/bin/resources/Engine/Graphics/dragon_recon/README similarity index 100% rename from tests/resources/Engine/Graphics/dragon_recon/README rename to bin/resources/Engine/Graphics/dragon_recon/README diff --git a/include/Nazara/Network/Algorithm.hpp b/include/Nazara/Network/Algorithm.hpp index 1b28fb747..9f8140385 100644 --- a/include/Nazara/Network/Algorithm.hpp +++ b/include/Nazara/Network/Algorithm.hpp @@ -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); diff --git a/include/NazaraSDK/Application.hpp b/include/NazaraSDK/Application.hpp index 2bd467137..e185892ad 100644 --- a/include/NazaraSDK/Application.hpp +++ b/include/NazaraSDK/Application.hpp @@ -15,11 +15,6 @@ #include #include -#ifndef NDK_SERVER -#include -#include -#endif - namespace Ndk { class NDK_API Application @@ -31,9 +26,6 @@ namespace Ndk Application(Application&&) = delete; inline ~Application(); - #ifndef NDK_SERVER - template T& AddWindow(Args&&... args); - #endif template World& AddWorld(Args&&... args); inline const std::set& 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&& window); - - std::unique_ptr window; - }; - - std::vector m_windows; - #endif - std::map m_parameters; std::set m_options; std::list m_worlds; Nz::Clock m_updateClock; - #ifndef NDK_SERVER - bool m_exitOnClosedWindows; - #endif bool m_shouldQuit; float m_updateTime; diff --git a/include/NazaraSDK/Application.inl b/include/NazaraSDK/Application.inl index d6b58a257..4016a9777 100644 --- a/include/NazaraSDK/Application.inl +++ b/include/NazaraSDK/Application.inl @@ -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 - T& Application::AddWindow(Args&&... args) - { - static_assert(std::is_base_of::value, "Type must inherit Window"); - - m_windows.emplace_back(std::make_unique(std::forward(args)...)); - WindowInfo& info = m_windows.back(); - - return static_cast(*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&& windowPtr) : - window(std::move(windowPtr)) - { - } - #endif } diff --git a/include/NazaraSDK/ClientApplication.hpp b/include/NazaraSDK/ClientApplication.hpp new file mode 100644 index 000000000..54875af27 --- /dev/null +++ b/include/NazaraSDK/ClientApplication.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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 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&& window); + + std::unique_ptr window; + }; + + std::vector m_windows; + Nz::UInt32 m_overlayFlags; + bool m_exitOnClosedWindows; + + static ClientApplication* s_clientApplication; + }; +} + +#include + +#endif // NDK_CLIENTAPPLICATION_HPP diff --git a/include/NazaraSDK/ClientApplication.inl b/include/NazaraSDK/ClientApplication.inl new file mode 100644 index 000000000..d4f10a245 --- /dev/null +++ b/include/NazaraSDK/ClientApplication.inl @@ -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 +#include +#include + +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 + T& ClientApplication::AddWindow(Args&&... args) + { + static_assert(std::is_base_of::value, "Type must inherit Window"); + + m_windows.emplace_back(std::make_unique(std::forward(args)...)); + WindowInfo& info = m_windows.back(); + + return static_cast(*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&& windowPtr) : + window(std::move(windowPtr)) + { + } +} diff --git a/include/NazaraSDK/ClientPrerequisites.hpp b/include/NazaraSDK/ClientPrerequisites.hpp new file mode 100644 index 000000000..b90c37761 --- /dev/null +++ b/include/NazaraSDK/ClientPrerequisites.hpp @@ -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 + +// 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 diff --git a/include/NazaraSDK/ClientSdk.hpp b/include/NazaraSDK/ClientSdk.hpp new file mode 100644 index 000000000..bc8a5b07a --- /dev/null +++ b/include/NazaraSDK/ClientSdk.hpp @@ -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 +#include +#include +#include + +namespace Ndk +{ + class NDK_CLIENT_API ClientSdk : public Nz::ModuleBase + { + friend ModuleBase; + + public: + using Dependencies = Nz::TypeList; + + struct Config {}; + + ClientSdk(Config /*config*/); + ~ClientSdk(); + + private: + static ClientSdk* s_instance; + }; +} + +#include + +#endif // NDK_CLIENTSDK_HPP diff --git a/include/NazaraSDK/ClientSdk.inl b/include/NazaraSDK/ClientSdk.inl new file mode 100644 index 000000000..5db72c705 --- /dev/null +++ b/include/NazaraSDK/ClientSdk.inl @@ -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 +{ +} diff --git a/include/NazaraSDK/Components/ListenerComponent.hpp b/include/NazaraSDK/Components/ListenerComponent.hpp index cea5a8d84..c8936bc81 100644 --- a/include/NazaraSDK/Components/ListenerComponent.hpp +++ b/include/NazaraSDK/Components/ListenerComponent.hpp @@ -4,10 +4,10 @@ #pragma once -#ifndef NDK_SERVER #ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP #define NDK_COMPONENTS_LISTENERCOMPONENT_HPP +#include #include namespace Ndk @@ -16,7 +16,7 @@ namespace Ndk using ListenerComponentHandle = Nz::ObjectHandle; - class NDK_API ListenerComponent : public Component + class NDK_CLIENT_API ListenerComponent : public Component { public: inline ListenerComponent(); @@ -35,4 +35,3 @@ namespace Ndk #include #endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP -#endif // NDK_SERVER \ No newline at end of file diff --git a/include/NazaraSDK/EntityList.inl b/include/NazaraSDK/EntityList.inl index 4fa991f30..128f12a24 100644 --- a/include/NazaraSDK/EntityList.inl +++ b/include/NazaraSDK/EntityList.inl @@ -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 +#include #include #include diff --git a/include/NazaraSDK/Sdk.hpp b/include/NazaraSDK/Sdk.hpp index 4d86229d1..3be008c22 100644 --- a/include/NazaraSDK/Sdk.hpp +++ b/include/NazaraSDK/Sdk.hpp @@ -17,11 +17,6 @@ #include #include -#ifndef NDK_SERVER -#include -#include -#endif - namespace Ndk { class NDK_API Sdk : public Nz::ModuleBase @@ -29,13 +24,7 @@ namespace Ndk friend ModuleBase; public: - using CommonDependencies = Nz::TypeList; -#ifdef NDK_SERVER - using Dependencies = CommonDependencies; -#else - using ClientDependencies = Nz::TypeList; - using Dependencies = Nz::TypeListConcat; -#endif + using Dependencies = Nz::TypeList; struct Config {}; diff --git a/include/NazaraSDK/Systems/ListenerSystem.hpp b/include/NazaraSDK/Systems/ListenerSystem.hpp index 3c9317e0d..b7d98cc4e 100644 --- a/include/NazaraSDK/Systems/ListenerSystem.hpp +++ b/include/NazaraSDK/Systems/ListenerSystem.hpp @@ -4,15 +4,15 @@ #pragma once -#ifndef NDK_SERVER #ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP #define NDK_SYSTEMS_LISTENERSYSTEM_HPP -#include + #include + #include namespace Ndk { - class NDK_API ListenerSystem : public System + class NDK_CLIENT_API ListenerSystem : public System { public: ListenerSystem(); @@ -28,4 +28,3 @@ namespace Ndk #include #endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/World.hpp b/include/NazaraSDK/World.hpp index bffc12004..346cb665d 100644 --- a/include/NazaraSDK/World.hpp +++ b/include/NazaraSDK/World.hpp @@ -32,13 +32,11 @@ namespace Ndk using EntityVector = std::vector; 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&& system); template SystemType& AddSystem(Args&&... args); diff --git a/include/NazaraSDK/World.inl b/include/NazaraSDK/World.inl index 41f10c3c3..4507a1b6b 100644 --- a/include/NazaraSDK/World.inl +++ b/include/NazaraSDK/World.inl @@ -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(); } /*! diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 00ea94eb7..1cca2a32d 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -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; } } diff --git a/src/NazaraSDK/Application.cpp b/src/NazaraSDK/Application.cpp index 148987070..b85059f16 100644 --- a/src/NazaraSDK/Application.cpp +++ b/src/NazaraSDK/Application.cpp @@ -7,11 +7,6 @@ #include #include -#ifndef NDK_SERVER -#include -#include -#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; } diff --git a/src/NazaraSDK/ClientApplication.cpp b/src/NazaraSDK/ClientApplication.cpp new file mode 100644 index 000000000..fd0f7a3b4 --- /dev/null +++ b/src/NazaraSDK/ClientApplication.cpp @@ -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 +#include +#include + +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; +} diff --git a/src/NazaraSDK/ClientSdk.cpp b/src/NazaraSDK/ClientSdk.cpp new file mode 100644 index 000000000..a0337e172 --- /dev/null +++ b/src/NazaraSDK/ClientSdk.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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("NdkList"); + + // Systems + + // Client systems + InitializeSystem(); + } + + /*! + * \brief Uninitializes the Sdk module + * + * \remark Produces a NazaraNotice + */ + ClientSdk::~ClientSdk() = default; + + ClientSdk* ClientSdk::s_instance = nullptr; +} diff --git a/src/NazaraSDK/Sdk.cpp b/src/NazaraSDK/Sdk.cpp index 5c44bf3c8..6ae2f16d2 100644 --- a/src/NazaraSDK/Sdk.cpp +++ b/src/NazaraSDK/Sdk.cpp @@ -19,11 +19,6 @@ #include #include -#ifndef NDK_SERVER -#include -#include -#endif - namespace Ndk { /*! @@ -52,11 +47,6 @@ namespace Ndk InitializeComponent("NdkVeloc"); InitializeComponent("NdkCons2"); - #ifndef NDK_SERVER - // Client components - InitializeComponent("NdkList"); - #endif - // Systems BaseSystem::Initialize(); @@ -66,11 +56,6 @@ namespace Ndk InitializeSystem(); InitializeSystem(); InitializeSystem(); - - #ifndef NDK_SERVER - // Client systems - InitializeSystem(); - #endif } Sdk::~Sdk() diff --git a/src/NazaraSDK/World.cpp b/src/NazaraSDK/World.cpp index 89b84b4bf..cdd67873d 100644 --- a/src/NazaraSDK/World.cpp +++ b/src/NazaraSDK/World.cpp @@ -11,10 +11,6 @@ #include #include -#ifndef NDK_SERVER -#include -#endif - namespace Ndk { /*! @@ -35,22 +31,6 @@ namespace Ndk Clear(); } - /*! - * \brief Adds default systems to the world - */ - - void World::AddDefaultSystems() - { - AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); - - #ifndef NDK_SERVER - AddSystem(); - #endif - } - /*! * \brief Creates an entity in the world * \return The entity created diff --git a/tests/Engine/Audio/Music.cpp b/tests/Engine/Audio/Music.cpp index 14cc2ede5..cd0d2857a 100644 --- a/tests/Engine/Audio/Music.cpp +++ b/tests/Engine/Audio/Music.cpp @@ -4,6 +4,8 @@ #include #include +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") { diff --git a/tests/Engine/Audio/Sound.cpp b/tests/Engine/Audio/Sound.cpp index ec0f655b4..8f239d694 100644 --- a/tests/Engine/Audio/Sound.cpp +++ b/tests/Engine/Audio/Sound.cpp @@ -4,6 +4,8 @@ #include #include +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") { diff --git a/tests/Engine/Audio/SoundBuffer.cpp b/tests/Engine/Audio/SoundBuffer.cpp index 292a1e98e..17b6b4b3d 100644 --- a/tests/Engine/Audio/SoundBuffer.cpp +++ b/tests/Engine/Audio/SoundBuffer.cpp @@ -1,13 +1,15 @@ #include #include +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") diff --git a/tests/Engine/Audio/SoundEmitter.cpp b/tests/Engine/Audio/SoundEmitter.cpp index c2cf4f318..ea2bdb47b 100644 --- a/tests/Engine/Audio/SoundEmitter.cpp +++ b/tests/Engine/Audio/SoundEmitter.cpp @@ -1,6 +1,8 @@ #include #include +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") { diff --git a/tests/Engine/Core/File.cpp b/tests/Engine/Core/File.cpp index cc3fa6661..130166746 100644 --- a/tests/Engine/Core/File.cpp +++ b/tests/Engine/Core/File.cpp @@ -1,6 +1,8 @@ #include #include +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") { diff --git a/tests/SDK/NDK/Application.cpp b/tests/SDK/NDK/Application.cpp index a7f471255..0fa2e75a0 100644 --- a/tests/SDK/NDK/Application.cpp +++ b/tests/SDK/NDK/Application.cpp @@ -1,11 +1,11 @@ -#include +#include #include SCENARIO("Application", "[NDK][APPLICATION]") { GIVEN("An application") { - Nz::Window& window = Ndk::Application::Instance()->AddWindow(); + Nz::Window& window = Ndk::ClientApplication::Instance()->AddWindow(); WHEN("We open a window") { @@ -22,4 +22,4 @@ SCENARIO("Application", "[NDK][APPLICATION]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/BaseSystem.cpp b/tests/SDK/NDK/BaseSystem.cpp index bf86a9011..f488a6bd9 100644 --- a/tests/SDK/NDK/BaseSystem.cpp +++ b/tests/SDK/NDK/BaseSystem.cpp @@ -32,7 +32,7 @@ SCENARIO("BaseSystem", "[NDK][BASESYSTEM]") { GIVEN("Our TestSystem") { - Ndk::World world(false); + Ndk::World world; Ndk::BaseSystem& system = world.AddSystem(); REQUIRE(&system.GetWorld() == &world); @@ -62,4 +62,4 @@ SCENARIO("BaseSystem", "[NDK][BASESYSTEM]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/Entity.cpp b/tests/SDK/NDK/Entity.cpp index e17b9114d..7de5789ee 100644 --- a/tests/SDK/NDK/Entity.cpp +++ b/tests/SDK/NDK/Entity.cpp @@ -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(); Ndk::EntityHandle entity = world.CreateEntity(); @@ -99,4 +99,4 @@ SCENARIO("Entity", "[NDK][ENTITY]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/EntityList.cpp b/tests/SDK/NDK/EntityList.cpp index 6b9c85ddf..5b464669c 100644 --- a/tests/SDK/NDK/EntityList.cpp +++ b/tests/SDK/NDK/EntityList.cpp @@ -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; @@ -39,4 +39,4 @@ SCENARIO("EntityList", "[NDK][ENTITYLIST]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/EntityOwner.cpp b/tests/SDK/NDK/EntityOwner.cpp index 1cb6f768c..0a0549286 100644 --- a/tests/SDK/NDK/EntityOwner.cpp +++ b/tests/SDK/NDK/EntityOwner.cpp @@ -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 entityOwners; for (std::size_t i = 1; i <= 10; ++i) diff --git a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp index 2081da617..58a218caf 100644 --- a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp +++ b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -13,6 +14,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") GIVEN("A world and an entity") { Ndk::World world; + world.AddSystem(); 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(); 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(); Nz::Vector2f position(3.f, 4.f); Nz::Rectf movingAABB(0.f, 0.f, 1.f, 2.f); diff --git a/tests/SDK/NDK/Systems/PhysicsSystem3D.cpp b/tests/SDK/NDK/Systems/PhysicsSystem3D.cpp index 7dc66673c..0273d59d3 100644 --- a/tests/SDK/NDK/Systems/PhysicsSystem3D.cpp +++ b/tests/SDK/NDK/Systems/PhysicsSystem3D.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include 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(); + const Ndk::EntityHandle& staticEntity = world.CreateEntity(); Ndk::CollisionComponent3D& collisionComponentStatic = staticEntity->AddComponent(); Ndk::NodeComponent& nodeComponentStatic = staticEntity->AddComponent(); @@ -31,4 +34,4 @@ SCENARIO("PhysicsSystem3D", "[NDK][PHYSICSSYSTEM3D]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/Systems/VelocitySystem.cpp b/tests/SDK/NDK/Systems/VelocitySystem.cpp index de77de28d..d8bb0731f 100644 --- a/tests/SDK/NDK/Systems/VelocitySystem.cpp +++ b/tests/SDK/NDK/Systems/VelocitySystem.cpp @@ -13,7 +13,7 @@ SCENARIO("VelocitySystem", "[NDK][VELOCITYSYSTEM]") Ndk::VelocityComponent& velocityComponent = entity->AddComponent(); Ndk::NodeComponent& nodeComponent = entity->AddComponent(); - world.GetSystem().SetFixedUpdateRate(30.f); + world.AddSystem().SetFixedUpdateRate(30.f); WHEN("We give a speed to our entity") { @@ -27,4 +27,4 @@ SCENARIO("VelocitySystem", "[NDK][VELOCITYSYSTEM]") } } } -} \ No newline at end of file +} diff --git a/tests/SDK/NDK/World.cpp b/tests/SDK/NDK/World.cpp index 56cb49d92..7c478fd77 100644 --- a/tests/SDK/NDK/World.cpp +++ b/tests/SDK/NDK/World.cpp @@ -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(); 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") { diff --git a/tests/main_client.cpp b/tests/main_client.cpp new file mode 100644 index 000000000..86dcbbb18 --- /dev/null +++ b/tests/main_client.cpp @@ -0,0 +1,20 @@ +#define CATCH_CONFIG_RUNNER +#include + +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + Nz::Modules nazaza; + Ndk::ClientApplication app(argc, argv); + + Nz::Log::GetLogger()->EnableStdReplication(false); + + int result = Catch::Session().run(argc, argv); + + return result; +} diff --git a/tests/resources.cpp b/tests/resources.cpp new file mode 100644 index 000000000..8a71d9249 --- /dev/null +++ b/tests/resources.cpp @@ -0,0 +1,15 @@ +#include + +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; +} diff --git a/tests/resources/Engine/Lua/LuaClass.lua b/tests/resources/Engine/Lua/LuaClass.lua deleted file mode 100644 index 3434a7d94..000000000 --- a/tests/resources/Engine/Lua/LuaClass.lua +++ /dev/null @@ -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 diff --git a/tests/resources/Engine/Lua/LuaCoroutine.lua b/tests/resources/Engine/Lua/LuaCoroutine.lua deleted file mode 100644 index 4a235cbe5..000000000 --- a/tests/resources/Engine/Lua/LuaCoroutine.lua +++ /dev/null @@ -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 diff --git a/tests/xmake.lua b/tests/xmake.lua new file mode 100644 index 000000000..120153c73 --- /dev/null +++ b/tests/xmake.lua @@ -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") diff --git a/tools/xmake.lua b/tools/xmake.lua index 402101d41..48e1c7a13 100644 --- a/tools/xmake.lua +++ b/tools/xmake.lua @@ -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") diff --git a/xmake.lua b/xmake.lua index 1a5233f7f..38bee4fd9 100644 --- a/xmake.lua +++ b/xmake.lua @@ -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")