Sdk: Add automatic system update

Former-commit-id: ce129cc945e7373ac5b9f48960894712d66b097a
This commit is contained in:
Lynix
2015-06-22 00:58:46 +02:00
parent 4b5c08e739
commit 90363406a6
12 changed files with 101 additions and 58 deletions

View File

@@ -10,12 +10,15 @@ namespace Ndk
inline BaseSystem::BaseSystem(SystemIndex systemId) :
m_systemIndex(systemId)
{
SetUpdateRate(30);
}
inline BaseSystem::BaseSystem(const BaseSystem& system) :
m_excludedComponents(system.m_excludedComponents),
m_requiredComponents(system.m_requiredComponents),
m_systemIndex(system.m_systemIndex)
m_systemIndex(system.m_systemIndex),
m_updateCounter(0.f),
m_updateRate(system.m_updateRate)
{
}
@@ -29,6 +32,11 @@ namespace Ndk
return m_systemIndex;
}
inline float BaseSystem::GetUpdateRate() const
{
return 1.f / m_updateRate;
}
inline World& BaseSystem::GetWorld() const
{
return *m_world;
@@ -42,6 +50,22 @@ namespace Ndk
return m_entityBits.UnboundedTest(entity->GetId());
}
inline void BaseSystem::SetUpdateRate(float updatePerSecond)
{
m_updateCounter = 0.f;
m_updateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
}
inline void BaseSystem::Update(float elapsedTime)
{
m_updateCounter -= elapsedTime;
if (m_updateCounter < 0.f)
{
m_updateCounter += m_updateRate;
OnUpdate(elapsedTime);
}
}
template<typename ComponentType>
void BaseSystem::Excludes()
{