Make Application template and responsible for modules init
This commit is contained in:
@@ -8,39 +8,25 @@
|
||||
#define NAZARA_CORE_APPLICATION_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <Nazara/Core/ApplicationBase.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API Application
|
||||
template<typename... ModuleList>
|
||||
class Application : public ApplicationBase
|
||||
{
|
||||
public:
|
||||
inline Application();
|
||||
inline Application(int argc, char** argv);
|
||||
Application(int argc, const char** argv);
|
||||
using ApplicationBase::ApplicationBase;
|
||||
Application(const Application&) = delete;
|
||||
Application(Application&&) = delete;
|
||||
~Application() = default;
|
||||
|
||||
template<typename T, typename... Args> T& AddComponent(Args&&... args);
|
||||
inline void AddComponent(std::unique_ptr<ApplicationComponent>&& component);
|
||||
|
||||
int Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
Application& operator=(const Application&) = delete;
|
||||
Application& operator=(Application&&) = delete;
|
||||
|
||||
private:
|
||||
std::atomic_bool m_running;
|
||||
std::vector<ApplicationComponent> m_components;
|
||||
HighPrecisionClock m_clock;
|
||||
Modules<ModuleList...> m_modules;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,35 +7,6 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T, typename ...Args>
|
||||
T& Nz::Application::AddComponent(Args&& ...args)
|
||||
{
|
||||
std::unique_ptr<T> component = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
T& componentRef = *component;
|
||||
AddComponent(std::move(component));
|
||||
|
||||
return componentRef;
|
||||
}
|
||||
|
||||
inline Application::Application() :
|
||||
Application(0, static_cast<const char**>(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
inline Application::Application(int argc, char** argv) :
|
||||
Application(argc, static_cast<const char**>(argv))
|
||||
{
|
||||
}
|
||||
|
||||
void Application::AddComponent(std::unique_ptr<ApplicationComponent>&& component)
|
||||
{
|
||||
m_components.emplace_back(std::move(component));
|
||||
}
|
||||
|
||||
inline void Application::Quit()
|
||||
{
|
||||
m_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
49
include/Nazara/Core/ApplicationBase.hpp
Normal file
49
include/Nazara/Core/ApplicationBase.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_APPLICATIONBASE_HPP
|
||||
#define NAZARA_CORE_APPLICATIONBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API ApplicationBase
|
||||
{
|
||||
public:
|
||||
inline ApplicationBase();
|
||||
inline ApplicationBase(int argc, char** argv);
|
||||
ApplicationBase(int argc, const Pointer<const char>* argv);
|
||||
ApplicationBase(const ApplicationBase&) = delete;
|
||||
ApplicationBase(ApplicationBase&&) = delete;
|
||||
~ApplicationBase() = default;
|
||||
|
||||
template<typename T, typename... Args> T& AddComponent(Args&&... args);
|
||||
inline void AddComponent(std::unique_ptr<ApplicationComponent>&& component);
|
||||
|
||||
int Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
ApplicationBase& operator=(const ApplicationBase&) = delete;
|
||||
ApplicationBase& operator=(ApplicationBase&&) = delete;
|
||||
|
||||
private:
|
||||
std::atomic_bool m_running;
|
||||
std::vector<std::unique_ptr<ApplicationComponent>> m_components;
|
||||
HighPrecisionClock m_clock;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ApplicationBase.inl>
|
||||
|
||||
#endif // NAZARA_CORE_APPLICATIONBASE_HPP
|
||||
41
include/Nazara/Core/ApplicationBase.inl
Normal file
41
include/Nazara/Core/ApplicationBase.inl
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ApplicationBase.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T, typename ...Args>
|
||||
T& Nz::ApplicationBase::AddComponent(Args&& ...args)
|
||||
{
|
||||
std::unique_ptr<T> component = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
T& componentRef = *component;
|
||||
AddComponent(std::move(component));
|
||||
|
||||
return componentRef;
|
||||
}
|
||||
|
||||
inline ApplicationBase::ApplicationBase() :
|
||||
ApplicationBase(0, static_cast<const char**>(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
inline ApplicationBase::ApplicationBase(int argc, char** argv) :
|
||||
ApplicationBase(argc, const_cast<const Pointer<const char>*>(argv))
|
||||
{
|
||||
}
|
||||
|
||||
void ApplicationBase::AddComponent(std::unique_ptr<ApplicationComponent>&& component)
|
||||
{
|
||||
m_components.emplace_back(std::move(component));
|
||||
}
|
||||
|
||||
inline void ApplicationBase::Quit()
|
||||
{
|
||||
m_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user