Skip to content

Commit

Permalink
Merge pull request #13 from hit9/dev
Browse files Browse the repository at this point in the history
0.4.0: separate cpp file
  • Loading branch information
hit9 committed Apr 29, 2024
2 parents ae47b2d + 15b64f3 commit d1c9c14
Show file tree
Hide file tree
Showing 15 changed files with 859 additions and 857 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20)

option(BT_TEST "Enables testing" OFF)

add_library(bt INTERFACE)
add_library(bt SHARED bt.cc)
set_target_properties(bt PROPERTIES PUBLIC_HEADER "bt.h")

if(BT_TEST)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# bt.h
# bt.cc

![](https://github.com/hit9/bt/actions/workflows/tests.yml/badge.svg)
![](https://img.shields.io/badge/license-BSD3-brightgreen)
Expand All @@ -15,7 +15,7 @@ Requires at least C++20.

## Installation

Just copy the header file `bt.h` and include it.
Copy away `bt.h` and `bt.cc`.

## Features

Expand Down Expand Up @@ -592,7 +592,7 @@ Reference: <span id="ref"></span>

* **Visualization** <span id="visualization"></span> <a href="#ref">[↑]</a>

There's a simple real time behavior tree visualization function implemented in `bt.h`.
There's a simple real time behavior tree visualization function implemented in `bt.cc`.
It simply displays the tree structure and execution status on the console.
The nodes colored in green are those currently executing and are synchronized with the latest tick cycles.
Expand Down Expand Up @@ -635,7 +635,7 @@ Reference: <span id="ref"></span>

* **Ticker Loop** <span id="ticker-loop"></span> <a href="#ref">[]</a>

There's a simple builtin ticker loop implemented in `bt.h`, to use it:
There's a simple builtin ticker loop implemented in `bt.cc`, to use it:

```cpp
root.TickForever(ctx, 100ms);
Expand Down Expand Up @@ -678,15 +678,15 @@ Reference: <span id="ref"></span>
It's a common case to emit and receive signals in a behavior tree.
But signal (or event) handling is a complex stuff, I don't want to couple with it in this small library.
General ideas to introduce signal handling into bt.h is:
General ideas to introduce signal handling into bt.cc is:
1. Creates a custom decorator node, supposed named `OnSignalNode`.
2. Creates a custom builder class, and add a method named `OnSignal`.
3. The `OnSignal` decorator propagates the tick down to its child only if the corresponding signal fired.
4. The data passing along with the fired signal, can be placed onto the blackboard temporary.
5. You can move the OnSignal node as high as possible to make the entire behavior tree more event-driven.
Here's an example in detail to combine my tiny signal library [blinker.h](https://github.com/hit9/blinker.h) with bt.h,
Here's an example in detail to combine my tiny signal library [blinker.h](https://github.com/hit9/blinker.h) with bt.cc,
please checkout the code example in folder [example/onsignal](example/onsignal).
```cpp
Expand Down
14 changes: 7 additions & 7 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# bt.h
# bt.cc

![](https://github.com/hit9/bt/actions/workflows/tests.yml/badge.svg)
![](https://img.shields.io/badge/license-BSD3-brightgreen)
Expand All @@ -13,7 +13,7 @@

## 安装

只需要拷贝走头文件 `bt.h`
只需要拷贝走 `bt.h``bt.cc`

## 特点

Expand Down Expand Up @@ -237,7 +237,7 @@ while(...) {
// 任何一个有实体状态的节点都应该定义一个类型成员, 叫做 Blob
using Blob = ANodeBlob;
// 需要重载这个方法, 返回一个指向基础类 NodeBlob 类型的指针
// getNodeBlob 是 bt.h 提供的方法, 定义在 `Node` 中
// getNodeBlob 是库提供的方法, 定义在 `Node` 中
NodeBlob* GetNodeBlob() const override { return getNodeBlob<ANodeBlob>(); }
// 在这个类的方法中,可以用 getNodeBlob<ANodeBlob>() 来获取数据块的指针, 来查询和修改实体相关的数据。
Expand Down Expand Up @@ -580,7 +580,7 @@ while(...) {

* **可视化** <span id="visualization"></span> <a href="#ref">[↑]</a>

`bt.h` 实现了一个简单的实时把行为树运行状态可视化展示的函数,绿色的节点表示正在被 tick 的节点。
`bt.cc` 实现了一个简单的实时把行为树运行状态可视化展示的函数,绿色的节点表示正在被 tick 的节点。

用法示例:

Expand Down Expand Up @@ -618,7 +618,7 @@ while(...) {

* **Tick 循环** <span id="ticker-loop"></span> <a href="#ref">[]</a>

`bt.h` 中内置了一个简单额 tick 主循环:
`bt.cc` 中内置了一个简单额 tick 主循环:

```cpp
root.TickForever(ctx, 100ms);
Expand Down Expand Up @@ -659,9 +659,9 @@ while(...) {
* **信号和事件** <span id="signals"></span> <a href="#ref">[↑]</a>
在行为树中释放和处理信号是常见的情况, 但是信号和事件的处理是一个复杂的事情, 我并不想让其和 bt.h 这个很小的库耦合起来.
在行为树中释放和处理信号是常见的情况, 但是信号和事件的处理是一个复杂的事情, 我并不想让其和 bt.cc 这个很小的库耦合起来.
一般来说, 要想把信号处理的带入 bt.h 中, 思路如下:
一般来说, 要想把信号处理的带入 bt.cc 中, 思路如下:
1. 创建一个自定义的装饰节点, 比如说叫做 `OnSignalNode`.
2. 创建一个自定义的 Builder 类, 添加一个方法叫做 `OnSignal`.
Expand Down
Loading

0 comments on commit d1c9c14

Please sign in to comment.