From 4827ef9d1ad5fcb7c92fb00319ff241e73314b1c Mon Sep 17 00:00:00 2001 From: Andrew Gresyk Date: Mon, 1 Jan 2024 20:44:40 +0200 Subject: [PATCH 1/2] 2.5.0 --- development/hfsm2/detail/config.hpp | 28 +- development/hfsm2/detail/containers/array.inl | 2 +- .../hfsm2/detail/features/transition.hpp | 8 +- development/hfsm2/detail/root/control_0.hpp | 10 + development/hfsm2/detail/root/control_0.inl | 22 + development/hfsm2/detail/root/control_3.hpp | 10 +- development/hfsm2/detail/root/control_3.inl | 54 +- development/hfsm2/detail/root/control_5.hpp | 33 + development/hfsm2/detail/root/plan_2.hpp | 8 + development/hfsm2/detail/root/plan_2.inl | 10 +- development/hfsm2/detail/root/plan_data.hpp | 9 + development/hfsm2/detail/root/plan_data.inl | 48 +- development/hfsm2/detail/root/registry.hpp | 5 + development/hfsm2/detail/root/registry_1.inl | 58 +- development/hfsm2/detail/root/registry_2.inl | 52 +- development/hfsm2/detail/root_0.hpp | 21 +- development/hfsm2/detail/root_0.inl | 6 +- .../hfsm2/detail/structure/ancestors_1.hpp | 7 +- .../hfsm2/detail/structure/ancestors_1.inl | 6 +- .../hfsm2/detail/structure/ancestors_2.hpp | 17 +- .../hfsm2/detail/structure/ancestors_2.inl | 6 +- development/hfsm2/detail/structure/base.hpp | 7 +- .../hfsm2/detail/structure/composite.hpp | 92 +- .../hfsm2/detail/structure/composite.inl | 41 +- .../detail/structure/composite_sub_1.hpp | 7 +- .../detail/structure/composite_sub_1.inl | 6 +- .../detail/structure/composite_sub_2.hpp | 7 +- .../detail/structure/composite_sub_2.inl | 6 +- .../hfsm2/detail/structure/forward.hpp | 7 + .../hfsm2/detail/structure/orthogonal.hpp | 20 +- .../hfsm2/detail/structure/orthogonal.inl | 37 +- .../detail/structure/orthogonal_sub_1.hpp | 7 +- .../detail/structure/orthogonal_sub_1.inl | 6 +- .../detail/structure/orthogonal_sub_2.hpp | 7 +- .../detail/structure/orthogonal_sub_2.inl | 6 +- .../hfsm2/detail/structure/reactions.inl | 527 ++++++++ .../hfsm2/detail/structure/state_1.hpp | 7 +- .../hfsm2/detail/structure/state_1.inl | 12 +- .../hfsm2/detail/structure/state_2.hpp | 7 +- .../hfsm2/detail/structure/state_2.inl | 12 +- development/hfsm2/machine_dev.hpp | 7 +- examples/advanced_event_handling/main.cpp | 12 +- examples/basic_audio_player/main.cpp | 20 +- examples/calculator/main.cpp | 86 +- examples/debug_logger_interface/main.cpp | 34 +- examples/snippets/wiki_utility-theory.cpp | 32 +- include/hfsm2/machine.hpp | 1135 ++++++++++++----- projects/premake/hfsm2-lite.sln | 84 +- projects/premake/test-14.vcxproj | 2 + projects/premake/test-14.vcxproj.filters | 6 + projects/premake/test-15.vcxproj | 2 + projects/premake/test-15.vcxproj.filters | 6 + projects/premake/test-16.vcxproj | 2 + projects/premake/test-16.vcxproj.filters | 6 + projects/premake/test-17.vcxproj | 2 + projects/premake/test-17.vcxproj.filters | 6 + projects/premake/test-clang.vcxproj | 2 + projects/premake/test-clang.vcxproj.filters | 6 + test/reported/issue_49.cpp | 4 +- test/shared/test_task_list.cpp | 56 +- test/test_ancestors.cpp | 6 +- test/test_internal_payloads.cpp | 10 +- test/test_internal_transitions.cpp | 10 +- test/test_react_order.cpp | 162 +++ test/tools.hpp | 16 +- test/wiki_tutorial.cpp | 8 +- 66 files changed, 2200 insertions(+), 763 deletions(-) create mode 100644 development/hfsm2/detail/structure/reactions.inl create mode 100644 test/test_react_order.cpp diff --git a/development/hfsm2/detail/config.hpp b/development/hfsm2/detail/config.hpp index 580ff9d..4ec6fee 100644 --- a/development/hfsm2/detail/config.hpp +++ b/development/hfsm2/detail/config.hpp @@ -32,10 +32,6 @@ struct G_ final { using RNG = TRNG; #endif -#if HFSM2_LOG_INTERFACE_AVAILABLE() - using LoggerInterface = LoggerInterfaceT; -#endif - static constexpr Short SUBSTITUTION_LIMIT = NSubstitutionLimit; #if HFSM2_PLANS_AVAILABLE() @@ -49,8 +45,12 @@ struct G_ final { using Task = TaskT; #endif +#if HFSM2_LOG_INTERFACE_AVAILABLE() + using LoggerInterface = LoggerInterfaceT; +#endif + /// @brief Set Context type - /// @tparam T Context type for data shared between states and/or data interface between FSM and external code + /// @tparam `T` Context type for data shared between states and/or data interface between FSM and external code template using ContextT = G_; @@ -63,38 +63,38 @@ struct G_ final { #if HFSM2_UTILITY_THEORY_AVAILABLE() /// @brief Set Rank type - /// @tparam T Rank type for 'TRank State::rank() const' method + /// @tparam `T` Rank type for 'TRank State::rank() const' method template using RankT = G_; /// @brief Set Utility type - /// @tparam T Utility type for 'TUtility State::utility() const' method + /// @tparam `T` Utility type for 'TUtility State::utility() const' method template using UtilityT = G_; /// @brief Set RNG type - /// @tparam T RNG type used in 'Random' regions + /// @tparam `T` RNG type used in 'Random' regions template using RandomT = G_; #endif /// @brief Set Substitution limit - /// @tparam N Maximum number times 'guard()' methods can substitute their states for others - template + /// @tparam `N` Maximum number times 'guard()' methods can substitute their states for others + template using SubstitutionLimitN = G_; #if HFSM2_PLANS_AVAILABLE() /// @brief Set Task capacity - /// @tparam N Maximum number of tasks across all plans + /// @tparam `N` Maximum number of tasks across all plans template using TaskCapacityN = G_; #endif /// @brief Set Transition Payload type - /// @tparam T Utility type for 'TUtility State::utility() const' method + /// @tparam `T` Payload type template using PayloadT = G_; @@ -364,8 +364,8 @@ using Config = detail::G_< >; /// @brief 'Template namespace' for FSM classes -/// @tparam TConfig 'ConfigT<>' type configuration for MachineT<> -/// @see ConfigT<> +/// @tparam `TConfig` `ConfigT<>` type configuration for MachineT<> +/// @see `ConfigT<>` template using MachineT = detail::M_; diff --git a/development/hfsm2/detail/containers/array.inl b/development/hfsm2/detail/containers/array.inl index 8b1b117..b5cab0d 100644 --- a/development/hfsm2/detail/containers/array.inl +++ b/development/hfsm2/detail/containers/array.inl @@ -7,7 +7,7 @@ template template HFSM2_CONSTEXPR(14) T& -StaticArrayT::operator[] (const N index) noexcept { +StaticArrayT::operator[] (const N index) noexcept { HFSM2_ASSERT(0 <= index && index < CAPACITY); return _items[static_cast(index)]; diff --git a/development/hfsm2/detail/features/transition.hpp b/development/hfsm2/detail/features/transition.hpp index 3daaf14..756e5c4 100644 --- a/development/hfsm2/detail/features/transition.hpp +++ b/development/hfsm2/detail/features/transition.hpp @@ -183,9 +183,9 @@ struct TransitionBase { HFSM2_CONSTEXPR(11) bool operator == (const TransitionBase& other) const noexcept { - return origin == other.origin && + return origin == other.origin && destination == other.destination && - method == other.method && + method == other.method && type == other.type; } @@ -194,9 +194,9 @@ struct TransitionBase { HFSM2_CONSTEXPR(11) bool operator != (const TransitionBase& other) const noexcept { - return origin != other.origin || + return origin != other.origin || destination != other.destination || - method != other.method || + method != other.method || type != other.type; } diff --git a/development/hfsm2/detail/root/control_0.hpp b/development/hfsm2/detail/root/control_0.hpp index 0ef22a7..3dea67a 100644 --- a/development/hfsm2/detail/root/control_0.hpp +++ b/development/hfsm2/detail/root/control_0.hpp @@ -17,6 +17,9 @@ class ConstControlT { template friend class R_; + template + friend struct QueryWrapperT; + protected: using Context = typename TArgs::Context; @@ -125,6 +128,12 @@ class ConstControlT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + /// @brief Stops processing of the current query down the hierarchy + /// @see Config::BottomUpReactions + HFSM2_CONSTEXPR(14) void consumeQuery() noexcept { _consumed = true; } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + /// @brief Inspect current transition requests /// @return Array of transition requests HFSM2_CONSTEXPR(11) const TransitionSet& requests() const noexcept { return _core.requests; } @@ -246,6 +255,7 @@ class ConstControlT { const Core& _core; StateID _originId = INVALID_STATE_ID; RegionID _regionId = 0; + bool _consumed = false; }; //////////////////////////////////////////////////////////////////////////////// diff --git a/development/hfsm2/detail/root/control_0.inl b/development/hfsm2/detail/root/control_0.inl index 9d42357..4454261 100644 --- a/development/hfsm2/detail/root/control_0.inl +++ b/development/hfsm2/detail/root/control_0.inl @@ -44,5 +44,27 @@ ConstControlT::Region::~Region() noexcept { //////////////////////////////////////////////////////////////////////////////// +template +HFSM2_CONSTEXPR(14) +void +ConstControlT::setRegion(const RegionID regionId_) noexcept { + HFSM2_ASSERT(_regionId <= regionId_ && regionId_ < RegionList::SIZE); + + _regionId = regionId_; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +template +HFSM2_CONSTEXPR(14) +void +ConstControlT::resetRegion(const RegionID regionId_) noexcept { + HFSM2_ASSERT(regionId_ <= _regionId && _regionId < RegionList::SIZE); + + _regionId = regionId_; +} + +//////////////////////////////////////////////////////////////////////////////// + } } diff --git a/development/hfsm2/detail/root/control_3.hpp b/development/hfsm2/detail/root/control_3.hpp index de15899..2edc7df 100644 --- a/development/hfsm2/detail/root/control_3.hpp +++ b/development/hfsm2/detail/root/control_3.hpp @@ -221,6 +221,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -233,6 +234,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -246,6 +248,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -271,6 +274,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -445,7 +449,7 @@ class FullControlT< using FullControlBase::_locked; }; -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +//------------------------------------------------------------------------------ template < typename TConfig @@ -454,6 +458,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) > @@ -465,6 +470,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void @@ -478,6 +484,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void @@ -503,6 +510,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void diff --git a/development/hfsm2/detail/root/control_3.inl b/development/hfsm2/detail/root/control_3.inl index 5ed5d6b..e72a2dd 100644 --- a/development/hfsm2/detail/root/control_3.inl +++ b/development/hfsm2/detail/root/control_3.inl @@ -217,12 +217,12 @@ FullControlBaseT::fail(const StateID stateId_) noexcept { #if HFSM2_PLANS_AVAILABLE() -template +template template HFSM2_CONSTEXPR(14) TaskStatus -FullControlT>::updatePlan(TState& headState, - const TaskStatus subStatus) noexcept +FullControlT>::updatePlan(TState& headState, + const TaskStatus subStatus) noexcept { constexpr StateID STATE_ID = TState::STATE_ID; // SPECIFIC @@ -280,11 +280,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::changeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::changeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::CHANGE, payload}); @@ -298,11 +298,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::restartWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::restartWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RESTART, payload}); @@ -316,11 +316,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::resumeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::resumeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RESUME, payload}); @@ -334,11 +334,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::selectWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::selectWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::SELECT, payload}); @@ -354,11 +354,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::utilizeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::utilizeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::UTILIZE, payload}); @@ -372,11 +372,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::randomizeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::randomizeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RANDOMIZE, payload}); @@ -392,11 +392,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::scheduleWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::scheduleWith(const StateID stateId_, + const Payload& payload) noexcept { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::SCHEDULE, payload}); @@ -407,12 +407,12 @@ FullControlT +template template HFSM2_CONSTEXPR(14) TaskStatus -FullControlT>::updatePlan(TState& headState, - const TaskStatus subStatus) noexcept +FullControlT>::updatePlan(TState& headState, + const TaskStatus subStatus) noexcept { constexpr StateID STATE_ID = TState::STATE_ID; // SPECIFIC diff --git a/development/hfsm2/detail/root/control_5.hpp b/development/hfsm2/detail/root/control_5.hpp index 1e01a27..dca68f2 100644 --- a/development/hfsm2/detail/root/control_5.hpp +++ b/development/hfsm2/detail/root/control_5.hpp @@ -3,5 +3,38 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// +template +class EventControlT final + : public FullControlT +{ + template + friend class R_; + + template + friend struct PreReactWrapperT; + + template + friend struct ReactWrapperT; + + template + friend struct PostReactWrapperT; + + using FullControl = FullControlT; + + using FullControl::FullControl; + +public: + using FullControl::context; + + /// @brief Stops processing of the current event down the hierarchy + /// @see `Config::BottomUpReactions` + HFSM2_CONSTEXPR(14) void consumeEvent() noexcept { _consumed = true; } + +private: + bool _consumed = false; +}; + +//////////////////////////////////////////////////////////////////////////////// + } } diff --git a/development/hfsm2/detail/root/plan_2.hpp b/development/hfsm2/detail/root/plan_2.hpp index 1d78321..af8f6a9 100644 --- a/development/hfsm2/detail/root/plan_2.hpp +++ b/development/hfsm2/detail/root/plan_2.hpp @@ -17,6 +17,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity , typename TPayload @@ -29,6 +30,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -42,6 +44,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -67,6 +70,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -357,6 +361,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity > @@ -368,6 +373,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -381,6 +387,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -406,6 +413,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void diff --git a/development/hfsm2/detail/root/plan_2.inl b/development/hfsm2/detail/root/plan_2.inl index f630bc1..f6f2939 100644 --- a/development/hfsm2/detail/root/plan_2.inl +++ b/development/hfsm2/detail/root/plan_2.inl @@ -5,13 +5,13 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// -template +template HFSM2_CONSTEXPR(14) bool -PayloadPlanT>::append(const StateID origin, - const StateID destination, - const TransitionType transitionType, - const Payload& payload) noexcept +PayloadPlanT>:: append(const StateID origin, + const StateID destination, + const TransitionType transitionType, + const Payload& payload) noexcept { if (_planData.tasks.count() < TASK_CAPACITY) { _planData.planExists.set(_regionId); diff --git a/development/hfsm2/detail/root/plan_data.hpp b/development/hfsm2/detail/root/plan_data.hpp index 93b4ab2..058c20f 100644 --- a/development/hfsm2/detail/root/plan_data.hpp +++ b/development/hfsm2/detail/root/plan_data.hpp @@ -55,6 +55,7 @@ template < , Long , Long , Long + , typename HFSM2_IF_SERIALIZATION(, Long) , Long , typename @@ -73,6 +74,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity , typename TPayload @@ -85,6 +87,7 @@ struct PlanDataT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -142,6 +145,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity > @@ -153,6 +157,7 @@ struct PlanDataT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -205,6 +210,7 @@ template < , typename TRegionList , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder , Long NTaskCapacity , typename TPayload > @@ -216,6 +222,7 @@ struct PlanDataT< , 0 , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, 0) , NTaskCapacity , TPayload @@ -241,6 +248,7 @@ template < , typename TRegionList , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder , Long NTaskCapacity > struct PlanDataT< @@ -251,6 +259,7 @@ struct PlanDataT< , 0 , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, 0) , NTaskCapacity , void diff --git a/development/hfsm2/detail/root/plan_data.inl b/development/hfsm2/detail/root/plan_data.inl index 68a8c0f..7cf0224 100644 --- a/development/hfsm2/detail/root/plan_data.inl +++ b/development/hfsm2/detail/root/plan_data.inl @@ -58,10 +58,10 @@ operator |= (TaskStatus& lhs, #if HFSM2_PLANS_AVAILABLE() -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { if (stateId != INVALID_STATE_ID) { tasksSuccesses.clear(stateId); tasksFailures .clear(stateId); @@ -70,10 +70,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { #if HFSM2_ASSERT_AVAILABLE() if (stateId != INVALID_STATE_ID) { @@ -86,20 +86,20 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearRegionStatuses() noexcept { +PlanDataT>::clearRegionStatuses() noexcept { headStatuses.clear(); subStatuses .clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clear() noexcept { +PlanDataT>::clear() noexcept { tasks .clear(); taskLinks .clear(); taskPayloads .clear(); @@ -117,10 +117,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyPlans() const noexcept { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) @@ -131,10 +131,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) Long -PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -174,10 +174,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { if (stateId != INVALID_STATE_ID) { tasksSuccesses.clear(stateId); tasksFailures .clear(stateId); @@ -186,10 +186,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { #if HFSM2_ASSERT_AVAILABLE() if (stateId != INVALID_STATE_ID) { @@ -202,20 +202,20 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearRegionStatuses() noexcept { +PlanDataT>::clearRegionStatuses() noexcept { headStatuses.clear(); subStatuses .clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clear() noexcept { +PlanDataT>::clear() noexcept { tasks .clear(); taskLinks .clear(); @@ -231,10 +231,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyPlans() const noexcept { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) @@ -245,10 +245,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) Long -PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; diff --git a/development/hfsm2/detail/root/registry.hpp b/development/hfsm2/detail/root/registry.hpp index c6a1cd2..e1abac4 100644 --- a/development/hfsm2/detail/root/registry.hpp +++ b/development/hfsm2/detail/root/registry.hpp @@ -54,6 +54,7 @@ template < , Long , Long , Long + , typename HFSM2_IF_SERIALIZATION(, Long) HFSM2_IF_PLANS(, Long) , typename @@ -72,6 +73,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -84,6 +86,7 @@ struct RegistryT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -167,6 +170,7 @@ template < , typename TStateList , typename TRegionList , Long NCompoCount + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -179,6 +183,7 @@ struct RegistryT< , NCompoCount , 0 , 0 + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload diff --git a/development/hfsm2/detail/root/registry_1.inl b/development/hfsm2/detail/root/registry_1.inl index 63b7db8..7fed4e9 100644 --- a/development/hfsm2/detail/root/registry_1.inl +++ b/development/hfsm2/detail/root/registry_1.inl @@ -3,10 +3,10 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// -template +template HFSM2_CONSTEXPR(14) Prong -RegistryT>::activeSubState(const StateID stateId) const noexcept { +RegistryT>::activeSubState(const StateID stateId) const noexcept { const StateID subStateId = stateId + 1; if (HFSM2_CHECKED( stateId < STATE_COUNT) && @@ -25,19 +25,19 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::isActive() const noexcept { +RegistryT>::isActive() const noexcept { return compoActive[0] != INVALID_PRONG; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isActive(const StateID stateId) const noexcept { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { for (Parent parent = stateParents[stateId]; parent; @@ -57,10 +57,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isResumable(const StateID stateId) const noexcept { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -77,10 +77,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingChange(const StateID stateId) const noexcept { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -98,10 +98,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingEnter(const StateID stateId) const noexcept { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -119,10 +119,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingExit(const StateID stateId) const noexcept { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -140,10 +140,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) const Parent& -RegistryT>::forkParent(const ForkID forkId) const noexcept { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId != 0); return forkId > 0 ? @@ -153,10 +153,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) -typename RegistryT>::OrthoBits -RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { +typename RegistryT>::OrthoBits +RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { HFSM2_ASSERT(forkId < 0); const Units& units = orthoUnits[-forkId - 1]; @@ -165,10 +165,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::requestImmediate(const Transition& request) noexcept { +RegistryT>::requestImmediate(const Transition& request) noexcept { if (request.destination == 0) return false; else if (HFSM2_CHECKED(request.destination < STATE_COUNT)) { @@ -220,10 +220,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::requestScheduled(const StateID stateId) noexcept { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -235,10 +235,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clearRequests() noexcept { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -246,10 +246,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clear() noexcept { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); @@ -258,10 +258,10 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::empty() const noexcept { +RegistryT>::empty() const noexcept { return compoRequested.empty() && orthoRequested.empty() && compoRemains .empty() diff --git a/development/hfsm2/detail/root/registry_2.inl b/development/hfsm2/detail/root/registry_2.inl index e46e651..d38b9a3 100644 --- a/development/hfsm2/detail/root/registry_2.inl +++ b/development/hfsm2/detail/root/registry_2.inl @@ -3,10 +3,10 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// -template +template HFSM2_CONSTEXPR(14) Prong -RegistryT>::activeSubState(const StateID stateId) const noexcept { +RegistryT>::activeSubState(const StateID stateId) const noexcept { const StateID subStateId = stateId + 1; if (HFSM2_CHECKED( stateId < STATE_COUNT) && @@ -25,19 +25,19 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::isActive() const noexcept { +RegistryT>::isActive() const noexcept { return compoActive[0] != INVALID_PRONG; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isActive(const StateID stateId) const noexcept { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -52,10 +52,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isResumable(const StateID stateId) const noexcept { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -68,10 +68,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingChange(const StateID stateId) const noexcept { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -85,10 +85,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingEnter(const StateID stateId) const noexcept { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -102,10 +102,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingExit(const StateID stateId) const noexcept { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -119,10 +119,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) const Parent& -RegistryT>::forkParent(const ForkID forkId) const noexcept { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId > 0); return compoParents[forkId - 1]; @@ -130,10 +130,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::requestImmediate(const Transition& request) noexcept { +RegistryT>::requestImmediate(const Transition& request) noexcept { // record request // promote it to all children @@ -174,10 +174,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::requestScheduled(const StateID stateId) noexcept { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -188,10 +188,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clearRequests() noexcept { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -199,10 +199,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clear() noexcept { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); @@ -211,10 +211,10 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::empty() const noexcept { +RegistryT>::empty() const noexcept { return compoRequested.empty() && orthoRequested.empty() && compoRemains .empty() diff --git a/development/hfsm2/detail/root_0.hpp b/development/hfsm2/detail/root_0.hpp index de5510c..11d76ae 100644 --- a/development/hfsm2/detail/root_0.hpp +++ b/development/hfsm2/detail/root_0.hpp @@ -52,6 +52,7 @@ class R_ { using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; static constexpr Short SUBSTITUTION_LIMIT = Forward::SUBSTITUTION_LIMIT; @@ -121,16 +122,6 @@ class R_ { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Access context - /// @return context - HFSM2_CONSTEXPR(14) Context& context() noexcept { return _core.context; } - - /// @brief Access context - /// @return context - HFSM2_CONSTEXPR(11) const Context& context() const noexcept { return _core.context; } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Get state identifier for a state type /// @tparam `TState` State type /// @return Numeric state identifier @@ -147,6 +138,16 @@ class R_ { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + /// @brief Access context + /// @return context + HFSM2_CONSTEXPR(14) Context& context() noexcept { return _core.context; } + + /// @brief Access context + /// @return context + HFSM2_CONSTEXPR(11) const Context& context() const noexcept { return _core.context; } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + /// @brief Access state instance /// @tparam `TState` State type /// @return State instance diff --git a/development/hfsm2/detail/root_0.inl b/development/hfsm2/detail/root_0.inl index 79aad76..76f4ff6 100644 --- a/development/hfsm2/detail/root_0.inl +++ b/development/hfsm2/detail/root_0.inl @@ -74,10 +74,14 @@ R_::react(const TEvent& event) noexcept { HFSM2_ASSERT(_core.registry.isActive()); TransitionSets emptyTransitions; - FullControl control{_core, emptyTransitions}; + EventControl control{_core, emptyTransitions}; _apex. deepPreReact(control, event); + + control._consumed = false; _apex. deepReact(control, event); + + control._consumed = false; _apex.deepPostReact(control, event); #if HFSM2_PLANS_AVAILABLE() diff --git a/development/hfsm2/detail/structure/ancestors_1.hpp b/development/hfsm2/detail/structure/ancestors_1.hpp index b347d25..e614830 100644 --- a/development/hfsm2/detail/structure/ancestors_1.hpp +++ b/development/hfsm2/detail/structure/ancestors_1.hpp @@ -37,6 +37,7 @@ struct HFSM2_EMPTY_BASES A_ using typename First::FullControl; using typename First::GuardControl; + using typename First::EventControl; using First::stateId; using First::regionId; @@ -56,15 +57,15 @@ struct HFSM2_EMPTY_BASES A_ template HFSM2_CONSTEXPR(14) void widePreReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void widePostReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery ( TEvent& event , diff --git a/development/hfsm2/detail/structure/ancestors_1.inl b/development/hfsm2/detail/structure/ancestors_1.inl index 851b551..74cb2ae 100644 --- a/development/hfsm2/detail/structure/ancestors_1.inl +++ b/development/hfsm2/detail/structure/ancestors_1.inl @@ -68,7 +68,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePreReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: preReact(event, control); Rest ::widePreReact(event, control); @@ -81,7 +81,7 @@ template HFSM2_CONSTEXPR(14) void A_::wideReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: react(event, control); Rest ::wideReact(event, control); @@ -94,7 +94,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePostReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { Rest ::widePostReact(event, control); First:: postReact(event, control); diff --git a/development/hfsm2/detail/structure/ancestors_2.hpp b/development/hfsm2/detail/structure/ancestors_2.hpp index b5e6ed6..a74ead4 100644 --- a/development/hfsm2/detail/structure/ancestors_2.hpp +++ b/development/hfsm2/detail/structure/ancestors_2.hpp @@ -4,7 +4,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -struct A_ +struct HFSM2_EMPTY_BASES A_ : TFirst { using First = TFirst; @@ -31,10 +31,13 @@ struct A_ using typename First::FullControl; using typename First::GuardControl; + using typename First::EventControl; using First::stateId; using First::regionId; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HFSM2_CONSTEXPR(14) Prong select (const Control& ) noexcept { return 0; } #if HFSM2_UTILITY_THEORY_AVAILABLE() @@ -55,15 +58,15 @@ struct A_ template HFSM2_CONSTEXPR(14) void preReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void react (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void postReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void query ( TEvent& , @@ -91,15 +94,15 @@ struct A_ template HFSM2_CONSTEXPR(14) void widePreReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void widePostReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery ( TEvent& event , diff --git a/development/hfsm2/detail/structure/ancestors_2.inl b/development/hfsm2/detail/structure/ancestors_2.inl index 6bea58b..aa32fd5 100644 --- a/development/hfsm2/detail/structure/ancestors_2.inl +++ b/development/hfsm2/detail/structure/ancestors_2.inl @@ -62,7 +62,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePreReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: preReact(event, control); } @@ -74,7 +74,7 @@ template HFSM2_CONSTEXPR(14) void A_::wideReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: react(event, control); } @@ -86,7 +86,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePostReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: postReact(event, control); } diff --git a/development/hfsm2/detail/structure/base.hpp b/development/hfsm2/detail/structure/base.hpp index ed1f051..1f3f555 100644 --- a/development/hfsm2/detail/structure/base.hpp +++ b/development/hfsm2/detail/structure/base.hpp @@ -30,6 +30,7 @@ class B_ { using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; #if HFSM2_PLANS_AVAILABLE() using Plan = PayloadPlanT ; @@ -49,15 +50,15 @@ class B_ { template HFSM2_CONSTEXPR(14) void preReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void react (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void postReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void query ( TEvent& , diff --git a/development/hfsm2/detail/structure/composite.hpp b/development/hfsm2/detail/structure/composite.hpp index 944746d..7fa3b2f 100644 --- a/development/hfsm2/detail/structure/composite.hpp +++ b/development/hfsm2/detail/structure/composite.hpp @@ -25,7 +25,7 @@ struct HFSM2_EMPTY_BASES C_ , TL_ > { - using Indices = TIndices; + using Indices = TIndices; static constexpr StateID HEAD_ID = Indices::STATE_ID; static constexpr Short COMPO_INDEX = Indices::COMPO_INDEX; static constexpr Short ORTHO_INDEX = Indices::ORTHO_INDEX; @@ -36,59 +36,67 @@ struct HFSM2_EMPTY_BASES C_ static constexpr RegionID REGION_ID = COMPO_INDEX + ORTHO_INDEX; static constexpr ForkID COMPO_ID = COMPO_INDEX + 1; - using Args = TArgs; + using Args = TArgs; #if HFSM2_UTILITY_THEORY_AVAILABLE() - using Rank = typename Args::Rank; - using Utility = typename Args::Utility; - using UP = typename Args::UP; + using Rank = typename Args::Rank; + using Utility = typename Args::Utility; + using UP = typename Args::UP; #endif - using StateList = typename Args::StateList; - using RegionList = typename Args::RegionList; + using StateList = typename Args::StateList; + using RegionList = typename Args::RegionList; - using Registry = RegistryT; - using StateParents = typename Registry::StateParents; + using ReactOrder = typename Args::ReactOrder; - using ConstControl = ConstControlT; - using Control = ControlT ; - using ScopedOrigin = typename Control::Origin; + using Registry = RegistryT; + using StateParents = typename Registry::StateParents; - using PlanControl = PlanControlT ; - using ScopedRegion = typename PlanControl::Region; + using ConstControl = ConstControlT; + using ScopedCRegion = typename ConstControl::Region; -#if HFSM2_PLANS_AVAILABLE() - using Plan = typename PlanControl::Plan; -#endif - - using FullControl = FullControlT ; - using ControlLock = typename FullControl::Lock; + using Control = ControlT ; + using ScopedOrigin = typename Control::Origin; - using GuardControl = GuardControlT; + using PlanControl = PlanControlT ; + using FullControl = FullControlT ; + using ControlLock = typename FullControl::Lock; + using ScopedRegion = typename PlanControl::Region; - using Head = THead; - using HeadState = S_; + using GuardControl = GuardControlT; + using EventControl = EventControlT; - using SubStates = CS_< - I_< - HEAD_ID + 1, - COMPO_INDEX + 1, - ORTHO_INDEX, - ORTHO_UNIT - >, - Args, - STRATEGY, - 0, - TL_ - >; - - using Info = CI_; +#if HFSM2_PLANS_AVAILABLE() + using Plan = typename PlanControl::Plan; +#endif + using Head = THead; + using HeadState = S_; + + using SubStates = CS_< + I_< + HEAD_ID + 1, + COMPO_INDEX + 1, + ORTHO_INDEX, + ORTHO_UNIT + >, + Args, + STRATEGY, + 0, + TL_ + >; + + using PreReactWrapper = PreReactWrapperT ; + using ReactWrapper = ReactWrapperT ; + using PostReactWrapper = PostReactWrapperT; + using QueryWrapper = QueryWrapperT ; + + using Info = CI_; static constexpr Short WIDTH = Info::WIDTH; #if HFSM2_UTILITY_THEORY_AVAILABLE() - using Ranks = Rank[WIDTH]; - using Utilities = Utility[WIDTH]; + using Ranks = Rank[WIDTH]; + using Utilities = Utility[WIDTH]; #endif #if HFSM2_SERIALIZATION_AVAILABLE() @@ -139,13 +147,13 @@ struct HFSM2_EMPTY_BASES C_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; diff --git a/development/hfsm2/detail/structure/composite.inl b/development/hfsm2/detail/structure/composite.inl index 365eed9..58af3b8 100644 --- a/development/hfsm2/detail/structure/composite.inl +++ b/development/hfsm2/detail/structure/composite.inl @@ -100,8 +100,9 @@ C_::deepReenter(PlanControl& control) noexcept { active = requested; - if (requested == resumable) + if (requested == resumable) { resumable = INVALID_PRONG; + } SubStates::wideEnter (control, active); } @@ -185,7 +186,7 @@ template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepPreReact(FullControl& control, +C_::deepPreReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -195,14 +196,7 @@ C_::deepPreReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepPreReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePreReact(control, event, active); - - return h; + return PreReactWrapper::execute(*this, control, event, active); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -211,7 +205,7 @@ template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepReact(FullControl& control, +C_::deepReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -221,14 +215,7 @@ C_::deepReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepReact (control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS( subStatus(control) |=) - SubStates::wideReact (control, event, active); - - return h; + return ReactWrapper::execute(*this, control, event, active); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -237,7 +224,7 @@ template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepPostReact(FullControl& control, +C_::deepPostReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -247,14 +234,7 @@ C_::deepPostReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - HFSM2_IF_PLANS( subStatus (control) |=) - SubStates::widePostReact(control, event, active); - - const TaskStatus h = - HeadState::deepPostReact(control, event); - HFSM2_IF_PLANS(headStatus (control) |= h); - - return h; + return PostReactWrapper::execute(*this, control, event, active); } //------------------------------------------------------------------------------ @@ -269,8 +249,9 @@ C_::deepQuery(ConstControl& control, const Prong active = compoActive(control); HFSM2_ASSERT(active < WIDTH); - HeadState::deepQuery(control, event); - SubStates::wideQuery(control, event, active); + ScopedCRegion region{control, REGION_ID}; + + QueryWrapper::execute(*this, control, event, active); } //------------------------------------------------------------------------------ diff --git a/development/hfsm2/detail/structure/composite_sub_1.hpp b/development/hfsm2/detail/structure/composite_sub_1.hpp index 7167162..080cbc6 100644 --- a/development/hfsm2/detail/structure/composite_sub_1.hpp +++ b/development/hfsm2/detail/structure/composite_sub_1.hpp @@ -65,6 +65,7 @@ struct HFSM2_EMPTY_BASES CS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using LStateList = LHalfTypes; using LHalfInfo = CSI_; @@ -105,13 +106,13 @@ struct HFSM2_EMPTY_BASES CS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event, const Prong prong) const noexcept; diff --git a/development/hfsm2/detail/structure/composite_sub_1.inl b/development/hfsm2/detail/structure/composite_sub_1.inl index 87e3c59..bcfccdf 100644 --- a/development/hfsm2/detail/structure/composite_sub_1.inl +++ b/development/hfsm2/detail/structure/composite_sub_1.inl @@ -129,7 +129,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePreReact(FullControl& control, +CS_>::widePreReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { @@ -146,7 +146,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::wideReact(FullControl& control, +CS_>::wideReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { @@ -163,7 +163,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePostReact(FullControl& control, +CS_>::widePostReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { diff --git a/development/hfsm2/detail/structure/composite_sub_2.hpp b/development/hfsm2/detail/structure/composite_sub_2.hpp index e1c4416..e4de305 100644 --- a/development/hfsm2/detail/structure/composite_sub_2.hpp +++ b/development/hfsm2/detail/structure/composite_sub_2.hpp @@ -53,6 +53,7 @@ struct HFSM2_EMPTY_BASES CS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Single = MaterialT< Indices @@ -77,13 +78,13 @@ struct HFSM2_EMPTY_BASES CS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event, const Prong prong) const noexcept; diff --git a/development/hfsm2/detail/structure/composite_sub_2.inl b/development/hfsm2/detail/structure/composite_sub_2.inl index 72310ff..d277c8a 100644 --- a/development/hfsm2/detail/structure/composite_sub_2.inl +++ b/development/hfsm2/detail/structure/composite_sub_2.inl @@ -110,7 +110,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePreReact(FullControl& control, +CS_>::widePreReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { @@ -125,7 +125,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::wideReact(FullControl& control, +CS_>::wideReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { @@ -140,7 +140,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePostReact(FullControl& control, +CS_>::widePostReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { diff --git a/development/hfsm2/detail/structure/forward.hpp b/development/hfsm2/detail/structure/forward.hpp index 52a6e7b..63b58af 100644 --- a/development/hfsm2/detail/structure/forward.hpp +++ b/development/hfsm2/detail/structure/forward.hpp @@ -225,6 +225,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -255,6 +256,8 @@ struct ArgsT final { static constexpr Short ORTHO_COUNT = NOrthoCount; static constexpr Short ORTHO_UNITS = NOrthoUnits; + using ReactOrder = TReactOrder; + #if HFSM2_SERIALIZATION_AVAILABLE() static constexpr Short SERIAL_BITS = NSerialBits; #endif @@ -357,6 +360,8 @@ struct RF_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + using ReactOrder = typename Config::ReactOrder; + using StateList = typename Apex::StateList; using RegionList = typename Apex::RegionList; @@ -389,6 +394,7 @@ struct RF_ final { , COMPO_COUNT , ORTHO_COUNT , ORTHO_UNITS + , ReactOrder HFSM2_IF_SERIALIZATION(, SERIAL_BITS) HFSM2_IF_PLANS(, TASK_CAPACITY) , Payload @@ -402,6 +408,7 @@ struct RF_ final { using Control = ControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/development/hfsm2/detail/structure/orthogonal.hpp b/development/hfsm2/detail/structure/orthogonal.hpp index 4fc0834..09a0b90 100644 --- a/development/hfsm2/detail/structure/orthogonal.hpp +++ b/development/hfsm2/detail/structure/orthogonal.hpp @@ -43,6 +43,8 @@ struct HFSM2_EMPTY_BASES O_ using StateList = typename Args::StateList; using RegionList = typename Args::RegionList; + using ReactOrder = typename Args::ReactOrder; + using Registry = RegistryT; using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; @@ -50,6 +52,8 @@ struct HFSM2_EMPTY_BASES O_ using ProngCBits = typename OrthoForks::CBits; using ConstControl = ConstControlT; + using ScopedCRegion = typename ConstControl::Region; + using Control = ControlT ; using ScopedOrigin = typename Control::Origin; @@ -58,8 +62,11 @@ struct HFSM2_EMPTY_BASES O_ using FullControl = FullControlT ; using ControlLock = typename FullControl::Lock; + using ScopedRegion = typename PlanControl::Region; using GuardControl = GuardControlT; + using EventControl = EventControlT; + using Head = THead; using HeadState = S_; @@ -81,9 +88,14 @@ struct HFSM2_EMPTY_BASES O_ TSubStates... >; + using PreReactWrapper = PreReactWrapperT ; + using ReactWrapper = ReactWrapperT ; + using PostReactWrapper = PostReactWrapperT; + using QueryWrapper = QueryWrapperT ; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Registry& registry) noexcept { return registry.orthoRequested.template bits(); } + HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Registry& registry) noexcept { return registry.orthoRequested.template bits(); } HFSM2_CONSTEXPR(11) static ProngCBits orthoRequested (const Registry& registry) noexcept { return registry.orthoRequested.template cbits(); } HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Control& control ) noexcept { return control._core.registry.orthoRequested.template bits(); } @@ -111,13 +123,13 @@ struct HFSM2_EMPTY_BASES O_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event ) const noexcept; diff --git a/development/hfsm2/detail/structure/orthogonal.inl b/development/hfsm2/detail/structure/orthogonal.inl index b6c656a..eb99235 100644 --- a/development/hfsm2/detail/structure/orthogonal.inl +++ b/development/hfsm2/detail/structure/orthogonal.inl @@ -135,19 +135,12 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepPreReact(FullControl& control, +O_::deepPreReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepPreReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePreReact(control, event); - - return h; + return PreReactWrapper::execute(*this, control, event); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -156,19 +149,12 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepReact(FullControl& control, +O_::deepReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::wideReact(control, event); - - return h; + return ReactWrapper::execute(*this, control, event); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -177,19 +163,12 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepPostReact(FullControl& control, +O_::deepPostReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePostReact(control, event); - - const TaskStatus h = - HeadState::deepPostReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - return h; + return PostReactWrapper::execute(*this, control, event); } //------------------------------------------------------------------------------ @@ -201,9 +180,9 @@ void O_::deepQuery(ConstControl& control, TEvent& event) const noexcept { - ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; + ScopedCRegion region{control, REGION_ID}; - SubStates::wideQuery(control, event); + QueryWrapper::execute(*this, control, event); } //------------------------------------------------------------------------------ diff --git a/development/hfsm2/detail/structure/orthogonal_sub_1.hpp b/development/hfsm2/detail/structure/orthogonal_sub_1.hpp index 94dd02b..d618b2a 100644 --- a/development/hfsm2/detail/structure/orthogonal_sub_1.hpp +++ b/development/hfsm2/detail/structure/orthogonal_sub_1.hpp @@ -67,6 +67,7 @@ struct HFSM2_EMPTY_BASES OS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using InitialInfo = WrapInfo; using InitialStates = typename InitialInfo::StateList; @@ -103,13 +104,13 @@ struct HFSM2_EMPTY_BASES OS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event ) const noexcept; diff --git a/development/hfsm2/detail/structure/orthogonal_sub_1.inl b/development/hfsm2/detail/structure/orthogonal_sub_1.inl index 53a3d16..b3725e1 100644 --- a/development/hfsm2/detail/structure/orthogonal_sub_1.inl +++ b/development/hfsm2/detail/structure/orthogonal_sub_1.inl @@ -118,7 +118,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePreReact(FullControl& control, +OS_::widePreReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; @@ -134,7 +134,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::wideReact(FullControl& control, +OS_::wideReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; @@ -150,7 +150,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePostReact(FullControl& control, +OS_::widePostReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; diff --git a/development/hfsm2/detail/structure/orthogonal_sub_2.hpp b/development/hfsm2/detail/structure/orthogonal_sub_2.hpp index 9232f5d..ded5073 100644 --- a/development/hfsm2/detail/structure/orthogonal_sub_2.hpp +++ b/development/hfsm2/detail/structure/orthogonal_sub_2.hpp @@ -48,6 +48,7 @@ struct HFSM2_EMPTY_BASES OS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Initial = InitialOS< TIndices, @@ -73,13 +74,13 @@ struct HFSM2_EMPTY_BASES OS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event ) const noexcept; diff --git a/development/hfsm2/detail/structure/orthogonal_sub_2.inl b/development/hfsm2/detail/structure/orthogonal_sub_2.inl index b948e13..7a13aca 100644 --- a/development/hfsm2/detail/structure/orthogonal_sub_2.inl +++ b/development/hfsm2/detail/structure/orthogonal_sub_2.inl @@ -93,7 +93,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePreReact(FullControl& control, +OS_::widePreReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepPreReact(control, event); @@ -105,7 +105,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::wideReact(FullControl& control, +OS_::wideReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepReact(control, event); @@ -117,7 +117,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePostReact(FullControl& control, +OS_::widePostReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepPostReact(control, event); diff --git a/development/hfsm2/detail/structure/reactions.inl b/development/hfsm2/detail/structure/reactions.inl new file mode 100644 index 0000000..544ecfb --- /dev/null +++ b/development/hfsm2/detail/structure/reactions.inl @@ -0,0 +1,527 @@ +namespace hfsm2 { +namespace detail { + +//////////////////////////////////////////////////////////////////////////////// + +template +struct PreReactWrapperT; + +//------------------------------------------------------------------------------ + +template +struct PreReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepPreReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.subStatus(control) |=) + subStates.widePreReact(control, event, active); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepPreReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.subStatus(control) |=) + subStates.widePreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//------------------------------------------------------------------------------ + +template +struct PreReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.widePreReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.widePreReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +struct ReactWrapperT; + +//------------------------------------------------------------------------------ + +template +struct ReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.wideReact(control, event, active); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.wideReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//------------------------------------------------------------------------------ + +template +struct ReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.wideReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.wideReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +struct PostReactWrapperT; + +//------------------------------------------------------------------------------ + +template +struct PostReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.widePostReact(control, event, active); + + if (control._consumed == false) { + const TaskStatus h = + headState.deepPostReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.widePostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + headState.deepPostReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//------------------------------------------------------------------------------ + +template +struct PostReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + subStates.widePostReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + subStates.widePostReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +struct QueryWrapperT; + +//------------------------------------------------------------------------------ + +template +struct QueryWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event, + const Prong active) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + headState.deepQuery(control, event); + + if (!control._consumed) + subStates.wideQuery(control, event, active); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + headState.deepQuery(control, event); + + if (!control._consumed) + subStates.wideQuery(control, event); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//------------------------------------------------------------------------------ + +template +struct QueryWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event, + const Prong active) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + subStates.wideQuery(control, event, active); + + if (!control._consumed) + headState.deepQuery(control, event); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + subStates.wideQuery(control, event); + + if (!control._consumed) + headState.deepQuery(control, event); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +}; + +//////////////////////////////////////////////////////////////////////////////// + +} +} diff --git a/development/hfsm2/detail/structure/state_1.hpp b/development/hfsm2/detail/structure/state_1.hpp index b942ab2..30634ff 100644 --- a/development/hfsm2/detail/structure/state_1.hpp +++ b/development/hfsm2/detail/structure/state_1.hpp @@ -38,6 +38,7 @@ struct HFSM2_EMPTY_BASES S_ using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Empty = EmptyT; using Head = THead; @@ -70,13 +71,13 @@ struct HFSM2_EMPTY_BASES S_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; diff --git a/development/hfsm2/detail/structure/state_1.inl b/development/hfsm2/detail/structure/state_1.inl index 581e99a..c048749 100644 --- a/development/hfsm2/detail/structure/state_1.inl +++ b/development/hfsm2/detail/structure/state_1.inl @@ -166,10 +166,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepPreReact(FullControl& control, +S_::deepPreReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::preReact); + auto method = static_cast(&Head::preReact); HFSM2_LOG_STATE_METHOD(method, Method::PRE_REACT); @@ -188,10 +188,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepReact(FullControl& control, +S_::deepReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::react); + auto method = static_cast(&Head::react); HFSM2_LOG_STATE_METHOD(method, Method::REACT); @@ -210,10 +210,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepPostReact(FullControl& control, +S_::deepPostReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::postReact); + auto method = static_cast(&Head::postReact); HFSM2_LOG_STATE_METHOD(method, Method::POST_REACT); diff --git a/development/hfsm2/detail/structure/state_2.hpp b/development/hfsm2/detail/structure/state_2.hpp index 1f2a3ea..84f136c 100644 --- a/development/hfsm2/detail/structure/state_2.hpp +++ b/development/hfsm2/detail/structure/state_2.hpp @@ -44,6 +44,7 @@ struct S_> using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Empty = EmptyT; using Head = Empty; @@ -76,13 +77,13 @@ struct S_> HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; diff --git a/development/hfsm2/detail/structure/state_2.inl b/development/hfsm2/detail/structure/state_2.inl index 4f3f688..24d2622 100644 --- a/development/hfsm2/detail/structure/state_2.inl +++ b/development/hfsm2/detail/structure/state_2.inl @@ -116,10 +116,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepPreReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepPreReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::preReact), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::preReact), Method::PRE_REACT); return TaskStatus{}; @@ -131,10 +131,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::react), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::react), Method::REACT); return TaskStatus{}; @@ -146,10 +146,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepPostReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepPostReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::postReact), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::postReact), Method::POST_REACT); return TaskStatus{}; diff --git a/development/hfsm2/machine_dev.hpp b/development/hfsm2/machine_dev.hpp index ec683e6..bc6797f 100644 --- a/development/hfsm2/machine_dev.hpp +++ b/development/hfsm2/machine_dev.hpp @@ -1,5 +1,5 @@ // HFSM2 (hierarchical state machine for games and interactive applications) -// 2.4.0 (2023-12-25) +// 2.5.0 (2024-01-01) // // Created by Andrew Gresyk // @@ -9,7 +9,7 @@ // // MIT License // -// Copyright (c) 2023 +// Copyright (c) 2024 // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -32,7 +32,7 @@ #pragma once #define HFSM2_VERSION_MAJOR 2 -#define HFSM2_VERSION_MINOR 4 +#define HFSM2_VERSION_MINOR 5 #define HFSM2_VERSION_PATCH 0 #define HFSM2_VERSION (10000 * HFSM2_VERSION_MAJOR + 100 * HFSM2_VERSION_MINOR + HFSM2_VERSION_PATCH) @@ -89,6 +89,7 @@ #include "detail/structure/state_1.hpp" #include "detail/structure/state_2.hpp" #include "detail/structure/forward.hpp" +#include "detail/structure/reactions.inl" #include "detail/structure/composite_sub_1.hpp" #include "detail/structure/composite_sub_2.hpp" #include "detail/structure/composite.hpp" diff --git a/examples/advanced_event_handling/main.cpp b/examples/advanced_event_handling/main.cpp index af07527..643b695 100644 --- a/examples/advanced_event_handling/main.cpp +++ b/examples/advanced_event_handling/main.cpp @@ -94,7 +94,7 @@ struct Reactive : FSM::State { // handle a single event type - TransitionEvent - void react(const TransitionEvent&, FullControl& control) { + void react(const TransitionEvent&, EventControl& control) { std::cout << " Reactive: reacting to TransitionEvent\n"; control.changeTo(); @@ -118,12 +118,12 @@ struct ConcreteHandler : FSM::State { // handle two event types - PrimaryEvent - void react(const PrimaryEvent&, FullControl&) { + void react(const PrimaryEvent&, EventControl&) { std::cout << " ConcreteHandler: reacting to PrimaryEvent\n"; } // and SecondaryEvent - void react(const SecondaryEvent&, FullControl&) { + void react(const SecondaryEvent&, EventControl&) { std::cout << " ConcreteHandler: reacting to SecondaryEvent\n"; } @@ -138,7 +138,7 @@ struct TemplateHandler { // handle all possible event types template - void react(const TEvent&, FullControl&) { + void react(const TEvent&, EventControl&) { std::cout << " TemplateHandler: reacting to TEvent\n"; } }; @@ -151,14 +151,14 @@ struct EnableIfHandler // use std::enable_if to build more complex conditional event handling template typename std::enable_if::value>::type - react(const TEvent&, FullControl&) { + react(const TEvent&, EventControl&) { std::cout << " EnableIfHandler: reacting to a \n"; } // but remember to cover all the remaining cases template typename std::enable_if::value>::type - react(const TEvent&, FullControl&) { + react(const TEvent&, EventControl&) { std::cout << " EnableIfHandler: reacting to a \n"; } }; diff --git a/examples/basic_audio_player/main.cpp b/examples/basic_audio_player/main.cpp index 05fae81..843d9f9 100644 --- a/examples/basic_audio_player/main.cpp +++ b/examples/basic_audio_player/main.cpp @@ -4,11 +4,11 @@ // An HFSM2 port of https://gist.github.com/martinmoene/797b1923f9c6c1ae355bb2d6870be25e // by Martin Moene (see https://twitter.com/MartinMoene/status/1118453128834232320) +#include + #include #include -#include - #define HFSM2_ENABLE_LOG_INTERFACE #define HFSM2_ENABLE_STRUCTURE_REPORT #include @@ -81,7 +81,7 @@ struct Logger void recordTransition(const Context& /*context*/, const StateID origin, const TransitionType /*transition*/, - const StateID target) override + const StateID target) override { std::cout << stateName(origin) << " -> " << stateName(target) << "\n"; } @@ -94,7 +94,7 @@ struct Base : FSM::State { template - void react(const Event&, FullControl&) { + void react(const Event&, EventControl&) { std::cout << "[unsupported transition]\n"; } }; @@ -105,7 +105,7 @@ struct Idle { using Base::react; - void react(const Play& event, FullControl& control) { + void react(const Play& event, EventControl& control) { control.context() = event.title; control.changeTo(); } @@ -116,11 +116,11 @@ struct Playing { using Base::react; - void react(const Pause&, FullControl& control) { + void react(const Pause&, EventControl& control) { control.changeTo(); } - void react(const Stop&, FullControl& control) { + void react(const Stop&, EventControl& control) { control.changeTo(); } }; @@ -130,11 +130,11 @@ struct Paused { using Base::react; - void react(const Resume&, FullControl& control) { + void react(const Resume&, EventControl& control) { control.changeTo(); } - void react(const Stop&, FullControl& control) { + void react(const Stop&, EventControl& control) { control.changeTo(); } }; @@ -156,7 +156,7 @@ int main() { machine.react(Stop{}); // Paused -> Idle machine.react(Play{"variant"}); // Idle -> Playing - machine.react(Pause{}); //-V760 // Playing -> Paused + machine.react(Pause{}); // Playing -> Paused machine.react(Resume{}); // Paused -> Playing machine.react(Stop{}); // Playing -> Idle diff --git a/examples/calculator/main.cpp b/examples/calculator/main.cpp index 2835b4c..48116f6 100644 --- a/examples/calculator/main.cpp +++ b/examples/calculator/main.cpp @@ -198,7 +198,7 @@ struct Off : FSM::State { using FSM::State::react; - void react(const TurnOn&, FullControl& control) + void react(const TurnOn&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -224,13 +224,13 @@ struct On : FSM::State control.context().reset(); } - void react(const Clear&, FullControl& control) + void react(const Clear&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const TurnOff&, FullControl& control) + void react(const TurnOff&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -244,7 +244,7 @@ struct Ready : FSM::State { using FSM::State::react; - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().clearOperand1(); @@ -252,7 +252,7 @@ struct Ready : FSM::State control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().clearOperand1(); @@ -260,14 +260,14 @@ struct Ready : FSM::State control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.context().clearOperand1(); control.changeTo(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; // This is where bottom-op invocation order is needed @@ -314,7 +314,7 @@ struct Result : FSM::State control.context().display(); } - void react(const Equals&, FullControl& control) + void react(const Equals&, EventControl& control) { PRINTCALL; control.context().performOp(); @@ -343,32 +343,32 @@ struct Negated1 : FSM::State control.context().display(); } - void react(const ClearEntry&, FullControl& control) + void react(const ClearEntry&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand1(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; if (op.mathOperator == MathOperator::MINUS) @@ -383,14 +383,14 @@ struct Operand1 : FSM::State { using FSM::State::react; - void react(const ClearEntry&, FullControl& control) + void react(const ClearEntry&, EventControl& control) { PRINTCALL; control.context().clearOperand1(); control.changeTo(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; control.context().mathOperator = op.mathOperator; @@ -419,20 +419,20 @@ struct Zero1 : FSM::State control.context().display(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand1(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -458,21 +458,21 @@ struct Int1 : FSM::State control.context().display(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().insertInOperand1(0); control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand1(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -504,14 +504,14 @@ struct Frac1 : FSM::State control.context().endFraction(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().insertInOperand1(0); control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand1(digit.digit); @@ -558,27 +558,27 @@ struct opEntered : FSM::State control.context().display(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().insertInOperand2(0); control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand2(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; if (op.mathOperator==MathOperator::MINUS) @@ -612,32 +612,32 @@ struct Negated2 : FSM::State control.context().display(); } - void react(const ClearEntry&, FullControl& control) + void react(const ClearEntry&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand2(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; if (op.mathOperator == MathOperator::MINUS) @@ -664,7 +664,7 @@ struct Operand2 : FSM::State control.context().display(); } - void react(const Operator& op, FullControl& control) + void react(const Operator& op, EventControl& control) { PRINTCALL; if (control.context().performOp()) @@ -676,7 +676,7 @@ struct Operand2 : FSM::State control.changeTo(); } - void react(const Equals&, FullControl& control) + void react(const Equals&, EventControl& control) { PRINTCALL; if (control.context().performOp()) @@ -685,7 +685,7 @@ struct Operand2 : FSM::State control.changeTo(); } - void react(const ClearEntry&, FullControl& control) + void react(const ClearEntry&, EventControl& control) { PRINTCALL; control.context().clearOperand2(); @@ -714,20 +714,20 @@ struct Zero2 : FSM::State control.context().display(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand2(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -753,21 +753,21 @@ struct Int2 : FSM::State control.context().display(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().insertInOperand2(0); control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand2(digit.digit); control.changeTo(); } - void react(const Point&, FullControl& control) + void react(const Point&, EventControl& control) { PRINTCALL; control.changeTo(); @@ -800,14 +800,14 @@ struct Frac2 : FSM::State control.context().endFraction(); } - void react(const Digit_0&, FullControl& control) + void react(const Digit_0&, EventControl& control) { PRINTCALL; control.context().insertInOperand2(0); control.changeTo(); } - void react(const Digit_1_9& digit, FullControl& control) + void react(const Digit_1_9& digit, EventControl& control) { PRINTCALL; control.context().insertInOperand2(digit.digit); diff --git a/examples/debug_logger_interface/main.cpp b/examples/debug_logger_interface/main.cpp index 01f6692..a728530 100644 --- a/examples/debug_logger_interface/main.cpp +++ b/examples/debug_logger_interface/main.cpp @@ -90,7 +90,7 @@ struct Logger { void recordMethod(const Context& /*context*/, const hfsm2::StateID /*origin*/, - const Method method) override + const Method method) override { std::cout //<< hfsm2::stateName(origin) << "::" << hfsm2::methodName(method) << "()\n"; @@ -99,7 +99,7 @@ struct Logger void recordTransition(const Context& /*context*/, const hfsm2::StateID /*origin*/, const TransitionType transitionType, - const hfsm2::StateID /*target*/) override + const hfsm2::StateID /*target*/) override { std::cout //<< hfsm2::stateName(origin) << ": " << hfsm2::transitionName(transitionType) << "<" @@ -115,12 +115,12 @@ struct Top : FSM::State // necessary boilerplate! { // all state methods: - void entryGuard(GuardControl&) {} // not going to be called in this example - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) {} // not going to be called in this example + void enter(Control&) {} + void update(FullControl&) {} template - void react(const TEvent&, FullControl&) {} - void exit(Control&) {} + void react(const TEvent&, EventControl&) {} + void exit(Control&) {} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -130,12 +130,12 @@ struct From : FSM::State { // all state methods: - void entryGuard(GuardControl&) {} // not going to be called in this example - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) {} // not going to be called in this example + void enter(Control&) {} + void update(FullControl&) {} template - void react(const TEvent&, FullControl& control) { control.changeTo(); } - void exit(Control&) {} + void react(const TEvent&, EventControl& control) { control.changeTo(); } + void exit(Control&) {} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -145,12 +145,12 @@ struct To : FSM::State { // all state methods: - void entryGuard(GuardControl&) {} - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) {} + void enter(Control&) {} + void update(FullControl&) {} template - void react(const TEvent&, FullControl&) {} // not going to be called in this example - void exit(Control&) {} + void react(const TEvent&, EventControl&) {} // not going to be called in this example + void exit(Control&) {} }; //////////////////////////////////////////////////////////////////////////////// diff --git a/examples/snippets/wiki_utility-theory.cpp b/examples/snippets/wiki_utility-theory.cpp index d5a19ae..acb79d2 100644 --- a/examples/snippets/wiki_utility-theory.cpp +++ b/examples/snippets/wiki_utility-theory.cpp @@ -25,7 +25,7 @@ struct Event { Event(const hfsm2::StateID state_, const Enum type_, - const hfsm2::StateID prong_ = hfsm2::INVALID_STATE_ID) noexcept + const hfsm2::StateID prong_ = hfsm2::INVALID_STATE_ID) : state{state_} , type{type_} , prong{prong_} @@ -42,9 +42,9 @@ using Events = std::vector; struct Logger : hfsm2::LoggerInterface // requires HFSM2_ENABLE_LOG_INTERFACE defined { - void recordMethod(Context& /*context*/, + void recordMethod(const Context& /*context*/, const StateID state, - const Method method) noexcept override + const Method method) override { if (method == Method::RANK) history.emplace_back(state, Event::RANK); @@ -52,23 +52,23 @@ struct Logger history.emplace_back(state, Event::UTILITY); } - void recordUtilityResolution(Context& /*context*/, + void recordUtilityResolution(const Context& /*context*/, const StateID head, - const StateID prong, - const Utilty /*utilty*/) noexcept override + const Prong prong, + const Utilty /*utilty*/) override { history.emplace_back(head, Event::UTILITY_RESOLUTION, prong); } - void recordRandomResolution(Context& /*context*/, + void recordRandomResolution(const Context& /*context*/, const StateID head, - const StateID prong, - const Utilty /*utilty*/) noexcept override + const Prong prong, + const Utilty /*utilty*/) override { history.emplace_back(head, Event::RANDOM_RESOLUTION, prong); } - void assertSequence(const Events& reference) noexcept { + void assertSequence(const Events& reference) { const auto count = std::max(history.size(), reference.size()); for (unsigned i = 0; i < count; ++i) { @@ -141,11 +141,11 @@ struct R_Activated : FSM::State {}; // only consider previously activated sub- struct U : FSM::State {}; // for 'Utilitarian' region, // find the highest-scoring sub-state struct U_033 : FSM::State { - Utility utility(const Control&) noexcept { return 0.33f; } + Utility utility(const Control&) { return 0.33f; } }; struct U_067 : FSM::State { - Utility utility(const Control&) noexcept { return 0.67f; } + Utility utility(const Control&) { return 0.67f; } }; struct D : FSM::State {}; // for 'Random' region, @@ -153,17 +153,17 @@ struct D : FSM::State {}; // for 'Random' region, // 2. from the remaining sub-states, // randomly select one based on their score struct D_Filtered : FSM::State { - Rank rank(const Control&) noexcept {return -1; } + Rank rank(const Control&) {return -1; } }; struct D_010 : FSM::State { - Rank rank(const Control&) noexcept {return 0; } - Utility utility(const Control&) noexcept { return 0.10f; } + Rank rank(const Control&) {return 0; } + Utility utility(const Control&) { return 0.10f; } }; struct D_090 : FSM::State { // inherit FSM::State::rank(), which returns '0' - Utility utility(const Control&) noexcept { return 0.90f; } + Utility utility(const Control&) { return 0.90f; } }; struct O : FSM::State {}; diff --git a/include/hfsm2/machine.hpp b/include/hfsm2/machine.hpp index 2a73622..c2cc508 100644 --- a/include/hfsm2/machine.hpp +++ b/include/hfsm2/machine.hpp @@ -1,5 +1,5 @@ // HFSM2 (hierarchical state machine for games and interactive applications) -// 2.4.0 (2023-12-25) +// 2.5.0 (2024-01-01) // // Created by Andrew Gresyk // @@ -9,7 +9,7 @@ // // MIT License // -// Copyright (c) 2023 +// Copyright (c) 2024 // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -32,7 +32,7 @@ #pragma once #define HFSM2_VERSION_MAJOR 2 -#define HFSM2_VERSION_MINOR 4 +#define HFSM2_VERSION_MINOR 5 #define HFSM2_VERSION_PATCH 0 #define HFSM2_VERSION (10000 * HFSM2_VERSION_MAJOR + 100 * HFSM2_VERSION_MINOR + HFSM2_VERSION_PATCH) @@ -3159,6 +3159,7 @@ template < , Long , Long , Long + , typename HFSM2_IF_SERIALIZATION(, Long) HFSM2_IF_PLANS(, Long) , typename @@ -3175,6 +3176,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -3187,6 +3189,7 @@ struct RegistryT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -3268,6 +3271,7 @@ template < , typename TStateList , typename TRegionList , Long NCompoCount + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -3280,6 +3284,7 @@ struct RegistryT< , NCompoCount , 0 , 0 + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -3374,10 +3379,10 @@ restore(TRegistry& registry, namespace hfsm2 { namespace detail { -template +template HFSM2_CONSTEXPR(14) Prong -RegistryT>::activeSubState(const StateID stateId) const noexcept { +RegistryT>::activeSubState(const StateID stateId) const noexcept { const StateID subStateId = stateId + 1; if (HFSM2_CHECKED( stateId < STATE_COUNT) && @@ -3394,17 +3399,17 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::isActive() const noexcept { +RegistryT>::isActive() const noexcept { return compoActive[0] != INVALID_PRONG; } -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isActive(const StateID stateId) const noexcept { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { for (Parent parent = stateParents[stateId]; parent; @@ -3422,10 +3427,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isResumable(const StateID stateId) const noexcept { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -3440,10 +3445,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingChange(const StateID stateId) const noexcept { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -3459,10 +3464,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingEnter(const StateID stateId) const noexcept { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -3478,10 +3483,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingExit(const StateID stateId) const noexcept { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -3497,10 +3502,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) const Parent& -RegistryT>::forkParent(const ForkID forkId) const noexcept { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId != 0); return forkId > 0 ? @@ -3508,20 +3513,20 @@ RegistryT +template HFSM2_CONSTEXPR(14) -typename RegistryT>::OrthoBits -RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { +typename RegistryT>::OrthoBits +RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { HFSM2_ASSERT(forkId < 0); const Units& units = orthoUnits[-forkId - 1]; return orthoRequested.bits(units); } -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::requestImmediate(const Transition& request) noexcept { +RegistryT>::requestImmediate(const Transition& request) noexcept { if (request.destination == 0) return false; else if (HFSM2_CHECKED(request.destination < STATE_COUNT)) { @@ -3571,10 +3576,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::requestScheduled(const StateID stateId) noexcept { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -3584,29 +3589,29 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clearRequests() noexcept { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); } -template +template HFSM2_CONSTEXPR(14) void -RegistryT>::clear() noexcept { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); compoResumable.clear(); } -template +template HFSM2_CONSTEXPR(11) bool -RegistryT>::empty() const noexcept { +RegistryT>::empty() const noexcept { return compoRequested.empty() && orthoRequested.empty() && compoRemains .empty() @@ -3620,10 +3625,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) Prong -RegistryT>::activeSubState(const StateID stateId) const noexcept { +RegistryT>::activeSubState(const StateID stateId) const noexcept { const StateID subStateId = stateId + 1; if (HFSM2_CHECKED( stateId < STATE_COUNT) && @@ -3640,17 +3645,17 @@ RegistryT +template HFSM2_CONSTEXPR(11) bool -RegistryT>::isActive() const noexcept { +RegistryT>::isActive() const noexcept { return compoActive[0] != INVALID_PRONG; } -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isActive(const StateID stateId) const noexcept { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -3663,10 +3668,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isResumable(const StateID stateId) const noexcept { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -3677,10 +3682,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingChange(const StateID stateId) const noexcept { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -3692,10 +3697,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingEnter(const StateID stateId) const noexcept { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -3707,10 +3712,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) bool -RegistryT>::isPendingExit(const StateID stateId) const noexcept { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -3722,19 +3727,19 @@ RegistryT +template HFSM2_CONSTEXPR(14) const Parent& -RegistryT>::forkParent(const ForkID forkId) const noexcept { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId > 0); return compoParents[forkId - 1]; } -template +template HFSM2_CONSTEXPR(14) bool -RegistryT>::requestImmediate(const Transition& request) noexcept { +RegistryT>::requestImmediate(const Transition& request) noexcept { // record request // promote it to all children @@ -3773,10 +3778,10 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::requestScheduled(const StateID stateId) noexcept { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -3785,29 +3790,29 @@ RegistryT +template HFSM2_CONSTEXPR(14) void -RegistryT>::clearRequests() noexcept { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); } -template +template HFSM2_CONSTEXPR(14) void -RegistryT>::clear() noexcept { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); compoResumable.clear(); } -template +template HFSM2_CONSTEXPR(11) bool -RegistryT>::empty() const noexcept { +RegistryT>::empty() const noexcept { return compoRequested.empty() && orthoRequested.empty() && compoRemains .empty() @@ -3865,6 +3870,7 @@ template < , Long , Long , Long + , typename HFSM2_IF_SERIALIZATION(, Long) , Long , typename @@ -3881,6 +3887,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity , typename TPayload @@ -3893,6 +3900,7 @@ struct PlanDataT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -3948,6 +3956,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity > @@ -3959,6 +3968,7 @@ struct PlanDataT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -4009,6 +4019,7 @@ template < , typename TRegionList , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder , Long NTaskCapacity , typename TPayload > @@ -4020,6 +4031,7 @@ struct PlanDataT< , 0 , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, 0) , NTaskCapacity , TPayload @@ -4043,6 +4055,7 @@ template < , typename TRegionList , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder , Long NTaskCapacity > struct PlanDataT< @@ -4053,6 +4066,7 @@ struct PlanDataT< , 0 , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, 0) , NTaskCapacity , void @@ -4123,20 +4137,20 @@ operator |= (TaskStatus& lhs, #if HFSM2_PLANS_AVAILABLE() -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { if (stateId != INVALID_STATE_ID) { tasksSuccesses.clear(stateId); tasksFailures .clear(stateId); } } -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { #if HFSM2_ASSERT_AVAILABLE() if (stateId != INVALID_STATE_ID) { @@ -4147,18 +4161,18 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearRegionStatuses() noexcept { +PlanDataT>::clearRegionStatuses() noexcept { headStatuses.clear(); subStatuses .clear(); } -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clear() noexcept { +PlanDataT>::clear() noexcept { tasks .clear(); taskLinks .clear(); taskPayloads .clear(); @@ -4174,10 +4188,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyPlans() const noexcept { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) @@ -4186,10 +4200,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) Long -PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -4227,20 +4241,20 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { if (stateId != INVALID_STATE_ID) { tasksSuccesses.clear(stateId); tasksFailures .clear(stateId); } } -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { #if HFSM2_ASSERT_AVAILABLE() if (stateId != INVALID_STATE_ID) { @@ -4251,18 +4265,18 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clearRegionStatuses() noexcept { +PlanDataT>::clearRegionStatuses() noexcept { headStatuses.clear(); subStatuses .clear(); } -template +template HFSM2_CONSTEXPR(14) void -PlanDataT>::clear() noexcept { +PlanDataT>::clear() noexcept { tasks .clear(); taskLinks .clear(); @@ -4276,10 +4290,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) void -PlanDataT>::verifyPlans() const noexcept { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) @@ -4288,10 +4302,10 @@ PlanDataT +template HFSM2_CONSTEXPR(14) Long -PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -5081,6 +5095,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity , typename TPayload @@ -5093,6 +5108,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -5106,6 +5122,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -5131,6 +5148,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , TPayload @@ -5402,6 +5420,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) , Long NTaskCapacity > @@ -5413,6 +5432,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -5426,6 +5446,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -5451,6 +5472,7 @@ class PayloadPlanT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) , NTaskCapacity , void @@ -5471,13 +5493,13 @@ class PayloadPlanT< namespace hfsm2 { namespace detail { -template +template HFSM2_CONSTEXPR(14) bool -PayloadPlanT>::append(const StateID origin, - const StateID destination, - const TransitionType transitionType, - const Payload& payload) noexcept +PayloadPlanT>:: append(const StateID origin, + const StateID destination, + const TransitionType transitionType, + const Payload& payload) noexcept { if (_planData.tasks.count() < TASK_CAPACITY) { _planData.planExists.set(_regionId); @@ -5616,6 +5638,9 @@ class ConstControlT { template friend class R_; + template + friend struct QueryWrapperT; + protected: using Context = typename TArgs::Context; @@ -5712,6 +5737,10 @@ class ConstControlT { /// @see Control::_() HFSM2_CONSTEXPR(11) const Context& context() const noexcept { return _core.context; } + /// @brief Stops processing of the current query down the hierarchy + /// @see Config::BottomUpReactions + HFSM2_CONSTEXPR(14) void consumeQuery() noexcept { _consumed = true; } + /// @brief Inspect current transition requests /// @return Array of transition requests HFSM2_CONSTEXPR(11) const TransitionSet& requests() const noexcept { return _core.requests; } @@ -5817,6 +5846,7 @@ class ConstControlT { const Core& _core; StateID _originId = INVALID_STATE_ID; RegionID _regionId = 0; + bool _consumed = false; }; } @@ -5858,6 +5888,24 @@ ConstControlT::Region::~Region() noexcept { control.resetRegion(prevId); } +template +HFSM2_CONSTEXPR(14) +void +ConstControlT::setRegion(const RegionID regionId_) noexcept { + HFSM2_ASSERT(_regionId <= regionId_ && regionId_ < RegionList::SIZE); + + _regionId = regionId_; +} + +template +HFSM2_CONSTEXPR(14) +void +ConstControlT::resetRegion(const RegionID regionId_) noexcept { + HFSM2_ASSERT(regionId_ <= _regionId && _regionId < RegionList::SIZE); + + _regionId = regionId_; +} + } } @@ -6577,6 +6625,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -6589,6 +6638,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -6602,6 +6652,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -6627,6 +6678,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , TPayload @@ -6788,6 +6840,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) > @@ -6799,6 +6852,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void @@ -6812,6 +6866,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void @@ -6837,6 +6892,7 @@ class FullControlT< , NCompoCount , NOrthoCount , NOrthoUnits + , TReactOrder HFSM2_IF_SERIALIZATION(, NSerialBits) HFSM2_IF_PLANS(, NTaskCapacity) , void @@ -7071,12 +7127,12 @@ FullControlBaseT::fail(const StateID stateId_) noexcept { #if HFSM2_PLANS_AVAILABLE() -template +template template HFSM2_CONSTEXPR(14) TaskStatus -FullControlT>::updatePlan(TState& headState, - const TaskStatus subStatus) noexcept +FullControlT>::updatePlan(TState& headState, + const TaskStatus subStatus) noexcept { constexpr StateID STATE_ID = TState::STATE_ID; // SPECIFIC @@ -7132,11 +7188,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::changeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::changeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::CHANGE, payload}); @@ -7148,11 +7204,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::restartWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::restartWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RESTART, payload}); @@ -7164,11 +7220,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::resumeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::resumeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RESUME, payload}); @@ -7180,11 +7236,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::selectWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::selectWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::SELECT, payload}); @@ -7198,11 +7254,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::utilizeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::utilizeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::UTILIZE, payload}); @@ -7214,11 +7270,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::randomizeWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::randomizeWith(const StateID stateId_, + const Payload& payload) noexcept { if (!_locked) { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::RANDOMIZE, payload}); @@ -7232,11 +7288,11 @@ FullControlT +template HFSM2_CONSTEXPR(14) void -FullControlT>::scheduleWith(const StateID stateId_, - const Payload& payload) noexcept +FullControlT>::scheduleWith(const StateID stateId_, + const Payload& payload) noexcept { _core.requests.emplace(Transition{_originId, stateId_, TransitionType::SCHEDULE, payload}); @@ -7245,12 +7301,12 @@ FullControlT +template template HFSM2_CONSTEXPR(14) TaskStatus -FullControlT>::updatePlan(TState& headState, - const TaskStatus subStatus) noexcept +FullControlT>::updatePlan(TState& headState, + const TaskStatus subStatus) noexcept { constexpr StateID STATE_ID = TState::STATE_ID; // SPECIFIC @@ -7425,6 +7481,37 @@ GuardControlT::cancelPendingTransitions() noexcept { namespace hfsm2 { namespace detail { +template +class EventControlT final + : public FullControlT +{ + template + friend class R_; + + template + friend struct PreReactWrapperT; + + template + friend struct ReactWrapperT; + + template + friend struct PostReactWrapperT; + + using FullControl = FullControlT; + + using FullControl::FullControl; + +public: + using FullControl::context; + + /// @brief Stops processing of the current event down the hierarchy + /// @see `Config::BottomUpReactions` + HFSM2_CONSTEXPR(14) void consumeEvent() noexcept { _consumed = true; } + +private: + bool _consumed = false; +}; + } } @@ -7458,6 +7545,7 @@ class B_ { using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; #if HFSM2_PLANS_AVAILABLE() using Plan = PayloadPlanT ; @@ -7476,15 +7564,15 @@ class B_ { template HFSM2_CONSTEXPR(14) void preReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void react (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void postReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void query ( TEvent& , @@ -7541,6 +7629,7 @@ struct HFSM2_EMPTY_BASES A_ using typename First::FullControl; using typename First::GuardControl; + using typename First::EventControl; using First::stateId; using First::regionId; @@ -7558,15 +7647,15 @@ struct HFSM2_EMPTY_BASES A_ template HFSM2_CONSTEXPR(14) void widePreReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void widePostReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery ( TEvent& event , @@ -7637,7 +7726,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePreReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: preReact(event, control); Rest ::widePreReact(event, control); @@ -7648,7 +7737,7 @@ template HFSM2_CONSTEXPR(14) void A_::wideReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: react(event, control); Rest ::wideReact(event, control); @@ -7659,7 +7748,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePostReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { Rest ::widePostReact(event, control); First:: postReact(event, control); @@ -7699,7 +7788,7 @@ namespace hfsm2 { namespace detail { template -struct A_ +struct HFSM2_EMPTY_BASES A_ : TFirst { using First = TFirst; @@ -7726,6 +7815,7 @@ struct A_ using typename First::FullControl; using typename First::GuardControl; + using typename First::EventControl; using First::stateId; using First::regionId; @@ -7748,15 +7838,15 @@ struct A_ template HFSM2_CONSTEXPR(14) void preReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void react (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void postReact (const TEvent& , - FullControl& ) noexcept {} + EventControl& ) noexcept {} template HFSM2_CONSTEXPR(14) void query ( TEvent& , @@ -7782,15 +7872,15 @@ struct A_ template HFSM2_CONSTEXPR(14) void widePreReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void widePostReact (const TEvent& event , - FullControl& control) noexcept; + EventControl& control) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery ( TEvent& event , @@ -7855,7 +7945,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePreReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: preReact(event, control); } @@ -7865,7 +7955,7 @@ template HFSM2_CONSTEXPR(14) void A_::wideReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: react(event, control); } @@ -7875,7 +7965,7 @@ template HFSM2_CONSTEXPR(14) void A_::widePostReact(const TEvent& event, - FullControl& control) noexcept + EventControl& control) noexcept { First:: postReact(event, control); } @@ -7945,6 +8035,7 @@ struct HFSM2_EMPTY_BASES S_ using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Empty = EmptyT; using Head = THead; @@ -7971,13 +8062,13 @@ struct HFSM2_EMPTY_BASES S_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; @@ -8236,10 +8327,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepPreReact(FullControl& control, +S_::deepPreReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::preReact); + auto method = static_cast(&Head::preReact); HFSM2_LOG_STATE_METHOD(method, Method::PRE_REACT); @@ -8256,10 +8347,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepReact(FullControl& control, +S_::deepReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::react); + auto method = static_cast(&Head::react); HFSM2_LOG_STATE_METHOD(method, Method::REACT); @@ -8276,10 +8367,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_::deepPostReact(FullControl& control, +S_::deepPostReact(EventControl& control, const TEvent& event) noexcept { - auto method = static_cast(&Head::postReact); + auto method = static_cast(&Head::postReact); HFSM2_LOG_STATE_METHOD(method, Method::POST_REACT); @@ -8585,6 +8676,7 @@ struct S_> using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Empty = EmptyT; using Head = Empty; @@ -8611,13 +8703,13 @@ struct S_> HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; @@ -8808,10 +8900,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepPreReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepPreReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::preReact), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::preReact), Method::PRE_REACT); return TaskStatus{}; @@ -8821,10 +8913,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::react), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::react), Method::REACT); return TaskStatus{}; @@ -8834,10 +8926,10 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -S_>::deepPostReact(FullControl& HFSM2_IF_LOG_STATE_METHOD(control), +S_>::deepPostReact(EventControl& HFSM2_IF_LOG_STATE_METHOD(control), const TEvent& HFSM2_UNUSED(event)) noexcept { - HFSM2_LOG_STATE_METHOD(static_cast(&Empty::postReact), + HFSM2_LOG_STATE_METHOD(static_cast(&Empty::postReact), Method::POST_REACT); return TaskStatus{}; @@ -9238,6 +9330,7 @@ template < , Long NCompoCount , Long NOrthoCount , Long NOrthoUnits + , typename TReactOrder HFSM2_IF_SERIALIZATION(, Long NSerialBits) HFSM2_IF_PLANS(, Long NTaskCapacity) , typename TPayload @@ -9268,6 +9361,8 @@ struct ArgsT final { static constexpr Short ORTHO_COUNT = NOrthoCount; static constexpr Short ORTHO_UNITS = NOrthoUnits; + using ReactOrder = TReactOrder; + #if HFSM2_SERIALIZATION_AVAILABLE() static constexpr Short SERIAL_BITS = NSerialBits; #endif @@ -9358,6 +9453,8 @@ struct RF_ final { using Context = typename Config::Context; using Apex = TApex; + using ReactOrder = typename Config::ReactOrder; + using StateList = typename Apex::StateList; using RegionList = typename Apex::RegionList; @@ -9390,6 +9487,7 @@ struct RF_ final { , COMPO_COUNT , ORTHO_COUNT , ORTHO_UNITS + , ReactOrder HFSM2_IF_SERIALIZATION(, SERIAL_BITS) HFSM2_IF_PLANS(, TASK_CAPACITY) , Payload @@ -9401,6 +9499,7 @@ struct RF_ final { using Control = ControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using State = EmptyT ; @@ -9532,6 +9631,468 @@ using RemainingOS = typename RemainingOST::Type; namespace hfsm2 { namespace detail { +template +struct PreReactWrapperT; + +template +struct PreReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepPreReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.subStatus(control) |=) + subStates.widePreReact(control, event, active); + + return h; + } else + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepPreReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.subStatus(control) |=) + subStates.widePreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + +}; + +template +struct PreReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.widePreReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.widePreReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPreReact(control, event); + + return h; + } else + return TaskStatus{}; + } + +}; + +template +struct ReactWrapperT; + +template +struct ReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.wideReact(control, event, active); + + return h; + } else + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + headState.deepReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.wideReact(control, event); + + return h; + } else + return TaskStatus{}; + } + +}; + +template +struct ReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.wideReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepReact(control, event); + + return h; + } else + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + const TaskStatus h = + subStates.wideReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + if (!control._consumed) + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepReact(control, event); + + return h; + } else + return TaskStatus{}; + } + +}; + +template +struct PostReactWrapperT; + +template +struct PostReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.widePostReact(control, event, active); + + if (control._consumed == false) { + const TaskStatus h = + headState.deepPostReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region. subStatus(control) |=) + subStates.widePostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + headState.deepPostReact(control, event); + HFSM2_IF_PLANS(region.headStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + +}; + +template +struct PostReactWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event, + const Prong active) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + subStates.widePostReact(control, event, active); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + + template + static + HFSM2_CONSTEXPR(14) + TaskStatus + execute(TRegion& region, + typename TRegion::EventControl& control, + const TEvent& event) noexcept + { + if (!control._consumed) { + HeadState& headState = static_cast(region); + SubStates& subStates = static_cast(region); + + HFSM2_IF_PLANS(region.headStatus(control) |=) + headState.deepPostReact(control, event); + + if (control._consumed == false) { + const TaskStatus h = + subStates.widePostReact(control, event); + HFSM2_IF_PLANS(region. subStatus(control) |= h); + + return h; + } + } + + return TaskStatus{}; + } + +}; + +template +struct QueryWrapperT; + +template +struct QueryWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event, + const Prong active) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + headState.deepQuery(control, event); + + if (!control._consumed) + subStates.wideQuery(control, event, active); + } + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + headState.deepQuery(control, event); + + if (!control._consumed) + subStates.wideQuery(control, event); + } + +}; + +template +struct QueryWrapperT { + using HeadState = THeadState; + using SubStates = TSubStates; + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event, + const Prong active) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + subStates.wideQuery(control, event, active); + + if (!control._consumed) + headState.deepQuery(control, event); + } + + template + static + HFSM2_CONSTEXPR(14) + void + execute(const TRegion& region, + typename TRegion::ConstControl& control, + TEvent& event) noexcept + { + const HeadState& headState = static_cast(region); + const SubStates& subStates = static_cast(region); + + if (!control._consumed) + subStates.wideQuery(control, event); + + if (!control._consumed) + headState.deepQuery(control, event); + } + +}; + +} +} + +namespace hfsm2 { +namespace detail { + template < typename TIndices , typename TArgs @@ -9594,6 +10155,7 @@ struct HFSM2_EMPTY_BASES CS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using LStateList = LHalfTypes; using LHalfInfo = CSI_; @@ -9630,13 +10192,13 @@ struct HFSM2_EMPTY_BASES CS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event, const Prong prong) const noexcept; @@ -9814,7 +10376,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePreReact(FullControl& control, +CS_>::widePreReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { @@ -9829,7 +10391,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::wideReact(FullControl& control, +CS_>::wideReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { @@ -9844,7 +10406,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePostReact(FullControl& control, +CS_>::widePostReact(EventControl& control, const TEvent& event, const Prong prong) noexcept { @@ -10291,6 +10853,7 @@ struct HFSM2_EMPTY_BASES CS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Single = MaterialT< Indices @@ -10311,13 +10874,13 @@ struct HFSM2_EMPTY_BASES CS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event, const Prong prong) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event, const Prong prong) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event, const Prong prong) const noexcept; @@ -10476,7 +11039,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePreReact(FullControl& control, +CS_>::widePreReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { @@ -10489,7 +11052,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::wideReact(FullControl& control, +CS_>::wideReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { @@ -10502,7 +11065,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -CS_>::widePostReact(FullControl& control, +CS_>::widePostReact(EventControl& control, const TEvent& event, const Prong HFSM2_IF_ASSERT(prong)) noexcept { @@ -10854,7 +11417,7 @@ struct HFSM2_EMPTY_BASES C_ , TL_ > { - using Indices = TIndices; + using Indices = TIndices; static constexpr StateID HEAD_ID = Indices::STATE_ID; static constexpr Short COMPO_INDEX = Indices::COMPO_INDEX; static constexpr Short ORTHO_INDEX = Indices::ORTHO_INDEX; @@ -10865,59 +11428,67 @@ struct HFSM2_EMPTY_BASES C_ static constexpr RegionID REGION_ID = COMPO_INDEX + ORTHO_INDEX; static constexpr ForkID COMPO_ID = COMPO_INDEX + 1; - using Args = TArgs; + using Args = TArgs; #if HFSM2_UTILITY_THEORY_AVAILABLE() - using Rank = typename Args::Rank; - using Utility = typename Args::Utility; - using UP = typename Args::UP; + using Rank = typename Args::Rank; + using Utility = typename Args::Utility; + using UP = typename Args::UP; #endif - using StateList = typename Args::StateList; - using RegionList = typename Args::RegionList; + using StateList = typename Args::StateList; + using RegionList = typename Args::RegionList; - using Registry = RegistryT; - using StateParents = typename Registry::StateParents; + using ReactOrder = typename Args::ReactOrder; - using ConstControl = ConstControlT; - using Control = ControlT ; - using ScopedOrigin = typename Control::Origin; + using Registry = RegistryT; + using StateParents = typename Registry::StateParents; - using PlanControl = PlanControlT ; - using ScopedRegion = typename PlanControl::Region; + using ConstControl = ConstControlT; + using ScopedCRegion = typename ConstControl::Region; -#if HFSM2_PLANS_AVAILABLE() - using Plan = typename PlanControl::Plan; -#endif + using Control = ControlT ; + using ScopedOrigin = typename Control::Origin; - using FullControl = FullControlT ; - using ControlLock = typename FullControl::Lock; + using FullControl = FullControlT ; + using PlanControl = PlanControlT ; + using ControlLock = typename FullControl::Lock; + using ScopedRegion = typename PlanControl::Region; - using GuardControl = GuardControlT; + using GuardControl = GuardControlT; + using EventControl = EventControlT; - using Head = THead; - using HeadState = S_; +#if HFSM2_PLANS_AVAILABLE() + using Plan = typename PlanControl::Plan; +#endif - using SubStates = CS_< - I_< - HEAD_ID + 1, - COMPO_INDEX + 1, - ORTHO_INDEX, - ORTHO_UNIT - >, - Args, - STRATEGY, - 0, - TL_ - >; + using Head = THead; + using HeadState = S_; + + using SubStates = CS_< + I_< + HEAD_ID + 1, + COMPO_INDEX + 1, + ORTHO_INDEX, + ORTHO_UNIT + >, + Args, + STRATEGY, + 0, + TL_ + >; - using Info = CI_; + using PreReactWrapper = PreReactWrapperT ; + using ReactWrapper = ReactWrapperT ; + using PostReactWrapper = PostReactWrapperT; + using QueryWrapper = QueryWrapperT ; + using Info = CI_; static constexpr Short WIDTH = Info::WIDTH; #if HFSM2_UTILITY_THEORY_AVAILABLE() - using Ranks = Rank[WIDTH]; - using Utilities = Utility[WIDTH]; + using Ranks = Rank[WIDTH]; + using Utilities = Utility[WIDTH]; #endif #if HFSM2_SERIALIZATION_AVAILABLE() @@ -10962,13 +11533,13 @@ struct HFSM2_EMPTY_BASES C_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event) const noexcept; @@ -11196,8 +11767,9 @@ C_::deepReenter(PlanControl& control) noexcept { active = requested; - if (requested == resumable) + if (requested == resumable) { resumable = INVALID_PRONG; + } SubStates::wideEnter (control, active); } @@ -11272,7 +11844,7 @@ template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepPreReact(FullControl& control, +C_::deepPreReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -11282,21 +11854,14 @@ C_::deepPreReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepPreReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePreReact(control, event, active); - - return h; + return PreReactWrapper::execute(*this, control, event, active); } template template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepReact(FullControl& control, +C_::deepReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -11306,21 +11871,14 @@ C_::deepReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepReact (control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS( subStatus(control) |=) - SubStates::wideReact (control, event, active); - - return h; + return ReactWrapper::execute(*this, control, event, active); } template template HFSM2_CONSTEXPR(14) TaskStatus -C_::deepPostReact(FullControl& control, +C_::deepPostReact(EventControl& control, const TEvent& event) noexcept { HFSM2_ASSERT(compoRequested(control) == INVALID_PRONG); @@ -11330,14 +11888,7 @@ C_::deepPostReact(FullControl& control, ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - HFSM2_IF_PLANS( subStatus (control) |=) - SubStates::widePostReact(control, event, active); - - const TaskStatus h = - HeadState::deepPostReact(control, event); - HFSM2_IF_PLANS(headStatus (control) |= h); - - return h; + return PostReactWrapper::execute(*this, control, event, active); } template @@ -11350,8 +11901,9 @@ C_::deepQuery(ConstControl& control, const Prong active = compoActive(control); HFSM2_ASSERT(active < WIDTH); - HeadState::deepQuery(control, event); - SubStates::wideQuery(control, event, active); + ScopedCRegion region{control, REGION_ID}; + + QueryWrapper::execute(*this, control, event, active); } #if HFSM2_PLANS_AVAILABLE() @@ -12137,6 +12689,7 @@ struct HFSM2_EMPTY_BASES OS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using InitialInfo = WrapInfo; using InitialStates = typename InitialInfo::StateList; @@ -12169,13 +12722,13 @@ struct HFSM2_EMPTY_BASES OS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event ) const noexcept; @@ -12335,7 +12888,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePreReact(FullControl& control, +OS_::widePreReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; @@ -12349,7 +12902,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::wideReact(FullControl& control, +OS_::wideReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; @@ -12363,7 +12916,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePostReact(FullControl& control, +OS_::widePostReact(EventControl& control, const TEvent& event) noexcept { TaskStatus status; @@ -12676,6 +13229,7 @@ struct HFSM2_EMPTY_BASES OS_< using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Initial = InitialOS< TIndices, @@ -12697,13 +13251,13 @@ struct HFSM2_EMPTY_BASES OS_< HFSM2_CONSTEXPR(14) TaskStatus widePostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus wideReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus wideReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus widePostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus widePostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void wideQuery (ConstControl& control, TEvent& event ) const noexcept; @@ -12838,7 +13392,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePreReact(FullControl& control, +OS_::widePreReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepPreReact(control, event); @@ -12848,7 +13402,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::wideReact(FullControl& control, +OS_::wideReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepReact(control, event); @@ -12858,7 +13412,7 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -OS_::widePostReact(FullControl& control, +OS_::widePostReact(EventControl& control, const TEvent& event) noexcept { return Initial::deepPostReact(control, event); @@ -13126,6 +13680,8 @@ struct HFSM2_EMPTY_BASES O_ using StateList = typename Args::StateList; using RegionList = typename Args::RegionList; + using ReactOrder = typename Args::ReactOrder; + using Registry = RegistryT; using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; @@ -13133,6 +13689,8 @@ struct HFSM2_EMPTY_BASES O_ using ProngCBits = typename OrthoForks::CBits; using ConstControl = ConstControlT; + using ScopedCRegion = typename ConstControl::Region; + using Control = ControlT ; using ScopedOrigin = typename Control::Origin; @@ -13141,8 +13699,10 @@ struct HFSM2_EMPTY_BASES O_ using FullControl = FullControlT ; using ControlLock = typename FullControl::Lock; + using ScopedRegion = typename PlanControl::Region; using GuardControl = GuardControlT; + using EventControl = EventControlT; using Head = THead; using HeadState = S_; @@ -13164,7 +13724,12 @@ struct HFSM2_EMPTY_BASES O_ TSubStates... >; - HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Registry& registry) noexcept { return registry.orthoRequested.template bits(); } + using PreReactWrapper = PreReactWrapperT ; + using ReactWrapper = ReactWrapperT ; + using PostReactWrapper = PostReactWrapperT; + using QueryWrapper = QueryWrapperT ; + + HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Registry& registry) noexcept { return registry.orthoRequested.template bits(); } HFSM2_CONSTEXPR(11) static ProngCBits orthoRequested (const Registry& registry) noexcept { return registry.orthoRequested.template cbits(); } HFSM2_CONSTEXPR(11) static ProngBits orthoRequested ( Control& control ) noexcept { return control._core.registry.orthoRequested.template bits(); } @@ -13188,13 +13753,13 @@ struct HFSM2_EMPTY_BASES O_ HFSM2_CONSTEXPR(14) TaskStatus deepPostUpdate ( FullControl& control ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPreReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPreReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepReact (EventControl& control, const TEvent& event ) noexcept; template - HFSM2_CONSTEXPR(14) TaskStatus deepPostReact ( FullControl& control, const TEvent& event ) noexcept; + HFSM2_CONSTEXPR(14) TaskStatus deepPostReact (EventControl& control, const TEvent& event ) noexcept; template HFSM2_CONSTEXPR(14) void deepQuery (ConstControl& control, TEvent& event ) const noexcept; @@ -13377,57 +13942,36 @@ template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepPreReact(FullControl& control, +O_::deepPreReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepPreReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePreReact(control, event); - - return h; + return PreReactWrapper::execute(*this, control, event); } template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepReact(FullControl& control, +O_::deepReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - const TaskStatus h = - HeadState::deepReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::wideReact(control, event); - - return h; + return ReactWrapper::execute(*this, control, event); } template template HFSM2_CONSTEXPR(14) TaskStatus -O_::deepPostReact(FullControl& control, +O_::deepPostReact(EventControl& control, const TEvent& event) noexcept { ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; - HFSM2_IF_PLANS(subStatus(control) |=) - SubStates::widePostReact(control, event); - - const TaskStatus h = - HeadState::deepPostReact(control, event); - HFSM2_IF_PLANS(headStatus(control) |= h); - - return h; + return PostReactWrapper::execute(*this, control, event); } template @@ -13437,9 +13981,9 @@ void O_::deepQuery(ConstControl& control, TEvent& event) const noexcept { - ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; + ScopedCRegion region{control, REGION_ID}; - SubStates::wideQuery(control, event); + QueryWrapper::execute(*this, control, event); } #if HFSM2_PLANS_AVAILABLE() @@ -13796,10 +14340,6 @@ struct G_ final { using RNG = TRNG; #endif -#if HFSM2_LOG_INTERFACE_AVAILABLE() - using LoggerInterface = LoggerInterfaceT; -#endif - static constexpr Short SUBSTITUTION_LIMIT = NSubstitutionLimit; #if HFSM2_PLANS_AVAILABLE() @@ -13813,8 +14353,12 @@ struct G_ final { using Task = TaskT; #endif +#if HFSM2_LOG_INTERFACE_AVAILABLE() + using LoggerInterface = LoggerInterfaceT; +#endif + /// @brief Set Context type - /// @tparam T Context type for data shared between states and/or data interface between FSM and external code + /// @tparam `T` Context type for data shared between states and/or data interface between FSM and external code template using ContextT = G_; @@ -13827,38 +14371,38 @@ struct G_ final { #if HFSM2_UTILITY_THEORY_AVAILABLE() /// @brief Set Rank type - /// @tparam T Rank type for 'TRank State::rank() const' method + /// @tparam `T` Rank type for 'TRank State::rank() const' method template using RankT = G_; /// @brief Set Utility type - /// @tparam T Utility type for 'TUtility State::utility() const' method + /// @tparam `T` Utility type for 'TUtility State::utility() const' method template using UtilityT = G_; /// @brief Set RNG type - /// @tparam T RNG type used in 'Random' regions + /// @tparam `T` RNG type used in 'Random' regions template using RandomT = G_; #endif /// @brief Set Substitution limit - /// @tparam N Maximum number times 'guard()' methods can substitute their states for others - template + /// @tparam `N` Maximum number times 'guard()' methods can substitute their states for others + template using SubstitutionLimitN = G_; #if HFSM2_PLANS_AVAILABLE() /// @brief Set Task capacity - /// @tparam N Maximum number of tasks across all plans + /// @tparam `N` Maximum number of tasks across all plans template using TaskCapacityN = G_; #endif /// @brief Set Transition Payload type - /// @tparam T Utility type for 'TUtility State::utility() const' method + /// @tparam `T` Payload type template using PayloadT = G_; @@ -14094,8 +14638,8 @@ using Config = detail::G_< >; /// @brief 'Template namespace' for FSM classes -/// @tparam TConfig 'ConfigT<>' type configuration for MachineT<> -/// @see ConfigT<> +/// @tparam `TConfig` `ConfigT<>` type configuration for MachineT<> +/// @see `ConfigT<>` template using MachineT = detail::M_; @@ -14156,6 +14700,7 @@ class R_ { using PlanControl = PlanControlT ; using FullControl = FullControlT ; using GuardControl = GuardControlT; + using EventControl = EventControlT; static constexpr Short SUBSTITUTION_LIMIT = Forward::SUBSTITUTION_LIMIT; @@ -14793,10 +15338,14 @@ R_::react(const TEvent& event) noexcept { HFSM2_ASSERT(_core.registry.isActive()); TransitionSets emptyTransitions; - FullControl control{_core, emptyTransitions}; + EventControl control{_core, emptyTransitions}; _apex. deepPreReact(control, event); + + control._consumed = false; _apex. deepReact(control, event); + + control._consumed = false; _apex.deepPostReact(control, event); #if HFSM2_PLANS_AVAILABLE() diff --git a/projects/premake/hfsm2-lite.sln b/projects/premake/hfsm2-lite.sln index 2c7de9c..0b3991b 100644 --- a/projects/premake/hfsm2-lite.sln +++ b/projects/premake/hfsm2-lite.sln @@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "temp-14", "temp-14.vcxproj", "{ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "advanced_event_handling-14", "advanced_event_handling-14.vcxproj", "{F2F0D850-DE00-8521-47BA-E93F33E973BA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic_audio_player-14", "basic_audio_player-14.vcxproj", "{D6549E75-42C1-5970-0BB5-F1CD77E07BD8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic_traffic_light-14", "basic_traffic_light-14.vcxproj", "{8EF02841-7AEA-5193-6357-E8A34FF0B7FF}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "temp-clang", "temp-clang.vcxproj", "{2DF246B5-19AA-8802-82B1-615E6E8823F3}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calculator-14", "calculator-14.vcxproj", "{81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "debug_logger_interface-14", "debug_logger_interface-14.vcxproj", "{CD91E21A-3954-16A5-8204-A531EE05EF82}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "temp-14", "temp-14.vcxproj", "{ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-14", "test-14.vcxproj", "{37901DD9-A36F-9C74-AC87-274B18E602D6}" EndProject @@ -23,26 +31,78 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|Any CPU.Build.0 = Debug|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|Win32.ActiveCfg = Debug|Win32 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|Win32.Build.0 = Debug|Win32 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|x64.ActiveCfg = Debug|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Debug|x64.Build.0 = Debug|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|Any CPU.ActiveCfg = Release|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|Any CPU.Build.0 = Release|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|Win32.ActiveCfg = Release|Win32 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|Win32.Build.0 = Release|Win32 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|x64.ActiveCfg = Release|x64 + {F2F0D850-DE00-8521-47BA-E93F33E973BA}.Release|x64.Build.0 = Release|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|Any CPU.ActiveCfg = Debug|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|Any CPU.Build.0 = Debug|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|Win32.ActiveCfg = Debug|Win32 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|Win32.Build.0 = Debug|Win32 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|x64.ActiveCfg = Debug|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Debug|x64.Build.0 = Debug|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|Any CPU.ActiveCfg = Release|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|Any CPU.Build.0 = Release|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|Win32.ActiveCfg = Release|Win32 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|Win32.Build.0 = Release|Win32 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|x64.ActiveCfg = Release|x64 + {D6549E75-42C1-5970-0BB5-F1CD77E07BD8}.Release|x64.Build.0 = Release|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|Any CPU.ActiveCfg = Debug|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|Any CPU.Build.0 = Debug|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|Win32.ActiveCfg = Debug|Win32 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|Win32.Build.0 = Debug|Win32 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|x64.ActiveCfg = Debug|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Debug|x64.Build.0 = Debug|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|Any CPU.ActiveCfg = Release|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|Any CPU.Build.0 = Release|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|Win32.ActiveCfg = Release|Win32 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|Win32.Build.0 = Release|Win32 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|x64.ActiveCfg = Release|x64 + {8EF02841-7AEA-5193-6357-E8A34FF0B7FF}.Release|x64.Build.0 = Release|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|Any CPU.ActiveCfg = Debug|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|Any CPU.Build.0 = Debug|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|Win32.ActiveCfg = Debug|Win32 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|Win32.Build.0 = Debug|Win32 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|x64.ActiveCfg = Debug|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Debug|x64.Build.0 = Debug|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|Any CPU.ActiveCfg = Release|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|Any CPU.Build.0 = Release|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|Win32.ActiveCfg = Release|Win32 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|Win32.Build.0 = Release|Win32 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|x64.ActiveCfg = Release|x64 + {81C649A8-ED86-C5DE-B6C1-0E5C22410ABB}.Release|x64.Build.0 = Release|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|Any CPU.ActiveCfg = Debug|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|Any CPU.Build.0 = Debug|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|Win32.ActiveCfg = Debug|Win32 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|Win32.Build.0 = Debug|Win32 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|x64.ActiveCfg = Debug|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Debug|x64.Build.0 = Debug|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|Any CPU.ActiveCfg = Release|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|Any CPU.Build.0 = Release|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|Win32.ActiveCfg = Release|Win32 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|Win32.Build.0 = Release|Win32 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|x64.ActiveCfg = Release|x64 + {CD91E21A-3954-16A5-8204-A531EE05EF82}.Release|x64.Build.0 = Release|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|Any CPU.ActiveCfg = Debug|x64 + {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|Any CPU.Build.0 = Debug|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|Win32.ActiveCfg = Debug|Win32 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|Win32.Build.0 = Debug|Win32 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|x64.ActiveCfg = Debug|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Debug|x64.Build.0 = Debug|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|Any CPU.ActiveCfg = Release|x64 + {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|Any CPU.Build.0 = Release|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|Win32.ActiveCfg = Release|Win32 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|Win32.Build.0 = Release|Win32 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|x64.ActiveCfg = Release|x64 {ADCBAED8-19AB-2D74-22C3-B84A8E2194D5}.Release|x64.Build.0 = Release|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Debug|Any CPU.ActiveCfg = Debug|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Debug|Win32.ActiveCfg = Debug|Win32 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Debug|Win32.Build.0 = Debug|Win32 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Debug|x64.ActiveCfg = Debug|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Debug|x64.Build.0 = Debug|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Release|Any CPU.ActiveCfg = Release|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Release|Win32.ActiveCfg = Release|Win32 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Release|Win32.Build.0 = Release|Win32 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Release|x64.ActiveCfg = Release|x64 - {2DF246B5-19AA-8802-82B1-615E6E8823F3}.Release|x64.Build.0 = Release|x64 {37901DD9-A36F-9C74-AC87-274B18E602D6}.Debug|Any CPU.ActiveCfg = Debug|x64 {37901DD9-A36F-9C74-AC87-274B18E602D6}.Debug|Any CPU.Build.0 = Debug|x64 {37901DD9-A36F-9C74-AC87-274B18E602D6}.Debug|Win32.ActiveCfg = Debug|Win32 diff --git a/projects/premake/test-14.vcxproj b/projects/premake/test-14.vcxproj index 64b47f0..65cb5ea 100644 --- a/projects/premake/test-14.vcxproj +++ b/projects/premake/test-14.vcxproj @@ -256,6 +256,7 @@ + @@ -291,6 +292,7 @@ + diff --git a/projects/premake/test-14.vcxproj.filters b/projects/premake/test-14.vcxproj.filters index a9e248b..55f3e1d 100644 --- a/projects/premake/test-14.vcxproj.filters +++ b/projects/premake/test-14.vcxproj.filters @@ -249,6 +249,9 @@ development\hfsm2\detail\structure + + development\hfsm2\detail\structure + development\hfsm2\detail\structure @@ -350,6 +353,9 @@ test + + test + test diff --git a/projects/premake/test-15.vcxproj b/projects/premake/test-15.vcxproj index 64f6fd5..ada7e54 100644 --- a/projects/premake/test-15.vcxproj +++ b/projects/premake/test-15.vcxproj @@ -260,6 +260,7 @@ + @@ -295,6 +296,7 @@ + diff --git a/projects/premake/test-15.vcxproj.filters b/projects/premake/test-15.vcxproj.filters index a9e248b..55f3e1d 100644 --- a/projects/premake/test-15.vcxproj.filters +++ b/projects/premake/test-15.vcxproj.filters @@ -249,6 +249,9 @@ development\hfsm2\detail\structure + + development\hfsm2\detail\structure + development\hfsm2\detail\structure @@ -350,6 +353,9 @@ test + + test + test diff --git a/projects/premake/test-16.vcxproj b/projects/premake/test-16.vcxproj index e592909..a64ee1b 100644 --- a/projects/premake/test-16.vcxproj +++ b/projects/premake/test-16.vcxproj @@ -248,6 +248,7 @@ + @@ -283,6 +284,7 @@ + diff --git a/projects/premake/test-16.vcxproj.filters b/projects/premake/test-16.vcxproj.filters index a9e248b..55f3e1d 100644 --- a/projects/premake/test-16.vcxproj.filters +++ b/projects/premake/test-16.vcxproj.filters @@ -249,6 +249,9 @@ development\hfsm2\detail\structure + + development\hfsm2\detail\structure + development\hfsm2\detail\structure @@ -350,6 +353,9 @@ test + + test + test diff --git a/projects/premake/test-17.vcxproj b/projects/premake/test-17.vcxproj index b1966c4..f65b9f6 100644 --- a/projects/premake/test-17.vcxproj +++ b/projects/premake/test-17.vcxproj @@ -252,6 +252,7 @@ + @@ -287,6 +288,7 @@ + diff --git a/projects/premake/test-17.vcxproj.filters b/projects/premake/test-17.vcxproj.filters index a9e248b..55f3e1d 100644 --- a/projects/premake/test-17.vcxproj.filters +++ b/projects/premake/test-17.vcxproj.filters @@ -249,6 +249,9 @@ development\hfsm2\detail\structure + + development\hfsm2\detail\structure + development\hfsm2\detail\structure @@ -350,6 +353,9 @@ test + + test + test diff --git a/projects/premake/test-clang.vcxproj b/projects/premake/test-clang.vcxproj index 9f23bbd..73b90b3 100644 --- a/projects/premake/test-clang.vcxproj +++ b/projects/premake/test-clang.vcxproj @@ -256,6 +256,7 @@ + @@ -291,6 +292,7 @@ + diff --git a/projects/premake/test-clang.vcxproj.filters b/projects/premake/test-clang.vcxproj.filters index a9e248b..55f3e1d 100644 --- a/projects/premake/test-clang.vcxproj.filters +++ b/projects/premake/test-clang.vcxproj.filters @@ -249,6 +249,9 @@ development\hfsm2\detail\structure + + development\hfsm2\detail\structure + development\hfsm2\detail\structure @@ -350,6 +353,9 @@ test + + test + test diff --git a/test/reported/issue_49.cpp b/test/reported/issue_49.cpp index 8de07cd..efa3b7a 100644 --- a/test/reported/issue_49.cpp +++ b/test/reported/issue_49.cpp @@ -37,7 +37,7 @@ struct Disabled : FSM::State control.changeTo(); } - void react(const Enable&, FullControl& control) + void react(const Enable&, EventControl& control) { control.changeTo(); } @@ -47,7 +47,7 @@ struct Disabled : FSM::State struct Enabled : FSM::State { - void react(const Disable&, FullControl& control) + void react(const Disable&, EventControl& control) { control.changeTo(); } diff --git a/test/shared/test_task_list.cpp b/test/shared/test_task_list.cpp index 916a9bb..c207bcf 100644 --- a/test/shared/test_task_list.cpp +++ b/test/shared/test_task_list.cpp @@ -16,7 +16,7 @@ TEST_CASE("Shared.List<>") { List list; constexpr auto CAPACITY = List::CAPACITY; - REQUIRE(list.count() == 0); //-V521 + REQUIRE(list.count() == 0); WHEN("fill, delete and re-insert an element") { for (List::Index i = 0; i < CAPACITY; ++i) { @@ -24,54 +24,54 @@ TEST_CASE("Shared.List<>") { static_cast(i), hfsm2::TransitionType::COUNT); - REQUIRE(index == i); //-V521 - REQUIRE(list.count() == i + 1); //-V521 + REQUIRE(index == i); + REQUIRE(list.count() == i + 1); } for (List::Index i = 0; i < CAPACITY; ++i) REQUIRE(list[i] == hfsm2::detail::TaskBase{static_cast(i), static_cast(i), - hfsm2::TransitionType::COUNT}); //-V521 + hfsm2::TransitionType::COUNT}); THEN("at the start") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); list.remove(0); - REQUIRE(list.count() == CAPACITY - 1); //-V521 + REQUIRE(list.count() == CAPACITY - 1); const auto index = list.emplace(static_cast(0u), static_cast(0u), hfsm2::TransitionType::COUNT); - REQUIRE(index == 0); //-V521 - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(index == 0); + REQUIRE(list.count() == CAPACITY); } AND_THEN("at the mid") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); constexpr List::Index mid = CAPACITY / 2; list.remove(mid); - REQUIRE(list.count() == CAPACITY - 1); //-V521 + REQUIRE(list.count() == CAPACITY - 1); const auto index = list.emplace(static_cast(mid), static_cast(mid), hfsm2::TransitionType::COUNT); - REQUIRE(index == mid); //-V521 - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(index == mid); + REQUIRE(list.count() == CAPACITY); } AND_THEN("at the end") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); constexpr List::Index end = CAPACITY - 1; list.remove(end); - REQUIRE(list.count() == CAPACITY - 1); //-V521 + REQUIRE(list.count() == CAPACITY - 1); const auto index = list.emplace(static_cast(end), static_cast(end), hfsm2::TransitionType::COUNT); - REQUIRE(index == end); //-V521 - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(index == end); + REQUIRE(list.count() == CAPACITY); } } @@ -81,21 +81,21 @@ TEST_CASE("Shared.List<>") { static_cast(i), hfsm2::TransitionType::COUNT); - REQUIRE(index == i); //-V521 - REQUIRE(list.count() == i + 1); //-V521 + REQUIRE(index == i); + REQUIRE(list.count() == i + 1); } for (List::Index i = 0; i < CAPACITY; ++i) REQUIRE(list[i] == hfsm2::detail::TaskBase{static_cast(i), static_cast(i), - hfsm2::TransitionType::COUNT}); //-V521 + hfsm2::TransitionType::COUNT}); THEN("from the start") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); for (List::Index i = 0; i < CAPACITY; ++i) { list.remove(i); - REQUIRE(list.count() == CAPACITY - 1 - i); //-V521 + REQUIRE(list.count() == CAPACITY - 1 - i); } for (List::Index i = 0; i < CAPACITY; ++i) { @@ -103,21 +103,21 @@ TEST_CASE("Shared.List<>") { static_cast(i), hfsm2::TransitionType::COUNT); - REQUIRE(index == CAPACITY - 1 - i); //-V521 - REQUIRE(list.count() == i + 1); //-V521 + REQUIRE(index == CAPACITY - 1 - i); + REQUIRE(list.count() == i + 1); } } AND_THEN("at the mid") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); } AND_THEN("from the end") { - REQUIRE(list.count() == CAPACITY); //-V521 + REQUIRE(list.count() == CAPACITY); for (List::Index i = 0; i < CAPACITY; ++i) { list.remove(CAPACITY - 1 - i); - REQUIRE(list.count() == CAPACITY - 1 - i); //-V521 + REQUIRE(list.count() == CAPACITY - 1 - i); } for (List::Index i = 0; i < CAPACITY; ++i) { @@ -125,8 +125,8 @@ TEST_CASE("Shared.List<>") { static_cast(i), hfsm2::TransitionType::COUNT); - REQUIRE(index == i); //-V521 - REQUIRE(list.count() == i + 1); //-V521 + REQUIRE(index == i); + REQUIRE(list.count() == i + 1); } } } diff --git a/test/test_ancestors.cpp b/test/test_ancestors.cpp index 06f25f4..3a229c7 100644 --- a/test/test_ancestors.cpp +++ b/test/test_ancestors.cpp @@ -111,13 +111,13 @@ struct AncestorT void postUpdate ( FullControl& control) { control._().emplace_back(stateId(), Event::Type::POST_UPDATE); REQUIRE(control.stateId() == stateId()); } void preReact (const Event&, - FullControl& control) { control._().emplace_back(stateId(), Event::Type::PRE_REACT); REQUIRE(control.stateId() == stateId()); } + EventControl& control) { control._().emplace_back(stateId(), Event::Type::PRE_REACT); REQUIRE(control.stateId() == stateId()); } void react (const Event&, - FullControl& control) { control._().emplace_back(stateId(), Event::Type::REACT); REQUIRE(control.stateId() == stateId()); } + EventControl& control) { control._().emplace_back(stateId(), Event::Type::REACT); REQUIRE(control.stateId() == stateId()); } void postReact (const Event&, - FullControl& control) { control._().emplace_back(stateId(), Event::Type::POST_REACT); REQUIRE(control.stateId() == stateId()); } + EventControl& control) { control._().emplace_back(stateId(), Event::Type::POST_REACT); REQUIRE(control.stateId() == stateId()); } void exitGuard (GuardControl& control) { control._().emplace_back(stateId(), Event::Type::EXIT_GUARD); REQUIRE(control.stateId() == stateId()); } diff --git a/test/test_internal_payloads.cpp b/test/test_internal_payloads.cpp index 205175a..7928428 100644 --- a/test/test_internal_payloads.cpp +++ b/test/test_internal_payloads.cpp @@ -75,7 +75,7 @@ class Timed { public: void enter(PlanControl&) { _elapsed = 0.0f; } - void preUpdate(FullControl& control) { _elapsed += control._(); } //-V669 + void preUpdate(FullControl& control) { _elapsed += control._(); } float elapsed() const { return _elapsed; } @@ -100,7 +100,7 @@ class Tracked } void react(const RegionStateIndex& event, - FullControl& control) + EventControl& control) { if (control.stateId() == event.stateId) REQUIRE(control.activeSubState() == event.prong); @@ -239,7 +239,7 @@ struct A_2_1 { void enter(PlanControl&) {} void update(FullControl&) {} - void react(const RegionStateIndex&, FullControl&) {} + void react(const RegionStateIndex&, EventControl&) {} void exit(PlanControl&) {} }; @@ -265,7 +265,7 @@ struct A_2_2 } //void update(FullControl&) {} - //void react(const RegionStateIndex&, FullControl&) {} + //void react(const RegionStateIndex&, EventControl&) {} void exit(PlanControl&) {} }; @@ -276,7 +276,7 @@ struct B { void enter(PlanControl&) {} void update(FullControl&) {} - void react(const RegionStateIndex&, FullControl&) {} + void react(const RegionStateIndex&, EventControl&) {} void exit(PlanControl&) {} }; diff --git a/test/test_internal_transitions.cpp b/test/test_internal_transitions.cpp index 362bc05..b5ccede 100644 --- a/test/test_internal_transitions.cpp +++ b/test/test_internal_transitions.cpp @@ -71,7 +71,7 @@ class Timed { public: void enter(PlanControl&) { _elapsed = 0.0f; } - void preUpdate(FullControl& control) { _elapsed += control._(); } //-V669 + void preUpdate(FullControl& control) { _elapsed += control._(); } float elapsed() const { return _elapsed; } @@ -113,7 +113,7 @@ struct A //void entryGuard(GuardControl&) {} void enter(PlanControl&) {} void update(FullControl&) {} - //void react(const Action&, FullControl&) {} + //void react(const Action&, EventControl&) {} void exit(PlanControl&) {} }; @@ -160,7 +160,7 @@ struct A_2_1 { void enter(PlanControl&) {} void update(FullControl&) {} - void react(const Action&, FullControl&) {} + void react(const Action&, EventControl&) {} void exit(PlanControl&) {} }; @@ -169,7 +169,7 @@ struct A_2_2 { void enter(PlanControl&) {} //void update(FullControl&) {} - //void react(const Action&, FullControl&) {} + //void react(const Action&, EventControl&) {} void exit(PlanControl&) {} }; @@ -180,7 +180,7 @@ struct B { void enter(PlanControl&) {} void update(FullControl&) {} - void react(const Action&, FullControl&) {} + void react(const Action&, EventControl&) {} void exit(PlanControl&) {} }; diff --git a/test/test_react_order.cpp b/test/test_react_order.cpp new file mode 100644 index 0000000..693c863 --- /dev/null +++ b/test/test_react_order.cpp @@ -0,0 +1,162 @@ +// HFSM2 (hierarchical state machine for games and interactive applications) +// Created by Andrew Gresyk + +#define HFSM2_ENABLE_PLANS +#include "tools.hpp" + +namespace test_react_order { + +//////////////////////////////////////////////////////////////////////////////// + +using Config = hfsm2::Config + ::BottomUpReactions; + +using M = hfsm2::MachineT; + +using Logger = LoggerT; + +struct Empty {}; + +//------------------------------------------------------------------------------ + +#define S(s) struct s + +using FSM = M::OrthogonalRoot, + M::Composite + >; + +#undef S + +//------------------------------------------------------------------------------ + +static_assert(FSM::stateId() == 0, ""); +static_assert(FSM::stateId() == 1, ""); +static_assert(FSM::stateId() == 2, ""); +static_assert(FSM::stateId() == 3, ""); +static_assert(FSM::stateId() == 4, ""); +static_assert(FSM::stateId() == 5, ""); +static_assert(FSM::stateId() == 6, ""); + +//////////////////////////////////////////////////////////////////////////////// + +struct R : FSM::State {}; +struct C1 : FSM::State {}; +struct I1 : FSM::State {}; + +struct D1 + : FSM::State +{ + void preReact(const Empty&, EventControl& control) { + control.consumeEvent(); + } + + void react(const Empty&, EventControl& control) { + control.consumeEvent(); + } + + void postReact(const Empty&, EventControl& control) { + control.consumeEvent(); + } +}; + +struct C2 : FSM::State {}; +struct I2 : FSM::State {}; +struct D2 : FSM::State {}; + +//////////////////////////////////////////////////////////////////////////////// + +const Types all = { + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), +}; + +//------------------------------------------------------------------------------ + +TEST_CASE("FSM.Prepend Plans") { + Logger logger; + + WHEN("Created") { + FSM::Instance machine{&logger}; + + logger.assertSequence({}); + + assertActive(machine, all, { + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + }); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + THEN("Initial reactions") { + machine.react(Empty{}); + + logger.assertSequence({ + { FSM::stateId(), Event::Type::PRE_REACT }, + { FSM::stateId(), Event::Type::PRE_REACT }, + { FSM::stateId(), Event::Type::PRE_REACT }, + { FSM::stateId(), Event::Type::PRE_REACT }, + { FSM::stateId(), Event::Type::PRE_REACT }, + + { FSM::stateId(), Event::Type::REACT }, + { FSM::stateId(), Event::Type::REACT }, + { FSM::stateId(), Event::Type::REACT }, + { FSM::stateId(), Event::Type::REACT }, + { FSM::stateId(), Event::Type::REACT }, + + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + }); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + AND_THEN("Secondary reactions") { + machine. changeTo(); + machine.immediateChangeTo(); + + assertActive(machine, all, { + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + FSM::stateId(), + }); + + machine.react(Empty{}); + + logger.assertSequence({ + { Event::Type::CHANGE, FSM::stateId() }, + { Event::Type::CHANGE, FSM::stateId() }, + + { FSM::stateId(), Event::Type::PRE_REACT }, + + { FSM::stateId(), Event::Type::REACT }, + + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + { FSM::stateId(), Event::Type::POST_REACT }, + }); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + } +} + +//////////////////////////////////////////////////////////////////////////////// + +} diff --git a/test/tools.hpp b/test/tools.hpp index f6a9b59..5c8ed8c 100644 --- a/test/tools.hpp +++ b/test/tools.hpp @@ -128,44 +128,44 @@ struct LoggerT final void recordMethod(const Context& context, const StateID origin, - const Method method) override; + const Method method) override; void recordTransition(const Context& context, const StateID origin, const TransitionType transitionType, - const StateID target) override; + const StateID target) override; #ifdef HFSM2_ENABLE_PLANS void recordTaskStatus(const Context& context, const RegionID region, const StateID origin, - const StatusEvent event) override; + const StatusEvent event) override; void recordPlanStatus(const Context& context, const RegionID region, - const StatusEvent event) override; + const StatusEvent event) override; #endif void recordCancelledPending(const Context& context, - const StateID origin) override; + const StateID origin) override; void recordSelectResolution(const Context& context, const StateID head, - const Prong prong) override; + const Prong prong) override; #ifdef HFSM2_ENABLE_UTILITY_THEORY void recordUtilityResolution(const Context& context, const StateID head, const Prong prong, - const Utilty utilty) override; + const Utilty utilty) override; void recordRandomResolution(const Context& context, const StateID head, const Prong prong, - const Utilty utilty) override; + const Utilty utilty) override; #endif diff --git a/test/wiki_tutorial.cpp b/test/wiki_tutorial.cpp index 8d0520c..0aae02f 100644 --- a/test/wiki_tutorial.cpp +++ b/test/wiki_tutorial.cpp @@ -54,7 +54,7 @@ struct Event {}; struct Off : FSM::State { - void entryGuard(FullControl& control) { // called before state activation, use to re-route transitions + void entryGuard(FullControl& control) { // called before state activation, use to re-route transitions if (control.context().powerOn) // access shared data control.changeTo(); // initiate a transition into 'On' region } @@ -63,7 +63,7 @@ struct Off struct On : FSM::State { - void enter(PlanControl& control) { // called on state activation + void enter(PlanControl& control) { // called on state activation auto plan = control.plan(); // access the plan for the region plan.change(); // sequence plan steps, executed when the previous state succeeds @@ -72,7 +72,7 @@ struct On plan.change(); } - void exit(PlanControl& /*control*/) {} // called on state deactivation + void exit(PlanControl& /*control*/) {} // called on state deactivation void planSucceeded(FullControl& control) { // called on the successful completion of all plan steps control.changeTo(); @@ -101,7 +101,7 @@ struct Yellow struct Green : FSM::State { - void react(const Event&, FullControl& control) { // called on external events + void react(const Event&, EventControl& control) { // called on external events control.succeed(); // advance to the next plan step } }; From a1557a7cfe4b204857a3ffecb6401bc7f5f4dbef Mon Sep 17 00:00:00 2001 From: Andrew Gresyk Date: Mon, 1 Jan 2024 20:50:53 +0200 Subject: [PATCH 2/2] Removed duplicate alias in `O_<>` --- .../hfsm2/detail/structure/orthogonal.hpp | 2 -- include/hfsm2/machine.hpp | 30 +++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/development/hfsm2/detail/structure/orthogonal.hpp b/development/hfsm2/detail/structure/orthogonal.hpp index 09a0b90..d53ce5b 100644 --- a/development/hfsm2/detail/structure/orthogonal.hpp +++ b/development/hfsm2/detail/structure/orthogonal.hpp @@ -58,8 +58,6 @@ struct HFSM2_EMPTY_BASES O_ using ScopedOrigin = typename Control::Origin; using PlanControl = PlanControlT ; - using ScopedRegion = typename PlanControl::Region; - using FullControl = FullControlT ; using ControlLock = typename FullControl::Lock; using ScopedRegion = typename PlanControl::Region; diff --git a/include/hfsm2/machine.hpp b/include/hfsm2/machine.hpp index c2cc508..721687d 100644 --- a/include/hfsm2/machine.hpp +++ b/include/hfsm2/machine.hpp @@ -1771,7 +1771,7 @@ template template HFSM2_CONSTEXPR(14) T& -StaticArrayT::operator[] (const N index) noexcept { +StaticArrayT::operator[] (const N index) noexcept { HFSM2_ASSERT(0 <= index && index < CAPACITY); return _items[static_cast(index)]; @@ -2500,18 +2500,18 @@ struct TransitionBase { HFSM2_CONSTEXPR(11) bool operator == (const TransitionBase& other) const noexcept { - return origin == other.origin && + return origin == other.origin && destination == other.destination && - method == other.method && + method == other.method && type == other.type; } HFSM2_CONSTEXPR(11) bool operator != (const TransitionBase& other) const noexcept { - return origin != other.origin || + return origin != other.origin || destination != other.destination || - method != other.method || + method != other.method || type != other.type; } @@ -11450,8 +11450,8 @@ struct HFSM2_EMPTY_BASES C_ using Control = ControlT ; using ScopedOrigin = typename Control::Origin; - using FullControl = FullControlT ; using PlanControl = PlanControlT ; + using FullControl = FullControlT ; using ControlLock = typename FullControl::Lock; using ScopedRegion = typename PlanControl::Region; @@ -13695,8 +13695,6 @@ struct HFSM2_EMPTY_BASES O_ using ScopedOrigin = typename Control::Origin; using PlanControl = PlanControlT ; - using ScopedRegion = typename PlanControl::Region; - using FullControl = FullControlT ; using ControlLock = typename FullControl::Lock; using ScopedRegion = typename PlanControl::Region; @@ -14767,14 +14765,6 @@ class R_ { HFSM2_CONSTEXPR(20) ~R_() noexcept; - /// @brief Access context - /// @return context - HFSM2_CONSTEXPR(14) Context& context() noexcept { return _core.context; } - - /// @brief Access context - /// @return context - HFSM2_CONSTEXPR(11) const Context& context() const noexcept { return _core.context; } - /// @brief Get state identifier for a state type /// @tparam `TState` State type /// @return Numeric state identifier @@ -14789,6 +14779,14 @@ class R_ { static HFSM2_CONSTEXPR(11) RegionID regionId() noexcept { return static_cast(index()); } + /// @brief Access context + /// @return context + HFSM2_CONSTEXPR(14) Context& context() noexcept { return _core.context; } + + /// @brief Access context + /// @return context + HFSM2_CONSTEXPR(11) const Context& context() const noexcept { return _core.context; } + /// @brief Access state instance /// @tparam `TState` State type /// @return State instance