Core/ApplicationBase: Add methods to query components

This commit is contained in:
SirLynix
2024-01-24 17:41:57 +01:00
parent e14614cf41
commit 086152c97d
2 changed files with 36 additions and 0 deletions

View File

@@ -75,11 +75,41 @@ namespace Nz
return static_cast<const T&>(*m_components[componentIndex]);
}
template<typename T>
bool ApplicationBase::HasComponent() const
{
std::size_t componentIndex = ApplicationComponentRegistry<T>::GetComponentId();
if (componentIndex >= m_components.size())
return false;
return m_components[componentIndex] != nullptr;
}
inline void ApplicationBase::Quit()
{
m_running = false;
}
template<typename T>
T* ApplicationBase::TryGetComponent()
{
std::size_t componentIndex = ApplicationComponentRegistry<T>::GetComponentId();
if (componentIndex >= m_components.size())
return nullptr;
return static_cast<T*>(m_components[componentIndex].get());
}
template<typename T>
const T* ApplicationBase::TryGetComponent() const
{
std::size_t componentIndex = ApplicationComponentRegistry<T>::GetComponentId();
if (componentIndex >= m_components.size())
return nullptr;
return static_cast<const T*>(m_components[componentIndex].get());
}
inline ApplicationBase* ApplicationBase::Instance()
{
return s_instance;
@@ -116,3 +146,4 @@ namespace Nz
}
#include <Nazara/Core/DebugOff.hpp>
#include "ApplicationBase.hpp"