Skip to content

Commit 5b38241

Browse files
committed
* fixed multiple peer regions bug
1 parent ed1a9ef commit 5b38241

26 files changed

+2043
-2094
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Header-only heriarchical FSM framework in C++14, with fully statically-defined s
1818
## Documentation
1919

2020
[Old Wiki](https://github.com/andrew-gresyk/HFSM2/wiki/Tutorial) docs are being upgraded and moved to the [New GitBook](https://doc.hfsm.dev/).
21+
2122
In-line comment-based docs is an on-going effort.
2223

2324
---

include/hfsm2/detail/debug/shared.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ static inline
100100
const char*
101101
transitionName(const TransitionType transitionType) {
102102
switch (transitionType) {
103-
case TransitionType::CHANGE: return "changeTo";
104-
case TransitionType::RESTART: return "restart";
105-
case TransitionType::RESUME: return "resume";
106-
case TransitionType::UTILIZE: return "utilize";
107-
case TransitionType::RANDOMIZE: return "randomize";
108-
case TransitionType::SCHEDULE: return "schedule";
103+
case TransitionType::CHANGE: return "changeTo";
104+
case TransitionType::RESTART: return "restart";
105+
case TransitionType::RESUME: return "resume";
106+
case TransitionType::UTILIZE: return "utilize";
107+
case TransitionType::RANDOMIZE: return "randomize";
108+
case TransitionType::SCHEDULE: return "schedule";
109109

110110
default:
111111
HFSM_BREAK();

include/hfsm2/detail/root.inl

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ namespace detail {
33

44
////////////////////////////////////////////////////////////////////////////////
55

6-
template <typename TG_, typename TA_>
7-
R_<TG_, TA_>::R_(Context& context,
8-
RNG& rng
9-
HFSM_IF_LOGGER(, Logger* const logger))
6+
template <typename TG, typename TA>
7+
R_<TG, TA>::R_(Context& context,
8+
RNG& rng
9+
HFSM_IF_LOGGER(, Logger* const logger))
1010
: _context{context}
1111
, _rng{rng}
1212
HFSM_IF_LOGGER(, _logger{logger})
@@ -20,8 +20,8 @@ R_<TG_, TA_>::R_(Context& context,
2020

2121
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2222

23-
template <typename TG_, typename TA_>
24-
R_<TG_, TA_>::~R_() {
23+
template <typename TG, typename TA>
24+
R_<TG, TA>::~R_() {
2525
PlanControl control{_context,
2626
_rng,
2727
_registry,
@@ -36,15 +36,16 @@ R_<TG_, TA_>::~R_() {
3636

3737
//------------------------------------------------------------------------------
3838

39-
template <typename TG_, typename TA_>
39+
template <typename TG, typename TA>
4040
void
41-
R_<TG_, TA_>::update() {
41+
R_<TG, TA>::update() {
4242
FullControl control(_context,
4343
_rng,
4444
_registry,
4545
_planData,
4646
_requests,
4747
HFSM_LOGGER_OR(_logger, nullptr));
48+
4849
_apex.deepUpdate(control);
4950

5051
HFSM_IF_ASSERT(_planData.verifyPlans());
@@ -57,16 +58,17 @@ R_<TG_, TA_>::update() {
5758

5859
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5960

60-
template <typename TG_, typename TA_>
61+
template <typename TG, typename TA>
6162
template <typename TEvent>
6263
void
63-
R_<TG_, TA_>::react(const TEvent& event) {
64+
R_<TG, TA>::react(const TEvent& event) {
6465
FullControl control{_context,
6566
_rng,
6667
_registry,
6768
_planData,
6869
_requests,
6970
HFSM_LOGGER_OR(_logger, nullptr)};
71+
7072
_apex.deepReact(control, event);
7173

7274
HFSM_IF_ASSERT(_planData.verifyPlans());
@@ -79,59 +81,59 @@ R_<TG_, TA_>::react(const TEvent& event) {
7981

8082
//------------------------------------------------------------------------------
8183

82-
template <typename TG_, typename TA_>
84+
template <typename TG, typename TA>
8385
void
84-
R_<TG_, TA_>::changeTo(const StateID stateId) {
86+
R_<TG, TA>::changeTo(const StateID stateId) {
8587
_requests.append(Request{Request::Type::CHANGE, stateId});
8688

8789
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::CHANGE, stateId);
8890
}
8991

9092
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9193

92-
template <typename TG_, typename TA_>
94+
template <typename TG, typename TA>
9395
void
94-
R_<TG_, TA_>::restart(const StateID stateId) {
96+
R_<TG, TA>::restart(const StateID stateId) {
9597
_requests.append(Request{Request::Type::RESTART, stateId});
9698

9799
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESTART, stateId);
98100
}
99101

100102
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101103

102-
template <typename TG_, typename TA_>
104+
template <typename TG, typename TA>
103105
void
104-
R_<TG_, TA_>::resume(const StateID stateId) {
106+
R_<TG, TA>::resume(const StateID stateId) {
105107
_requests.append(Request{Request::Type::RESUME, stateId});
106108

107109
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESUME, stateId);
108110
}
109111

110112
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111113

112-
template <typename TG_, typename TA_>
114+
template <typename TG, typename TA>
113115
void
114-
R_<TG_, TA_>::utilize(const StateID stateId) {
116+
R_<TG, TA>::utilize(const StateID stateId) {
115117
_requests.append(Request{Request::Type::UTILIZE, stateId});
116118

117119
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::UTILIZE, stateId);
118120
}
119121

120122
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121123

122-
template <typename TG_, typename TA_>
124+
template <typename TG, typename TA>
123125
void
124-
R_<TG_, TA_>::randomize(const StateID stateId) {
126+
R_<TG, TA>::randomize(const StateID stateId) {
125127
_requests.append(Request{Request::Type::RANDOMIZE, stateId});
126128

127129
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RANDOMIZE, stateId);
128130
}
129131

130132
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131133

132-
template <typename TG_, typename TA_>
134+
template <typename TG, typename TA>
133135
void
134-
R_<TG_, TA_>::schedule(const StateID stateId) {
136+
R_<TG, TA>::schedule(const StateID stateId) {
135137
_requests.append(Request{Request::Type::SCHEDULE, stateId});
136138

137139
HFSM_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::SCHEDULE, stateId);
@@ -141,10 +143,10 @@ R_<TG_, TA_>::schedule(const StateID stateId) {
141143

142144
#ifdef HFSM_ENABLE_TRANSITION_HISTORY
143145

144-
template <typename TG_, typename TA_>
146+
template <typename TG, typename TA>
145147
void
146-
R_<TG_, TA_>::replayTransitions(const Transition* const transitions,
147-
const uint64_t count)
148+
R_<TG, TA>::replayTransitions(const Transition* const transitions,
149+
const uint64_t count)
148150
{
149151
if (HFSM_CHECKED(transitions && count)) {
150152
HFSM_IF_TRANSITION_HISTORY(_transitionHistory.clear());
@@ -171,9 +173,9 @@ R_<TG_, TA_>::replayTransitions(const Transition* const transitions,
171173

172174
//------------------------------------------------------------------------------
173175

174-
template <typename TG_, typename TA_>
176+
template <typename TG, typename TA>
175177
void
176-
R_<TG_, TA_>::reset() {
178+
R_<TG, TA>::reset() {
177179
PlanControl control{_context,
178180
_rng,
179181
_registry,
@@ -194,19 +196,19 @@ R_<TG_, TA_>::reset() {
194196

195197
#ifdef HFSM_ENABLE_SERIALIZATION
196198

197-
template <typename TG_, typename TA_>
199+
template <typename TG, typename TA>
198200
void
199-
R_<TG_, TA_>::save(SerialBuffer& _buffer) const {
201+
R_<TG, TA>::save(SerialBuffer& _buffer) const {
200202
WriteStream stream{_buffer};
201203

202204
_apex.deepSaveActive(_registry, stream);
203205
}
204206

205207
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206208

207-
template <typename TG_, typename TA_>
209+
template <typename TG, typename TA>
208210
void
209-
R_<TG_, TA_>::load(const SerialBuffer& buffer) {
211+
R_<TG, TA>::load(const SerialBuffer& buffer) {
210212
PlanControl control{_context,
211213
_rng,
212214
_registry,
@@ -227,9 +229,9 @@ R_<TG_, TA_>::load(const SerialBuffer& buffer) {
227229

228230
//------------------------------------------------------------------------------
229231

230-
template <typename TG_, typename TA_>
232+
template <typename TG, typename TA>
231233
void
232-
R_<TG_, TA_>::initialEnter() {
234+
R_<TG, TA>::initialEnter() {
233235
HFSM_ASSERT(_requests.count() == 0);
234236
HFSM_IF_TRANSITION_HISTORY(HFSM_ASSERT(_transitionHistory.count() == 0));
235237

@@ -280,9 +282,9 @@ R_<TG_, TA_>::initialEnter() {
280282

281283
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282284

283-
template <typename TG_, typename TA_>
285+
template <typename TG, typename TA>
284286
void
285-
R_<TG_, TA_>::processTransitions() {
287+
R_<TG, TA>::processTransitions() {
286288
HFSM_ASSERT(_requests.count());
287289

288290
HFSM_IF_TRANSITION_HISTORY(_transitionHistory.clear());
@@ -333,9 +335,11 @@ R_<TG_, TA_>::processTransitions() {
333335

334336
//------------------------------------------------------------------------------
335337

336-
template <typename TG_, typename TA_>
338+
template <typename TG, typename TA>
337339
bool
338-
R_<TG_, TA_>::applyRequest(Control& control, const Request& request) {
340+
R_<TG, TA>::applyRequest(Control& control,
341+
const Request& request)
342+
{
339343
HFSM_IF_TRANSITION_HISTORY(_transitionHistory.append(Transition{request, Method::NONE}));
340344

341345
switch (request.type) {
@@ -365,9 +369,9 @@ R_<TG_, TA_>::applyRequest(Control& control, const Request& request) {
365369

366370
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
367371

368-
template <typename TG_, typename TA_>
372+
template <typename TG, typename TA>
369373
bool
370-
R_<TG_, TA_>::applyRequests(Control& control) {
374+
R_<TG, TA>::applyRequests(Control& control) {
371375
bool changesMade = false;
372376

373377
for (const Request& request : _requests)
@@ -380,11 +384,11 @@ R_<TG_, TA_>::applyRequests(Control& control) {
380384

381385
#ifdef HFSM_ENABLE_TRANSITION_HISTORY
382386

383-
template <typename TG_, typename TA_>
387+
template <typename TG, typename TA>
384388
bool
385-
R_<TG_, TA_>::applyRequests(Control& control,
386-
const Transition* const transitions,
387-
const uint64_t count)
389+
R_<TG, TA>::applyRequests(Control& control,
390+
const Transition* const transitions,
391+
const uint64_t count)
388392
{
389393
if (HFSM_CHECKED(transitions && count)) {
390394
bool changesMade = false;
@@ -401,16 +405,16 @@ R_<TG_, TA_>::applyRequests(Control& control,
401405

402406
//------------------------------------------------------------------------------
403407

404-
template <typename TG_, typename TA_>
408+
template <typename TG, typename TA>
405409
bool
406-
R_<TG_, TA_>::cancelledByEntryGuards(const Requests& pendingRequests) {
410+
R_<TG, TA>::cancelledByEntryGuards(const Requests& pendingRequests) {
407411
GuardControl guardControl{_context,
408412
_rng,
409413
_registry,
410414
_planData,
411415
_requests,
412416
pendingRequests,
413-
HFSM_LOGGER_OR(_logger, nullptr)};
417+
HFSM_LOGGER_OR(_logger, nullptr)};
414418

415419
if (_apex.deepEntryGuard(guardControl)) {
416420
HFSM_IF_TRANSITION_HISTORY(recordRequestsAs(Method::ENTRY_GUARD));
@@ -422,9 +426,9 @@ R_<TG_, TA_>::cancelledByEntryGuards(const Requests& pendingRequests) {
422426

423427
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
424428

425-
template <typename TG_, typename TA_>
429+
template <typename TG, typename TA>
426430
bool
427-
R_<TG_, TA_>::cancelledByGuards(const Requests& pendingRequests) {
431+
R_<TG, TA>::cancelledByGuards(const Requests& pendingRequests) {
428432
GuardControl guardControl{_context,
429433
_rng,
430434
_registry,
@@ -449,9 +453,9 @@ R_<TG_, TA_>::cancelledByGuards(const Requests& pendingRequests) {
449453

450454
#ifdef HFSM_ENABLE_STRUCTURE_REPORT
451455

452-
template <typename TG_, typename TA_>
456+
template <typename TG, typename TA>
453457
void
454-
R_<TG_, TA_>::getStateNames() {
458+
R_<TG, TA>::getStateNames() {
455459
_stateInfos.clear();
456460
_apex.deepGetNames((LongIndex) -1, StructureStateInfo::COMPOSITE, 0, _stateInfos);
457461

@@ -527,9 +531,9 @@ R_<TG_, TA_>::getStateNames() {
527531

528532
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
529533

530-
template <typename TG_, typename TA_>
534+
template <typename TG, typename TA>
531535
void
532-
R_<TG_, TA_>::udpateActivity() {
536+
R_<TG, TA>::udpateActivity() {
533537
for (LongIndex s = 0, i = 0; s < _stateInfos.count(); ++s)
534538
if (_stateInfos[s].name[0] != L'\0') {
535539
_structure[i].isActive = isActive(s);
@@ -558,9 +562,9 @@ R_<TG_, TA_>::udpateActivity() {
558562

559563
#ifdef HFSM_ENABLE_TRANSITION_HISTORY
560564

561-
template <typename TG_, typename TA_>
565+
template <typename TG, typename TA>
562566
void
563-
R_<TG_, TA_>::recordRequestsAs(const Method method) {
567+
R_<TG, TA>::recordRequestsAs(const Method method) {
564568
for (const auto& request : _requests)
565569
_transitionHistory.append(Transition{request, method});
566570
}

include/hfsm2/detail/root/plan_data.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace detail {
55

66
#ifdef HFSM_ENABLE_ASSERT
77

8-
template <typename TC_, typename TG_, typename TSL_, typename TRL_, LongIndex NCC_, LongIndex NOC_, LongIndex NOU_, LongIndex NSB_, LongIndex NTC_>
8+
template <typename TC, typename TG, typename TSL, typename TRL, LongIndex NCC, LongIndex NOC, LongIndex NOU, LongIndex NSB, LongIndex NTC>
99
void
10-
PlanDataT<ArgsT<TC_, TG_, TSL_, TRL_, NCC_, NOC_, NOU_, NSB_, NTC_>>::verifyPlans() const {
10+
PlanDataT<ArgsT<TC, TG, TSL, TRL, NCC, NOC, NOU, NSB, NTC>>::verifyPlans() const {
1111
LongIndex planCount = 0;
1212
for (RegionID id = 0; id < REGION_COUNT; ++id)
1313
planCount += verifyPlan(id);
@@ -17,9 +17,9 @@ PlanDataT<ArgsT<TC_, TG_, TSL_, TRL_, NCC_, NOC_, NOU_, NSB_, NTC_>>::verifyPlan
1717

1818
//------------------------------------------------------------------------------
1919

20-
template <typename TC_, typename TG_, typename TSL_, typename TRL_, LongIndex NCC_, LongIndex NOC_, LongIndex NOU_, LongIndex NSB_, LongIndex NTC_>
20+
template <typename TC, typename TG, typename TSL, typename TRL, LongIndex NCC, LongIndex NOC, LongIndex NOU, LongIndex NSB, LongIndex NTC>
2121
LongIndex
22-
PlanDataT<ArgsT<TC_, TG_, TSL_, TRL_, NCC_, NOC_, NOU_, NSB_, NTC_>>::verifyPlan(const RegionID regionId) const {
22+
PlanDataT<ArgsT<TC, TG, TSL, TRL, NCC, NOC, NOU, NSB, NTC>>::verifyPlan(const RegionID regionId) const {
2323
LongIndex length = 0;
2424
const Bounds& bounds = tasksBounds[regionId];
2525

0 commit comments

Comments
 (0)