Core/Application: Add updaters
This commit is contained in:
parent
a71d4885f9
commit
2b7ff9274c
|
|
@ -32,11 +32,11 @@
|
|||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/AppEntitySystemComponent.hpp>
|
||||
#include <Nazara/Core/Application.hpp>
|
||||
#include <Nazara/Core/ApplicationBase.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/ApplicationComponentRegistry.hpp>
|
||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteArrayPool.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
|
@ -26,6 +27,7 @@ namespace Nz
|
|||
~ApplicationBase() = default;
|
||||
|
||||
template<typename T, typename... Args> T& AddComponent(Args&&... args);
|
||||
template<typename F> void AddUpdater(F&& functor);
|
||||
|
||||
inline void ClearComponents();
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ namespace Nz
|
|||
|
||||
inline void Quit();
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
bool Update(Time elapsedTime);
|
||||
|
||||
ApplicationBase& operator=(const ApplicationBase&) = delete;
|
||||
ApplicationBase& operator=(ApplicationBase&&) = delete;
|
||||
|
|
@ -44,6 +46,7 @@ namespace Nz
|
|||
private:
|
||||
std::atomic_bool m_running;
|
||||
std::vector<std::unique_ptr<ApplicationComponent>> m_components;
|
||||
std::vector<std::unique_ptr<ApplicationUpdater>> m_updaters;
|
||||
HighPrecisionClock m_clock;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,12 @@ namespace Nz
|
|||
return componentRef;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void ApplicationBase::AddUpdater(F&& functor)
|
||||
{
|
||||
m_updaters.emplace_back(std::make_unique<ApplicationUpdaterFunctor<std::decay_t<F>>>(std::forward<F>(functor)));
|
||||
}
|
||||
|
||||
inline void ApplicationBase::ClearComponents()
|
||||
{
|
||||
m_components.clear();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_APPLICATIONUPDATER_HPP
|
||||
#define NAZARA_CORE_APPLICATIONUPDATER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API ApplicationUpdater
|
||||
{
|
||||
public:
|
||||
ApplicationUpdater() = default;
|
||||
ApplicationUpdater(const ApplicationUpdater&) = delete;
|
||||
ApplicationUpdater(ApplicationUpdater&&) = delete;
|
||||
virtual ~ApplicationUpdater();
|
||||
|
||||
virtual void Update(Time elapsedTime) = 0;
|
||||
|
||||
ApplicationUpdater& operator=(const ApplicationUpdater&) = delete;
|
||||
ApplicationUpdater& operator=(ApplicationUpdater&&) = delete;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
class ApplicationUpdaterFunctor : public ApplicationUpdater
|
||||
{
|
||||
public:
|
||||
ApplicationUpdaterFunctor(F functor);
|
||||
|
||||
void Update(Time elapsedTime) override;
|
||||
|
||||
private:
|
||||
F m_functor;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ApplicationUpdater.inl>
|
||||
|
||||
#endif // NAZARA_CORE_APPLICATIONUPDATER_HPP
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename F>
|
||||
ApplicationUpdaterFunctor<F>::ApplicationUpdaterFunctor(F functor) :
|
||||
m_functor(std::move(functor))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void ApplicationUpdaterFunctor<F>::Update(Time elapsedTime)
|
||||
{
|
||||
m_functor(elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -26,12 +26,17 @@ namespace Nz
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ApplicationBase::Update(Time elapsedTime)
|
||||
bool ApplicationBase::Update(Time elapsedTime)
|
||||
{
|
||||
for (auto& componentPtr : m_components)
|
||||
{
|
||||
if (componentPtr)
|
||||
componentPtr->Update(elapsedTime);
|
||||
}
|
||||
|
||||
for (auto& updater : m_updaters)
|
||||
updater->Update(elapsedTime);
|
||||
|
||||
return m_running;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ApplicationUpdater.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ApplicationUpdater::~ApplicationUpdater() = default;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ on_run(function ()
|
|||
end
|
||||
|
||||
paths["Audio"].Excludes["OpenALFunctions.hpp"] = true
|
||||
paths["Core"].Excludes["ECS.hpp"] = true
|
||||
paths["Core"].Excludes["AppEntitySystemComponent.hpp"] = true
|
||||
paths["OpenGLRenderer"].Excludes["Wrapper.hpp"] = true
|
||||
paths["VulkanRenderer"].Excludes["Wrapper.hpp"] = true
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue