diff --git a/examples/action/action_add_rage.erl b/examples/action/action_add_rage.erl index d92e927..fafdc94 100644 --- a/examples/action/action_add_rage.erl +++ b/examples/action/action_add_rage.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_add_rage). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_become_attacking.erl b/examples/action/action_become_attacking.erl index f791afd..8fb7e46 100644 --- a/examples/action/action_become_attacking.erl +++ b/examples/action/action_become_attacking.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_become_attacking). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_become_idle.erl b/examples/action/action_become_idle.erl index 248eb16..4ebfd6d 100644 --- a/examples/action/action_become_idle.erl +++ b/examples/action/action_become_idle.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_become_idle). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_become_patrolling.erl b/examples/action/action_become_patrolling.erl index 949d3ac..b783f6c 100644 --- a/examples/action/action_become_patrolling.erl +++ b/examples/action/action_become_patrolling.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_become_patrolling). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_become_recovering.erl b/examples/action/action_become_recovering.erl index 25c9905..37f96f3 100644 --- a/examples/action/action_become_recovering.erl +++ b/examples/action/action_become_recovering.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_become_recovering). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_collect_dest_path.erl b/examples/action/action_collect_dest_path.erl index 703bac5..0a57349 100644 --- a/examples/action/action_collect_dest_path.erl +++ b/examples/action/action_collect_dest_path.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_collect_dest_path). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_collect_path.erl b/examples/action/action_collect_path.erl index 66bb702..de076c0 100644 --- a/examples/action/action_collect_path.erl +++ b/examples/action/action_collect_path.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_collect_path). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_collect_patrol.erl b/examples/action/action_collect_patrol.erl index efd27ce..c41875c 100644 --- a/examples/action/action_collect_patrol.erl +++ b/examples/action/action_collect_patrol.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_collect_patrol). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_cost_power.erl b/examples/action/action_cost_power.erl index a553978..4ad55bf 100644 --- a/examples/action/action_cost_power.erl +++ b/examples/action/action_cost_power.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_cost_power). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_cost_rage.erl b/examples/action/action_cost_rage.erl index 39e7004..a6909cc 100644 --- a/examples/action/action_cost_rage.erl +++ b/examples/action/action_cost_rage.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_cost_rage). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_del_dead_target.erl b/examples/action/action_del_dead_target.erl index 5476296..2c1b1d4 100644 --- a/examples/action/action_del_dead_target.erl +++ b/examples/action/action_del_dead_target.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_del_dead_target). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_died.erl b/examples/action/action_died.erl index 9b7c2be..477e2a5 100644 --- a/examples/action/action_died.erl +++ b/examples/action/action_died.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_died). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_finish.erl b/examples/action/action_finish.erl index 39942f4..f733667 100644 --- a/examples/action/action_finish.erl +++ b/examples/action/action_finish.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_finish). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_move_grid.erl b/examples/action/action_move_grid.erl index 37ff7d2..741e9b0 100644 --- a/examples/action/action_move_grid.erl +++ b/examples/action/action_move_grid.erl @@ -8,7 +8,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_move_grid). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_recover_power.erl b/examples/action/action_recover_power.erl index 94ccf5b..63fc923 100644 --- a/examples/action/action_recover_power.erl +++ b/examples/action/action_recover_power.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_recover_power). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/action/action_skill_attack.erl b/examples/action/action_skill_attack.erl index 9a8bd82..f2f9d2a 100644 --- a/examples/action/action_skill_attack.erl +++ b/examples/action/action_skill_attack.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(action_skill_attack). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_attacking.erl b/examples/condition/cond_is_attacking.erl index 97f4f4f..2063710 100644 --- a/examples/condition/cond_is_attacking.erl +++ b/examples/condition/cond_is_attacking.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(cond_is_attacking). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_dest.erl b/examples/condition/cond_is_dest.erl index ee47c44..3a1511d 100644 --- a/examples/condition/cond_is_dest.erl +++ b/examples/condition/cond_is_dest.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:18 %%%------------------------------------------------------------------- -module(cond_is_dest). --include("behavior3.hrl"). +-include("eBhv3.hrl"). %% API -export([tick/2]). diff --git a/examples/condition/cond_is_died.erl b/examples/condition/cond_is_died.erl index 7c9accb..b9f39f8 100644 --- a/examples/condition/cond_is_died.erl +++ b/examples/condition/cond_is_died.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:26 %%%------------------------------------------------------------------- -module(cond_is_died). --include("behavior3.hrl"). +-include("eBhv3.hrl"). %% API -export([tick/2]). diff --git a/examples/condition/cond_is_idle.erl b/examples/condition/cond_is_idle.erl index 22dc20e..3a196fc 100644 --- a/examples/condition/cond_is_idle.erl +++ b/examples/condition/cond_is_idle.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(cond_is_idle). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_patrolling.erl b/examples/condition/cond_is_patrolling.erl index 17d2654..205de66 100644 --- a/examples/condition/cond_is_patrolling.erl +++ b/examples/condition/cond_is_patrolling.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(cond_is_patrolling). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_power_full.erl b/examples/condition/cond_is_power_full.erl index da22419..af9c9e4 100644 --- a/examples/condition/cond_is_power_full.erl +++ b/examples/condition/cond_is_power_full.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(cond_is_power_full). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_rage_full.erl b/examples/condition/cond_is_rage_full.erl index 58b974a..7586f64 100644 --- a/examples/condition/cond_is_rage_full.erl +++ b/examples/condition/cond_is_rage_full.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:18 %%%------------------------------------------------------------------- -module(cond_is_rage_full). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_recovering.erl b/examples/condition/cond_is_recovering.erl index 50c07c8..57e813b 100644 --- a/examples/condition/cond_is_recovering.erl +++ b/examples/condition/cond_is_recovering.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:13 %%%------------------------------------------------------------------- -module(cond_is_recovering). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/examples/condition/cond_is_target_died.erl b/examples/condition/cond_is_target_died.erl index c634de9..e585eb4 100644 --- a/examples/condition/cond_is_target_died.erl +++ b/examples/condition/cond_is_target_died.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:20 %%%------------------------------------------------------------------- -module(cond_is_target_died). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API -export([tick/2]). diff --git a/examples/condition/cond_power_lt.erl b/examples/condition/cond_power_lt.erl index 3e2d19b..ac6b369 100644 --- a/examples/condition/cond_power_lt.erl +++ b/examples/condition/cond_power_lt.erl @@ -9,7 +9,7 @@ %%% Created : 07. 10月 2020 15:20 %%%------------------------------------------------------------------- -module(cond_power_lt). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API -export([tick/2]). diff --git a/examples/game_dict.erl b/examples/game_dict.erl index 68b52fe..c823007 100644 --- a/examples/game_dict.erl +++ b/examples/game_dict.erl @@ -8,7 +8,7 @@ %%%------------------------------------------------------------------- -module(game_dict). --include("behavior3.hrl"). +-include("eBhv3.hrl"). -include("example.hrl"). %% API diff --git a/include/behavior3.hrl b/include/eBhv3.hrl similarity index 86% rename from include/behavior3.hrl rename to include/eBhv3.hrl index 370a946..10b1e7d 100644 --- a/include/behavior3.hrl +++ b/include/eBhv3.hrl @@ -1,7 +1,17 @@ --ifndef(behavior3_h). --define(behavior3_h, true). +-ifndef(__eBhv3_H__). +-define(__eBhv3_H__, 1). --export_type([bt_uid/0, bt_status/0, bt_node_id/0, bt_state/0, properties/0, uninit_bt_node/0, tree_nodes/0, btree/0, bt_node/0]). +-export_type([ + bt_uid/0 + , bt_status/0 + , bt_node_id/0 + , bt_state/0 + , properties/0 + , uninit_bt_node/0 + , tree_nodes/0 + , btree/0 + , bt_node/0 +]). -type bt_uid() :: reference(). diff --git a/rebar.config b/rebar.config index aeeda93..804ac9f 100644 --- a/rebar.config +++ b/rebar.config @@ -3,7 +3,7 @@ ]}. {deps, [ - jsx + {jsx, {git, "https://github.com/happyshiyu/jsx.git"}} ]}. {xref_checks, [ diff --git a/src/action/error.erl b/src/action/error.erl index 3598921..73101dc 100644 --- a/src/action/error.erl +++ b/src/action/error.erl @@ -1,22 +1,10 @@ -module(error). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(_BTNode, BTState) -> {?BT_ERROR, BTState}. -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/action/failer.erl b/src/action/failer.erl index 6a6f3f2..ad555e3 100644 --- a/src/action/failer.erl +++ b/src/action/failer.erl @@ -1,22 +1,10 @@ -module(failer). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(_BTNode, BTState) -> {?BT_FAILURE, BTState}. -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/action/runner.erl b/src/action/runner.erl index c72c9f3..5801fc4 100644 --- a/src/action/runner.erl +++ b/src/action/runner.erl @@ -1,22 +1,10 @@ -module(runner). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(_BTNode, BTState) -> {?BT_RUNNING, BTState}. -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/action/succeeder.erl b/src/action/succeeder.erl index 1240809..efc8a3a 100644 --- a/src/action/succeeder.erl +++ b/src/action/succeeder.erl @@ -1,22 +1,9 @@ -module(succeeder). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(_BTNode, BTState) -> {?BT_SUCCESS, BTState}. - -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/action/wait.erl b/src/action/wait.erl index f36d0f2..7977764 100644 --- a/src/action/wait.erl +++ b/src/action/wait.erl @@ -1,13 +1,7 @@ -module(wait). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). %%-------------------------------------------------------------------- @@ -30,7 +24,3 @@ tick(#{id := ID, properties := #{milliseconds := EndTime}} = _BTNode, BTState) - -spec close(bt_node(), bt_state()) -> bt_state(). close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(start_time, ID, BTState). - -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/composite/mem_priority.erl b/src/composite/mem_priority.erl index 7e2e32f..2c2957a 100644 --- a/src/composite/mem_priority.erl +++ b/src/composite/mem_priority.erl @@ -1,18 +1,9 @@ -module(mem_priority). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID, children := Children} = _BTNode, BTState) -> blackboard:set(running_children, Children, ID, BTState). @@ -26,9 +17,6 @@ tick(#{id := ID} = _BTNode, BTState) -> close(#{id := ID} = _BTNode, State) -> blackboard:remove(running_children, ID, State). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1([ChildID | T] = Children, ID, BTState) -> case base_node:execute(ChildID, BTState) of {?BT_FAILURE, BTState1} -> diff --git a/src/composite/mem_sequence.erl b/src/composite/mem_sequence.erl index 0b548bb..21b4dd0 100644 --- a/src/composite/mem_sequence.erl +++ b/src/composite/mem_sequence.erl @@ -1,18 +1,9 @@ -module(mem_sequence). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID, children := Children} = _BTNode, BTState) -> blackboard:set(running_children, Children, ID, BTState). @@ -26,9 +17,6 @@ tick(#{id := ID} = _BTNode, BTState) -> close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(running_children, ID, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1([ChildID | T] = Children, ID, BTState) -> case base_node:execute(ChildID, BTState) of {?BT_SUCCESS, BTState1} -> diff --git a/src/composite/priority.erl b/src/composite/priority.erl index 5160b8e..ffdc650 100644 --- a/src/composite/priority.erl +++ b/src/composite/priority.erl @@ -1,25 +1,13 @@ -module(priority). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(#{children := Children} = _BTNode, BTState) -> tick_1(Children, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1([ChildID | T], BTState) -> case base_node:execute(ChildID, BTState) of {?BT_FAILURE, BTState1} -> diff --git a/src/composite/sequence.erl b/src/composite/sequence.erl index 8c47fb7..083ce80 100644 --- a/src/composite/sequence.erl +++ b/src/composite/sequence.erl @@ -1,25 +1,13 @@ -module(sequence). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(#{children := Children} = _BTNode, BTState) -> tick_1(Children, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1([ChildID | T], BTState) -> case base_node:execute(ChildID, BTState) of {?BT_SUCCESS, BTState1} -> diff --git a/src/core/base_node.erl b/src/core/base_node.erl index 868d7b1..5b5237e 100644 --- a/src/core/base_node.erl +++ b/src/core/base_node.erl @@ -1,19 +1,17 @@ -module(base_node). --compile([inline, {inline_size, 100}]). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-export([ + execute/2 +]). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- --export([execute/2]). - -%% Internal API --export([do_init/4, do_open/2, do_tick/2, do_close/2]). +-export([ + do_init/4 + , do_open/2 + , do_tick/2 + , do_close/2 +]). %% 节点初始化 -callback(init(bt_node()) -> bt_node()). @@ -29,9 +27,6 @@ -optional_callbacks([init/1, open/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- %% @doc 执行节点 -spec execute(bt_uid(), bt_state()) -> {bt_status(), bt_state()}. execute(NodeID, BTState) -> @@ -46,9 +41,6 @@ execute(NodeID, BTState) -> {BTStatus, BTState3} end. -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- %% 初始化行为树 -spec do_init(bt_uid()|undefined, bt_node_id(), #{bt_node_id() => btree()}, tree_nodes()) -> {ok, bt_uid()}|{error, term()}. do_init(ParentNodeID, BTNodeID, TreeMaps, TreeNodeMaps) -> diff --git a/src/core/behavior_tree.erl b/src/core/behavior_tree.erl index 47f6730..b0c856b 100644 --- a/src/core/behavior_tree.erl +++ b/src/core/behavior_tree.erl @@ -1,27 +1,15 @@ -module(behavior_tree). --compile([inline, {inline_size, 100}]). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). - -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([ load_tree_file/1, init_btree_by_title/4, init_btree/3, execute/2, execute_child/2, close_btree_node/2, unload_btree/1 ]). -%% Internal API -export([get_btree_id_by_title/2, get_btree/2, get_btree_node/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- %% @doc %% 载入行为树文件 -spec load_tree_file(file:name_all()) -> {#{string() => bt_node_id()}, #{bt_node_id() => btree()}, tree_nodes()}|{error, term()}. @@ -115,9 +103,6 @@ close_btree_node(NodeID, BTState) -> unload_btree(NodeID) -> do_unload_btree_node(NodeID). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- %% 解析行为树 -spec parse_btree(map()) -> {#{string() => bt_node_id()}, #{bt_node_id() => btree()}, tree_nodes()}. parse_btree(#{<<"trees">> := Trees}) -> diff --git a/src/core/blackboard.erl b/src/core/blackboard.erl index a8fe2bc..6bab61e 100644 --- a/src/core/blackboard.erl +++ b/src/core/blackboard.erl @@ -1,13 +1,7 @@ -module(blackboard). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([ get_btree_node/1, set_btree_node/1, erase_btree_node/1, set_global/3, set/4, diff --git a/src/decorator/inverter.erl b/src/decorator/inverter.erl index 2d88c10..ecb0a05 100644 --- a/src/decorator/inverter.erl +++ b/src/decorator/inverter.erl @@ -1,18 +1,9 @@ -module(inverter). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([tick/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}. tick(#{children := [ChildID]} = _BTNode, BTState) -> case base_node:execute(ChildID, BTState) of @@ -25,7 +16,3 @@ tick(#{children := [ChildID]} = _BTNode, BTState) -> end; tick(_BTNode, BTState) -> {?BT_ERROR, BTState}. - -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/decorator/limiter.erl b/src/decorator/limiter.erl index 3fa38ba..f337f02 100644 --- a/src/decorator/limiter.erl +++ b/src/decorator/limiter.erl @@ -1,18 +1,9 @@ -module(limiter). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID} = _BTNode, BTState) -> blackboard:set(i, 0, ID, BTState). @@ -37,7 +28,3 @@ tick(_BTNode, BTState) -> -spec close(bt_node(), bt_state()) -> bt_state(). close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(i, ID, BTState). - -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/decorator/max_time.erl b/src/decorator/max_time.erl index 9e36ff7..d3c4ff9 100644 --- a/src/decorator/max_time.erl +++ b/src/decorator/max_time.erl @@ -1,18 +1,9 @@ -module(max_time). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID} = _BTNode, BTState) -> blackboard:set(start_time, erlang:system_time(millisecond), ID, BTState). @@ -33,7 +24,3 @@ tick(_BTNode, BTState) -> -spec close(bt_node(), bt_state()) -> bt_state(). close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(start_time, ID, BTState). - -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- diff --git a/src/decorator/repeat_until_failure.erl b/src/decorator/repeat_until_failure.erl index 806822a..fbd6ba2 100644 --- a/src/decorator/repeat_until_failure.erl +++ b/src/decorator/repeat_until_failure.erl @@ -1,18 +1,9 @@ -module(repeat_until_failure). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID} = _BTNode, BTState) -> blackboard:set(i, 0, ID, BTState). @@ -30,9 +21,6 @@ tick(_BTNode, BTState) -> close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(i, ID, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1(MaxLoop, I, ChildID, _BTStatus, BTState) when MaxLoop < 0 orelse I < MaxLoop -> case base_node:execute(ChildID, BTState) of {?BT_SUCCESS, BTState1} -> diff --git a/src/decorator/repeat_until_success.erl b/src/decorator/repeat_until_success.erl index 857c883..b4e9241 100644 --- a/src/decorator/repeat_until_success.erl +++ b/src/decorator/repeat_until_success.erl @@ -1,19 +1,9 @@ -module(repeat_until_success). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). - -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID} = _BTNode, BTState) -> blackboard:set(i, 0, ID, BTState). @@ -31,9 +21,6 @@ tick(_BTNode, BTState) -> close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(i, ID, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1(MaxLoop, I, ChildID, _BTStatus, BTState) when MaxLoop < 0 orelse I < MaxLoop -> case base_node:execute(ChildID, BTState) of {?BT_FAILURE, BTBTState1} -> diff --git a/src/decorator/repeater.erl b/src/decorator/repeater.erl index 396638b..465a21d 100644 --- a/src/decorator/repeater.erl +++ b/src/decorator/repeater.erl @@ -1,18 +1,9 @@ -module(repeater). -%%-------------------------------------------------------------------- -%% include -%%-------------------------------------------------------------------- --include("behavior3.hrl"). +-include("eBhv3.hrl"). -%%-------------------------------------------------------------------- -%% export API -%%-------------------------------------------------------------------- -export([open/2, tick/2, close/2]). -%%-------------------------------------------------------------------- -%% API functions -%%-------------------------------------------------------------------- -spec open(bt_node(), bt_state()) -> bt_state(). open(#{id := ID} = _BTNode, BTState) -> blackboard:set(i, 0, ID, BTState). @@ -30,9 +21,6 @@ tick(_BTNode, BTState) -> close(#{id := ID} = _BTNode, BTState) -> blackboard:remove(i, ID, BTState). -%%-------------------------------------------------------------------- -%% Internal functions -%%-------------------------------------------------------------------- tick_1(MaxLoop, I, ChildID, _BTStatus, BTState) when MaxLoop < 0 orelse I < MaxLoop -> case base_node:execute(ChildID, BTState) of {BTStatus, BTState1} when BTStatus =:= ?BT_SUCCESS; BTStatus =:= ?BT_FAILURE ->