Files
NazaraEngine/SDK/include/NDK/StateMachine.inl
Lynix e7b940c6cf SDK/StateMachine: Add GetCurrentState function
Former-commit-id: 3fb462b92a8b1190c974f16079458fccbcc0135a [formerly 4092a64ff127dd696ea0f824687670a18367e28f] [formerly 926df48c28edb7db9682e4a16613f5a6e12e8f26 [formerly 2cff9c75a1b974b6407fd0ff577dd50d620f18e2]]
Former-commit-id: 3555eea4a1e89a4c6e750349c55e603b6d4dc237 [formerly b60dbd584782aafc339acaa666cd45508ef9891d]
Former-commit-id: 0ddbe91d5bab84c65429e651ed8585d7129e04f0
2016-08-03 13:46:42 +02:00

46 lines
1.0 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/Error.hpp>
#include <NDK/StateMachine.hpp>
#include <utility>
namespace Ndk
{
inline StateMachine::StateMachine(std::shared_ptr<State> originalState) :
m_currentState(std::move(originalState))
{
NazaraAssert(m_currentState, "StateMachine must have a state to begin with");
m_currentState->Enter(*this);
}
inline StateMachine::~StateMachine()
{
m_currentState->Leave(*this);
}
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
{
m_nextState = std::move(state);
}
inline const std::shared_ptr<State>& StateMachine::GetCurrentState() const
{
return m_currentState;
}
inline bool StateMachine::Update(float elapsedTime)
{
if (m_nextState)
{
m_currentState->Leave(*this);
m_currentState = std::move(m_nextState);
m_currentState->Enter(*this);
}
return m_currentState->Update(*this, elapsedTime);
}
}