send world to client
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <td/misc/Signal.h>
|
||||
|
||||
namespace td {
|
||||
|
||||
@@ -16,7 +16,7 @@ class StateMachine {
|
||||
virtual TReturn Update(TArgs... args) = 0;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T* ChangeState(Args&&... args) {
|
||||
T* ChangeState(Args... args) {
|
||||
return m_StateMachine.template ChangeState<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -24,18 +24,25 @@ class StateMachine {
|
||||
TDerived& m_StateMachine;
|
||||
};
|
||||
|
||||
utils::Signal<State&> OnStateChange;
|
||||
|
||||
StateMachine() {}
|
||||
StateMachine(StateMachine&&) = default;
|
||||
virtual ~StateMachine() {}
|
||||
|
||||
virtual TReturn Update(TArgs... args) {
|
||||
assert(m_State && "You must change state at least once before updating !");
|
||||
return m_State->Update(args...);
|
||||
return m_State->Update(std::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T* ChangeState(Args&&... args) {
|
||||
m_State = std::make_unique<T>(static_cast<TDerived&>(*this), std::forward<Args>(args)...);
|
||||
T* ChangeState(Args... args) {
|
||||
auto* currentState = m_State.get();
|
||||
auto newState = std::make_unique<T>(static_cast<TDerived&>(*this), std::forward<Args>(args)...);
|
||||
// This allows chaining
|
||||
if (m_State.get() == currentState)
|
||||
m_State = std::move(newState);
|
||||
OnStateChange(*m_State);
|
||||
return static_cast<T*>(m_State.get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user