%% a process for running an instance of the bt -module(bt_engine). -behaviour(gen_server). -include("./bt_node_behaviours/nodes.hrl"). -record(state, { bt :: any(), blackboard :: blackboard() }). -export([ %% api start_link/1, start_link/3, %% cb tick/2, init/1, handle_call/3, handle_cast/2 ]). %% API start_link({Tree, BB}) -> gen_server:start_link(?MODULE, [Tree, BB], []). start_link(RootFilePath, TreeName, Args) -> {Tree, BB} = parser:parse(RootFilePath, TreeName, Args), start_link({Tree, BB}). tick(Pid, Event) -> gen_server:call(Pid, Event). %% Callbacks init([Tree, BB]) -> {ok, #state{ bt = Tree, blackboard = BB } }. handle_call(Event, _From, #state{bt = Tree, blackboard = BB}) -> {Status, NewTree, NewBB} = runner:run(Tree, BB, Event), { reply, Status, #state{ bt = NewTree, blackboard = NewBB } }. %% not using handle_cast(_, State) -> {noreply, State}.