From be1e34456b87cf89d1abd08651bd52a98d5f8ff9 Mon Sep 17 00:00:00 2001 From: Marcel da Silva Date: Thu, 3 Jul 2025 15:23:09 +0200 Subject: [PATCH] allow state transitions while in stateLogic execution --- src/State.cpp | 3 +-- src/State.h | 2 +- src/StateMachine.cpp | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/State.cpp b/src/State.cpp index b8ed521..e9e1d59 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -56,9 +56,8 @@ int State::evalTransitions(){ * all available transitions. The transition that * returns true is returned. */ -int State::execute(){ +void State::execute(){ stateLogic(); - return evalTransitions(); } /* diff --git a/src/State.h b/src/State.h index a13b237..a75aafe 100644 --- a/src/State.h +++ b/src/State.h @@ -27,7 +27,7 @@ class State{ void addTransition(bool (*c)(), State* s); void addTransition(bool (*c)(), int stateNumber); int evalTransitions(); - int execute(); + void execute(); int setTransition(int index, int stateNumber); //Can now dynamically set the transition // stateLogic is the pointer to the function diff --git a/src/StateMachine.cpp b/src/StateMachine.cpp index 116ba43..d9b3287 100644 --- a/src/StateMachine.cpp +++ b/src/StateMachine.cpp @@ -28,7 +28,8 @@ void StateMachine::run(){ // if it wasnt't changed in state logic. If it was, we // should ignore predefined transitions. int initialState = currentState; - int next = stateList->get(currentState)->execute(); + stateList->get(currentState)->execute(); + int next = stateList->get(currentState)->evalTransitions(); if(initialState == currentState){ executeOnce = (currentState == next)?false:true; currentState = next;