| Crates.io | magma_ecs |
| lib.rs | magma_ecs |
| version | 0.5.0 |
| created_at | 2023-11-30 11:12:18.741575+00 |
| updated_at | 2025-10-14 18:07:34.991981+00 |
| description | Entity-Component-System for the Magma3D game engine |
| homepage | https://dynamicgoose.github.io/magma3d-engine/ |
| repository | https://codeberg.com/DynamicGoose/magma-ecs |
| max_upload_size | |
| id | 1054077 |
| size | 149,413 |
Magma-ECS is the Entity-component-system developed for the Magma3D engine. It aims to be simple to use and lightweight. It also provides an easy way for parallel execution of systems.
Even though this is intended for the magma_api it is easily possible to use on it's own.
Add the crate to your Cargo.toml:
[dependencies]
magma_ecs = "0.5.0-alpha.3"
Entity: An entity is just an index into the component storage.
Component: A component holds some type of data. Entities can have components assigned to them.
System: A system is a piece of code (usually a function), that reads and modifies the data.
Another way to think about this would be Identifier-Data-Logic.
use magma_ecs::World;
use magma_ecs::component::Component;
use magma_ecs::systems::SystemGraph;
use magma_ecs::query::{Query, With};
use magma_ecs::resources::Res;
use std::any::Any;
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))?;
}
let mut system_graph = SystemGraph::new();
system_graph.add_system(sys_a, vec![]);
let mut dispatcher = system_graph.into_dispatcher(&mut world).unwrap();
dispatcher.dispatch(&mut world);
Ok(())
}
fn sys_a(resource: Res<String>, query: Query<&Name, (With<Health>, With<Npc>)>) {
for name in query {
println!("{} Entity: {}", *resource, name.0);
}
}
// Component can be derived for any type implementing `Send + Sync`.
#[derive(Component)]
struct Name(String);
#[derive(Component)]
struct Health(u32);
#[derive(Component)]
enum Npc {
Ally,
Enemy,
}
none
This is still in developement and not production ready.