GithubHelp home page GithubHelp logo

behavior3erl's Introduction

中文

Erlang的行为树运行库,使用 behavior3editor 编辑生成行为树

快速开始

添加如下内容到rebar.config

{deps, [
   ...
   {behavior3, "2.0.1"}
]}.

编译

$ rebar3 compile

使用

Filename = "example.json",
BTTitle = <<"example_ai"/utf8>>, 
State = #{},
%% 执行这步后会产生大量垃圾,建议手动执行一次erlang:garbage_collect/0,1,2
TreeMod = behavior_tree:load_tree_file(Filename),
BB = blackboard:init_blackboard(TreeMod, BTTitle),
{_BTStatus, _BB1, _State1} = behavior_tree:execute(BB, State).

调试

添加{d,'BT_DEBUG'}rebar.config文件中,默认调试信息输出到控制台,可调用blackboard:set_io/2重定向日志输出位置

{erl_opts, [
    {d, 'BT_DEBUG'}
]}.
./rebar3 clean -a
./rebar3 compile

热更新行为树

行为树配置文件发生改变时,可调用behavior_tree:load_tree_file/1进行生成加载,并返回一个新的模块名供后续使用。

考虑到老的行为树模块会有已运行的行为树调用,自动清除可能会造成异常,老的行为树模块由使用者自行决定后续操作,可调用behavior_tree:unload_tree_mod/1清除。

一个DEMO

rogue_adventure

Behavior3使用系列文章:

里面的代码实例是1.0.0版本的,各位主要看看概念就好

(一)行为树应用之行为树简介

(二)行为树应用之组合节点

(三)行为树应用之装饰节点

(四)行为树应用之自定义节点

English

Erlang runtime library behavior tree, use behavior3editor to edit generated tree

Quickstart

add to rebar.config

{deps, [
   ...
   {behavior3erl, "2.0.1"}
]}.

Build

$ rebar3 compile

Usage

Filename = "example.json",
BTTitle = <<"example_ai"/utf8>>, 
State = #{},
%% This step generates a lot of garbage and a manual erlang:garbage_collect/0,1,2 is recommended
TreeMod = behavior_tree:load_tree_file(Filename), 
BB = blackboard:init_blackboard(TreeMod, BTTitle),
{_BTStatus, _BB1, _State1} = behavior_tree:execute(BB, State).

DEBUG

Add {d,'BT_DEBUG'} to rebar.config and default debug information is output to the console by calling blackboard:set_IO/2 to redirect the log output location

{erl_opts, [
    {d, 'BT_DEBUG'}
]}.
./rebar3 clean -a
./rebar3 compile

HotFix

When the behavior tree configuration file changes, call behavior_tree:load_tree_file/1 to load the configuration file and return a new module name for future use

Because the old behavior tree module has running behavior tree calls, automatic clearing may cause exceptions. Follow-up operations of the old behavior tree module are determined by users. You can call behavior_tree:unload_tree_mod/1 to clear the behavior tree module

behavior3erl's People

Contributors

0k-1 avatar dong50252409 avatar leigong996 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.