Macro ABC_ECS::get_components
source · macro_rules! get_components { ($engine:expr, $entity:expr, $($component:ty),*) => { ... }; }
Expand description
This macro is used to get a variable ammount of components from an entity It returns a tuple of references to the components
use ABC_ECS::{get_components, GameEngine, Component};
struct Position {
x: f32,
y: f32,
}
impl Component for Position {}
struct Velocity {
x: f32,
y: f32,
}
impl Component for Velocity {}
fn main() {
let mut engine = GameEngine::new();
let entities_and_components = &mut engine.entities_and_components;
let entity = entities_and_components.add_entity();
entities_and_components.add_component_to(entity, Position { x: 0.0, y: 0.0 });
entities_and_components.add_component_to(entity, Velocity { x: 1.0, y: 1.0 });
let (position, velocity) = get_components!(engine.entities_and_components, entity, Position, Velocity);
println!("Position: {}, {}", position.x, position.y);
println!("Velocity: {}, {}", velocity.x, velocity.y);
}