diff --git a/include/state-machine_pool.hpp b/include/state-machine_pool.hpp index 4432294..722b5b7 100755 --- a/include/state-machine_pool.hpp +++ b/include/state-machine_pool.hpp @@ -30,20 +30,25 @@ class StateMachinePool { void UpdateAll() { for (const auto &[id, machine] : machines) { - auto &owner = machine->GetOwner(); - const std::string ¤t = machine->GetCurrentStateId(); - - auto it = transitions.find(current); - if (it != transitions.end() && auto_transition == true) - for (const auto &transition : it->second) - if (transition.condition(owner)) { - machine->ChangeState(transition.target_state); - break; - } - machine->Update(); + Update(id); } } + void Update(const std::string &id) { + auto &machine = machines.find(id); + auto &owner = machine->GetOwner(); + const std::string ¤t = machine->GetCurrentStateId(); + + auto it = transitions.find(current); + if (it != transitions.end() && auto_transition == true) + for (const auto &transition : it->second) + if (transition.condition(owner)) { + machine->ChangeState(transition.target_state); + break; + } + machine->Update(); + } + void ChangeState(const std::string &id, const std::string &stateId) { auto it = machines.find(id); const std::string current = it->second->GetCurrentStateId(); diff --git a/include/state_system.hpp b/include/state_system.hpp index a9b1441..053529d 100644 --- a/include/state_system.hpp +++ b/include/state_system.hpp @@ -43,6 +43,11 @@ class StateSystem { GetPool().UpdateAll(); } + template + void Update(const std::string &id) { + GetPool().Update(id); + } + template json Serialize() const { StateMachinePool &pool = GetPool();