Files
NazaraEngine/SDK/include/NDK/Application.inl
Lynix 2007edd398 Sdk/Application: Add MakeExitOnLastWindowClosed
At least it's explicit


Former-commit-id: e5bf5064222934b4f9dade56aab74b8f29367ed8 [formerly 5d7aa20615adf39407b95096a2da8c4888111fef]
Former-commit-id: b404314721413e7d9b6d0307f7316f22ac5f81fb
2016-06-09 08:48:35 +02:00

81 lines
1.7 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/ErrorFlags.hpp>
#include <type_traits>
#include <NDK/Sdk.hpp>
namespace Ndk
{
inline Application::Application() :
#ifndef NDK_SERVER
m_exitOnClosedWindows(true),
#endif
m_shouldQuit(false),
m_updateTime(0.f)
{
NazaraAssert(s_application == nullptr, "You can create only one application instance per program");
s_application = this;
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
// Initialisation du SDK
Sdk::Initialize();
}
inline Application::~Application()
{
m_worlds.clear();
#ifndef NDK_SERVER
m_windows.clear();
#endif
// Libération du SDK
Sdk::Uninitialize();
// Libération automatique des modules
s_application = nullptr;
}
#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(new T(std::forward<Args>(args)...));
return static_cast<T&>(*m_windows.back().get());
}
#endif
template<typename... Args>
World& Application::AddWorld(Args&&... args)
{
m_worlds.emplace_back(std::forward<Args>(args)...);
return m_worlds.back();
}
inline float Application::GetUpdateTime() const
{
return m_updateTime;
}
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
inline void Application::Quit()
{
m_shouldQuit = true;
}
inline Application* Application::Instance()
{
return s_application;
}
}