Add tests and SDK
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
69
include/NazaraSDK/ClientApplication.hpp
Normal file
69
include/NazaraSDK/ClientApplication.hpp
Normal 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
|
||||
79
include/NazaraSDK/ClientApplication.inl
Normal file
79
include/NazaraSDK/ClientApplication.inl
Normal 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))
|
||||
{
|
||||
}
|
||||
}
|
||||
46
include/NazaraSDK/ClientPrerequisites.hpp
Normal file
46
include/NazaraSDK/ClientPrerequisites.hpp
Normal 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
|
||||
36
include/NazaraSDK/ClientSdk.hpp
Normal file
36
include/NazaraSDK/ClientSdk.hpp
Normal 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
|
||||
7
include/NazaraSDK/ClientSdk.inl
Normal file
7
include/NazaraSDK/ClientSdk.inl
Normal 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
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user