NodeTree
NodeTree is a framework to create large scalable programs and games through a tree of processes. Each process is fully autonomous and is capable of storing its own state or data, and communicating with other processes. These processes are known as Nodes.
⚠️WARNING⚠️ This crate is in early development. Beware of possible bugs or safety violations.
Getting Started!
Simply either run cargo add node_tree at the terminal directed towards the directory of your project, or add node_tree = X.X to your cargo.toml file.
To begin creating a program in Rust that utilizes a NodeTree, we must first create a root Node. In order to reduce boilerplate, we will use the included NodeSys derive macro to implement the required Dynamic and NodeAbstract traits. We will then implement the Node trait ourselves.
use *;
// Nodes require `Debug` and `Clone`.
// Example implementation of the Node trait with custom behaviours.
Finally, in order to activate our NodeTree, we must instance the root Node and feed it into the NodeTree constructor.
// ...previous implementations
use TreeSimple;
Node Scenes
You may also input a NodeScene when initializing a NodeTree or adding a child via add_child:
use *;
let scene: NodeScene = scene! ;
// Scenes can also be cloned, stored, and reused.
let _ = scene.clone;
Logging
Logging is also supported. Here is an example setup with an output of a few warnings and a crash. Note that the crash header/footer are customizable, and that the output is actually colored in a real terminal.
/// Root Node
<22/04/2024 17:25:46 UTC> | [Root/1_Node/2_Node/3_Node2] | WARN | Simulating warning!
<22/04/2024 17:25:46 UTC> | [Root/1_Node/2_Node1/3_Node2] | WARN | Simulating warning!
<22/04/2024 17:25:46 UTC> | [Root/1_Node/2_Node2/3_Node2] | WARN | Simulating warning!
<22/04/2024 17:25:46 UTC> | [Root/1_Node2/2_Node/3_Node2] | PANIC! | Simulating panic!
Unfortunately the program has crashed. Please contact the development team with the following crash report as well as the attachment of the log posted during the time of the crash.
[REPORT START]
Root
├── 1_Node
│ ├── 2_Node
│ │ ├── 3_Node
│ │ ├── 3_Node1
│ │ └── 3_Node2
│ ├── 2_Node1
│ │ ├── 3_Node
│ │ ├── 3_Node1
│ │ └── 3_Node2
│ └── 2_Node2
│ ├── 3_Node
│ ├── 3_Node1
│ └── 3_Node2
├── 1_Node1
│ ├── 2_Node
│ │ ├── 3_Node
│ │ ├── 3_Node1
│ │ └── 3_Node2
│ ├── 2_Node1
│ │ ├── 3_Node
│ │ ├── 3_Node1
│ │ └── 3_Node2
│ └── 2_Node2
│ ├── 3_Node
│ ├── 3_Node1
│ └── 3_Node2
└── 1_Node2
├── 2_Node
│ ├── 3_Node
│ ├── 3_Node1
│ └── 3_Node2
├── 2_Node1
│ ├── 3_Node
│ ├── 3_Node1
│ └── 3_Node2
└── 2_Node2
├── 3_Node
├── 3_Node1
└── 3_Node2
[Same-Frame Warnings]
3_Node2 - Simulating warning!
3_Node2 - Simulating warning!
3_Node2 - Simulating warning!
[Same-Frame Panics]
3_Node2 - Simulating panic!
[REPORT END]
Time of Crash: 22/04/2024 17:25:46
Exit Code: 1
Goodbye World! (Program Exited)
About Cloning
All nodes are expected to implement the Clone trait since there are a few implementations that depend on it, such as NodeScene. However, it is possible to mark a field of a node so that it either has a special clone attribute or is uncloneable via provided types by this crate:
use ; // All of these types implement Deref & DerefMut!
Features
- 🏗️ An easy abstraction framework for different processes to communicate and interact with each other in a scalable manner. Inspired by Godot!
- ⏯️ The ability to
pause()andunpause()theNodeTree, and fine tune individualNodebehaviours for when a tree is paused/unpaused. - 📡 Various methods to communicate with other nodes, such as
owner(),parent(),get_child(),children(), andget_node(). - 🔗 An abstracted smart pointer known as
Tp<T>andTpDynwhich clones implicitly to reduce syntax noise and allows for low boilerplate. - 📚 A caching system hosted on the
NodeTreeto act as a safe interface to ensureTp<T>/TpDynsoundness, and increase performance! - 👪 The ability to manage nodes with
add_child()andremove_child(). - 📝 Includes a dynamic logging system that is deeply integrated with the node framework.
- 🌲 Allows for the direct referencing of the
NodeTreethrough a node'sroot()function. - 📜 Includes a method to save (TODO) and handle individual node scenes, such as the handy visual macro
scene!.