Skip to content

Commit 989e59b

Browse files
Merge pull request #19 from andrew-gresyk/experimental
+ hid plan-related functionality under HFSM2_ENABLE_PLANS + added HFSM2_ENABLE_ALL as a shortcut to enable all features
2 parents 02e2124 + bd02b13 commit 989e59b

38 files changed

+1138
-689
lines changed

examples/basic_audio_player/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static_assert(FSM::stateId<Paused>() == 3, "");
6262

6363
// custom logger for recording all transitions
6464
struct Logger
65-
: hfsm2::LoggerInterfaceT<Context>
65+
: M::LoggerInterface
6666
{
6767
static const char* stateName(const StateID stateId) {
6868
switch (stateId) {

examples/snippets/wiki_plans.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33

4+
#define HFSM2_ENABLE_PLANS
45
#include <hfsm2/machine.hpp>
56

67
#include <catch2/catch.hpp>

examples/snippets/wiki_tutorial.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// HFSM2 (hierarchical state machine for games and interactive applications)
22
// Created by Andrew Gresyk
33

4+
#define HFSM2_ENABLE_PLANS
45
#include <hfsm2/machine.hpp>
56

67
#include <catch2/catch.hpp>

include/hfsm2/detail/debug/logger_interface.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ namespace hfsm2 {
55
////////////////////////////////////////////////////////////////////////////////
66

77
template <typename TContext = EmptyContext
8-
9-
#ifdef HFSM2_ENABLE_UTILITY_THEORY
10-
, typename TUtilty = float
11-
#endif
12-
13-
>
8+
HFSM2_IF_UTILITY_THEORY(, typename TUtilty = float)
9+
, FeatureTag NFeatureTag = FEATURE_TAG>
1410
struct LoggerInterfaceT {
1511
using Context = TContext;
1612

@@ -22,7 +18,10 @@ struct LoggerInterfaceT {
2218
using StateID = ::hfsm2::StateID;
2319
using RegionID = ::hfsm2::RegionID;
2420
using TransitionType = ::hfsm2::TransitionType;
21+
22+
#ifdef HFSM2_ENABLE_PLANS
2523
using StatusEvent = ::hfsm2::StatusEvent;
24+
#endif
2625

2726
virtual void recordMethod(Context& /*context*/,
2827
const StateID /*origin*/,
@@ -35,6 +34,8 @@ struct LoggerInterfaceT {
3534
const StateID /*target*/)
3635
{}
3736

37+
#ifdef HFSM2_ENABLE_PLANS
38+
3839
virtual void recordTaskStatus(Context& /*context*/,
3940
const RegionID /*region*/,
4041
const StateID /*origin*/,
@@ -46,6 +47,8 @@ struct LoggerInterfaceT {
4647
const StatusEvent /*event*/)
4748
{}
4849

50+
#endif
51+
4952
virtual void recordCancelledPending(Context& /*context*/,
5053
const StateID /*origin*/)
5154
{}
@@ -71,8 +74,9 @@ struct LoggerInterfaceT {
7174

7275
#else
7376

74-
template <typename TContext = EmptyContext,
75-
typename TUtilty = float>
77+
template <typename TContext = EmptyContext
78+
HFSM2_IF_UTILITY_THEORY(, typename TUtilty = float)
79+
, FeatureTag NFeatureTag = FEATURE_TAG>
7680
using LoggerInterfaceT = void;
7781

7882
#endif

include/hfsm2/detail/debug/shared.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ enum class Method : uint8_t {
1919
EXIT_GUARD,
2020
EXIT,
2121
DESTRUCT,
22+
23+
#ifdef HFSM2_ENABLE_PLANS
2224
PLAN_SUCCEEDED,
2325
PLAN_FAILED,
26+
#endif
2427

2528
COUNT
2629
};
@@ -40,13 +43,17 @@ enum class TransitionType : uint8_t {
4043
COUNT
4144
};
4245

46+
#ifdef HFSM2_ENABLE_PLANS
47+
4348
enum class StatusEvent : uint8_t {
4449
SUCCEEDED,
4550
FAILED,
4651

4752
COUNT
4853
};
4954

55+
#endif
56+
5057
//------------------------------------------------------------------------------
5158

5259
static inline
@@ -94,8 +101,11 @@ methodName(const Method method) {
94101
case Method::EXIT_GUARD: return "exitGuard";
95102
case Method::EXIT: return "exit";
96103
case Method::DESTRUCT: return "destruct";
104+
105+
#ifdef HFSM2_ENABLE_PLANS
97106
case Method::PLAN_SUCCEEDED: return "planSucceeded";
98107
case Method::PLAN_FAILED: return "planFailed";
108+
#endif
99109

100110
default:
101111
HFSM2_BREAK();

include/hfsm2/detail/debug/structure_report.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace detail {
1919
#ifdef HFSM2_ENABLE_TRANSITION_HISTORY
2020

2121
TransitionType
22-
HFSM2_INLINE
22+
inline
2323
convert(const Request::Type type) {
2424
switch (type) {
2525
case Request::CHANGE:
@@ -53,7 +53,7 @@ convert(const Request::Type type) {
5353
//------------------------------------------------------------------------------
5454

5555
Request::Type
56-
HFSM2_INLINE
56+
inline
5757
convert(const TransitionType type) {
5858
switch (type) {
5959
case TransitionType::CHANGE:
@@ -180,7 +180,9 @@ struct alignas(4) Transition {
180180

181181
//------------------------------------------------------------------------------
182182

183-
bool operator == (const Transition& l, const Transition& r) {
183+
inline
184+
bool
185+
operator == (const Transition& l, const Transition& r) {
184186
return l.stateId == r.stateId
185187
&& l.method == r.method
186188
&& l.transitionType == r.transitionType;

include/hfsm2/detail/root.hpp

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class R_ {
1818
#endif
1919

2020
#ifdef HFSM2_ENABLE_LOG_INTERFACE
21-
using Logger = typename TConfig::Logger;
21+
using Logger = typename TConfig::LoggerInterface;
2222
#endif
2323

2424
using Apex = TApex;
@@ -28,21 +28,24 @@ class R_ {
2828
using StateList = typename Info::StateList;
2929
using RegionList = typename Info::RegionList;
3030

31-
static constexpr LongIndex SUBSTITUTION_LIMIT = Info::SUBSTITUTION_LIMIT;
32-
static constexpr LongIndex TASK_CAPACITY = Info::TASK_CAPACITY;
31+
static constexpr LongIndex SUBSTITUTION_LIMIT = Info::SUBSTITUTION_LIMIT;
32+
33+
#ifdef HFSM2_ENABLE_PLANS
34+
static constexpr LongIndex TASK_CAPACITY = Info::TASK_CAPACITY;
35+
#endif
3336

3437
public:
35-
static constexpr LongIndex REVERSE_DEPTH = ApexInfo::REVERSE_DEPTH;
36-
static constexpr ShortIndex COMPO_REGIONS = ApexInfo::COMPO_REGIONS;
37-
static constexpr LongIndex COMPO_PRONGS = ApexInfo::COMPO_PRONGS;
38-
static constexpr ShortIndex ORTHO_REGIONS = ApexInfo::ORTHO_REGIONS;
39-
static constexpr ShortIndex ORTHO_UNITS = ApexInfo::ORTHO_UNITS;
38+
static constexpr LongIndex REVERSE_DEPTH = ApexInfo::REVERSE_DEPTH;
39+
static constexpr ShortIndex COMPO_REGIONS = ApexInfo::COMPO_REGIONS;
40+
static constexpr LongIndex COMPO_PRONGS = ApexInfo::COMPO_PRONGS;
41+
static constexpr ShortIndex ORTHO_REGIONS = ApexInfo::ORTHO_REGIONS;
42+
static constexpr ShortIndex ORTHO_UNITS = ApexInfo::ORTHO_UNITS;
4043

41-
static constexpr LongIndex ACTIVE_BITS = ApexInfo::ACTIVE_BITS;
42-
static constexpr LongIndex RESUMABLE_BITS = ApexInfo::RESUMABLE_BITS;
44+
static constexpr LongIndex ACTIVE_BITS = ApexInfo::ACTIVE_BITS;
45+
static constexpr LongIndex RESUMABLE_BITS = ApexInfo::RESUMABLE_BITS;
4346

44-
static constexpr LongIndex STATE_COUNT = ApexInfo::STATE_COUNT;
45-
static constexpr LongIndex REGION_COUNT = ApexInfo::REGION_COUNT;
47+
static constexpr LongIndex STATE_COUNT = ApexInfo::STATE_COUNT;
48+
static constexpr LongIndex REGION_COUNT = ApexInfo::REGION_COUNT;
4649

4750
static_assert(STATE_COUNT < (ShortIndex) -1, "Too many states in the hierarchy. Change 'ShortIndex' type.");
4851
static_assert(STATE_COUNT == (ShortIndex) StateList::SIZE, "STATE_COUNT != StateList::SIZE");
@@ -57,9 +60,11 @@ class R_ {
5760
using MaterialApex = Material<I_<0, 0, 0, 0>, Args, Apex>;
5861

5962
using Control = ControlT<Args>;
60-
6163
using PlanControl = PlanControlT<Args>;
64+
65+
#ifdef HFSM2_ENABLE_PLANS
6266
using PlanData = PlanDataT <Args>;
67+
#endif
6368

6469
using FullControl = FullControlT<Args>;
6570
using Requests = typename FullControl::Requests;
@@ -454,7 +459,7 @@ class R_ {
454459
HFSM2_IF_UTILITY_THEORY(RNG& _rng);
455460

456461
Registry _registry;
457-
PlanData _planData;
462+
HFSM2_IF_PLANS(PlanData _planData);
458463

459464
Requests _requests;
460465

@@ -486,30 +491,34 @@ template <
486491
typename TRNG,
487492
#endif
488493
LongIndex NSubstitutionLimit,
494+
495+
#ifdef HFSM2_ENABLE_PLANS
489496
LongIndex NTaskCapacity,
497+
#endif
498+
490499
typename TApex>
491-
class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, TRNG,) NSubstitutionLimit, NTaskCapacity>, TApex> final
492-
: public R_<::hfsm2::ConfigT<::hfsm2::EmptyContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, TRNG,) NSubstitutionLimit, NTaskCapacity>, TApex>
500+
class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex> final
501+
: public R_<::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex>
493502
, ::hfsm2::EmptyContext
494503
{
495504
#ifdef HFSM2_ENABLE_UTILITY_THEORY
496505
using RNG = TRNG;
497506
#endif
498507

499508
using Context = ::hfsm2::EmptyContext;
500-
using Cfg = ::hfsm2::ConfigT<Context, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, RNG,) NSubstitutionLimit, NTaskCapacity>;
509+
using Cfg = ::hfsm2::ConfigT<Context HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, RNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>;
501510
using R = R_<Cfg, TApex>;
502511

503512
#ifdef HFSM2_ENABLE_LOG_INTERFACE
504-
using Logger = typename Cfg::Logger;
513+
using Logger = typename Cfg::LoggerInterface;
505514
#endif
506515

507516
public:
508517

509518
#ifdef HFSM2_ENABLE_UTILITY_THEORY
510519

511520
explicit HFSM2_INLINE RW_(RNG& rng
512-
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
521+
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
513522
: R{static_cast<Context&>(*this),
514523
rng
515524
HFSM2_IF_LOG_INTERFACE(, logger)}
@@ -533,30 +542,34 @@ template <typename TContext,
533542
typename TUtility,
534543
#endif
535544
LongIndex NSubstitutionLimit,
545+
546+
#ifdef HFSM2_ENABLE_PLANS
536547
LongIndex NTaskCapacity,
548+
#endif
549+
537550
typename TApex>
538-
class RW_ <::hfsm2::ConfigT<TContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, ::hfsm2::RandomT<TUtility>,) NSubstitutionLimit, NTaskCapacity>, TApex> final
539-
: public R_<::hfsm2::ConfigT<TContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, ::hfsm2::RandomT<TUtility>,) NSubstitutionLimit, NTaskCapacity>, TApex>
551+
class RW_ <::hfsm2::ConfigT<TContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, ::hfsm2::RandomT<TUtility>), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex> final
552+
: public R_<::hfsm2::ConfigT<TContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, ::hfsm2::RandomT<TUtility>), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex>
540553
HFSM2_IF_UTILITY_THEORY(, ::hfsm2::RandomT<TUtility>)
541554
{
542555
#ifdef HFSM2_ENABLE_UTILITY_THEORY
543556
using RNG = ::hfsm2::RandomT<TUtility>;
544557
#endif
545558

546559
using Context = TContext;
547-
using Cfg = ::hfsm2::ConfigT<Context, HFSM2_IF_UTILITY_THEORY(TRank, TUtility, RNG,) NSubstitutionLimit, NTaskCapacity>;
560+
using Cfg = ::hfsm2::ConfigT<Context HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, ::hfsm2::RandomT<TUtility>), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>;
548561
using R = R_<Cfg, TApex>;
549562

550563
#ifdef HFSM2_ENABLE_LOG_INTERFACE
551-
using Logger = typename Cfg::Logger;
564+
using Logger = typename Cfg::LoggerInterface;
552565
#endif
553566

554567

555568
public:
556569
#ifdef HFSM2_ENABLE_UTILITY_THEORY
557570

558571
explicit HFSM2_INLINE RW_(Context& context
559-
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
572+
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
560573
: R{context,
561574
static_cast<RNG&>(*this)
562575
HFSM2_IF_LOG_INTERFACE(, logger)}
@@ -566,7 +579,7 @@ class RW_ <::hfsm2::ConfigT<TContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility
566579
#else
567580

568581
explicit HFSM2_INLINE RW_(Context& context
569-
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
582+
HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr))
570583
: R{context
571584
HFSM2_IF_LOG_INTERFACE(, logger)}
572585
{}
@@ -581,20 +594,24 @@ class RW_ <::hfsm2::ConfigT<TContext, HFSM2_IF_UTILITY_THEORY(TRank, TUtility
581594
template <typename TRank,
582595
typename TUtility,
583596
LongIndex NSubstitutionLimit,
597+
598+
#ifdef HFSM2_ENABLE_PLANS
584599
LongIndex NTaskCapacity,
600+
#endif
601+
585602
typename TApex>
586-
class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT<TUtility>, NSubstitutionLimit, NTaskCapacity>, TApex> final
587-
: public R_<::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT<TUtility>, NSubstitutionLimit, NTaskCapacity>, TApex>
603+
class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT<TUtility>, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex> final
604+
: public R_<::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT<TUtility>, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>, TApex>
588605
, ::hfsm2::EmptyContext
589606
, ::hfsm2::RandomT<TUtility>
590607
{
591608
using Context = ::hfsm2::EmptyContext;
592609
using RNG = ::hfsm2::RandomT<TUtility>;
593-
using Cfg = ::hfsm2::ConfigT<Context, TRank, TUtility, RNG, NSubstitutionLimit, NTaskCapacity>;
610+
using Cfg = ::hfsm2::ConfigT<Context, TRank, TUtility, RNG, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity)>;
594611
using R = R_<Cfg, TApex>;
595612

596613
#ifdef HFSM2_ENABLE_LOG_INTERFACE
597-
using Logger = typename Cfg::Logger;
614+
using Logger = typename Cfg::LoggerInterface;
598615
#endif
599616

600617
public:

0 commit comments

Comments
 (0)