less dependencies
fast to build
easy to use
``` rust // a function-system fn hello_world() { println!("Hello World") }
fn main() { // create a world let mut world = tecs::World::new(); world // add "hello world" system into world's startupsystems // startupsystems will only run once .addstartupsystem(helloworld) // make the loop run once only .run_until(|| true); }
```
you can use spawn
method to add any types that implemented Bundle
or Component
trait into world
``` rust use tecs::tools::Command;
let mut world = tecs::World::new();
world.spawn(12345);
world.spawn("abcde");
``
you can derive
Bundleand
Component` trait easily
Component
is just a tag, it could be implemented by any type
``` rust use tecs::bundle::Component;
struct MyComponent{ name : String, }
``
all of the field of
Bundleshould implement
Component`
``` rust use tecs::bundle::Bundle;
struct MyBundle{ inner : MyComponent, }
```
Component
defaults to the following type implementation
Bundle
defaults to all tuple implementations that contain only types thatComponent
trait implemented
such as:
use Query
directly
``` rust
use tecs::world::Query;
use tecs::tool::Command;
let mut world = tecs::World::new();
// add two Bundle
into world
world.spawn(12345);
world.spawn((54321,"abcde"));
// create a Query
to get all i32'a refence
let query = Query::<&i32>::new(&mut world);
for item in query {
println!("{item}")
}
// this code will print:
// 12345
// 54321
```
or use system
``` rust use tecs::world::{Query,Commands}; use tecs::tool::Command;
// use command to do spawn fn do_spawn(mut commands: Commands){ commands.spawn(12345); commands.spawn((54321,"abcde")); }
// note: you cant use conflict Query in one system, or the program will panic when you add system into world
// a example of conflict Query: Query<&i32> and Query<&mut i32>
fn printalli23(mut query : Query<&i32>){
for item in query {
println!("{item}")
}
}
world.addstartupsyste(dospawn); world.addstartupsyste(printalli23); world.rununtil(||true);
``
Query` is a type that receiver two generic
rust
pub struct Query<'a, F: WorldFetch, Q: WorldFilter = ()> {...}
it could be the (im)mutable reference of Component,or a tuple that contains only WorldFetch
it could be
All
OneOf
Not
Query<&i32>
will query all components that contain i32
component, and give immutable references of i32
in iterator
use Query<&mut i32>
to let iterator give mutable references of i32
in iterator
use Query<&i32,All<&str>>
will query all components that contain i32
and &str
, and give immutable references of i32
in iterator
use Query<&i32,AnyOf<(&str,MyComponent)>>
will query all components that contain i32
and one of &str
and MyComponent
, and give immutable references of i32
in iterator
use Query<&i32,All<&str>>
will query all components that contain i32
and dont contain &str
, and give immutable references of i32
in iterator
you can use for to get the result of the query
the type of fetch
is WorldFetch
rust
for fetch in query {}
you can use for with .into_eiter() method to get the result of the query,and the Entity
of result
rust
for e in query.into_eiter() {}
the type of e
is EBundle
rust
pub struct EBundle<'a, F: WorldFetch> {...}
you can deref e
to get the result of query, use .entity() method to get the Entity
of result
Entity
could be used to remove the bundle that queried
rust
commands.remove(b.entity());
Resources are stored in the world type by type
```rust use tecs::tools::ResManager;
let mut world = tecs::World::new();
// get resources usize, and init it to 1
world.getres
only function-system supported in this version
all types that implemented SystemParm
trait could be the parm of the function-system
follow types impled SystemParm
trait
you can find them in tecs::world
mod
| type | usage | note |
| --- | --- | --- |
| Res
to run a system,you need to add system into world by using .add_system()
method or .add_startup_system()
method fist
to run systems in world,you can
use .startup()
method to run all startup_systems
use .run_once()
method to run all systems once(dont include startup_systems)
use .run()
method to run all systems many times, this method will not return.
use .run_until(f)
method to run all systems many times, the loop will be break when f
return true
;