Files
NazaraEngine/SDK/include/NDK/StateMachine.inl
Lynix ee1bd866ab SDK/StateMachine: Add GetCurrentState function
Former-commit-id: 20b8c0d81deb5d5c6aafc1c8d4d261b046f260c3 [formerly 37762eaaf8bd7c0b2434b65dfc62d95d4ae2db15] [formerly 5606a74447be6048ce12a502722a75c726cbf9ef [formerly cc437974e34587cf7f63d8fb7f5447473826ee1c]]
Former-commit-id: 677c22d4ebcfa8bf22a85210712fea061dedc0da [formerly 3979a42d5a2ed3c2635ed654bf6f25b88c32a00e]
Former-commit-id: 0d31a924eead5ed4f384fcbdde6411054c3a9b27
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);
}
}