Crate magma_ecs

Crate magma_ecs 

Source
Expand description

This crate provides the Entity-Component-System of the Magma3D-Engine.

The crate provides a World struct with Resources and Entities. An entity is just an index into the component storage. A resource is like a global component, independent of the Entities.

§Usage Example

use magma_ecs::World;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut world = World::new();

    // Register component types.
    world.register_component::<Name>();
    world.register_component::<Health>();
    world.register_component::<Npc>();

    // Add a resource.
    world.add_resource(String::from("This is an example resource!"))?;

    // create a couple of entities with registered components
    for _ in 0..10 {
        world.create_entity((Name("Enemy".to_owned()), Health(20), Npc::Enemy))?;
    }
    Ok(())
}

// Components can be any type that implements `Send + Sync` (or just any if you disable the `multithreading` feature).
struct Name(String);
struct Health(u32);
enum Npc {
    Ally,
    Enemy,
}

Re-exports§

pub use rayon;

Modules§

entities
Provides the Entities struct as well as query_entity modules.
error
Error types Error types
resources
Provides the Resources struct.
systems
Provides the Systems struct, from which a Dispatcher can be created.

Structs§

World
The World struct holds all the data of a world.