#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(clippy::print_stdout)]
#![allow(unused_must_use)]
#![allow(path_statements)]
#![allow(clippy::no_effect)]
#![allow(clippy::if_same_then_else)]
use std::os::raw::c_void;
use flecs_ecs::macros::*;
use flecs_ecs::prelude::*;
use flecs_ecs::sys;
#[derive(Component, Default)]
struct Position {
pub x: f32,
pub y: f32,
}
#[derive(Component, Default)]
struct Velocity {
pub x: f32,
pub y: f32,
}
#[derive(Component, Default)]
struct Game {
pub time: f32,
}
#[derive(Component, Default)]
struct Foo;
#[derive(Component, Default)]
struct Plate;
#[derive(Component, Default)]
struct Npc;
#[derive(Component, Default)]
struct Likes;
#[derive(Component, Default)]
struct Tag;
#[derive(Component, Default)]
struct Speed;
#[derive(Component, Default, Clone, Copy, PartialEq)]
struct Mass {
value: f32,
}
#[derive(Component, Default)]
struct Bar;
#[derive(Component, Default)]
struct SimTime {
value: f32,
}
#[derive(Component, Default)]
struct SimConfig {
sim_speed: f32,
}
#[derive(Component, Default)]
struct Player;
#[derive(Component, Default)]
struct Input;
#[derive(Component, Default)]
struct SpaceShip;
#[derive(Component, Default)]
struct Planet;
#[derive(Component, Default)]
struct DockedTo;
#[derive(Component, Default)]
struct Depth {
value: i32,
}
#[derive(Component, Default)]
struct TimeOfDay {
pub value: f32,
}
#[derive(Component, Default)]
struct Eats {
amount: u32,
}
#[derive(Component, Default)]
struct Apples;
#[derive(Component, Default)]
struct MaxSpeed {
value: u32,
}
#[derive(Component, Default)]
struct Defense {
value: u32,
}
#[derive(Component, Default)]
struct Serializable;
#[derive(Component, Default)]
struct Gravity {
x: i32,
y: i32,
}
#[derive(Component, Default)]
struct Transform;
#[derive(Component, Default)]
struct Mesh;
#[derive(Component, Default)]
struct Health {
value: u32,
}
#[derive(Component, Default)]
struct Archer;
#[derive(Component, Default)]
struct Node;
fn flecs_system_docs_compile_test() {
let world = World::new();
let sys = world
.system_named::<(&mut Position, &Velocity)>("Move")
.each(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
sys.run();
world.progress();
world
.system_named::<(&mut Position, &Velocity)>("Move")
.kind(0)
.each(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
let q = world.new_query::<(&mut Position, &Velocity)>();
q.each(|(p, v)| { });
world
.system_named::<(&mut Position, &Velocity)>("Move")
.each(|(p, v)| { });
q.run(|mut it| {
while it.next() {
let mut p = it
.field_mut::<Position>(0)
.expect("query term changed and not at the same index anymore");
let v = it
.field::<Velocity>(1)
.expect("query term changed and not at the same index anymore");
for i in it.iter() {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
});
world
.system_named::<(&mut Position, &Velocity)>("Move")
.run(|mut it| {
while it.next() {
let mut p = it
.field_mut::<Position>(0)
.expect("query term changed and not at the same index anymore");
let v = it
.field::<Velocity>(1)
.expect("query term changed and not at the same index anymore");
for i in it.iter() {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
});
q.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
for i in it.iter() {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
});
world
.system_named::<(&mut Position, &Velocity)>("Move")
.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
for i in it.iter() {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
});
world
.system_named::<(&mut Position, &Velocity)>("Move")
.each_iter(|it, i, (p, v)| {
p.x += v.x * it.delta_time();
p.y += v.y * it.delta_time();
});
world
.system_named::<(&mut Position, &Velocity)>("Move")
.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
for i in it.iter() {
p[i].x += v[i].x * it.delta_time();
p[i].y += v[i].y * it.delta_time();
}
}
});
let delta_time = 1.0;
world.progress_time(delta_time);
world.system_named::<()>("PrintTime").run(|mut it| {
while it.next() {
println!("Time: {}", it.delta_time());
}
});
world
.system_named::<&Game>("PrintTime")
.term_at(0)
.singleton()
.kind(id::<flecs::pipeline::OnUpdate>())
.run(|mut it| {
while it.next() {
println!("Time: {}", it.field::<Game>(0)[9].time);
}
});
world
.system_named::<(&mut Position, &Velocity)>("Move")
.kind(id::<flecs::pipeline::OnUpdate>())
.each(|(p, v)| {
});
#[derive(Component, Default)]
struct Physics;
let physics = world
.component::<Physics>()
.add(id::<flecs::pipeline::Phase>());
let collisions = world.entity().add(id::<flecs::pipeline::Phase>());
physics.add_trait::<(flecs::DependsOn, flecs::pipeline::OnUpdate)>();
collisions.add_trait::<(flecs::DependsOn, Physics)>();
world
.system_named::<(&Position, &Velocity)>("Collide")
.kind(collisions) .each(|(p, v)| {
});
world
.pipeline()
.with(id::<flecs::system::System>())
.with(id::<flecs::pipeline::Phase>())
.cascade_id(id::<flecs::DependsOn>())
.without(id::<flecs::Disabled>())
.up_id(id::<flecs::DependsOn>())
.without(id::<flecs::Disabled>())
.up_id(id::<flecs::ChildOf>())
.build();
let pipeline = world
.pipeline()
.with(id::<flecs::system::System>())
.with(Foo::id()) .build();
world.set_pipeline(pipeline);
world
.system_named::<(&mut Position, &Velocity)>("Move")
.kind(Foo::id()) .each(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
world.progress();
sys.disable_self();
sys.enable_self();
sys.add(id::<flecs::Disabled>());
world
.system::<&Position>()
.with(&mut Transform::id())
.each(|p| {
});
world
.system::<&Position>()
.with(&Transform::id())
.each(|p| {
});
world
.system_named::<&Plate>("AssignPlate")
.immediate(true)
.run(|mut it| {
while it.next() {
}
});
world
.system_named::<&Plate>("AssignPlate")
.immediate(true)
.run(|mut it| {
while it.next() {
it.world().defer_suspend();
it.world().defer_resume();
}
});
world.set_threads(4);
world.system::<&Position>().par_each(|p| {
});
world.set_task_threads(4);
world
.system::<&Position>()
.set_interval(1.0) .each(|p| {
});
world
.system::<&Position>()
.set_rate(2) .each(|p| {
});
}
fn flecs_query_docs_compile_test() {
let world = World::new();
let q = world
.query::<(&mut Position, &Velocity)>()
.set_cached()
.query_flags(QueryFlags::MatchEmptyTables)
.build();
world.delete_empty_tables(sys::ecs_delete_empty_tables_desc_t {
clear_generation: 10,
delete_generation: 0,
time_budget_seconds: 0.0,
});
let q = world.new_query::<(&mut Position, &Velocity)>();
q.each(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
let add_npc = true;
let mut q = world.query::<(&mut Position, &Velocity)>();
q.with(&Velocity::id());
if add_npc {
q.with(&Foo::id()); }
q.build();
let q = world.new_query::<(&mut Position, &Velocity)>();
q.each_entity(|e, (p, v)| {
println!("Entity: {}", e.name());
p.x += v.x;
p.y += v.y;
});
let q = world
.query::<&Position>()
.read((Likes::id(), id::<flecs::Wildcard>()))
.build();
q.each_iter(|it, index, p| {
println!(
"Entity: {}: {}",
it.get_entity(index).unwrap().name(),
it.id(1).to_str()
);
});
#[derive(Component, Default)]
struct Tag;
world.new_query::<&Tag>().each_entity(|e, tag| { });
world
.query::<()>()
.with(&Tag)
.build()
.each_entity(|e, _| { });
let q = world.new_query::<(&Position, &Velocity)>();
q.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
for i in it.iter() {
p[i].x += v[i].x;
p[i].y += v[i].y;
println!("Entity: {}", it.get_entity(i).unwrap().name());
}
}
});
let q = world.new_query::<&Position>();
q.each_entity(|e, p| {
e.add(Velocity::id()); });
let q = world.new_query::<&Position>();
world.defer(|| {
q.each_entity(|e, p| {
e.add(Velocity::id()); });
});
let q = world.new_query::<&Position>();
world.defer_begin();
q.each_entity(|e, p| {
e.add(Velocity::id()); });
world.defer_end();
let q = world.new_query::<(&mut Position, &Velocity)>();
q.each(|(p, v)| { });
let q = world.query::<&mut Position>().with(&Velocity::id()).build();
let npc = world.entity();
let platoon_01 = world.entity();
let q = world
.query::<(&mut Position, &Velocity)>()
.with(npc)
.with(platoon_01)
.build();
world.component::<Position>();
let npc = world.entity_named("npc");
let q = world
.query::<(&Position, &Npc)>()
.with("npc")
.with("Position")
.build();
let e = world.entity().add(Position::id()).add(Velocity::id());
let q = world.query::<()>().with(id::<flecs::Wildcard>()).build();
let e = world.entity().add(Position::id()).add(Velocity::id());
let q = world.query::<()>().with(id::<flecs::Any>()).build();
#[derive(Component, Default)]
struct Eats {
value: f32,
}
#[derive(Component, Default)]
struct Apples;
let q = world.new_query::<&mut (Eats, Apples)>();
q.each(|eats| {
eats.value += 1.0;
});
let eats = world.component::<Eats>();
let apples = world.component::<Apples>();
let q1 = world.query::<()>().with((Eats::id(), Apples::id())).build();
let q2 = world.query::<()>().with((Eats::id(), apples)).build();
let q3 = world.query::<()>().with((eats, apples)).build();
let q = world
.query::<()>()
.term()
.set_first(Eats::id())
.set_second(apples)
.build();
let q = world
.query::<()>()
.term()
.set_first("Eats")
.set_second("Apples")
.build();
let q = world
.query::<()>()
.with((Eats::id(), id::<flecs::Wildcard>()))
.build();
q.each_iter(|it, index, _| {
let pair = it.pair(0).unwrap();
let second = pair.second_id();
let e = it.get_entity(index).unwrap();
println!("Entity {} likes {}", e.name(), second.name());
});
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.set_inout_kind(InOutKind::In)
.build();
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.set_in() .build();
let q = world.new_query::<(&mut Position, &Velocity)>();
let q = world
.query::<()>()
.with(&mut Position::id())
.with(&Velocity::id()) .build();
let q = world
.query::<()>()
.with(&mut Position::id())
.with(&Velocity::id())
.build();
q.run(|mut it| {
while it.next() {
let p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
}
});
let q = world
.query::<()>()
.with(Position::id())
.set_inout()
.with(Velocity::id())
.set_in()
.build();
let q = world
.query::<()>()
.with(Position::id())
.and()
.with(Velocity::id())
.and()
.build();
let q = world.new_query::<(&mut Position, &Velocity)>();
let q2 = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.build();
let q3 = world
.query::<()>()
.with(Position::id())
.set_oper(OperKind::And)
.with(Velocity::id())
.set_oper(OperKind::And)
.build();
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.set_oper(OperKind::Or)
.with(Speed::id())
.with(Mass::id())
.build();
q.run(|mut it| {
while it.next() {
let p = it.field_mut::<Position>(0);
let v = it.field::<Mass>(2);
let vs_id = it.id(1);
if vs_id == world.component_id::<Velocity>() {
let v = it.range().unwrap().get_mut::<Velocity>();
} else if vs_id == world.component_id::<Speed>() {
let s = it.range().unwrap().get_mut::<Speed>();
}
}
});
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.or()
.with(Speed::id())
.with(Mass::id())
.build();
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.set_oper(OperKind::Not)
.build();
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.not()
.build();
let q = world
.query::<()>()
.with(Position::id())
.without(Velocity::id())
.build();
let q = world.new_query::<(&Position, Option<&Velocity>)>();
q.each(|(p, v)| {
if let Some(v) = v {
}
});
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.set_oper(OperKind::Optional)
.build();
q.run(|mut it| {
while it.next() {
let p = it.field_mut::<Position>(0);
if let Some(v) = it.field::<Velocity>(1) {
}
}
});
let q = world
.query::<()>()
.with(Position::id())
.with(Velocity::id())
.optional()
.build();
world
.query::<()>()
.with((id::<flecs::PredEq>(), Foo::id()))
.without((id::<flecs::PredEq>(), Bar::id()))
.with(id::<flecs::PredEq>())
.set_second("Foo")
.flags(sys::EcsIsName)
.with(id::<flecs::PredMatch>())
.set_second("Fo")
.flags(sys::EcsIsName)
.build();
let type_list = world.prefab().add(Position::id()).add(Velocity::id());
let q = world
.query::<()>()
.with(type_list)
.set_oper(OperKind::AndFrom) .with(type_list)
.set_oper(OperKind::OrFrom) .with(type_list)
.set_oper(OperKind::NotFrom) .build();
let q = world
.query::<()>()
.with(type_list)
.and_from()
.with(type_list)
.or_from()
.with(type_list)
.not_from()
.build();
world
.query::<()>()
.with(Position::id())
.scope_open()
.not()
.with(Velocity::id())
.or()
.with(Speed::id())
.scope_close()
.build();
let game = world.entity().add(SimTime::id());
let q = world
.query::<()>()
.with(Position::id()) .with(Velocity::id()) .with(SimTime::id())
.set_src(game) .build();
q.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let v = it.field::<Velocity>(1);
let st = it.field::<SimTime>(2);
for i in it.iter() {
p[i].x += v[i].x * st[0].value;
p[i].y += v[i].y * st[0].value;
}
}
});
let q = world
.query::<(&mut Position, &Velocity, &SimTime)>()
.term_at(2)
.set_src(game) .build();
q.each_entity(|e, (p, v, st)| {
p.x += v.x * st.value;
p.y += v.y * st.value;
});
let cfg = world.entity().add(SimConfig::id());
let q = world
.query::<(&SimConfig, &mut SimTime)>()
.term_at(0)
.set_src(cfg)
.term_at(1)
.set_src(game)
.build();
q.run(|mut it| {
while it.next() {
let sc = it.field::<SimConfig>(0);
let mut st = it.field_mut::<SimTime>(1);
st[0].value += sc[0].sim_speed; }
});
q.each(|(sc, st)| {
st.value += sc.sim_speed;
});
q.each_iter(|it, index, (sc, st)| {
st.value += sc.sim_speed;
});
q.each_entity(|e, (sc, st)| {
st.value += sc.sim_speed;
});
let q = world
.query::<(&SimConfig, &SimTime)>()
.term_at(0)
.set_src("cfg")
.term_at(1)
.set_src("game")
.build();
let q = world
.query::<(&Player, &Position)>()
.with(Input::id())
.set_src(Input::id()) .build();
let q = world
.query::<(&Player, &Position)>()
.with(Input::id())
.singleton() .build();
let q = world
.query::<(&Player, &Position, &Input)>()
.term_at(2)
.singleton() .build();
let q1 = world
.query::<()>()
.with(Mass::id())
.up_id(id::<flecs::ChildOf>())
.build();
let q2 = world
.query::<()>()
.with(Mass::id())
.up() .build();
let q3 = world
.query::<()>()
.with(Mass::id())
.parent() .build();
world
.component::<Mass>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let q1 = world
.query::<()>()
.with(Mass::id())
.self_()
.up_id(id::<flecs::IsA>())
.build();
let q2 = world
.query::<()>()
.with(Mass::id()) .build();
world
.component::<Mass>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let base = world.entity().add(Mass::id());
let parent = world.entity().is_a(base);
let child = world.entity().child_of(parent);
let q = world
.query::<()>()
.with(Mass::id())
.up() .build();
world
.component::<Position>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let base = world.entity().add(Position::id());
let inst = world.entity().is_a(base);
let q1 = world.new_query::<&Position>();
let q2 = world
.query::<&Position>()
.term_at(0)
.self_()
.up_id(flecs::IsA::ID)
.build();
let parent = world.entity().add(Position::id());
let child = world.entity().child_of(parent);
let q = world.query::<&Position>().term_at(0).up().build();
let contained_by = world.entity().add(id::<flecs::Traversable>());
let parent = world.entity().add(Position::id());
let child = world.entity().add((contained_by, parent));
let q = world
.query::<&Position>()
.term_at(0)
.up_id(contained_by)
.build();
let q = world
.query::<(&Position, &Mass)>()
.term_at(0)
.self_()
.build();
q.run(|mut it| {
while it.next() {
let mut p = it.field_mut::<Position>(0);
let m = it.field::<Mass>(1);
if it.is_self(1) {
for i in it.iter() {
p[i].x += 1.0 / m[i].value;
p[i].y += 1.0 / m[i].value;
}
} else {
for i in it.iter() {
p[i].x += 1.0 / m[0].value; p[i].y += 1.0 / m[0].value;
}
}
}
});
let q = world
.query::<()>()
.with(SpaceShip::id())
.with(DockedTo::id())
.set_second("$Location")
.with(Planet::id())
.set_src("$Location")
.build();
let q = world
.query::<()>()
.with(SpaceShip::id())
.with(DockedTo::id())
.second()
.set_var("$Location")
.with(Planet::id())
.src()
.set_var("$Location")
.build();
let earth = world.entity();
let location_var = q.find_var("$Location").unwrap();
q.iterable().set_var(location_var, earth).each(|it| {
});
let earth = world.entity();
q.iterable().set_var_expr("$Location", earth).each(|it| {
});
#[derive(Component, Default)]
struct Movement {
value: Entity,
}
let q_read = world.new_query::<&Position>();
let q_write = world.new_query::<&mut Position>();
let changed = q_read.is_changed();
let e = world.entity().set(Position { x: 10.0, y: 20.0 });
q_write.run(|mut it| {
while it.next() {
if !changed {
it.skip();
} else {
}
}
});
q_read.run(|mut it| {
while it.next() {
if it.is_changed() {
}
}
});
let q = world
.query::<(&Depth, &Position)>()
.order_by::<Depth>(|e1, d1: &Depth, e2, d2: &Depth| {
(d1.value > d2.value) as i32 - (d1.value < d2.value) as i32
})
.build();
let depth_id = world.component::<Depth>();
let q = world
.query::<&Position>()
.with(depth_id)
.set_in()
.order_by_id(depth_id, |e1, d1: *const c_void, e2, d2: *const c_void| {
let d1 = unsafe { &*(d1 as *const Depth) };
let d2 = unsafe { &*(d2 as *const Depth) };
(d1.value > d2.value) as i32 - (d1.value < d2.value) as i32
})
.build();
let q = world
.query::<&Position>()
.order_by_id(0, |e1, _d1: *const c_void, e2, _d2: *const c_void| {
(e1 > e2) as i32 - (e1 < e2) as i32
})
.build();
#[derive(Component)]
struct Unit;
let unit = world.component::<Unit>();
let melee_unit = world.entity().is_a(Unit::id());
let ranged_unit = world.entity().is_a(Unit::id());
let unit_01 = world.entity().add(melee_unit);
let unit_02 = world.entity().add(ranged_unit);
let q = world.query::<&Unit>();
#[derive(Component)]
struct LocatedIn;
world
.component::<LocatedIn>()
.add(id::<flecs::Transitive>());
let new_york = world.entity();
let manhattan = world.entity().add((LocatedIn::id(), new_york));
let central_park = world.entity().add((LocatedIn::id(), manhattan));
let bob = world.entity().add((LocatedIn::id(), central_park));
let q = world
.query::<()>()
.with((LocatedIn::id(), new_york))
.build();
let q = world
.query::<()>()
.with(LocatedIn::id())
.set_second("$Place")
.build();
#[derive(Component)]
struct City;
new_york.add(City::id());
let q = world
.query::<()>()
.with(LocatedIn::id())
.set_second("$Place")
.with(City::id())
.set_src("$Place")
.build();
let tree = world.entity();
let oak = world.entity().is_a(tree);
let q = world.query::<()>().with((id::<flecs::IsA>(), tree)).build();
}
fn flecs_entities_components_docs_compile_test() {
let world = World::new();
let my_entity = world.entity();
my_entity.destruct();
let e1 = world.entity(); e1.destruct(); let e2 = world.entity(); e1.add(Npc::id());
e2.add(Npc::id());
let e1 = world.entity();
e1.destruct();
e1.destruct();
my_entity.clear();
let e1 = world.entity();
let e2 = world.entity();
e1.destruct();
e1.is_alive(); e2.is_alive();
let e1 = world.entity();
let e2 = world.entity();
e1.destruct();
e1.is_valid(); world.entity_from_id(0).is_valid();
let e = world.make_alive(1000);
world.set_entity_range(5000, 0);
world.set_entity_range(5000, 10000);
world.enable_range_check(true);
let e = world.entity_named("MyEntity");
if e == world.lookup("MyEntity") {
}
println!("{}", e.name());
let p = world.entity_named("Parent");
let e = world.entity_named("Child").child_of(p);
if e == world.lookup("Parent::Child") {
}
let p = world.entity_named("Parent");
let e = world.entity_named("Child").child_of(p);
if e == p.lookup("Child") {
}
let p = world.entity_named("Parent");
let e = world.entity_named("Child").child_of(p);
println!("{}", e.name()); println!("{}", e.path().unwrap());
let e1 = world.entity_named("Parent::Child");
let e2 = world.entity_named("Parent::Child");
if e1 == e2 {
}
let e = world.entity_named("Foo");
e.set_name("Bar");
let ten = world.entity_named("10");
let twenty = world.entity_named("20");
let e = world.entity();
e.enable_self();
e.disable_self();
let e1 = world.entity();
let e2 = world.entity();
let e3 = world.entity();
let p = world.prefab();
p.add(e1);
p.add(e2);
p.add(e3);
p.disable_self();
p.enable_self();
let e1 = world.entity();
let e2 = world.entity();
let e3 = world.entity();
let p1 = world.prefab().add(e1);
let p2 = world.prefab().is_a(p1).add(e2).add(e3);
p2.disable_self();
p1.enable_self();
e.add(id::<flecs::Disabled>());
let pos = world.component::<Position>();
pos.get::<&flecs::Component>(|comp_data| {
println!(
"size: {}, alignment: {}",
comp_data.size, comp_data.alignment
);
});
world.component::<Position>().add_trait::<flecs::Sparse>();
fn main() {
let world = World::new();
let e1 = world
.entity()
.set(Position { x: 10.0, y: 20.0 }) .set(Velocity { x: 1.0, y: 2.0 }); let e2 = world
.entity()
.set(Position { x: 10.0, y: 20.0 }) .set(Velocity { x: 1.0, y: 2.0 }); }
world.component::<Position>();
use flecs_ecs::prelude::*;
#[derive(Component)]
struct Movement;
impl Module for Movement {
fn module(world: &World) {
world.module::<Movement>("Movement");
}
}
let world = World::new();
world.import::<Movement>();
let pos = world.component::<Position>();
let e = world.entity().add(Position::id());
pos.destruct();
world.set(TimeOfDay { value: 0.5 });
world.get::<&TimeOfDay>(|time| println!("{}", time.value));
world.set(TimeOfDay { value: 0.5 });
world.component::<TimeOfDay>().set(TimeOfDay { value: 0.5 });
world
.component::<Position>()
.add_trait::<flecs::CanToggle>();
let e = world.entity().set(Position { x: 10.0, y: 20.0 });
e.disable(Position::id());
assert!(!e.is_enabled(Position::id())); e.enable(Position::id());
assert!(e.is_enabled(Position::id())); }
fn flecs_docs_relationships_compile_test() {
let world = World::new();
let likes = world.entity();
let bob = world.entity();
let alice = world.entity();
bob.add((likes, alice));
bob.remove((likes, alice));
let bob = world.entity();
let eats = world.entity();
let apples = world.entity();
let pears = world.entity();
bob.add((eats, apples));
bob.add((eats, pears));
bob.has((eats, apples)); bob.has((eats, pears));
let q = world.query::<()>().expr("(Eats, Apples)").build();
let q = world.query::<()>().expr("(Eats, *)").build();
let q = world.query::<()>().with((eats, apples)).build();
let q = world.new_query::<&(Eats, Apples)>();
bob.has((eats, apples));
bob.has((eats, flecs::Wildcard::ID));
let parent = bob.parent();
let food = bob.target(eats, 0);
let mut index = 0;
while bob.target(eats, index).is_some() {
index += 1;
}
let parent = bob.target_for(Position::id(), flecs::ChildOf::ID);
bob.each_component(|id| {
if id.is_pair() {
let first = id.first_id();
let second = id.second_id();
}
});
world
.query::<()>()
.with((eats, apples))
.build()
.each_entity(|e, _| {
});
world
.query::<()>()
.with((eats, flecs::Wildcard::ID))
.build()
.each_iter(|it, i, _| {
let food = it.pair(0).unwrap().second_id(); let e = it.get_entity(i).unwrap();
});
let parent = world.entity();
parent.each_child(|child| {
});
#[derive(Component)]
struct Begin;
#[derive(Component)]
struct End;
let likes = world.entity();
let apples = world.entity();
let e = world.entity();
e.add((likes, apples));
e.set_pair::<Eats, Apples>(Eats { amount: 1 });
e.set_pair::<Begin, Position>(Position { x: 10.0, y: 20.0 });
e.set_pair::<End, Position>(Position { x: 100.0, y: 20.0 }); e.add((flecs::ChildOf::ID, world.component_id::<Position>()));
e.add((id::<flecs::ChildOf>(), Position::id()));
let e = world.entity();
let first = world.entity();
let second = world.entity();
let third = world.entity();
e.set_first::<Position>(Position { x: 1.0, y: 2.0 }, first);
e.set_first::<Position>(Position { x: 3.0, y: 4.0 }, second);
e.set_first::<Position>(Position { x: 5.0, y: 6.0 }, third);
let q = world
.query::<()>()
.with((likes, flecs::Wildcard::ID))
.build();
q.each_iter(|it, i, _| {
println!(
"entity {} has relationship {} {}",
it.get_entity(i).unwrap(),
it.pair(0).unwrap().first_id().name(),
it.pair(0).unwrap().second_id().name()
);
});
let q = world.query::<()>().expr("(likes, *)").build();
let bob = world.entity();
let eats = world.entity();
let apples = world.entity();
let pears = world.entity();
bob.add((eats, apples));
bob.add((eats, pears));
bob.each_pair(eats, flecs::Wildcard::ID, |id| {
println!("bob eats {}", id.second_id().name());
});
bob.each_target(eats, |entity| {
println!("bob eats {}", entity.name());
});
let apple = world.entity();
let fruit = world.entity();
apple.add((flecs::IsA::ID, fruit));
apple.is_a(fruit);
let granny_smith = world.entity();
granny_smith.add((flecs::IsA::ID, apple));
let spaceship = world
.entity()
.set(MaxSpeed { value: 100 })
.set(Defense { value: 50 });
let frigate = world
.entity()
.is_a(spaceship) .set(Defense { value: 75 });
let is_100 = frigate.get::<&mut MaxSpeed>(|v| {
v.value == 100 });
let is_75 = frigate.get::<&mut Defense>(|v| {
v.value == 75 });
let fast_frigate = world.entity().is_a(frigate).set(MaxSpeed { value: 200 });
let is_200 = fast_frigate.get::<&mut MaxSpeed>(|v| {
v.value == 200 });
let is_75 = fast_frigate.get::<&mut Defense>(|v| {
v.value == 75 });
let spaceship = world.entity();
let cockpit = world.entity();
cockpit.add((flecs::ChildOf::ID, spaceship));
cockpit.child_of(spaceship);
let parent = world.entity_named("Parent");
let child = world.entity_named("Child").child_of(parent);
child == world.lookup("Parent::Child"); child == parent.lookup("Child");
let parent = world.entity();
let prev = world.set_scope(parent);
let child_a = world.entity();
let child_b = world.entity();
world.set_scope(prev);
child_a.has((flecs::ChildOf::ID, parent)); child_b.has((flecs::ChildOf::ID, parent));
let parent = world.entity().run_in_scope(|| {
let child_a = world.entity();
let child_b = world.entity();
child_a.has((flecs::ChildOf::ID, parent)); child_b.has((flecs::ChildOf::ID, parent)); });
}
fn flecs_docs_quick_start_compile_test() {
let world = World::new();
let eats = world.entity();
let apples = world.entity();
let pears = world.entity();
let grows = world.entity();
let world = World::new();
let e = world.entity();
e.is_alive();
e.destruct();
e.is_alive();
let e = world.entity_named("bob");
println!("Entity name: {}", e.name());
let e = world.lookup("bob");
let e = world.entity();
e.add(Velocity::id());
e.set(Position { x: 10.0, y: 20.0 })
.set(Velocity { x: 1.0, y: 2.0 });
e.get::<&Position>(|p| {
println!("Position: ({}, {})", p.x, p.y);
});
e.remove(Position::id());
let pos_e = world.entity_from::<Position>();
println!("Name: {}", pos_e.name());
pos_e.add(Serializable::id());
let pos_e = world.entity_from::<Position>();
pos_e.get::<&flecs::Component>(|c| {
println!("Component size: {}", c.size);
});
#[derive(Component)]
struct Enemy;
let e = world.entity().add(Enemy::id());
e.has(Enemy::id());
e.remove(Enemy::id());
e.has(Enemy::id());
let enemy = world.entity();
let e = world.entity().add(enemy);
e.has(enemy);
e.remove(enemy);
e.has(enemy);
#[derive(Component)]
struct Likes;
let bob = world.entity();
let alice = world.entity();
bob.add((Likes::id(), alice)); alice.add((Likes::id(), bob)); bob.has((Likes::id(), alice));
bob.remove((Likes::id(), alice));
bob.has((Likes::id(), alice));
let id_likes_apples = world.id_view_from((Likes::id(), Apples::id()));
if id_likes_apples.is_pair() {
let relationship = id_likes_apples.first_id();
let target = id_likes_apples.second_id();
}
let bob = world.entity();
bob.add((eats, apples));
bob.add((eats, pears));
bob.add((grows, pears));
bob.has((eats, apples)); bob.has((eats, pears)); bob.has((grows, pears));
let alice = world.entity().add((Likes::id(), bob));
let o = alice.target(Likes::id(), 0);
let parent = world.entity();
let child = world.entity().child_of(parent);
parent.destruct();
let parent = world.entity_named("parent");
let child = world.entity_named("child").child_of(parent);
println!("Child path: {}", child.path().unwrap());
world.lookup("parent::child"); parent.lookup("child");
let q = world
.query::<(&Position, &mut Position)>()
.term_at(1)
.parent()
.cascade()
.build();
q.each(|(p, p_parent)| {
});
let e = world.entity().add(Position::id()).add(Velocity::id());
println!("Components: {}", e.archetype().to_string().unwrap());
e.each_component(|id| {
if id == world.component_id::<Position>() {
}
});
world.set(Gravity { x: 10, y: 20 });
world.get::<&Gravity>(|g| {
println!("Gravity: {}, {}", g.x, g.y);
});
let grav_e = world.entity_from::<Gravity>();
grav_e.set(Gravity { x: 10, y: 20 });
grav_e.get::<&Gravity>(|g| {
println!("Gravity: {}, {}", g.x, g.y);
});
world
.query::<(&Velocity, &Gravity)>()
.term_at(1)
.singleton()
.build();
world.each::<(&mut Position, &Velocity)>(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
let q = world
.query::<&Position>()
.with((flecs::ChildOf::ID, parent))
.build();
q.each_entity(|e, p| {
println!("{}: ({}, {})", e.name(), p.x, p.y);
});
q.run(|mut it| {
while it.next() {
let p = it.field_mut::<Position>(0);
for i in it.iter() {
println!(
"{}: ({}, {})",
it.get_entity(i).unwrap().name(),
p[i].x,
p[i].y
);
}
}
});
let q = world
.query::<()>()
.with((id::<flecs::ChildOf>(), id::<flecs::Wildcard>()))
.with(Position::id())
.set_oper(OperKind::Not)
.build();
let move_sys = world
.system::<(&mut Position, &Velocity)>()
.each_iter(|it, i, (p, v)| {
p.x += v.x * it.delta_time();
p.y += v.y * it.delta_time();
});
move_sys.run();
println!("System: {}", move_sys.name());
move_sys.add(id::<flecs::pipeline::OnUpdate>());
move_sys.destruct();
flecs::pipeline::OnLoad;
flecs::pipeline::PostLoad;
flecs::pipeline::PreUpdate;
flecs::pipeline::OnUpdate;
flecs::pipeline::OnValidate;
flecs::pipeline::PostUpdate;
flecs::pipeline::PreStore;
flecs::pipeline::OnStore;
world
.system_named::<(&mut Position, &Velocity)>("Move")
.kind(id::<flecs::pipeline::OnUpdate>())
.each(|(p, v)| {});
world
.system_named::<(&mut Position, &Transform)>("Transform")
.kind(id::<flecs::pipeline::PostUpdate>())
.each(|(p, t)| {});
world
.system_named::<(&Transform, &mut Mesh)>("Render")
.kind(id::<flecs::pipeline::OnStore>())
.each(|(t, m)| {});
world.progress();
move_sys.add(id::<flecs::pipeline::OnUpdate>());
move_sys.remove(id::<flecs::pipeline::PostUpdate>());
world
.observer_named::<flecs::OnSet, (&Position, &Velocity)>("OnSetPosition")
.each(|(p, v)| {});
let e = world.entity(); e.set(Position { x: 10.0, y: 20.0 }); e.set(Velocity { x: 1.0, y: 2.0 }); e.set(Position { x: 30.0, y: 40.0 });
#[derive(Component)]
struct MyModule;
impl Module for MyModule {
fn module(world: &World) {
world.module::<MyModule>("MyModule");
}
}
world.import::<MyModule>();
}
fn flecs_docs_observers_compile_test() {
let world = World::new();
world
.observer::<flecs::OnSet, &Position>()
.each_entity(|e, p| {
println!("Position set: {{ {}, {} }}", p.x, p.y);
});
world.entity().set(Position { x: 10.0, y: 20.0 });
let e = world.entity();
e.add(Position::id());
e.add(Position::id());
let e = world.entity();
e.set(Position { x: 10.0, y: 20.0 });
e.set(Position { x: 10.0, y: 20.0 });
let p = world.prefab().set(Position { x: 10.0, y: 20.0 });
let i = world.entity().is_a(p);
let p = world.prefab().set(Position { x: 10.0, y: 20.0 });
let i = world.entity().is_a(p);
i.set(Position { x: 20.0, y: 30.0 });
i.remove(Position::id());
let p = world.prefab().set(Position { x: 10.0, y: 20.0 });
let i = world.entity().is_a(p);
let e = world.entity().set(Position { x: 10.0, y: 20.0 });
e.remove(Position::id());
e.remove(Position::id());
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.add_event(id::<flecs::OnRemove>())
.each_entity(|e, p| {
});
world
.observer::<flecs::OnAdd, ()>()
.add_event(id::<flecs::OnRemove>())
.with(Position::id())
.each_iter(|it, i, p| {
if it.event() == flecs::OnAdd::ID {
} else if it.event() == flecs::OnRemove::ID {
}
});
world
.observer::<flecs::Wildcard, &Position>()
.each_entity(|e, p| {
});
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.with(Velocity::id())
.each_entity(|e, _| {
});
let e = world.entity();
e.add(Position::id());
e.add(Velocity::id());
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.with(Velocity::id())
.filter()
.each_entity(|e, p| {
});
let e = world.entity();
e.set(Position { x: 10.0, y: 20.0 });
e.set(Velocity { x: 1.0, y: 2.0 });
e.set(Position { x: 20.0, y: 30.0 });
world
.observer::<flecs::OnSet, &Position>()
.with(Npc::id()) .each_entity(|e, p| {
});
let e = world.entity();
e.set(Position { x: 10.0, y: 20.0 });
e.add(Npc::id());
e.set(Position { x: 20.0, y: 30.0 });
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.without(Velocity::id())
.each_entity(|e, p| {
});
let e = world.entity();
e.set(Position { x: 10.0, y: 20.0 });
e.set(Velocity { x: 1.0, y: 2.0 });
e.remove(Velocity::id());
world
.observer::<flecs::Monitor, (&Position, &Velocity)>()
.each_iter(|it, i, (p, v)| {
if it.event() == flecs::OnAdd::ID {
} else if it.event() == flecs::OnRemove::ID {
}
});
let e = world.entity();
e.set(Position { x: 10.0, y: 20.0 });
e.set(Velocity { x: 1.0, y: 2.0 });
e.remove(Position::id());
let e1 = world.entity().set(Position { x: 10.0, y: 20.0 });
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.with(Velocity::id())
.yield_existing()
.each_iter(|it, i, _| {
});
let e2 = world.entity().set(Position { x: 10.0, y: 20.0 });
let game = world.entity().set(TimeOfDay { value: 0.0 });
world
.observer::<flecs::OnSet, &TimeOfDay>()
.term_at(0)
.set_src(game) .each_iter(|it, i, time| {
});
game.set(TimeOfDay { value: 1.0 });
let e = world.entity().set(TimeOfDay { value: 0.0 });
world.set(TimeOfDay { value: 0.0 });
world
.observer::<flecs::OnSet, &TimeOfDay>()
.term_at(0)
.singleton()
.each_iter(|it, i, time| {
});
world.set(TimeOfDay { value: 1.0 });
let e = world.entity().set(TimeOfDay { value: 0.0 });
world
.observer::<flecs::OnSet, &Position>()
.term_at(0)
.self_()
.up() .each_entity(|e, p| {
});
let parent = world.entity();
let child = world.entity().child_of(parent);
parent.set(Position { x: 10.0, y: 20.0 });
world
.observer::<flecs::OnAdd, ()>()
.with(Position::id())
.term_at(0)
.up() .each_entity(|e, _| {
});
let parent = world.entity().set(Position { x: 10.0, y: 20.0 });
let child = world.entity().child_of(parent);
#[derive(Component)]
struct Synchronized;
world
.observer::<Synchronized, &Position>()
.each_entity(|e, p| {
});
let e = world.entity().set(Position { x: 10.0, y: 20.0 });
world
.event()
.add(Position::id())
.entity(e)
.emit(&Synchronized);
#[derive(Component)]
struct Clicked;
let widget = world.entity_named("widget");
widget.observe::<Clicked>(|| {
});
widget.emit(&Clicked);
#[derive(Component)]
struct Resize {
width: u32,
height: u32,
}
let widget = world.entity_named("widget");
widget.observe_payload::<&Resize>(|r| {
});
widget.emit(&Resize {
width: 100,
height: 200,
});
world
.observer::<flecs::OnSet, &Position>()
.each_entity(|e, p| {
});
e.set(Position { x: 10.0, y: 20.0 });
world.defer_begin();
e.set(Position { x: 20.0, y: 30.0 });
world.defer_end();
}
fn flecs_docs_prefabs_compile_test() {
let world = World::new();
#[derive(Component)]
struct Defense {
value: u32,
}
let spaceship = world.prefab_named("spaceship").set(Defense { value: 50 });
let inst_1 = world.entity().is_a(spaceship);
let inst_2 = world.entity().is_a(spaceship);
inst_1.get::<&Defense>(|defense| {
println!("Defense value: {}", defense.value);
});
let myprefab = world.entity().add(id::<flecs::Prefab>());
let myprefab = world.prefab();
world
.query::<&Position>()
.with(id::<flecs::Prefab>())
.build();
world
.query::<&Position>()
.with(id::<flecs::Prefab>())
.optional()
.build();
world
.query::<&Position>()
.query_flags(QueryFlags::MatchPrefab)
.build();
world
.component::<Defense>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let spaceship = world
.prefab()
.set(Health { value: 100 })
.set(Defense { value: 50 });
let inst = world.entity().is_a(spaceship);
inst.get::<&Health>(|health| {
println!("Health value: {}", health.value);
});
inst.get::<&Defense>(|defense| {
println!("Defense value: {}", defense.value);
});
if inst.owns(Defense::id()) {
}
let inherited_from = inst.target(Defense::id(), 0);
if inherited_from.is_none() {
}
world
.component::<Defense>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let spaceship = world.prefab().set(Defense { value: 50 });
let inst_a = world.entity().is_a(spaceship);
let inst_b = world.entity().is_a(spaceship);
inst_a.set(Defense { value: 75 });
world
.component::<Defense>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let spaceship = world.prefab().set(Defense { value: 50 });
let inst_a = world.entity().is_a(spaceship);
let inst_b = world.entity().is_a(spaceship);
inst_a.add(Defense::id());
world
.component::<Defense>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let spaceship = world.prefab().set_auto_override(Defense { value: 50 });
let inst = world.entity().is_a(spaceship);
inst.owns(Defense::id());
let spaceship = world
.prefab_named("spaceship")
.set(Defense { value: 50 })
.set(Health { value: 100 });
let freighter = world
.prefab_named("Freighter")
.is_a(spaceship)
.set(Health { value: 150 });
let inst = world.entity().is_a(freighter);
inst.get::<&Health>(|health| {
println!("Health value: {}", health.value); });
inst.get::<&Defense>(|defense| {
println!("Defense value: {}", defense.value); });
let spaceship = world.prefab_named("Spaceship");
let cockpit = world.prefab_named("Cockpit").child_of(spaceship);
let inst = world.entity().is_a(spaceship);
let inst_cockpit = inst.lookup("Cockpit");
let spaceship = world.prefab_named("Spaceship");
let cockpit = world.prefab_named("Cockpit").child_of(spaceship).slot();
let inst = world.entity().is_a(spaceship);
let inst_cockpit = inst.target(cockpit, 0);
#[derive(Component)]
struct Spaceship;
world
.prefab_type::<Spaceship>()
.set(Defense { value: 50 })
.set(Health { value: 100 });
let inst = world.entity().is_a(Spaceship::id());
let prefab = world.lookup("spaceship");
}
fn flecs_docs_component_traits_compile_test() {
let world = World::new();
let e = world.entity();
let parent = world.entity();
let archer = world.entity();
#[derive(Component)]
struct MyComponent {
e: Entity, }
e.child_of(parent);
world.remove_all(archer);
world.remove_all(archer);
world.remove_all((archer, flecs::Wildcard::ID));
world.remove_all((flecs::Wildcard::ID, archer));
world
.component::<Archer>()
.add_trait::<(flecs::OnDelete, flecs::Remove)>();
let e = world.entity().add(Archer::id());
world.component::<Archer>().destruct();
world
.component::<Archer>()
.add_trait::<(flecs::OnDelete, flecs::Delete)>();
let e = world.entity().add(Archer::id());
world.component::<Archer>().destruct();
world
.component::<flecs::ChildOf>()
.add_trait::<(flecs::OnDeleteTarget, flecs::Delete)>();
let p = world.entity();
let e = world.entity().add((id::<flecs::ChildOf>(), p));
p.destruct();
world
.observer::<flecs::OnRemove, &Node>()
.each_entity(|e, node| {
});
let p = world.entity().add(Node::id());
let c = world.entity().add(Node::id()).child_of(p);
{
#[derive(Component)]
struct Serializable;
world
.component::<Serializable>()
.add_trait::<flecs::Trait>();
}
{
#[derive(Component)]
struct Likes;
#[derive(Component)]
struct Apples;
world
.component::<Likes>()
.add_trait::<flecs::Relationship>();
let e = world
.entity()
.add(Likes::id()) .add((Apples::id(), Likes::id())) .add((Likes::id(), Apples::id())); }
{
#[derive(Component)]
struct Likes;
#[derive(Component)]
struct Loves;
world
.component::<Likes>()
.add_trait::<flecs::Relationship>();
world
.component::<Loves>()
.add_trait::<(flecs::With, Likes)>();
}
#[derive(Component)]
struct Likes;
#[derive(Component)]
struct Apples;
world.component::<Apples>().add_trait::<flecs::Target>();
let e = world
.entity()
.add(Apples::id()) .add((Apples::id(), Likes::id())) .add((Likes::id(), Apples::id()));
#[derive(Component)]
struct Serializable;
#[derive(Component)]
struct Position {
x: f32,
y: f32,
}
let e = world
.entity()
.set(Position { x: 10.0, y: 20.9 })
.add_trait::<(Serializable, Position)>();
e.get::<&Position>(|pos| {
println!("Position: ({}, {})", pos.x, pos.y);
});
e.get::<&(Serializable, Position)>(|pos| {
println!("Serializable Position: ({}, {})", pos.x, pos.y);
});
let e = world.entity().add_trait::<flecs::Final>();
let i = world.entity().is_a(e);
world
.component::<Mass>()
.add_trait::<(flecs::OnInstantiate, flecs::Override)>();
let base = world.entity().set(Mass { value: 100.0 });
let inst = world.entity().is_a(base);
assert!(inst.owns(Mass::id()));
assert!(base.cloned::<&Mass>() != inst.cloned::<&Mass>());
world
.component::<Mass>()
.add_trait::<(flecs::OnInstantiate, flecs::Inherit)>();
let base = world.entity().set(Mass { value: 100.0 });
let inst = world.entity().is_a(base);
assert!(inst.has(Mass::id()));
assert!(!inst.owns(Mass::id()));
assert!(base.cloned::<&Mass>() != inst.cloned::<&Mass>());
world
.component::<Mass>()
.add_trait::<(flecs::OnInstantiate, flecs::DontInherit)>();
let base = world.entity().set(Mass { value: 100.0 });
let inst = world.entity().is_a(base);
assert!(!inst.has(Mass::id()));
assert!(!inst.owns(Mass::id()));
assert!(inst.try_get::<&Mass>(|mass| {}).is_none());
let locatedin = world.entity();
let manhattan = world.entity();
let newyork = world.entity();
let usa = world.entity();
manhattan.add((locatedin, newyork));
newyork.add((locatedin, usa));
locatedin.add_trait::<flecs::Transitive>();
let parent_a = world.entity();
let parent_b = world.entity();
e.child_of(parent_a);
e.child_of(parent_b);
let married_to = world.entity().add_trait::<flecs::Exclusive>();
world
.component::<Position>()
.add_trait::<flecs::CanToggle>();
let e = world.entity().set(Position { x: 10.0, y: 20.0 });
e.disable(Position::id()); assert!(!e.is_enabled(Position::id()));
e.enable(Position::id()); assert!(e.is_enabled(Position::id()));
let walking = world.entity();
let running = world.entity();
world.component::<Position>().add_trait::<flecs::Sparse>();
let married_to = world.entity().add_trait::<flecs::Symmetric>();
let bob = world.entity();
let alice = world.entity();
bob.add((married_to, alice));
let responsibility = world.entity();
let power = world.entity().add((id::<flecs::With>(), responsibility));
let e = world.entity().add(power);
let likes = world.entity();
let loves = world.entity().add_trait::<(flecs::With, Likes)>();
let pears = world.entity();
let e = world.entity().add((loves, pears));
let food = world.entity().add_trait::<flecs::OneOf>();
let apples = world.entity().child_of(food);
let fork = world.entity();
let a = world.entity().add((food, apples));
let b = world.entity().add((food, fork));
let food = world.entity();
let eats = world.entity().add((id::<flecs::OneOf>(), food));
let apples = world.entity().child_of(food);
let fork = world.entity();
let a = world.entity().add((eats, apples));
let b = world.entity().add((eats, fork));
}
fn flecs_docs_remote_api_compile_test() {
let world = World::new();
world.import::<stats::Stats>();
world.set(flecs::rest::Rest::default());
while world.progress() {}
world
.app()
.enable_stats(true)
.enable_rest(0)
.run();
world.import::<stats::Stats>();
world.set(flecs::rest::Rest::default());
while world.progress() {}
}