Added MachinePool::Update
MachinePool::Update allows a user update the states of a single machine
This commit is contained in:
parent
7f441153ab
commit
c42b0aa5bf
@ -30,20 +30,25 @@ class StateMachinePool {
|
|||||||
|
|
||||||
void UpdateAll() {
|
void UpdateAll() {
|
||||||
for (const auto &[id, machine] : machines) {
|
for (const auto &[id, machine] : machines) {
|
||||||
auto &owner = machine->GetOwner();
|
Update(id);
|
||||||
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 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) {
|
void ChangeState(const std::string &id, const std::string &stateId) {
|
||||||
auto it = machines.find(id);
|
auto it = machines.find(id);
|
||||||
const std::string current = it->second->GetCurrentStateId();
|
const std::string current = it->second->GetCurrentStateId();
|
||||||
|
|||||||
@ -43,6 +43,11 @@ class StateSystem {
|
|||||||
GetPool<T>().UpdateAll();
|
GetPool<T>().UpdateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Update(const std::string &id) {
|
||||||
|
GetPool<T>().Update(id);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
json Serialize() const {
|
json Serialize() const {
|
||||||
StateMachinePool<T> &pool = GetPool<T>();
|
StateMachinePool<T> &pool = GetPool<T>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user