Skip to content

Commit 0c0ca7f

Browse files
Experimental (#21)
+ added payload versions of transition methods to root, control and plan ^ reworked transition history into previousTransitions(), currentTransitions(), requests()
1 parent 989e59b commit 0c0ca7f

File tree

87 files changed

+9742
-4059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+9742
-4059
lines changed

CMakeLists.txt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.5)
22

33
LIST(APPEND CMAKE_MODULE_PATH
44
"${CMAKE_CURRENT_SOURCE_DIR}/CMake/modules")
55

6-
set(CMAKE_CXX_STANDARD 11)
7-
set(CMAKE_CXX_EXTENSIONS OFF)
8-
96
set(SANITIZE_CXX_FLAGS "")
107
#set(SANITIZE_CXX_FLAGS "-fsanitize=address -g -O1 -fno-omit-frame-pointer")
118
#set(SANITIZE_CXX_FLAGS "-fsanitize=memory -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
129
#set(SANITIZE_CXX_FLAGS "-fsanitize=undefined")
1310

14-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_CXX_FLAGS} -pedantic -Werror")
15-
1611
project(hfsm2_test)
1712

18-
include_directories("${CMAKE_CURRENT_LIST_DIR}/external"
19-
"${CMAKE_CURRENT_LIST_DIR}/include")
20-
2113
file(GLOB SOURCE_FILES "test/*.cpp" "test/shared/*.cpp")
2214
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
2315

24-
add_test(NAME hfsm2_test COMMAND hfsm2_test)
16+
target_include_directories(${PROJECT_NAME} PRIVATE
17+
"${CMAKE_CURRENT_LIST_DIR}/external"
18+
"${CMAKE_CURRENT_LIST_DIR}/include")
19+
20+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
21+
22+
if(MSVC)
23+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
24+
else()
25+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
26+
endif()
27+
28+
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
2529

26-
add_custom_command(TARGET hfsm2_test
30+
add_custom_command(TARGET ${PROJECT_NAME}
2731
POST_BUILD
28-
COMMAND hfsm2_test)
32+
COMMAND ${PROJECT_NAME})
2933

