Skip to content

Commit 4d2b3fd

Browse files
2.9.0
`FSM::Instance::Structure` has entries for every (even headless) state
1 parent ad2488b commit 4d2b3fd

26 files changed

+373
-108
lines changed

development/hfsm2/detail/features/structure_report.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ namespace hfsm2 {
55
//------------------------------------------------------------------------------
66

77
struct StructureEntry final {
8+
HFSM2_CONSTEXPR(11)
9+
StructureEntry(const bool isActive_ = false,
10+
const wchar_t* const prefix_ = nullptr,
11+
const char * const name_ = nullptr) noexcept
12+
: isActive{isActive_}
13+
, prefix {prefix_ }
14+
, name {name_ }
15+
{}
16+
817
bool isActive;
918
const wchar_t* prefix;
10-
const char* name;
19+
const char * name;
1120
};
1221

1322
namespace detail {

development/hfsm2/detail/root_0.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ class R_ {
6666
using ReadStream = typename Args::ReadStream;
6767
#endif
6868

69-
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
70-
static constexpr Long NAME_COUNT = Apex::NAME_COUNT;
71-
#endif
72-
7369
public:
7470
using Info = WrapInfo<TApex>;
7571

@@ -561,11 +557,11 @@ class R_ {
561557

562558
/// @brief Array of 'StructureEntry' representing FSM structure
563559
/// @see HFSM2_ENABLE_STRUCTURE_REPORT
564-
using Structure = DynamicArrayT<StructureEntry, NAME_COUNT>;
560+
using Structure = StaticArrayT<StructureEntry, STATE_COUNT>;
565561

566562
/// @brief Array of 'int8_t' representing FSM activation history (negative - 'update()' cycles since deactivated, positive - 'update()' cycles since activated)
567563
/// @see `HFSM2_ENABLE_STRUCTURE_REPORT`
568-
using ActivityHistory = DynamicArrayT<int8_t, NAME_COUNT>;
564+
using ActivityHistory = StaticArrayT<int8_t, STATE_COUNT>;
569565

570566
/// @brief Get the array of `StructureEntry` representing FSM structure
571567
/// @return FSM structure
@@ -677,7 +673,6 @@ class R_ {
677673
HFSM2_CONSTEXPR(14) void udpateActivity() noexcept;
678674

679675
Prefixes _prefixes;
680-
NamedStates _namedStates;
681676

682677
Structure _structure;
683678
ActivityHistory _activityHistory;

development/hfsm2/detail/root_0.inl

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,6 @@ R_<TG_, TA_>::getStateNames() noexcept {
767767
const StructureStateInfo& stateInfo = stateInfos[s];
768768
Prefix& prefix = _prefixes[s];
769769

770-
if (stateInfo.name[0] != '\0')
771-
_namedStates.set(s);
772-
773770
if (margin > stateInfo.depth && stateInfo.name[0] != '\0')
774771
margin = stateInfo.depth;
775772

@@ -805,16 +802,17 @@ R_<TG_, TA_>::getStateNames() noexcept {
805802
if (margin > 0)
806803
margin -= 1;
807804

808-
_structure.clear();
809805
for (Long s = 0; s < stateInfos.count(); ++s) {
810806
const StructureStateInfo& stateInfo = stateInfos[s];
811807
Prefix& prefix = _prefixes[s];
812808
const Long space = stateInfo.depth * 2;
813809

814810
if (stateInfo.name[0] != L'\0') {
815-
_structure.emplace(StructureEntry{false, &prefix[margin * 2], stateInfo.name});
816-
_activityHistory.emplace(static_cast<int8_t>(0));
817-
} else if (s + 1 < stateInfos.count()) {
811+
_structure[s] = StructureEntry{false, &prefix[margin * 2], stateInfo.name};
812+
_activityHistory[s] = static_cast<int8_t>(0);
813+
}
814+
else
815+
if (s + 1 < stateInfos.count()) {
818816
Prefix& nextPrefix = _prefixes[s + 1];
819817

820818
if (s > 0)
@@ -841,26 +839,25 @@ template <typename TG_, typename TA_>
841839
HFSM2_CONSTEXPR(14)
842840
void
843841
R_<TG_, TA_>::udpateActivity() noexcept {
844-
for (Long s = 0, i = 0; s < STATE_COUNT; ++s)
845-
if (_namedStates.get(s)) {
846-
_structure[i].isActive = isActive(s);
847-
848-
typename ActivityHistory::Item& activity = _activityHistory[i];
849-
850-
if (_structure[i].isActive) {
851-
if (activity < 0)
852-
activity = +1;
853-
else
854-
activity = activity < INT8_MAX ? activity + 1 : activity;
855-
} else {
856-
if (activity > 0)
857-
activity = -1;
858-
else
859-
activity = activity > INT8_MIN ? activity - 1 : activity;
860-
}
861-
862-
++i;
842+
for (Long s = 0, i = 0; s < STATE_COUNT; ++s) {
843+
_structure[i].isActive = isActive(s);
844+
845+
typename ActivityHistory::Item& activity = _activityHistory[i];
846+
847+
if (_structure[i].isActive) {
848+
if (activity < 0)
849+
activity = +1;
850+
else
851+
activity = activity < INT8_MAX ? activity + 1 : activity;
852+
} else {
853+
if (activity > 0)
854+
activity = -1;
855+
else
856+
activity = activity > INT8_MIN ? activity - 1 : activity;
863857
}
858+
859+
++i;
860+
}
864861
}
865862

866863
#endif

development/hfsm2/detail/structure/composite.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ struct HFSM2_EMPTY_BASES C_
292292
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
293293
using StructureStateInfos = typename Args::StructureStateInfos;
294294

295-
static constexpr Long NAME_COUNT = HeadState::NAME_COUNT + SubStates::NAME_COUNT;
296-
297295
HFSM2_CONSTEXPR(14) void deepGetNames(const Long parent,
298296
const RegionType region,
299297
const Short depth,

development/hfsm2/detail/structure/composite_sub_1.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ struct HFSM2_EMPTY_BASES CS_<
181181
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
182182
using StructureStateInfos = typename Args::StructureStateInfos;
183183

184-
static constexpr Long NAME_COUNT = LHalf::NAME_COUNT + RHalf::NAME_COUNT;
185-
186184
HFSM2_CONSTEXPR(14) void wideGetNames(const Long parent,
187185
const RegionType region,
188186
const Short depth,

development/hfsm2/detail/structure/composite_sub_2.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ struct HFSM2_EMPTY_BASES CS_<
153153
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
154154
using StructureStateInfos = typename Args::StructureStateInfos;
155155

156-
static constexpr Long NAME_COUNT = Single::NAME_COUNT;
157-
158156
HFSM2_CONSTEXPR(14) void wideGetNames(const Long parent,
159157
const RegionType region,
160158
const Short depth,

development/hfsm2/detail/structure/orthogonal.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ struct HFSM2_EMPTY_BASES O_
190190
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
191191
using StructureStateInfos = typename Args::StructureStateInfos;
192192

193-
static constexpr Long NAME_COUNT = HeadState::NAME_COUNT + SubStates::NAME_COUNT;
194-
195193
HFSM2_CONSTEXPR(14) void deepGetNames(const Long parent,
196194
const RegionType region,
197195
const Short depth,

development/hfsm2/detail/structure/orthogonal_sub_1.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ struct HFSM2_EMPTY_BASES OS_<
170170
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
171171
using StructureStateInfos = typename Args::StructureStateInfos;
172172

173-
static constexpr Long NAME_COUNT = Initial::NAME_COUNT + Remaining::NAME_COUNT;
174-
175173
HFSM2_CONSTEXPR(14) void wideGetNames(const Long parent,
176174
const Short depth,
177175
StructureStateInfos& stateInfos) const noexcept;

development/hfsm2/detail/structure/orthogonal_sub_2.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ struct HFSM2_EMPTY_BASES OS_<
138138
#if HFSM2_STRUCTURE_REPORT_AVAILABLE()
139139
using StructureStateInfos = typename Args::StructureStateInfos;
140140

141-
static constexpr Long NAME_COUNT = Initial::NAME_COUNT;
142-
143141
HFSM2_CONSTEXPR(14) void wideGetNames(const Long parent,
144142
const Short depth,
145143
StructureStateInfos& stateInfos) const noexcept;

development/hfsm2/detail/structure/state_1.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ struct HFSM2_EMPTY_BASES S_
157157

158158
HFSM2_IF_TYPEINDEX(const std::type_index TYPE = typeid(Head));
159159

160-
static constexpr Long NAME_COUNT = 1;
161-
162160
#endif
163161

164162
#if HFSM2_LOG_INTERFACE_AVAILABLE()

0 commit comments

Comments
 (0)