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 class!
macro to implement the required Dynamic
, NodeAbstract
, and Node
traits.
use *;
class!
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 child_scene: NodeScene = scene! ;
let parent_scene: NodeScene = scene! ;
let scene: NodeScene = scene! ;
// Scenes can also be cloned, stored, and reused.
//
// # Note
// Saved node scenes are stored in .scn files, with a toml format.
let cloned_scene: NodeScene = scene.clone;
cloned_scene.save.unwrap; // Pass the directory and the scene name.
let loaded_scene: NodeScene = load.unwrap;
// A built in hashing function allows for structural integrity of scenes to be checked.
// (`NodeScene` has a custom implementation for `std::hash::Hash`.)
//
// # Note
// This only hashes the tree's layout, note types, and ownership.
// This does not hash or keep any reference to the node's fields.
assert_eq!;
Logging
Logging is also supported. Here is an example setup with an output of a warning and a crash. Note that the crash header/footer are customizable, and that the output is actually colored in a real terminal.
use *;
use TreeSimple;
class!
Signals
Signals are introduced in order to allow for easy communication between various nodes. An example is shown below:
use *;
use TreeSimple;
class!
class!
Supported Features
glam
- Enables support with glam's (v0.29.*) types when it comes with saving and loading.
Highlights
- ποΈ 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 individualNode
behaviours for when a tree is paused/unpaused. - π‘ Various methods to communicate with other nodes, such as
owner()
,parent()
,get_child()
,children()
, andget_node()
, as well as methods to automate the process such as signals. - π An abstracted smart pointer known as
Tp<T>
andTpDyn
which clones implicitly to reduce syntax noise and allows for low boilerplate. - π A caching system hosted on the
NodeTree
to act as a safe interface to ensureTp<T>
/TpDyn
soundness, and increase performance! - πͺ The ability to manage nodes with
add_child()
andremove_child()
. - π Includes a dynamic logging and error handling system that is deeply integrated with the node framework.
- π² Allows for the direct referencing of the
NodeTree
through a node'sroot()
function. - π Includes functionality to save, load and handle individual node scenes, such as the handy visual macro
scene!
.