Core/ApplicationBase: Add methods to query components
This commit is contained in:
parent
e14614cf41
commit
086152c97d
|
|
@ -42,10 +42,15 @@ namespace Nz
|
||||||
template<typename T> T& GetComponent();
|
template<typename T> T& GetComponent();
|
||||||
template<typename T> const T& GetComponent() const;
|
template<typename T> const T& GetComponent() const;
|
||||||
|
|
||||||
|
template<typename T> bool HasComponent() const;
|
||||||
|
|
||||||
inline void Quit();
|
inline void Quit();
|
||||||
|
|
||||||
int Run();
|
int Run();
|
||||||
|
|
||||||
|
template<typename T> T* TryGetComponent();
|
||||||
|
template<typename T> const T* TryGetComponent() const;
|
||||||
|
|
||||||
bool Update(Time elapsedTime);
|
bool Update(Time elapsedTime);
|
||||||
|
|
||||||
ApplicationBase& operator=(const ApplicationBase&) = delete;
|
ApplicationBase& operator=(const ApplicationBase&) = delete;
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,41 @@ namespace Nz
|
||||||
return static_cast<const T&>(*m_components[componentIndex]);
|
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()
|
inline void ApplicationBase::Quit()
|
||||||
{
|
{
|
||||||
m_running = false;
|
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()
|
inline ApplicationBase* ApplicationBase::Instance()
|
||||||
{
|
{
|
||||||
return s_instance;
|
return s_instance;
|
||||||
|
|
@ -116,3 +146,4 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/DebugOff.hpp>
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
#include "ApplicationBase.hpp"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue