diff --git a/include/Nazara/Core/ApplicationBase.hpp b/include/Nazara/Core/ApplicationBase.hpp index 1663a3366..7d529624c 100644 --- a/include/Nazara/Core/ApplicationBase.hpp +++ b/include/Nazara/Core/ApplicationBase.hpp @@ -42,10 +42,15 @@ namespace Nz template T& GetComponent(); template const T& GetComponent() const; + template bool HasComponent() const; + inline void Quit(); int Run(); + template T* TryGetComponent(); + template const T* TryGetComponent() const; + bool Update(Time elapsedTime); ApplicationBase& operator=(const ApplicationBase&) = delete; diff --git a/include/Nazara/Core/ApplicationBase.inl b/include/Nazara/Core/ApplicationBase.inl index 5c97fb228..0cdf9ca7b 100644 --- a/include/Nazara/Core/ApplicationBase.inl +++ b/include/Nazara/Core/ApplicationBase.inl @@ -75,11 +75,41 @@ namespace Nz return static_cast(*m_components[componentIndex]); } + template + bool ApplicationBase::HasComponent() const + { + std::size_t componentIndex = ApplicationComponentRegistry::GetComponentId(); + if (componentIndex >= m_components.size()) + return false; + + return m_components[componentIndex] != nullptr; + } + inline void ApplicationBase::Quit() { m_running = false; } + template + T* ApplicationBase::TryGetComponent() + { + std::size_t componentIndex = ApplicationComponentRegistry::GetComponentId(); + if (componentIndex >= m_components.size()) + return nullptr; + + return static_cast(m_components[componentIndex].get()); + } + + template + const T* ApplicationBase::TryGetComponent() const + { + std::size_t componentIndex = ApplicationComponentRegistry::GetComponentId(); + if (componentIndex >= m_components.size()) + return nullptr; + + return static_cast(m_components[componentIndex].get()); + } + inline ApplicationBase* ApplicationBase::Instance() { return s_instance; @@ -116,3 +146,4 @@ namespace Nz } #include +#include "ApplicationBase.hpp"