3034
if ("x_${CMAKE_BUILD_TYPE}" STREQUAL "x_Coverage")
31-
set (TEST_PROJECT hfsm2_test)
35+
set (TEST_PROJECT ${PROJECT_NAME})
3236
include (coverage)
3337
endif ("x_${CMAKE_BUILD_TYPE}" STREQUAL "x_Coverage")

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ In-line comment-based docs is an on-going effort.
3131
- Convenient, minimal boilerplate
3232
- Fully static, no dynamic allocations
3333
- Uses inline-friendly compile-time pylymorphism, no virtual methods were harmed
34-
- Type-safe transitions: `FSM.changeTo<TargetState>()`
34+
- Type-safe transitions: `FSM.changeTo<TargetState>()` with optional payloads
3535
- 100% NoUML-compliant
3636
- [Hierarchical](https://github.com/andrew-gresyk/HFSM2/wiki/Transitions-within-Hierarchy), with a selection of composite (sub-machine) and orthogonal regions
3737
- Gamedev-friendly, supports explicit `State::update()`
3838
- Also supports traditional event-based workflow with `State::react()`
39-
- AI-friendly with [Dynamic planning](https://github.com/andrew-gresyk/HFSM2/wiki/Plans) support
40-
- [Utility theory](https://github.com/andrew-gresyk/HFSM2/wiki/Utility-Theory) support (both max score and ranked weighted random)
39+
- Inspect anything: previous and current transitions, state activation status, and more!
40+
- Game AI-friendly with [Dynamic planning](https://github.com/andrew-gresyk/HFSM2/wiki/Plans) support
41+
- [Utility theory](https://github.com/andrew-gresyk/HFSM2/wiki/Utility-Theory) support (max score and ranked weighted random)
4142
- Scaleable, supports robust state re-use via state injections
42-
- [Debug-assisted](https://gresyk.dev/features/2018/01/15/hfsm-magic.html), includes automatic structure and activity visualization API with `#define HFSM_ENABLE_STRUCTURE_REPORT`
4343
- [Serializable](https://doc.hfsm.dev/user-guide/debugging-and-tools/serialization), with activity and transition history support
44+
- [Debug-assisted](https://gresyk.dev/features/2018/01/15/hfsm-magic.html), includes automatic structure and activity visualization API with `#define HFSM_ENABLE_STRUCTURE_REPORT`
4445
- Built-in logging support
4546

4647
---
@@ -70,6 +71,7 @@ Please share your comments and suggestions on:
7071

7172
## Special Thanks
7273

74+
- [DJuego](https://github.com/DJuego)
7375
- [Kevin Greene](https://github.com/kgreenek)
7476
- [Kjeld Mathias Petersen](https://github.com/DonMathi)
7577
- Mehdi Houshmand
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(advanced_event_handling)
8-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../include")
9-
add_executable(${PROJECT_NAME} main.cpp)
4+
5+
file(GLOB SOURCE_FILES "*.cpp")
6+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
7+
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
10+
11+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
12+
13+
if(MSVC)
14+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
15+
else()
16+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
17+
endif()

examples/advanced_event_handling/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,6 @@ main() {
206206

207207
std::cout<< std::endl;
208208
return 0;
209-
};
209+
}
210210

211211
////////////////////////////////////////////////////////////////////////////////
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(basic_audio_player)
8-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../include")
9-
add_executable(${PROJECT_NAME} main.cpp)
4+
5+
file(GLOB SOURCE_FILES "*.cpp")
6+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
7+
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
10+
11+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
12+
13+
if(MSVC)
14+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
15+
else()
16+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
17+
endif()
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(basic_traffic_light)
8-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../include")
9-
add_executable(${PROJECT_NAME} main.cpp)
4+
5+
file(GLOB SOURCE_FILES "*.cpp")
6+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
7+
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
10+
11+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
12+
13+
if(MSVC)
14+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
15+
else()
16+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
17+
endif()

examples/calculator/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(calculator)
8-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../include")
9-
add_executable(${PROJECT_NAME} main.cpp)
4+
5+
file(GLOB SOURCE_FILES "*.cpp")
6+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
7+
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
10+
11+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
12+
13+
if(MSVC)
14+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
15+
else()
16+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
17+
endif()
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(debug_logger_interface)
8-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../include")
9-
add_executable(${PROJECT_NAME} main.cpp)
4+
5+
file(GLOB SOURCE_FILES "*.cpp")
6+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
7+
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
10+
11+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
12+
13+
if(MSVC)
14+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
15+
else()
16+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
17+
endif()

examples/snippets/CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_EXTENSIONS OFF)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
1+
cmake_minimum_required(VERSION 3.5)
62

73
project(snippets)
84

9-
include_directories("${CMAKE_CURRENT_LIST_DIR}/../../external"
10-
"${CMAKE_CURRENT_LIST_DIR}/../../include")
11-
125
file(GLOB SOURCE_FILES "*.cpp")
136
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
147

15-
add_test(NAME snippets COMMAND snippets)
8+
target_include_directories(${PROJECT_NAME} PRIVATE
9+
"${CMAKE_CURRENT_LIST_DIR}/../../external"
10+
"${CMAKE_CURRENT_LIST_DIR}/../../include")
11+
12+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
13+
14+
if(MSVC)
15+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
16+
else()
17+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic)
18+
endif()
19+
20+
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
1621

17-
add_custom_command(TARGET snippets
22+
add_custom_command(TARGET ${PROJECT_NAME}
1823
POST_BUILD
19-
COMMAND snippets)
24+
COMMAND ${PROJECT_NAME})

examples/snippets/wiki_plans.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <hfsm2/machine.hpp>
66

77
#include <catch2/catch.hpp>
8+
#undef assert
9+
#define assert(x) REQUIRE(x)
810

911
////////////////////////////////////////////////////////////////////////////////
1012

@@ -55,19 +57,19 @@ TEST_CASE("Wiki.Plans.Traffic Light", "[Wiki]") {
5557

5658
FSM::Instance fsm;
5759

58-
REQUIRE(fsm.isActive<Red>());
60+
assert(fsm.isActive<Red>());
5961

6062
fsm.update();
61-
REQUIRE(fsm.isActive<Yellow>());
63+
assert(fsm.isActive<Yellow>());
6264

6365
fsm.update();
64-
REQUIRE(fsm.isActive<Green>());
66+
assert(fsm.isActive<Green>());
6567

6668
fsm.update();
67-
REQUIRE(fsm.isActive<Yellow>());
69+
assert(fsm.isActive<Yellow>());
6870

6971
fsm.update();
70-
REQUIRE(fsm.isActive<Red>());
72+
assert(fsm.isActive<Red>());
7173
}
7274

7375
////////////////////////////////////////////////////////////////////////////////
@@ -183,13 +185,13 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") {
183185
// parametrized version of PlanControl::plan() allows access to plans
184186
// hosted by any region
185187
auto plan = control.plan<PlanOwner>();
186-
REQUIRE(plan);
188+
assert(plan);
187189

188190
// inspect the plan
189191
auto taskIterator = plan.first();
190-
REQUIRE(taskIterator);
191-
REQUIRE(taskIterator->origin == control.stateId<ReplanTask>());
192-
REQUIRE(taskIterator->destination == control.stateId<End>());
192+
assert(taskIterator);
193+
assert(taskIterator->origin == control.stateId<ReplanTask>());
194+
assert(taskIterator->destination == control.stateId<End>());
193195

194196
// loop over plan task sequence
195197
for (auto it = plan.first(); it; ++it) {
@@ -199,7 +201,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") {
199201
}
200202

201203
// when the plan is empty it is reported as 'invalid'
202-
REQUIRE(!plan);
204+
assert(!plan);
203205

204206
// plan can be explicitly cleared too
205207
plan.clear();
@@ -261,35 +263,35 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") {
261263

262264
FSM::Instance fsm;
263265

264-
REQUIRE(fsm.isActive<PlanOwner>());
265-
REQUIRE(fsm.isActive<StateTask>());
266+
assert(fsm.isActive<PlanOwner>());
267+
assert(fsm.isActive<StateTask>());
266268

267269
fsm.update();
268-
REQUIRE(fsm.isActive<CompositeTask>());
269-
REQUIRE(fsm.isActive<CT_Initial>());
270+
assert(fsm.isActive<CompositeTask>());
271+
assert(fsm.isActive<CT_Initial>());
270272

271273
fsm.update();
272-
REQUIRE(fsm.isActive<CompositeTask>());
273-
REQUIRE(fsm.isActive<CT_Following>());
274+
assert(fsm.isActive<CompositeTask>());
275+
assert(fsm.isActive<CT_Following>());
274276

275277
fsm.update();
276-
REQUIRE(fsm.isActive<OrthogonalTask>());
277-
REQUIRE(fsm.isActive<OT_1>());
278-
REQUIRE(fsm.isActive<OT_2>());
278+
assert(fsm.isActive<OrthogonalTask>());
279+
assert(fsm.isActive<OT_1>());
280+
assert(fsm.isActive<OT_2>());
279281

280282
fsm.update();
281-
REQUIRE(fsm.isActive<ReplanTask>());
283+
assert(fsm.isActive<ReplanTask>());
282284

283285
fsm.update();
284-
REQUIRE(fsm.isActive<SubPlanOwner>());
285-
REQUIRE(fsm.isActive<SubTask_2>());
286+
assert(fsm.isActive<SubPlanOwner>());
287+
assert(fsm.isActive<SubTask_2>());
286288

287289
fsm.update();
288-
REQUIRE(fsm.isActive<SubPlanOwner>());
289-
REQUIRE(fsm.isActive<SubTask_1>());
290+
assert(fsm.isActive<SubPlanOwner>());
291+
assert(fsm.isActive<SubTask_1>());
290292

291293
fsm.update();
292-
REQUIRE(fsm.isActive<End>());
294+
assert(fsm.isActive<End>());
293295
}
294296

295297
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)