a tiny entity-component-system library

Hello World

``` 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); }

```

add components into world

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 deriveBundleandComponent` trait easily

Component is just a tag, it could be implemented by any type

``` rust use tecs::bundle::Component;

[derive(Component)]

struct MyComponent{ name : String, }

`` all of the field ofBundleshould implementComponent`

``` rust use tecs::bundle::Bundle;

[derive(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:

query components in world

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 = ()> {...}

WorldFetch is used to fetch component in world

it could be the (im)mutable reference of Component,or a tuple that contains only WorldFetch

WorldFilter is used to fetch bundle in world

it could be

Example

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

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().getorinit(||1); asserteq!(*world.get_res().get().unwrap(),1); ```

with system

System

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 get resources of type T in world | cant use same Res in one system | | Resources | to get any type of resources in world | cant use be used with any Res in one system| | Query | to query components in world | cant use conflict query in one system, like Query<&T> and Query<&mut T>| Commands | to add and remove bundle into world | use spawn_many() method to spawn many bundle with the same type quickly|

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