diff --git a/README.md b/README.md index d924f6fe..e24ea7c5 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ fn main() { .entity_named("Bob") .set(Position { x: 0.0, y: 0.0 }) .set(Velocity { x: 1.0, y: 2.0 }) - .add::<(Eats, Apples)>(); + .add((id::(), id::())); // Show us what you got println!("{}'s got [{:?}]", bob.name(), bob.archetype()); @@ -172,7 +172,7 @@ Some of the features that make Flecs stand out are: * [Builder API] ```rust world.system::<&A>() - .with::() + .with(id::()) .each(|| { }); ``` * [DSL API] diff --git a/flecs_ecs/README.md b/flecs_ecs/README.md index 86260ef8..cc024c95 100644 --- a/flecs_ecs/README.md +++ b/flecs_ecs/README.md @@ -131,7 +131,7 @@ fn main() { .entity_named("Bob") .set(Position { x: 0.0, y: 0.0 }) .set(Velocity { x: 1.0, y: 2.0 }) - .add::<(Eats, Apples)>(); + .add((id::(), id::())); // Show us what you got println!("{}'s got [{:?}]", bob.name(), bob.archetype()); @@ -172,7 +172,7 @@ Some of the features that make Flecs stand out are: * [Builder API] ```rust world.system::<&A>() - .with::() + .with(id::()) .each(|| { }); ``` * [DSL API] diff --git a/flecs_ecs/doc/flecs/src/quickstart.md b/flecs_ecs/doc/flecs/src/quickstart.md index a052cf99..8350b2ee 100644 --- a/flecs_ecs/doc/flecs/src/quickstart.md +++ b/flecs_ecs/doc/flecs/src/quickstart.md @@ -88,7 +88,7 @@ let e = world.entity(); // Add a component. This creates the component in the ECS storage, but does not // assign it with a value. To add a component, it needs to be derived with the // Default trait otherwise it will panic at compile time. -e.add::(); +e.add(id::()); // Set the value for the Position & Velocity components. A component will be // added if the entity doesn't have it yet. @@ -101,7 +101,7 @@ e.get::<&Position>(|p| { }); // Remove component -e.remove::(); +e.remove(id::()); # } ``` @@ -123,7 +123,7 @@ let pos_e = world.entity_from::(); println!("Name: {}", pos_e.name()); // outputs 'Name: Position' // It's possible to add components like you would for any entity -pos_e.add::(); +pos_e.add(id::()); # } ``` @@ -162,21 +162,21 @@ A tag is a component that does not have any data. In Flecs tags are empty types struct Enemy; // Create entity, add Enemy tag -let e = world.entity().add::(); -e.has::(); // true! +let e = world.entity().add(id::()); +e.has(id::()); // true! -e.remove::(); -e.has::(); // false! +e.remove(id::()); +e.has(id::()); // false! // Option 2: create Tag as entity let enemy = world.entity(); // Create entity, add Enemy tag -let e = world.entity().add_id(enemy); -e.has_id(enemy); // true! +let e = world.entity().add(enemy); +e.has(enemy); // true! -e.remove_id(enemy); -e.has_id(enemy); // false! +e.remove(enemy); +e.has(enemy); // false! # } ``` @@ -201,12 +201,12 @@ struct Likes; let bob = world.entity(); let alice = world.entity(); -bob.add_first::(alice); // bob likes alice -alice.add_first::(bob); // alice likes bob -bob.has_first::(alice); // true! +bob.add((id::(), alice)); // bob likes alice +alice.add((id::(), bob)); // alice likes bob +bob.has((id::(), alice)); // true! -bob.remove_first::(alice); -bob.has_first::(alice); // false! +bob.remove((id::(), alice)); +bob.has((id::(), alice)); // false! # } ``` @@ -222,7 +222,7 @@ A pair can be encoded in a single 64 bit identifier using the `world.id_first` f # fn main() { # let world = World::new(); # let bob = world.entity(); -let id = world.id_first::(bob); +let id = world.id_view_from(id::(),bob); # } ``` @@ -239,7 +239,7 @@ The following examples show how to get back the elements from a pair: # # fn main() { # let world = World::new(); -let id = world.id_from::<(Likes, Apples)>(); +let id = world.id_view_from((id::(), id::())); if id.is_pair() { let relationship = id.first_id(); let target = id.second_id(); @@ -260,13 +260,13 @@ A component or tag can be added multiple times to the same entity as long as it # let apples = world.entity(); # let pears = world.entity(); let bob = world.entity(); -bob.add_id((eats, apples)); -bob.add_id((eats, pears)); -bob.add_id((grows, pears)); +bob.add((eats, apples)); +bob.add((eats, pears)); +bob.add((grows, pears)); -bob.has_id((eats, apples)); // true! -bob.has_id((eats, pears)); // true! -bob.has_id((grows, pears)); // true! +bob.has((eats, apples)); // true! +bob.has((eats, pears)); // true! +bob.has((grows, pears)); // true! # } ``` @@ -282,15 +282,15 @@ The `target` function can be used to get the object for a relationship: # fn main() { # let world = World::new(); # let bob = world.entity(); -let alice = world.entity().add_first::(bob); -let o = alice.target::(0); // Returns bob +let alice = world.entity().add((id::(), bob)); +let o = alice.target(id::(),0); // Returns bob # } ``` Entity relationships enable lots of interesting patterns and possibilities. Make sure to check out the [Relationships manual](Relationships.md). ### Hierarchies -Flecs has builtin support for hierarchies with the builtin `ChildOf` relationship. A hierarchy can be created with the regular relationship API or with the `child_of_id` function: +Flecs has builtin support for hierarchies with the builtin `ChildOf` relationship. A hierarchy can be created with the regular relationship API or with the .child_of` function: ```rust # extern crate flecs_ecs; @@ -299,7 +299,7 @@ Flecs has builtin support for hierarchies with the builtin `ChildOf` relationshi # fn main() { # let world = World::new(); let parent = world.entity(); -let child = world.entity().child_of_id(parent); +let child = world.entity().child_of(parent); // Deleting the parent also deletes its children parent.destruct(); @@ -315,7 +315,7 @@ When entities have names, they can be used together with hierarchies to generate # fn main() { # let world = World::new(); let parent = world.entity_named("parent"); -let child = world.entity_named("child").child_of_id(parent); +let child = world.entity_named("child").child_of(parent); println!("Child path: {}", child.path().unwrap()); // output: 'parent::child' @@ -364,7 +364,7 @@ The type (often referred to as "archetype") is the list of ids an entity has. Ty # # fn main() { # let world = World::new(); -let e = world.entity().add::().add::(); +let e = world.entity().add(id::()).add(id::()); println!("Components: {}", e.archetype().to_string().unwrap()); // output: 'Position,Velocity' # } @@ -381,7 +381,7 @@ A type can also be iterated by an application: # # fn main() { # let world = World::new(); -# let e = world.entity().add::(); +# let e = world.entity().add(id::()); e.each_component(|id| { if id == world.component_id::() { // Found Position component! @@ -497,7 +497,7 @@ q.run(|mut it| { let p = it.field::(0).unwrap(); for i in it.iter() { - println!("{}: ({}, {})", it.entity(i).name(), p[i].x, p[i].y); + println!("{}: ({}, {})", it.entity(i).unwrap().name(), p[i].x, p[i].y); } } }); @@ -520,7 +520,7 @@ The following example shows a query that matches all entities with a parent that let q = world .query::<()>() .with::<(flecs::ChildOf, flecs::Wildcard)>() - .with::() + .with(id::()) .set_oper(OperKind::Not) .build(); @@ -579,7 +579,7 @@ Systems are stored as entities with additional components, similar to components # p.y += v.y * it.delta_time(); # }); println!("System: {}", move_sys.name()); -move_sys.add::(); +move_sys.add(id::()); move_sys.destruct(); # } ``` @@ -623,17 +623,17 @@ When a pipeline is executed, systems are ran in the order of the phases. This ma # let world = World::new(); world .system_named::<(&mut Position, &Velocity)>("Move") - .kind::() + .has(id::()) .each(|(p, v)| {}); world .system_named::<(&mut Position, &Transform)>("Transform") - .kind::() + .has(id::()) .each(|(p, t)| {}); world .system_named::<(&Transform, &mut Mesh)>("Render") - .kind::() + .has(id::()) .each(|(t, m)| {}); world.progress(); @@ -659,8 +659,8 @@ Because phases are just tags that are added to systems, applications can use the # p.x += v.x * it.delta_time(); # p.y += v.y * it.delta_time(); # }); -move_sys.add::(); -move_sys.remove::(); +move_sys.add(id::()); +move_sys.remove(id::()); # } ``` diff --git a/flecs_ecs/examples/flecs/entities/entity_basics.rs b/flecs_ecs/examples/flecs/entities/entity_basics.rs index ce6bc3c5..2e013e12 100644 --- a/flecs_ecs/examples/flecs/entities/entity_basics.rs +++ b/flecs_ecs/examples/flecs/entities/entity_basics.rs @@ -28,7 +28,7 @@ fn main() { .set(Position { x: 10.0, y: 20.0 }) // The add operation adds a component without setting a value. This is // useful for tags, or when adding a component with its default value. - .add::(); + .add(id::()); // Get the value for the Position component // - get panics if the component is not present, use try_get for a non-panicking version which does not run the callback. @@ -48,14 +48,14 @@ fn main() { .set(Position { x: 10.0, y: 20.0 }); // Add a tag after entity is created - alice.add::(); + alice.add(id::()); // Print all of the components the entity has. This will output: // Position, Walking, (Identifier,Name) println!("[{}]", alice.archetype()); // Remove tag - alice.remove::(); + alice.remove(id::()); // Iterate all entities with position world.each_entity::<&Position>(|entity, pos| { diff --git a/flecs_ecs/examples/flecs/entities/entity_hierarchy.rs b/flecs_ecs/examples/flecs/entities/entity_hierarchy.rs index 44d90439..5c04566c 100644 --- a/flecs_ecs/examples/flecs/entities/entity_hierarchy.rs +++ b/flecs_ecs/examples/flecs/entities/entity_hierarchy.rs @@ -51,32 +51,32 @@ fn main() { world .entity_named("Mercury") .set(Position { x: 1.0, y: 1.0 }) - .add::() - .child_of_id(sun); // Shortcut for add(flecs::ChildOf, sun) + .add(id::()) + .child_of(sun); // Shortcut for add(flecs::ChildOf, sun) world .entity_named("Venus") .set(Position { x: 2.0, y: 2.0 }) - .add::() - .child_of_id(sun); + .add(id::()) + .child_of(sun); let earth = world .entity_named("Earth") .set(Position { x: 3.0, y: 3.0 }) - .add::() - .child_of_id(sun); + .add(id::()) + .child_of(sun); let moon = world .entity_named("Moon") .set(Position { x: 0.1, y: 0.1 }) - .add::() - .child_of_id(earth); + .add(id::()) + .child_of(earth); // Is the Moon a child of the Earth? println!( "Is the Moon a child of the Earth? {} / {}", - moon.has_id((flecs::ChildOf::ID, earth)), //or you can do - moon.has_first::(earth) + moon.has((flecs::ChildOf::ID, earth)), //or you can do + moon.has((id::(), earth)) ); println!(); diff --git a/flecs_ecs/examples/flecs/entities/entity_hooks.rs b/flecs_ecs/examples/flecs/entities/entity_hooks.rs index 6e26bda2..8abaf15b 100644 --- a/flecs_ecs/examples/flecs/entities/entity_hooks.rs +++ b/flecs_ecs/examples/flecs/entities/entity_hooks.rs @@ -32,7 +32,7 @@ fn main() { // This operation changes the entity's archetype, which invokes a move // add is used for adding tags. - entity.add::(); + entity.add(id::()); entity.destruct(); diff --git a/flecs_ecs/examples/flecs/entities/entity_iterate_components.rs b/flecs_ecs/examples/flecs/entities/entity_iterate_components.rs index 1f9ef6c5..fde7223f 100644 --- a/flecs_ecs/examples/flecs/entities/entity_iterate_components.rs +++ b/flecs_ecs/examples/flecs/entities/entity_iterate_components.rs @@ -67,8 +67,8 @@ fn main() { .entity_named("Bob") .set(Position { x: 10.0, y: 20.0 }) .set(Velocity { x: 1.0, y: 1.0 }) - .add::() - .add::<(Eats, Apples)>(); + .add(id::()) + .add((id::(), id::())); println!("Bob's components:"); iterate_components(bob); diff --git a/flecs_ecs/examples/flecs/entities/entity_prefab.rs b/flecs_ecs/examples/flecs/entities/entity_prefab.rs index 349c5fbe..387562e6 100644 --- a/flecs_ecs/examples/flecs/entities/entity_prefab.rs +++ b/flecs_ecs/examples/flecs/entities/entity_prefab.rs @@ -61,25 +61,25 @@ fn main() { // By default components in an inheritance hierarchy are shared between // entities. The override function ensures that instances have a private // copy of the component. - .auto_override::(); + .auto_override(id::()); let freighter = world .prefab_named("Freighter") - .is_a_id(spaceship) + .is_a(spaceship) .set(FreightCapacity { value: 100.0 }) .set(Defence { value: 100.0 }) - .add::(); + .add(id::()); let mammoth_freighter = world .prefab_named("MammothFreighter") - .is_a_id(freighter) + .is_a(freighter) .set(FreightCapacity { value: 500.0 }) .set(Defence { value: 300.0 }); world .prefab_named("Frigate") - .is_a_id(spaceship) - .add::() + .is_a(spaceship) + .add(id::()) .set(Attack { value: 100.0 }) .set(Defence { value: 75.0 }) .set(ImpulseSpeed { value: 125.0 }); @@ -89,7 +89,7 @@ fn main() { // of the override in the spaceship entity. All other components are shared. let inst = world .entity_named("my_mammoth_freighter") - .is_a_id(mammoth_freighter); + .is_a(mammoth_freighter); // Inspect the type of the entity. This outputs: // Position,(Identifier,Name),(IsA,MammothFreighter) diff --git a/flecs_ecs/examples/flecs/game_mechanics/inventory_system.rs b/flecs_ecs/examples/flecs/game_mechanics/inventory_system.rs index 2bc95fd4..0d5f6441 100644 --- a/flecs_ecs/examples/flecs/game_mechanics/inventory_system.rs +++ b/flecs_ecs/examples/flecs/game_mechanics/inventory_system.rs @@ -73,18 +73,18 @@ fn item_kind(item: EntityView<'_>) -> Option { let world = item.world(); let mut result_entity: Option = None; - item.each_component(|id| { - if id.is_entity() { + item.each_component(|comp| { + if comp.is_entity() { // If id is a plain entity (component), check if component inherits // from Item - if id.entity_view().has::<(flecs::IsA, Item)>() { - result_entity = Some(id.entity_view().id()); + if comp.entity_view().has((id::(), id::())) { + result_entity = Some(comp.entity_view().id()); } - } else if id.is_pair() { + } else if comp.is_pair() { // If item has a base entity, check if the base has an attribute // that is an Item. - if id.first_id() == flecs::IsA::ID { - if let Some(base_kind) = item_kind(id.second_id()) { + if comp.first_id() == flecs::IsA::ID { + if let Some(base_kind) = item_kind(comp.second_id()) { result_entity = Some(base_kind); } } @@ -100,14 +100,14 @@ fn item_name(item: EntityView<'_>) -> Option { let world = item.world(); let mut result_name: Option = None; - item.each_component(|id| { - if id.is_entity() { - if id.entity_view().has::<(flecs::IsA, Item)>() { - result_name = id.entity_view().get_name(); + item.each_component(|comp| { + if comp.is_entity() { + if comp.entity_view().has((id::(), id::())) { + result_name = comp.entity_view().get_name(); } - } else if id.is_pair() && id.first_id() == flecs::IsA::ID { - if let Some(base_kind) = item_kind(id.second_id()) { - result_name = id.second_id().get_name(); + } else if comp.is_pair() && comp.first_id() == flecs::IsA::ID { + if let Some(base_kind) = item_kind(comp.second_id()) { + result_name = comp.second_id().get_name(); } } }); @@ -118,10 +118,10 @@ fn item_name(item: EntityView<'_>) -> Option { /// If entity is not a Container, get its Inventory target (the actual container). fn get_container(container: EntityView<'_>) -> Entity { let world = container.world(); - if container.has::() { + if container.has(id::()) { return container.id(); } - container.target::(0).unwrap().id() + container.target(id::(), 0).unwrap().id() } /// Iterate all items in an inventory @@ -132,7 +132,7 @@ where let world = container.world(); world .query::<()>() - .with_first::(container) + .with((id::(), container)) .build() .each_entity(func); } @@ -153,7 +153,7 @@ fn find_item_w_kind( for_each_item(container, |item, _| { // Check if we should only return active items. This is useful when // searching for an item that needs to be equipped. - if active_required && !item.has::() { + if active_required && !item.has(id::()) { return; } @@ -196,7 +196,7 @@ fn transfer_item(container: EntityView<'_>, item: EntityView<'_>) { } // Move item to target container (replaces previous ContainedBy, if any) - item.add_first::(container); + item.add((id::(), container)); } /// Move all items from `src` container to `dst` container. @@ -396,40 +396,40 @@ impl Module for ItemComponentsModule { world .component::() - .is_a::() + .is_a(id::()) .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); world .component::() - .is_a::() + .is_a(id::()) .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); world .component::() - .is_a::() + .is_a(id::()) .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); //register item prefabs world .prefab_type::() - .add::() + .add(id::()) .set(Attack { value: 1 }) // copy to instance, don't share .set(Health { value: 5 }); world .prefab_type::() - .add::() + .add(id::()) .set(Attack { value: 4 }) .set(Health { value: 10 }); world .prefab_type::() - .add::() + .add(id::()) .set(Health { value: 10 }); world .prefab_type::() - .add::() + .add(id::()) .set(Health { value: 20 }); } } @@ -456,22 +456,23 @@ fn main() { // Create a loot box with items let loot_box = world .entity_named("Chest") - .add::() - .with_first::(|| { - world.entity().is_a::(); - world.entity().is_a::(); - world.entity().add::().set(Amount { amount: 30 }); + .add(id::()) + .with_first(id::(), || { + world.entity().is_a(id::()); + world.entity().is_a(id::()); + world.entity().add(id::()).set(Amount { amount: 30 }); }); // Create a player entity with an inventory - let player = world - .entity_named("Player") - .set(Health { value: 10 }) - .add_first::(world.entity().add::().with_first::( - || { - world.entity().add::().set(Amount { amount: 20 }); - }, - )); + let player = world.entity_named("Player").set(Health { value: 10 }).add(( + id::(), + world + .entity() + .add(id::()) + .with_first(id::(), || { + world.entity().add(id::()).set(Amount { amount: 20 }); + }), + )); // Print items in loot box print_items(loot_box); @@ -490,11 +491,11 @@ fn main() { // Find armor entity & equip it if let Some(armor) = find_item_w_kind(player, world.component_id::(), false) { - world.entity_from_id(armor).add::(); + world.entity_from_id(armor).add(id::()); } // Create a weapon to attack the player with - let my_sword = world.entity().is_a::(); + let my_sword = world.entity().is_a(id::()); // Attack player attack(player, my_sword); diff --git a/flecs_ecs/examples/flecs/hello_world.rs b/flecs_ecs/examples/flecs/hello_world.rs index 74d19044..611c1813 100644 --- a/flecs_ecs/examples/flecs/hello_world.rs +++ b/flecs_ecs/examples/flecs/hello_world.rs @@ -38,7 +38,7 @@ fn main() { .entity_named("Bob") .set(Position { x: 0.0, y: 0.0 }) .set(Velocity { x: 1.0, y: 2.0 }) - .add::<(Eats, Apples)>(); + .add((id::(), id::())); // Show us what you got // println!( "{}'s got [{:?}]", bob.name(), bob.archetype()); diff --git a/flecs_ecs/examples/flecs/observers/observer_basics.rs b/flecs_ecs/examples/flecs/observers/observer_basics.rs index d34e379d..838ac594 100644 --- a/flecs_ecs/examples/flecs/observers/observer_basics.rs +++ b/flecs_ecs/examples/flecs/observers/observer_basics.rs @@ -13,24 +13,28 @@ fn main() { world .observer::() - .with::() + .with(id::()) .each_iter(|it, index, _| { - // We use .with::() because we cannot safely access the component + // We use .with(id::()) because we cannot safely access the component // value here. The component value is uninitialized when the OnAdd event // is emitted, which is UB in Rust. To work around this, we use .with:: - println!(" - OnAdd: {}: {}", it.event_id().to_str(), it.entity(index)); + println!( + " - OnAdd: {}: {}", + it.event_id().to_str(), + it.entity(index).unwrap() + ); }); // Create an observer for three events world .observer::() - .add_event::() //or .add_event_id(OnRemove::ID) + .add_event(id::()) .each_iter(|it, index, pos| { println!( " - {}: {}: {}: with {:?}", it.event().name(), it.event_id().to_str(), - it.entity(index), + it.entity(index).unwrap(), pos ); }); @@ -39,10 +43,10 @@ fn main() { let entity = world.entity_named("e1").set(Position { x: 10.0, y: 20.0 }); // Remove Position (emits EcsOnRemove) - entity.remove::(); + entity.remove(id::()); // Remove Position again (no event emitted) - entity.remove::(); + entity.remove(id::()); // Output: // - OnAdd: Position: e1 diff --git a/flecs_ecs/examples/flecs/observers/observer_custom_event.rs b/flecs_ecs/examples/flecs/observers/observer_custom_event.rs index 9af5d4cb..2be8245a 100644 --- a/flecs_ecs/examples/flecs/observers/observer_custom_event.rs +++ b/flecs_ecs/examples/flecs/observers/observer_custom_event.rs @@ -22,7 +22,7 @@ fn main() { " - {}: {}: {}", it.event().name(), it.event_id().to_str(), - it.entity(index) + it.entity(index).unwrap() ); }); @@ -34,7 +34,7 @@ fn main() { // Emit the custom event. This triggers the observer. world .event() - .add::() + .add(id::()) .entity(entity) .emit(&MyEvent); diff --git a/flecs_ecs/examples/flecs/observers/observer_entity_event.rs b/flecs_ecs/examples/flecs/observers/observer_entity_event.rs index 1ae47b47..478853b6 100644 --- a/flecs_ecs/examples/flecs/observers/observer_entity_event.rs +++ b/flecs_ecs/examples/flecs/observers/observer_entity_event.rs @@ -38,7 +38,7 @@ fn main() { // Create an observer for the CloseRequested event to listen to any entity. world .observer::() - .with::() + .with(id::()) .each_iter(|it, _index, _| { let reason = it.param().reason; println!("Close request with reason: {:?}", reason); diff --git a/flecs_ecs/examples/flecs/observers/observer_monitor.rs b/flecs_ecs/examples/flecs/observers/observer_monitor.rs index d9251af1..6eebaaf0 100644 --- a/flecs_ecs/examples/flecs/observers/observer_monitor.rs +++ b/flecs_ecs/examples/flecs/observers/observer_monitor.rs @@ -34,13 +34,13 @@ fn main() { println!( " - Enter: {}: {}", it.event_id().to_str(), - it.entity(index).name() + it.entity(index).unwrap().name() ); } else if it.event() == flecs::OnRemove::ID { println!( " - Leave: {}: {}", it.event_id().to_str(), - it.entity(index).name() + it.entity(index).unwrap().name() ); } }); @@ -55,7 +55,7 @@ fn main() { entity.set(Velocity { x: 1.0, y: 2.0 }); // This triggers the monitor with EcsOnRemove, as the entity no longer matches. - entity.remove::(); + entity.remove(id::()); // Output: // - Enter: Velocity: e diff --git a/flecs_ecs/examples/flecs/observers/observer_propagate.rs b/flecs_ecs/examples/flecs/observers/observer_propagate.rs index 38611081..20bbf2d2 100644 --- a/flecs_ecs/examples/flecs/observers/observer_propagate.rs +++ b/flecs_ecs/examples/flecs/observers/observer_propagate.rs @@ -32,7 +32,7 @@ fn main() { " - {}: {}: {}: self: {{ {}, {} }}, parent: {{ {}, {} }}", it.event().name(), it.event_id().to_str(), - it.entity(index).name(), + it.entity(index).unwrap().name(), pos_self.x, pos_self.y, pos_parent.x, @@ -42,7 +42,7 @@ fn main() { // Create entity and parent let parent = world.entity_named("p"); - let entity = world.entity_named("e").child_of_id(parent); + let entity = world.entity_named("e").child_of(parent); // Set Position on entity. This doesn't trigger the observer yet, since the // parent doesn't have Position yet. diff --git a/flecs_ecs/examples/flecs/observers/observer_two_components.rs b/flecs_ecs/examples/flecs/observers/observer_two_components.rs index 90a152d6..4196b9e7 100644 --- a/flecs_ecs/examples/flecs/observers/observer_two_components.rs +++ b/flecs_ecs/examples/flecs/observers/observer_two_components.rs @@ -29,7 +29,7 @@ fn main() { " - {}: {}: {}: p: {{ {}, {} }}, v: {{ {}, {} }}", it.event().name(), it.event_id().to_str(), - it.entity(index).name(), + it.entity(index).unwrap().name(), pos.x, pos.y, vel.x, diff --git a/flecs_ecs/examples/flecs/observers/observer_yield_existing.rs b/flecs_ecs/examples/flecs/observers/observer_yield_existing.rs index e46d8ad8..e2204ae5 100644 --- a/flecs_ecs/examples/flecs/observers/observer_yield_existing.rs +++ b/flecs_ecs/examples/flecs/observers/observer_yield_existing.rs @@ -28,7 +28,7 @@ fn main() { " - {}: {}: {}: {{ {}, {} }}", it.event().name(), it.event_id().to_str(), - it.entity(index), + it.entity(index).unwrap(), pos.x, pos.y ); diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_basics.rs b/flecs_ecs/examples/flecs/prefabs/prefab_basics.rs index 8dcf7564..e46ccef0 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_basics.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_basics.rs @@ -37,7 +37,7 @@ fn main() { let spaceship = world.prefab_named("Prefab").set(Defence { value: 50.0 }); // Create a prefab instance - let inst = world.entity_named("my_spaceship").is_a_id(spaceship); + let inst = world.entity_named("my_spaceship").is_a(spaceship); // Because of the IsA relationship, the instance now shares the Defense // component with the prefab, and can be retrieved as a regular component: diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_hierarchy.rs b/flecs_ecs/examples/flecs/prefabs/prefab_hierarchy.rs index b2f76fb3..2b34bc0d 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_hierarchy.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_hierarchy.rs @@ -9,12 +9,12 @@ fn main() { // Create a prefab hierarchy. let spaceship = world.prefab_named("SpaceShip"); - world.prefab_named("Engine").child_of_id(spaceship); - world.prefab_named("Cockpit").child_of_id(spaceship); + world.prefab_named("Engine").child_of(spaceship); + world.prefab_named("Cockpit").child_of(spaceship); // Instantiate the prefab. This also creates an Engine and Cockpit child // for the instance. - let inst = world.entity_named("my_spaceship").is_a_id(spaceship); + let inst = world.entity_named("my_spaceship").is_a(spaceship); // Because of the IsA relationship, the instance now has the Engine and Cockpit // children of the prefab. This means that the instance can look up the Engine diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_nested.rs b/flecs_ecs/examples/flecs/prefabs/prefab_nested.rs index 0b97a562..a619e730 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_nested.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_nested.rs @@ -31,18 +31,18 @@ fn main() { // method, which has the same effect as adding the (ChildOf, Car) pair. let car = world.prefab_named("Car"); car.run_in_scope(|| { - world.prefab_named("FrontLeft").is_a_id(wheel); + world.prefab_named("FrontLeft").is_a(wheel); - world.prefab_named("FrontRight").is_a_id(wheel); + world.prefab_named("FrontRight").is_a(wheel); - world.prefab_named("BackLeft").is_a_id(wheel); + world.prefab_named("BackLeft").is_a(wheel); - world.prefab_named("BackRight").is_a_id(wheel); + world.prefab_named("BackRight").is_a(wheel); }); // Create a prefab instance. let inst_car = world.entity_named("my_car"); - inst_car.is_a_id(car); + inst_car.is_a(car); // Lookup one of the wheels if let Some(inst) = inst_car.try_lookup_recursive("FrontLeft") { diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_override.rs b/flecs_ecs/examples/flecs/prefabs/prefab_override.rs index 12e70093..fffc790a 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_override.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_override.rs @@ -54,7 +54,7 @@ fn main() { .set(Damage { value: 50.0 }); // Create a prefab instance. - let inst = world.entity_named("my_spaceship").is_a_id(spaceship); + let inst = world.entity_named("my_spaceship").is_a(spaceship); // The entity will now have a private copy of the Damage component, but not // of the Attack and Defense components. We can see this when we look at the diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_slots.rs b/flecs_ecs/examples/flecs/prefabs/prefab_slots.rs index 25d4b325..4f89af9a 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_slots.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_slots.rs @@ -32,13 +32,13 @@ fn main() { let spaceship = world.prefab_named("SpaceShip"); let engine = world .prefab_named("Engine") - .child_of_id(spaceship) - .slot_of_id(spaceship); + .child_of(spaceship) + .slot_of(spaceship); let cockpit = world .prefab_named("Cockpit") - .child_of_id(spaceship) - .slot_of_id(spaceship); + .child_of(spaceship) + .slot_of(spaceship); // Add an additional child to the Cockpit prefab to demonstrate how // slots can be different from the parent. This slot could have been @@ -47,16 +47,16 @@ fn main() { let pilot_seat = world .prefab_named("PilotSeat") - .child_of_id(cockpit) - .slot_of_id(spaceship); + .child_of(cockpit) + .slot_of(spaceship); // Create a prefab instance. - let inst = world.entity_named("my_spaceship").is_a_id(spaceship); + let inst = world.entity_named("my_spaceship").is_a(spaceship); // Get the instantiated entities for the prefab slots - let inst_engine = inst.target_id(engine, 0).unwrap(); - let inst_cockpit = inst.target_id(cockpit, 0).unwrap(); - let inst_seat = inst.target_id(pilot_seat, 0).unwrap(); + let inst_engine = inst.target(engine, 0).unwrap(); + let inst_cockpit = inst.target(cockpit, 0).unwrap(); + let inst_seat = inst.target(pilot_seat, 0).unwrap(); println!("instance engine: {}", inst_engine.path().unwrap()); diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_typed.rs b/flecs_ecs/examples/flecs/prefabs/prefab_typed.rs index f160ba47..16aa5a2a 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_typed.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_typed.rs @@ -35,27 +35,27 @@ fn main() { world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); - world.prefab_type::().is_a::(); + world.prefab_type::().is_a(id::()); world .prefab_type::() - .slot_of::() - .child_of::(); + .slot_of(id::()) + .child_of(id::()); // Create prefab instance. - let inst = world.entity_named("my_railgun").is_a::(); + let inst = world.entity_named("my_railgun").is_a(id::()); // Get entities for slots - let inst_base = inst.target::(0).unwrap(); - let inst_head = inst.target::(0).unwrap(); - let inst_beam = inst.target::(0).unwrap(); + let inst_base = inst.target(id::(), 0).unwrap(); + let inst_head = inst.target(id::(), 0).unwrap(); + let inst_beam = inst.target(id::(), 0).unwrap(); println!("instance base: {}", inst_base.path().unwrap()); println!("instance head: {}", inst_head.path().unwrap()); diff --git a/flecs_ecs/examples/flecs/prefabs/prefab_variant.rs b/flecs_ecs/examples/flecs/prefabs/prefab_variant.rs index 278951cc..e846b00f 100644 --- a/flecs_ecs/examples/flecs/prefabs/prefab_variant.rs +++ b/flecs_ecs/examples/flecs/prefabs/prefab_variant.rs @@ -43,20 +43,20 @@ fn main() { // Create a Freighter variant which inherits from SpaceShip let freighter = world .prefab_named("Freighter") - .is_a_id(spaceship) + .is_a(spaceship) .set(FreightCapacity { value: 100.0 }) .set(Defence { value: 50.0 }); // Create a MammotFreighter variant which inherits from Freighter let mammoth_freighter = world .prefab_named("MammothFreighter") - .is_a_id(freighter) + .is_a(freighter) .set(FreightCapacity { value: 500.0 }); // Create a Frigate variant which inherits from SpaceShip world .prefab_named("Frigate") - .is_a_id(spaceship) + .is_a(spaceship) .set(Attack { value: 100.0 }) .set(Defence { value: 75.0 }) .set(ImpulseSpeed { value: 125.0 }); @@ -64,9 +64,7 @@ fn main() { // Create an instance of the MammothFreighter. This entity will inherit the // ImpulseSpeed from SpaceShip, Defence from Freighter and FreightCapacity // from MammothFreighter. - let inst = world - .entity_named("my_freighter") - .is_a_id(mammoth_freighter); + let inst = world.entity_named("my_freighter").is_a(mammoth_freighter); // Add a private Position component. inst.set(Position { x: 10.0, y: 20.0 }); diff --git a/flecs_ecs/examples/flecs/queries/query_chaining_queries.rs b/flecs_ecs/examples/flecs/queries/query_chaining_queries.rs index 8e08c2db..645ea6da 100644 --- a/flecs_ecs/examples/flecs/queries/query_chaining_queries.rs +++ b/flecs_ecs/examples/flecs/queries/query_chaining_queries.rs @@ -39,7 +39,7 @@ fn main() { }); if i % 2 == 0 { - creature.add::(); + creature.add(id::()); } } @@ -54,7 +54,7 @@ fn main() { if i % 2 != 0 { // Differentiate enchantment condition to diversify - artifact.add::(); + artifact.add(id::()); } } @@ -62,7 +62,7 @@ fn main() { let query_creatures = forest.query::<(&Location, &Ability)>().set_cached().build(); // Filter specifically for enchanted things in the world - let mut query_enchanted = forest.query::<()>().with::<&Enchanted>().build(); + let mut query_enchanted = forest.query::<()>().with(id::<&Enchanted>()).build(); // Iterate over creatures to find the enchanted ones query_creatures.run(|mut iter| { @@ -77,7 +77,7 @@ fn main() { .each_iter( |it, index ,_| { let pos = &loc[index]; let abil_power = ability[index].power; - let entity = it.entity(index); + let entity = it.entity(index).unwrap(); println!( "Creature id: {entity} at location {},{} is enchanted with mystical energy, ability power: {} " , pos.x, pos.y, abil_power diff --git a/flecs_ecs/examples/flecs/queries/query_change_tracking_1.rs b/flecs_ecs/examples/flecs/queries/query_change_tracking_1.rs index 088d97a8..3f966450 100644 --- a/flecs_ecs/examples/flecs/queries/query_change_tracking_1.rs +++ b/flecs_ecs/examples/flecs/queries/query_change_tracking_1.rs @@ -89,14 +89,14 @@ fn main() { .entity_named("child") .set(Position { x: 10.0, y: 20.0 }) .set(WorldPosition { x: 0.0, y: 0.0 }) - .child_of_id(parent); + .child_of(parent); let independent = world .entity_named("independent") .set(Position { x: 50.0, y: 30.0 }) .set(WorldPosition { x: 0.0, y: 0.0 }) // this is to make sure independent entity is in a different archetype - .add::(); + .add(id::()); // Since this is the first time the query is iterated, all tables // will show up as changed and not skipped diff --git a/flecs_ecs/examples/flecs/queries/query_change_tracking_2.rs b/flecs_ecs/examples/flecs/queries/query_change_tracking_2.rs index 0bb45b46..b3389f80 100644 --- a/flecs_ecs/examples/flecs/queries/query_change_tracking_2.rs +++ b/flecs_ecs/examples/flecs/queries/query_change_tracking_2.rs @@ -42,7 +42,7 @@ fn main() { let query_write = world .query::<(&Dirty, &mut Position)>() .term_at(0) - .up_type::() // Only match Dirty from prefab + .up_id(id::()) // Only match Dirty from prefab .build(); // Create two prefabs with a Dirty component. We can use this to share a @@ -59,22 +59,22 @@ fn main() { // prefabs, they end up in different tables. world .entity_named("e1_dirty_false") - .is_a_id(prefab_dirty_false) + .is_a(prefab_dirty_false) .set(Position { x: 10.0, y: 20.0 }); world .entity_named("e2_dirty_false") - .is_a_id(prefab_dirty_false) + .is_a(prefab_dirty_false) .set(Position { x: 30.0, y: 40.0 }); world .entity_named("e3_dirty_true") - .is_a_id(prefab_dirty_true) + .is_a(prefab_dirty_true) .set(Position { x: 40.0, y: 50.0 }); world .entity_named("e4_dirty_true") - .is_a_id(prefab_dirty_true) + .is_a(prefab_dirty_true) .set(Position { x: 50.0, y: 60.0 }); // We can use the changed() function on the query to check if any of the diff --git a/flecs_ecs/examples/flecs/queries/query_component_inheritance.rs b/flecs_ecs/examples/flecs/queries/query_component_inheritance.rs index f1935e79..30e15eb9 100644 --- a/flecs_ecs/examples/flecs/queries/query_component_inheritance.rs +++ b/flecs_ecs/examples/flecs/queries/query_component_inheritance.rs @@ -32,30 +32,30 @@ fn main() { // Make the ECS aware of the inheritance relationships. Note that IsA // relationship used here is the same as in the prefab example. - world.component::().is_a::(); - world.component::().is_a::(); - world.component::().is_a::(); + world.component::().is_a(id::()); + world.component::().is_a(id::()); + world.component::().is_a(id::()); - world.component::().is_a::(); - world.component::().is_a::(); - world.component::().is_a::(); - world.component::().is_a::(); + world.component::().is_a(id::()); + world.component::().is_a(id::()); + world.component::().is_a(id::()); + world.component::().is_a(id::()); // Create a few units - world.entity_named("warrior_1").add::(); - world.entity_named("warrior_2").add::(); + world.entity_named("warrior_1").add(id::()); + world.entity_named("warrior_2").add(id::()); - world.entity_named("marksman_1").add::(); - world.entity_named("marksman_2").add::(); + world.entity_named("marksman_1").add(id::()); + world.entity_named("marksman_2").add(id::()); - world.entity_named("wizard_1").add::(); - world.entity_named("wizard_2").add::(); + world.entity_named("wizard_1").add(id::()); + world.entity_named("wizard_2").add(id::()); - world.entity_named("builder_1").add::(); - world.entity_named("builder_2").add::(); + world.entity_named("builder_1").add(id::()); + world.entity_named("builder_2").add(id::()); // Create a rule to find all ranged units - let r = world.query::<()>().with::().build(); + let r = world.query::<()>().with(id::()).build(); // Iterate the rule r.each_entity(|e, rangedunit| { diff --git a/flecs_ecs/examples/flecs/queries/query_cyclic_variables.rs b/flecs_ecs/examples/flecs/queries/query_cyclic_variables.rs index 5cf5c286..fa35bcd3 100644 --- a/flecs_ecs/examples/flecs/queries/query_cyclic_variables.rs +++ b/flecs_ecs/examples/flecs/queries/query_cyclic_variables.rs @@ -15,11 +15,11 @@ fn main() { let john = world.entity_named("John"); let jane = world.entity_named("Jane"); - bob.add_first::(alice); - alice.add_first::(bob); - john.add_first::(jane); - jane.add_first::(john); - bob.add_first::(jane); // inserting a bit of drama + bob.add((id::(), alice)); + alice.add((id::(), bob)); + john.add((id::(), jane)); + jane.add((id::(), john)); + bob.add((id::(), jane)); // inserting a bit of drama // The following rule will only return entities that have a cyclic Likes // relationship- that is they must both like each other. @@ -37,10 +37,10 @@ fn main() { let rule = world .query::<()>() - .with_first_name::<&Likes>("$Y") - .set_src_name("$X") - .with_first_name::<&Likes>("$X") - .set_src_name("$Y") + .with((id::(), "$Y")) + .set_src("$X") + .with((id::(), "$X")) + .set_src("$Y") .build(); // Lookup the index of the variables. This will let us quickly lookup their diff --git a/flecs_ecs/examples/flecs/queries/query_facts.rs b/flecs_ecs/examples/flecs/queries/query_facts.rs index a57fc11c..d8b4a16a 100644 --- a/flecs_ecs/examples/flecs/queries/query_facts.rs +++ b/flecs_ecs/examples/flecs/queries/query_facts.rs @@ -30,11 +30,11 @@ fn main() { let john = world.entity_named("John"); let jane = world.entity_named("Jane"); - bob.add_first::(alice); - alice.add_first::(bob); - john.add_first::(jane); - jane.add_first::(john); - bob.add_first::(jane); // inserting a bit of drama + bob.add((id::(), alice)); + alice.add((id::(), bob)); + john.add((id::(), jane)); + jane.add((id::(), john)); + bob.add((id::(), jane)); // inserting a bit of drama // Create a rule that checks if two entities like each other. By itself this // rule is not a fact, but we can use it to check facts by populating both @@ -49,10 +49,10 @@ fn main() { let mut friends = world .query::<()>() - .with_first_name::<&Likes>("$Y") - .set_src_name("$X") - .with_first_name::<&Likes>("$X") - .set_src_name("$Y") + .with((id::(), "$Y")) + .set_src("$X") + .with((id::(), "$X")) + .set_src("$Y") .build(); let x_var = friends.find_var("X").unwrap(); diff --git a/flecs_ecs/examples/flecs/queries/query_group_by.rs b/flecs_ecs/examples/flecs/queries/query_group_by.rs index 3e1886f9..b4659a5c 100644 --- a/flecs_ecs/examples/flecs/queries/query_group_by.rs +++ b/flecs_ecs/examples/flecs/queries/query_group_by.rs @@ -30,36 +30,36 @@ fn main() { world.component::(); world.component::(); - let query = world.query::<&Position>().group_by::().build(); + let query = world.query::<&Position>().group_by(id::()).build(); world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 1.0, y: 1.0 }); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 2.0, y: 2.0 }); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 3.0, y: 3.0 }); world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 4.0, y: 4.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 5.0, y: 5.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 6.0, y: 6.0 }) - .add::(); + .add(id::()); println!(); diff --git a/flecs_ecs/examples/flecs/queries/query_group_by_callbacks.rs b/flecs_ecs/examples/flecs/queries/query_group_by_callbacks.rs index 3ab1f9ce..f86eae6e 100644 --- a/flecs_ecs/examples/flecs/queries/query_group_by_callbacks.rs +++ b/flecs_ecs/examples/flecs/queries/query_group_by_callbacks.rs @@ -83,7 +83,7 @@ fn main() { // Grouped query let query = world .query::<(&Position,)>() - .group_by::() + .group_by(id::()) // Callback invoked when a new group is created .on_group_create(Some(callback_group_create)) // Callback invoked when a group is deleted @@ -93,32 +93,32 @@ fn main() { // Create entities in 6 different tables with 3 group ids world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 1.0, y: 1.0 }); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 2.0, y: 2.0 }); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 3.0, y: 3.0 }); world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 4.0, y: 4.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 5.0, y: 5.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 6.0, y: 6.0 }) - .add::(); + .add(id::()); println!(); diff --git a/flecs_ecs/examples/flecs/queries/query_group_by_custom.rs b/flecs_ecs/examples/flecs/queries/query_group_by_custom.rs index cd4189ac..3b15f494 100644 --- a/flecs_ecs/examples/flecs/queries/query_group_by_custom.rs +++ b/flecs_ecs/examples/flecs/queries/query_group_by_custom.rs @@ -54,38 +54,38 @@ fn main() { // Grouped query let query = world .query::<&Position>() - .group_by_fn::(Some(callback_group_by_relationship)) + .group_by_fn(id::(), Some(callback_group_by_relationship)) .build(); // Create entities in 6 different tables with 3 group ids world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 1.0, y: 1.0 }); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 2.0, y: 2.0 }); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 3.0, y: 3.0 }); world .entity() - .add::<(Group, Third)>() + .add((id::(), id::())) .set(Position { x: 4.0, y: 4.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, Second)>() + .add((id::(), id::())) .set(Position { x: 5.0, y: 5.0 }) - .add::(); + .add(id::()); world .entity() - .add::<(Group, First)>() + .add((id::(), id::())) .set(Position { x: 6.0, y: 6.0 }) - .add::(); + .add(id::()); println!(); diff --git a/flecs_ecs/examples/flecs/queries/query_group_iter.rs b/flecs_ecs/examples/flecs/queries/query_group_iter.rs index d9e12722..9b1f5360 100644 --- a/flecs_ecs/examples/flecs/queries/query_group_iter.rs +++ b/flecs_ecs/examples/flecs/queries/query_group_iter.rs @@ -55,50 +55,50 @@ fn main() { // Create npc's in world cell 0_0 world .entity() - .add::<(WorldCell, Cell_0_0)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); world .entity() - .add::<(WorldCell, Cell_0_0)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); // Create npc's in world cell 0_1 world .entity() - .add::<(WorldCell, Cell_0_1)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); world .entity() - .add::<(WorldCell, Cell_0_1)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); // Create npc's in world cell 1_0 world .entity() - .add::<(WorldCell, Cell_1_0)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); world .entity() - .add::<(WorldCell, Cell_1_0)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); // Create npc's in world cell 1_1 world .entity() - .add::<(WorldCell, Cell_1_1)>() - .add::() - .add::(); + .add((id::(), id::())) + .add(id::()) + .add(id::()); let mut query = world .query::<()>() - .with::<&Npc>() - .group_by::() + .with(id::<&Npc>()) + .group_by(id::()) .build(); // Iterate all tables @@ -119,7 +119,7 @@ fn main() { println!("Tables for cell 1_0:"); - query.set_group::().run(|mut iter| { + query.set_group(id::()).run(|mut iter| { while iter.next() { let world = iter.world(); let group = world.entity_from_id(iter.group_id()); diff --git a/flecs_ecs/examples/flecs/queries/query_hierarchy.rs b/flecs_ecs/examples/flecs/queries/query_hierarchy.rs index aeb142ae..a995f7bb 100644 --- a/flecs_ecs/examples/flecs/queries/query_hierarchy.rs +++ b/flecs_ecs/examples/flecs/queries/query_hierarchy.rs @@ -24,25 +24,25 @@ fn main() { world .entity_named("Mercury") - .child_of_id(sun) + .child_of(sun) .set_pair::(Position::default()) .set_pair::(Position { x: 1.0, y: 1.0 }); world .entity_named("Venus") - .child_of_id(sun) + .child_of(sun) .set_pair::(Position::default()) .set_pair::(Position { x: 2.0, y: 2.0 }); let earth = world .entity_named("Earth") - .child_of_id(sun) + .child_of(sun) .set_pair::(Position::default()) .set_pair::(Position { x: 3.0, y: 3.0 }); world .entity_named("Moon") - .child_of_id(earth) + .child_of(earth) .set_pair::(Position::default()) .set_pair::(Position { x: 0.1, y: 0.1 }); diff --git a/flecs_ecs/examples/flecs/queries/query_run.rs b/flecs_ecs/examples/flecs/queries/query_run.rs index 7cf4e20e..c5aff86a 100644 --- a/flecs_ecs/examples/flecs/queries/query_run.rs +++ b/flecs_ecs/examples/flecs/queries/query_run.rs @@ -66,7 +66,11 @@ fn main() { for i in it.iter() { position[i].x += velocity[i].x; position[i].y += velocity[i].y; - println!(" - entity {}: has {:?}", it.entity(i).name(), position[i]); + println!( + " - entity {}: has {:?}", + it.entity(i).unwrap().name(), + position[i] + ); } println!(); diff --git a/flecs_ecs/examples/flecs/queries/query_setting_variables.rs b/flecs_ecs/examples/flecs/queries/query_setting_variables.rs index 8fcf773f..aa26db75 100644 --- a/flecs_ecs/examples/flecs/queries/query_setting_variables.rs +++ b/flecs_ecs/examples/flecs/queries/query_setting_variables.rs @@ -44,13 +44,13 @@ fn main() { // Make the ECS aware of the inheritance relationships. Note that IsA // relationship used here is the same as in the prefab example. - world.component::().is_a::(); - world.component::().is_a::(); - world.component::().is_a::(); + world.component::().is_a(id::()); + world.component::().is_a(id::()); + world.component::().is_a(id::()); - world.component::().is_a::(); - world.component::().is_a::(); - world.component::().is_a::(); + world.component::().is_a(id::()); + world.component::().is_a(id::()); + world.component::().is_a(id::()); // Populate store with players and platoons for p in 0..PLAYER_COUNT { @@ -62,25 +62,28 @@ fn main() { }; // Add player tag so we can query for all players if we want to - player.add::(); + player.add(id::()); for _ in 0..PLATOONS_PER_PLAYER { let platoon = world .entity() - .add_first::(player) + .add((id::(), player)) // Add platoon tag so we can query for all platoons if we want to - .add::(); + .add(id::()); // Add warriors, wizards and marksmen to the platoon world .entity() - .add::() - .add_first::(platoon); + .add(id::()) + .add((id::(), platoon)); world .entity() - .add::() - .add_first::(platoon); - world.entity().add::().add_first::(platoon); + .add(id::()) + .add((id::(), platoon)); + world + .entity() + .add(id::()) + .add((id::(), platoon)); } } @@ -93,11 +96,11 @@ fn main() { // - check if _Platoon has (Player, *), store * in _Player let mut query = world .query::<()>() - .with::() - .with::<&Platoon>() - .set_second_name("$platoon") - .with_first_name::<&Player>("$player") - .set_src_name("$platoon") + .with(id::()) + .with(id::<&Platoon>()) + .set_second("$platoon") + .with((id::(), "$player")) + .set_src("$platoon") .build(); // If we would iterate this query it would return all ranged units for all @@ -112,7 +115,7 @@ fn main() { query .set_var(player_var, world.lookup_recursive("MyPlayer")) .each_iter(|it, index, _| { - let unit = it.entity(index); + let unit = it.entity(index).unwrap(); println!( "Unit id: {} of class {} in platoon id: {} for player {}", unit, diff --git a/flecs_ecs/examples/flecs/queries/query_transitive_queries.rs b/flecs_ecs/examples/flecs/queries/query_transitive_queries.rs index 037f1385..b69d7c6f 100644 --- a/flecs_ecs/examples/flecs/queries/query_transitive_queries.rs +++ b/flecs_ecs/examples/flecs/queries/query_transitive_queries.rs @@ -39,80 +39,82 @@ fn main() { let world = World::new(); // Register the LocatedIn relationship as transitive - world.component::().add::(); + world + .component::() + .add(id::()); // Populate the store with locations - let earth = world.entity_named("Earth").add::(); + let earth = world.entity_named("Earth").add(id::()); // Continents let north_america = world .entity_named("NorthAmerica") - .add::() - .add_first::(earth); + .add(id::()) + .add((id::(), earth)); let europe = world .entity_named("Europe") - .add::() - .add_first::(earth); + .add(id::()) + .add((id::(), earth)); // Countries let united_states = world .entity_named("UnitedStates") - .add::() - .add_first::(north_america); + .add(id::()) + .add((id::(), north_america)); let netherlands = world .entity_named("Netherlands") - .add::() - .add_first::(europe); + .add(id::()) + .add((id::(), europe)); // States let california = world .entity_named("California") - .add::() - .add_first::(united_states); + .add(id::()) + .add((id::(), united_states)); let washington = world .entity_named("Washington") - .add::() - .add_first::(united_states); + .add(id::()) + .add((id::(), united_states)); let noord_holland = world .entity_named("NoordHolland") - .add::() - .add_first::(netherlands); + .add(id::()) + .add((id::(), netherlands)); // Cities let san_francisco = world .entity_named("SanFrancisco") - .add::() - .add_first::(california); + .add(id::()) + .add((id::(), california)); let seattle = world .entity_named("Seattle") - .add::() - .add_first::(washington); + .add(id::()) + .add((id::(), washington)); let amsterdam = world .entity_named("Amsterdam") - .add::() - .add_first::(noord_holland); + .add(id::()) + .add((id::(), noord_holland)); // Inhabitants world .entity_named("Bob") - .add::() - .add_first::(san_francisco); + .add(id::()) + .add((id::(), san_francisco)); world .entity_named("Alice") - .add::() - .add_first::(seattle); + .add(id::()) + .add((id::(), seattle)); world .entity_named("Job") - .add::() - .add_first::(amsterdam); + .add(id::()) + .add((id::(), amsterdam)); // Create a query that finds the countries persons live in. Note that these // have not been explicitly added to the Person entities, but because the @@ -124,10 +126,10 @@ fn main() { let query = world .query::<()>() - .with::<&Person>() - .with_first_name::<&LocatedIn>("$Location") - .with::<&Country>() - .set_src_name("$Location") + .with(id::<&Person>()) + .with((id::(), "$Location")) + .with(id::<&Country>()) + .set_src("$Location") .build(); // Lookup the index of the variable. This will let us quickly lookup its @@ -136,7 +138,11 @@ fn main() { // Iterate the query query.each_iter(|it, index, _| { - println!("{} lives in {}", it.entity(index), it.get_var(location_var)); + println!( + "{} lives in {}", + it.entity(index).unwrap(), + it.get_var(location_var) + ); }); // Output: diff --git a/flecs_ecs/examples/flecs/queries/query_variables.rs b/flecs_ecs/examples/flecs/queries/query_variables.rs index eab86886..280a2e86 100644 --- a/flecs_ecs/examples/flecs/queries/query_variables.rs +++ b/flecs_ecs/examples/flecs/queries/query_variables.rs @@ -11,23 +11,23 @@ struct Healthy; fn main() { let world = World::new(); - let apples = world.entity_named("Apples").add::(); - let salad = world.entity_named("Salad").add::(); + let apples = world.entity_named("Apples").add(id::()); + let salad = world.entity_named("Salad").add(id::()); let burgers = world.entity_named("Burgers"); let pizza = world.entity_named("Pizza"); let chocolate = world.entity_named("Chocolate"); world .entity_named("Bob") - .add_first::(apples) - .add_first::(burgers) - .add_first::(pizza); + .add((id::(), apples)) + .add((id::(), burgers)) + .add((id::(), pizza)); world .entity_named("Alice") - .add_first::(salad) - .add_first::(chocolate) - .add_first::(apples); + .add((id::(), salad)) + .add((id::(), chocolate)) + .add((id::(), apples)); // Here we're creating a rule that in the query DSL would look like this: // Eats($This, $Food), Healthy($Food) @@ -46,9 +46,9 @@ fn main() { // // By replacing * with _Food, both terms are constrained to use the // same entity. - .with_first_name::<&Eats>("$food") - .with::<&Healthy>() - .set_src_name("$food") + .with((id::(), "$food")) + .with(id::<&Healthy>()) + .set_src("$food") .build(); // Lookup the index of the variable. This will let us quickly lookup its @@ -59,7 +59,7 @@ fn main() { rule.each_iter(|it, index, ()| { println!( "{} eats {}", - it.entity(index).name(), + it.entity(index).unwrap().name(), it.get_var(food_var.unwrap()).name() ); }); diff --git a/flecs_ecs/examples/flecs/queries/query_wildcard.rs b/flecs_ecs/examples/flecs/queries/query_wildcard.rs index 236cd04c..8cceefe3 100644 --- a/flecs_ecs/examples/flecs/queries/query_wildcard.rs +++ b/flecs_ecs/examples/flecs/queries/query_wildcard.rs @@ -33,7 +33,7 @@ fn main() { // Iterate the query with a flecs::iter. This makes it possible to inspect // the pair that we are currently matched with. query.each_iter(|it, index, eats| { - let entity = it.entity(index); + let entity = it.entity(index).unwrap(); let pair = it.pair(0).unwrap(); let food = pair.second_id(); diff --git a/flecs_ecs/examples/flecs/queries/query_with.rs b/flecs_ecs/examples/flecs/queries/query_with.rs index 81e1e8e0..45427601 100644 --- a/flecs_ecs/examples/flecs/queries/query_with.rs +++ b/flecs_ecs/examples/flecs/queries/query_with.rs @@ -19,18 +19,18 @@ fn main() { // result does not become part of the function signatures of each and iter. // This is useful for things like tags, which because they don't have a // value are less useful to pass to the each/iter functions as argument. - let query = world.query::<&Position>().with::<&Npc>().build(); + let query = world.query::<&Position>().with(id::<&Npc>()).build(); // Create a few test entities for the Position, Npc query world .entity_named("e1") .set(Position { x: 10.0, y: 20.0 }) - .add::(); + .add(id::()); world .entity_named("e2") .set(Position { x: 10.0, y: 20.0 }) - .add::(); + .add(id::()); // This entity will not match as it does not have Position, Npc world.entity_named("e3").set(Position { x: 10.0, y: 20.0 }); diff --git a/flecs_ecs/examples/flecs/queries/query_without.rs b/flecs_ecs/examples/flecs/queries/query_without.rs index d28d9283..d84006c6 100644 --- a/flecs_ecs/examples/flecs/queries/query_without.rs +++ b/flecs_ecs/examples/flecs/queries/query_without.rs @@ -22,7 +22,7 @@ fn main() { // // The without method is short for: // .term().not_() - let query = world.query::<&Position>().without::<&Npc>().build(); + let query = world.query::<&Position>().without(id::()).build(); // Create a few test entities for the Position query world.entity_named("e1").set(Position { x: 10.0, y: 20.0 }); @@ -33,7 +33,7 @@ fn main() { world .entity_named("e3") .set(Position { x: 10.0, y: 20.0 }) - .add::(); + .add(id::()); // Note how the Npc tag is not part of the each signature query.each_entity(|entity, pos| { diff --git a/flecs_ecs/examples/flecs/reflection/entity_type.rs b/flecs_ecs/examples/flecs/reflection/entity_type.rs index 8de34b5e..087ba0f9 100644 --- a/flecs_ecs/examples/flecs/reflection/entity_type.rs +++ b/flecs_ecs/examples/flecs/reflection/entity_type.rs @@ -16,7 +16,7 @@ fn main() { world.component::().meta(); /* Alternatively, you can do it manually like so (without the derive macro) - .member::("e", 1, core::mem::offset_of!(TypeWithEntity, e)); + .member(id::(),"e", 1, core::mem::offset_of!(TypeWithEntity, e)); */ let bar = world.entity_named("bar"); diff --git a/flecs_ecs/examples/flecs/reflection/reflection_basics.rs b/flecs_ecs/examples/flecs/reflection/reflection_basics.rs index d649d28a..a584a6be 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_basics.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_basics.rs @@ -16,8 +16,8 @@ fn main() { world.component::().meta(); /* Alternatively, you can do it manually like so (without the derive macro) - .member::("x", 1 /* count */, core::mem::offset_of!(Position, x)) - .member::("y", 1, core::mem::offset_of!(Position, y)); + .member(id::(),"x", 1 /* count */, core::mem::offset_of!(Position, x)) + .member(id::(),"y", 1, core::mem::offset_of!(Position, y)); */ // Create a new entity diff --git a/flecs_ecs/examples/flecs/reflection/reflection_basics_bitmask.rs b/flecs_ecs/examples/flecs/reflection/reflection_basics_bitmask.rs index 05ba98a8..6a3ee3b9 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_basics_bitmask.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_basics_bitmask.rs @@ -63,7 +63,9 @@ fn main() { .bit("lettuce", Toppings::LETTUCE) .bit("tomato", Toppings::TOMATO); - world.component::().member::("toppings"); + world + .component::() + .member(id::(), "toppings"); // Create entity with Sandwich let e = world.entity().set(Sandwich { diff --git a/flecs_ecs/examples/flecs/reflection/reflection_basics_deserialize.rs b/flecs_ecs/examples/flecs/reflection/reflection_basics_deserialize.rs index 0b4fa536..71f9d05c 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_basics_deserialize.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_basics_deserialize.rs @@ -16,12 +16,12 @@ fn main() { world.component::().meta(); /* Alternatively, you can do it manually like so (without the derive macro) - .member::("x", 1 /* count */, core::mem::offset_of!(Position, x)) - .member::("y", 1, core::mem::offset_of!(Position, y)); + .member(id::(),"x", 1 /* count */, core::mem::offset_of!(Position, x)) + .member(id::(),"y", 1, core::mem::offset_of!(Position, y)); */ // Create a new entity, set value of position using reflection API - let e = world.entity().add::(); + let e = world.entity().add(id::()); e.get::<&mut Position>(|pos| { let mut cur = world.cursor::(pos); diff --git a/flecs_ecs/examples/flecs/reflection/reflection_basics_json.rs b/flecs_ecs/examples/flecs/reflection/reflection_basics_json.rs index f0c7ede9..4bba9ba6 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_basics_json.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_basics_json.rs @@ -16,8 +16,8 @@ fn main() { world.component::().meta(); /* Alternatively, you can do it manually like so (without the derive macro) - .member::("x", 1 /* count */, core::mem::offset_of!(Position, x)) - .member::("y", 1, core::mem::offset_of!(Position, y)); + .member(id::(),"x", 1 /* count */, core::mem::offset_of!(Position, x)) + .member(id::(),"y", 1, core::mem::offset_of!(Position, y)); */ // Create a new entity with the Position component diff --git a/flecs_ecs/examples/flecs/reflection/reflection_basics_simple_enum.rs b/flecs_ecs/examples/flecs/reflection/reflection_basics_simple_enum.rs index 4bc2e457..efaf5bc3 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_basics_simple_enum.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_basics_simple_enum.rs @@ -32,7 +32,7 @@ fn main() { world.component::().meta(); /* Alternatively, you can do it manually like so (without the derive macro) - .member::("color", 1, core::mem::offset_of!(TypeWithEnum, color)); + .member(id::(),"color", 1, core::mem::offset_of!(TypeWithEnum, color)); */ // Create a new entity diff --git a/flecs_ecs/examples/flecs/reflection/reflection_nested_set_member.rs b/flecs_ecs/examples/flecs/reflection/reflection_nested_set_member.rs index 33153f4b..043b558f 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_nested_set_member.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_nested_set_member.rs @@ -24,7 +24,7 @@ fn main() { world.component::().meta(); // Create entity, set value of Line using reflection API - let e = world.entity().add::(); + let e = world.entity().add(id::()); e.get::<&mut Line>(|line| { let mut cur = world.cursor(line); diff --git a/flecs_ecs/examples/flecs/reflection/reflection_runtime_component.rs b/flecs_ecs/examples/flecs/reflection/reflection_runtime_component.rs index 14ffe3d6..23279299 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_runtime_component.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_runtime_component.rs @@ -7,8 +7,8 @@ fn main() { let position = world .component_untyped_named("Position") - .member::("x") - .member::("y"); + .member(id::(), "x") + .member(id::(), "y"); // Create entity let e = world.entity(); diff --git a/flecs_ecs/examples/flecs/reflection/reflection_runtime_nested_component.rs b/flecs_ecs/examples/flecs/reflection/reflection_runtime_nested_component.rs index 4cb58524..647515de 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_runtime_nested_component.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_runtime_nested_component.rs @@ -7,16 +7,16 @@ fn main() { let point = world .component_untyped_named("Point") - .member::("x") - .member::("y"); + .member(id::(), "x") + .member(id::(), "y"); let line = world .component_untyped_named("Line") - .member_id(point, "start") - .member_id(point, "stop"); + .member(point, "start") + .member(point, "stop"); // Create entity, set value of line using reflection API - let e = world.entity().add_id(line); + let e = world.entity().add(line); let ptr = e.get_untyped_mut(line); diff --git a/flecs_ecs/examples/flecs/reflection/reflection_ser_opaque_type.rs b/flecs_ecs/examples/flecs/reflection/reflection_ser_opaque_type.rs index 039c64f3..a82cf661 100644 --- a/flecs_ecs/examples/flecs/reflection/reflection_ser_opaque_type.rs +++ b/flecs_ecs/examples/flecs/reflection/reflection_ser_opaque_type.rs @@ -21,9 +21,9 @@ fn main() { .opaque_id( world .component_untyped() - .member::("a") - .member::("b") - .member::("result"), + .member(id::(), "a") + .member(id::(), "b") + .member(id::(), "result"), ) // Forward struct members to serializer .serialize(|s: &Serializer, data: &Sum| { diff --git a/flecs_ecs/examples/flecs/relationships/relationships_basics.rs b/flecs_ecs/examples/flecs/relationships/relationships_basics.rs index 1bf8090a..882bbcbd 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_basics.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_basics.rs @@ -20,20 +20,20 @@ fn main() { let bob = world .entity_named("Bob") // Pairs can be constructed from a type and entity - .add_first::(apples) - .add_first::(pears) + .add((id::(), apples)) + .add((id::(), pears)) // Pairs can also be constructed from two entity ids - .add_id((grows, pears)); + .add((grows, pears)); // Has can be used with relationships as well - println!("Bob eats apples? {}", bob.has_first::(apples)); + println!("Bob eats apples? {}", bob.has((id::(), apples))); // Wildcards can be used to match relationships println!( "Bob grows food? {}, {}", - bob.has_id((grows, flecs::Wildcard::ID)), + bob.has((grows, flecs::Wildcard::ID)), //or you can do - bob.has_second::(grows) + bob.has((grows, id::())) ); println!(); @@ -45,7 +45,7 @@ fn main() { println!(); // Relationships can be iterated for an entity. This iterates (Eats, *): - bob.each_target::(|second| { + bob.each_target(id::(), |second| { println!("Bob eats {}", second.name()); }); @@ -59,10 +59,13 @@ fn main() { println!(); // Get first target of relationship - println!("Bob eats {}", bob.target::(0).unwrap().name()); + println!("Bob eats {}", bob.target(id::(), 0).unwrap().name()); // Get second target of relationship - println!("Bob also eats {}", bob.target::(1).unwrap().name()); + println!( + "Bob also eats {}", + bob.target(id::(), 1).unwrap().name() + ); // Output: // Bob eats apples? true diff --git a/flecs_ecs/examples/flecs/relationships/relationships_component_data.rs b/flecs_ecs/examples/flecs/relationships/relationships_component_data.rs index 32ce26be..80934cfb 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_component_data.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_component_data.rs @@ -78,7 +78,7 @@ fn main() { println!( "{}", world - .id_from::<(Requires, Gigawatts)>() + .id_view_from((id::(), id::())) .type_id() .path() .unwrap() @@ -86,7 +86,7 @@ fn main() { println!( "{}", world - .id_from::<(Gigawatts, Requires)>() + .id_view_from((id::(), id::())) .type_id() .path() .unwrap() @@ -94,7 +94,7 @@ fn main() { println!( "{}", world - .id_from::<(Expires, Position)>() + .id_view_from((id::(), id::())) .type_id() .path() .unwrap() diff --git a/flecs_ecs/examples/flecs/relationships/relationships_enum.rs b/flecs_ecs/examples/flecs/relationships/relationships_enum.rs index 7cc6d41b..d5052b9f 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_enum.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_enum.rs @@ -55,11 +55,8 @@ fn main() { println!(); // Check if the entity has the Tile relationship and the Tile::Stone pair - println!("has tile enum: {}", tile.has::()); // true - println!( - "is the enum from tile stone?: {}", - tile.has_enum(Tile::Stone) - ); // true + println!("has tile enum: {}", tile.has(id::())); // true + println!("is the enum from tile stone?: {}", tile.has(Tile::Stone)); // true // Get the current value of the enum tile.try_get::<&Tile>(|tile| { @@ -116,7 +113,7 @@ fn main() { println!(); // Remove any instance of the TileStatus relationship - tile.remove::(); + tile.remove(id::()); // (Tile, Tile.Stone) println!("{:?}", tile.archetype()); diff --git a/flecs_ecs/examples/flecs/relationships/relationships_exclusive.rs b/flecs_ecs/examples/flecs/relationships/relationships_exclusive.rs index 10b233c5..47b45fb3 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_exclusive.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_exclusive.rs @@ -10,7 +10,7 @@ fn main() { // Register Platoon as exclusive relationship. This ensures that an entity // can only belong to a single Platoon. - world.component::().add::(); + world.component::().add(id::()); // Create two platoons let platoon_1 = world.entity(); @@ -20,16 +20,16 @@ fn main() { let unit = world.entity(); // Add unit to platoon 1 - unit.add_first::(platoon_1); + unit.add((id::(), platoon_1)); // Log platoon of unit println!( "Unit in platoon 1: {}", - unit.has_first::(platoon_1) + unit.has((id::(), platoon_1)) ); // true println!( "Unit in platoon 2: {}", - unit.has_first::(platoon_2) + unit.has((id::(), platoon_2)) ); // false println!(); @@ -37,16 +37,16 @@ fn main() { // Add unit to platoon 2. Because Platoon is an exclusive relationship, this // both removes (Platoon, platoon_1) and adds (Platoon, platoon_2) in a // single operation. - unit.add_first::(platoon_2); + unit.add((id::(), platoon_2)); // Log platoon of unit println!( "Unit in platoon 1: {}", - unit.has_first::(platoon_1) + unit.has((id::(), platoon_1)) ); // false println!( "Unit in platoon 2: {}", - unit.has_first::(platoon_2) + unit.has((id::(), platoon_2)) ); // true // Output: diff --git a/flecs_ecs/examples/flecs/relationships/relationships_symmetric.rs b/flecs_ecs/examples/flecs/relationships/relationships_symmetric.rs index f4fb104e..474426b8 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_symmetric.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_symmetric.rs @@ -9,7 +9,9 @@ fn main() { // Register TradesWith as symmetric relationship. Symmetric relationships // go both ways, adding (R, B) to A will also add (R, A) to B. - world.component::().add::(); + world + .component::() + .add(id::()); // Create two players let player_1 = world.entity(); @@ -17,16 +19,16 @@ fn main() { // Add (TradesWith, player_2) to player_1. This also adds // (TradesWith, player_1) to player_2. - player_1.add_first::(player_2); + player_1.add((id::(), player_2)); // Log platoon of unit println!( "Player 1 trades with Player 2: {}", - player_1.has_first::(player_2) + player_1.has((id::(), player_2)) ); // true println!( "Player 2 trades with Player 1: {}", - player_2.has_first::(player_1) + player_2.has((id::(), player_1)) ); // true // Output: diff --git a/flecs_ecs/examples/flecs/relationships/relationships_union.rs b/flecs_ecs/examples/flecs/relationships/relationships_union.rs index ddfa9e18..189a98ad 100644 --- a/flecs_ecs/examples/flecs/relationships/relationships_union.rs +++ b/flecs_ecs/examples/flecs/relationships/relationships_union.rs @@ -37,8 +37,8 @@ fn main() { // Register Movement and Direction as union relationships. This ensures that // an entity can only have one Movement and one Direction. - world.component::().add::(); - world.component::().add::(); + world.component::().add(id::()); + world.component::().add(id::()); // Create a query that subscribes for all entities that have a Direction // and that are walking. @@ -69,7 +69,7 @@ fn main() { // Iterate the query q.each_iter(|it, index, ()| { - let entity = it.entity(index); + let entity = it.entity(index).unwrap(); // Movement will always be Walking, Direction can be any state println!( diff --git a/flecs_ecs/examples/flecs/systems/system_ctx.rs b/flecs_ecs/examples/flecs/systems/system_ctx.rs index 4a4ae07b..13fc8090 100644 --- a/flecs_ecs/examples/flecs/systems/system_ctx.rs +++ b/flecs_ecs/examples/flecs/systems/system_ctx.rs @@ -52,7 +52,7 @@ fn main() { .set_context(&mut query_collide as *mut Query<(&Position, &Radius)> as *mut c_void) .each_iter(|mut it, index, (p1, r1)| { let query = unsafe { it.context::>() }; - let e1 = it.entity(index); + let e1 = it.entity(index).unwrap(); query.each_entity(|e2, (p2, r2)| { if e1 == *e2 { diff --git a/flecs_ecs/examples/flecs/systems/system_custom_phases.rs b/flecs_ecs/examples/flecs/systems/system_custom_phases.rs index 35b8062d..263c3a5e 100644 --- a/flecs_ecs/examples/flecs/systems/system_custom_phases.rs +++ b/flecs_ecs/examples/flecs/systems/system_custom_phases.rs @@ -20,28 +20,28 @@ fn main() { // to discover which systems it should run. let physics = world .entity() - .add::() - .depends_on::(); + .add(id::()) + .depends_on(id::()); let collisions = world .entity() - .add::() - .depends_on_id(physics); + .add(id::()) + .depends_on(physics); // Create 3 dummy systems. world .system_named::<()>("CollisionSystem") - .kind_id(collisions) + .kind(collisions) .run(sys); world .system_named::<()>("PhysicsSystem") - .kind_id(physics) + .kind(physics) .run(sys); world .system_named::<()>("GameSystem") - .kind::() + .kind(id::()) .run(sys); // Run pipeline diff --git a/flecs_ecs/examples/flecs/systems/system_custom_phases_no_builtin.rs b/flecs_ecs/examples/flecs/systems/system_custom_phases_no_builtin.rs index 2d64000b..897962ca 100644 --- a/flecs_ecs/examples/flecs/systems/system_custom_phases_no_builtin.rs +++ b/flecs_ecs/examples/flecs/systems/system_custom_phases_no_builtin.rs @@ -19,33 +19,30 @@ fn main() { // which is necessary for the builtin pipeline to discover which systems it // should run. - let update = world.entity().add::(); + let update = world.entity().add(id::()); let physics = world .entity() - .add::() - .depends_on_id(update); + .add(id::()) + .depends_on(update); let collisions = world .entity() - .add::() - .depends_on_id(physics); + .add(id::()) + .depends_on(physics); // Create 3 dummy systems. world .system_named::<()>("CollisionSystem") - .kind_id(collisions) + .kind(collisions) .run(sys); world .system_named::<()>("PhysicsSystem") - .kind_id(physics) + .kind(physics) .run(sys); - world - .system_named::<()>("GameSystem") - .kind_id(update) - .run(sys); + world.system_named::<()>("GameSystem").kind(update).run(sys); // Run pipeline world.progress(); diff --git a/flecs_ecs/examples/flecs/systems/system_custom_pipeline.rs b/flecs_ecs/examples/flecs/systems/system_custom_pipeline.rs index 06f56812..45758106 100644 --- a/flecs_ecs/examples/flecs/systems/system_custom_pipeline.rs +++ b/flecs_ecs/examples/flecs/systems/system_custom_pipeline.rs @@ -20,15 +20,15 @@ fn main() { // DependsOn relationship. let pipeline = world .pipeline() - .with_id(flecs::system::System::ID) - .with::<&Physics>() + .with(flecs::system::System::ID) + .with(id::<&Physics>()) .build(); // Configure the world to use the custom pipeline - world.set_pipeline_id(pipeline.entity()); + world.set_pipeline(pipeline.entity()); // Create system with Physics tag - world.system::<()>().kind::().run(|mut it| { + world.system::<()>().kind(id::()).run(|mut it| { while it.next() { println!("System with Physics ran!"); } diff --git a/flecs_ecs/examples/flecs/systems/system_immediate.rs b/flecs_ecs/examples/flecs/systems/system_immediate.rs index 67676e8a..1a04a4e1 100644 --- a/flecs_ecs/examples/flecs/systems/system_immediate.rs +++ b/flecs_ecs/examples/flecs/systems/system_immediate.rs @@ -27,8 +27,8 @@ fn main() { // Create query to find all waiters without a plate let mut q_waiter = world .query::<()>() - .with::() - .without::<(&Plate, flecs::Wildcard)>() + .with(id::()) + .without((id::(), id::())) .build(); // System that assigns plates to waiter. By making this system no_readonly @@ -36,12 +36,12 @@ fn main() { // ensures that we won't assign plates to the same waiter more than once. world .system_named::<()>("AssignPlate") - .with::() - .without::<(&Waiter, flecs::Wildcard)>() + .with(id::()) + .without((id::(), id::())) .immediate(true) .each_iter(move |mut it, index, plate| { let world = it.world(); - let plate = it.entity(index); + let plate = it.entity(index).unwrap(); // Find an available waiter if let Some(waiter) = q_waiter.try_first_entity() { @@ -54,7 +54,7 @@ fn main() { // components to the entities being iterated would interfere // with the system iterator. it.world().defer_suspend(); - waiter.add_first::<&Plate>(plate); + waiter.add((id::<&Plate>(), plate)); it.world().defer_resume(); // Now that deferring is resumed, we can safely also add the @@ -63,22 +63,22 @@ fn main() { // currently iterating, and we don't want to move it to a // different table while we're iterating it. - plate.add_first::<&Waiter>(waiter); + plate.add((id::<&Waiter>(), waiter)); println!("Assigned {} to {}!", waiter.name(), plate.name()); } }); - let waiter_1 = world.entity_named("waiter_1").add::(); - world.entity_named("waiter_2").add::(); - world.entity_named("waiter_3").add::(); + let waiter_1 = world.entity_named("waiter_1").add(id::()); + world.entity_named("waiter_2").add(id::()); + world.entity_named("waiter_3").add(id::()); - world.entity_named("plate_1").add::(); - let plate_2 = world.entity_named("plate_2").add::(); - world.entity_named("plate_3").add::(); + world.entity_named("plate_1").add(id::()); + let plate_2 = world.entity_named("plate_2").add(id::()); + world.entity_named("plate_3").add(id::()); - waiter_1.add_first::<&Plate>(plate_2); - plate_2.add_first::<&Waiter>(waiter_1); + waiter_1.add((id::<&Plate>(), plate_2)); + plate_2.add((id::<&Waiter>(), waiter_1)); // run systems world.progress(); diff --git a/flecs_ecs/examples/flecs/systems/system_mutate_entity.rs b/flecs_ecs/examples/flecs/systems/system_mutate_entity.rs index 3cae0fb3..73134620 100644 --- a/flecs_ecs/examples/flecs/systems/system_mutate_entity.rs +++ b/flecs_ecs/examples/flecs/systems/system_mutate_entity.rs @@ -26,7 +26,7 @@ fn main() { // When the entity to be mutated is not the same as the entity // provided by the system, an additional mut() call is required. // See the mutate_entity_handle example. - let e = it.entity(index); + let e = it.entity(index).unwrap(); e.destruct(); println!("Expire: {} deleted!", e.name()); } diff --git a/flecs_ecs/examples/flecs/systems/system_mutate_entity_handle.rs b/flecs_ecs/examples/flecs/systems/system_mutate_entity_handle.rs index ccceafe1..afefb3d2 100644 --- a/flecs_ecs/examples/flecs/systems/system_mutate_entity_handle.rs +++ b/flecs_ecs/examples/flecs/systems/system_mutate_entity_handle.rs @@ -41,7 +41,7 @@ fn main() { // // The current entity can also be used to provide context. This // is useful for functions that accept a flecs::entity: - // t.to_delete.mut(it.entity(index)).destruct(); + // t.to_delete.mut(it.entity(index).unwrap()).destruct(); // // A shortcut is to use the iterator directly: let world = it.world(); @@ -65,12 +65,12 @@ fn main() { // Observer that triggers when entity is actually deleted world .observer::() - .with::() + .with(id::()) .each_entity(|e, _tag| { println!("Expired: {} actually deleted", e.name()); }); - let to_delete = world.entity_named("ToDelete").add::(); + let to_delete = world.entity_named("ToDelete").add(id::()); world.entity_named("MyEntity").set(Timeout { to_delete: to_delete.id(), diff --git a/flecs_ecs/examples/flecs/systems/system_pipeline.rs b/flecs_ecs/examples/flecs/systems/system_pipeline.rs index 96f24763..22130d1e 100644 --- a/flecs_ecs/examples/flecs/systems/system_pipeline.rs +++ b/flecs_ecs/examples/flecs/systems/system_pipeline.rs @@ -20,7 +20,7 @@ fn main() { // Create a system for moving an entity world .system::<(&mut Position, &Velocity)>() - .kind::() + .kind(id::()) .each(|(p, v)| { p.x += v.x; p.y += v.y; @@ -29,7 +29,7 @@ fn main() { // Create a system for printing the entity position world .system::<&Position>() - .kind::() + .kind(id::()) .each_entity(|e, p| { println!("{}: {{ {}, {} }}", e.name(), p.x, p.y); }); diff --git a/flecs_ecs/examples/flecs/systems/system_startup_system.rs b/flecs_ecs/examples/flecs/systems/system_startup_system.rs index 488c6423..bbb5754d 100644 --- a/flecs_ecs/examples/flecs/systems/system_startup_system.rs +++ b/flecs_ecs/examples/flecs/systems/system_startup_system.rs @@ -16,7 +16,7 @@ fn main() { // Startup system world .system_named::<()>("Startup") - .kind::() + .kind(id::()) .run(|mut it| { while it.next() { println!("{}", it.system().name()); diff --git a/flecs_ecs/examples/flecs/systems/system_sync_point.rs b/flecs_ecs/examples/flecs/systems/system_sync_point.rs index 2c7bc56f..46887eb6 100644 --- a/flecs_ecs/examples/flecs/systems/system_sync_point.rs +++ b/flecs_ecs/examples/flecs/systems/system_sync_point.rs @@ -32,9 +32,9 @@ fn main() { world .system_named::<()>("SetVelocitySP") - .with::<&PositionSP>() + .with(id::<&PositionSP>()) .set_inout_none() - .write::() // VelocitySP is written, but shouldn't be matched + .with(id::<&mut VelocitySP>()) // VelocitySP is written, but shouldn't be matched .each_entity(|e, ()| { e.set(VelocitySP { x: 1.0, y: 2.0 }); }); @@ -86,7 +86,7 @@ fn main() { // The "merge" lines indicate sync points. // - // Removing `.write::()` from the system will remove the first + // Removing `.with(id::<&mut VelocitySP>())` from the system will remove the first // sync point from the schedule. } diff --git a/flecs_ecs/examples/flecs/systems/system_sync_point_delete.rs b/flecs_ecs/examples/flecs/systems/system_sync_point_delete.rs index 9ca5b7ac..57d22edd 100644 --- a/flecs_ecs/examples/flecs/systems/system_sync_point_delete.rs +++ b/flecs_ecs/examples/flecs/systems/system_sync_point_delete.rs @@ -43,7 +43,7 @@ fn main() { // const, since inside the system we're only reading it. world .system_named::<&Position>("DeleteEntity") - .write::() + .with(id::<&mut flecs::Wildcard>()) .each_entity(|e, p| { if p.x >= 3.0 { println!("Delete entity {}", e.name()); @@ -77,7 +77,7 @@ fn main() { set_log_level(1); while world.progress() { - if world.count::() == 0 { + if world.count(id::()) == 0 { break; // No more entities left with Position } } diff --git a/flecs_ecs/src/addons/alerts/alert_builder.rs b/flecs_ecs/src/addons/alerts/alert_builder.rs index c56ac852..ac38be0a 100644 --- a/flecs_ecs/src/addons/alerts/alert_builder.rs +++ b/flecs_ecs/src/addons/alerts/alert_builder.rs @@ -5,7 +5,6 @@ use crate::core::*; use crate::sys; use super::Alert; -use super::SeverityAlert; use core::mem::ManuallyDrop; @@ -173,27 +172,11 @@ where /// # See also /// /// * `ecs_alert_desc_t::severity` - pub fn severity_id(&mut self, severity: impl Into) -> &mut Self { - self.desc.severity = *severity.into(); + pub fn severity(&mut self, severity: impl IntoEntity) -> &mut Self { + self.desc.severity = *severity.into_entity(self.world); self } - /// Set severity of alert (default is Error). - /// - /// # Type Parameters - /// - /// * `Severity` - The severity component. - /// - /// # See also - /// - /// * `ecs_alert_desc_t::severity` - pub fn severity(&mut self) -> &mut Self - where - Severity: ComponentId + SeverityAlert, - { - self.severity_id(Severity::id(self.world())) - } - /// Set retain period of alert. /// /// # Arguments @@ -219,10 +202,10 @@ where /// # See also /// /// * `ecs_alert_desc_t::severity_filters` - pub fn severity_filter_id( + pub fn severity_filter( &mut self, - severity: impl Into, - with: impl Into, + severity: impl IntoEntity, + with: impl IntoId, var: Option<&str>, ) -> &mut Self { ecs_assert!( @@ -232,8 +215,8 @@ where let filter = &mut self.desc.severity_filters[self.severity_filter_count as usize]; self.severity_filter_count += 1; - filter.severity = *severity.into(); - filter.with = *with.into(); + filter.severity = *severity.into_entity(self.world); + filter.with = *with.into_id(self.world); if let Some(var) = var { let var = ManuallyDrop::new(format!("{}\0", var)); filter.var = var.as_ptr() as *const _; @@ -242,28 +225,6 @@ where self } - /// Add severity filter. - /// - /// # Type Parameters - /// - /// * `Severity` - Severity component. - /// - /// # Arguments - /// - /// * `with` - Filter with this id. - /// * `var` - Variable name (optional). - /// - /// # See also - /// - /// * `ecs_alert_desc_t::severity_filters` - pub fn severity_filter(&mut self, with: impl Into, var: Option<&str>) -> &mut Self - where - Severity: ComponentId, - { - let severity_id = Severity::id(self.world()); - self.severity_filter_id(severity_id, with, var) - } - /// Add severity filter for non-enum components. /// /// # Type Parameters @@ -285,7 +246,7 @@ where { let severity_id = Severity::id(self.world()); let with_id = With::id(self.world()); - self.severity_filter_id(severity_id, with_id, var) + self.severity_filter(severity_id, with_id, var) } /// Add severity filter for enum components. @@ -317,7 +278,7 @@ where let with_id = With::id(world); let constant_id = with.id_variant(world); let pair_id = ecs_pair(with_id, *constant_id.id()); - self.severity_filter_id(severity_id, pair_id, var) + self.severity_filter(severity_id, pair_id, var) } /// Set member to create an alert for out of range values. @@ -329,8 +290,8 @@ where /// # See also /// /// * `ecs_alert_desc_t::member` - pub fn member_id(&mut self, member: impl Into) -> &mut Self { - self.desc.member = *member.into(); + pub fn member(&mut self, member: impl IntoEntity) -> &mut Self { + self.desc.member = *member.into_entity(self.world); self } @@ -344,8 +305,8 @@ where /// # See also /// /// * `ecs_alert_desc_t::id` - pub fn id(&mut self, id: impl Into) -> &mut Self { - self.desc.id = *id.into(); + pub fn id(&mut self, id: impl IntoId) -> &mut Self { + self.desc.id = *id.into_id(self.world); self } @@ -395,7 +356,7 @@ where self.str_ptrs_to_free.push(var); } - self.member_id(member_id) + self.member(member_id) } /// Set source variable for member (optional, defaults to `$this`). @@ -453,9 +414,6 @@ where type BuiltType = Alert<'a>; /// Build the `AlertBuilder` into an Alert - /// - /// See also - /// fn build(&mut self) -> Self::BuiltType { let alert = Alert::new(self.world(), self.desc); for s in self.term_builder.str_ptrs_to_free.iter_mut() { diff --git a/flecs_ecs/src/addons/doc.rs b/flecs_ecs/src/addons/doc.rs index 9f42d93b..16292f3f 100644 --- a/flecs_ecs/src/addons/doc.rs +++ b/flecs_ecs/src/addons/doc.rs @@ -44,7 +44,7 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// * [`World::doc_name()`] fn doc_name(&self) -> Option { - self.world().doc_name_id(self.clone()) + self.world().doc_name(self.clone()) } /// Get brief description for an entity. @@ -57,7 +57,7 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// * [`World::doc_brief()`] fn doc_brief(&self) -> Option { - self.world().doc_brief_id(self.clone()) + self.world().doc_brief(self.clone()) } /// Get detailed description for an entity. @@ -70,7 +70,7 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// * [`World::doc_detail()`] fn doc_detail(&self) -> Option { - self.world().doc_detail_id(self.clone()) + self.world().doc_detail(self.clone()) } /// Get link to external documentation for an entity. @@ -83,7 +83,7 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// * [`World::doc_link()`] fn doc_link(&self) -> Option { - self.world().doc_link_id(self.clone()) + self.world().doc_link(self.clone()) } /// Get color for an entity. @@ -96,7 +96,7 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// * [`World::doc_color()`] fn doc_color(&self) -> Option { - self.world().doc_color_id(self.clone()) + self.world().doc_color(self.clone()) } /// Get UUID for entity @@ -107,13 +107,11 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// /// # See also /// - /// * [`World::doc_uuid_id()`] /// * [`World::doc_uuid()`] /// * [`Doc::set_doc_uuid()`] - /// * [`World::set_doc_uuid_id()`] /// * [`World::set_doc_uuid()`] fn doc_uuid(&self) -> Option { - self.world().doc_uuid_id(self.clone()) + self.world().doc_uuid(self.clone()) } //MARK: _setters @@ -130,9 +128,8 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// # See also /// /// * [`World::set_doc_name()`] - /// * [`World::set_doc_name_id()`] fn set_doc_name(&self, name: &str) -> &Self { - self.world().set_doc_name_id(self.clone(), name); + self.world().set_doc_name(self.clone(), name); self } @@ -145,9 +142,8 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// # See also /// /// * [`World::set_doc_brief()`] - /// * [`World::set_doc_brief_id()`] fn set_doc_brief(&self, brief: &str) -> &Self { - self.world().set_doc_brief_id(self.clone(), brief); + self.world().set_doc_brief(self.clone(), brief); self } @@ -160,9 +156,8 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// # See also /// /// * [`World::set_doc_detail()`] - /// * [`World::set_doc_detail_id()`] fn set_doc_detail(&self, detail: &str) -> &Self { - self.world().set_doc_detail_id(self.clone(), detail); + self.world().set_doc_detail(self.clone(), detail); self } @@ -175,9 +170,8 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// # See also /// /// * [`World::set_doc_link()`] - /// * [`World::set_doc_link_id()`] fn set_doc_link(&self, link: &str) -> &Self { - self.world().set_doc_link_id(self.clone(), link); + self.world().set_doc_link(self.clone(), link); self } @@ -193,9 +187,8 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// # See also /// /// * [`World::set_doc_color()`] - /// * [`World::set_doc_color_id()`] fn set_doc_color(&self, color: &str) -> &Self { - self.world().set_doc_color_id(self.clone(), color); + self.world().set_doc_color(self.clone(), color); self } @@ -207,13 +200,11 @@ pub trait Doc<'a>: WorldProvider<'a> + Into + Clone { /// * `uuid` - The UUID to add. /// /// # See also - /// * [`World::set_doc_uuid_id()`] /// * [`World::set_doc_uuid()`] /// * [`World::doc_uuid()`] - /// * [`World::doc_uuid_id()`] /// * [`Doc::doc_uuid()`] fn set_doc_uuid(&self, uuid: &str) -> &Self { - self.world().set_doc_uuid_id(self.clone(), uuid); + self.world().set_doc_uuid(self.clone(), uuid); self } } @@ -222,37 +213,18 @@ impl<'a, T> Doc<'a> for T where T: Into + WorldProvider<'a> + Clone {} //MARK: impl World /// ``` -/// use flecs_ecs::{addons::doc::Doc, core::World, macros::Component}; +/// use flecs_ecs::prelude::*; /// /// #[derive(Component)] /// struct Tag; /// /// let world = World::default(); /// world.component::(); -/// world.set_doc_name::("A tag"); +/// world.set_doc_name(id::(), "A tag"); /// ``` impl World { //MARK: _World::getters - /// Get human readable name for an entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// The human readable name of the entity. - /// - /// # See also - /// - /// * [`Doc::doc_name()`] - /// * [`World::doc_name_id()`] - #[inline(always)] - pub fn doc_name(&self) -> Option { - self.doc_name_id(T::get_id(self)) - } - /// Get human readable name for an entity. /// /// # Arguments @@ -268,33 +240,14 @@ impl World { /// * [`Doc::doc_name()`] /// * [`World::doc_name()`] #[inline(always)] - pub fn doc_name_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_name(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_name(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_name(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } - /// Get brief description for an entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// The brief description of the entity. - /// - /// # See also - /// - /// * [`Doc::doc_brief()`] - /// * [`World::doc_brief_id()`] - #[inline(always)] - pub fn doc_brief(&self) -> Option { - self.doc_brief_id(T::get_id(self)) - } - /// Get brief description for an entity. /// /// # Arguments @@ -310,32 +263,14 @@ impl World { /// * [`Doc::doc_brief()`] /// * [`World::doc_brief()`] #[inline(always)] - pub fn doc_brief_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_brief(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_brief(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_brief(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } - /// Get detailed description for an entity. - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// The detailed description of the entity. - /// - /// # See also - /// - /// * [`Doc::doc_detail()`] - /// * [`World::doc_detail_id()`] - #[inline(always)] - pub fn doc_detail(&self) -> Option { - self.doc_detail_id(T::get_id(self)) - } - /// Get detailed description for an entity. /// /// # Arguments @@ -351,33 +286,14 @@ impl World { /// * [`Doc::doc_detail()`] /// * [`World::doc_detail()`] #[inline(always)] - pub fn doc_detail_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_detail(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_detail(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_detail(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } - /// Get link to external documentation for an entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// The link to external documentation of the entity. - /// - /// # See also - /// - /// * [`Doc::doc_link()`] - /// * [`World::doc_link_id()`] - #[inline(always)] - pub fn doc_link(&self) -> Option { - self.doc_link_id(T::get_id(self)) - } - /// Get link to external documentation for an entity. /// # Arguments /// @@ -392,32 +308,14 @@ impl World { /// * [`Doc::doc_link()`] /// * [`World::doc_link()`] #[inline(always)] - pub fn doc_link_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_link(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_link(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_link(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } - /// Get color for an entity. - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// The color of the entity. - /// - /// # See also - /// - /// * [`Doc::doc_color()`] - /// * [`World::doc_color_id()`] - #[inline(always)] - pub fn doc_color(&self) -> Option { - self.doc_color_id(T::get_id(self)) - } - /// Get color for an entity. /// # Arguments /// @@ -432,10 +330,10 @@ impl World { /// * [`Doc::doc_color()`] /// * [`World::doc_color()`] #[inline(always)] - pub fn doc_color_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_color(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_color(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_color(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } @@ -446,56 +344,17 @@ impl World { /// /// * [`World::doc_uuid()`] /// * [`Doc::doc_uuid()`] - /// * [`World::set_doc_uuid_id()`] /// * [`Doc::set_doc_uuid()`] - pub fn doc_uuid_id(&self, entity: impl Into) -> Option { - let cstr = NonNull::new( - unsafe { sys::ecs_doc_get_uuid(self.world_ptr(), *entity.into()) } as *mut _, - ) + pub fn doc_uuid(&self, entity: impl IntoEntity) -> Option { + let cstr = NonNull::new(unsafe { + sys::ecs_doc_get_uuid(self.world_ptr(), *entity.into_entity(self)) + } as *mut _) .map(|s| unsafe { CStr::from_ptr(s.as_ptr()) }); cstr.and_then(|s| s.to_str().ok().map(ToString::to_string)) } - /// Get UUID for component - /// - /// # Type Parameters - /// - /// * `T` - The component. - /// - /// # See Also - /// - /// * [`World::doc_uuid_id()`] - /// * [`Doc::doc_uuid()`] - /// * [`World::set_doc_uuid_id()`] - /// * [`Doc::set_doc_uuid()`] - pub fn doc_uuid(&self) -> Option { - self.doc_uuid_id(T::get_id(self)) - } - //MARK: _World::setters - /// Add human-readable name to entity. - /// - /// Contrary to entity names, human readable names do not have to be unique and - /// can contain special characters used in the query language like '*'. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Arguments - /// - /// * `name` - The name to add. - /// - /// # See also - /// - /// * [`Doc::set_doc_name()`] - /// * [`World::set_doc_name_id()`] - #[inline(always)] - pub fn set_doc_name(&self, name: &str) { - self.set_doc_name_id(T::get_id(self), name); - } - /// Add human-readable name to entity. /// /// Contrary to entity names, human readable names do not have to be unique and @@ -511,28 +370,15 @@ impl World { /// * [`Doc::set_doc_name()`] /// * [`World::set_doc_name()`] #[inline(always)] - pub fn set_doc_name_id(&self, entity: impl Into, name: &str) { + pub fn set_doc_name(&self, entity: impl IntoEntity, name: &str) { let name = compact_str::format_compact!("{}\0", name); - unsafe { sys::ecs_doc_set_name(self.ptr_mut(), *entity.into(), name.as_ptr() as *const _) }; - } - - /// Add brief description to entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Arguments - /// - /// * `brief` - The brief description to add. - /// - /// # See also - /// - /// * [`Doc::set_doc_brief()`] - /// * [`World::set_doc_brief_id()`] - #[inline(always)] - pub fn set_doc_brief(&self, brief: &str) { - self.set_doc_brief_id(T::get_id(self), brief); + unsafe { + sys::ecs_doc_set_name( + self.ptr_mut(), + *entity.into_entity(self), + name.as_ptr() as *const _, + ); + }; } /// Add brief description to entity. @@ -547,32 +393,17 @@ impl World { /// * [`Doc::set_doc_brief()`] /// * [`World::set_doc_brief()`] #[inline(always)] - pub fn set_doc_brief_id(&self, entity: impl Into, brief: &str) { + pub fn set_doc_brief(&self, entity: impl IntoEntity, brief: &str) { let brief = compact_str::format_compact!("{}\0", brief); unsafe { - sys::ecs_doc_set_brief(self.ptr_mut(), *entity.into(), brief.as_ptr() as *const _); + sys::ecs_doc_set_brief( + self.ptr_mut(), + *entity.into_entity(self), + brief.as_ptr() as *const _, + ); }; } - /// Add detailed description to entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Arguments - /// - /// * `detail` - The detailed description to add. - /// - /// # See also - /// - /// * [`Doc::set_doc_detail()`] - /// * [`World::set_doc_detail_id()`] - #[inline(always)] - pub fn set_doc_detail(&self, detail: &str) { - self.set_doc_detail_id(T::get_id(self), detail); - } - /// Add detailed description to entity. /// /// # Arguments @@ -585,32 +416,17 @@ impl World { /// * [`Doc::set_doc_detail()`] /// * [`World::set_doc_detail()`] #[inline(always)] - pub fn set_doc_detail_id(&self, entity: impl Into, detail: &str) { + pub fn set_doc_detail(&self, entity: impl IntoEntity, detail: &str) { let detail = compact_str::format_compact!("{}\0", detail); unsafe { - sys::ecs_doc_set_detail(self.ptr_mut(), *entity.into(), detail.as_ptr() as *const _); + sys::ecs_doc_set_detail( + self.ptr_mut(), + *entity.into_entity(self), + detail.as_ptr() as *const _, + ); }; } - /// Add link to external documentation to entity. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Arguments - /// - /// * `link` - The link to add. - /// - /// # See also - /// - /// * [`Doc::set_doc_link()`] - /// * [`World::set_doc_link_id()`] - #[inline(always)] - pub fn set_doc_link(&self, link: &str) { - self.set_doc_link_id(T::get_id(self), link); - } - /// Add link to external documentation to entity. /// /// # Arguments @@ -623,30 +439,15 @@ impl World { /// * [`Doc::set_doc_link()`] /// * [`World::set_doc_link()`] #[inline(always)] - pub fn set_doc_link_id(&self, entity: impl Into, link: &str) { + pub fn set_doc_link(&self, entity: impl IntoEntity, link: &str) { let link = compact_str::format_compact!("{}\0", link); - unsafe { sys::ecs_doc_set_link(self.ptr_mut(), *entity.into(), link.as_ptr() as *const _) }; - } - - /// Add color to component. - /// - /// UIs can use color as hint to improve visualizing entities. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Arguments - /// - /// * `color` - The color to add. - /// - /// # See also - /// - /// * [`Doc::set_doc_color()`] - /// * [`World::set_doc_color_id()`] - #[inline(always)] - pub fn set_doc_color(&self, color: &str) { - self.set_doc_color_id(T::get_id(self), color); + unsafe { + sys::ecs_doc_set_link( + self.ptr_mut(), + *entity.into_entity(self), + link.as_ptr() as *const _, + ); + }; } /// Add color to entity. @@ -663,10 +464,14 @@ impl World { /// * [`Doc::set_doc_color()`] /// * [`World::set_doc_color()`] #[inline(always)] - pub fn set_doc_color_id(&self, entity: impl Into, color: &str) { + pub fn set_doc_color(&self, entity: impl IntoEntity, color: &str) { let color = compact_str::format_compact!("{}\0", color); unsafe { - sys::ecs_doc_set_color(self.ptr_mut(), *entity.into(), color.as_ptr() as *const _); + sys::ecs_doc_set_color( + self.ptr_mut(), + *entity.into_entity(self), + color.as_ptr() as *const _, + ); }; } @@ -683,36 +488,17 @@ impl World { /// * [`Doc::set_doc_uuid()`] /// * [`World::set_doc_uuid()`] /// * [`World::doc_uuid()`] - /// * [`World::doc_uuid_id()`] /// * [`Doc::doc_uuid()`] - pub fn set_doc_uuid_id(&self, entity: impl Into, uuid: &str) { + pub fn set_doc_uuid(&self, entity: impl IntoEntity, uuid: &str) { let uuid = compact_str::format_compact!("{}\0", uuid); unsafe { - sys::ecs_doc_set_uuid(self.ptr_mut(), *entity.into(), uuid.as_ptr() as *const _); + sys::ecs_doc_set_uuid( + self.ptr_mut(), + *entity.into_entity(self), + uuid.as_ptr() as *const _, + ); }; } - - /// Add UUID to component - /// This adds `(flecs.doc.Description, flecs.doc.Uuid)` to the component - /// - /// # Type Parameters - /// - /// * `T` - The component. - /// - /// # Arguments - /// - /// * `uuid` - The UUID to add. - /// - /// # See also - /// - /// * [`World::set_doc_uuid_id()`] - /// * [`Doc::set_doc_uuid()`] - /// * [`World::doc_uuid()`] - /// * [`World::doc_uuid_id()`] - /// * [`Doc::doc_uuid()`] - pub fn set_doc_uuid(&self, uuid: &str) { - self.set_doc_uuid_id(T::get_id(self), uuid); - } } #[test] @@ -733,7 +519,7 @@ fn test_compile_doc() { let observer = world .observer::() - .with::() + .with(id::()) .run(|_| {}); observer.set_doc_name("name"); diff --git a/flecs_ecs/src/addons/json/mod.rs b/flecs_ecs/src/addons/json/mod.rs index 2f8a3d9b..33896cb8 100644 --- a/flecs_ecs/src/addons/json/mod.rs +++ b/flecs_ecs/src/addons/json/mod.rs @@ -24,8 +24,8 @@ pub type IterToJsonDesc = sys::ecs_iter_to_json_desc_t; impl EntityView<'_> { /// Set component or pair id from JSON. - pub fn set_json_id(self, comp: impl IntoId, json: &str, desc: Option<&FromJsonDesc>) -> Self { - let comp: u64 = *comp.into(); + pub fn set_json(self, comp: impl IntoId, json: &str, desc: Option<&FromJsonDesc>) -> Self { + let comp: u64 = *comp.into_id(self.world); let world = self.world_ptr_mut(); let id = *self.id; unsafe { @@ -59,31 +59,6 @@ impl EntityView<'_> { self } - /// Set component or pair from JSON. - pub fn set_json(self, json: &str, desc: Option<&FromJsonDesc>) -> Self { - self.set_json_id(T::get_id(self.world), json, desc) - } - - /// Set pair from JSON where First is a type and Second is an entity id. - pub fn set_json_first( - self, - target: impl Into + Copy, - json: &str, - desc: Option<&FromJsonDesc>, - ) -> Self { - self.set_json_id((Rel::get_id(self.world), target), json, desc) - } - - /// Set pair from JSON where First is an entity id and Second is a type. - pub fn set_json_second( - self, - rel: impl Into + Copy, - json: &str, - desc: Option<&FromJsonDesc>, - ) -> Self { - self.set_json_id((rel, Second::get_id(self.world)), json, desc) - } - /// Serialize entity to JSON. pub fn to_json(&self, desc: Option<&EntityToJsonDesc>) -> String { let world = self.world_ptr(); @@ -120,7 +95,7 @@ impl World { /// Serialize untyped value to JSON. #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn to_json_id(&self, tid: impl IntoId, value: *const core::ffi::c_void) -> String { - let tid: u64 = *tid.into(); + let tid: u64 = *tid.into_id(self); let world = self.world_ptr(); unsafe { let json_ptr = sys::ecs_ptr_to_json(world, tid, value); @@ -172,7 +147,7 @@ impl World { json: &str, desc: Option<&FromJsonDesc>, ) { - let tid: u64 = *tid.into(); + let tid: u64 = *tid.into_id(self); let world = self.ptr_mut(); let desc_ptr = desc .map(|d| d as *const FromJsonDesc) diff --git a/flecs_ecs/src/addons/meta/cursor.rs b/flecs_ecs/src/addons/meta/cursor.rs index ff253d5e..9227f4e1 100644 --- a/flecs_ecs/src/addons/meta/cursor.rs +++ b/flecs_ecs/src/addons/meta/cursor.rs @@ -12,12 +12,13 @@ impl<'a> Cursor<'a> { #[allow(clippy::not_unsafe_ptr_arg_deref)] pub(crate) fn new( world: impl WorldProvider<'a>, - type_id: impl Into, + type_id: impl IntoEntity, ptr: *mut core::ffi::c_void, ) -> Self { - let world = world.world_ptr(); - let type_id = *type_id.into(); - let cursor = unsafe { sys::ecs_meta_cursor(world, type_id, ptr) }; + let world = world.world(); + let world_ptr = world.world_ptr(); + let type_id = *type_id.into_entity(world); + let cursor = unsafe { sys::ecs_meta_cursor(world_ptr, type_id, ptr) }; Self { cursor, phantom: core::marker::PhantomData, @@ -134,7 +135,14 @@ impl<'a> Cursor<'a> { /// Set (component) id value pub fn set_id(&mut self, value: impl IntoId) -> i32 { - unsafe { sys::ecs_meta_set_id(&mut self.cursor, *value.into()) } + unsafe { + sys::ecs_meta_set_id( + &mut self.cursor, + *value.into_id(WorldRef::from_ptr( + self.cursor.world as *mut sys::ecs_world_t, + )), + ) + } } /// Set null value diff --git a/flecs_ecs/src/addons/meta/macros/macro_component.rs b/flecs_ecs/src/addons/meta/macros/macro_component.rs index cbccee45..73040836 100644 --- a/flecs_ecs/src/addons/meta/macros/macro_component.rs +++ b/flecs_ecs/src/addons/meta/macros/macro_component.rs @@ -113,11 +113,11 @@ macro_rules! member { macro_rules! member_ext { ($world:expr, $compvar:ident: $component:ty, $name:tt : [$type:ty; $n:literal]) => { $crate::assert_is_type!($component, $name: [$type; $n]); - $compvar.member_id(::flecs_ecs::prelude::id!($world, $type), (::core::stringify!($name), flecs_ecs::addons::meta::Count($n), ::core::mem::offset_of!($component, $name).try_into().unwrap())) + $compvar.member(::flecs_ecs::prelude::id!($world, $type), (::core::stringify!($name), flecs_ecs::addons::meta::Count($n), ::core::mem::offset_of!($component, $name).try_into().unwrap())) }; ($world:expr, $compvar:ident: $component:ty, $name:tt : $type:ty) => { $crate::assert_is_type!($component, $name: $type); - $compvar.member_id(::flecs_ecs::prelude::id!($world, $type), (::core::stringify!($name), flecs_ecs::addons::meta::Count(1), ::core::mem::offset_of!($component, $name).try_into().unwrap())) + $compvar.member(::flecs_ecs::prelude::id!($world, $type), (::core::stringify!($name), flecs_ecs::addons::meta::Count(1), ::core::mem::offset_of!($component, $name).try_into().unwrap())) }; ($world:expr, $component:ty, $name:tt : $($tail:tt)*) => {{ let world = $world; @@ -332,12 +332,12 @@ pub fn opaque_option_struct(world: WorldRef) -> Opaque, T> Some: T, } let dummy = world.component_ext(id!(&world, Dummy)); - if !dummy.has::() { - dummy.member_id( + if !dummy.has(crate::core::utility::id::()) { + dummy.member( id!(&world, bool), ("None", Count(1), core::mem::offset_of!(Dummy, None)), ); - dummy.member_id( + dummy.member( id!(&world, T), ("Some", Count(1), core::mem::offset_of!(Dummy, Some)), ); diff --git a/flecs_ecs/src/addons/meta/macros/macro_meta_register_vector.rs b/flecs_ecs/src/addons/meta/macros/macro_meta_register_vector.rs index aa4327f4..ffc1acd5 100644 --- a/flecs_ecs/src/addons/meta/macros/macro_meta_register_vector.rs +++ b/flecs_ecs/src/addons/meta/macros/macro_meta_register_vector.rs @@ -2,7 +2,7 @@ /// /// This macro expands to a function that registers a vector component type with metadata. /// It performs the following actions: -/// - Generates a unique ID for the vector component type using the [`id!`](crate::addons::meta::id) macro. +/// - Generates a unique ID for the vector component type using the [`id!`](crate::addons::meta::id!) macro. /// - Registers the vector component type with the [`World`](crate::core::World) using the [`component_ext`](crate::core::World::component_ext) function. /// - Associates the generated function with the vector component type using the [`meta_register_vector_func`] macro. /// diff --git a/flecs_ecs/src/addons/meta/mod.rs b/flecs_ecs/src/addons/meta/mod.rs index 1d2bc01c..b447ca18 100644 --- a/flecs_ecs/src/addons/meta/mod.rs +++ b/flecs_ecs/src/addons/meta/mod.rs @@ -60,7 +60,13 @@ impl World { } /// Return meta cursor to value - pub fn cursor_id(&self, type_id: impl Into, ptr: *mut c_void) -> Cursor { + pub fn cursor(&self, data: &mut T) -> Cursor { + let type_id = T::get_id(self.world()); + Cursor::new(self, type_id, data as *mut T as *mut c_void) + } + + /// Return meta cursor to value + pub fn cursor_id(&self, type_id: impl IntoEntity, ptr: *mut c_void) -> Cursor { if ptr.is_null() { panic!("ptr is null"); } @@ -68,12 +74,6 @@ impl World { Cursor::new(self, type_id, ptr) } - /// Return meta cursor to value - pub fn cursor(&self, data: &mut T) -> Cursor { - let type_id = T::get_id(self.world()); - Cursor::new(self, type_id, data as *mut T as *mut c_void) - } - /// Create primitive type pub fn primitive(&self, kind: EcsPrimitiveKind) -> EntityView { let desc = sys::ecs_primitive_desc_t { @@ -91,9 +91,9 @@ impl World { } /// Create array type - pub fn array_id(&self, elem_id: impl Into, array_count: i32) -> EntityView { + pub fn array(&self, elem_id: impl IntoEntity, array_count: i32) -> EntityView { let desc = sys::ecs_array_desc_t { - type_: *elem_id.into(), + type_: *elem_id.into_entity(self), count: array_count, entity: 0u64, }; @@ -107,11 +107,6 @@ impl World { EntityView::new_from(self, eid) } - /// Create array type - pub fn array(&self, array_count: i32) -> EntityView { - self.array_id(T::get_id(self.world()), array_count) - } - /// Create vector type pub fn vector_id(&self, elem_id: impl Into) -> EntityView { let elem_id: u64 = *elem_id.into(); @@ -165,9 +160,15 @@ pub trait EcsSerializer { impl EcsSerializer for sys::ecs_serializer_t { #[allow(clippy::not_unsafe_ptr_arg_deref)] - fn value_id(&self, type_id: impl Into, value: *const c_void) -> i32 { + fn value_id(&self, type_id: impl IntoEntity, value: *const c_void) -> i32 { if let Some(value_func) = self.value { - unsafe { value_func(self, *type_id.into(), value) } + unsafe { + value_func( + self, + *type_id.into_entity(WorldRef::from_ptr(self.world as *mut _)), + value, + ) + } } else { 0 } @@ -192,8 +193,6 @@ impl EcsSerializer for sys::ecs_serializer_t { /// Register opaque type interface impl<'a, T: 'static> Component<'a, T> { - /// # See also - /// pub fn opaque_func(&self, func: Func) -> &Self where Func: FnOnce(WorldRef<'a>) -> Opaque<'a, T>, @@ -204,8 +203,6 @@ impl<'a, T: 'static> Component<'a, T> { self } - /// # See also - /// pub fn opaque_func_id(&self, id: impl Into, func: Func) -> &Self where Func: FnOnce(WorldRef<'a>) -> Opaque<'a, T, Elem>, @@ -216,8 +213,6 @@ impl<'a, T: 'static> Component<'a, T> { self } - /// # See also - /// pub fn opaque(&self) -> Opaque<'a, T> { let id = self.world().component_id_map::(); let mut opaque = Opaque::::new(self.world()); @@ -225,17 +220,13 @@ impl<'a, T: 'static> Component<'a, T> { opaque } - /// # See also - /// - pub fn opaque_id(&self, id: impl Into) -> Opaque<'a, T> { - let id = id.into(); + pub fn opaque_id(&self, id: impl IntoEntity) -> Opaque<'a, T> { + let id = id.into_entity(self.world()); let mut opaque = Opaque::::new(self.world()); opaque.as_type(id); opaque } - /// # See also - /// pub fn opaque_dyn_id(&self, id_type: E, id_field: E) -> Opaque<'a, T> where E: Into + Copy, @@ -367,17 +358,17 @@ impl UntypedComponent<'_> { /// (name : &'static str,), /// (name: &'static str, count: i32), /// (name: &'static str, count: i32, offset: i32) - pub fn member_id_unit( + pub fn member_unit( self, - type_id: impl Into, - unit: impl Into, + type_id: impl IntoEntity, + unit: impl IntoEntity, data: Meta, ) -> Self { let name = compact_str::format_compact!("{}\0", data.name()); let world = self.world_ptr_mut(); let id = *self.id; - let type_id = *type_id.into(); - let unit = *unit.into(); + let type_id = *type_id.into_entity(world); + let unit = *unit.into_entity(world); let desc = sys::ecs_entity_desc_t { name: name.as_ptr() as *const _, @@ -411,32 +402,8 @@ impl UntypedComponent<'_> { /// (name : &'static str,), /// (name: &'static str, count: i32), /// (name: &'static str, count: i32, offset: i32) - pub fn member_id(self, type_id: impl Into, data: impl MetaMember) -> Self { - self.member_id_unit(type_id, 0, data) - } - - /// Add member. - /// - /// [`MetaMember`] is a trait that accepts the following options: - /// (name : &'static str,), - /// (name: &'static str, count: i32), - /// (name: &'static str, count: i32, offset: i32) - pub fn member(self, data: impl MetaMember) -> Self { - self.member_id(T::get_id(self.world()), data) - } - - /// Add member with unit. - /// - /// [`MetaMember`] is a trait that accepts the following options: - /// (name : &'static str,), - /// (name: &'static str, count: i32), - /// (name: &'static str, count: i32, offset: i32) - pub fn member_unit( - self, - unit: impl Into, - data: impl MetaMember, - ) -> Self { - self.member_id_unit(T::get_id(self.world()), unit, data) + pub fn member(self, type_id: impl IntoEntity, data: impl MetaMember) -> Self { + self.member_unit(type_id, 0, data) } /// Add member with unit typed. @@ -446,7 +413,7 @@ impl UntypedComponent<'_> { /// (name: &'static str, count: i32), /// (name: &'static str, count: i32, offset: i32) pub fn member_unit_type(self, data: impl MetaMember) -> Self { - self.member_id_unit(T::get_id(self.world()), U::get_id(self.world()), data) + self.member_unit(T::get_id(self.world()), U::get_id(self.world()), data) } //TODO @@ -541,7 +508,7 @@ impl UntypedComponent<'_> { mr.value.min = min; mr.value.max = max; - me.modified::(); + me.modified(flecs::meta::MemberRanges::ID); self } @@ -563,7 +530,7 @@ impl UntypedComponent<'_> { mr.warning.min = min; mr.warning.max = max; - me.modified::(); + me.modified(flecs::meta::MemberRanges::ID); self } @@ -585,7 +552,7 @@ impl UntypedComponent<'_> { mr.error.min = min; mr.error.max = max; - me.modified::(); + me.modified(flecs::meta::MemberRanges::ID); self } } diff --git a/flecs_ecs/src/addons/metrics/metric_builder.rs b/flecs_ecs/src/addons/metrics/metric_builder.rs index 3a831ac5..c04990d8 100644 --- a/flecs_ecs/src/addons/metrics/metric_builder.rs +++ b/flecs_ecs/src/addons/metrics/metric_builder.rs @@ -56,8 +56,8 @@ impl<'a> MetricBuilder<'a> { /// # Arguments /// /// * `e` - The entity representing the member. - pub fn member_id(&mut self, e: impl Into) -> &mut Self { - self.desc.member = *e.into(); + pub fn member(&mut self, e: impl IntoEntity) -> &mut Self { + self.desc.member = *e.into_entity(self.world); self } @@ -97,7 +97,7 @@ impl<'a> MetricBuilder<'a> { //eprintln!("member '{}' not found", name); } - self.member_id(member_id) + self.member(member_id) } /// Set the member for the metric using a component type and member name. @@ -109,7 +109,7 @@ impl<'a> MetricBuilder<'a> { /// # Arguments /// /// * `name` - The name of the member within the component. - pub fn member(&mut self, name: &str) -> &mut Self + pub fn member_named_type(&mut self, name: &str) -> &mut Self where T: ComponentId, { @@ -135,7 +135,7 @@ impl<'a> MetricBuilder<'a> { return self; } - self.member_id(m.unwrap()) + self.member(m.unwrap()) } /// Set the `dotmember` expression for the metric. @@ -176,66 +176,11 @@ impl<'a> MetricBuilder<'a> { /// # Arguments /// /// * `the_id` - The ID to set. - pub fn id(&mut self, the_id: impl Into) -> &mut Self { - self.desc.id = *the_id.into(); + pub fn id(&mut self, the_id: impl IntoId) -> &mut Self { + self.desc.id = *the_id.into_id(self.world); self } - /// Set the ID for the metric using a pair of entities. - /// - /// # Arguments - /// - /// * `first` - The first entity in the pair. - /// * `second` - The second entity in the pair. - pub fn id_pair(&mut self, first: impl Into, second: impl Into) -> &mut Self { - self.desc.id = ecs_pair(*first.into(), *second.into()); - self - } - - /// Set the ID for the metric using a component type. - /// - /// # Type Parameters - /// - /// * `T` - The component type. - pub fn id_type(&mut self) -> &mut Self - where - T: ComponentOrPairId, - { - self.id(T::get_id(self.world())) - } - - /// Set the ID for the metric using a component type as the first element and an entity as the second. - /// - /// # Type Parameters - /// - /// * `First` - The component type for the first element. - /// - /// # Arguments - /// - /// * `second` - The second entity in the pair. - pub fn id_first(&mut self, second: impl Into) -> &mut Self - where - First: ComponentId, - { - self.id_pair(First::id(self.world()), second) - } - - /// Set the ID for the metric using an entity as the first element and a component type as the second. - /// - /// # Type Parameters - /// - /// * `Second` - The component type for the second element. - /// - /// # Arguments - /// - /// * `first` - The first entity in the pair. - pub fn id_second(&mut self, first: impl Into) -> &mut Self - where - Second: ComponentId, - { - self.id_pair(first, Second::id(self.world())) - } - /// Specify whether the metric should include targets. /// /// # Arguments @@ -251,23 +196,11 @@ impl<'a> MetricBuilder<'a> { /// # Arguments /// /// * `the_kind` - The entity representing the kind. - pub fn kind_id(&mut self, the_kind: impl Into) -> &mut Self { - self.desc.kind = *the_kind.into(); + pub fn kind(&mut self, the_kind: impl IntoEntity) -> &mut Self { + self.desc.kind = *the_kind.into_entity(self.world); self } - /// Set the kind of the metric using a component type. - /// - /// # Type Parameters - /// - /// * `Kind` - The component type representing the kind. - pub fn kind(&mut self) -> &mut Self - where - Kind: ComponentId, - { - self.kind_id(Kind::id(self.world())) - } - /// Set a brief description for the metric. /// /// # Arguments diff --git a/flecs_ecs/src/addons/metrics/mod.rs b/flecs_ecs/src/addons/metrics/mod.rs index ac078134..2dd48504 100644 --- a/flecs_ecs/src/addons/metrics/mod.rs +++ b/flecs_ecs/src/addons/metrics/mod.rs @@ -55,14 +55,14 @@ impl<'a> UntypedComponent<'a> { if let Some(parent) = parent { let component_name = unsafe { e.get_name_cstr() }; if let Some(metric_name) = metric_name { - world.run_in_scope_with_id(parent, || { + world.run_in_scope_with(parent, || { metric_entity = world.entity_named(metric_name); }); } else { let member_name = unsafe { core::ffi::CStr::from_ptr((*member).name) }; let member_name_str = member_name.to_str().expect("non valid Utf8 conversion"); if member_name_str == "value" || component_name.is_none() { - world.run_in_scope_with_id(parent, || { + world.run_in_scope_with(parent, || { metric_entity = world.entity_named(member_name_str); }); } else { @@ -75,7 +75,7 @@ impl<'a> UntypedComponent<'a> { .to_str() .expect("non valid Utf8 conversion") }; - world.run_in_scope_with_id(parent, || { + world.run_in_scope_with(parent, || { metric_entity = world.entity_named(snake_name_str); }); unsafe { @@ -89,7 +89,7 @@ impl<'a> UntypedComponent<'a> { } let mut metric = world.metric(metric_entity); - metric.member_id(me).kind::(); + metric.member(me).kind(id::()); if let Some(brief) = brief { metric.brief(brief); } diff --git a/flecs_ecs/src/addons/module.rs b/flecs_ecs/src/addons/module.rs index daefe8b8..8d9ced0d 100644 --- a/flecs_ecs/src/addons/module.rs +++ b/flecs_ecs/src/addons/module.rs @@ -3,6 +3,7 @@ //! * To define a module, see [`Module`]. //! * To import a module, see [`World::import()`]. //! * To override the name of a module, see [`World::module()`]. +use crate::core::utility::id; use crate::core::{ ComponentId, EntityView, FlecsConstantId, IdOperations, SEPARATOR, World, WorldProvider, ecs_pair, flecs, register_componment_data_explicit, @@ -74,7 +75,7 @@ impl World { /// * [`World::module()`] pub fn import(&self) -> EntityView { // Reset scope - let prev_scope = self.set_scope_id(0); + let prev_scope = self.set_scope(0); let module = if T::is_registered_with_world(self) { self.component::().entity @@ -96,7 +97,7 @@ impl World { }; // If we have already registered this type don't re-create the module - if module.has::() { + if module.has(id::()) { return module; } @@ -106,16 +107,16 @@ impl World { module.add_trait::(); // Set scope to our module - self.set_scope_id(module); + self.set_scope(module); // Build the module T::module(self); // Return out scope to the previous scope - self.set_scope_id(prev_scope); + self.set_scope(prev_scope); // Initialise component for the module and add Module tag - module.add::(); + module.add(flecs::Module::ID); module } @@ -147,7 +148,7 @@ impl World { let id = comp.id(); if let Some(existing) = self.try_lookup_recursive(name) { - self.set_scope_id(existing); + self.set_scope(existing); return existing; } diff --git a/flecs_ecs/src/addons/script/mod.rs b/flecs_ecs/src/addons/script/mod.rs index 1f2ef81c..9f450309 100644 --- a/flecs_ecs/src/addons/script/mod.rs +++ b/flecs_ecs/src/addons/script/mod.rs @@ -71,8 +71,6 @@ impl World { /// # Returns /// /// True if success, false if failed. - /// - /// # See also pub fn run_file(&self, filename: &str) -> bool { Script::run_file(self, filename) } @@ -86,10 +84,10 @@ impl World { #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn to_expr_id( &self, - id_of_value: impl Into, + id_of_value: impl IntoEntity, value: *const core::ffi::c_void, ) -> String { - Script::to_expr_id(self, id_of_value, value) + Script::to_expr(self, id_of_value, value) } /// Serialize value into a String. @@ -99,7 +97,11 @@ impl World { /// /// * C API: `ecs_ptr_to_expr` pub fn to_expr(&self, value: &T) -> String { - Script::to_expr(self, value) + Script::to_expr( + self, + id::(), + value as *const T as *const core::ffi::c_void, + ) } /// Wraps the provided entity id in a [`ScriptEntityView`]. @@ -107,16 +109,7 @@ impl World { /// # Panics /// /// The entity must have a [`flecs::Script`] component. - pub fn script_entity_from_id(&self, id: impl Into) -> ScriptEntityView { + pub fn script_entity_from(&self, id: impl IntoEntity) -> ScriptEntityView { ScriptEntityView::new_from(self, id) } - - /// Wraps the provided entity in a [`ScriptEntityView`]. - /// - /// # Panics - /// - /// The entity must have a [`flecs::Script`] component. - pub fn script_entity_from(&self) -> ScriptEntityView { - ScriptEntityView::new_from(self, T::id(self)) - } } diff --git a/flecs_ecs/src/addons/script/script_entity_view.rs b/flecs_ecs/src/addons/script/script_entity_view.rs index 4b7f2f59..cc612278 100644 --- a/flecs_ecs/src/addons/script/script_entity_view.rs +++ b/flecs_ecs/src/addons/script/script_entity_view.rs @@ -34,10 +34,10 @@ impl DerefMut for ScriptEntityView<'_> { impl<'a> ScriptEntityView<'a> { /// Create a new script entity view. - pub fn new_from(world: impl WorldProvider<'a>, entity: impl Into) -> Self { + pub fn new_from(world: impl WorldProvider<'a>, entity: impl IntoEntity) -> Self { let entity = EntityView::new_from(world, entity); ecs_assert!( - entity.has::(), + entity.has(id::()), FlecsErrorCode::InvalidParameter, "Entity does not have a script component" ); diff --git a/flecs_ecs/src/addons/script/unmanaged_script.rs b/flecs_ecs/src/addons/script/unmanaged_script.rs index 05ffb60a..32fbfc94 100644 --- a/flecs_ecs/src/addons/script/unmanaged_script.rs +++ b/flecs_ecs/src/addons/script/unmanaged_script.rs @@ -151,8 +151,6 @@ impl<'a> Script<'a> { /// # Returns /// /// True if success, false if failed. - /// - /// # See also pub fn run_file(world: impl WorldProvider<'a>, filename: &str) -> bool { let filename = compact_str::format_compact!("{}\0", filename); let world_ptr = world.world_ptr_mut(); @@ -207,12 +205,13 @@ impl<'a> Script<'a> { /// /// * C API: `ecs_ptr_to_expr` #[allow(clippy::not_unsafe_ptr_arg_deref)] - pub fn to_expr_id( + pub fn to_expr( world: impl WorldProvider<'a>, - id_of_value: impl Into, + id_of_value: impl IntoEntity, value: *const core::ffi::c_void, ) -> String { - let id = *id_of_value.into(); + let world = world.world(); + let id = *id_of_value.into_entity(world); let world = world.world_ptr_mut(); let expr = unsafe { sys::ecs_ptr_to_expr(world, id, value) }; let c_str = unsafe { CStr::from_ptr(expr) }; @@ -222,16 +221,4 @@ impl<'a> Script<'a> { }; str } - - /// Convert value to string - /// - /// # See also - /// - /// * C API: `ecs_ptr_to_expr` - #[allow(clippy::not_unsafe_ptr_arg_deref)] - pub fn to_expr(world: impl WorldProvider<'a>, value: &T) -> String { - let world = world.world(); - let id = T::get_id(world); - Self::to_expr_id(world, id, value as *const T as *const core::ffi::c_void) - } } diff --git a/flecs_ecs/src/addons/system/system_builder.rs b/flecs_ecs/src/addons/system/system_builder.rs index 1d470059..317c44ba 100644 --- a/flecs_ecs/src/addons/system/system_builder.rs +++ b/flecs_ecs/src/addons/system/system_builder.rs @@ -112,8 +112,8 @@ where /// # Arguments /// /// * `phase` - the phase - pub fn kind_id(&mut self, phase: impl Into) -> &mut Self { - let phase = *phase.into(); + pub fn kind(&mut self, phase: impl IntoEntity) -> &mut Self { + let phase = *phase.into_entity(self.world); let current_phase: sys::ecs_entity_t = unsafe { sys::ecs_get_target(self.world_ptr_mut(), self.desc.entity, ECS_DEPENDS_ON, 0) }; @@ -134,18 +134,6 @@ where self } - /// Specify in which phase the system should run - /// - /// # Type Parameters - /// - /// * `Phase` - the phase - pub fn kind(&mut self) -> &mut Self - where - Phase: ComponentId + ComponentType, - { - self.kind_id(Phase::id(self.world())) - } - /// Specify in which enum phase the system should run /// /// # Arguments @@ -156,7 +144,7 @@ where Phase: ComponentId + ComponentType + EnumComponentInfo, { let enum_id = phase.id_variant(self.world()); - self.kind_id(enum_id) + self.kind(enum_id) } /// Specify whether system can run on multiple threads. @@ -223,9 +211,6 @@ where type BuiltType = System<'a>; /// Build the `system_builder` into an system - /// - /// See also - /// fn build(&mut self) -> Self::BuiltType { let system = System::new(self.world(), self.desc); for s in self.term_builder.str_ptrs_to_free.iter_mut() { diff --git a/flecs_ecs/src/addons/timer.rs b/flecs_ecs/src/addons/timer.rs index 38450535..309d205d 100644 --- a/flecs_ecs/src/addons/timer.rs +++ b/flecs_ecs/src/addons/timer.rs @@ -4,7 +4,7 @@ use core::ops::{Deref, DerefMut}; use flecs_ecs_sys::{self as sys}; -use crate::core::{ComponentId, Entity, EntityView, QueryTuple, World, WorldProvider}; +use crate::core::{ComponentId, Entity, EntityView, IntoEntity, QueryTuple, World, WorldProvider}; use super::system::{System, SystemBuilder}; @@ -235,7 +235,7 @@ impl TimerAPI for System<'_> { } impl System<'_> { - /// Assign tick source to system based on a type. + /// Assign tick source to system based on an id. /// Systems can be their own tick source, which can be any of the tick sources (one shot timers, interval times and rate filters). /// However, in some cases it is must be guaranteed that different systems tick on the exact same frame. /// @@ -248,29 +248,16 @@ impl System<'_> { /// If the provided entity is not a tick source the system will not be ran. /// /// To disassociate a tick source from a system, use [`System::reset_tick_source()`](crate::addons::system::System::reset_tick_source). - pub fn set_tick_source(&self) { + pub fn set_tick_source(&self, id: impl IntoEntity) { unsafe { - sys::ecs_set_tick_source(self.entity.world_ptr_mut(), *self.id, T::id(self.world())); + sys::ecs_set_tick_source( + self.entity.world_ptr_mut(), + *self.id, + *id.into_entity(self.world), + ); } } - /// Assign tick source to system based on an id. - /// Systems can be their own tick source, which can be any of the tick sources (one shot timers, interval times and rate filters). - /// However, in some cases it is must be guaranteed that different systems tick on the exact same frame. - /// - /// This cannot be guaranteed by giving two systems the same interval/rate filter as it is possible - /// that one system is (for example) disabled, which would cause the systems to go out of sync. - /// To provide these guarantees, systems must use the same tick source, which is what this operation enables. - /// - /// When two systems share the same tick source, it is guaranteed that they tick in the same frame. - /// The provided tick source can be any entity that is a tick source, including another system. - /// If the provided entity is not a tick source the system will not be ran. - /// - /// To disassociate a tick source from a system, use [`System::reset_tick_source()`](crate::addons::system::System::reset_tick_source). - pub fn set_tick_source_id(&self, id: impl Into) { - unsafe { sys::ecs_set_tick_source(self.entity.world_ptr_mut(), *self.id, *id.into()) } - } - /// Reset, disassociate a tick source from a system pub fn reset_tick_source(&self) { unsafe { sys::ecs_set_tick_source(self.entity.world_ptr_mut(), *self.id, 0) } @@ -307,18 +294,10 @@ impl SystemBuilder<'_, T> { self } - /// Set tick source with the type associated with the singleton - /// tick source to use for the system. - /// This operation sets a shared tick source for the system. - pub fn set_tick_source(&mut self) -> &mut Self { - self.desc.tick_source = C::id(self.world()); - self - } - /// Set tick source. /// This operation sets a shared tick source for the system. - pub fn set_tick_source_id(&mut self, tick_source: impl Into) -> &mut Self { - self.desc.tick_source = *tick_source.into(); + pub fn set_tick_source(&mut self, tick_source: impl IntoEntity) -> &mut Self { + self.desc.tick_source = *tick_source.into_entity(self.world()); self } } diff --git a/flecs_ecs/src/core/archetype.rs b/flecs_ecs/src/core/archetype.rs index b28caf39..4b88dd12 100644 --- a/flecs_ecs/src/core/archetype.rs +++ b/flecs_ecs/src/core/archetype.rs @@ -33,7 +33,7 @@ pub struct Archetype<'a> { impl Display for Archetype<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { if let Some(s) = self.to_string() { - write!(f, "{}", s) + write!(f, "{s}") } else { write!(f, "empty archetype") } diff --git a/flecs_ecs/src/core/components/component.rs b/flecs_ecs/src/core/components/component.rs index 9cd51b5f..77b799c1 100644 --- a/flecs_ecs/src/core/components/component.rs +++ b/flecs_ecs/src/core/components/component.rs @@ -161,9 +161,6 @@ impl<'a, T> Component<'a, T> { } /// Function to free the binding context. - /// - /// # See also - /// unsafe extern "C-unwind" fn binding_ctx_drop(ptr: *mut c_void) { let ptr_struct: *mut ComponentBindingCtx = ptr as *mut ComponentBindingCtx; unsafe { diff --git a/flecs_ecs/src/core/components/component_untyped.rs b/flecs_ecs/src/core/components/component_untyped.rs index 6763a2fc..ac613cff 100644 --- a/flecs_ecs/src/core/components/component_untyped.rs +++ b/flecs_ecs/src/core/components/component_untyped.rs @@ -62,7 +62,7 @@ impl<'a> UntypedComponent<'a> { /// /// * `world`: the world. /// * `id`: the id of the component to reference. - pub(crate) fn new_from(world: impl WorldProvider<'a>, id: impl Into) -> Self { + pub(crate) fn new_from(world: impl WorldProvider<'a>, id: impl IntoEntity) -> Self { UntypedComponent { entity: EntityView::new_from(world, id), } diff --git a/flecs_ecs/src/core/components/lifecycle_traits.rs b/flecs_ecs/src/core/components/lifecycle_traits.rs index 525dbac8..a9da328e 100644 --- a/flecs_ecs/src/core/components/lifecycle_traits.rs +++ b/flecs_ecs/src/core/components/lifecycle_traits.rs @@ -104,9 +104,6 @@ pub fn register_copy_panic_lifecycle_action(type_hooks: &mut sys::ecs_type_ho /// * `ptr` - pointer to the memory to be initialized /// * `count` - number of elements to be initialized /// * `_type_info` - type info for the type to be initialized -/// -/// # See also -/// extern "C-unwind" fn ctor( ptr: *mut c_void, count: i32, @@ -133,9 +130,6 @@ extern "C-unwind" fn ctor( /// * `ptr` - pointer to the memory to be destructed /// * `count` - number of elements to be destructed /// * `_type_info` - type info for the type to be destructed -/// -/// # See also -/// extern "C-unwind" fn dtor( ptr: *mut c_void, count: i32, @@ -156,9 +150,6 @@ extern "C-unwind" fn dtor( /// This is the generic copy for trivial types /// It will copy the memory -/// -/// # See also -/// extern "C-unwind" fn copy( dst_ptr: *mut c_void, src_ptr: *const c_void, @@ -184,9 +175,6 @@ extern "C-unwind" fn copy( /// This is the generic copy for trivial types /// It will copy the memory -/// -/// # See also -/// extern "C-unwind" fn copy_ctor( dst_ptr: *mut c_void, src_ptr: *const c_void, @@ -234,9 +222,6 @@ extern "C-unwind" fn panic_copy( /// This is the generic move for non-trivial types /// It will move the memory -/// -/// # See also -/// extern "C-unwind" fn move_dtor( dst_ptr: *mut c_void, src_ptr: *mut c_void, @@ -265,9 +250,6 @@ extern "C-unwind" fn move_dtor( } /// a move to from src to dest where src will not be used anymore and dest is in control of the drop. -/// -/// # See also -/// extern "C-unwind" fn move_ctor( dst_ptr: *mut c_void, src_ptr: *mut c_void, diff --git a/flecs_ecs/src/core/ecs_os_api.rs b/flecs_ecs/src/core/ecs_os_api.rs index 148bc31e..de196a49 100644 --- a/flecs_ecs/src/core/ecs_os_api.rs +++ b/flecs_ecs/src/core/ecs_os_api.rs @@ -4,7 +4,6 @@ //! This module provides a basic structure for hooking into the initialization //! of that API, which allows, for example, customizing how Flecs sends log //! messages. -//! #[cfg(feature = "std")] extern crate std; diff --git a/flecs_ecs/src/core/entity_view/bulk_entity_builder.rs b/flecs_ecs/src/core/entity_view/bulk_entity_builder.rs index 64228c96..da24cdd7 100644 --- a/flecs_ecs/src/core/entity_view/bulk_entity_builder.rs +++ b/flecs_ecs/src/core/entity_view/bulk_entity_builder.rs @@ -159,7 +159,7 @@ impl<'a> BulkEntityBuilder<'a> { /// let entities_created = world.entity_bulk(10).add_id(entity).build(); /// ``` pub fn add_id(&mut self, id: impl IntoId) -> &mut Self { - let id = *id.into(); + let id = *id.into_id(self.world); let world = self.world.world_ptr_mut(); check_add_id_validity(world, id); @@ -290,8 +290,8 @@ impl<'a> BulkEntityBuilder<'a> { /// let ent = world /// .entity() /// .set(Position { x: 0, y: 0 }) - /// .add::() - /// .add_id(ent_id); + /// .add(id::()) + /// .add(ent_id); /// /// let mut table = ent.table().unwrap(); /// diff --git a/flecs_ecs/src/core/entity_view/entity_view_const.rs b/flecs_ecs/src/core/entity_view/entity_view_const.rs index 837423d9..bef34ad6 100644 --- a/flecs_ecs/src/core/entity_view/entity_view_const.rs +++ b/flecs_ecs/src/core/entity_view/entity_view_const.rs @@ -53,7 +53,7 @@ use alloc::{borrow::ToOwned, boxed::Box, format, string::String, string::ToStrin /// .entity_named("Player") /// .set(Position { x: 10.0, y: 20.0 }) /// .set(Velocity { x: 1.0, y: 0.0 }) -/// .add::(); +/// .add(id::()); /// /// // Get component data /// player.get::<&Position>(|pos| { @@ -61,10 +61,10 @@ use alloc::{borrow::ToOwned, boxed::Box, format, string::String, string::ToStrin /// }); /// /// // Check for components -/// assert!(player.has::()); +/// assert!(player.has(id::())); /// /// // Remove components -/// player.remove::(); +/// player.remove(id::()); /// ``` /// /// Working with hierarchies: @@ -74,7 +74,7 @@ use alloc::{borrow::ToOwned, boxed::Box, format, string::String, string::ToStrin /// let world = World::new(); /// /// let parent = world.entity_named("parent"); -/// let child = world.entity_named("child").child_of_id(parent); +/// let child = world.entity_named("child").child_of(parent); /// /// assert!(parent.has_children()); /// assert_eq!(child.path().unwrap(), "::parent::child"); @@ -209,11 +209,10 @@ impl<'a> EntityView<'a> { /// * [`Entity::entity_view()`] - Convert Entity to EntityView /// * [`World::entity_from_id()`] - Get entity view from ID #[doc(hidden)] //public due to macro newtype_of and world.entity_from_id has lifetime issues. - pub fn new_from(world: impl WorldProvider<'a>, id: impl Into) -> Self { - Self { - world: world.world(), - id: id.into(), - } + pub fn new_from(world: impl WorldProvider<'a>, id: impl IntoEntity) -> Self { + let world = world.world(); + let id = id.into_entity(world); + Self { world, id } } /// Create a named entity. @@ -446,10 +445,6 @@ impl<'a> EntityView<'a> { // /// Returns the entity name as a `CStr`. // /// // /// if the entity has no name, this will return an empty string - // /// - // /// # See also - // /// - // /// * C++ API: `entity_view::name` // pub fn name_cstr(self) -> &'a CStr { // self.get_name_cstr().unwrap_or(c"") // } @@ -496,7 +491,7 @@ impl<'a> EntityView<'a> { /// let parent = world.entity_named("Parent"); /// /// // Create child entity - /// let child = world.entity_named("Child").child_of_id(parent); + /// let child = world.entity_named("Child").child_of(parent); /// /// assert_eq!( /// child.path_w_sep("::", "::"), @@ -513,7 +508,7 @@ impl<'a> EntityView<'a> { /// * [`EntityView::path()`] - Get path with default separator /// * [`EntityView::name()`] - Get entity name only pub fn path_w_sep(self, sep: &str, init_sep: &str) -> Option { - self.path_from_id_w_sep(0, sep, init_sep) + self.path_from_w_sep(0, sep, init_sep) } /// Return the hierarchical entity path using the default separator "::". @@ -525,7 +520,7 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let parent = world.entity_named("Parent"); - /// let child = world.entity_named("Child").child_of_id(parent); + /// let child = world.entity_named("Child").child_of(parent); /// /// assert_eq!(child.path(), Some("::Parent::Child".to_string())); /// ``` @@ -535,7 +530,7 @@ impl<'a> EntityView<'a> { /// * [`EntityView::path_w_sep()`] - Get path with custom separator /// * [`EntityView::path_from()`] - Get path relative to parent pub fn path(self) -> Option { - self.path_from_id(0) + self.path_from(0) } /// Return the hierarchical entity path relative to a parent. @@ -554,18 +549,18 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let root = world.entity_named("Root"); - /// let parent = world.entity_named("Parent").child_of_id(root); - /// let child = world.entity_named("Child").child_of_id(parent); + /// let parent = world.entity_named("Parent").child_of(root); + /// let child = world.entity_named("Child").child_of(parent); /// /// // Get path relative to root /// assert_eq!( - /// child.path_from_id_w_sep(root, "::", "::"), + /// child.path_from_w_sep(root, "::", "::"), /// Some("Parent::Child".to_string()) /// ); /// /// // Get path relative to parent /// assert_eq!( - /// child.path_from_id_w_sep(parent, "::", "::"), + /// child.path_from_w_sep(parent, "::", "::"), /// Some("Child".to_string()) /// ); /// ``` @@ -574,9 +569,9 @@ impl<'a> EntityView<'a> { /// /// * [`EntityView::path_from()`] - Get path relative to parent type /// * [`EntityView::path()`] - Get full path - pub fn path_from_id_w_sep( + pub fn path_from_w_sep( &self, - parent: impl Into, + parent: impl IntoEntity, sep: &str, init_sep: &str, ) -> Option { @@ -586,7 +581,7 @@ impl<'a> EntityView<'a> { NonNull::new(unsafe { sys::ecs_get_path_w_sep( self.world.world_ptr(), - *parent.into(), + *parent.into_entity(self.world), *self.id, sep.as_ptr() as *const _, init_sep.as_ptr() as *const _, @@ -600,24 +595,6 @@ impl<'a> EntityView<'a> { }) } - fn path_from_id_default_sep(&self, parent: impl Into) -> Option { - NonNull::new(unsafe { - sys::ecs_get_path_w_sep( - self.world.world_ptr(), - *parent.into(), - *self.id, - SEPARATOR.as_ptr(), - SEPARATOR.as_ptr(), - ) - }) - .map(|s| unsafe { - let len = CStr::from_ptr(s.as_ptr()).to_bytes().len(); - // Convert the C string to a Rust String without any new heap allocation. - // The String will de-allocate the C string when it goes out of scope. - String::from_utf8_unchecked(Vec::from_raw_parts(s.as_ptr() as *mut u8, len, len)) - }) - } - /// Return the hierarchical entity path relative to a parent id using the default separator "::". /// /// # Examples @@ -627,21 +604,21 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let root = world.entity_named("Root"); - /// let parent = world.entity_named("Parent").child_of_id(root); - /// let child = world.entity_named("Child").child_of_id(parent); + /// let parent = world.entity_named("Parent").child_of(root); + /// let child = world.entity_named("Child").child_of(parent); /// - /// assert_eq!(child.path_from_id(root), Some("Parent::Child".to_string())); + /// assert_eq!(child.path_from(root), Some("Parent::Child".to_string())); /// ``` /// /// # See also /// - /// * [`EntityView::path_from_id_w_sep()`] - Get path with custom separator + /// * [`EntityView::path_from_w_sep()`] - Get path with custom separator /// * [`EntityView::path_from()`] - Get path relative to parent type - pub fn path_from_id(self, parent: impl Into) -> Option { + pub fn path_from(self, parent: impl IntoEntity) -> Option { NonNull::new(unsafe { sys::ecs_get_path_w_sep( self.world.world_ptr(), - *parent.into(), + *parent.into_entity(self.world), *self.id, SEPARATOR.as_ptr(), SEPARATOR.as_ptr(), @@ -656,64 +633,9 @@ impl<'a> EntityView<'a> { }) } - /// Return the hierarchical entity path relative to a parent type. - /// - /// Gets the path relative to an entity of the specified component type. - /// - /// # Examples - /// - /// ``` - /// # use flecs_ecs::prelude::*; - /// #[derive(Component)] - /// struct Earth; - /// - /// let world = World::new(); - /// let sun = world.entity_named("Sun"); - /// let earth = world.component::().child_of_id(sun); - /// let moon = world.entity_named("Moon").child_of_id(earth); - /// - /// // Get moon's path relative to nearest Planet - /// assert_eq!(moon.path_from::(), Some("Moon".to_string())); - /// ``` - /// - /// # See also - /// - /// * [`EntityView::path_from_id()`] - Get path relative to specific entity - /// * [`EntityView::path()`] - Get full path - pub fn path_from(self) -> Option { - self.path_from_id_default_sep(T::id(self.world)) - } - /// Return the hierarchical entity path relative to a parent type with custom separators. - /// - /// # Examples - /// - /// ``` - /// # use flecs_ecs::prelude::*; - /// #[derive(Component)] - /// struct Sun; - /// - /// let world = World::new(); - /// let sun = world.component::(); - /// let earth = world.entity_named("Earth").child_of_id(sun); - /// let moon = world.entity_named("Moon").child_of_id(earth); - /// - /// assert_eq!( - /// moon.path_from_w_sep::("/", "/"), - /// Some("Earth/Moon".to_string()) - /// ); - /// ``` - /// - /// # See also - /// - /// * [`EntityView::path_from()`] - Get path with default separator - /// * [`EntityView::path_from_id_w_sep()`] - Get path relative to ID with custom separator - pub fn path_from_w_sep(&self, sep: &str, init_sep: &str) -> Option { - self.path_from_id_w_sep(T::id(self.world), sep, init_sep) - } - /// Return the hierarchical entity path relative to a parent type using the default separator "::". - pub fn hierarchy_path_from_parent_type(self) -> Option { - self.path_from_id(T::id(self.world)) + pub fn hierarchy_path_from_parent(self, id: impl IntoEntity) -> Option { + self.path_from(id) } /// Checks if the entity is enabled. @@ -790,7 +712,7 @@ impl<'a> EntityView<'a> { /// } /// /// let world = World::new(); - /// let entity = world.entity().add::(); + /// let entity = world.entity().add(id::()); /// /// if let Some(table) = entity.table() { /// println!( @@ -833,7 +755,7 @@ impl<'a> EntityView<'a> { /// } /// /// let world = World::new(); - /// let entity = world.entity().add::(); + /// let entity = world.entity().add(id::()); /// /// if let Some(range) = entity.range() { /// println!("Entity is at row {} in its table", range.offset()); @@ -922,8 +844,8 @@ impl<'a> EntityView<'a> { /// /// let entity = world /// .entity() - /// .add_first::(apple) - /// .add_first::(banana); + /// .add((id::(), apple)) + /// .add((id::(), banana)); /// /// // Iterate over all "Likes" relationships /// entity.each_pair(world.component_id::(), flecs::Wildcard::ID, |id| { @@ -990,11 +912,11 @@ impl<'a> EntityView<'a> { /// let parent = world.entity_named("Parent"); /// /// // Create some child entities - /// let child1 = world.entity_named("Child1").child_of_id(parent); - /// let child2 = world.entity_named("Child2").child_of_id(parent); + /// let child1 = world.entity_named("Child1").child_of(parent); + /// let child2 = world.entity_named("Child2").child_of(parent); /// /// // Iterate over all children - /// parent.each_target_id(flecs::ChildOf::ID, |child| { + /// parent.each_target(flecs::ChildOf::ID, |child| { /// println!("Found child: {}", child.name()); /// }); /// ``` @@ -1004,48 +926,13 @@ impl<'a> EntityView<'a> { /// * [`EntityView::each_component()`] - Iterate over all components /// * [`EntityView::each_pair()`] - Iterate over pairs /// * [`EntityView::target_id_count()`] - Get number of targets - pub fn each_target_id(self, relationship: impl Into, mut func: impl FnMut(EntityView)) { - self.each_pair(relationship.into(), ECS_WILDCARD, |id| { + pub fn each_target(self, relationship: impl IntoEntity, mut func: impl FnMut(EntityView)) { + self.each_pair(relationship.into_entity(self.world), ECS_WILDCARD, |id| { let obj = id.second_id(); func(obj); }); } - /// Iterate over targets for a given relationship type. - /// - /// # Examples - /// - /// ```rust - /// use flecs_ecs::prelude::*; - /// - /// #[derive(Component)] - /// struct Likes; - /// - /// let world = World::new(); - /// let entity = world.entity(); - /// let apple = world.entity_named("Apple"); - /// let banana = world.entity_named("Banana"); - /// - /// entity.add_first::(apple).add_first::(banana); - /// - /// entity.each_target::(|target| { - /// println!("Entity likes: {}", target.name()); - /// }); - /// ``` - /// - /// # See also - /// - /// * [`EntityView::each_component()`] - Iterate over all components - /// * [`EntityView::each_pair()`] - Iterate over pairs - /// * [`EntityView::target_count()`] - Get number of targets - /// * [`EntityView::each_target_id()`] - Iterate over targets for a specific relationship - pub fn each_target(self, func: impl FnMut(EntityView)) - where - T: ComponentId, - { - self.each_target_id(EntityView::new_from(self.world, T::id(self.world)), func); - } - /// Get the count of targets for a given relationship. /// /// Returns the number of entities that are targets of the specified relationship. @@ -1064,7 +951,7 @@ impl<'a> EntityView<'a> { /// let apple = world.entity_named("Apple"); /// let banana = world.entity_named("Banana"); /// - /// entity.add_id((likes,apple)).add_id((likes,banana)); + /// entity.add((likes, apple)).add((likes, banana)); /// /// assert_eq!(entity.target_id_count(likes), Some(2)); /// ``` @@ -1077,7 +964,7 @@ impl<'a> EntityView<'a> { /// # See also /// /// * [`EntityView::target_count()`] - Type-safe version - /// * [`EntityView::each_target_id()`] - Iterate over targets + /// * [`EntityView::each_target()`] - Iterate over targets pub fn target_id_count(self, relationship: impl Into) -> Option { let world = self.world.real_world().ptr_mut(); let id = ecs_pair(*relationship.into(), ECS_WILDCARD); @@ -1105,7 +992,9 @@ impl<'a> EntityView<'a> { /// let apple = world.entity_named("Apple"); /// let banana = world.entity_named("Banana"); /// - /// entity.add_first::(apple).add_first::(banana); + /// entity + /// .add((id::(), apple)) + /// .add((id::(), banana)); /// /// assert_eq!(entity.target_count::(), Some(2)); /// ``` @@ -1133,9 +1022,9 @@ impl<'a> EntityView<'a> { /// /// * `relationship` - The relationship to follow /// * `func` - The function invoked for each child. Must match the signature `FnMut(EntityView)`. - pub fn each_child_of_id( + pub fn each_child_of( self, - relationship: impl Into, + relationship: impl IntoEntity, mut func: impl FnMut(EntityView), ) -> bool { let mut count = 0; @@ -1147,8 +1036,12 @@ impl<'a> EntityView<'a> { return false; } - let mut it: sys::ecs_iter_t = - unsafe { sys::ecs_each_id(self.world_ptr(), ecs_pair(*relationship.into(), *self.id)) }; + let mut it: sys::ecs_iter_t = unsafe { + sys::ecs_each_id( + self.world_ptr(), + ecs_pair(*relationship.into_entity(self.world), *self.id), + ) + }; while unsafe { sys::ecs_each_next(&mut it) } { count += it.count; for i in 0..it.count as usize { @@ -1163,19 +1056,6 @@ impl<'a> EntityView<'a> { count > 0 } - /// Iterate children for entity - /// - /// # Arguments - /// - /// * T - The relationship to follow - /// * `func` - The function invoked for each child. Must match the signature `FnMut(EntityView)`. - pub fn each_child_of(self, func: impl FnMut(EntityView)) -> bool - where - T: ComponentId, - { - self.each_child_of_id(T::id(self.world), func) - } - /// Iterate children for entity /// This operation follows the `ChildOf` relationship. /// @@ -1187,7 +1067,7 @@ impl<'a> EntityView<'a> { /// /// Returns `true` if the entity has children, `false` otherwise. pub fn each_child(self, func: impl FnMut(EntityView)) -> bool { - self.each_child_of_id(flecs::ChildOf::ID, func) + self.each_child_of(flecs::ChildOf::ID, func) } /// Returns if the entity has any children. @@ -1200,7 +1080,7 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let parent = world.entity(); - /// let child = world.entity().child_of_id(parent); + /// let child = world.entity().child_of(parent); /// /// assert!(parent.has_children()); /// assert!(!child.has_children()); @@ -1224,11 +1104,11 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let parent = world.entity(); - /// let child = world.entity().child_of_id(parent); + /// let child = world.entity().child_of(parent); /// /// assert_eq!(parent.count_children(), 1); /// - /// let child2 = world.entity().child_of_id(parent); + /// let child2 = world.entity().child_of(parent); /// /// assert_eq!(parent.count_children(), 2); /// ``` @@ -1237,11 +1117,11 @@ impl<'a> EntityView<'a> { unsafe { sys::ecs_iter_count(&mut it) as u32 } } - /// Returns the count of targets for a given relationship. + /// Returns the count of targets for a given relationship id. /// /// # Arguments /// - /// * `relationship` - The relationship to follow + /// * `relationship` - The relationship id to follow /// /// # Example /// @@ -1251,56 +1131,25 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let parent = world.entity(); - /// let child = world.entity().child_of_id(parent); + /// let child = world.entity().child_of(parent); /// - /// assert_eq!(parent.count_relationship::(), 1); + /// assert_eq!(parent.count_relationship(id::()), 1); /// - /// let child2 = world.entity().child_of_id(parent); + /// let child2 = world.entity().child_of(parent); /// - /// assert_eq!(parent.count_relationship::(), 2); + /// assert_eq!(parent.count_relationship(id::()), 2); /// ``` - pub fn count_relationship(self) -> u32 { + pub fn count_relationship(self, relationship: impl IntoEntity) -> u32 { let world = self.world; let mut it = unsafe { sys::ecs_each_id( world.world_ptr(), - ecs_pair(*world.component_id::(), *self.id), + ecs_pair(*relationship.into_entity(self.world), *self.id), ) }; unsafe { sys::ecs_iter_count(&mut it) as u32 } } - - /// Returns the count of targets for a given relationship id. - /// - /// # Arguments - /// - /// * `relationship` - The relationship id to follow - /// - /// # Example - /// - /// ```rust - /// use flecs_ecs::prelude::*; - /// - /// let world = World::new(); - /// - /// let parent = world.entity(); - /// let child = world.entity().child_of_id(parent); - /// - /// assert_eq!(parent.count_relationship_id(flecs::ChildOf::ID), 1); - /// - /// let child2 = world.entity().child_of_id(parent); - /// - /// assert_eq!(parent.count_relationship_id(flecs::ChildOf::ID), 2); - /// ``` - pub fn count_relationship_id(self, relationship: impl Into) -> u32 { - let world = self.world; - let mut it = unsafe { - sys::ecs_each_id(world.world_ptr(), ecs_pair(*relationship.into(), *self.id)) - }; - - unsafe { sys::ecs_iter_count(&mut it) as u32 } - } } pub trait EntityViewGet { @@ -1654,7 +1503,13 @@ impl<'a> EntityView<'a> { /// Ensure the pointer is valid before use. The caller must know the actual type to cast the pointer correctly. /// The pointer might get invalided if the table alters. pub fn get_untyped(self, component_id: impl IntoId) -> *const c_void { - unsafe { sys::ecs_get_id(self.world.world_ptr(), *self.id, *component_id.into()) } + unsafe { + sys::ecs_get_id( + self.world.world_ptr(), + *self.id, + *component_id.into_id(self), + ) + } } /// Get the pair value as untyped pointer. @@ -1736,7 +1591,7 @@ impl<'a> EntityView<'a> { /// Ensure the pointer is valid before use. The caller must know the actual type to cast the pointer correctly. /// The pointer might get invalided if the table alters. pub fn get_untyped_mut(self, id: impl IntoId) -> *mut c_void { - unsafe { sys::ecs_get_mut_id(self.world.world_ptr(), *self.id(), *id.into()) } + unsafe { sys::ecs_get_mut_id(self.world.world_ptr(), *self.id(), *id.into_id(self)) } } /// Get mutable pair value as untyped pointer. @@ -1808,19 +1663,16 @@ impl<'a> EntityView<'a> { /// index can be used to iterate through targets, in case the entity `get_has` /// multiple instances for the same relationship. /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// /// # Arguments /// + /// * `first` - The first element of the pair for which to retrieve the target. /// * `index` - The index (0 for the first instance of the relationship). - pub fn target(self, index: i32) -> Option> { + pub fn target(self, first: impl IntoEntity, index: i32) -> Option> { let id = unsafe { sys::ecs_get_target( self.world.world_ptr(), *self.id, - First::id(self.world), + *first.into_entity(self.world), index, ) }; @@ -1831,26 +1683,6 @@ impl<'a> EntityView<'a> { } } - /// Get target for a given pair. - /// - /// This operation returns the target for a given pair. The optional - /// index can be used to iterate through targets, in case the entity `get_has` - /// multiple instances for the same relationship. - /// - /// # Arguments - /// - /// * `first` - The first element of the pair for which to retrieve the target. - /// * `index` - The index (0 for the first instance of the relationship). - pub fn target_id(self, first: impl Into, index: i32) -> Option> { - let id = - unsafe { sys::ecs_get_target(self.world.world_ptr(), *self.id, *first.into(), index) }; - if id == 0 { - None - } else { - Some(EntityView::new_from(self.world, id)) - } - } - /// Get the target of a pair for a given relationship id. /// /// This operation returns the first entity that has the provided id by following @@ -1870,17 +1702,17 @@ impl<'a> EntityView<'a> { /// # See also /// /// * [`EntityView::target_for()`] - pub fn target_for_id( + pub fn target_for( &self, - relationship: impl Into, + relationship: impl IntoEntity, component_id: impl IntoId, ) -> Option> { let id = unsafe { sys::ecs_get_target_for_id( self.world.world_ptr(), *self.id, - *relationship.into(), - *component_id.into(), + *relationship.into_entity(self.world), + *component_id.into_id(self.world), ) }; if id == 0 { @@ -1890,47 +1722,6 @@ impl<'a> EntityView<'a> { } } - /// Get the target for a given component and relationship. - /// - /// This function is a convenient wrapper around `get_target_by_relationship_and_component_id`, - /// allowing callers to provide a type and automatically deriving the component id. - /// - /// This operation can be used to lookup, for example, which prefab is providing - /// a component by specifying the `IsA` pair: - /// - /// ``` - /// # use flecs_ecs::prelude::*; - /// # let world = World::new(); - /// # let entity = world.entity(); - /// # #[derive(Component)] - /// # struct Position(f32, f32, f32); - /// // Is Position provided by the entity or one of its base entities? - /// let e = entity.target_for::(flecs::IsA::ID); - /// ``` - /// - /// # Type Parameters - /// - /// * `T` - The component type to use for deriving the id. - /// - /// # Arguments - /// - /// * `relationship` - The relationship to follow. - /// - /// # Returns - /// - /// * The entity for which the target `get_has` been found. - /// - /// # See also - /// - /// * [`EntityView::target_for_id()`] - #[inline(always)] - pub fn target_for( - self, - relationship: impl Into, - ) -> Option> { - self.target_for_id(relationship, T::get_id(self.world)) - } - // TODO this needs a better name and documentation, the rest of the cpp functions still have to be done as well // TODO, I removed the second template parameter and changed the fn parameter second to entityT, check validity /// Get the target for a given pair of components and a relationship. @@ -1948,7 +1739,6 @@ impl<'a> EntityView<'a> { /// * The entity for which the target has been found. /// /// # See also - /// // TODO needs to be made safe pub(crate) fn target_for_first( &self, @@ -1979,25 +1769,14 @@ impl<'a> EntityView<'a> { /// /// * The depth of the relationship. #[inline(always)] - pub fn depth_id(self, relationship: impl Into) -> i32 { - unsafe { sys::ecs_get_depth(self.world.world_ptr(), *self.id, *relationship.into()) } - } - - /// Retrieves the depth for a specified relationship. - /// - /// This function is a convenient wrapper around `get_depth_id`, allowing callers - /// to provide a type and automatically deriving the relationship id. - /// - /// # Type Parameters - /// - /// * `T` - The relationship type to use for deriving the id. - /// - /// # Returns - /// - /// * The depth of the relationship. - #[inline(always)] - pub fn depth(self) -> i32 { - self.depth_id(T::id(self.world)) + pub fn depth(self, relationship: impl IntoEntity) -> i32 { + unsafe { + sys::ecs_get_depth( + self.world.world_ptr(), + *self.id, + *relationship.into_entity(self.world), + ) + } } /// Retrieves the parent of the entity. @@ -2009,7 +1788,7 @@ impl<'a> EntityView<'a> { /// * The parent of the entity. #[inline(always)] pub fn parent(self) -> Option> { - self.target_id(ECS_CHILD_OF, 0) + self.target(ECS_CHILD_OF, 0) } /// Lookup an entity by name. @@ -2110,10 +1889,7 @@ impl<'a> EntityView<'a> { #[inline(always)] pub fn lookup_recursive(&self, name: &str) -> EntityView { self.try_lookup_recursive(name).unwrap_or_else(|| { - panic!( - "Entity {} not found, when unsure, use try_lookup_recursive", - name - ) + panic!("Entity {name} not found, when unsure, use try_lookup_recursive") }) } @@ -2154,52 +1930,21 @@ impl<'a> EntityView<'a> { /// /// * [`EntityView::has()`] #[inline(always)] - pub fn has_id(self, id: impl IntoId) -> bool { - unsafe { sys::ecs_has_id(self.world.world_ptr(), *self.id, *id.into()) } - } - - /// Check if entity has the provided component. - /// - /// # Type Parameters - /// - /// * `T` - The component to check. - /// - /// # Returns - /// - /// True if the entity has or inherits the provided component, false otherwise. - /// - /// # See also - /// - /// * [`EntityView::has_id()`] - pub fn has(self) -> bool { - if !T::IS_ENUM { - unsafe { sys::ecs_has_id(self.world.world_ptr(), *self.id, T::get_id(self.world)) } + pub fn has(self, id: T) -> bool { + if !::IS_ENUM { + unsafe { sys::ecs_has_id(self.world.world_ptr(), *self.id, *id.into_id(self.world)) } } else { - let component_id = T::get_id(self.world); - self.has_id((component_id, ECS_WILDCARD)) + let component_id = id.into_id(self.world); + self.has((component_id, ECS_WILDCARD)) } } - /// Check if entity has the provided enum constant. - /// - /// # Type Parameters - /// - /// * `T` - The enum type. - /// - /// # Arguments - /// - /// * `constant` - The enum constant to check. - /// - /// # Returns - /// - /// True if the entity has the provided constant, false otherwise. - pub fn has_enum(self, constant: T) -> bool + // this is pub(crate) because it's used for development purposes only + pub(crate) fn has_enum(self, enum_id: impl IntoEntity, constant: T) -> bool where T: ComponentId + ComponentType + EnumComponentInfo, { - let component_id: sys::ecs_id_t = T::id(self.world); - // Safety: we know the enum fields are registered because of the previous T::id call - let enum_constant_entity_id = unsafe { constant.id_variant_unchecked(self.world) }; + let enum_constant_entity_id = constant.id_variant(self.world); ecs_assert!( *enum_constant_entity_id.id != 0, @@ -2207,50 +1952,7 @@ impl<'a> EntityView<'a> { "Constant was not found in Enum reflection data. Did you mean to use has() instead of has(E)?" ); - self.has_id((component_id, enum_constant_entity_id)) - } - - // this is pub(crate) because it's used for development purposes only - pub(crate) fn has_enum_id(self, enum_id: impl Into, constant: T) -> bool - where - T: ComponentId + ComponentType + EnumComponentInfo, - { - let enum_constant_entity_id = constant.id_variant(self.world); - self.has_id((enum_id.into(), enum_constant_entity_id)) - } - - /// Check if entity has the provided pair. - /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// - /// # Arguments - /// - /// * `second` - The second element of the pair. - /// - /// # Returns - /// - /// True if the entity has the provided component, false otherwise. - pub fn has_first(self, second: impl Into) -> bool { - self.has_id((First::id(self.world), second.into())) - } - - /// Check if entity has the provided pair. - /// - /// # Type Parameters - /// - /// * `Second` - The second element of the pair. - /// - /// # Arguments - /// - /// * `first` - The first element of the pair. - /// - /// # Returns - /// - /// True if the entity has the provided component, false otherwise. - pub fn has_second(self, first: impl Into) -> bool { - self.has_id((first.into(), Second::id(self.world))) + self.has((enum_id.into_entity(self.world), enum_constant_entity_id)) } /// Check if entity has the provided pair with an enum constant. @@ -2274,7 +1976,7 @@ impl<'a> EntityView<'a> { let component_id: sys::ecs_id_t = T::id(self.world); let enum_constant_entity_id = constant.id_variant(self.world); - self.has_id((component_id, enum_constant_entity_id)) + self.has((component_id, enum_constant_entity_id)) } /// Check if the entity owns the provided entity (pair, component, entity). @@ -2285,66 +1987,12 @@ impl<'a> EntityView<'a> { /// /// # Returns /// - `true` if the entity owns the provided entity, `false` otherwise. - pub fn owns_id(self, entity_id: impl IntoId) -> bool { - unsafe { sys::ecs_owns_id(self.world.world_ptr(), *self.id, *entity_id.into()) } - } - - /// Check if the entity owns the provided component. - /// A component is owned if it is not shared from a base entity. - /// - /// # Type Parameters - /// - /// - `T`: The component to check. - /// - /// # Returns - /// - /// - `true` if the entity owns the provided component, `false` otherwise. - pub fn owns(self) -> bool { - unsafe { sys::ecs_owns_id(self.world.world_ptr(), *self.id, T::get_id(self.world)) } - } - - /// Check if the entity owns the provided pair. - /// A pair is owned if it is not shared from a base entity. - /// - /// # Type Parameters - /// - `First`: The first element of the pair. - /// - /// # Arguments - /// - /// - `second`: The second element of the pair. - /// - /// # Returns - /// - /// - `true` if the entity owns the provided pair, `false` otherwise. - pub fn owns_first(self, second: impl Into) -> bool { - unsafe { - sys::ecs_owns_id( - self.world.world_ptr(), - *self.id, - ecs_pair(First::id(self.world), *second.into()), - ) - } - } - - /// Check if the entity owns the provided pair. - /// A pair is owned if it is not shared from a base entity. - /// - /// # Type Parameters - /// - `Second`: The first element of the pair. - /// - /// # Arguments - /// - /// - `first`: The second element of the pair. - /// - /// # Returns - /// - /// - `true` if the entity owns the provided pair, `false` otherwise. - pub fn owns_second(self, first: impl Into) -> bool { + pub fn owns(self, entity_id: impl IntoId) -> bool { unsafe { sys::ecs_owns_id( self.world.world_ptr(), *self.id, - ecs_pair(*first.into(), Second::id(self.world)), + *entity_id.into_id(self.world), ) } } @@ -2356,47 +2004,8 @@ impl<'a> EntityView<'a> { /// /// # Returns /// - `true` if enabled, `false` if not. - pub fn is_enabled_id(self, id: impl IntoId) -> bool { - unsafe { sys::ecs_is_enabled_id(self.world.world_ptr(), *self.id, *id.into()) } - } - - /// Test if component is enabled. - /// - /// # Type Parameters - /// - `T`: The component to test. - /// - /// # Returns - /// - `true` if enabled, `false` if not. - pub fn is_enabled(self) -> bool { - unsafe { sys::ecs_is_enabled_id(self.world.world_ptr(), *self.id, T::get_id(self.world)) } - } - - /// Test if pair is enabled. - /// - /// # Type Parameters - /// - `T`: The first element of the pair. - /// - /// # Arguments - /// - `second`: The second element of the pair. - /// - /// # Returns - /// - `true` if enabled, `false` if not. - pub fn is_enabled_first(self, second: impl Into) -> bool { - self.is_enabled_id((First::id(self.world), second.into())) - } - - /// Test if pair is enabled. - /// - /// # Type Parameters - /// - `T`: The second element of the pair. - /// - /// # Arguments - /// - `first`: The second element of the pair. - /// - /// # Returns - /// - `true` if enabled, `false` if not. - pub fn is_enabled_second(self, first: impl Into) -> bool { - self.is_enabled_id((first.into(), Second::id(self.world))) + pub fn is_enabled(self, id: impl IntoId) -> bool { + unsafe { sys::ecs_is_enabled_id(self.world.world_ptr(), *self.id, *id.into_id(self.world)) } } /// Clones the current entity to a new or specified entity. diff --git a/flecs_ecs/src/core/entity_view/entity_view_impl.rs b/flecs_ecs/src/core/entity_view/entity_view_impl.rs index 6a063410..f5401696 100644 --- a/flecs_ecs/src/core/entity_view/entity_view_impl.rs +++ b/flecs_ecs/src/core/entity_view/entity_view_impl.rs @@ -22,7 +22,7 @@ impl<'a> IdOperations<'a> for EntityView<'a> { fn new_from_id(world: impl WorldProvider<'a>, id: impl IntoId) -> Self { Self { world: world.world(), - id: Entity::from(*id.into()), + id: Entity::from(*id.into_id(world)), } } diff --git a/flecs_ecs/src/core/entity_view/entity_view_mut.rs b/flecs_ecs/src/core/entity_view/entity_view_mut.rs index 68d13e47..f2406382 100644 --- a/flecs_ecs/src/core/entity_view/entity_view_mut.rs +++ b/flecs_ecs/src/core/entity_view/entity_view_mut.rs @@ -24,15 +24,37 @@ impl<'a> EntityView<'a> { /// # Usage /// /// For types that are not ZST and do not implement a constructor hook, use the `set_id` method to safely initialize the `id`. - /// - /// # See Also - /// - /// * C++ API equivalent: `entity_builder::add` - pub fn add_id(self, id: impl IntoId) -> Self { - let id = *id.into(); + #[allow(clippy::should_implement_trait)] + pub fn add(self, id: T) -> Self { + let id = *id.into_id(self.world); let world = self.world.world_ptr_mut(); - check_add_id_validity(world, id); + if !T::IS_PAIR { + if !T::IS_TYPED { + check_add_id_validity(world, id); + } else if !T::IF_ID_IS_DEFAULT && !::IS_TYPE_TAG { + panic!("Default hook not implemented for non ZST type"); + } + } else if T::IS_TYPED { + if !T::IF_ID_IS_DEFAULT { + if T::IS_TYPED_SECOND { + if !T::IF_ID_IS_DEFAULT_SECOND && !::IS_TYPE_TAG { + //for some reason const panic doesn't work here + panic!( + "none implement default, use `set_pair` instead to ensure valid data" + ) + } + } else { + check_add_id_validity(world, id); + } + } + } else if T::IS_TYPED_SECOND { + if !T::IF_ID_IS_DEFAULT_SECOND { + check_add_id_validity(world, id); + } + } else { + check_add_id_validity(world, id); + } unsafe { sys::ecs_add_id(world, *self.id, id) } self @@ -51,25 +73,15 @@ impl<'a> EntityView<'a> { /// /// # See Also /// - /// * [`add_id`](Self::add_id) /// * [`set_id`](Self::set_id) pub unsafe fn add_id_unchecked(self, id: impl IntoId) -> Self { - let id = *id.into(); + let id = *id.into_id(self.world); let world = self.world.world_ptr_mut(); unsafe { sys::ecs_add_id(world, *self.id, id) } self } - /// Add a Tag or Tags relationship to an entity. - pub fn add(self) -> Self - where - T: ComponentOrPairId, - { - let world = self.world; - self.add_id(T::get_id(world)) - } - /// Adds a flecs trait. pub fn add_trait(self) -> Self where @@ -99,82 +111,6 @@ impl<'a> EntityView<'a> { unsafe { self.add_id_unchecked(id) } } - /// Adds a pair to the entity - /// - /// # Panics - /// - /// Caller must ensure the id is a non ZST types. Otherwise it could cause you to read uninitialized payload data. - /// use `set_first` for ZST types. - pub fn add_first(self, second: impl Into) -> Self { - const { - if !First::IS_TAG && !First::IMPLS_DEFAULT { - panic!( - "Adding an element that is not a Tag / Zero sized type requires to implement Default" - ); - } - } - - let world = self.world; - let world_ptr = world.world_ptr(); - - let second = *second.into(); - - let is_valid_id = unsafe { sys::ecs_id_is_valid(world_ptr, second) }; - - if !is_valid_id { - panic!("Id is not a valid component or entity."); - } - - if First::IS_TAG { - let is_second_not_tag = unsafe { sys::ecs_get_typeid(world_ptr, second) != 0 }; - - if is_second_not_tag { - assert!( - has_default_hook(world_ptr, second), - "second id is not a zero-sized type (ZST) such as a Tag or Entity or does not implement the Default hook for a non ZST type. Default hooks are automatically implemented if the type has a Default trait." - ); - } - } - - // SAFETY: we know that the id is a valid because first is a Type and second has been checked - unsafe { self.add_id_unchecked((First::id(world), second)) } - } - - /// Adds a pair to the entity - /// - /// # Safety - /// - /// Caller must ensure the id is a non ZST types. Otherwise it could cause you to read uninitialized payload data. - /// use `set_second` for ZST types. - pub fn add_second(self, first: impl Into) -> Self { - let world = self.world; - let world_ptr = world.world_ptr(); - - let first = *first.into(); - - let is_valid = unsafe { sys::ecs_id_is_valid(world_ptr, first) }; - - if !is_valid { - panic!("Id is not a valid component or entity."); - } - - let is_first_tag = unsafe { sys::ecs_get_typeid(world_ptr, first) == 0 }; - - if is_first_tag { - if !Second::IS_TAG && !Second::IMPLS_DEFAULT { - panic!( - "first id is a tag type such as a Tag or Entity, but second id is not a zero-sized type (ZST) such as a Tag or Entity or does not implement the Default hook for a non ZST type. Default hooks are automatically implemented if the type has a Default trait." - ); - } - } else { - assert!(has_default_hook(world_ptr,first),"first id is not a zero-sized type (ZST) such as a Tag or Entity and does not implement the Default hook. Default hooks are automatically implemented if the type has a Default trait. - Use `set_id` or `set_pair`."); - } - - // SAFETY: we know that the id is a valid because first is a Type and second has been checked - self.add_id((first, Second::id(world))) - } - /// Adds a pair to the entity composed of a tag and an (C) flecs enum constant. pub fn add_pair_enum(self, enum_value: Second) -> Self where @@ -228,109 +164,31 @@ impl<'a> EntityView<'a> { /// /// * `condition`: The condition to evaluate. /// * `component`: The component to add. - pub fn add_id_if(self, id: T, condition: bool) -> Self - where - T: IntoId, - { - if condition { - self.add_id(id) - } else { - // the compiler will optimize this branch away since it's known at compile time - if T::IS_PAIR { - // If second is 0 or if relationship is exclusive, use wildcard for - // second which will remove all instances of the relationship. - // Replacing 0 with Wildcard will make it possible to use the second - // as the condition. - let first = id.get_id_first(); - let mut second = id.get_id_second(); - if second == 0 - || unsafe { sys::ecs_has_id(self.world.world_ptr(), *first, ECS_EXCLUSIVE) } - { - second = ECS_WILDCARD.into(); - } - self.remove_id((first, second)) - } else { - self.remove_id(id) - } - } - } - - /// Conditional add. - /// This operation adds if condition is true, removes if condition is false. - /// - /// # Type Parameters - /// - /// * `T`: The component to add. - /// - /// # Arguments - /// - /// * `condition`: The condition to evaluate. - pub fn add_if(self, condition: bool) -> Self { - let world = self.world; + pub fn add_if(self, id: T, condition: bool) -> Self { if condition { - self.add::() + self.add(id) } else { - let id = T::get_id(world); // the compiler will optimize this branch away since it's known at compile time if T::IS_PAIR { // If second is 0 or if relationship is exclusive, use wildcard for // second which will remove all instances of the relationship. // Replacing 0 with Wildcard will make it possible to use the second // as the condition. - let first = ecs_first(id); - let mut second = ecs_second(id); + let id = id.into_id(self.world); + let first = id.get_id_first(self.world); + let mut second = id.get_id_second(self.world); if second == 0 || unsafe { sys::ecs_has_id(self.world.world_ptr(), *first, ECS_EXCLUSIVE) } { second = ECS_WILDCARD.into(); } - self.remove_id((first, second)) + self.remove((first, second)) } else { - self.remove_id(id) + self.remove(id) } } } - /// Conditional add. - /// This operation adds if condition is true, removes if condition is false. - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair - /// - /// # Arguments - /// - /// * `condition`: The condition to evaluate. - /// * `second`: The second element of the pair. - pub fn add_first_if( - self, - second: impl Into, - condition: bool, - ) -> Self { - let world = self.world; - self.add_id_if((First::id(world), second.into()), condition) - } - - /// Conditional add. - /// This operation adds if condition is true, removes if condition is false. - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair - /// - /// # Arguments - /// - /// * `condition`: The condition to evaluate. - /// * `first`: The first element of the pair. - pub fn add_second_if( - self, - first: impl Into, - condition: bool, - ) -> Self { - let world = self.world; - self.add_id_if((first.into(), Second::id(world)), condition) - } - /// Conditional add. /// This operation adds if condition is true, removes if condition is false. /// @@ -348,7 +206,7 @@ impl<'a> EntityView<'a> { { let world = self.world; // SAFETY: we know that the enum_value is a valid because of the T::id call - self.add_id_if( + self.add_if( (T::id(world), unsafe { enum_value.id_variant_unchecked(world) }), @@ -361,25 +219,17 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// * `component_id`: The entity to remove. - pub fn remove_id(self, id: impl IntoId) -> Self { - unsafe { sys::ecs_remove_id(self.world.world_ptr_mut(), *self.id, *id.into()) } - self - } + pub fn remove(self, id: T) -> Self { + let id = *id.into_id(self.world); + let id = if ::IS_ENUM { + ecs_pair(id, ECS_WILDCARD) + } else { + id + }; - /// Remove a component from an entity. - /// - /// # Type Parameters - /// - /// * `T`: the type of the component to remove. - pub fn remove(self) -> Self { - let world = self.world; + unsafe { sys::ecs_remove_id(self.world.world_ptr_mut(), *self.id, id) } - //this branch will be compiled away in release mode - if T::IS_ENUM { - self.remove_id((T::get_id(world), ECS_WILDCARD)) - } else { - self.remove_id(T::get_id(world)) - } + self } /// Remove a pair. @@ -399,37 +249,7 @@ impl<'a> EntityView<'a> { Second: ComponentId + ComponentType + EnumComponentInfo, { let world = self.world; - self.remove_id((First::id(world), enum_value.id_variant(world))) - } - - /// Removes a pair. - /// This operation removes a pair from the entity. - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second element of the pair. - pub fn remove_first(self, second: impl Into) -> Self { - let world = self.world; - self.remove_id((First::id(world), second.into())) - } - - /// Removes a pair. - /// This operation removes a pair from the entity. - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first element of the pair. - pub fn remove_second(self, first: impl Into) -> Self { - let world = self.world; - self.remove_id((first.into(), Second::id(world))) + self.remove((First::id(world), enum_value.id_variant(world))) } /// Shortcut for `add((flecs::IsA, id))`. @@ -437,37 +257,17 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// * `second`: The second element of the pair. - pub fn is_a_id(self, second: impl Into) -> Self { - unsafe { self.add_id_unchecked((ECS_IS_A, second.into())) } - } - - /// Shortcut for `add_id((flecs::IsA::ID, entity))`. - /// - /// # Type Parameters - /// - /// * `T`: the type associated with the entity. - pub fn is_a(self) -> Self { - let world = self.world; - self.is_a_id(T::id(world)) + pub fn is_a(self, second: impl IntoEntity) -> Self { + unsafe { self.add_id_unchecked((ECS_IS_A, second.into_entity(self.world))) } } /// Shortcut for `add_id((flecs::ChildOf::ID, entity))`. /// /// # Arguments /// - /// * `second`: The second element of the pair. - pub fn child_of_id(self, parent: impl Into) -> Self { - unsafe { self.add_id_unchecked((ECS_CHILD_OF, parent.into())) } - } - - /// Shortcut for `add_id((flecs::ChildOf::ID, entity))`. - /// - /// # Type Parameters - /// - /// * `T`: the type associated with the entity. - pub fn child_of(self) -> Self { - let world = self.world; - self.child_of_id(T::id(world)) + /// * `parent`: The parent entity to establish the relationship with. + pub fn child_of(self, parent: impl IntoEntity) -> Self { + unsafe { self.add_id_unchecked((ECS_CHILD_OF, parent.into_entity(self.world))) } } /// Shortcut for `add_id((flecs::DependsOn::ID, entity))`. @@ -475,18 +275,8 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// * `second`: The second element of the pair. - pub fn depends_on_id(self, second: impl Into) -> Self { - unsafe { self.add_id_unchecked((ECS_DEPENDS_ON, second.into())) } - } - - /// Shortcut for `add_id((flecs::ependsOn::ID, entity))`. - /// - /// # Type Parameters - /// - /// * `T`: the type associated with the entity. - pub fn depends_on>(self) -> Self { - let world = self.world; - self.depends_on_id(T::id(world)) + pub fn depends_on(self, second: impl IntoEntity) -> Self { + unsafe { self.add_id_unchecked((ECS_DEPENDS_ON, second.into_entity(self.world))) } } /// Shortcut for `add_id((flecs::Dependency::ID, entity))`for Enums. @@ -503,7 +293,7 @@ impl<'a> EntityView<'a> { enum_value: T, ) -> Self { let world = self.world; - self.depends_on_id(enum_value.id_variant(world)) + self.depends_on(enum_value.id_variant(world)) } /// Shortcut for `add_id((flecs::SlotOf::ID, entity))`. @@ -511,29 +301,19 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// * `second`: The second element of the pair. - pub fn slot_of_id(self, second: impl Into) -> Self { - unsafe { self.add_id_unchecked((ECS_SLOT_OF, second.into())) } - } - - /// Shortcut for `add_id((flecs::SlotOf::ID, entity))`. - /// - /// # Type Parameters - /// - /// * `T`: the type associated with the entity. - pub fn slot_of(self) -> Self { - let world = self.world; - self.slot_of_id(T::id(world)) + pub fn slot_of(self, second: impl IntoEntity) -> Self { + unsafe { self.add_id_unchecked((ECS_SLOT_OF, second.into_entity(self.world))) } } /// Shortcut for `add_id((flecs::SlotOf::ID, target(ChildOf)))`. pub fn slot(self) -> Self { ecs_assert!( - self.target::(0).is_some(), + self.target(flecs::ChildOf::ID, 0).is_some(), FlecsErrorCode::InvalidParameter, "add ChildOf pair before using slot()" ); - let id = self.target_id(ECS_CHILD_OF, 0); - self.slot_of_id(id.expect("ChildOf pair not found")) + let id = self.target(ECS_CHILD_OF, 0); + self.slot_of(id.expect("ChildOf pair not found")) } /// Mark id for auto-overriding. @@ -545,70 +325,8 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// * `id`: The id to mark for overriding. - pub fn auto_override_id(self, id: impl IntoId) -> Self { - unsafe { self.add_id_unchecked(ECS_AUTO_OVERRIDE | id.into()) } - } - - /// Mark component for auto-overriding. - /// - /// # Type Parameters - /// - /// * `T`: The component to mark for overriding. - pub fn auto_override(self) -> Self { - let world = self.world; - self.auto_override_id(T::get_id(world)) - } - - /// Mark pair for auto-overriding with a given second ID. - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second element of the pair. - pub fn auto_override_first( - self, - second: impl Into, - ) -> Self { - let world = self.world; - let pair_id = ecs_pair(First::id(world), *second.into()); - self.auto_override_id(pair_id) - } - - /// Mark pair for auto-overriding with a given first ID. - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first element of the pair. - pub fn auto_override_second( - self, - first: impl Into, - ) -> Self { - let world = self.world; - let pair_id = ecs_pair(*first.into(), Second::id(world)); - self.auto_override_id(pair_id) - } - - /// Sets a component for an entity and marks it as overridden. - /// - /// This function sets a component for an entity and marks the component - /// as overridden, meaning that it will not be updated by systems that - /// typically update this component. - pub fn set_auto_override_id(self, id: impl IntoId) -> Self { - unsafe { - sys::ecs_add_id( - self.world.world_ptr_mut(), - *self.id, - ECS_AUTO_OVERRIDE | *id.into(), - ); - } - self + pub fn auto_override(self, id: impl IntoId) -> Self { + unsafe { self.add_id_unchecked(ECS_AUTO_OVERRIDE | id.into_id(self.world)) } } /// Sets a component mark override for the entity and sets the component data. @@ -616,7 +334,7 @@ impl<'a> EntityView<'a> { self, component: T, ) -> Self { - self.auto_override::().set(component) + self.auto_override(id::()).set(component) } /// Sets a pair, mark component for auto-overriding. @@ -631,7 +349,7 @@ impl<'a> EntityView<'a> { <(First, Second) as ComponentOrPairId>::CastType: DataComponent, { let id_pair = <(First, Second) as ComponentOrPairId>::get_id(self.world); - self.auto_override_id(id_pair).set_id(data, id_pair) + self.auto_override(id_pair).set_id(data, id_pair) } /// Sets a pair, mark component for auto-overriding. @@ -650,7 +368,7 @@ impl<'a> EntityView<'a> { let second_id = *second.into(); let first_id = First::id(self.world); let pair_id = ecs_pair(first_id, second_id); - self.auto_override_id(pair_id).set_id(first, pair_id) + self.auto_override(pair_id).set_id(first, pair_id) } /// Sets a pair, mark component for auto-overriding. @@ -669,7 +387,7 @@ impl<'a> EntityView<'a> { let first_id = first.into(); let second_id = Second::id(self.world); let pair_id = ecs_pair(*first_id, second_id); - self.auto_override_id(pair_id).set_id(second, pair_id) + self.auto_override(pair_id).set_id(second, pair_id) } /// Sets a component of type `T` on the entity. @@ -725,7 +443,6 @@ impl<'a> EntityView<'a> { /// # See also /// /// * [`EntityView::add`] - /// * [`EntityView::add_id`] /// * [`EntityView::set`] /// * [`EntityView::set_pair`] pub fn set_id(self, data: T, id: impl IntoId) -> Self @@ -733,7 +450,7 @@ impl<'a> EntityView<'a> { T: ComponentId + DataComponent, { let world = self.world.world_ptr_mut(); - let id = *id.into(); + let id = *id.into_id(self.world); let data_id = T::id(self.world); let id_data_id = unsafe { sys::ecs_get_typeid(world, id) }; @@ -775,8 +492,6 @@ impl<'a> EntityView<'a> { /// // ... /// }); /// ``` - /// # See also - /// pub fn set_pair( self, data: <(First, Second) as ComponentOrPairId>::CastType, @@ -992,49 +707,18 @@ impl<'a> EntityView<'a> { /// /// - `component_id`: The ID to enable. /// - `toggle`: True to enable, false to disable (default = true). - pub fn enable_id(self, id: impl IntoId) -> Self { - unsafe { sys::ecs_enable_id(self.world.world_ptr_mut(), *self.id, *id.into(), true) } + pub fn enable(self, id: impl IntoId) -> Self { + unsafe { + sys::ecs_enable_id( + self.world.world_ptr_mut(), + *self.id, + *id.into_id(self.world), + true, + ); + } self } - /// Enables a component or pair. - /// - /// # Type Parameters - /// - /// - `T`: The component to enable. - pub fn enable(self) -> Self { - let world = self.world; - self.enable_id(T::get_id(world)) - } - - /// Enables a pair with a specific ID for the second element. - /// - /// # Type Parameters - /// - /// - `First`: The first element of the pair. - /// - /// # Arguments - /// - /// - `second`: The ID of the second element of the pair. - pub fn enable_first(self, second: impl Into) -> Self { - let world = self.world; - self.enable_id((First::id(world), second.into())) - } - - /// Enables a pair with a specific ID for the first element. - /// - /// # Type Parameters - /// - /// - `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// - `first`: The ID of the first element of the pair. - pub fn enable_second(self, first: impl Into) -> Self { - let world = self.world; - self.enable_id((first.into(), Second::id(world))) - } - /// Disables self (entity). /// /// Disabled entities are not matched with systems and cannot be searched with queries, @@ -1052,34 +736,18 @@ impl<'a> EntityView<'a> { /// # Arguments /// /// - `component_id`: The ID to disable. - pub fn disable_id(self, id: impl IntoId) -> Self { - unsafe { sys::ecs_enable_id(self.world.world_ptr_mut(), *self.id, *id.into(), false) } + pub fn disable(self, id: impl IntoId) -> Self { + unsafe { + sys::ecs_enable_id( + self.world.world_ptr_mut(), + *self.id, + *id.into_id(self.world), + false, + ); + } self } - /// Disables a component or pair. - /// - /// # Type Parameters - /// - /// - `T`: The component to disable. - pub fn disable(self) -> Self { - let world = self.world; - self.disable_id(T::get_id(world)) - } - - /// Disables a pair with a specific ID for the second element. - /// - /// # Type Parameters - /// - /// - `First`: The first element of the pair. - /// - /// # Arguments - /// - /// - `second`: The ID of the second element of the pair. - pub fn disable_first(self, second: impl Into) -> Self { - let world = self.world; - self.disable_id((First::id(world), second.into())) - } /// Entities created in the function will have the current entity. /// This operation is thread safe. /// @@ -1102,13 +770,11 @@ impl<'a> EntityView<'a> { /// /// - `first`: The first element of the pair. /// - `func`: The function to call./// - /// # See also - /// - pub fn with_first_id(self, first: impl Into, func: impl FnOnce()) -> Self { + pub fn with_first(self, first: impl IntoEntity, func: impl FnOnce()) -> Self { unsafe { let prev = sys::ecs_set_with( self.world.world_ptr_mut(), - ecs_pair(*first.into(), *self.id), + ecs_pair(*first.into_entity(self.world), *self.id), ); func(); sys::ecs_set_with(self.world.world_ptr_mut(), prev); @@ -1123,11 +789,11 @@ impl<'a> EntityView<'a> { /// /// - `second`: The second element of the pair. /// - `func`: The function to call. - pub fn with_second_id(self, second: impl Into, func: impl FnOnce()) -> Self { + pub fn with_second(self, second: impl IntoEntity, func: impl FnOnce()) -> Self { unsafe { let prev = sys::ecs_set_with( self.world.world_ptr_mut(), - ecs_pair(*self.id, *second.into()), + ecs_pair(*self.id, *second.into_entity(self.world)), ); func(); sys::ecs_set_with(self.world.world_ptr_mut(), prev); @@ -1135,36 +801,6 @@ impl<'a> EntityView<'a> { self } - /// Entities created in the function will have (First, self). - /// This operation is thread safe. - /// - /// # Type Parameters - /// - /// - `First`: The first element of the pair. - /// - /// # Arguments - /// - /// - `func`: The function to call. - pub fn with_first(self, func: impl FnOnce()) -> Self { - let world = self.world; - self.with_first_id(First::id(world), func) - } - - /// Entities created in the function will have (self, Second) - /// This operation is thread safe. - /// - /// # Type Parameters - /// - /// - `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// - `func`: The function to call. - pub fn with_second(self, func: impl FnOnce()) -> Self { - let world = self.world; - self.with_second_id(Second::id(world), func) - } - /// The function will be ran with the scope set to the current entity. /// /// # Arguments @@ -1182,7 +818,7 @@ impl<'a> EntityView<'a> { /// Calls the provided function with a world scoped to entity pub fn scope(self, f: impl FnMut(&World)) -> Self { let world = &*self.world; - world.scope_id(self.id, f); + world.scope(self.id, f); self } @@ -1195,58 +831,21 @@ impl<'a> EntityView<'a> { /// # See also /// /// * [`EntityView::modified()`] - /// * [`EntityView::modified_first()`] /// * [`World::modified()`] - pub fn modified_id(self, id: impl IntoId) { - unsafe { sys::ecs_modified_id(self.world.world_ptr_mut(), *self.id, *id.into()) } - } - - /// Signal that component was modified. - /// - /// # Type Parameters - /// - /// * `T` - The type of the component that was modified. - /// - /// # See also - /// - /// * [`EntityView::modified_first()`] - /// * [`EntityView::modified_id()`] - /// * [`World::modified()`] - pub fn modified(&self) { + pub fn modified(self, id: T) { const { - assert!( - core::mem::size_of::() != 0, - "cannot modify zero-sized-type / tag components" - ); - }; - - self.modified_id(T::get_id(self.world)); - } - - /// Signal that the first part of a pair was modified. - /// - /// # Type Parameters - /// - /// * `First` - The first part of the pair. - /// - /// # Arguments - /// - /// * `second` - The second element of the pair. - /// - /// # See also - /// - /// * [`EntityView::modified()`] - /// * [`EntityView::modified_id()`] - /// * [`World::modified()`] - pub fn modified_first(self, second: impl Into) { - ecs_assert!( - core::mem::size_of::() != 0, - FlecsErrorCode::InvalidParameter, - "invalid type: {}", - core::any::type_name::() - ); + if ::IS_TYPE_TAG { + panic!("Cannot modify tag component"); + } + } - self.modified_id((First::id(self.world), second.into())); + unsafe { + sys::ecs_modified_id( + self.world.world_ptr_mut(), + *self.id, + *id.into_id(self.world), + ); + } } /// Get reference to component specified by id. @@ -1277,7 +876,7 @@ impl<'a> EntityView<'a> { /// let world = World::new(); /// /// let base = world.component::(); - /// let derived = world.component::().is_a_id(base); + /// let derived = world.component::().is_a(base); /// /// let entity = world.entity().set(Derived { x: 10 }); /// @@ -1301,12 +900,13 @@ impl<'a> EntityView<'a> { /// * [`EntityView::get_ref()`] /// * [`EntityView::get_ref_first()`] /// * [`EntityView::get_ref_second()`] + //TODO: can this be shrunk to just one function like with add,add_id pub fn get_ref_w_id(&self, component: impl IntoId) -> CachedRef<'a, T::CastType> where T: ComponentOrPairId, T::CastType: DataComponent, { - CachedRef::::new(self.world, *self.id, *component.into()) + CachedRef::::new(self.world, *self.id, *component.into_id(self.world)) } /// Get a reference to a component or pair. diff --git a/flecs_ecs/src/core/event.rs b/flecs_ecs/src/core/event.rs index bd75dbba..754378e6 100644 --- a/flecs_ecs/src/core/event.rs +++ b/flecs_ecs/src/core/event.rs @@ -87,8 +87,8 @@ impl<'a, T: ComponentId> EventBuilder<'a, T> { /// # Arguments /// /// * `id` - The id of the component to add to the event - pub fn add_id(&mut self, id: impl IntoId) -> &mut Self { - let id = *id.into(); + pub fn add(&mut self, id: impl IntoId) -> &mut Self { + let id = *id.into_id(self.world); let ids = &mut self.ids; let ids_array = &mut self.ids_array; ids.array = ids_array.as_mut_ptr(); @@ -99,19 +99,6 @@ impl<'a, T: ComponentId> EventBuilder<'a, T> { self } - /// Add component to emit for the event. - /// - /// # Type parameters - /// - /// * `C` - The component to add to the event - pub fn add(&mut self) -> &mut Self - where - C: ComponentOrPairId, - { - let world = self.world; - self.add_id(C::get_id(world)) - } - pub fn add_enum + EnumComponentInfo>( &mut self, enum_value: C, @@ -125,32 +112,7 @@ impl<'a, T: ComponentId> EventBuilder<'a, T> { FlecsErrorCode::InvalidParameter, "Component was not found in reflection data." ); - self.add_id((rel, target)) - } - - /// Add a pair of components to emit for the event. - /// - /// # Type parameters - /// - /// * `First` - The first component to add to the event - /// - /// # Arguments - /// - /// * `second` - The id of the second component to add to the event - fn add_first(&mut self, second: impl Into) -> &mut Self - where - First: ComponentId, - { - let world = self.world; - self.add_id(ecs_pair(First::id(world), *second.into())) - } - - fn add_second(&mut self, first: impl Into) -> &mut Self - where - Second: ComponentId, - { - let world = self.world; - self.add_id(ecs_pair(*first.into(), Second::id(world))) + self.add((rel, target)) } /// Set the target entity to emit for the event. diff --git a/flecs_ecs/src/core/fields_tuple.rs b/flecs_ecs/src/core/fields_tuple.rs new file mode 100644 index 00000000..5ea63c49 --- /dev/null +++ b/flecs_ecs/src/core/fields_tuple.rs @@ -0,0 +1,614 @@ +use core::marker::PhantomData; + +use crate::core::*; +use crate::sys; +use flecs_ecs_derive::tuples; + +#[doc(hidden)] +pub struct IsAnyArray { + pub a_ref: bool, //e.g. singleton + pub a_row: bool, //e.g. sparse +} + +pub struct ComponentsFieldData { + pub array_components: [*mut u8; LEN], + pub is_ref_array_components: [bool; LEN], + pub is_row_array_components: [bool; LEN], + pub index_array_components: [i8; LEN], + pub is_any_array: IsAnyArray, + _marker: PhantomData, +} + +pub trait ComponentFieldPointers { + fn new(iter: &sys::ecs_iter_t) -> Self; + + fn get_tuple(&mut self, iter: &sys::ecs_iter_t, index: usize) -> T::TupleType<'_>; +} + +impl ComponentFieldPointers for ComponentsFieldData { + fn new(iter: &sys::ecs_iter_t) -> Self { + let mut array_components = [core::ptr::null::() as *mut u8; LEN]; + let mut is_ref_array_components = [false; LEN]; + let mut is_row_array_components = [false; LEN]; + let mut index_array_components = [0; LEN]; + + let is_any_array = if (iter.ref_fields | iter.up_fields) != 0 { + T::populate_array_ptrs( + iter, + &mut array_components[..], + &mut is_ref_array_components[..], + &mut is_row_array_components[..], + &mut index_array_components[..], + ) + } else { + // TODO since we know there is no is_ref and this always return false, we could mitigate a branch if we + // split up the functions + T::populate_self_array_ptrs(iter, &mut array_components[..]); + IsAnyArray { + a_ref: false, + a_row: false, + } + }; + + Self { + array_components, + is_ref_array_components, + is_row_array_components, + index_array_components, + is_any_array, + _marker: PhantomData::, + } + } + + fn get_tuple(&mut self, iter: &sys::ecs_iter_t, index: usize) -> T::TupleType<'_> { + if self.is_any_array.a_row { + T::create_tuple_with_row( + iter, + &mut self.array_components[..], + &self.is_ref_array_components[..], + &self.is_row_array_components[..], + &self.index_array_components[..], + index, + ) + } else if self.is_any_array.a_ref { + T::create_tuple_with_ref( + &self.array_components[..], + &self.is_ref_array_components[..], + index, + ) + } else { + T::create_tuple(&self.array_components[..], index) + } + } +} + +pub trait IterableTypeFieldOperation { + type CastType; + type ActualType<'w>; + type SliceType<'w>; + type OnlyType: ComponentOrPairId; + type OnlyPairType: ComponentId; + const IS_IMMUTABLE: bool; + + fn create_tuple_data<'a>(array_components_data: *mut u8, index: usize) -> Self::ActualType<'a>; + + fn create_tuple_with_ref_data<'a>( + array_components_data: *mut u8, + is_ref: bool, + index: usize, + ) -> Self::ActualType<'a>; +} + +impl IterableTypeFieldOperation for &T +where + T: ComponentOrPairId, +{ + type CastType = *const ::CastType; + type ActualType<'w> = &'w ::CastType; + type SliceType<'w> = &'w [::CastType]; + type OnlyType = T; + type OnlyPairType = ::CastType; + const IS_IMMUTABLE: bool = true; + + fn create_tuple_data<'a>(array_components_data: *mut u8, index: usize) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + unsafe { &*data_ptr.add(index) } + } + + fn create_tuple_with_ref_data<'a>( + array_components_data: *mut u8, + is_ref: bool, + index: usize, + ) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + unsafe { + if is_ref { + &*data_ptr.add(0) + } else { + &*data_ptr.add(index) + } + } + } +} + +impl IterableTypeFieldOperation for &mut T +where + T: ComponentOrPairId, +{ + type CastType = *mut ::CastType; + type ActualType<'w> = &'w mut ::CastType; + type SliceType<'w> = &'w mut [::CastType]; + type OnlyType = T; + type OnlyPairType = ::CastType; + const IS_IMMUTABLE: bool = false; + + fn create_tuple_data<'a>(array_components_data: *mut u8, index: usize) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + unsafe { &mut *data_ptr.add(index) } + } + + fn create_tuple_with_ref_data<'a>( + array_components_data: *mut u8, + is_ref: bool, + index: usize, + ) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + unsafe { + if is_ref { + &mut *data_ptr.add(0) + } else { + &mut *data_ptr.add(index) + } + } + } +} + +impl IterableTypeFieldOperation for Option<&T> +where + T: ComponentOrPairId, +{ + type CastType = *const ::CastType; + type ActualType<'w> = Option<&'w ::CastType>; + type SliceType<'w> = Option<&'w [::CastType]>; + type OnlyType = T; + type OnlyPairType = ::CastType; + const IS_IMMUTABLE: bool = true; + + fn create_tuple_data<'a>(array_components_data: *mut u8, index: usize) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + if data_ptr.is_null() { + None + } else { + Some(unsafe { &*data_ptr.add(index) }) + } + } + + fn create_tuple_with_ref_data<'a>( + array_components_data: *mut u8, + is_ref: bool, + index: usize, + ) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + if data_ptr.is_null() { + None + } else if is_ref { + Some(unsafe { &*data_ptr.add(0) }) + } else { + Some(unsafe { &*data_ptr.add(index) }) + } + } +} + +impl IterableTypeFieldOperation for Option<&mut T> +where + T: ComponentOrPairId, +{ + type CastType = *mut ::CastType; + type ActualType<'w> = Option<&'w mut ::CastType>; + type SliceType<'w> = Option<&'w mut [::CastType]>; + type OnlyType = T; + type OnlyPairType = ::CastType; + const IS_IMMUTABLE: bool = false; + + fn create_tuple_data<'a>(array_components_data: *mut u8, index: usize) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + if data_ptr.is_null() { + None + } else { + Some(unsafe { &mut *data_ptr.add(index) }) + } + } + + fn create_tuple_with_ref_data<'a>( + array_components_data: *mut u8, + is_ref: bool, + index: usize, + ) -> Self::ActualType<'a> { + let data_ptr = array_components_data as Self::CastType; + if data_ptr.is_null() { + None + } else if is_ref { + Some(unsafe { &mut *data_ptr.add(0) }) + } else { + Some(unsafe { &mut *data_ptr.add(index) }) + } + } +} + +pub trait FieldsTuple: Sized { + type Pointers: ComponentFieldPointers; + type TupleType<'a>; + const CONTAINS_ANY_TAG_TERM: bool; + const COUNT: i32; + + fn create_ptrs(iter: &sys::ecs_iter_t) -> Self::Pointers { + Self::Pointers::new(iter) + } + + fn populate<'a>(query: &mut impl QueryBuilderImpl<'a>); + + fn populate_array_ptrs( + it: &sys::ecs_iter_t, + components: &mut [*mut u8], + is_ref: &mut [bool], + is_row: &mut [bool], + indexes: &mut [i8], + ) -> IsAnyArray; + + fn populate_self_array_ptrs(it: &sys::ecs_iter_t, components: &mut [*mut u8]); + + fn create_tuple(array_components: &[*mut u8], index: usize) -> Self::TupleType<'_>; + + fn create_tuple_with_ref<'a>( + array_components: &'a [*mut u8], + is_ref_array_components: &[bool], + index: usize, + ) -> Self::TupleType<'a>; + + fn create_tuple_with_row<'a>( + iter: *const sys::ecs_iter_t, + array_components: &'a mut [*mut u8], + is_ref_array_components: &[bool], + is_row_array_components: &[bool], + indexes_array_components: &[i8], + index_row_entity: usize, + ) -> Self::TupleType<'a>; +} + +///////////////////// +// The higher sized tuples are done by a macro towards the bottom of this file. +///////////////////// + +#[rustfmt::skip] +impl FieldsTuple for A +where + A: IterableTypeFieldOperation, +{ + type Pointers = ComponentsFieldData; + type TupleType<'w> = A::ActualType<'w>; + const CONTAINS_ANY_TAG_TERM: bool = <::UnderlyingType as ComponentInfo>::IS_TAG; + const COUNT : i32 = 1; + + fn populate<'a>(query: &mut impl QueryBuilderImpl<'a>) { + let _world_ptr = query.world_ptr(); + + let id = ::get_id(query.world()); + + if ::IS_PAIR { + ecs_assert!( + unsafe { sys::ecs_get_typeid(_world_ptr, id) } != 0, + FlecsErrorCode::InvalidOperation, + "Pair is not a (data) component. Possible cause: PairIsTag trait" + ); + } + + ecs_assert!( + { + if (id & (sys::ECS_ID_FLAGS_MASK as u64)) == 0 { + let ti = unsafe { sys::ecs_get_type_info(_world_ptr, id) }; + if !ti.is_null() { + // Union relationships always return a value of type + // flecs::entity_t which holds the target id of the + // union relationship. + // If a union component with a non-zero size (like an + // enum) is added to the query signature, the each/iter + // functions would accept a parameter of the component + // type instead of flecs::entity_t, which would cause + // an assert. + (unsafe { (*ti).size == 0 } || !unsafe { sys::ecs_has_id(_world_ptr, id, *flecs::Union)}) + } else { true } + } else { true } + }, FlecsErrorCode::InvalidParameter, "use `with` method to add union relationship"); + + query.with_id(id); + let term = query.current_term_mut(); + + } + + fn populate_array_ptrs( + it: &sys::ecs_iter_t, + components: &mut [*mut u8], + is_ref: &mut [bool], + is_row: &mut [bool], + indexes: &mut [i8], + ) -> IsAnyArray { + if it.row_fields & (1u32 << 0) != 0 { + // Need to fetch the value with ecs_field_at() + is_ref[0] = true; + is_row[0] = true; + indexes[0] = 0; + } else { + components[0] = unsafe { ecs_field::(it, 0) as *mut u8 }; + is_ref[0] = unsafe { *it.sources.add(0) != 0 }; + }; + + IsAnyArray { + a_ref: is_ref[0], + a_row: is_row[0], + } + } + + fn populate_self_array_ptrs( + it: &sys::ecs_iter_t, + components: &mut [*mut u8], + ) { + ecs_assert!(unsafe { *it.sources.add(0) == 0 }, FlecsErrorCode::InternalError, "unexpected source"); + + components[0] = unsafe { ecs_field::(it, 0) as *mut u8 }; + } + + fn create_tuple(array_components: &[*mut u8], index: usize) -> Self::TupleType<'_> { + A::create_tuple_data(array_components[0], index) + + } + + // TODO since it's only one component, we don't need to check if it's a ref array or not, we can just return the first element of the array + // I think this is the case for all tuples of size 1 + fn create_tuple_with_ref<'a>( + array_components: &'a [*mut u8], + is_ref_array_components: &[bool], + index: usize + ) -> Self::TupleType<'a> { + A::create_tuple_with_ref_data(array_components[0], is_ref_array_components[0], index) + } + + #[allow(clippy::not_unsafe_ptr_arg_deref)] + fn create_tuple_with_row<'a>( + iter: *const sys::ecs_iter_t, + array_components: &'a mut [*mut u8], + is_ref_array_components: &[bool], + is_row_array_components: &[bool], + indexes_array_components: &[i8], + index_row_entity: usize + ) -> Self::TupleType<'a> { + + if is_row_array_components[0] { + let ptr_to_first_index_array = &mut array_components[0]; + *ptr_to_first_index_array = unsafe { ecs_field_at::(iter, indexes_array_components[0], index_row_entity as i32) } as *mut u8; + } + + A::create_tuple_with_ref_data( + array_components[0], + is_ref_array_components[0], + index_row_entity, + ) + } +} + +pub struct Wrapper(T); + +pub trait TupleForm<'a, T, U> { + type Tuple; + type TupleSlice; + const IS_OPTION: bool; + + fn return_type_for_tuple(array: *mut U, index: usize) -> Self::Tuple; + fn return_type_for_tuple_with_ref(array: *mut U, is_ref: bool, index: usize) -> Self::Tuple; +} + +impl<'a, T: 'a> TupleForm<'a, T, T> for Wrapper { + type Tuple = &'a mut T; + type TupleSlice = &'a mut [T]; + const IS_OPTION: bool = false; + + #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[inline(always)] + fn return_type_for_tuple(array: *mut T, index: usize) -> Self::Tuple { + unsafe { &mut (*array.add(index)) } + } + + #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[inline(always)] + fn return_type_for_tuple_with_ref(array: *mut T, is_ref: bool, index: usize) -> Self::Tuple { + unsafe { + if is_ref { + &mut (*array.add(0)) + } else { + &mut (*array.add(index)) + } + } + } +} + +impl<'a, T: 'a> TupleForm<'a, Option, T> for Wrapper { + type Tuple = Option<&'a mut T>; + type TupleSlice = Option<&'a mut [T]>; + const IS_OPTION: bool = true; + + #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[inline(always)] + fn return_type_for_tuple(array: *mut T, index: usize) -> Self::Tuple { + unsafe { + if array.is_null() { + None + } else { + Some(&mut (*array.add(index))) + } + } + } + + #[allow(clippy::not_unsafe_ptr_arg_deref)] + #[inline(always)] + fn return_type_for_tuple_with_ref(array: *mut T, is_ref: bool, index: usize) -> Self::Tuple { + unsafe { + if array.is_null() { + None + } else if is_ref { + Some(&mut (*array.add(0))) + } else { + Some(&mut (*array.add(index))) + } + } + } +} + +macro_rules! tuple_count { + () => { 0 }; + ($head:ident) => { 1 }; + ($head:ident, $($tail:ident),*) => { 1 + tuple_count!($($tail),*) }; +} + +macro_rules! impl_iterable { + ($($t:ident),*) => { + impl<$($t: IterableTypeFieldOperation),*> FieldsTuple for ($($t,)*) { + type TupleType<'w> = ($( + $t::ActualType<'w>, + )*); + + const CONTAINS_ANY_TAG_TERM: bool = $(<<$t::OnlyPairType as ComponentId>::UnderlyingType as ComponentInfo>::IS_TAG ||)* false; + + type Pointers = ComponentsFieldData; + const COUNT : i32 = tuple_count!($($t),*); + + fn populate<'a>(query: &mut impl QueryBuilderImpl<'a>) { + let _world = query.world(); + let _world_ptr = query.world_ptr(); + + $( + let id = <$t::OnlyType as ComponentOrPairId>::get_id(_world); + + if <$t::OnlyType as ComponentOrPairId>::IS_PAIR { + ecs_assert!( + unsafe { sys::ecs_get_typeid(_world_ptr, id) } != 0, + FlecsErrorCode::InvalidOperation, + "Pair is not a (data) component. Possible cause: PairIsTag trait" + ); + } + + ecs_assert!( + { + if (id & (sys::ECS_ID_FLAGS_MASK as u64)) == 0 { + let ti = unsafe { sys::ecs_get_type_info(_world_ptr, id) }; + if !ti.is_null() { + // Union relationships always return a value of type + // flecs::entity_t which holds the target id of the + // union relationship. + // If a union component with a non-zero size (like an + // enum) is added to the query signature, the each/iter + // functions would accept a parameter of the component + // type instead of flecs::entity_t, which would cause + // an assert. + (unsafe { (*ti).size == 0 } || !unsafe { sys::ecs_has_id(_world_ptr, id, *flecs::Union)}) + } else { true } + } else { true } + }, FlecsErrorCode::InvalidParameter, "use `with` method to add union relationship"); + + query.with_id(id); + let term = query.current_term_mut(); + + )* + } + + #[allow(unused)] + fn populate_array_ptrs( + it: &sys::ecs_iter_t, + components: &mut [*mut u8], + is_ref: &mut [bool], + is_row: &mut [bool], + indexes: &mut [i8], + ) -> IsAnyArray { + let mut index = 0; + let mut any_ref = false; + let mut any_row = false; + $( + if it.row_fields & (1u32 << index) != 0 { + // Need to fetch the value with ecs_field_at() + is_ref[index as usize] = true; + is_row[index as usize] = true; + indexes[index as usize] = index as i8; + } else { + components[index as usize] = + unsafe { ecs_field::<$t::OnlyPairType>(it, index as i8) as *mut u8 }; + is_ref[index as usize] = unsafe { *it.sources.add(index as usize) != 0 }; + } + + any_ref |= is_ref[index as usize]; + any_row |= is_row[index as usize]; + index += 1; + )* + IsAnyArray { + a_ref: any_ref, + a_row: any_row, + } + } + + #[allow(unused)] + fn populate_self_array_ptrs( + it: &sys::ecs_iter_t, + components: &mut [*mut u8], + ) { + let mut index = 0; + $( + ecs_assert!(unsafe { *it.sources.add(index as usize) == 0 }, FlecsErrorCode::InternalError, "unexpected source"); + components[index as usize] = + unsafe { ecs_field::<$t::OnlyPairType>(it, index) as *mut u8 }; + + index += 1; + )* + + } + + #[allow(unused, clippy::unused_unit)] + fn create_tuple(array_components: &[*mut u8], index: usize) -> Self::TupleType<'_> { + let mut column: isize = -1; + ($({ + column += 1; + $t::create_tuple_data(array_components[column as usize], index) + },)*) + } + + #[allow(unused, clippy::unused_unit)] + fn create_tuple_with_ref<'a>(array_components: &'a [*mut u8], is_ref_array_components: &[bool], index: usize) -> Self::TupleType<'a> { + let mut column: isize = -1; + ($({ + column += 1; + $t::create_tuple_with_ref_data(array_components[column as usize], is_ref_array_components[column as usize], index) + },)*) + } + + #[allow(unused, clippy::unused_unit)] + #[allow(clippy::not_unsafe_ptr_arg_deref)] + fn create_tuple_with_row<'a>( + iter: *const sys::ecs_iter_t, + array_components: &'a mut [*mut u8], + is_ref_array_components: &[bool], + is_row_array_components: &[bool], + indexes_array_components: &[i8], + index_row_entity: usize + ) -> Self::TupleType<'a> { + let mut column: isize = -1; + ($({ + column += 1; + if is_row_array_components[column as usize] { + let ptr_to_first_index_array = &mut array_components[column as usize]; + *ptr_to_first_index_array = unsafe { ecs_field_at::<$t::OnlyPairType>(iter, indexes_array_components[column as usize], index_row_entity as i32) } as *mut $t::OnlyPairType as *mut u8; + } + + $t::create_tuple_with_ref_data(array_components[column as usize], is_ref_array_components[column as usize], index_row_entity) + },)*) + } + } + } +} + +tuples!(impl_iterable, 0, 32); diff --git a/flecs_ecs/src/core/flecs.rs b/flecs_ecs/src/core/flecs.rs index d065849b..bf546124 100644 --- a/flecs_ecs/src/core/flecs.rs +++ b/flecs_ecs/src/core/flecs.rs @@ -13,7 +13,7 @@ macro_rules! create_pre_registered_component { create_pre_registered_component!($struct_name, $const_name, ""); }; ($struct_name:ident, $const_name:ident, $doc:tt) => { - #[derive(Debug, Default)] + #[derive(Debug, Default, Clone)] #[allow(clippy::empty_docs)] #[doc = $doc] pub struct $struct_name; @@ -57,8 +57,8 @@ macro_rules! create_pre_registered_component { const IS_GENERIC: bool = false; const IS_ENUM: bool = false; const IS_TAG: bool = true; - const IMPLS_CLONE: bool = false; - const IMPLS_DEFAULT: bool = false; + const IMPLS_CLONE: bool = true; + const IMPLS_DEFAULT: bool = true; const IS_REF: bool = false; const IS_MUT: bool = false; type TagType = diff --git a/flecs_ecs/src/core/id_view.rs b/flecs_ecs/src/core/id_view.rs index 41f66ce4..97c06b93 100644 --- a/flecs_ecs/src/core/id_view.rs +++ b/flecs_ecs/src/core/id_view.rs @@ -170,7 +170,7 @@ impl<'a> IdView<'a> { return false; } - ecs_first(self.id) == first.into() + ecs_first(self.id, self.world) == first.into() } /// Get first element from a pair. @@ -181,7 +181,7 @@ impl<'a> IdView<'a> { pub fn first_id(&self) -> EntityView { ecs_assert!(self.is_pair(), FlecsErrorCode::InvalidOperation); - let entity = ecs_first(self.id); + let entity = ecs_first(self.id, self.world); self.world.get_alive(entity) } @@ -194,7 +194,7 @@ impl<'a> IdView<'a> { if !self.is_pair() { None } else { - let entity = ecs_first(self.id); + let entity = ecs_first(self.id, self.world); self.world.try_get_alive(entity) } } @@ -206,7 +206,7 @@ impl<'a> IdView<'a> { pub fn second_id(&self) -> EntityView { ecs_assert!(self.is_pair(), FlecsErrorCode::InvalidOperation); - let entity = ecs_second(self.id); + let entity = ecs_second(self.id, self.world); self.world.get_alive(entity) } @@ -218,7 +218,7 @@ impl<'a> IdView<'a> { if !self.is_pair() { None } else { - let entity = ecs_second(self.id); + let entity = ecs_second(self.id, self.world); self.world.try_get_alive(entity) } } @@ -323,7 +323,7 @@ impl<'a> IdOperations<'a> for IdView<'a> { fn new_from_id(world: impl WorldProvider<'a>, id: impl IntoId) -> Self { Self { world: world.world(), - id: id.into(), + id: id.into_id(world), } } diff --git a/flecs_ecs/src/core/mod.rs b/flecs_ecs/src/core/mod.rs index daf16ceb..b5e16bb1 100644 --- a/flecs_ecs/src/core/mod.rs +++ b/flecs_ecs/src/core/mod.rs @@ -10,7 +10,7 @@ mod entity_view; mod event; pub mod flecs; pub(crate) mod get_tuple; -mod id; +pub mod id; mod id_view; mod observer; mod observer_builder; diff --git a/flecs_ecs/src/core/observer.rs b/flecs_ecs/src/core/observer.rs index 4fc57604..9d8c1c6e 100644 --- a/flecs_ecs/src/core/observer.rs +++ b/flecs_ecs/src/core/observer.rs @@ -70,15 +70,15 @@ impl<'a> Observer<'a> { should be written as: ``` .observer::() - .with::() // Note: no `&` or `&mut` here! + .with(id::()) // Note: no `&` or `&mut` here! ``` Invalid signatures include: ``` .observer::() .observer::() - .observer::().with::<&T>() - .observer::().with::<&mut T>() + .observer::().with(id::<&T>()) + .observer::().read_write(id::()) ``` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "# diff --git a/flecs_ecs/src/core/observer_builder.rs b/flecs_ecs/src/core/observer_builder.rs index 5c1b7c7c..5819497f 100644 --- a/flecs_ecs/src/core/observer_builder.rs +++ b/flecs_ecs/src/core/observer_builder.rs @@ -27,9 +27,6 @@ impl<'a, P: ComponentId, T: QueryTuple> ObserverBuilder<'a, P, T> { /// # Arguments /// /// * `world` - The world to create the observer in - /// - /// See also - /// pub(crate) fn new(world: impl WorldProvider<'a>) -> Self { let desc = Default::default(); let mut obj = Self { @@ -54,9 +51,6 @@ impl<'a, P: ComponentId, T: QueryTuple> ObserverBuilder<'a, P, T> { /// /// * `world` - The world to create the observer in /// * `name` - The name of the observer - /// - /// See also - /// pub fn new_named(world: impl WorldProvider<'a>, name: &str) -> Self { let name = compact_str::format_compact!("{}\0", name); @@ -107,9 +101,6 @@ impl<'a, P, T: QueryTuple> ObserverBuilder<'a, P, T> { /// /// * `world` - The world to create the observer in /// * `desc` - The descriptor to create the observer from - /// - /// See also - /// pub(crate) fn new_from_desc( world: impl WorldProvider<'a>, desc: sys::ecs_observer_desc_t, @@ -148,30 +139,14 @@ impl ObserverBuilder<'_, P, T> { /// # Arguments /// /// * `event` - The event to add - pub fn add_event_id(&mut self, event: impl Into) -> &mut ObserverBuilder<(), T> { - let event = *event.into(); + pub fn add_event(&mut self, event: impl IntoEntity) -> &mut ObserverBuilder<(), T> { + let event = *event.into_entity(self.world); self.desc.events[self.event_count] = event; self.event_count += 1; // SAFETY: Same layout unsafe { core::mem::transmute(self) } } - /// Specify the event(s) for when the observer should run. - /// - /// # Type parameters - /// - /// * `T` - The type of the event - pub fn add_event(&mut self) -> &mut ObserverBuilder<(), T> - where - E: ComponentId, - { - let id = E::id(self.world()); - self.desc.events[self.event_count] = id; - self.event_count += 1; - // SAFETY: Same layout - unsafe { core::mem::transmute(self) } - } - /// Invoke observer for anything that matches its query on creation /// /// # Arguments @@ -221,9 +196,6 @@ where type BuiltType = Observer<'a>; /// Build the `observer_builder` into an `observer` - /// - /// See also - /// fn build(&mut self) -> Self::BuiltType { let observer = Observer::new(self.world(), self.desc); for s in self.term_builder.str_ptrs_to_free.iter_mut() { diff --git a/flecs_ecs/src/core/query.rs b/flecs_ecs/src/core/query.rs index 89c87cd5..93b4ab3b 100644 --- a/flecs_ecs/src/core/query.rs +++ b/flecs_ecs/src/core/query.rs @@ -311,9 +311,6 @@ where /// # Arguments /// /// * `world` - The world to get the iterator for - /// - /// # See also - /// unsafe fn get_iter_raw(&mut self) -> sys::ecs_iter_t { unsafe { sys::ecs_query_iter(self.world_ptr(), self.query.as_ptr()) } } diff --git a/flecs_ecs/src/core/query_builder.rs b/flecs_ecs/src/core/query_builder.rs index d0e47bb1..b01121a6 100644 --- a/flecs_ecs/src/core/query_builder.rs +++ b/flecs_ecs/src/core/query_builder.rs @@ -80,9 +80,6 @@ where /// # Arguments /// /// * `world` - The world to create the observer in - /// - /// See also - /// pub fn new(world: &'a World) -> Self { let mut obj = Self { desc: Default::default(), @@ -102,9 +99,6 @@ where /// /// * `world` - The world to create the observer in /// * `name` - The name of the observer - /// - /// See also - /// pub fn new_named(world: &'a World, name: &str) -> Self { let name = compact_str::format_compact!("{}\0", name); @@ -136,21 +130,16 @@ where /// /// * `world` - The world to create the observer in /// * `desc` - The descriptor to create the observer from - /// - /// See also - /// pub(crate) fn new_from_desc( world: impl WorldProvider<'a>, desc: &mut sys::ecs_query_desc_t, ) -> Self { - let obj = Self { + Self { desc: *desc, term_builder: Default::default(), world: world.world(), _phantom: core::marker::PhantomData, - }; - - obj + } } /// Create a new query builder from an existing descriptor with a term index @@ -160,9 +149,6 @@ where /// * `world` - The world to create the observer in /// * `desc` - The descriptor to create the observer from /// * `term_index` - The index of the term to create the observer from - /// - /// See also - /// pub(crate) fn new_from_desc_term_index( world: &'a World, desc: &mut sys::ecs_query_desc_t, @@ -311,7 +297,7 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { /// /// * `expr` - the expression to set fn expr(&mut self, expr: &'a str) -> &mut Self { - let expr = ManuallyDrop::new(format!("{}\0", expr)); + let expr = ManuallyDrop::new(format!("{expr}\0")); ecs_assert!( *self.expr_count_mut() == 0, FlecsErrorCode::InvalidOperation, @@ -324,57 +310,48 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { self } - /// set term with Id - fn with_id(&mut self, id: impl IntoId) -> &mut Self { + fn with(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { + let access = >::from_access_arg(id, self.world()); self.term(); - self.init_current_term(id); - self - } - /// set term with type - /// - /// if T is passed along, inout is set to `inout_none` which indicates - /// that you are not planning on fetching the component data - /// for reading or writing purposes use &T or &mut T instead. - /// you can alternatively use `.set_in()` and `.set_inout()` to set the - /// inout mode explicitly. - /// - /// ``` - /// use flecs_ecs::prelude::*; - /// - /// #[derive(Component)] - /// struct Position; - /// - /// #[derive(Component)] - /// struct Velocity; - /// - /// #[derive(Component)] - /// struct Mass; - /// - /// let world = World::new(); - /// - /// world - /// .query::<()>() - /// //this can be retrieved from it.field if desired - /// .with::() - /// .set_inout() //equivalent to .with::<&mut Position>() - /// .with::<&Velocity>() //equivalent to .with::().set_in() - /// .with::<&mut Mass>() //equivalent to .with::().set_inout() - /// .build(); - /// ``` - fn with(&mut self) -> &mut Self { - if ::IS_PAIR { - self.with_id(::get_id(self.world())); - } else { - self.term(); - let world = self.world(); - let id = T::get_id(world); - self.init_current_term(id); - if T::First::IS_REF { + match access.target { + AccessTarget::Entity(entity) => { + self.init_current_term(entity); + } + AccessTarget::Pair(rel, target) => { + self.init_current_term(ecs_pair(*rel, *target)); + } + AccessTarget::Name(name) => { + self.set_first::<&'static str>(name); + } + AccessTarget::PairName(rel, target) => { + self.set_first::<&'static str>(rel) + .set_second::<&'static str>(target); + } + AccessTarget::PairEntityName(rel, target) => { + self.init_current_term(rel); + self.set_second::<&'static str>(target); + } + AccessTarget::PairNameEntity(rel, target) => { + self.set_first::<&'static str>(rel); + self.set_second::(target); + } + } + + match access.mode { + AccessMode::Read => { self.current_term_mut().inout = InOutKind::In as i16; - } else if T::First::IS_MUT { + } + AccessMode::ReadWrite => { self.current_term_mut().inout = InOutKind::InOut as i16; } + AccessMode::Write => { + self.current_term_mut().inout = InOutKind::Out as i16; + } + _ => {} } self } @@ -386,73 +363,22 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { ) -> &mut Self { let enum_id = T::id(self.world()); let enum_field_id = value.id_variant(self.world()); - self.with_id((enum_id, enum_field_id)) + self.with((enum_id, enum_field_id)) } /// set term with enum wildcard fn with_enum_wildcard + ComponentId>(&mut self) -> &mut Self { - self.with_first::(flecs::Wildcard::ID) - } - - /// set term with pairs - fn with_first(&mut self, second: impl Into + Copy) -> &mut Self { - self.with_id((First::id(self.world()), second)) - } - - /// set term with pairs - fn with_first_name(&mut self, second: &'a str) -> &mut Self { - self.with_first_id(First::id(self.world()), second) - } - - /// set term with pairs - fn with_second(&mut self, first: impl Into + Copy) -> &mut Self { - self.with_id((first, Second::id(self.world()))) - } - - /// set term with pairs - fn with_second_name(&mut self, first: &'a str) -> &mut Self { - self.with_second_id(first, Second::id(self.world())) - } - - /// set term with Name - fn with_name(&mut self, name: &'a str) -> &mut Self { - self.term(); - self.set_first_name(name); - self - } - - /// set term with pair names - fn with_names(&mut self, first: &'a str, second: &'a str) -> &mut Self { - self.term(); - self.set_first_name(first).set_second_name(second); - self - } - - /// set term with first id and second name - fn with_first_id(&mut self, first: impl Into, second: &'a str) -> &mut Self { - self.term(); - self.init_current_term(first.into()); - self.set_second_name(second); - self - } - - /// set term with second id and first name - fn with_second_id(&mut self, first: &'a str, second: impl Into) -> &mut Self { - self.term(); - self.set_first_name(first).set_second_id(second.into()); - self + self.with((id::(), flecs::Wildcard::ID)) } /* Without methods, shorthand for .with(...).not() */ /// set term without Id - fn without_id(&mut self, id: impl IntoId) -> &mut Self { - self.with_id(id).not() - } - - /// set term without type - fn without(&mut self) -> &mut Self { - self.with::().not() + fn without(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { + self.with(id).not() } /// set term without enum @@ -470,49 +396,6 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { self.with_enum_wildcard::().not() } - /// set term without pairs - fn without_first(&mut self, second: impl Into + Copy) -> &mut Self { - self.with_first::(second).not() - } - - /// set term without pairs - fn without_first_name(&mut self, second: &'a str) -> &mut Self { - self.with_first_name::(second).not() - } - - /// set term without pairs - fn without_second( - &mut self, - first: impl Into + Copy, - ) -> &mut Self { - self.with_second::(first).not() - } - - /// set term without pairs - fn without_second_name(&mut self, first: &'a str) -> &mut Self { - self.with_second_name::(first).not() - } - - /// set term without Name - fn without_name(&mut self, name: &'a str) -> &mut Self { - self.with_name(name).not() - } - - /// set term without pair names - fn without_names(&mut self, first: &'a str, second: &'a str) -> &mut Self { - self.with_names(first, second).not() - } - - /// set term without first id and second name - fn without_first_id(&mut self, first: impl Into, second: &'a str) -> &mut Self { - self.with_first_id(first, second).not() - } - - /// set term without second id and first name - fn without_second_id(&mut self, first: &'a str, second: impl Into) -> &mut Self { - self.with_second_id(first, second).not() - } - /// Term notation for more complex query features fn term(&mut self) -> &mut Self { //let index = *self.current_term_index(); @@ -560,27 +443,12 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { self } - /// Set the type as current term and in mode out - fn write(&mut self) -> &mut Self { - self.with::(); - TermBuilderImpl::write_curr(self) - } - /// Set the id as current term and in mode out - fn write_id(&mut self, id: impl IntoId) -> &mut Self { - self.with_id(id); - TermBuilderImpl::write_curr(self) - } - - /// Set the name as current term and in mode out - fn write_name(&mut self, name: &'a str) -> &mut Self { - self.with_name(name); - TermBuilderImpl::write_curr(self) - } - - /// Set the names as current term and in mode out - fn write_names(&mut self, first: &'a str, second: &'a str) -> &mut Self { - self.with_names(first, second); + fn write(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { + self.with(id); TermBuilderImpl::write_curr(self) } @@ -593,51 +461,12 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { TermBuilderImpl::write_curr(self) } - /// Set the relationship as current term and in mode out - fn write_first(&mut self, second: impl Into + Copy) -> &mut Self { - self.with_first::(second); - TermBuilderImpl::write_curr(self) - } - - /// Set the relationship as current term and in mode out - fn write_first_name(&mut self, second: &'a str) -> &mut Self { - self.with_first_name::(second); - TermBuilderImpl::write_curr(self) - } - - /// Set the relationship as current term and in mode out - fn write_second(&mut self, first: impl Into + Copy) -> &mut Self { - self.with_second::(first); - TermBuilderImpl::write_curr(self) - } - - /// Set the relationship as current term and in mode out - fn write_second_name(&mut self, first: &'a str) -> &mut Self { - self.with_second_name::(first); - TermBuilderImpl::write_curr(self) - } - - /// Set the type as current term and in mode in - fn read(&mut self) -> &mut Self { - self.with::(); - TermBuilderImpl::read_curr(self) - } - /// Set the id as current term and in mode in - fn read_id(&mut self, id: impl IntoId) -> &mut Self { - self.with_id(id); - TermBuilderImpl::read_curr(self) - } - - /// Set the name as current term and in mode in - fn read_name(&mut self, name: &'a str) -> &mut Self { - self.with_name(name); - TermBuilderImpl::read_curr(self) - } - - /// Set the names as current term and in mode in - fn read_names(&mut self, first: &'a str, second: &'a str) -> &mut Self { - self.with_names(first, second); + fn read(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { + self.with(id); TermBuilderImpl::read_curr(self) } @@ -650,40 +479,16 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { TermBuilderImpl::read_curr(self) } - /// Set the relationship as current term and in mode in - fn read_first(&mut self, second: impl Into + Copy) -> &mut Self { - self.with_first::(second); - TermBuilderImpl::read_curr(self) - } - - /// Set the relationship as current term and in mode in - fn read_first_name(&mut self, second: &'a str) -> &mut Self { - self.with_first_name::(second); - TermBuilderImpl::read_curr(self) - } - - /// Set the relationship as current term and in mode in - fn read_second(&mut self, first: impl Into + Copy) -> &mut Self { - self.with_second::(first); - TermBuilderImpl::read_curr(self) - } - - /// Set the relationship as current term and in mode in - fn read_second_name(&mut self, first: &'a str) -> &mut Self { - self.with_second_name::(first); - TermBuilderImpl::read_curr(self) - } - /* scope_open/scope_close shorthand notation. */ /// Open a scope for the query fn scope_open(&mut self) -> &mut Self { - self.with_id(flecs::ScopeOpen::ID).entity(0) + self.with(flecs::ScopeOpen::ID).entity(0) } /// Close a scope for the query fn scope_close(&mut self) -> &mut Self { - self.with_id(flecs::ScopeClose::ID).entity(0) + self.with(flecs::ScopeClose::ID).entity(0) } /// Sorts the output of a query. @@ -750,8 +555,6 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { /// /// * `component`: The component used to sort. /// * `compare`: The compare function used to sort the components. - /// # See also - /// fn order_by_id( &mut self, component: impl Into, @@ -774,20 +577,6 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { self } - /// Group and sort matched tables. - /// - /// This function is similar to `group_by`, but uses a default `group_by` action. - /// - /// # Type Parameters - /// - /// * `T`: The component used to determine the group rank. - fn group_by(&mut self) -> &mut Self - where - T: ComponentId, - { - self.group_by_id_fn(T::id(self.world()), None) - } - /// Group and sort matched tables. /// /// This function is similar to `order_by`, but instead of sorting individual entities, @@ -803,37 +592,19 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { /// with entity sorting, table sorting takes precedence, and entities will be sorted /// within each set of tables that are assigned the same rank. /// - /// # Type Parameters - /// - /// * `T`: The component used to determine the group rank. - /// - /// # Arguments - /// - /// * `group_by_action`: Callback that determines group id for table. - fn group_by_fn(&mut self, group_by_action: sys::ecs_group_by_action_t) -> &mut Self - where - T: ComponentId, - { - self.group_by_id_fn(T::id(self.world()), group_by_action); - self - } - - /// Group and sort matched tables. - /// - /// This is similar to `group_by`, but uses a component identifier instead. - /// /// # Arguments /// /// * `component`: The component used to determine the group rank. /// * `group_by_action`: Callback that determines group id for table. - fn group_by_id_fn( + fn group_by_fn( &mut self, - component: impl Into, + component: impl IntoEntity, group_by_action: sys::ecs_group_by_action_t, ) -> &mut Self { + let world = self.world(); let desc = self.query_desc_mut(); desc.group_by_callback = group_by_action; - desc.group_by = *component.into(); + desc.group_by = *component.into_entity(world); self } @@ -844,8 +615,8 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> { /// # Arguments /// /// * `component`: The component used to determine the group rank. - fn group_by_id(&mut self, component: impl Into) -> &mut Self { - self.group_by_id_fn(component, None) + fn group_by(&mut self, component: impl IntoEntity) -> &mut Self { + self.group_by_fn(component, None) } /// Specify context to be passed to the `group_by` function. diff --git a/flecs_ecs/src/core/query_iter.rs b/flecs_ecs/src/core/query_iter.rs index a4af24b1..3a7379bb 100644 --- a/flecs_ecs/src/core/query_iter.rs +++ b/flecs_ecs/src/core/query_iter.rs @@ -33,19 +33,8 @@ where /// # Arguments /// /// * `group_id`: the group id to set - pub fn set_group_id(&mut self, group_id: impl Into) -> &mut Self { - unsafe { sys::ecs_iter_set_group(&mut self.iter, *group_id.into()) } - self - } - - /// Limit results to tables with specified group id (grouped queries only) - /// - /// # Type parameters - /// - /// * `Group`: the group to set - pub fn set_group(&mut self) -> &mut Self { - let world = unsafe { WorldRef::from_ptr(self.iter.real_world) }; - unsafe { sys::ecs_iter_set_group(&mut self.iter, Group::id(world)) } + pub fn set_group(&mut self, group_id: impl IntoEntity) -> &mut Self { + unsafe { sys::ecs_iter_set_group(&mut self.iter, *group_id.into_entity(self.world())) } self } diff --git a/flecs_ecs/src/core/query_tuple.rs b/flecs_ecs/src/core/query_tuple.rs index 12862da7..4898edda 100644 --- a/flecs_ecs/src/core/query_tuple.rs +++ b/flecs_ecs/src/core/query_tuple.rs @@ -355,7 +355,7 @@ where } else { true } }, FlecsErrorCode::InvalidParameter, "use `with` method to add union relationship"); - query.with_id(id); + query.with(id); let term = query.current_term_mut(); A::populate_term(term); @@ -559,7 +559,7 @@ macro_rules! impl_iterable { } else { true } }, FlecsErrorCode::InvalidParameter, "use `with` method to add union relationship"); - query.with_id(id); + query.with(id); let term = query.current_term_mut(); $t::populate_term(term); diff --git a/flecs_ecs/src/core/table/field.rs b/flecs_ecs/src/core/table/field.rs index c827362e..66179767 100644 --- a/flecs_ecs/src/core/table/field.rs +++ b/flecs_ecs/src/core/table/field.rs @@ -70,9 +70,6 @@ pub struct FieldUntyped { /// * `size`: size of the component type. /// * `count`: number of elements in the array. /// * `is_shared`: whether the component is shared. -/// -/// # See also -/// impl FieldUntyped { pub(crate) fn new(array: *mut c_void, size: usize, count: usize, is_shared: bool) -> Self { Self { diff --git a/flecs_ecs/src/core/table/iter.rs b/flecs_ecs/src/core/table/iter.rs index 3784b9f2..5370ae92 100644 --- a/flecs_ecs/src/core/table/iter.rs +++ b/flecs_ecs/src/core/table/iter.rs @@ -101,8 +101,12 @@ where /// # Arguments /// /// * `row` - Row being iterated over - pub fn entity(&self, row: usize) -> EntityView<'a> { - unsafe { EntityView::new_from(self.real_world(), *self.iter.entities.add(row)) } + pub fn entity(&self, row: usize) -> Option> { + let ptr = unsafe { self.iter.entities.add(row) }; + if ptr.is_null() { + return None; + } + Some(unsafe { EntityView::new_from(self.real_world(), *ptr) }) } /// Return a mut reference to the raw iterator object. @@ -145,20 +149,14 @@ where self.table().map(|t| t.archetype()) } - /// # See also - /// pub fn table(&self) -> Option> { NonNull::new(self.iter.table).map(|ptr| Table::new(self.real_world(), ptr)) } - /// # See also - /// pub fn other_table(&self) -> Option> { NonNull::new(self.iter.other_table).map(|ptr| Table::new(self.real_world(), ptr)) } - /// # See also - /// pub fn range(&self) -> Option> { self.table() .map(|t| TableRange::new(t, self.iter.offset, self.iter.count)) @@ -377,9 +375,6 @@ where /// # Returns /// /// Returns a column object that can be used to access the field data. - /// - /// # See also - /// // TODO? in C++ API there is a mutable and immutable version of this function // Maybe we should create a ColumnView struct that is immutable and use the Column struct for mutable access? pub unsafe fn field_unchecked(&self, index: i8) -> Field { @@ -522,6 +517,7 @@ where /// # Returns /// /// An option containing a mutable reference to the field data + #[allow(clippy::mut_from_ref)] pub fn field_at_mut(&self, index: i8, row: usize) -> Option<&mut T::UnderlyingType> where T: ComponentId, @@ -626,8 +622,8 @@ where /// /// let entity = world /// .entity() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()); /// /// world.new_query::<&Action>().run(|mut it| { /// let mut vec = vec![]; @@ -649,7 +645,7 @@ where ); let id = unsafe { self.iter.ids.add(index as usize).read() }; - Id::new(id) + crate::core::Id::new(id) } /// Get readonly access to entity ids. @@ -846,15 +842,18 @@ where /// let likes = world.entity(); /// let pizza = world.entity(); /// let salad = world.entity(); - /// let alice = world.entity().add_id((likes, pizza)).add_id((likes, salad)); + /// let alice = world.entity().add((likes, pizza)).add((likes, salad)); /// - /// let q = world.query::<()>().with_second::(likes).build(); + /// let q = world + /// .query::<()>() + /// .with((likes, id::())) + /// .build(); /// /// let mut count = 0; /// let mut tgt_count = 0; /// /// q.each_iter(|mut it, row, _| { - /// let e = it.entity(row); + /// let e = it.entity(row).unwrap(); /// assert_eq!(e, alice); /// /// it.targets(0, |tgt| { @@ -894,7 +893,10 @@ where FlecsErrorCode::InvalidParameter, "field does not match a pair" ); - let target = EntityView::new_from(self.world(), ecs_second(id)); + let target = EntityView::new_from( + self.world(), + ecs_second(id, unsafe { WorldRef::from_ptr(self.iter.world) }), + ); func(target); i += 1; } diff --git a/flecs_ecs/src/core/table/mod.rs b/flecs_ecs/src/core/table/mod.rs index 4ba34926..11543fb4 100644 --- a/flecs_ecs/src/core/table/mod.rs +++ b/flecs_ecs/src/core/table/mod.rs @@ -155,93 +155,17 @@ pub trait TableOperations<'a>: IntoTable { /// # Returns /// /// The index of the id in the table type, or `None` if the id is not found - fn find_type_index_id(&self, id: sys::ecs_id_t) -> Option { + fn find_type_index(&self, id: impl IntoId) -> Option { let index = unsafe { - sys::ecs_table_get_type_index(self.world().world_ptr(), self.table_ptr_mut(), id) + sys::ecs_table_get_type_index( + self.world().world_ptr(), + self.table_ptr_mut(), + *id.into_id(self.world()), + ) }; if index == -1 { None } else { Some(index) } } - /// Find type index for component type - /// - /// # Type parameters - /// - /// * `T` - The type of the component - /// - /// # Returns - /// - /// The index of the component in the table type, or `None` if the component is not in the table - fn find_type_index(&self) -> Option { - self.find_type_index_id(T::id(self.world())) - } - - /// Find type index for pair of component types - /// - /// # Arguments - /// - /// * `first` - First element of the pair - /// * `second` - Second element of the pair - /// - /// # Returns - /// - /// The index of the pair in the table type, or `None` if the pair is not in the table - fn find_type_index_pair_ids( - &self, - first: impl Into, - second: impl Into, - ) -> Option { - self.find_type_index_id(ecs_pair(*first.into(), *second.into())) - } - - /// Find type index for pair of component types - /// - /// # Type parameters - /// - /// * `First` - The type of the first component - /// * `Second` - The type of the second component - /// - /// # Returns - /// - /// The index of the pair in the table type, or `None` if the pair is not in the table - fn find_type_index_pair(&self) -> Option { - let world = self.world(); - self.find_type_index_pair_ids(First::id(world), Second::id(world)) - } - - /// Find type index for pair of component types - /// - /// # Type parameters - /// - /// * `First` - The type of the first component - /// - /// # Arguments - /// - /// * `second` - The id of the second component - /// - /// # Returns - /// - /// The index of the pair in the table type, or `None` if the pair is not in the table - fn find_type_index_first(&self, second: impl Into) -> Option { - self.find_type_index_pair_ids(First::id(self.world()), second) - } - - /// Find type index for pair of component types - /// - /// # Type parameters - /// - /// * `Second` - The type of the second component - /// - /// # Arguments - /// - /// * `first` - The id of the first component - /// - /// # Returns - /// - /// The index of the pair in the table type, or `None` if the pair is not in the table - fn find_type_index_second(&self, first: impl Into) -> Option { - self.find_type_index_pair_ids(first, Second::id(self.world())) - } - /// Find index for (component) id in table type /// /// This operation returns the index of first occurrence of the id in the table type. The id may be a wildcard. @@ -256,126 +180,17 @@ pub trait TableOperations<'a>: IntoTable { /// # Returns /// /// The index of the id in the table, or `None` if the id is not in the table - fn find_column_index_id(&self, id: sys::ecs_id_t) -> Option { + fn find_column_index(&self, id: impl IntoId) -> Option { let index = unsafe { - sys::ecs_table_get_column_index(self.world().world_ptr(), self.table_ptr_mut(), id) + sys::ecs_table_get_column_index( + self.world().world_ptr(), + self.table_ptr_mut(), + *id.into_id(self.world()), + ) }; if index == -1 { None } else { Some(index) } } - /// Find column index for component type in table - /// - /// This operation returns the index of first occurrence of the type in the table type. - /// - /// This is a constant time operation. - /// - /// # Type parameters - /// - /// * `T` - The type of the component - /// - /// # Returns - /// - /// The index of the component in the table, or `None` if the component is not in the table - fn find_column_index(&self) -> Option { - self.find_column_index_id(T::id(self.world())) - } - - /// Find index for pair of component types in table - /// - /// This operation returns the index of first occurrence of the pair in the table type. - /// - /// This is a constant time operation. - /// - /// # Type parameters - /// - /// * `First` - The type of the first component - /// * `Second` - The type of the second component - /// - /// # Returns - /// - /// The index of the pair in the table, or `None` if the pair is not in the table - fn find_column_index_pair(&self) -> Option { - let world = self.world(); - self.find_column_index_id(ecs_pair(First::id(world), Second::id(world))) - } - - /// Find index for pair of component ids in table type - /// - /// This operation returns the index of first occurrence of the pair in the table type. - /// - /// This is a constant time operation. - /// - /// # Arguments - /// - /// * `first` - The id of the first component - /// * `second` - The id of the second component - /// - /// # Returns - /// - /// The index of the pair in the table, or `None` if the pair is not in the table - fn find_column_index_pair_ids( - &self, - first: impl Into, - second: impl Into, - ) -> Option { - self.find_column_index_id(ecs_pair(*first.into(), *second.into())) - } - - /// Find index for pair of component types in table type - /// - /// # Type parameters - /// - /// * `First` - The type of the first component - /// - /// # Arguments - /// - /// * `second` - The id of the second component - /// - /// # Returns - /// - /// The index of the pair in the table, or `None` if the pair is not in the table - fn find_column_index_first( - &self, - second: impl Into, - ) -> Option { - self.find_column_index_pair_ids(First::id(self.world()), second) - } - - /// Find index for pair of component types in table type - /// - /// # Type parameters - /// - /// * `Second` - The type of the second component - /// - /// # Arguments - /// - /// * `first` - The id of the first component - /// - /// # Returns - /// - /// The index of the pair in the table, or `None` if the pair is not in the table - fn find_column_index_second( - &self, - first: impl Into, - ) -> Option { - self.find_column_index_pair_ids(first, Second::id(self.world())) - } - - /// Test if table has component type - /// - /// This is a constant time operation. - /// - /// # Type parameters - /// - /// * `T` - The type of the component - /// - /// # Returns - /// - /// True if the table has the component type, false otherwise - fn has_type(&self) -> bool { - self.find_type_index::().is_some() - } - /// Test if table has (component) id /// /// This is a constant time operation. @@ -387,40 +202,8 @@ pub trait TableOperations<'a>: IntoTable { /// # Returns /// /// True if the table has the component id, false otherwise - fn has_type_id(&self, id: sys::ecs_id_t) -> bool { - self.find_type_index_id(id).is_some() - } - - /// Test if table has pair of component types - /// - /// This is a constant time operation. - /// - /// # Type parameters - /// - /// * `First` - The type of the first component - /// * `Second` - The type of the second component - /// - /// # Returns - /// - /// True if the table has the pair of component types, false otherwise - fn has_pair(&self) -> bool { - self.find_type_index_pair::().is_some() - } - - /// Test if table has pair of component ids - /// - /// This is a constant time operation. - /// - /// # Arguments - /// - /// * `first` - The id of the first component - /// * `second` - The id of the second component - /// - /// # Returns - /// - /// True if the table has the pair of component ids, false otherwise - fn has_pair_ids(&self, first: impl Into, second: impl Into) -> bool { - self.find_type_index_pair_ids(first, second).is_some() + fn has(&self, id: impl IntoId) -> bool { + self.find_type_index(id).is_some() } /// Get column, components array ptr from table by column index. @@ -446,7 +229,7 @@ pub trait TableOperations<'a>: IntoTable { /// # Returns /// /// Some(Pointer) to the column, or `None` if not found - fn get_mut(&self) -> Option<&mut [T]> { + fn get_mut(&mut self) -> Option<&mut [T]> { self.get_mut_untyped(T::id(self.world())).map(|ptr| unsafe { core::slice::from_raw_parts_mut(ptr as *mut T, (self.count()) as usize) }) @@ -462,7 +245,7 @@ pub trait TableOperations<'a>: IntoTable { /// /// Some(Pointer) to the column, or `None` if not found fn get_mut_untyped(&self, id: sys::ecs_id_t) -> Option<*mut c_void> { - if let Some(index) = self.find_column_index_id(id) { + if let Some(index) = self.find_column_index(id) { self.column_untyped(index) } else { None @@ -515,21 +298,6 @@ pub trait TableOperations<'a>: IntoTable { unsafe { sys::ecs_table_get_column_size(self.table_ptr_mut(), index) } } - /// Return depth for table in tree for relationship type. - /// Depth is determined by counting the number of targets encountered while traversing up the - /// relationship tree for rel. Only acyclic relationships are supported. - /// - /// # Type parameters - /// - /// * `Rel` - The type of the relationship - /// - /// # Returns - /// - /// The depth of the relationship - fn depth(&self) -> i32 { - self.depth_id(Rel::id(self.world())) - } - /// Return depth for table in tree for relationship type. /// Depth is determined by counting the number of targets encountered while traversing up the /// relationship tree for rel. Only acyclic relationships are supported. @@ -541,12 +309,13 @@ pub trait TableOperations<'a>: IntoTable { /// # Returns /// /// The depth of the relationship - fn depth_id(&self, rel: impl Into) -> i32 { + fn depth(&self, rel: impl IntoEntity) -> i32 { + let world = self.world(); unsafe { sys::ecs_table_get_depth( - self.world().world_ptr_mut(), + world.world_ptr_mut(), self.table_ptr_mut(), - *rel.into(), + *rel.into_entity(world), ) } } @@ -585,8 +354,6 @@ impl<'a> TableOperations<'a> for TableRange<'a> { } /// Returns the table range count - /// - /// # See also fn count(&self) -> i32 { self.count } diff --git a/flecs_ecs/src/core/term.rs b/flecs_ecs/src/core/term.rs index 4c450cfd..27bf9072 100644 --- a/flecs_ecs/src/core/term.rs +++ b/flecs_ecs/src/core/term.rs @@ -184,7 +184,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi where T: IntoId, { - let id = id.into(); + let id = id.into_id(self.world()); let term = self.current_term_mut(); #[allow(clippy::collapsible_else_if)] @@ -275,8 +275,6 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi } /// The self flag indicates the term identifier itself is used - /// # See also - /// fn self_(&mut self) -> &mut Self { self.term_ref_mut().id |= ECS_SELF; self @@ -287,13 +285,14 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// # Arguments /// /// * `id` - The id to set. - fn set_id(&mut self, id: impl Into) -> &mut Self { + fn set_id(&mut self, id: impl IntoEntity) -> &mut Self { + let world = self.world(); if self.current_term_ref_mode() != TermRefMode::Src { check_term_access_validity(self); } let term_ref = self.term_ref_mut(); - term_ref.id = *id.into(); + term_ref.id = *id.into_entity(world); self } @@ -381,134 +380,107 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi self } - /// Select src identifier, initialize it with entity id - /// - /// # Arguments - /// - /// * `id` - The id to set. - fn set_src_id(&mut self, id: impl Into) -> &mut Self { - self.src().set_id(id) - } - - /// Select src identifier, initialize it with id associated with type - /// - /// # Type Arguments - /// - /// * `T` - The type to use. - fn set_src(&mut self) -> &mut Self { - self.set_src_id(T::id(self.world())) - } - - /// Select src identifier, initialize it with name. If name starts with a $ - /// the name is interpreted as a variable. + /// Select src identifier /// - /// # Arguments /// - /// * `name` - The name to set. - fn set_src_name(&mut self, name: &'a str) -> &mut Self { - ecs_assert!( - !name.is_empty(), - FlecsErrorCode::InvalidParameter, - "name is empty" - ); - - self.src(); - if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { - self.set_var(stripped_name) - } else { - self.name(name) - } - } - - /// Select first identifier, initialize it with entity id + /// * initialize it with entity id or + /// * initialize it with name. If name starts with a $ + /// the name is interpreted as a variable. /// /// # Arguments /// /// * `id` - The id to set. - fn set_first_id(&mut self, id: impl Into) -> &mut Self { - check_term_access_validity(self); - self.first().set_id(id); - // reset term ref mode to src, otherwise it stays on second and makes other actions potentially invalid - self.set_term_ref_mode(TermRefMode::Src); - self - } - - /// Select first identifier, initialize it with id associated with type - /// - /// # Type Arguments - /// - /// * `T` - The type to use. - fn set_first(&mut self) -> &mut Self { - check_term_access_validity(self); - self.set_first_id(First::id(self.world())) - } - - /// Select first identifier, initialize it with name. If name starts with a $ - /// the name is interpreted as a variable. - /// - /// # Arguments - /// - /// * `name` - The name to set. - fn set_first_name(&mut self, name: &'a str) -> &mut Self { - check_term_access_validity(self); - ecs_assert!( - !name.is_empty(), - FlecsErrorCode::InvalidParameter, - "name is empty" - ); - - self.first(); - if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { - self.set_var(stripped_name); - } else { - self.name(name); + fn set_src(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { + let access = Access::from_access_arg(id, self.world()); + + match access.target { + AccessTarget::Entity(entity) => self.src().set_id(entity), + AccessTarget::Name(name) => { + ecs_assert!( + !name.is_empty(), + FlecsErrorCode::InvalidParameter, + "name is empty" + ); + self.src(); + if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { + self.set_var(stripped_name) + } else { + self.name(name) + } + } + _ => panic!("Invalid access target, only single targets allowed"), } - // reset term ref mode to src, otherwise it stays on second and makes other actions potentially invalid - self.set_term_ref_mode(TermRefMode::Src); - self } - /// Select second identifier, initialize it with entity id + /// Select first identifier /// - /// # Arguments - /// - /// * `id` - The id to set. - fn set_second_id(&mut self, id: impl Into) -> &mut Self { + /// * initialize with id or + /// * initialize it with name. If name starts with a $ + /// the name is interpreted as a variable. + fn set_first(&mut self, id: Q) -> &mut Self + where + Access: FromAccessArg, + { check_term_access_validity(self); - self.second().set_id(id); + let access = Access::from_access_arg(id, self.world()); + match access.target { + AccessTarget::Entity(entity) => { + self.first().set_id(entity); + } + AccessTarget::Name(name) => { + ecs_assert!( + !name.is_empty(), + FlecsErrorCode::InvalidParameter, + "name is empty" + ); + + self.first(); + if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { + self.set_var(stripped_name); + } else { + self.name(name); + } + } + _ => panic!("Invalid access target, only single targets allowed"), + } // reset term ref mode to src, otherwise it stays on second and makes other actions potentially invalid self.set_term_ref_mode(TermRefMode::Src); self } - /// Select second identifier, initialize it with id associated with type - /// - /// # Type Arguments + /// Select second identifier /// - /// * `T` - The type to use. - fn set_second(&mut self) -> &mut Self { + /// * initialize with id or + /// * initialize it with name. If name starts with a $ + /// the name is interpreted as a variable. + fn set_second(&mut self, id: T) -> &mut Self + where + Access: FromAccessArg, + { check_term_access_validity(self); - self.set_second_id(Second::id(self.world())) - } - - /// Select second identifier, initialize it with name. If name starts with a $ - /// the name is interpreted as a variable. - /// - /// # Arguments - /// - /// * `name` - The name to set. - fn set_second_name(&mut self, name: &'a str) -> &mut Self { - ecs_assert!( - !name.is_empty(), - FlecsErrorCode::InvalidParameter, - "name is empty" - ); - - self.second(); - if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { - self.set_var(stripped_name); - } else { - self.name(name); + let access = Access::from_access_arg(id, self.world()); + match access.target { + AccessTarget::Entity(entity) => { + self.second().set_id(entity); + } + AccessTarget::Name(name) => { + ecs_assert!( + !name.is_empty(), + FlecsErrorCode::InvalidParameter, + "name is empty" + ); + + self.second(); + if let Some(stripped_name) = strip_prefix_str_raw(name, "$") { + self.set_var(stripped_name); + } else { + self.name(name); + } + } + _ => panic!("Invalid access target, only single targets allowed"), } // reset term ref mode to src, otherwise it stays on second and makes other actions potentially invalid self.set_term_ref_mode(TermRefMode::Src); @@ -543,7 +515,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// # Arguments /// /// * `traverse_relationship` - The relationship to traverse. - fn up_id(&mut self, traverse_relationship: impl Into) -> &mut Self { + fn up_id(&mut self, traverse_relationship: impl IntoEntity) -> &mut Self { ecs_assert!( self.current_term_ref_mode() == TermRefMode::Src, FlecsErrorCode::InvalidParameter, @@ -551,25 +523,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi ); let term_ref = self.term_ref_mut(); term_ref.id |= ECS_UP; - self.current_term_mut().trav = *traverse_relationship.into(); - self - } - - /// The up flag indicates that the term identifier may be substituted by - /// traversing a relationship upwards. For example: substitute the identifier - /// with its parent by traversing the `ChildOf` relationship. - /// - /// # Type Arguments - /// - /// * `TravRel` - The relationship to traverse. - fn up_type(&mut self) -> &mut Self { - ecs_assert!( - self.current_term_ref_mode() == TermRefMode::Src, - FlecsErrorCode::InvalidParameter, - "up traversal can only be applied to term source" - ); - self.term_ref_mut().id |= ECS_UP; - self.current_term_mut().trav = TravRel::id(self.world()); + self.current_term_mut().trav = *traverse_relationship.into_entity(self.world()); self } @@ -589,25 +543,12 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// # Arguments /// /// * `traverse_relationship` - The optional relationship to traverse. - fn cascade_id(&mut self, traverse_relationship: impl Into) -> &mut Self { + fn cascade_id(&mut self, traverse_relationship: impl IntoEntity) -> &mut Self { self.up_id(traverse_relationship); self.term_ref_mut().id |= ECS_CASCADE; self } - /// Cascade iterates a hierarchy in top to bottom order (breadth first search) - /// The cascade flag is like up, but returns results in breadth-first order. - /// Only supported for `flecs::query` - /// - /// # Type Arguments - /// - /// * `TravRel` - The relationship to traverse. - fn cascade_type(&mut self) -> &mut Self { - self.up_type::(); - self.term_ref_mut().id |= ECS_CASCADE; - self - } - /// Use with cascade to iterate results in descending (bottom + top) order. fn desc(&mut self) -> &mut Self { self.term_ref_mut().id |= ECS_DESC; @@ -620,8 +561,8 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// /// * `traverse_relationship` - The relationship to traverse. /// * `flags` - The direction to traverse. - fn trav(&mut self, traverse_relationship: impl Into, flags: u64) -> &mut Self { - self.current_term_mut().trav = *traverse_relationship.into(); + fn trav(&mut self, traverse_relationship: impl IntoEntity, flags: u64) -> &mut Self { + self.current_term_mut().trav = *traverse_relationship.into_entity(self.world()); self.term_ref_mut().id |= flags; self } @@ -632,7 +573,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// /// * `flags` - The direction to traverse. fn id_flags(&mut self, flags: impl IntoId) -> &mut Self { - self.term_ref_mut().id |= *flags.into(); + self.term_ref_mut().id |= *flags.into_id(self.world()); self } @@ -704,7 +645,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi /// * [`Self::inout_stage`] /// * [`InOutKind`] #[inline(always)] - fn read_write(&mut self) -> &mut Self { + fn read_write_curr(&mut self) -> &mut Self { check_term_access_validity(self); self.inout_stage(InOutKind::InOut) } @@ -892,7 +833,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi self.current_term_mut().src.id = sid; } else { self.current_term_mut().src.id = - sys::ecs_get_alive(self.world_ptr_mut(), *ecs_first(sid)); + sys::ecs_get_alive(self.world_ptr_mut(), *ecs_first(sid, self.world())); } } self diff --git a/flecs_ecs/src/core/utility/functions.rs b/flecs_ecs/src/core/utility/functions.rs index 0d7c9d29..a32959b4 100644 --- a/flecs_ecs/src/core/utility/functions.rs +++ b/flecs_ecs/src/core/utility/functions.rs @@ -123,8 +123,10 @@ pub fn ecs_add_pair( /// /// The first entity from the pair. #[inline(always)] -pub fn ecs_first(e: impl IntoId) -> Entity { - Entity(ecs_entity_id_high(e.into() & RUST_ECS_COMPONENT_MASK)) +pub fn ecs_first<'a>(e: impl IntoId, world: impl WorldProvider<'a>) -> Entity { + let world = world.world(); + let id = e.into_id(world) & RUST_ECS_COMPONENT_MASK; + Entity(ecs_entity_id_high(id, world)) } /// Get the second entity from a pair. @@ -137,8 +139,9 @@ pub fn ecs_first(e: impl IntoId) -> Entity { /// /// The second entity from the pair. #[inline(always)] -pub fn ecs_second(e: impl IntoId) -> Entity { - Entity(ecs_entity_id_low(e.into())) +pub fn ecs_second<'a>(e: impl IntoId, world: impl WorldProvider<'a>) -> Entity { + let world = world.world(); + Entity(ecs_entity_id_low(e.into_id(world), world)) } /// Get the lower 32 bits of an entity id. @@ -151,8 +154,8 @@ pub fn ecs_second(e: impl IntoId) -> Entity { /// /// The lower 32 bits of the entity id. #[inline(always)] -pub fn ecs_entity_id_low(value: impl IntoId) -> u64 { - *value.into() as u32 as u64 +pub fn ecs_entity_id_low<'a>(value: impl IntoId, world: impl WorldProvider<'a>) -> u64 { + *value.into_id(world) as u32 as u64 } /// Get the higher 32 bits of an entity id. @@ -165,8 +168,8 @@ pub fn ecs_entity_id_low(value: impl IntoId) -> u64 { /// /// The higher 32 bits of the entity id. #[inline(always)] -pub fn ecs_entity_id_high(value: impl IntoId) -> u64 { - (*value.into()) >> 32 +pub fn ecs_entity_id_high<'a>(value: impl IntoId, world: impl WorldProvider<'a>) -> u64 { + *value.into_id(world) >> 32 } pub fn type_name_cstring() -> CString { @@ -406,7 +409,6 @@ pub(crate) unsafe fn ecs_field_at(it: *const sys::ecs_iter_t, index: i8, row: /// * `T`: The type to get the `OperKind` for. /// /// # See also -/// pub(crate) fn type_to_oper() -> OperKind { T::OPER } diff --git a/flecs_ecs/src/core/utility/id.rs b/flecs_ecs/src/core/utility/id.rs new file mode 100644 index 00000000..a491be11 --- /dev/null +++ b/flecs_ecs/src/core/utility/id.rs @@ -0,0 +1,28 @@ +use crate::core::ComponentId; + +impl Clone for Id { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for Id {} + +#[derive(Debug)] +pub struct Id { + _marker: core::marker::PhantomData, +} + +#[inline(always)] +pub const fn id() -> Id { + Id::new() +} + +impl Id { + #[inline(always)] + pub(crate) const fn new() -> Self { + Id { + _marker: core::marker::PhantomData, + } + } +} diff --git a/flecs_ecs/src/core/utility/mod.rs b/flecs_ecs/src/core/utility/mod.rs index c2d90fe5..d907e77c 100644 --- a/flecs_ecs/src/core/utility/mod.rs +++ b/flecs_ecs/src/core/utility/mod.rs @@ -3,6 +3,7 @@ mod errors; mod functions; +pub mod id; pub(crate) mod id_map; mod log; pub mod traits; @@ -10,6 +11,7 @@ pub mod types; pub use errors::*; pub use functions::*; +pub use id::id; pub(crate) use id_map::*; pub use log::*; diff --git a/flecs_ecs/src/core/utility/traits/id_operations.rs b/flecs_ecs/src/core/utility/traits/id_operations.rs index 5417393f..73fd22fa 100644 --- a/flecs_ecs/src/core/utility/traits/id_operations.rs +++ b/flecs_ecs/src/core/utility/traits/id_operations.rs @@ -16,31 +16,37 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { /// /// * C API: `ecs_id_is_wildcard` fn is_wildcard(self) -> bool { - unsafe { sys::ecs_id_is_wildcard(*self.into()) } + let world = self.world(); + unsafe { sys::ecs_id_is_wildcard(*self.into_id(world)) } } /// Return id with role added #[inline(always)] fn add_flags(self, flags: impl IntoId) -> Self { - Self::new_from_id(self.world(), self.into() | flags.into()) + let world = self.world(); + Self::new_from_id(self.world(), self.into_id(world) | flags.into_id(world)) } /// Return id with role removed. /// This function checks if the id has the specified role, and if it does not, the function will assert. #[inline(always)] fn remove_flags_checked(self, _flags: impl IntoId) -> Self { + let world = self.world(); ecs_assert!( - self.into() & RUST_ecs_id_FLAGS_MASK == _flags.into(), + self.into_id(world) & RUST_ecs_id_FLAGS_MASK == _flags.into_id(world), FlecsErrorCode::InvalidParameter ); - Self::new_from_id(self.world(), self.into() & RUST_ECS_COMPONENT_MASK) + Self::new_from_id(self.world(), self.into_id(world) & RUST_ECS_COMPONENT_MASK) } /// Return id with role removed #[inline(always)] fn remove_flags(self) -> Self { - Self::new_from_id(self.world(), self.into() & RUST_ECS_COMPONENT_MASK) + Self::new_from_id( + self.world(), + self.into_id(self.world()) & RUST_ECS_COMPONENT_MASK, + ) } /// Get flags associated with id @@ -50,25 +56,26 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { /// The flags associated with the id or 0 Entity if the id is not in use #[inline(always)] fn flags(self) -> Self { - Self::new_from_id(self.world(), self.into() & RUST_ecs_id_FLAGS_MASK) + let world = self.world(); + Self::new_from_id(world, self.into_id(world) & RUST_ecs_id_FLAGS_MASK) } /// Test if id has specified role #[inline(always)] fn has_flags_for(self, flags: u64) -> bool { - self.into() & flags == flags + self.into_id(self.world()) & flags == flags } /// Test if id has any role #[inline(always)] fn has_any_flags(self) -> bool { - self.into() & RUST_ecs_id_FLAGS_MASK != 0 + self.into_id(self.world()) & RUST_ecs_id_FLAGS_MASK != 0 } /// Return id without role #[inline(always)] fn remove_generation(self) -> EntityView<'a> { - EntityView::new_from(self.world(), *self.into() as u32 as u64) + EntityView::new_from(self.world(), *self.into_id(self.world()) as u32 as u64) } /// Convert id to string @@ -78,12 +85,14 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { /// * C API: `ecs_id_str` #[inline(always)] fn to_str(self) -> &'a str { + let world = self.world(); // SAFETY: We assume that `ecs_id_str` returns a pointer to a null-terminated // C string with a static lifetime. The caller must ensure this invariant. // ecs_id_ptr never returns null, so we don't need to check for that. - if let Ok(str) = - unsafe { core::ffi::CStr::from_ptr(sys::ecs_id_str(self.world_ptr(), *self.into())) } - .to_str() + if let Ok(str) = unsafe { + core::ffi::CStr::from_ptr(sys::ecs_id_str(self.world_ptr(), *self.into_id(world))) + } + .to_str() { str } else { @@ -91,7 +100,7 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { false, FlecsErrorCode::UnwrapFailed, "Failed to convert id to string (id: {})", - self.into() + self.into_id(world) ); "invalid_str_from_id" @@ -112,7 +121,7 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { // SAFETY: We assume that `ecs_id_str` returns a pointer to a null-terminated // C string with a static lifetime. The caller must ensure this invariant. // ecs_id_ptr never returns null, so we don't need to check for that. - let c_str_ptr = unsafe { sys::ecs_id_str(self.world_ptr(), *self.into()) }; + let c_str_ptr = unsafe { sys::ecs_id_str(self.world_ptr(), *self.into_id(self.world())) }; // SAFETY: We assume the C string is valid UTF-8. This is risky if not certain. unsafe { core::str::from_utf8_unchecked(core::ffi::CStr::from_ptr(c_str_ptr).to_bytes()) } @@ -125,11 +134,14 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { /// * C API: `ecs_id_flag_str` #[inline(always)] fn flags_str(self) -> &'a str { + let world = self.world(); // SAFETY: We assume that `ecs_role_str` returns a pointer to a null-terminated // C string with a static lifetime. The caller must ensure this invariant. // ecs_role_str never returns null, so we don't need to check for that. unsafe { - core::ffi::CStr::from_ptr(sys::ecs_id_flag_str(*self.into() & RUST_ecs_id_FLAGS_MASK)) + core::ffi::CStr::from_ptr(sys::ecs_id_flag_str( + *self.into_id(world) & RUST_ecs_id_FLAGS_MASK, + )) } .to_str() .unwrap_or({ @@ -137,7 +149,7 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { false, FlecsErrorCode::UnwrapFailed, "Failed to convert id to string (id: {})", - self.into() + self.into_id(world) ); "invalid_str_from_id" }) @@ -156,7 +168,8 @@ pub trait IdOperations<'a>: WorldProvider<'a> + IntoId + Sized + Copy { // SAFETY: We assume that `ecs_id_str` returns a pointer to a null-terminated // C string with a static lifetime. The caller must ensure this invariant. // ecs_id_ptr never returns null, so we don't need to check for that. - let c_str_ptr = unsafe { sys::ecs_id_flag_str(*self.into() & RUST_ecs_id_FLAGS_MASK) }; + let c_str_ptr = + unsafe { sys::ecs_id_flag_str(*self.into_id(self.world()) & RUST_ecs_id_FLAGS_MASK) }; // SAFETY: We assume the C string is valid UTF-8. This is risky if not certain. unsafe { core::str::from_utf8_unchecked(core::ffi::CStr::from_ptr(c_str_ptr).to_bytes()) } diff --git a/flecs_ecs/src/core/utility/traits/into_entity.rs b/flecs_ecs/src/core/utility/traits/into_entity.rs new file mode 100644 index 00000000..dbf5a8d6 --- /dev/null +++ b/flecs_ecs/src/core/utility/traits/into_entity.rs @@ -0,0 +1,184 @@ +use super::{super::id::Id, WorldProvider}; +use crate::core::{ComponentId, ComponentInfo, Entity}; + +pub trait IntoEntity { + const IS_TYPED_PAIR: bool; + const IS_TYPED: bool; + const IF_ID_IS_DEFAULT: bool; + const IS_TYPED_SECOND: bool; + const IF_ID_IS_DEFAULT_SECOND: bool; + const IS_ENUM: bool; + const IS_TYPE_TAG: bool; + const IS_TYPED_REF: bool; + const IS_TYPED_MUT_REF: bool; + fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity; +} + +impl IntoEntity for Id { + const IS_TYPED_PAIR: bool = false; + const IS_TYPED: bool = true; + const IF_ID_IS_DEFAULT: bool = T::IMPLS_DEFAULT; + const IS_TYPED_SECOND: bool = true; + const IF_ID_IS_DEFAULT_SECOND: bool = false; + const IS_ENUM: bool = T::IS_ENUM; + const IS_TYPE_TAG: bool = T::IS_TAG; + const IS_TYPED_REF: bool = ::IS_REF; + const IS_TYPED_MUT_REF: bool = ::IS_MUT; + fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity { + world.world().component_id::() + } +} + +impl> IntoEntity for T { + const IS_TYPED_PAIR: bool = false; + const IS_TYPED: bool = false; + const IF_ID_IS_DEFAULT: bool = false; //we don't know if the id is default or not + const IS_TYPED_SECOND: bool = true; + const IF_ID_IS_DEFAULT_SECOND: bool = false; + const IS_ENUM: bool = false; + const IS_TYPE_TAG: bool = false; + const IS_TYPED_REF: bool = false; + const IS_TYPED_MUT_REF: bool = false; + fn into_entity<'a>(self, _world: impl WorldProvider<'a>) -> Entity { + self.into() + } +} + +#[doc(hidden)] +pub trait InternalIntoEntity { + const IS_TYPED_PAIR: bool; + const IS_TYPED: bool; + const IF_ID_IS_DEFAULT: bool; + const IS_TYPED_SECOND: bool; + const IF_ID_IS_DEFAULT_SECOND: bool; + const IS_ENUM: bool; + const IS_TYPE_TAG: bool; + const IS_TYPED_REF: bool; + const IS_TYPED_MUT_REF: bool; + + fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity; +} + +#[doc(hidden)] +impl InternalIntoEntity for T { + const IS_TYPED_PAIR: bool = T::IS_TYPED_PAIR; + const IS_TYPED: bool = T::IS_TYPED; + const IF_ID_IS_DEFAULT: bool = T::IF_ID_IS_DEFAULT; + const IS_TYPED_SECOND: bool = T::IS_TYPED_SECOND; + const IF_ID_IS_DEFAULT_SECOND: bool = T::IF_ID_IS_DEFAULT_SECOND; + const IS_ENUM: bool = T::IS_ENUM; + const IS_TYPE_TAG: bool = ::IS_TYPE_TAG; + const IS_TYPED_REF: bool = T::IS_TYPED_REF; + const IS_TYPED_MUT_REF: bool = T::IS_TYPED_MUT_REF; + fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity { + self.into_entity(world) + } +} + +// we implement this to optimize the case where we add a component id to add +// normally we shouldn't implement IntoEntity for Id +#[doc(hidden)] +impl InternalIntoEntity for crate::core::Id { + const IS_TYPED_PAIR: bool = false; + const IS_TYPED: bool = false; + const IF_ID_IS_DEFAULT: bool = false; //we don't know if the id is default or not + const IS_TYPED_SECOND: bool = true; + const IF_ID_IS_DEFAULT_SECOND: bool = false; + const IS_ENUM: bool = false; + const IS_TYPE_TAG: bool = false; + const IS_TYPED_REF: bool = false; + const IS_TYPED_MUT_REF: bool = false; + fn into_entity<'a>(self, _world: impl WorldProvider<'a>) -> Entity { + Entity(self.0) + } +} + +// we implement this to optimize the case where we add a component id to add +// normally we shouldn't implement IntoEntity for Id +#[doc(hidden)] +impl InternalIntoEntity for crate::core::IdView<'_> { + const IS_TYPED_PAIR: bool = false; + const IS_TYPED: bool = false; + const IF_ID_IS_DEFAULT: bool = false; //we don't know if the id is default or not + const IS_TYPED_SECOND: bool = true; + const IF_ID_IS_DEFAULT_SECOND: bool = false; + const IS_ENUM: bool = false; + const IS_TYPE_TAG: bool = false; + const IS_TYPED_REF: bool = false; + const IS_TYPED_MUT_REF: bool = false; + fn into_entity<'a>(self, _world: impl WorldProvider<'a>) -> Entity { + Entity(*self.id) + } +} + +#[doc(hidden)] +impl InternalIntoEntity for (T, U) +where + T: InternalIntoEntity + Copy, + U: InternalIntoEntity + Copy, +{ + const IS_TYPED_PAIR: bool = true; + const IS_TYPED: bool = T::IS_TYPED; + const IF_ID_IS_DEFAULT: bool = T::IF_ID_IS_DEFAULT; //we don't know if the id is default or not + const IS_TYPED_SECOND: bool = U::IS_TYPED; + const IF_ID_IS_DEFAULT_SECOND: bool = U::IF_ID_IS_DEFAULT; //we don't know if the id is default or not + const IS_ENUM: bool = false; + const IS_TYPE_TAG: bool = T::IS_TYPE_TAG & U::IS_TYPE_TAG; + const IS_TYPED_REF: bool = false; + const IS_TYPED_MUT_REF: bool = false; + fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity { + let world = world.world(); + Entity(crate::core::ecs_pair( + *(self.0.into_entity(world)), + *(self.1.into_entity(world)), + )) + } +} + +// #[doc(hidden)] +// impl InternalIntoEntity for &(T, U) +// where +// T: InternalIntoEntity + Copy, +// U: InternalIntoEntity + Copy, +// { +// const IS_TYPED_PAIR: bool = true; +// const IS_TYPED: bool = T::IS_TYPED; +// const IF_ID_IS_DEFAULT: bool = T::IF_ID_IS_DEFAULT; //we don't know if the id is default or not +// const IS_TYPED_SECOND: bool = U::IS_TYPED; +// const IF_ID_IS_DEFAULT_SECOND: bool = U::IF_ID_IS_DEFAULT; //we don't know if the id is default or not +// const IS_ENUM: bool = false; +// const IS_TYPE_TAG: bool = T::IS_TYPE_TAG & U::IS_TYPE_TAG; +// const IS_TYPED_REF: bool = true; +// const IS_TYPED_MUT_REF: bool = false; +// fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity { +// let world = world.world(); +// Entity(crate::core::ecs_pair( +// *(self.0.into_entity(world)), +// *(self.1.into_entity(world)), +// )) +// } +// } + +// #[doc(hidden)] +// impl InternalIntoEntity for &mut (T, U) +// where +// T: InternalIntoEntity + Copy, +// U: InternalIntoEntity + Copy, +// { +// const IS_TYPED_PAIR: bool = true; +// const IS_TYPED: bool = T::IS_TYPED; +// const IF_ID_IS_DEFAULT: bool = T::IF_ID_IS_DEFAULT; //we don't know if the id is default or not +// const IS_TYPED_SECOND: bool = U::IS_TYPED; +// const IF_ID_IS_DEFAULT_SECOND: bool = U::IF_ID_IS_DEFAULT; //we don't know if the id is default or not +// const IS_ENUM: bool = false; +// const IS_TYPE_TAG: bool = T::IS_TYPE_TAG & U::IS_TYPE_TAG; +// const IS_TYPED_REF: bool = false; +// const IS_TYPED_MUT_REF: bool = true; +// fn into_entity<'a>(self, world: impl WorldProvider<'a>) -> Entity { +// let world = world.world(); +// Entity(crate::core::ecs_pair( +// *(self.0.into_entity(world)), +// *(self.1.into_entity(world)), +// )) +// } +// } diff --git a/flecs_ecs/src/core/utility/traits/into_id.rs b/flecs_ecs/src/core/utility/traits/into_id.rs index 74b0e39f..d3d18693 100644 --- a/flecs_ecs/src/core/utility/traits/into_id.rs +++ b/flecs_ecs/src/core/utility/traits/into_id.rs @@ -1,21 +1,33 @@ use crate::core::*; -use crate::sys; -/// Extracts the Ecs ID from a type. -/// Extension trait from [`Into`] for tuples that implement `Into`. +/// Extracts the Ecs ID a type. +/// Extension trait [`Into`] for tuples that implement `Into`. /// These types can be [`Id`], [`IdView`], [`Entity`], [`EntityView`], [`Component`], [`UntypedComponent`]. -pub trait IntoId: Into { +pub trait IntoId: InternalIntoEntity +where + Self: Sized, +{ /// # Safety /// This is used to determine if the type is a pair or not. /// not if the underlying id represents a pair. /// This should generally not be used by the user. const IS_PAIR: bool; + const IS_ENUM: bool; + const IS_TYPE_TAG: bool; + const IS_TYPED_REF: bool; + const IS_TYPED_MUT_REF: bool; + + #[doc(hidden)] // not meant to be used by the user + #[inline] + fn into_id<'a>(self, _world: impl WorldProvider<'a>) -> Id { + Id(0) + } /// This will return the id of the first part of a pair. /// If this is called on a non_pair, it will return the same as get_id. #[doc(hidden)] // not meant to be used by the user #[inline] - fn get_id_first(&self) -> Entity { + fn get_id_first<'a>(self, _world: impl WorldProvider<'a>) -> Entity { Entity(0) } @@ -23,71 +35,222 @@ pub trait IntoId: Into { /// If this is called on a non_pair, it will return the same as get_id. #[doc(hidden)] #[inline] - fn get_id_second(&self) -> Entity { + fn get_id_second<'a>(self, _world: impl WorldProvider<'a>) -> Entity { Entity::new(0) } } -impl From<(T, U)> for Id -where - T: Into, - U: Into, -{ - fn from(pair: (T, U)) -> Self { - ecs_pair(*pair.0.into(), *pair.1.into()).into() - } -} - -impl IntoId for (T, U) -where - T: Into + Copy, - U: Into + Copy, -{ - const IS_PAIR: bool = true; +impl IntoId for T { + const IS_PAIR: bool = T::IS_TYPED_PAIR; + const IS_ENUM: bool = ::IS_ENUM; + const IS_TYPE_TAG: bool = ::IS_TYPE_TAG; + const IS_TYPED_REF: bool = ::IS_TYPED_REF; + const IS_TYPED_MUT_REF: bool = ::IS_TYPED_MUT_REF; #[doc(hidden)] // not meant to be used by the user #[inline] - fn get_id_first(&self) -> Entity { - self.0.into() + fn into_id<'a>(self, world: impl WorldProvider<'a>) -> Id { + Id(*(self.into_entity(world))) } #[doc(hidden)] // not meant to be used by the user #[inline] - fn get_id_second(&self) -> Entity { - self.1.into() + fn get_id_first<'a>(self, world: impl WorldProvider<'a>) -> Entity { + let world = world.world(); + ecs_first(self.into_entity(world), world) + } + fn get_id_second<'a>(self, world: impl WorldProvider<'a>) -> Entity { + let world = world.world(); + ecs_second(self.into_entity(world), world) } } -// // We can not implement for T where T : `Into`, because it would essentially extend the trait, which we don't want -// // so we have to implement for each type that implements `Into` separately. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum AccessMode { + None, + Read, + Write, + ReadWrite, +} -impl IntoId for sys::ecs_id_t { - const IS_PAIR: bool = false; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum AccessSingleTarget { + /// A single `Entity` + Entity(Entity), + /// A single name + Name(&'static str), } -impl IntoId for Entity { - const IS_PAIR: bool = false; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum AccessTarget { + /// A single `Entity` + Entity(Entity), + /// A single name + Name(&'static str), + /// Two Entities + Pair(Entity, Entity), + /// Two names + PairName(&'static str, &'static str), + /// Name + Entity + PairNameEntity(&'static str, Entity), + /// Entity + Name + PairEntityName(Entity, &'static str), } -impl IntoId for Id { - const IS_PAIR: bool = false; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Access { + pub mode: AccessMode, + pub target: AccessTarget, } -impl IntoId for IdView<'_> { - const IS_PAIR: bool = false; +impl From for Id { + fn from(access: Access) -> Id { + match access.target { + AccessTarget::Entity(entity) => entity.into(), + AccessTarget::Pair(first, second) => Id(ecs_pair(*first, *second)), + _ => panic!("AccessTarget {:?} not convertible to Id", access.target), + } + } } -impl IntoId for EntityView<'_> { - const IS_PAIR: bool = false; +pub trait FromAccessArg { + fn from_access_arg<'a>(value: T, world: impl WorldProvider<'a>) -> Access; } -impl IntoId for Component<'_, T> +/// “Only single‐target inputs” (Entity, &str, `Id`, …) +pub trait SingleAccessArg: Sized where - T: ComponentId, + Access: FromAccessArg, { - const IS_PAIR: bool = false; } -impl IntoId for UntypedComponent<'_> { - const IS_PAIR: bool = false; +/// for single or pair inputs +pub trait AccessArg: Sized +where + Access: FromAccessArg, +{ +} + +impl SingleAccessArg for &'static str {} +impl SingleAccessArg for T where Access: FromAccessArg {} + +impl AccessArg for &'static str {} +impl AccessArg for T where Access: FromAccessArg {} +impl AccessArg for (&'static str, &'static str) {} +impl AccessArg for (&'static str, T) {} +impl AccessArg for (T, &'static str) {} + +impl FromAccessArg<&crate::core::utility::id::Id> for Access { + fn from_access_arg<'a>( + id: &crate::core::utility::id::Id, + world: impl WorldProvider<'a>, + ) -> Access { + let entity = IntoId::into_id(*id, world); + Access { + mode: AccessMode::Read, + target: AccessTarget::Entity(Entity(*entity)), + } + } +} + +impl FromAccessArg<&mut crate::core::utility::id::Id> for Access { + fn from_access_arg<'a>( + id: &mut crate::core::utility::id::Id, + world: impl WorldProvider<'a>, + ) -> Access { + let entity = IntoId::into_id(*id, world); + Access { + mode: AccessMode::ReadWrite, + target: AccessTarget::Entity(Entity(*entity)), + } + } +} + +impl FromAccessArg<&'static str> for Access { + fn from_access_arg<'a>(name: &'static str, _world: impl WorldProvider<'a>) -> Access { + Access { + mode: AccessMode::Read, + target: AccessTarget::Name(name), + } + } +} + +impl FromAccessArg<(&'static str, &'static str)> for Access { + fn from_access_arg<'a>( + names: (&'static str, &'static str), + _world: impl WorldProvider<'a>, + ) -> Access { + Access { + mode: AccessMode::Read, + target: AccessTarget::PairName(names.0, names.1), + } + } +} + +impl FromAccessArg<(&'static str, T)> for Access +where + T: IntoId, +{ + fn from_access_arg<'a>(names: (&'static str, T), world: impl WorldProvider<'a>) -> Access { + let id = names.1.into_id(world); + Access { + mode: AccessMode::Read, + target: AccessTarget::PairNameEntity(names.0, Entity(*id)), + } + } +} + +impl FromAccessArg<(T, &'static str)> for Access +where + T: IntoId, +{ + fn from_access_arg<'a>(names: (T, &'static str), world: impl WorldProvider<'a>) -> Access { + let id = names.0.into_id(world); + Access { + mode: AccessMode::Read, + target: AccessTarget::PairEntityName(Entity(*id), names.1), + } + } +} + +impl FromAccessArg for Access { + fn from_access_arg<'a>(id: T, world: impl WorldProvider<'a>) -> Access { + let world = world.world(); + let id = id.into_id(world); + if T::IS_PAIR { + let first = id.get_id_first(world); + let second = id.get_id_second(world); + if ::IS_TYPED_REF { + Access { + mode: AccessMode::Read, + target: AccessTarget::Pair(first, second), + } + } else if ::IS_TYPED_MUT_REF { + Access { + mode: AccessMode::ReadWrite, + target: AccessTarget::Pair(first, second), + } + } else { + Access { + mode: AccessMode::None, + target: AccessTarget::Pair(first, second), + } + } + } else if ::IS_TYPED_REF { + Access { + mode: AccessMode::Read, + target: AccessTarget::Entity(Entity(*id)), + } + } else if ::IS_TYPED_MUT_REF { + Access { + mode: AccessMode::ReadWrite, + target: AccessTarget::Entity(Entity(*id)), + } + } else { + Access { + mode: AccessMode::None, + target: AccessTarget::Entity(Entity(*id)), + } + } + } } diff --git a/flecs_ecs/src/core/utility/traits/mod.rs b/flecs_ecs/src/core/utility/traits/mod.rs index c0130535..e35b56a0 100644 --- a/flecs_ecs/src/core/utility/traits/mod.rs +++ b/flecs_ecs/src/core/utility/traits/mod.rs @@ -1,6 +1,7 @@ mod id_operations; mod inout_oper; mod into_component_id; +mod into_entity; mod into_id; mod into_table; mod query_api; @@ -10,6 +11,7 @@ mod world_provider; pub use id_operations::*; pub use inout_oper::*; pub use into_component_id::*; +pub use into_entity::*; pub use into_id::*; pub use into_table::*; pub use query_api::*; @@ -70,7 +72,6 @@ pub mod private { /// * `iter` - The iterator which gets passed in from `C` /// /// # See also - /// unsafe extern "C-unwind" fn execute_each( iter: *mut sys::ecs_iter_t, ) where @@ -120,7 +121,6 @@ pub mod private { /// * `iter` - The iterator which gets passed in from `C` /// /// # See also - /// unsafe extern "C-unwind" fn execute_each_entity( iter: *mut sys::ecs_iter_t, ) where @@ -182,7 +182,6 @@ pub mod private { /// * `iter` - The iterator which gets passed in from `C` /// /// # See also - /// unsafe extern "C-unwind" fn execute_each_iter(iter: *mut sys::ecs_iter_t) where Func: FnMut(TableIter, usize, T::TupleType<'_>), @@ -227,7 +226,6 @@ pub mod private { /// * `iter` - The iterator which gets passed in from `C` /// /// # See also - /// unsafe extern "C-unwind" fn execute_run(iter: *mut sys::ecs_iter_t) where Func: FnMut(TableIter), diff --git a/flecs_ecs/src/core/utility/traits/query_api.rs b/flecs_ecs/src/core/utility/traits/query_api.rs index 46c59359..7456f970 100644 --- a/flecs_ecs/src/core/utility/traits/query_api.rs +++ b/flecs_ecs/src/core/utility/traits/query_api.rs @@ -168,14 +168,14 @@ where /// world /// .entity_named("adam") /// .set(Position { x: 10, y: 20 }) - /// .add_first::(eva); + /// .add((id::(), eva)); /// /// world /// .query::<&Position>() - /// .with::<(Likes, flecs::Wildcard)>() + /// .with((id::(), id::())) /// .build() /// .each_iter(|it, index, p| { - /// let e = it.entity(index); + /// let e = it.entity(index).unwrap(); /// println!("{:?}: {:?} - {:?}", e.name(), p, it.id(1).to_str()); /// }); /// @@ -380,13 +380,13 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// /// let query = world.new_query::<(&Tag, &Position)>(); /// @@ -400,7 +400,7 @@ where /// let pos = it.field::<&Position>(1).unwrap(); //at index 1 in (&Tag, &Position) /// for i in it.iter() { /// count_entities += 1; - /// let entity = it.entity(i); + /// let entity = it.entity(i).unwrap(); /// println!("{:?}: {:?}", entity, pos[i]); /// } /// } @@ -474,15 +474,15 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// - /// let query = world.query::<(&Position)>().with::().build(); + /// let query = world.query::<(&Position)>().with(id::()).build(); /// /// let mut count_tables = 0; /// let mut count_entities = 0; @@ -562,15 +562,15 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// - /// let query = world.query::<(&Position)>().with::().build(); + /// let query = world.query::<(&Position)>().with(id::()).build(); /// /// let mut count_tables = 0; /// let mut count_entities = 0; @@ -1095,20 +1095,9 @@ where /// # Arguments /// /// * `group_id`: the group id to set - fn set_group_id(&self, group_id: impl Into) -> QueryIter { + fn set_group(&self, group_id: impl IntoEntity) -> QueryIter { let mut iter = self.iterable(); - QueryIter::::set_group_id(&mut iter, group_id); - iter - } - - /// Limit results to tables with specified group id (grouped queries only) - /// - /// # Type parameters - /// - /// * `Group`: the group to set - fn set_group(&self) -> QueryIter { - let mut iter = self.iterable(); - QueryIter::::set_group::(&mut iter); + QueryIter::::set_group(&mut iter, group_id); iter } diff --git a/flecs_ecs/src/core/utility/traits/system_api.rs b/flecs_ecs/src/core/utility/traits/system_api.rs index 9dc4881c..d0b7845a 100644 --- a/flecs_ecs/src/core/utility/traits/system_api.rs +++ b/flecs_ecs/src/core/utility/traits/system_api.rs @@ -87,13 +87,13 @@ where /// world /// .entity_named("adam") /// .set(Position { x: 10, y: 20 }) - /// .add_first::(eva); + /// .add((id::(), eva)); /// /// world /// .system::<&Position>() - /// .with::<(Likes, flecs::Wildcard)>() + /// .with((id::(), id::())) /// .each_iter(|it, index, p| { - /// let e = it.entity(index); + /// let e = it.entity(index).unwrap(); /// println!("{:?}: {:?} - {:?}", e.name(), p, it.id(1).to_str()); /// }) /// .run(); @@ -158,13 +158,13 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// /// let count_entities = Rc::new(RefCell::new(0)); /// let count_tables = Rc::new(RefCell::new(0)); @@ -179,7 +179,7 @@ where /// let pos = it.field::<&Position>(1).unwrap(); //at index 1 in (&Tag, &Position) /// for i in it.iter() { /// *count_entities_ref.borrow_mut() += 1; - /// let entity = it.entity(i); + /// let entity = it.entity(i).unwrap(); /// println!("{:?}: {:?}", entity, pos[i]); /// } /// } @@ -248,13 +248,13 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// /// /// @@ -264,7 +264,7 @@ where /// let count_entities_ref = count_entities.clone(); /// let count_tables_ref = count_tables.clone(); /// - /// let system = world.system::<(&Position)>().with::() + /// let system = world.system::<(&Position)>().with(id::()) /// .run_each( /// move |mut it| { /// println!("start operations"); @@ -358,13 +358,13 @@ where /// /// let world = World::new(); /// - /// world.entity().add::().add::(); - /// world.entity().add::().add::(); + /// world.entity().add(id::()).add(id::()); + /// world.entity().add(id::()).add(id::()); /// world /// .entity() - /// .add::() - /// .add::() - /// .add::(); + /// .add(id::()) + /// .add(id::()) + /// .add(id::()); /// /// /// @@ -374,7 +374,7 @@ where /// let count_entities_ref = count_entities.clone(); /// let count_tables_ref = count_tables.clone(); /// - /// let system = world.system::<(&Position)>().with::() + /// let system = world.system::<(&Position)>().with(id::()) /// .run_each_entity( /// move |mut it| { /// println!("start operations"); diff --git a/flecs_ecs/src/core/utility/traits/world_provider.rs b/flecs_ecs/src/core/utility/traits/world_provider.rs index c9955163..c8294077 100644 --- a/flecs_ecs/src/core/utility/traits/world_provider.rs +++ b/flecs_ecs/src/core/utility/traits/world_provider.rs @@ -20,6 +20,13 @@ pub trait WorldProvider<'a> { fn world(&self) -> WorldRef<'a>; } +impl<'a> WorldProvider<'a> for *mut sys::ecs_world_t { + #[inline(always)] + fn world(&self) -> WorldRef<'a> { + unsafe { WorldRef::from_ptr(*self) } + } +} + impl<'a> WorldProvider<'a> for IdView<'a> { #[inline(always)] fn world(&self) -> WorldRef<'a> { diff --git a/flecs_ecs/src/core/world.rs b/flecs_ecs/src/core/world.rs index 31d62780..bb7d4a2c 100644 --- a/flecs_ecs/src/core/world.rs +++ b/flecs_ecs/src/core/world.rs @@ -425,7 +425,7 @@ impl World { /// /// world.readonly_begin(false); /// - /// assert_eq!(stage.count::(), 0); + /// assert_eq!(stage.count(id::()), 0); /// /// world.readonly_end(); /// @@ -434,11 +434,11 @@ impl World { /// stage.entity().set(Position { x: 10, y: 20 }); /// stage.entity().set(Position { x: 10, y: 20 }); /// - /// assert_eq!(stage.count::(), 0); + /// assert_eq!(stage.count(id::()), 0); /// /// world.readonly_end(); /// - /// assert_eq!(stage.count::(), 2); + /// assert_eq!(stage.count(id::()), 2); /// ``` /// /// # See also @@ -540,11 +540,11 @@ impl World { /// /// let e = world.entity().set(Position { x: 10, y: 20 }); /// - /// assert!(!e.has::()); + /// assert!(!e.has(id::())); /// /// world.defer_end(); /// - /// assert!(e.has::()); + /// assert!(e.has(id::())); /// ``` /// /// # See also @@ -886,11 +886,11 @@ impl World { /// /// e.mut_current_stage(stage).set(Position { x: 10, y: 20 }); /// - /// assert!(!e.has::()); + /// assert!(!e.has(id::())); /// /// stage.merge(); /// - /// assert!(e.has::()); + /// assert!(e.has(id::())); /// ``` /// /// # See also @@ -992,14 +992,12 @@ impl World { /// /// e.mut_current_stage(stage).set(Position { x: 10, y: 20 }); /// - /// assert!(!e.has::()); + /// assert!(!e.has(id::())); /// /// stage.merge(); /// - /// assert!(e.has::()); + /// assert!(e.has(id::())); /// ``` - /// # See also - /// pub fn create_async_stage(&self) -> WorldRef { unsafe { WorldRef::from_ptr(sys::ecs_stage_new(self.raw_world.as_ptr())) } } @@ -1218,7 +1216,7 @@ impl World { /// world.set_entity_range(5000, 0); /// world.enable_range_check(true); /// - /// e.add_id(e2); // panics in debug mode! because e and e2 are outside the range + /// e.add(e2); // panics in debug mode! because e and e2 are outside the range /// panic!("in release mode, this does not panic, this is to prevent the test from failing") /// ``` /// @@ -1246,7 +1244,7 @@ impl World { /// /// let e = world.entity_named("scope"); /// - /// world.set_scope_id(e); + /// world.set_scope(e); /// /// let s = world.get_scope(); /// @@ -1256,7 +1254,6 @@ impl World { /// # See also /// /// * [`World::set_scope()`] - /// * [`World::set_scope_id()`] #[inline(always)] pub fn get_scope(&self) -> Option { let scope = unsafe { sys::ecs_get_scope(self.raw_world.as_ptr()) }; @@ -1292,7 +1289,7 @@ impl World { /// let e = world.entity_named("scope"); /// /// // previous scope can be used to set the scope back to the original. - /// let previous_scope = world.set_scope_id(e); + /// let previous_scope = world.set_scope(e); /// /// let s = world.get_scope(); /// @@ -1304,52 +1301,12 @@ impl World { /// * [`World::get_scope()`] /// * [`World::set_scope()`] #[inline(always)] - pub fn set_scope_id(&self, id: impl IntoId) -> EntityView { + pub fn set_scope(&self, id: impl IntoId) -> EntityView { EntityView::new_from(self, unsafe { - sys::ecs_set_scope(self.raw_world.as_ptr(), *id.into()) + sys::ecs_set_scope(self.raw_world.as_ptr(), *id.into_id(self)) }) } - /// Sets the current scope, but allows the scope type to be inferred from the type parameter. - /// This operation sets the scope of the current stage to the provided entity. - /// As a result new entities will be created in this scope, and lookups will be relative to the provided scope. - /// It is considered good practice to restore the scope to the old value. - /// - /// # Type Parameters - /// - /// * `T` - The type that implements `ComponentId`. - /// - /// # Returns - /// - /// Returns an `EntityView` representing the previous set scope. - /// - /// # Example - /// - /// ``` - /// use flecs_ecs::prelude::*; - /// - /// #[derive(Component)] - /// struct Scope; - /// - /// let world = World::new(); - /// - /// // previous scope can be used to set the scope back to the original. - /// let previous_scope = world.set_scope::(); - /// - /// let s = world.get_scope(); - /// - /// assert_eq!(s.unwrap(), world.component_id::()); - /// ``` - /// - /// # See also - /// - /// * [`World::get_scope()`] - /// * [`World::set_scope_id()`] - #[inline(always)] - pub fn set_scope(&self) -> EntityView { - self.set_scope_id(T::id(self)) - } - /// Sets the search path for entity lookup operations. /// /// This function configures the search path used for looking up an entity. @@ -1425,7 +1382,7 @@ impl World { /// }); /// /// let x = world.lookup_recursive("X"); - /// assert!(x.has_id(a)); + /// assert!(x.has(a)); /// ``` /// /// # See also @@ -1606,27 +1563,9 @@ impl World { /// * [`EntityView::modified()`] /// * [`World::modified()`] #[inline(always)] - pub fn modified_id(&self, id: impl Into) { + pub fn modified(&self, id: impl Into) { let id = id.into(); - EntityView::new_from(self, id).modified_id(id); - } - - /// Signal that singleton component was modified. - /// - /// # Type Parameters - /// - /// * `T` - The type of the component that was modified. - /// - /// # See also - /// - /// * [`EntityView::modified()`] - /// * [`World::modified_id()`] - #[inline(always)] - pub fn modified(&self) - where - T: ComponentId, - { - self.modified_id(T::id(self)); + EntityView::new_from(self, id).modified(id); } /// set the version of the provided entity. @@ -1877,7 +1816,6 @@ impl World { /// Returns: The reference singleton component. /// /// # See also - /// // #[doc(alias = "world::get_ref")] // #[inline(always)] pub fn get_ref(&self) -> CachedRef @@ -1902,33 +1840,6 @@ impl World { EntityView::new_from(self, T::id(self)) } - /// Gets the target for a given pair from a singleton entity. - /// - /// This operation returns the target for a given pair. The optional - /// `index` can be used to iterate through targets, in case the entity has - /// multiple instances for the same relationship. - /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// - /// # Arguments - /// - /// * `index` - The index (None for the first instance of the relationship). - /// - /// # See also - /// - /// * [`World::target_id()`] - pub fn target(&self, index: Option) -> EntityView - where - First: ComponentId, - { - let id = First::id(self); - EntityView::new_from(self, unsafe { - sys::ecs_get_target(self.raw_world.as_ptr(), id, id, index.unwrap_or(0)) - }) - } - /// Retrieves the target for a given pair from a singleton entity. /// /// This operation fetches the target associated with a specific pair. An optional @@ -1943,8 +1854,8 @@ impl World { /// # See also /// /// * [`World::target()`] - pub fn target_id(&self, relationship: impl Into, index: Option) -> EntityView { - let relationship = *relationship.into(); + pub fn target(&self, relationship: impl IntoEntity, index: Option) -> EntityView { + let relationship = *relationship.into_entity(self); EntityView::new_from(self, unsafe { sys::ecs_get_target( self.raw_world.as_ptr(), @@ -1970,31 +1881,14 @@ impl World { /// * [`World::has()`] /// * [`World::has_enum()`] #[inline(always)] - pub fn has_id(&self, id: impl IntoId) -> bool { - let id = *id.into(); - EntityView::new_from(self, id).has_id(id) - } - - /// Check if world has the provided type (enum,pair,struct). - /// - /// # Type Parameters - /// - /// * `T` - The type to check. - /// - /// # Returns - /// - /// True if the world has the provided type, false otherwise. - /// - /// # See also - /// - /// * [`World::has_enum()`] - /// * [`World::has_id()`] - #[inline(always)] - pub fn has(&self) -> bool - where - T: ComponentOrPairId, - { - EntityView::new_from(self, T::get_id(self)).has::() + pub fn has(&self, id: T) -> bool { + let id = *id.into_id(self); + if T::IS_PAIR { + let first_id = id.get_id_first(self); + EntityView::new_from(self, first_id).has(id) + } else { + EntityView::new_from(self, id).has(id) + } } /// Check if world has the provided enum constant. @@ -2014,14 +1908,13 @@ impl World { /// # See also /// /// * [`World::has()`] - /// * [`World::has_id()`] #[inline(always)] pub fn has_enum(&self, constant: T) -> bool where T: ComponentId + ComponentType + EnumComponentInfo, { let id = T::id(self); - EntityView::new_from(self, id).has_enum_id::(id, constant) + EntityView::new_from(self, id).has_enum(id, constant) } /// Add a singleton component by id. @@ -2035,35 +1928,17 @@ impl World { /// /// `EntityView` handle to the singleton component. #[inline(always)] - pub fn add_id(&self, id: T) -> EntityView - where - T: IntoId, - { - let id = *id.into(); + pub fn add(&self, id: T) -> EntityView { + let id = *id.into_id(self); // this branch will compile out in release mode if T::IS_PAIR { - let first_id = id.get_id_first(); - EntityView::new_from(self, first_id).add_id(id) + let first_id = id.get_id_first(self); + EntityView::new_from(self, first_id).add(id) } else { - EntityView::new_from(self, id).add_id(id) + EntityView::new_from(self, id).add(id) } } - /// Add a singleton component. - /// - /// # Type Parameters - /// - /// * `T` - The component to add. - /// - /// # Returns - /// - /// `EntityView` handle to the singleton component. - #[inline(always)] - pub fn add(&self) -> EntityView { - let id = T::CastType::id(self); - EntityView::new_from(self, id).add::() - } - /// Add a singleton enum component. /// /// # Type Parameters @@ -2081,40 +1956,6 @@ impl World { EntityView::new_from(self, T::id(self)).add_enum::(enum_value) } - /// Add a singleton pair by first id. - /// - /// # Safety - /// - /// Caller must ensure the id is a non ZST types. Otherwise it could cause the payload to have uninitialized data. - /// - /// # Returns - /// - /// `EntityView` handle to the singleton pair. - #[inline(always)] - pub fn add_second( - &self, - first: impl Into, - ) -> EntityView { - EntityView::new_from(self, Second::id(self)).add_second::(first) - } - - /// Add a singleton pair by second id. - /// - /// # Safety - /// - /// Caller must ensure the id is a non ZST types. Otherwise it could cause the payload to have uninitialized data. - /// - /// # Returns - /// - /// `EntityView` handle to the singleton pair. - #[inline(always)] - pub fn add_first( - &self, - second: impl Into, - ) -> EntityView { - EntityView::new_from(self, First::id(self)).add_first::(second) - } - /// Add a singleton pair with enum tag. /// /// # Type Parameters @@ -2144,31 +1985,13 @@ impl World { /// # Arguments /// /// * `id`: The id of the component to remove. - pub fn remove_id(&self, id: T) -> EntityView - where - T: IntoId, - { - let id = *id.into(); + pub fn remove(&self, id: T) -> EntityView { + let id = *id.into_id(self); if T::IS_PAIR { - let first_id = id.get_id_first(); - EntityView::new_from(self, first_id).remove_id(id) + let first_id = id.get_id_first(self); + EntityView::new_from(self, first_id).remove(id) } else { - EntityView::new_from(self, id).remove_id(id) - } - } - - /// Remove singleton component. - /// - /// # Type Parameters - /// - /// * `T` - The component to remove. - #[inline(always)] - pub fn remove(&self) { - if T::IS_PAIR { - let first_id = ::id(self); - EntityView::new_from(self, first_id).remove::(); - } else { - EntityView::new_from(self, T::get_id(self)).remove::(); + EntityView::new_from(self, id).remove(id) } } @@ -2191,34 +2014,6 @@ impl World { EntityView::new_from(self, First::id(self)).remove_enum_tag::(enum_value); } - /// Remove singleton pair by first id. - /// - /// # Type Parameters - /// - /// * `Second` - The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first element of the pair. - #[inline(always)] - pub fn remove_second(&self, first: impl Into) { - EntityView::new_from(self, Second::id(self)).remove_second::(first); - } - - /// Remove singleton pair by second id. - /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second element of the pair. - #[inline(always)] - pub fn remove_first(&self, second: impl Into) { - EntityView::new_from(self, First::id(self)).remove_first::(second); - } - /// Iterate entities in root of world /// /// # Arguments @@ -2326,55 +2121,8 @@ impl World { /// # Returns /// /// The number of entities with the provided id. - pub fn count_id(&self, id: impl IntoId) -> i32 { - unsafe { sys::ecs_count_id(self.raw_world.as_ptr(), *id.into()) } - } - - /// Count entities with the provided component. - /// - /// # Type Parameters - /// - /// * `T` - The component to count. - /// - /// # Returns - /// - /// The number of entities with the provided component. - pub fn count(&self) -> i32 { - self.count_id(T::get_id(self)) - } - - /// Count entities with the provided pair. - /// - /// # Type Parameters - /// - /// * `Second` - The second element of the pair. - /// - /// # Arguments - /// - /// * `first` - The ID of the first element of the pair. - /// - /// # Returns - /// - /// The number of entities with the provided pair. - pub fn count_second(&self, first: impl Into) -> i32 { - self.count_id((first.into(), Second::id(self))) - } - - /// Count entities with the provided pair. - /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// - /// # Arguments - /// - /// * `second` - The ID of the second element of the pair. - /// - /// # Returns - /// - /// The number of entities with the provided pair. - pub fn count_first(&self, second: impl Into) -> i32 { - self.count_id((First::id(self), second.into())) + pub fn count(&self, id: impl IntoId) -> i32 { + unsafe { sys::ecs_count_id(self.raw_world.as_ptr(), *id.into_id(self)) } } /// Count entities with the provided enum constant. @@ -2431,29 +2179,16 @@ impl World { /// /// * `parent_id` - The id of the scope to use. /// * `func` - The function to run. - pub fn run_in_scope_with_id(&self, parent_id: impl Into, mut func: impl FnMut()) { + pub fn run_in_scope_with(&self, parent_id: impl IntoEntity, mut func: impl FnMut()) { + let world = self.world(); let prev: sys::ecs_id_t = - unsafe { sys::ecs_set_scope(self.raw_world.as_ptr(), *parent_id.into()) }; + unsafe { sys::ecs_set_scope(self.raw_world.as_ptr(), *parent_id.into_entity(world)) }; func(); unsafe { sys::ecs_set_scope(self.raw_world.as_ptr(), prev); } } - /// All entities created in function are created in scope. All operations - /// called in function (such as lookup) are relative to scope. - /// - /// # Type Parameters - /// - /// * `T` - The component type to use as scope / parent. - /// - /// # Arguments - /// - /// * `func` - The function to run. - pub fn run_in_scope_with(&self, func: impl FnMut()) { - self.run_in_scope_with_id(T::id(self), func); - } - /// Use provided scope for operations ran on returned world. /// Operations need to be ran in a single statement /// @@ -2464,26 +2199,10 @@ impl World { /// # Returns /// /// A scoped world. - pub fn scope_id(&self, parent_id: impl IntoId, mut f: impl FnMut(&World)) { - let previous_scope = self.set_scope_id(parent_id); + pub fn scope(&self, parent_id: impl IntoId, mut f: impl FnMut(&World)) { + let previous_scope = self.set_scope(parent_id); f(self); - self.set_scope_id(previous_scope); - } - - /// Use provided scope for operations ran on returned world. - /// Operations need to be ran in a single statement - /// - /// # Type Parameters - /// - /// * `T` - The component type to use as scope. - /// - /// # Returns - /// - /// A scoped world. - pub fn scope(&self, mut f: impl FnMut(&World)) { - let previous_scope = self.set_scope_id(T::id(self)); - f(self); - self.set_scope_id(previous_scope); + self.set_scope(previous_scope); } /// Use provided scope of name for operations ran on returned world. @@ -2497,7 +2216,7 @@ impl World { /// /// A scoped world. pub fn scope_name(&self, name: &str, f: impl FnMut(&World)) { - self.scope_id(EntityView::new_named(self, name).id, f); + self.scope(EntityView::new_named(self, name).id, f); } /// all entities created in function are created with id @@ -2506,55 +2225,15 @@ impl World { /// /// * `id`: The id to create entities with. /// * `func`: The function to run. - pub fn with_id(&self, id: impl IntoId, mut func: impl FnMut()) { - let prev: sys::ecs_id_t = unsafe { sys::ecs_set_with(self.raw_world.as_ptr(), *id.into()) }; + pub fn with(&self, id: impl IntoId, mut func: impl FnMut()) { + let prev: sys::ecs_id_t = + unsafe { sys::ecs_set_with(self.raw_world.as_ptr(), *id.into_id(self)) }; func(); unsafe { sys::ecs_set_with(self.raw_world.as_ptr(), prev); } } - /// Entities created in function are created with component - /// - /// # Type Parameters - /// - /// * `T`: The component type. - /// - /// # Arguments - /// - /// * `func`: The function to run. - pub fn with(&self, func: impl FnMut()) { - self.with_id(T::get_id(self), func); - } - - /// Entities created in function are created with pair - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first element of the pair. - /// * `func`: The function to run. - pub fn with_second(&self, first: impl Into, func: impl FnMut()) { - self.with_id(ecs_pair(*first.into(), Second::id(self)), func); - } - - /// Entities created in function are created with pair - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second element of the pair. - /// * `func`: The function to run. - pub fn with_first(&self, second: impl Into, func: impl FnMut()) { - self.with_id(ecs_pair(First::id(self), *second.into()), func); - } - /// Entities created in function are created with enum constant /// /// # Type Parameters @@ -2569,7 +2248,7 @@ impl World { where T: ComponentId + ComponentType + EnumComponentInfo, { - self.with_id(enum_value.id_variant(self), func); + self.with(enum_value.id_variant(self), func); } /// Entities created in function are created with enum tag pair @@ -2588,7 +2267,7 @@ impl World { First: ComponentId, Second: ComponentId + ComponentType + EnumComponentInfo, { - self.with_id( + self.with( ecs_pair(First::id(self), **(enum_value.id_variant(self))), func, ); @@ -2599,47 +2278,12 @@ impl World { /// # Arguments /// /// * `id`: The id to delete. - pub fn delete_entities_with_id(&self, id: impl IntoId) { + pub fn delete_entities_with(&self, id: impl IntoId) { unsafe { - sys::ecs_delete_with(self.raw_world.as_ptr(), *id.into()); + sys::ecs_delete_with(self.raw_world.as_ptr(), *id.into_id(self)); } } - /// Delete all entities with the given component - /// - /// # Type Parameters - /// - /// * `T`: The component type to delete. - pub fn delete_entities_with(&self) { - self.delete_entities_with_id(T::get_id(self)); - } - - /// Delete all entities with the given pair - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first id of the pair. - pub fn delete_entities_with_second(&self, first: impl Into) { - self.delete_entities_with_id(ecs_pair(*first.into(), Second::id(self))); - } - - /// Delete all entities with the given pair - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second id of the pair. - pub fn delete_entities_with_first(&self, second: impl Into) { - self.delete_entities_with_id(ecs_pair(First::id(self), *second.into())); - } - /// Delete all entities with the given enum constant /// /// # Type Parameters @@ -2653,7 +2297,7 @@ impl World { &self, enum_value: T, ) { - self.delete_entities_with_id(enum_value.id_variant(self)); + self.delete_entities_with(enum_value.id_variant(self)); } /// Delete all entities with the given enum tag pair / relationship @@ -2675,7 +2319,7 @@ impl World { First: ComponentId, Second: ComponentId + ComponentType + EnumComponentInfo, { - self.delete_entities_with_id(ecs_pair(First::id(self), **enum_value.id_variant(self))); + self.delete_entities_with(ecs_pair(First::id(self), **enum_value.id_variant(self))); } /// Remove all instances of the given id from entities @@ -2683,47 +2327,12 @@ impl World { /// # Arguments /// /// * `id`: The id to remove. - pub fn remove_all_id(&self, id: impl IntoId) { + pub fn remove_all(&self, id: impl IntoId) { unsafe { - sys::ecs_remove_all(self.raw_world.as_ptr(), *id.into()); + sys::ecs_remove_all(self.raw_world.as_ptr(), *id.into_id(self)); } } - /// Remove all instances of the given component from entities - /// - /// # Type Parameters - /// - /// * `T`: The component type to remove. - pub fn remove_all(&self) { - self.remove_all_id(T::get_id(self)); - } - - /// Remove all instances of the given pair from entities - /// - /// # Type Parameters - /// - /// * `Second`: The second element of the pair. - /// - /// # Arguments - /// - /// * `first`: The first id of the pair. - pub fn remove_all_second(&self, first: impl Into) { - self.remove_all_id((first.into(), Second::id(self))); - } - - /// Remove all instances of the given pair from entities - /// - /// # Type Parameters - /// - /// * `First`: The first element of the pair. - /// - /// # Arguments - /// - /// * `second`: The second id of the pair. - pub fn remove_all_first(&self, second: impl Into) { - self.remove_all_id((First::id(self), second.into())); - } - /// Remove all instances with the given enum constant from entities /// /// # Type Parameters @@ -2737,7 +2346,7 @@ impl World { &self, enum_value: T, ) { - self.remove_all_id(enum_value.id_variant(self)); + self.remove_all(enum_value.id_variant(self)); } /// Remove all instances with the given enum tag pair / relationship from entities @@ -2755,7 +2364,7 @@ impl World { First: ComponentId, Second: ComponentId + ComponentType + EnumComponentInfo, { - self.remove_all_id((First::id(self), enum_value.id_variant(self))); + self.remove_all((First::id(self), enum_value.id_variant(self))); } /// Checks if the given entity ID exists in the world. @@ -2976,7 +2585,7 @@ impl World { EntityView::new_null(self) } - /// Create a new entity with the provided id. + /// wraps an [`EntityView`] with the provided id. /// /// # Arguments /// @@ -2998,7 +2607,7 @@ impl World { /// * [`World::prefab_type_named()`] pub fn prefab(&self) -> EntityView { let result = EntityView::new(self); - result.add_id(flecs::Prefab::ID); + result.add(flecs::Prefab::ID); result } @@ -3019,7 +2628,7 @@ impl World { /// * [`World::prefab_type_named()`] pub fn prefab_named<'a>(&'a self, name: &str) -> EntityView<'a> { let result = EntityView::new_named(self, name); - result.add_id(ECS_PREFAB); + result.add(ECS_PREFAB); result } @@ -3040,7 +2649,7 @@ impl World { /// * [`World::prefab_type_named()`] pub fn prefab_type(&self) -> EntityView { let result = self.entity_from::(); - result.add_id(ECS_PREFAB); + result.add(ECS_PREFAB); result } @@ -3065,7 +2674,7 @@ impl World { /// * [`World::prefab_type()`] pub fn prefab_type_named<'a, T: ComponentId>(&'a self, name: &str) -> EntityView<'a> { let result = self.entity_from_named::(name); - result.add_id(ECS_PREFAB); + result.add(ECS_PREFAB); result } } @@ -3088,21 +2697,8 @@ impl World { } /// Get the id of the provided pair of components. - pub fn relationship_id(&self) -> Id { - Id(ecs_pair(First::id(self), Second::id(self))) - } - - /// Get the id view of component / pair - /// - /// # Type Parameters - /// - /// * `T` - The component type. - /// - /// # Returns - /// - /// The id of the component. - pub fn id_from(&self) -> IdView { - IdView::new_from_id(self, T::get_id(self)) + pub fn id_from(&self, id: T) -> Id { + Id(*id.into_id(self)) } /// get `IdView` from an id or from a relationship pair @@ -3114,16 +2710,13 @@ impl World { /// # Returns /// /// The `IdView` from the provided id. - pub fn id_from_id(&self, id: Id) -> IdView - where - Id: IntoId, - { - let id = *id.into(); + pub fn id_view_from(&self, id: Id) -> IdView { + let id = *id.into_id(self); if Id::IS_PAIR { ecs_assert!( { - let first = ecs_first(id); - let second = ecs_second(id); + let first = ecs_first(id, self); + let second = ecs_second(id, self); !ecs_is_pair(first) && !ecs_is_pair(second) }, FlecsErrorCode::InvalidParameter, @@ -3133,52 +2726,6 @@ impl World { IdView::new_from_id(self, id) } - - /// get pair id from relationship, object. - /// - /// # Type Parameters - /// - /// * `First` - The first element of the pair. - /// - /// # Arguments - /// - /// * `second` - The id of the second element of the pair. - /// - /// # Returns - /// - /// The pair as Id - pub fn id_first(&self, second: impl Into) -> IdView { - let id: Entity = second.into(); - ecs_assert!( - !ecs_is_pair(id), - FlecsErrorCode::InvalidParameter, - "cannot create nested pairs" - ); - IdView::new_from_id(self, (First::id(self), id)) - } - - /// get pair id from relationship, object. - /// - /// # Type Parameters - /// - /// * `Second` - The second element of the pair. - /// - /// # Arguments - /// - /// * `first` - The id of the first element of the pair. - /// - /// # Returns - /// - /// The pair as Id - pub fn id_second(&self, first: impl Into) -> IdView { - let id = first.into(); - ecs_assert!( - !ecs_is_pair(id), - FlecsErrorCode::InvalidParameter, - "cannot create nested pairs" - ); - IdView::new_from_id(self, (id, Second::id(self))) - } } /// Component mixin implementation @@ -3226,19 +2773,6 @@ impl World { UntypedComponent::new_named(self, name) } - /// Find or register untyped component. - /// - /// # Type Parameters - /// - /// * `T` - The component type. - /// - /// # Returns - /// - /// The found or registered untyped component. - pub fn component_untyped_from(&self) -> UntypedComponent { - UntypedComponent::new_from(self, T::id(self)) - } - /// Find or register untyped component. /// /// # Arguments @@ -3248,7 +2782,7 @@ impl World { /// # Returns /// /// The found or registered untyped component. - pub fn component_untyped_from_id(&self, id: impl Into) -> UntypedComponent { + pub fn component_untyped_from(&self, id: impl IntoEntity) -> UntypedComponent { UntypedComponent::new_from(self, id) } @@ -3376,7 +2910,7 @@ impl World { Components: QueryTuple, { let mut builder = ObserverBuilder::<(), Components>::new_untyped(self); - builder.add_event_id(event); + builder.add_event(event); builder } @@ -3728,29 +3262,10 @@ impl World { /// * [`World::get_pipeline()`] /// * [`World::set_pipeline()`] #[inline(always)] - pub fn set_pipeline_id(&self, pipeline: impl Into) { - unsafe { - sys::ecs_set_pipeline(self.raw_world.as_ptr(), *pipeline.into()); - } - } - - /// Set a custom pipeline by type. This operation sets the pipeline to run when [`World::progress()`] is invoked. - /// - /// # Type Parameters - /// - /// * `Pipeline` - The associated type to use for the pipeline. - /// - /// # See also - /// - /// * [`World::get_pipeline()`] - /// * [`World::set_pipeline_id()`] - #[inline(always)] - pub fn set_pipeline(&self) - where - Pipeline: ComponentType + ComponentId, - { + pub fn set_pipeline(&self, pipeline: impl IntoEntity) { + let world = self.world(); unsafe { - sys::ecs_set_pipeline(self.raw_world.as_ptr(), Pipeline::id(self)); + sys::ecs_set_pipeline(self.raw_world.as_ptr(), *pipeline.into_entity(world)); } } @@ -3763,7 +3278,7 @@ impl World { /// # See also /// /// * [`World::set_pipeline()`] - /// * [`World::set_pipeline_id()`] + /// * [`World::set_pipeline()`] #[inline(always)] pub fn get_pipeline(&self) -> EntityView { EntityView::new_from(self, unsafe { @@ -3826,7 +3341,7 @@ impl World { /// synchronization. /// /// Providing 0 for pipeline id runs the default pipeline (builtin or set via - /// `set_pipeline_id()`). Using [`World::progress()`] auto-invokes this for the + /// `set_pipeline()`). Using [`World::progress()`] auto-invokes this for the /// default pipeline. Additional pipelines may be run explicitly. /// /// # Note @@ -3840,11 +3355,10 @@ impl World { /// # See also /// /// * [`World::run_pipeline()`] - /// * [`World::run_pipeline_id_time()`] /// * [`World::run_pipeline_time()`] #[inline(always)] - pub fn run_pipeline_id(&self, pipeline: impl Into) { - Self::run_pipeline_id_time(self, pipeline, 0.0); + pub fn run_pipeline(&self, pipeline: impl IntoEntity) { + Self::run_pipeline_time(self, pipeline, 0.0); } /// Run pipeline. @@ -3853,7 +3367,7 @@ impl World { /// synchronization. /// /// Providing 0 for pipeline id runs the default pipeline (builtin or set via - /// `set_pipeline_id()`). Using [`World::progress()`] auto-invokes this for the + /// `set_pipeline()`). Using [`World::progress()`] auto-invokes this for the /// default pipeline. Additional pipelines may be run explicitly. /// /// # Note @@ -3868,77 +3382,19 @@ impl World { /// # See also /// /// * [`World::run_pipeline()`] - /// * [`World::run_pipeline_id()`] /// * [`World::run_pipeline_time()`] #[inline(always)] - pub fn run_pipeline_id_time(&self, pipeline: impl Into, delta_time: super::FTime) { + pub fn run_pipeline_time(&self, pipeline: impl IntoEntity, delta_time: super::FTime) { + let world = self.world(); unsafe { - sys::ecs_run_pipeline(self.raw_world.as_ptr(), *pipeline.into(), delta_time); - } - } - - /// Run pipeline. - /// Runs all systems in the specified pipeline. Can be invoked from multiple - /// threads if staging is disabled, managing staging and, if needed, thread - /// synchronization. - /// - /// Using [`World::progress()`] auto-invokes this for the default pipeline. - /// Additional pipelines may be run explicitly. - /// - /// # Note - /// - /// Only supports single-threaded applications with a single stage when called from an application. - /// - /// # Type Parameters - /// - /// * `Component` - The associated type to use for the pipeline. - /// - /// # Arguments - /// - /// * `delta_time` - Time to advance the world. - /// - /// # See also - /// - /// * [`World::run_pipeline()`] - /// * [`World::run_pipeline_id()`] - /// * [`World::run_pipeline_id_time()`] - pub fn run_pipeline_time(&self, delta_time: super::FTime) - where - Component: ComponentType + ComponentId, - { - unsafe { - sys::ecs_run_pipeline(self.raw_world.as_ptr(), Component::id(self), delta_time); + sys::ecs_run_pipeline( + self.raw_world.as_ptr(), + *pipeline.into_entity(world), + delta_time, + ); } } - /// Run pipeline. - /// Runs all systems in the specified pipeline. Can be invoked from multiple - /// threads if staging is disabled, managing staging and, if needed, thread - /// synchronization. - /// - /// Using [`World::progress()`] auto-invokes this for the default pipeline. - /// Additional pipelines may be run explicitly. - /// - /// # Note - /// - /// Only supports single-threaded applications with a single stage when called from an application. - /// - /// # Type Parameters - /// - /// * `Component` - The associated type to use for the pipeline. - /// - /// # See also - /// - /// * [`World::run_pipeline_id()`] - /// * [`World::run_pipeline_id_time()`] - /// * [`World::run_pipeline_time()`] - pub fn run_pipeline(&self) - where - Component: ComponentType + ComponentId, - { - Self::run_pipeline_time::(self, 0.0); - } - /// Set time scale. Increase or decrease simulation speed by the provided multiplier. /// /// # Arguments diff --git a/flecs_ecs/src/core/world_ctx.rs b/flecs_ecs/src/core/world_ctx.rs index 73c28817..7c44b647 100644 --- a/flecs_ecs/src/core/world_ctx.rs +++ b/flecs_ecs/src/core/world_ctx.rs @@ -88,7 +88,7 @@ fn query_ref_count() { struct Tag; let world = World::new(); - let query = world.query::<()>().with::<&Tag>().build(); + let query = world.query::<()>().with(id::()).build(); assert_eq!(world.world_ctx().query_ref_count(), 1); assert_eq!(query.reference_count(), 1); diff --git a/flecs_ecs/src/lib.rs b/flecs_ecs/src/lib.rs index 7cda88aa..8df094f0 100644 --- a/flecs_ecs/src/lib.rs +++ b/flecs_ecs/src/lib.rs @@ -44,3 +44,97 @@ pub mod prelude; fn register_test_crash_handler() { test_crash_handler::register(); } + +#[cfg(test)] +mod tests { + use super::*; + use flecs_ecs::prelude::*; + + #[derive(Debug, Component, Default)] + pub struct Position { + pub x: f32, + pub y: f32, + } + + impl World { + pub fn add_(&self, id: impl IntoEntity) -> EntityView { + let id = id.into_entity(self); + EntityView::new_from(self, id).add(id) + } + } + + fn take_copy(t: T) -> T { + t + } + + fn take_into_entity(t: T, world: &World) -> Entity { + t.into_entity(world) + } + + #[test] + fn test_add_op() { + #[derive(Debug, Component, Default)] + struct Position { + x: f32, + y: f32, + } + + #[derive(Debug, Component)] + struct Tag; + + let world = World::new(); + let e = world.entity(); + + // let e_pair = ecs_pair(e, e); + // // dbg!(check_add_id_validity(world.ptr_mut(), e)); + // // dbg!(check_add_id_validity(world.ptr_mut(), e_pair)); + // // dbg!(check_add_id_validity(world.ptr_mut(), p)); + // // dbg!(check_add_id_validity(world.ptr_mut(), t)); + // let p_t = ecs_pair(p, t); + // let t_p = ecs_pair(t, p); + // // dbg!(check_add_id_validity(world.ptr_mut(), p_t)); + // dbg!(check_add_id_validity(world.ptr_mut(), t_p)); + + // // all same API + // + // dbg!(flecs_ecs::core::utility::id::Id::::IF_ID_IS_DEFAULT); + // dbg!(flecs_ecs::core::utility::id::Id::::IS_TYPED); + // dbg!(flecs_ecs::core::utility::id::Id::::IF_ID_IS_DEFAULT); + // dbg!(flecs_ecs::core::utility::id::Id::::IS_TYPED); + // dbg!( + // <( + // flecs_ecs::core::utility::id::Id::, + // flecs_ecs::core::utility::id::Id:: + // )>::IS_PAIR + // ); + // dbg!( + // <( + // flecs_ecs::core::utility::id::Id::, + // flecs_ecs::core::utility::id::Id:: + // )>::IS_TYPED_SECOND + // ); + // dbg!( + // <( + // flecs_ecs::core::utility::id::Id::, + // flecs_ecs::core::utility::id::Id:: + // )>::IF_ID_IS_DEFAULT_SECOND + // ); + + e.add((id::(), id::())); + e.add((id::(), id::())); + e.add((id::(), id::())); + + e.add(e); + e.add((e, e)); + e.add((id::(), e)); + e.add((e, id::())); + + // //ignore + // assert!(e.has(id::())); + // assert!(e.has(e)); + // assert!(e.has(id::())); + // assert!(e.has((e, e))); + // assert!(e.has((id::(), e))); + // assert!(e.has((e, id::()))); + } +} diff --git a/flecs_ecs/tests/flecs/component_lifecycle_test.rs b/flecs_ecs/tests/flecs/component_lifecycle_test.rs index 15c8b789..afca5e27 100644 --- a/flecs_ecs/tests/flecs/component_lifecycle_test.rs +++ b/flecs_ecs/tests/flecs/component_lifecycle_test.rs @@ -33,7 +33,7 @@ fn component_lifecycle_count_in_remove_hook() { world.set(Count(0)); world.component::().on_remove(|e, _| { - e.world().set(Count(e.world().count::())); + e.world().set(Count(e.world().count(id::()))); }); let entity = world.entity().set(Position { x: 1, y: 2 }); diff --git a/flecs_ecs/tests/flecs/component_test.rs b/flecs_ecs/tests/flecs/component_test.rs index 89d981b8..e715b72c 100644 --- a/flecs_ecs/tests/flecs/component_test.rs +++ b/flecs_ecs/tests/flecs/component_test.rs @@ -66,7 +66,7 @@ fn temp_test_hook() { }); }); - entity.remove::(); + entity.remove(id::()); assert_eq!(unsafe { COUNT_ADD_POS }, 1); assert_eq!(unsafe { COUNT_SET_POS }, 3); @@ -79,10 +79,10 @@ fn temp_test_hook() { assert_eq!(unsafe { COUNT_SET_VEL }, 1); - entity.remove::(); + entity.remove(id::()); assert_eq!(unsafe { COUNT_ADD_POS }, 1); assert_eq!(unsafe { COUNT_SET_POS }, 3); - entity2.remove::(); + entity2.remove(id::()); assert_eq!(unsafe { COUNT_ADD_POS }, 0); assert_eq!(unsafe { COUNT_SET_POS }, 3); } @@ -103,7 +103,7 @@ fn on_component_registration() { }); world - .component_untyped_from_id(component_id) + .component_untyped_from(component_id) .add_trait::(); } } @@ -137,7 +137,11 @@ fn on_component_registration() { assert_eq!(count.0, 1); }); - assert!(world.component::().has::()); + assert!( + world + .component::() + .has(id::()) + ); world.component::(); @@ -167,7 +171,7 @@ fn on_component_registration_named() { }); world - .component_untyped_from_id(component_id) + .component_untyped_from(component_id) .add_trait::(); } } @@ -201,7 +205,11 @@ fn on_component_registration_named() { assert_eq!(count.0, 1); }); - assert!(world.component::().has::()); + assert!( + world + .component::() + .has(id::()) + ); world.component::(); diff --git a/flecs_ecs/tests/flecs/entity_bulk_rust_test.rs b/flecs_ecs/tests/flecs/entity_bulk_rust_test.rs index b1b3ee47..703010e2 100644 --- a/flecs_ecs/tests/flecs/entity_bulk_rust_test.rs +++ b/flecs_ecs/tests/flecs/entity_bulk_rust_test.rs @@ -16,8 +16,8 @@ fn bulk_entity_builder_simple_add() { for entity in entities { let entity = world.entity_from_id(entity); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); } } @@ -42,8 +42,8 @@ fn bulk_entity_builder_simple_set() { assert_eq!(entities.len(), 10); for (index, entity) in entities.into_iter().enumerate() { let entity = world.entity_from_id(entity); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); let position = entity.cloned::<&Position>(); let velocity = entity.cloned::<&Velocity>(); assert_eq!(position.x, velocity.x / 2); @@ -61,9 +61,9 @@ fn bulk_entity_builder_table() { let ent = world .entity() - .add::() - .add::() - .add_id(ent_id); + .add(id::()) + .add(id::()) + .add(ent_id); let mut table = ent.table().unwrap(); @@ -90,12 +90,12 @@ fn bulk_entity_builder_table() { for (index, entity) in entities.into_iter().enumerate() { let entity = world.entity_from_id(entity); - assert!(entity.has::()); - assert!(entity.has::()); - assert!(entity.has_id(ent_id)); + assert!(entity.has(id::())); + assert!(entity.has(id::())); + assert!(entity.has(ent_id)); - assert!(!entity.has::()); - assert!(!entity.has_id(random_ent_id)); + assert!(!entity.has(id::())); + assert!(!entity.has(random_ent_id)); let position = entity.cloned::<&Position>(); let velocity = entity.cloned::<&Velocity>(); @@ -179,7 +179,7 @@ fn bulk_entity_builder_with_entity_ids() { for (index, entity) in new_entities.into_iter().enumerate() { let entity = world.entity_from_id(entity); - assert!(entity.has::()); + assert!(entity.has(id::())); assert_eq!(entity.id(), entities[index]); } @@ -203,8 +203,8 @@ fn bulk_entity_builder_add_and_set() { for entity in entities { let entity = world.entity_from_id(entity); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); let position = entity.cloned::<&Position>(); assert_eq!(position.x, position.y); } @@ -222,7 +222,7 @@ fn bulk_entity_builder_build_to_table_missing_default() { let ent = world .entity() - .add::() + .add(id::()) .set(NonDefaultComponent { value: 5 }); let mut table = ent.table().unwrap(); @@ -249,7 +249,7 @@ fn bulk_entity_builder_duplicate_add() { for entity in entities { let entity = world.entity_from_id(entity); - assert!(entity.has::()); + assert!(entity.has(id::())); } } @@ -271,7 +271,7 @@ fn bulk_entity_builder_set_after_add() { for entity in entities { let entity = world.entity_from_id(entity); - assert!(entity.has::()); + assert!(entity.has(id::())); let position = entity.cloned::<&Position>(); assert_eq!(position.x, position.y); } @@ -287,7 +287,7 @@ fn bulk_entity_builder_no_components() { for entity in entities { let entity = world.entity_from_id(entity); - assert!(!entity.has::()); + assert!(!entity.has(id::())); } } diff --git a/flecs_ecs/tests/flecs/entity_rust_test.rs b/flecs_ecs/tests/flecs/entity_rust_test.rs index 9bc2f73f..5d46c73b 100644 --- a/flecs_ecs/tests/flecs/entity_rust_test.rs +++ b/flecs_ecs/tests/flecs/entity_rust_test.rs @@ -10,20 +10,20 @@ fn count_target_ids() { let r = world.entity(); let o = world.entity(); - e.add_id((r, o)); - e.add_id((r, o)); + e.add((r, o)); + e.add((r, o)); assert_eq!(e.target_id_count(r).unwrap(), 1); let e2 = world.entity(); - e2.add_id((r, o)); + e2.add((r, o)); assert_eq!(e.target_id_count(r).unwrap(), 1); assert_eq!(e2.target_id_count(r).unwrap(), 1); let o2 = world.entity(); - e.add_id((r, o2)); + e.add((r, o2)); assert_eq!(e.target_id_count(r).unwrap(), 2); assert_eq!(e2.target_id_count(r).unwrap(), 1); @@ -34,12 +34,12 @@ fn entity_id_reuse() { let world = World::new(); let a = world.entity_named("a"); - let b = world.entity().child_of_id(a); + let b = world.entity().child_of(a); let first_archetype = b.archetype().to_string(); a.destruct(); let a = world.entity_named("a"); - let b = world.entity().child_of_id(a); + let b = world.entity().child_of(a); assert!( b.id() > u32::MAX as u64, "this test is not valid if the id was not reused" diff --git a/flecs_ecs/tests/flecs/entity_test.rs b/flecs_ecs/tests/flecs/entity_test.rs index 667eb16d..8df5246b 100644 --- a/flecs_ecs/tests/flecs/entity_test.rs +++ b/flecs_ecs/tests/flecs/entity_test.rs @@ -25,11 +25,11 @@ fn entity_new_named_from_scope() { let entity = world.entity_named("Foo"); assert!(entity.is_valid()); - let prev = world.set_scope_id(entity); + let prev = world.set_scope(entity); let child = world.entity_named("Bar"); assert!(child.is_valid()); - world.set_scope_id(prev); + world.set_scope(prev); assert_eq!(child.name(), "Bar"); assert_eq!(child.path().unwrap(), "::Foo::Bar"); @@ -50,7 +50,7 @@ fn entity_new_nested_named_from_nested_scope() { assert_eq!(entity.path().unwrap(), "::Foo::Bar"); // Set the current scope to `entity` - let prev = world.set_scope_id(entity); + let prev = world.set_scope(entity); // Create a child entity with nested name "Hello::World" under the current scope let child = world.entity_named("Hello::World"); @@ -59,7 +59,7 @@ fn entity_new_nested_named_from_nested_scope() { assert!(child.is_valid()); // Restore the previous scope - world.set_scope_id(prev); + world.set_scope(prev); // Verify the name and hierarchical path of the child entity assert_eq!(child.name(), "World"); @@ -73,7 +73,7 @@ fn entity_new_add() { let entity = world.entity().set(Position { x: 0, y: 0 }); assert!(entity.is_valid()); - assert!(entity.has::()); + assert!(entity.has(id::())); } #[test] @@ -86,8 +86,8 @@ fn entity_new_add_2() { .set(Velocity { x: 0, y: 0 }); assert!(entity.is_valid()); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); } #[test] @@ -101,7 +101,7 @@ fn entity_new_set() { assert!(entity.is_valid()); // Verify that the entity has the Position component - assert!(entity.has::()); + assert!(entity.has(id::())); // Verify the component data entity.get::<&Position>(|pos| { @@ -120,8 +120,8 @@ fn entity_new_set_2() { .set(Velocity { x: 1, y: 2 }); assert!(entity.is_valid()); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); entity.get::<(&Position, &Velocity)>(|(pos, vel)| { assert_eq!(pos.x, 10); @@ -141,7 +141,7 @@ fn entity_add() { entity.set(Position { x: 0, y: 0 }); - assert!(entity.has::()); + assert!(entity.has(id::())); } #[test] @@ -152,10 +152,10 @@ fn entity_remove() { assert!(entity.is_valid()); entity.set(Position { x: 0, y: 0 }); - assert!(entity.has::()); + assert!(entity.has(id::())); - entity.remove::(); - assert!(!entity.has::()); + entity.remove(id::()); + assert!(!entity.has(id::())); } #[test] @@ -166,7 +166,7 @@ fn entity_set() { assert!(entity.is_valid()); entity.set(Position { x: 10, y: 20 }); - assert!(entity.has::()); + assert!(entity.has(id::())); entity.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -185,8 +185,8 @@ fn entity_add_2() { .set(Position { x: 0, y: 0 }) .set(Velocity { x: 0, y: 0 }); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); } #[test] @@ -199,8 +199,8 @@ fn entity_add_entity() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id(tag); - assert!(entity.has_id(tag)); + entity.add(tag); + assert!(entity.has(tag)); } #[test] @@ -213,8 +213,8 @@ fn entity_add_childof() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id((flecs::ChildOf::ID, parent)); - assert!(entity.has_id((flecs::ChildOf::ID, parent))); + entity.add((flecs::ChildOf::ID, parent)); + assert!(entity.has((flecs::ChildOf::ID, parent))); } #[test] @@ -227,8 +227,8 @@ fn entity_add_instanceof() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id((flecs::IsA::ID, base)); - assert!(entity.has_id((flecs::IsA::ID, base))); + entity.add((flecs::IsA::ID, base)); + assert!(entity.has((flecs::IsA::ID, base))); } #[test] @@ -240,13 +240,13 @@ fn entity_remove_2() { .set(Position { x: 0, y: 0 }) .set(Velocity { x: 0, y: 0 }); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); - entity.remove::().remove::(); + entity.remove(id::()).remove(id::()); - assert!(!entity.has::()); - assert!(!entity.has::()); + assert!(!entity.has(id::())); + assert!(!entity.has(id::())); } #[test] @@ -258,8 +258,8 @@ fn entity_set_2() { .set::(Position { x: 10, y: 20 }) .set::(Velocity { x: 1, y: 2 }); - assert!(entity.has::()); - assert!(entity.has::()); + assert!(entity.has(id::())); + assert!(entity.has(id::())); entity.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -282,11 +282,11 @@ fn entity_remove_entity() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id(tag); - assert!(entity.has_id(tag)); + entity.add(tag); + assert!(entity.has(tag)); - entity.remove_id(tag); - assert!(!entity.has_id(tag)); + entity.remove(tag); + assert!(!entity.has(tag)); } #[test] @@ -299,11 +299,11 @@ fn entity_remove_childof() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id((flecs::ChildOf::ID, parent)); - assert!(entity.has_id((flecs::ChildOf::ID, parent))); + entity.add((flecs::ChildOf::ID, parent)); + assert!(entity.has((flecs::ChildOf::ID, parent))); - entity.remove_id((flecs::ChildOf::ID, parent)); - assert!(!entity.has_id((flecs::ChildOf::ID, parent))); + entity.remove((flecs::ChildOf::ID, parent)); + assert!(!entity.has((flecs::ChildOf::ID, parent))); } #[test] @@ -316,11 +316,11 @@ fn entity_remove_instanceof() { let entity = world.entity(); assert!(entity.is_valid()); - entity.add_id((flecs::IsA::ID, base)); - assert!(entity.has_id((flecs::IsA::ID, base))); + entity.add((flecs::IsA::ID, base)); + assert!(entity.has((flecs::IsA::ID, base))); - entity.remove_id((flecs::IsA::ID, base)); - assert!(!entity.has_id((flecs::IsA::ID, base))); + entity.remove((flecs::IsA::ID, base)); + assert!(!entity.has((flecs::IsA::ID, base))); } #[test] @@ -331,9 +331,9 @@ fn entity_get_generic() { let entity = world.entity().set(Position { x: 10, y: 20 }); assert!(entity.is_valid()); - assert!(entity.has::()); + assert!(entity.has(id::())); - let pos_void = entity.get_untyped(world.id_from::()); + let pos_void = entity.get_untyped(world.id_view_from(id::())); assert!(!pos_void.is_null()); let pos = unsafe { &*(pos_void as *const Position) }; @@ -355,7 +355,7 @@ fn entity_get_generic_mut() { let entity = world.entity().set(Position { x: 10, y: 20 }); assert!(entity.is_valid()); - assert!(entity.has::()); + assert!(entity.has(id::())); world .observer::() @@ -372,7 +372,7 @@ fn entity_get_generic_mut() { assert_eq!(pos.x, 10); assert_eq!(pos.y, 20); - entity.modified_id(position); + entity.modified(position); world.get::<&Flags>(|flags| { assert_eq!(flags.invoked, 1); }); @@ -387,7 +387,7 @@ fn entity_get_mut_generic_w_id() { let entity = world.entity().set(Position { x: 10, y: 20 }); assert!(entity.is_valid()); - assert!(entity.has::()); + assert!(entity.has(id::())); let void_p = entity.get_untyped(position); assert!(!void_p.is_null()); @@ -412,8 +412,8 @@ fn entity_set_generic() { ) }; - assert!(entity.has::()); - assert!(entity.has_id(position)); + assert!(entity.has(id::())); + assert!(entity.has(position)); entity.try_get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -434,8 +434,8 @@ fn entity_set_generic_no_size() { .set_ptr(position.id(), &pos as *const _ as *const c_void) }; - assert!(entity.has::()); - assert!(entity.has_id(position)); + assert!(entity.has(id::())); + assert!(entity.has(position)); entity.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -619,9 +619,9 @@ fn entity_has_childof() { let parent = world.entity(); - let child = world.entity().add_id((flecs::ChildOf::ID, parent)); + let child = world.entity().add((flecs::ChildOf::ID, parent)); - assert!(child.has_id((flecs::ChildOf::ID, parent))); + assert!(child.has((flecs::ChildOf::ID, parent))); } #[test] @@ -630,9 +630,9 @@ fn entity_has_instanceof() { let base = world.entity(); - let instance = world.entity().add_id((flecs::IsA::ID, base)); + let instance = world.entity().add((flecs::IsA::ID, base)); - assert!(instance.has_id((flecs::IsA::ID, base))); + assert!(instance.has((flecs::IsA::ID, base))); } #[test] @@ -640,11 +640,11 @@ fn entity_has_instanceof_indirect() { let world = World::new(); let base_of_base = world.entity(); - let base = world.entity().add_id((flecs::IsA::ID, base_of_base)); + let base = world.entity().add((flecs::IsA::ID, base_of_base)); - let instance = world.entity().add_id((flecs::IsA::ID, base)); + let instance = world.entity().add((flecs::IsA::ID, base)); - assert!(instance.has_id((flecs::IsA::ID, base_of_base))); + assert!(instance.has((flecs::IsA::ID, base_of_base))); } #[test] @@ -729,8 +729,8 @@ fn entity_clear() { .set(Velocity { x: 0, y: 0 }); entity.clear(); - assert!(!entity.has::()); - assert!(!entity.has::()); + assert!(!entity.has(id::())); + assert!(!entity.has(id::())); let entity2 = world.entity(); assert!(entity2 > entity); @@ -742,23 +742,23 @@ fn entity_force_owned() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let prefab = world .prefab() .set(Position { x: 0, y: 0 }) .set(Velocity { x: 0, y: 0 }) - .auto_override::(); + .auto_override(id::()); - let entity = world.entity().add_id((flecs::IsA::ID, prefab)); + let entity = world.entity().add((flecs::IsA::ID, prefab)); - assert!(entity.has::()); - assert!(entity.owns::()); - assert!(entity.has::()); - assert!(!entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); + assert!(entity.has(id::())); + assert!(!entity.owns(id::())); } #[test] @@ -767,24 +767,24 @@ fn entity_force_owned_2() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let prefab = world .prefab() .set(Position { x: 0, y: 0 }) .set(Velocity { x: 0, y: 0 }) - .auto_override::() - .auto_override::(); + .auto_override(id::()) + .auto_override(id::()); - let entity = world.entity().add_id((flecs::IsA::ID, prefab)); + let entity = world.entity().add((flecs::IsA::ID, prefab)); - assert!(entity.has::()); - assert!(entity.owns::()); - assert!(entity.has::()); - assert!(entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); } #[test] @@ -793,25 +793,25 @@ fn entity_force_owned_nested() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let prefab = world .prefab() .set(Position { x: 0, y: 0 }) .set(Velocity { x: 0, y: 0 }) - .auto_override::(); + .auto_override(id::()); - let prefab_2 = world.entity().add_id((flecs::IsA::ID, prefab)); + let prefab_2 = world.entity().add((flecs::IsA::ID, prefab)); - let entity = world.entity().add_id((flecs::IsA::ID, prefab_2)); + let entity = world.entity().add((flecs::IsA::ID, prefab_2)); - assert!(entity.has::()); - assert!(entity.owns::()); - assert!(entity.has::()); - assert!(!entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); + assert!(entity.has(id::())); + assert!(!entity.owns(id::())); } #[test] @@ -845,23 +845,23 @@ fn entity_get_target() { let obj3 = world.entity().set(Mass { value: 0 }); let child = world .entity() - .add_id((rel, obj1)) - .add_id((rel, obj2)) - .add_id((rel, obj3)); + .add((rel, obj1)) + .add((rel, obj2)) + .add((rel, obj3)); - let mut target = child.target_id(rel, 0).unwrap(); + let mut target = child.target(rel, 0).unwrap(); assert!(target.is_valid()); assert_eq!(target, obj1); - target = child.target_id(rel, 1).unwrap(); + target = child.target(rel, 1).unwrap(); assert!(target.is_valid()); assert_eq!(target, obj2); - target = child.target_id(rel, 2).unwrap(); + target = child.target(rel, 2).unwrap(); assert!(target.is_valid()); assert_eq!(target, obj3); - assert!(child.target_id(rel, 3).is_none()); + assert!(child.target(rel, 3).is_none()); } #[test] @@ -869,9 +869,9 @@ fn entity_get_parent() { let world = World::new(); let parent = world.entity(); - let child = world.entity().child_of_id(parent); + let child = world.entity().child_of(parent); - assert_eq!(child.target_id(flecs::ChildOf::ID, 0).unwrap(), parent); + assert_eq!(child.target(flecs::ChildOf::ID, 0).unwrap(), parent); assert_eq!(child.parent().unwrap(), parent); } @@ -881,9 +881,9 @@ fn entity_get_parent() { fn entity_is_component_enabled() { let world = World::new(); - world.component::().add_id(flecs::CanToggle::ID); - world.component::().add_id(flecs::CanToggle::ID); - world.component::().add::(); + world.component::().add(flecs::CanToggle::ID); + world.component::().add(flecs::CanToggle::ID); + world.component::().add(id::()); let entity = world .entity() @@ -891,45 +891,45 @@ fn entity_is_component_enabled() { .set(Velocity { x: 0, y: 0 }) .set(Mass { value: 0 }); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); - entity.disable::(); + entity.disable(id::()); - assert!(!entity.is_enabled::()); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); + assert!(!entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); - entity.disable::(); + entity.disable(id::()); - assert!(!entity.is_enabled::()); - assert!(!entity.is_enabled::()); - assert!(entity.is_enabled::()); + assert!(!entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); - entity.disable::(); + entity.disable(id::()); - assert!(!entity.is_enabled::()); - assert!(!entity.is_enabled::()); - assert!(!entity.is_enabled::()); + assert!(!entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); - entity.enable::(); + entity.enable(id::()); - assert!(entity.is_enabled::()); - assert!(!entity.is_enabled::()); - assert!(!entity.is_enabled::()); + assert!(entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); - entity.enable::(); + entity.enable(id::()); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); - assert!(!entity.is_enabled::()); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); + assert!(!entity.is_enabled(id::())); - entity.enable::(); + entity.enable(id::()); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); - assert!(entity.is_enabled::()); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); + assert!(entity.is_enabled(id::())); } /// # See also @@ -938,37 +938,37 @@ fn entity_is_component_enabled() { fn entity_is_enabled_pair() { let world = World::new(); - world.component::().add_id(flecs::CanToggle::ID); - world.component::().add_id(flecs::CanToggle::ID); - world.component::().add_id(flecs::CanToggle::ID); - world.component::().add_id(flecs::CanToggle::ID); + world.component::().add(flecs::CanToggle::ID); + world.component::().add(flecs::CanToggle::ID); + world.component::().add(flecs::CanToggle::ID); + world.component::().add(flecs::CanToggle::ID); let entity = world .entity() .set_pair::(Position { x: 0, y: 0 }) .set_pair::(Position { x: 0, y: 0 }) - .add::<(TagB, TagC)>() - .disable::<(Position, TagC)>(); + .add((id::(), id::())) + .disable((id::(), id::())); - assert!(entity.is_enabled::<(Position, TagA)>()); - assert!(!entity.is_enabled::<(Position, TagB)>()); - assert!(!entity.is_enabled::<(Position, TagC)>()); + assert!(entity.is_enabled((id::(), id::()))); + assert!(!entity.is_enabled((id::(), id::()))); + assert!(!entity.is_enabled((id::(), id::()))); - entity.enable::<(Position, TagC)>(); - assert!(entity.is_enabled::<(Position, TagC)>()); + entity.enable((id::(), id::())); + assert!(entity.is_enabled((id::(), id::()))); - entity.disable::<(Position, TagA)>(); - assert!(!entity.is_enabled::<(Position, TagA)>()); + entity.disable((id::(), id::())); + assert!(!entity.is_enabled((id::(), id::()))); - entity.enable::<(Position, TagA)>(); - entity.enable::<(Position, TagC)>(); - assert!(entity.is_enabled::<(Position, TagA)>()); - assert!(entity.is_enabled::<(Position, TagC)>()); + entity.enable((id::(), id::())); + entity.enable((id::(), id::())); + assert!(entity.is_enabled((id::(), id::()))); + assert!(entity.is_enabled((id::(), id::()))); - entity.disable::<(Position, TagC)>(); - assert!(!entity.is_enabled::<(Position, TagC)>()); + entity.disable((id::(), id::())); + assert!(!entity.is_enabled((id::(), id::()))); //component it doesn't have - assert!(!entity.is_enabled::<(Position, TagB)>()); + assert!(!entity.is_enabled((id::(), id::()))); } /// # See also @@ -979,26 +979,26 @@ fn entity_is_enabled_pair() { fn entity_is_enabled_pair_ids() { let world = World::new(); - let rel = world.entity().add_id(flecs::CanToggle::ID); + let rel = world.entity().add(flecs::CanToggle::ID); let tgt_a = world.entity(); let tgt_b = world.entity(); - let e = world.entity().add_id((rel, tgt_a)); + let e = world.entity().add((rel, tgt_a)); - assert!(e.is_enabled_id((rel, tgt_a))); - assert!(!e.is_enabled_id((rel, tgt_b))); + assert!(e.is_enabled((rel, tgt_a))); + assert!(!e.is_enabled((rel, tgt_b))); - e.disable_id((rel, tgt_a)); - assert!(!e.is_enabled_id((rel, tgt_a))); + e.disable((rel, tgt_a)); + assert!(!e.is_enabled((rel, tgt_a))); - e.enable_id((rel, tgt_a)); - assert!(e.is_enabled_id((rel, tgt_a))); + e.enable((rel, tgt_a)); + assert!(e.is_enabled((rel, tgt_a))); - e.add_id((rel, tgt_b)).disable_id((rel, tgt_b)); - assert!(!e.is_enabled_id((rel, tgt_b))); + e.add((rel, tgt_b)).disable((rel, tgt_b)); + assert!(!e.is_enabled((rel, tgt_b))); - e.enable_id((rel, tgt_b)); - assert!(e.is_enabled_id((rel, tgt_b))); + e.enable((rel, tgt_b)); + assert!(e.is_enabled((rel, tgt_b))); } #[test] @@ -1012,8 +1012,8 @@ fn entity_is_first_enabled() { .entity() .set_first::(Position { x: 0, y: 0 }, tgt_a); - assert!(e.is_enabled_first::(tgt_a)); - assert!(!e.is_enabled_first::(tgt_b)); + assert!(e.is_enabled((id::(), tgt_a))); + assert!(!e.is_enabled((id::(), tgt_b))); } #[test] @@ -1033,13 +1033,13 @@ fn entity_get_type() { { let type_2 = entity.archetype(); assert_eq!(type_2.count(), 1); - assert_eq!(type_2.get(0).unwrap(), world.id_from::()); + assert_eq!(type_2.get(0).unwrap(), world.id_view_from(id::())); } entity.set(Velocity { x: 0, y: 0 }); let type_3 = entity.archetype(); assert_eq!(type_3.count(), 2); - assert_eq!(type_3.get(1).unwrap(), world.id_from::()); + assert_eq!(type_3.get(1).unwrap(), world.id_view_from(id::())); } #[test] @@ -1051,11 +1051,11 @@ fn entity_get_nonempty_type() { let type_1 = entity.archetype(); assert_eq!(type_1.count(), 1); - assert_eq!(type_1.get(0).unwrap(), world.id_from::()); + assert_eq!(type_1.get(0).unwrap(), world.id_view_from(id::())); let type_2 = entity.archetype(); assert_eq!(type_2.count(), 1); - assert_eq!(type_2.get(0).unwrap(), world.id_from::()); + assert_eq!(type_2.get(0).unwrap(), world.id_view_from(id::())); } #[test] @@ -1068,7 +1068,7 @@ fn entity_set_no_copy() { assert_eq!(pod.clone_count, 0); }); - assert!(entity.has::()); + assert!(entity.has(id::())); entity.get::<&Pod>(|pod| { assert_eq!(pod.value, 10); @@ -1087,13 +1087,13 @@ fn entity_set_copy() { assert_eq!(pod.clone_count, 1); }); - assert!(entity.has::()); + assert!(entity.has(id::())); entity.get::<&Pod>(|pod| { assert_eq!(pod.value, 10); }); - assert!(entity_dupl.has::()); + assert!(entity_dupl.has(id::())); entity_dupl.get::<&Pod>(|pod| { assert_eq!(pod.value, 10); @@ -1106,7 +1106,7 @@ fn entity_set_deduced() { let entity = world.entity().set(Position { x: 10, y: 20 }); - assert!(entity.has::()); + assert!(entity.has(id::())); entity.get::<&Position>(|p| { assert_eq!(p.x, 10); @@ -1120,36 +1120,32 @@ fn entity_override() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); - let base = world.entity().auto_override::(); + let base = world.entity().auto_override(id::()); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::()); - assert!(entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); } #[test] -fn entity_auto_override_id() { +fn entity_auto_override() { let world = World::new(); - let tag_a = world - .entity() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); - let tag_b = world - .entity() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + let tag_a = world.entity().add((*flecs::OnInstantiate, *flecs::Inherit)); + let tag_b = world.entity().add((*flecs::OnInstantiate, *flecs::Inherit)); - let base = world.entity().auto_override_id(tag_a).add_id(tag_b); + let base = world.entity().auto_override(tag_a).add(tag_b); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has_id(tag_a)); - assert!(entity.owns_id(tag_a)); + assert!(entity.has(tag_a)); + assert!(entity.owns(tag_a)); - assert!(entity.has_id(tag_b)); - assert!(!entity.owns_id(tag_b)); + assert!(entity.has(tag_b)); + assert!(!entity.owns(tag_b)); } #[test] @@ -1158,47 +1154,42 @@ fn entity_override_pair_w_tgt_id() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let tgt_a = world.entity(); let tgt_b = world.entity(); let base = world .entity() - .auto_override_first::(tgt_a) + .auto_override((id::(), tgt_a)) .set_first::(Position { x: 0, y: 0 }, tgt_b); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has_first::(tgt_a)); - assert!(entity.owns_first::(tgt_a)); + assert!(entity.has((id::(), tgt_a))); + assert!(entity.owns((id::(), tgt_a))); - assert!(entity.has_first::(tgt_b)); - assert!(!entity.owns_first::(tgt_b)); + assert!(entity.has((id::(), tgt_b))); + assert!(!entity.owns((id::(), tgt_b))); } #[test] fn entity_override_pair_w_ids() { let world = World::new(); - let rel = world - .entity() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + let rel = world.entity().add((*flecs::OnInstantiate, *flecs::Inherit)); let tgt_a = world.entity(); let tgt_b = world.entity(); - let base = world - .entity() - .auto_override_id((rel, tgt_a)) - .add_id((rel, tgt_b)); + let base = world.entity().auto_override((rel, tgt_a)).add((rel, tgt_b)); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has_id((rel, tgt_a))); - assert!(entity.owns_id((rel, tgt_a))); + assert!(entity.has((rel, tgt_a))); + assert!(entity.owns((rel, tgt_a))); - assert!(entity.has_id((rel, tgt_b))); - assert!(!entity.owns_id((rel, tgt_b))); + assert!(entity.has((rel, tgt_b))); + assert!(!entity.owns((rel, tgt_b))); } #[test] @@ -1207,19 +1198,19 @@ fn entity_override_pair() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let base = world .entity() - .auto_override::<(Position, TagA)>() + .auto_override((id::(), id::())) .set_pair::(Position { x: 0, y: 0 }); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::<(Position, TagA)>()); - assert!(entity.owns::<(Position, TagA)>()); + assert!(entity.has((id::(), id::()))); + assert!(entity.owns((id::(), id::()))); - assert!(entity.has::<(Position, TagB)>()); - assert!(!entity.owns::<(Position, TagB)>()); + assert!(entity.has((id::(), id::()))); + assert!(!entity.owns((id::(), id::()))); } #[test] @@ -1228,14 +1219,14 @@ fn entity_set_auto_override() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let base = world.entity().set_auto_override(Position { x: 10, y: 20 }); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::()); - assert!(entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); entity.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -1254,16 +1245,16 @@ fn entity_set_auto_override_lvalue() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let plvalue = Position { x: 10, y: 20 }; let base = world.entity().set_auto_override(plvalue); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::()); - assert!(entity.owns::()); + assert!(entity.has(id::())); + assert!(entity.owns(id::())); entity.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -1282,16 +1273,16 @@ fn entity_set_auto_override_pair() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let base = world .entity() .set_pair_override::(Position { x: 10, y: 20 }); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::<(Position, TagA)>()); - assert!(entity.owns::<(Position, TagA)>()); + assert!(entity.has((id::(), id::()))); + assert!(entity.owns((id::(), id::()))); entity.get::<&(Position, TagA)>(|pos| { assert_eq!(pos.x, 10); @@ -1315,13 +1306,13 @@ fn entity_set_auto_override_pair_w_tgt_id() { // let base = unsafe { // world // .entity() - // .set_auto_override_first::(Position { x: 10, y: 20 }, tgt) + // .set_auto_override((id::(), Position { x: 10, y: 20 }, tgt)) // }; - // let entity = world.entity().add_id((flecs::IsA::ID, base)); + // let entity = world.entity().add((flecs::IsA::ID, base)); - // assert!(entity.has_first::(tgt)); - // assert!(entity.owns_first::(tgt)); + // assert!(entity.has((id::(), tgt))); + // assert!(entity.owns((id::(), tgt))); // let p = entity.try_get_first_id::(tgt); // assert!(p.is_some()); @@ -1342,16 +1333,16 @@ fn entity_set_auto_override_pair_w_rel_tag() { world .component::() - .add_id((*flecs::OnInstantiate, *flecs::Inherit)); + .add((*flecs::OnInstantiate, *flecs::Inherit)); let base = world .entity() .set_pair_override::(Position { x: 10, y: 20 }); - let entity = world.entity().add_id((flecs::IsA::ID, base)); + let entity = world.entity().add((flecs::IsA::ID, base)); - assert!(entity.has::<(TagA, Position)>()); - assert!(entity.owns::<(TagA, Position)>()); + assert!(entity.has((id::(), id::()))); + assert!(entity.owns((id::(), id::()))); entity.get::<&(TagA, Position)>(|pos| { assert_eq!(pos.x, 10); @@ -1393,7 +1384,7 @@ fn entity_path() { let world = World::new(); let parent = world.entity_named("parent"); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); assert_eq!(&child.path().unwrap(), "::parent::child"); @@ -1404,16 +1395,13 @@ fn entity_path_from() { let world = World::new(); let parent = world.entity_named("parent"); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); - world.set_scope_id(child.id()); + world.set_scope(child.id()); let grandchild = world.entity_named("grandchild"); assert_eq!(&grandchild.path().unwrap(), "::parent::child::grandchild"); - assert_eq!( - &grandchild.path_from_id(parent).unwrap(), - "child::grandchild" - ); + assert_eq!(&grandchild.path_from(parent).unwrap(), "child::grandchild"); } #[test] @@ -1421,16 +1409,13 @@ fn entity_path_from_type() { let world = World::new(); let parent = world.entity_named("parent"); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); - world.set_scope_id(child.id()); + world.set_scope(child.id()); let grandchild = world.entity_named("grandchild"); assert_eq!(&grandchild.path().unwrap(), "::parent::child::grandchild"); - assert_eq!( - &grandchild.path_from_id(parent).unwrap(), - "child::grandchild" - ); + assert_eq!(&grandchild.path_from(parent).unwrap(), "child::grandchild"); } #[test] @@ -1438,7 +1423,7 @@ fn entity_path_custom_sep() { let world = World::new(); let parent = world.entity_named("parent"); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); assert_eq!(&child.path_w_sep("_", "?").unwrap(), "?parent_child"); @@ -1449,9 +1434,9 @@ fn entity_path_from_custom_sep() { let world = World::new(); let parent = world.entity_named("parent"); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); - world.set_scope_id(child.id()); + world.set_scope(child.id()); let grandchild = world.entity_named("grandchild"); assert_eq!( @@ -1459,7 +1444,7 @@ fn entity_path_from_custom_sep() { "?parent_child_grandchild" ); assert_eq!( - &grandchild.path_from_id_w_sep(parent, "_", "::").unwrap(), + &grandchild.path_from_w_sep(parent, "_", "::").unwrap(), "child_grandchild" ); } @@ -1469,9 +1454,9 @@ fn entity_path_from_type_custom_sep() { let world = World::new(); let parent = world.entity_from::(); - world.set_scope_id(parent.id()); + world.set_scope(parent.id()); let child = world.entity_named("child"); - world.set_scope_id(child.id()); + world.set_scope(child.id()); let grandchild = world.entity_named("grandchild"); assert_eq!( @@ -1479,7 +1464,7 @@ fn entity_path_from_type_custom_sep() { "?flecs_common\\_test_Parent_child_grandchild" ); assert_eq!( - &grandchild.path_from_id_w_sep(parent, "_", "::").unwrap(), + &grandchild.path_from_w_sep(parent, "_", "::").unwrap(), "child_grandchild" ); } @@ -1537,7 +1522,7 @@ fn entity_entity_view_to_entity_world() { let entity_mut = entity_view.mut_current_stage(&world); entity_mut.set(Position { x: 10, y: 20 }); - assert!(entity_view.has::()); + assert!(entity_view.has(id::())); entity_view.get::<&Position>(|p| { assert_eq!(p.x, 10); assert_eq!(p.y, 20); @@ -1555,12 +1540,12 @@ fn entity_entity_view_to_entity_stage() { let entity_mut = entity_view.mut_current_stage(stage); entity_mut.set(Position { x: 10, y: 20 }); - assert!(!entity_mut.has::()); + assert!(!entity_mut.has(id::())); world.readonly_end(); - assert!(entity_mut.has::()); - assert!(entity_view.has::()); + assert!(entity_mut.has(id::())); + assert!(entity_view.has(id::())); entity_view.get::<&Position>(|p| { assert_eq!(p.x, 10); @@ -1580,7 +1565,7 @@ fn entity_create_entity_view_from_stage() { let entity_mut = entity_view.mut_current_stage(&world); entity_mut.set(Position { x: 10, y: 20 }); - assert!(entity_view.has::()); + assert!(entity_view.has(id::())); entity_mut.get::<&Position>(|p| { assert_eq!(p.x, 10); @@ -1823,11 +1808,11 @@ fn entity_defer_set_1_component() { let e = world.entity().set(Position { x: 10, y: 20 }); - assert!(!e.has::()); + assert!(!e.has(id::())); world.defer_end(); - assert!(e.has::()); + assert!(e.has(id::())); e.get::<&Position>(|p| { assert_eq!(p.x, 10); @@ -1846,13 +1831,13 @@ fn entity_defer_set_2_components() { .set(Position { x: 10, y: 20 }) .set(Velocity { x: 1, y: 2 }); - assert!(!e.has::()); - assert!(!e.has::()); + assert!(!e.has(id::())); + assert!(!e.has(id::())); world.defer_end(); - assert!(e.has::()); - assert!(e.has::()); + assert!(e.has(id::())); + assert!(e.has(id::())); e.get::<(&Velocity, &Position)>(|(v, p)| { assert_eq!(p.x, 10); @@ -1874,15 +1859,15 @@ fn entity_defer_set_3_components() { .set(Velocity { x: 1, y: 2 }) .set(Mass { value: 50 }); - assert!(!e.has::()); - assert!(!e.has::()); - assert!(!e.has::()); + assert!(!e.has(id::())); + assert!(!e.has(id::())); + assert!(!e.has(id::())); world.defer_end(); - assert!(e.has::()); - assert!(e.has::()); - assert!(e.has::()); + assert!(e.has(id::())); + assert!(e.has(id::())); + assert!(e.has(id::())); e.get::<(&Velocity, &Position, &Mass)>(|(v, p, m)| { assert_eq!(p.x, 10); @@ -2007,7 +1992,7 @@ fn entity_set_2_after_set_1() { let e = world.entity().set(Position { x: 5, y: 10 }); - assert!(e.has::()); + assert!(e.has(id::())); e.get::<&Position>(|p| { assert_eq!(p.x, 5); @@ -2037,8 +2022,8 @@ fn entity_set_2_after_set_2() { .set(Position { x: 5, y: 10 }) .set(Velocity { x: 1, y: 2 }); - assert!(e.has::()); - assert!(e.has::()); + assert!(e.has(id::())); + assert!(e.has(id::())); e.get::<(&Position, &Velocity)>(|(p, v)| { assert_eq!(p.x, 5); @@ -2076,13 +2061,13 @@ fn entity_with_self() { // Ensures that while Self is (implicitly) registered within the with, it // does not get the tag. - assert!(!world.component::().has_id(tag)); + assert!(!world.component::().has(tag)); let mut count = 0; - let q = world.query::<()>().with_id(tag).build(); + let q = world.query::<()>().with(tag).build(); q.each_entity(|e, _| { - assert!(e.has_id(tag)); + assert!(e.has(tag)); e.get::<&SelfRef>(|s| { assert_eq!(s.value, e); @@ -2098,7 +2083,7 @@ fn entity_with_self() { fn entity_with_relation_type_self() { let world = World::new(); - let bob = world.entity().with_first::(|| { + let bob = world.entity().with_first(id::(), || { let e1 = world.entity(); e1.set(SelfRef { value: e1.into() }); @@ -2109,13 +2094,13 @@ fn entity_with_relation_type_self() { e3.set(SelfRef { value: e3.into() }); }); - assert!(!world.component::().has_first::(bob)); + assert!(!world.component::().has((id::(), bob))); let mut count = 0; - let q = world.query::<()>().with_first::<&Likes>(bob).build(); + let q = world.query::<()>().with((id::<&Likes>(), bob)).build(); q.each_entity(|e, _| { - assert!(e.has_first::(bob)); + assert!(e.has((id::(), bob))); e.get::<&SelfRef>(|s| { assert_eq!(s.value, e); @@ -2131,7 +2116,7 @@ fn entity_with_relation_type_self() { fn entity_with_relation_self() { let world = World::new(); - let bob = world.entity().with_first::(|| { + let bob = world.entity().with_first(id::(), || { let e1 = world.entity(); e1.set(SelfRef { value: e1.into() }); @@ -2142,13 +2127,13 @@ fn entity_with_relation_self() { e3.set(SelfRef { value: e3.into() }); }); - assert!(!world.component::().has_first::(bob)); + assert!(!world.component::().has((id::(), bob))); let mut count = 0; - let q = world.query::<()>().with_first::<&Likes>(bob).build(); + let q = world.query::<()>().with((id::<&Likes>(), bob)).build(); q.each_entity(|e, _| { - assert!(e.has_first::(bob)); + assert!(e.has((id::(), bob))); e.get::<&SelfRef>(|s| { assert_eq!(s.value, e); @@ -2173,7 +2158,7 @@ fn entity_with_self_w_name() { let tier2 = world.try_lookup_recursive("Tier2"); assert!(tier2.is_some()); let tier2 = tier2.unwrap(); - assert!(tier2.has_id(tier1)); + assert!(tier2.has(tier1)); } #[test] @@ -2189,8 +2174,8 @@ fn entity_with_self_nested() { let tier2 = world.try_lookup_recursive("Tier2").unwrap(); let tier3 = world.try_lookup_recursive("Tier3").unwrap(); - assert!(tier2.has_id(tier1)); - assert!(tier3.has_id(tier2)); + assert!(tier2.has(tier1)); + assert!(tier3.has(tier2)); } #[test] @@ -2240,17 +2225,14 @@ fn entity_with_scope() { assert!( !world .component::() - .has_id((flecs::ChildOf::ID, parent)) + .has((flecs::ChildOf::ID, parent)) ); let mut count = 0; - let q = world - .query::<()>() - .with_id((*flecs::ChildOf, parent)) - .build(); + let q = world.query::<()>().with((*flecs::ChildOf, parent)).build(); q.each_entity(|e, _| { - assert!(e.has_id((*flecs::ChildOf, parent))); + assert!(e.has((*flecs::ChildOf, parent))); e.get::<&SelfRef>(|s| { assert_eq!(s.value, e); @@ -2282,10 +2264,10 @@ fn entity_with_scope_nested() { assert!(world.try_lookup_recursive("C::GC").is_none()); let child = world.lookup_recursive("P::C"); - assert!(child.has_id((flecs::ChildOf::ID, parent))); + assert!(child.has((flecs::ChildOf::ID, parent))); let grandchild = world.lookup_recursive("P::C::GC"); - assert!(grandchild.has_id((flecs::ChildOf::ID, child))); + assert!(grandchild.has((flecs::ChildOf::ID, child))); } #[test] @@ -2307,10 +2289,10 @@ fn entity_with_scope_nested_same_name_as_parent() { assert!(world.try_lookup_recursive("C::C").is_none()); let child = world.lookup_recursive("P::C"); - assert!(child.has_id((flecs::ChildOf::ID, parent))); + assert!(child.has((flecs::ChildOf::ID, parent))); let gchild = world.lookup_recursive("P::C::C"); - assert!(gchild.has_id((flecs::ChildOf::ID, child))); + assert!(gchild.has((flecs::ChildOf::ID, child))); } #[test] @@ -2318,8 +2300,8 @@ fn entity_no_recursive_lookup() { let world = World::new(); let p = world.entity_named("P"); - let c = world.entity_named("C").child_of_id(p); - let gc = world.entity_named("GC").child_of_id(c); + let c = world.entity_named("C").child_of(p); + let gc = world.entity_named("GC").child_of(c); assert_eq!(c.lookup("GC"), gc); assert!(c.try_lookup("C").is_none()); @@ -2336,7 +2318,7 @@ fn entity_defer_new_w_name() { assert!(e.is_valid()); }); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Foo"); } @@ -2350,7 +2332,7 @@ fn entity_defer_new_w_nested_name() { assert!(e.is_valid()); }); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Bar"); assert_eq!(e.path().unwrap(), "::Foo::Bar"); } @@ -2368,7 +2350,7 @@ fn entity_defer_new_w_scope_name() { }); }); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Foo"); assert_eq!(e.path().unwrap(), "::Parent::Foo"); } @@ -2386,7 +2368,7 @@ fn entity_defer_new_w_scope_nested_name() { }); }); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Bar"); assert_eq!(e.path().unwrap(), "::Parent::Foo::Bar"); } @@ -2405,7 +2387,7 @@ fn entity_defer_new_w_scope() { }); }); - assert!(e.has_first::(parent)); + assert!(e.has((id::(), parent))); } #[test] @@ -2418,11 +2400,11 @@ fn entity_defer_new_w_with() { tag.with(|| { e = world.entity(); assert!(e.is_valid()); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); }); - assert!(e.has_id(tag)); + assert!(e.has(tag)); } #[test] @@ -2437,17 +2419,17 @@ fn entity_defer_new_w_name_scope_with() { parent.scope(|_w| { e = world.entity_named("Foo"); assert!(e.is_valid()); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(e.has_id(tag)); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has(tag)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Foo"); assert_eq!(e.path().unwrap(), "::Parent::Foo"); } @@ -2464,17 +2446,17 @@ fn entity_defer_new_w_nested_name_scope_with() { parent.scope(|_w| { e = world.entity_named("Foo::Bar"); assert!(e.is_valid()); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(!e.has_id(tag)); + assert!(!e.has(tag)); }); - assert!(e.has_id(tag)); - assert!(e.has_first::(flecs::Name::ID)); + assert!(e.has(tag)); + assert!(e.has((id::(), flecs::Name::ID))); assert_eq!(e.name(), "Bar"); assert_eq!(e.path().unwrap(), "::Parent::Foo::Bar"); } @@ -2485,15 +2467,15 @@ fn entity_defer_w_with_implicit_component() { let mut e = world.entity_null(); world.defer(|| { - world.with::(|| { + world.with(id::(), || { e = world.entity(); - assert!(!e.has::()); + assert!(!e.has(id::())); }); - assert!(!e.has::()); + assert!(!e.has(id::())); }); - assert!(e.has::()); + assert!(e.has(id::())); } #[test] @@ -2503,20 +2485,20 @@ fn entity_defer_suspend_resume() { world.defer(|| { e.set(Position { x: 10, y: 20 }); - assert!(!e.has::()); + assert!(!e.has(id::())); world.defer_suspend(); e.set(Velocity { x: 1, y: 2 }); - assert!(!e.has::()); - assert!(e.has::()); + assert!(!e.has(id::())); + assert!(e.has(id::())); world.defer_resume(); - assert!(!e.has::()); - assert!(e.has::()); + assert!(!e.has(id::())); + assert!(e.has(id::())); }); - assert!(e.has::()); - assert!(e.has::()); + assert!(e.has(id::())); + assert!(e.has(id::())); } #[test] @@ -2530,14 +2512,14 @@ fn entity_with_after_builder_method() { let b = world .entity() .set(Position { x: 30, y: 40 }) - .with_first::(|| { + .with_first(id::(), || { world.entity_named("Y"); }); let c = world .entity() .set(Position { x: 50, y: 60 }) - .with_first_id(*flecs::IsA, || { + .with_first(*flecs::IsA, || { world.entity_named("Z"); }); @@ -2557,13 +2539,13 @@ fn entity_with_after_builder_method() { }); let x = world.lookup_recursive("X"); - assert!(x.has_id(a)); + assert!(x.has(a)); let y = world.lookup_recursive("Y"); - assert!(y.has_first::(b)); + assert!(y.has((id::(), b))); let z = world.lookup_recursive("Z"); - assert!(z.has_id((*flecs::IsA, c))); + assert!(z.has((*flecs::IsA, c))); } #[test] @@ -2579,14 +2561,14 @@ fn entity_with_before_builder_method() { let b = world .entity() - .with_first::(|| { + .with_first(id::(), || { world.entity_named("Y"); }) .set(Position { x: 30, y: 40 }); let c = world .entity() - .with_first_id(*flecs::IsA, || { + .with_first(*flecs::IsA, || { world.entity_named("Z"); }) .set(Position { x: 50, y: 60 }); @@ -2607,13 +2589,13 @@ fn entity_with_before_builder_method() { }); let x = world.lookup_recursive("X"); - assert!(x.has_id(a)); + assert!(x.has(a)); let y = world.lookup_recursive("Y"); - assert!(y.has_first::(b)); + assert!(y.has((id::(), b))); let z = world.lookup_recursive("Z"); - assert!(z.has_id((*flecs::IsA, c))); + assert!(z.has((*flecs::IsA, c))); } #[test] @@ -2651,7 +2633,7 @@ fn entity_insert() { let world = World::new(); let e = world.entity().set(Position { x: 10, y: 20 }); - assert!(e.has::()); + assert!(e.has(id::())); e.get::<&Position>(|p| { assert_eq!(p.x, 10); @@ -2671,7 +2653,7 @@ fn entity_entity_id_str() { fn entity_pair_id_str() { let world = World::new(); - let id = world.id_from_id((world.entity_named("Rel"), world.entity_named("Obj"))); + let id = world.id_view_from((world.entity_named("Rel"), world.entity_named("Obj"))); assert_eq!(id.to_str(), "(Rel,Obj)"); } @@ -2680,7 +2662,7 @@ fn entity_pair_id_str() { fn entity_role_id_str() { let world = World::new(); - let id = world.id_from_id(flecs::id_flags::AutoOverride::ID | world.entity_named("Foo").id()); + let id = world.id_view_from(flecs::id_flags::AutoOverride::ID | world.entity_named("Foo").id()); assert_eq!(id.to_str(), "AUTO_OVERRIDE|Foo"); } @@ -2716,10 +2698,10 @@ fn entity_is_wildcard() { let e2 = world.entity(); let p0 = e1; - let p1 = world.id_from_id((e1, e2)); - let p2 = world.id_from_id((e1, *flecs::Wildcard)); - let p3 = world.id_from_id((*flecs::Wildcard, e2)); - let p4 = world.id_from_id((*flecs::Wildcard, *flecs::Wildcard)); + let p1 = world.id_view_from((e1, e2)); + let p2 = world.id_view_from((e1, *flecs::Wildcard)); + let p3 = world.id_view_from((*flecs::Wildcard, e2)); + let p4 = world.id_view_from((*flecs::Wildcard, *flecs::Wildcard)); assert!(!e1.is_wildcard()); assert!(!e2.is_wildcard()); @@ -2737,10 +2719,10 @@ fn entity_has_id_t() { let id_1 = world.entity(); let id_2 = world.entity(); - let e = world.entity().add_id(id_1); + let e = world.entity().add(id_1); - assert!(e.has_id(id_1)); - assert!(!e.has_id(id_2)); + assert!(e.has(id_1)); + assert!(!e.has(id_2)); } #[test] @@ -2751,10 +2733,10 @@ fn entity_has_pair_id_t() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_id((id_1, id_2)); + let e = world.entity().add((id_1, id_2)); - assert!(e.has_id((id_1, id_2))); - assert!(!e.has_id((id_1, id_3))); + assert!(e.has((id_1, id_2))); + assert!(!e.has((id_1, id_3))); } #[test] @@ -2764,10 +2746,10 @@ fn entity_has_pair_id_t_w_type() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_first::(id_2); + let e = world.entity().add((id::(), id_2)); - assert!(e.has_first::(id_2)); - assert!(!e.has_first::(id_3)); + assert!(e.has((id::(), id_2))); + assert!(!e.has((id::(), id_3))); } #[test] @@ -2777,10 +2759,10 @@ fn entity_has_id() { let id_1 = world.entity(); let id_2 = world.entity(); - let e = world.entity().add_id(id_1); + let e = world.entity().add(id_1); - assert!(e.has_id(id_1)); - assert!(!e.has_id(id_2)); + assert!(e.has(id_1)); + assert!(!e.has(id_2)); } #[test] @@ -2791,10 +2773,10 @@ fn entity_has_pair_id() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_id((id_1, id_2)); + let e = world.entity().add((id_1, id_2)); - assert!(e.has_id((id_1, id_2))); - assert!(!e.has_id((id_1, id_3))); + assert!(e.has((id_1, id_2))); + assert!(!e.has((id_1, id_3))); } #[test] @@ -2804,10 +2786,10 @@ fn entity_has_pair_id_w_type() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_first::(id_2); + let e = world.entity().add((id::(), id_2)); - assert!(e.has_first::(id_2)); - assert!(!e.has_first::(id_3)); + assert!(e.has((id::(), id_2))); + assert!(!e.has((id::(), id_3))); } #[test] @@ -2816,11 +2798,11 @@ fn entity_has_wildcard_id() { let id = world.entity(); - let e1 = world.entity().add_id(id); + let e1 = world.entity().add(id); let e2 = world.entity(); - assert!(e1.has_id(*flecs::Wildcard)); - assert!(!e2.has_id(*flecs::Wildcard)); + assert!(e1.has(*flecs::Wildcard)); + assert!(!e2.has(*flecs::Wildcard)); } #[test] @@ -2831,29 +2813,29 @@ fn entity_has_wildcard_pair_id() { let obj = world.entity(); let obj_2 = world.entity(); - let w1 = world.id_from_id((rel, *flecs::Wildcard)); - let w2 = world.id_from_id((*flecs::Wildcard, obj)); + let w1 = world.id_view_from((rel, *flecs::Wildcard)); + let w2 = world.id_view_from((*flecs::Wildcard, obj)); - let e1 = world.entity().add_id((rel, obj)); - let e2 = world.entity().add_id((rel, obj_2)); + let e1 = world.entity().add((rel, obj)); + let e2 = world.entity().add((rel, obj_2)); - assert!(e1.has_id(w1)); - assert!(e1.has_id(w2)); - assert!(e2.has_id(w1)); - assert!(!e2.has_id(w2)); + assert!(e1.has(w1)); + assert!(e1.has(w2)); + assert!(e2.has(w1)); + assert!(!e2.has(w2)); } #[test] -fn entity_owns_id_t() { +fn entity_owns_t() { let world = World::new(); let id_1 = world.entity(); let id_2 = world.entity(); - let e = world.entity().add_id(id_1); + let e = world.entity().add(id_1); - assert!(e.owns_id(id_1)); - assert!(!e.owns_id(id_2)); + assert!(e.owns(id_1)); + assert!(!e.owns(id_2)); } #[test] @@ -2864,10 +2846,10 @@ fn entity_owns_pair_id_t() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_id((id_1, id_2)); + let e = world.entity().add((id_1, id_2)); - assert!(e.owns_id((id_1, id_2))); - assert!(!e.owns_id((id_1, id_3))); + assert!(e.owns((id_1, id_2))); + assert!(!e.owns((id_1, id_3))); } #[test] @@ -2877,23 +2859,23 @@ fn entity_owns_pair_id_t_w_type() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_first::(id_2); + let e = world.entity().add((id::(), id_2)); - assert!(e.owns_first::(id_2)); - assert!(!e.owns_first::(id_3)); + assert!(e.owns((id::(), id_2))); + assert!(!e.owns((id::(), id_3))); } #[test] -fn entity_owns_id() { +fn entity_owns() { let world = World::new(); let id_1 = world.entity(); let id_2 = world.entity(); - let e = world.entity().add_id(id_1); + let e = world.entity().add(id_1); - assert!(e.owns_id(id_1)); - assert!(!e.owns_id(id_2)); + assert!(e.owns(id_1)); + assert!(!e.owns(id_2)); } #[test] @@ -2904,10 +2886,10 @@ fn entity_owns_pair_id() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_id((id_1, id_2)); + let e = world.entity().add((id_1, id_2)); - assert!(e.owns_id((id_1, id_2))); - assert!(!e.owns_id((id_1, id_3))); + assert!(e.owns((id_1, id_2))); + assert!(!e.owns((id_1, id_3))); } #[test] @@ -2916,11 +2898,11 @@ fn entity_owns_wildcard_id() { let id = world.entity(); - let e1 = world.entity().add_id(id); + let e1 = world.entity().add(id); let e2 = world.entity(); - assert!(e1.owns_id(*flecs::Wildcard)); - assert!(!e2.owns_id(*flecs::Wildcard)); + assert!(e1.owns(*flecs::Wildcard)); + assert!(!e2.owns(*flecs::Wildcard)); } #[test] @@ -2931,16 +2913,16 @@ fn entity_owns_wildcard_pair() { let obj = world.entity(); let obj_2 = world.entity(); - let w1 = world.id_from_id((rel, *flecs::Wildcard)); - let w2 = world.id_from_id((*flecs::Wildcard, obj)); + let w1 = world.id_view_from((rel, *flecs::Wildcard)); + let w2 = world.id_view_from((*flecs::Wildcard, obj)); - let e1 = world.entity().add_id((rel, obj)); - let e2 = world.entity().add_id((rel, obj_2)); + let e1 = world.entity().add((rel, obj)); + let e2 = world.entity().add((rel, obj_2)); - assert!(e1.owns_id(w1)); - assert!(e1.owns_id(w2)); - assert!(e2.owns_id(w1)); - assert!(!e2.owns_id(w2)); + assert!(e1.owns(w1)); + assert!(e1.owns(w2)); + assert!(e2.owns(w1)); + assert!(!e2.owns(w2)); } #[test] @@ -2950,10 +2932,10 @@ fn entity_owns_pair_id_w_type() { let id_2 = world.entity(); let id_3 = world.entity(); - let e = world.entity().add_first::(id_2); + let e = world.entity().add((id::(), id_2)); - assert!(e.owns_first::(id_2)); - assert!(!e.owns_first::(id_3)); + assert!(e.owns((id::(), id_2))); + assert!(!e.owns((id::(), id_3))); } #[test] @@ -2963,14 +2945,14 @@ fn entity_id_from_world() { let e = world.entity(); assert!(e.is_valid()); - let id_1 = world.id_from_id(e); + let id_1 = world.id_view_from(e); assert!(id_1.is_valid()); assert_eq!(id_1, e.id()); assert_eq!(id_1.world().ptr_mut(), world.ptr_mut()); assert!(!id_1.is_pair()); assert!(!id_1.is_wildcard()); - let id_2 = world.id_from_id(*flecs::Wildcard); + let id_2 = world.id_view_from(*flecs::Wildcard); assert!(id_2.is_valid()); assert_eq!(id_2, *flecs::Wildcard); assert_eq!(id_2.world().ptr_mut(), world.ptr_mut()); @@ -2988,14 +2970,14 @@ fn entity_id_pair_from_world() { let obj = world.entity(); assert!(obj.is_valid()); - let id_1 = world.id_from_id((rel, obj)); + let id_1 = world.id_view_from((rel, obj)); assert_eq!(id_1.first_id(), rel); assert_eq!(id_1.second_id(), obj); assert_eq!(id_1.world().ptr_mut(), world.ptr_mut()); assert!(id_1.is_pair()); assert!(!id_1.is_wildcard()); - let id_2 = world.id_from_id((rel, *flecs::Wildcard)); + let id_2 = world.id_view_from((rel, *flecs::Wildcard)); assert_eq!(id_2.first_id(), rel); assert_eq!(id_2.second_id(), *flecs::Wildcard); assert_eq!(id_2.world().ptr_mut(), world.ptr_mut()); @@ -3009,9 +2991,9 @@ fn entity_is_a_id() { let base = world.entity(); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); - assert!(e.has_id((*flecs::IsA, base))); + assert!(e.has((*flecs::IsA, base))); } #[test] @@ -3020,10 +3002,10 @@ fn entity_is_a_w_type() { let base = world.entity_from::(); - let e = world.entity().is_a::(); + let e = world.entity().is_a(id::()); - assert!(e.has_id((*flecs::IsA, base))); - assert!(e.has_second::(*flecs::IsA)); + assert!(e.has((*flecs::IsA, base))); + assert!(e.has((id::(), id::()))); } #[test] @@ -3032,9 +3014,9 @@ fn entity_child_of_id() { let base = world.entity(); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); - assert!(e.has_id((*flecs::ChildOf, base))); + assert!(e.has((*flecs::ChildOf, base))); } #[test] @@ -3043,10 +3025,10 @@ fn entity_child_of_w_type() { let base = world.entity_from::(); - let e = world.entity().child_of::(); + let e = world.entity().child_of(id::()); - assert!(e.has_id((*flecs::ChildOf, base))); - assert!(e.has_second::(*flecs::ChildOf)); + assert!(e.has((*flecs::ChildOf, base))); + assert!(e.has((*flecs::ChildOf, id::()))); } #[test] @@ -3054,12 +3036,12 @@ fn entity_slot_of() { let world = World::new(); let base = world.prefab(); - let base_child = world.prefab().child_of_id(base).slot_of_id(base); + let base_child = world.prefab().child_of(base).slot_of(base); - assert!(base_child.has_id((*flecs::SlotOf, base))); + assert!(base_child.has((*flecs::SlotOf, base))); - let inst = world.entity().is_a_id(base); - assert!(inst.has_id((base_child, *flecs::Wildcard))); + let inst = world.entity().is_a(base); + assert!(inst.has((base_child, *flecs::Wildcard))); } #[test] @@ -3067,12 +3049,12 @@ fn entity_slot_of_w_type() { let world = World::new(); let base = world.prefab_type::(); - let base_child = world.prefab().child_of_id(base).slot_of::(); + let base_child = world.prefab().child_of(base).slot_of(id::()); - assert!(base_child.has_id((*flecs::SlotOf, base))); + assert!(base_child.has((*flecs::SlotOf, base))); - let inst = world.entity().is_a_id(base); - assert!(inst.has_id((base_child, *flecs::Wildcard))); + let inst = world.entity().is_a(base); + assert!(inst.has((base_child, *flecs::Wildcard))); } #[test] @@ -3080,12 +3062,12 @@ fn entity_slot() { let world = World::new(); let base = world.prefab(); - let base_child = world.prefab().child_of_id(base).slot(); + let base_child = world.prefab().child_of(base).slot(); - assert!(base_child.has_id((*flecs::SlotOf, base))); + assert!(base_child.has((*flecs::SlotOf, base))); - let inst = world.entity().is_a_id(base); - assert!(inst.has_id((base_child, *flecs::Wildcard))); + let inst = world.entity().is_a(base); + assert!(inst.has((base_child, *flecs::Wildcard))); } #[test] @@ -3094,7 +3076,7 @@ fn entity_id_get_entity() { let e = world.entity(); - let id = world.id_from_id(e); + let id = world.id_view_from(e); assert_eq!(id.entity_view(), e); } @@ -3106,7 +3088,7 @@ fn entity_id_get_invalid_entity() { let r = world.entity(); let o = world.entity(); - let id = world.id_from_id((r, o)); + let id = world.id_view_from((r, o)); assert!(!id.is_valid()); } @@ -3115,17 +3097,17 @@ fn entity_id_get_invalid_entity() { fn entity_each_in_stage() { let world = World::new(); - let e = world.entity().add::<(Rel, Obj)>(); - assert!(e.has::<(Rel, Obj)>()); + let e = world.entity().add((id::(), id::())); + assert!(e.has((id::(), id::()))); world.readonly_begin(false); let s = world.stage(0); let em = e.mut_current_stage(s); - assert!(em.has::<(Rel, Obj)>()); + assert!(em.has((id::(), id::()))); let mut count = 0; - em.each_target::(|obj| { + em.each_target(id::(), |obj| { count += 1; assert_eq!(obj, world.entity_from::()); }); @@ -3146,7 +3128,7 @@ fn entity_iter_recycled_parent() { assert_ne!(e, e2); assert_eq!(*e.id() as u32, *e2.id() as u32); - let e_child = world.entity().child_of_id(e2); + let e_child = world.entity().child_of(e2); let mut count = 0; e2.each_child(|child| { @@ -3165,11 +3147,11 @@ fn entity_get_obj_by_template() { let o1 = world.entity(); let o2 = world.entity(); - e1.add_first::(o1); - e1.add_first::(o2); + e1.add((id::(), o1)); + e1.add((id::(), o2)); - assert_eq!(o1, e1.target::(0).unwrap()); - assert_eq!(o2, e1.target::(1).unwrap()); + assert_eq!(o1, e1.target(id::(), 0).unwrap()); + assert_eq!(o2, e1.target(id::(), 1).unwrap()); } #[test] @@ -3204,10 +3186,10 @@ fn entity_clone() { let v = Position { x: 10, y: 20 }; - let src = world.entity().add::().set(v); + let src = world.entity().add(id::()).set(v); let dst = src.duplicate(true); - assert!(dst.has::()); - assert!(dst.has::()); + assert!(dst.has(id::())); + assert!(dst.has(id::())); dst.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -3221,10 +3203,10 @@ fn entity_clone_w_value() { let v = Position { x: 10, y: 20 }; - let src = world.entity().add::().set(v); + let src = world.entity().add(id::()).set(v); let dst = src.duplicate(true); - assert!(dst.has::()); - assert!(dst.has::()); + assert!(dst.has(id::())); + assert!(dst.has(id::())); dst.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -3238,13 +3220,13 @@ fn entity_clone_to_existing() { let v = Position { x: 10, y: 20 }; - let src = world.entity().add::().set(v); + let src = world.entity().add(id::()).set(v); let dst = world.entity(); let result = src.duplicate_into(true, dst); assert_eq!(result, dst); - assert!(dst.has::()); - assert!(dst.has::()); + assert!(dst.has(id::())); + assert!(dst.has(id::())); dst.get::<&Position>(|pos| { assert_eq!(pos.x, 10); @@ -3260,7 +3242,7 @@ fn entity_clone_to_existing_overlap() { let v = Position { x: 10, y: 20 }; - let src = world.entity().add::().set(v); + let src = world.entity().add(id::()).set(v); let dst = world.entity().set(Position { x: 0, y: 0 }); src.duplicate_into(true, dst); @@ -3282,9 +3264,9 @@ fn entity_entity_w_root_name_from_scope() { let world = World::new(); let p = world.entity_named("parent"); - world.set_scope_id(p); + world.set_scope(p); let e = world.entity_named("::foo"); - world.set_scope_id(0); + world.set_scope(0); assert_eq!(e.name(), "foo"); assert_eq!(e.path().unwrap(), "::foo"); @@ -3298,7 +3280,7 @@ fn entity_entity_w_type() { assert_eq!(e.name(), "EntityType"); assert_eq!(e.path().unwrap(), "::flecs::common_test::EntityType"); - //assert!(!e.has::()); + //assert!(!e.has(id::())); //TODO this assert should work, but we register it a bit different than cpp, no problem though. let e_2 = world.entity_from::(); assert_eq!(e, e_2); @@ -3312,9 +3294,9 @@ fn entity_prefab_w_type() { assert_eq!(e.name(), "EntityType"); assert_eq!(e.path().unwrap(), "::flecs::common_test::EntityType"); - //assert!(!e.has::()); + //assert!(!e.has(id::())); //TODO this assert should work, but we register it a bit different than cpp, no problem though. - assert!(e.has::()); + assert!(e.has(id::())); let e_2 = world.entity_from::(); assert_eq!(e, e_2); @@ -3327,12 +3309,12 @@ fn entity_prefab_hierarchy_w_types() { let turret = world.prefab_type::(); let turret_base = world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); assert!(turret.is_valid()); assert!(turret_base.is_valid()); - assert!(turret_base.has_id((*flecs::ChildOf, turret))); + assert!(turret_base.has((*flecs::ChildOf, turret))); assert_eq!(turret.path().unwrap(), "::flecs::common_test::Turret"); assert_eq!( @@ -3343,24 +3325,24 @@ fn entity_prefab_hierarchy_w_types() { assert_eq!(turret.symbol(), "flecs::common_test::Turret"); assert_eq!(turret_base.symbol(), "flecs::common_test::Base"); - let railgun = world.prefab_type::().is_a::(); + let railgun = world.prefab_type::().is_a(id::()); let railgun_base = railgun.lookup_recursive("Base"); let railgun_head = world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); let railgun_beam = world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); assert!(railgun.is_valid()); assert!(railgun_base.is_valid()); assert!(railgun_head.is_valid()); assert!(railgun_beam.is_valid()); - assert!(railgun_base.has_id((*flecs::ChildOf, railgun))); - assert!(railgun_head.has_id((*flecs::ChildOf, railgun))); - assert!(railgun_beam.has_id((*flecs::ChildOf, railgun))); + assert!(railgun_base.has((*flecs::ChildOf, railgun))); + assert!(railgun_head.has((*flecs::ChildOf, railgun))); + assert!(railgun_beam.has((*flecs::ChildOf, railgun))); assert_eq!(railgun.path().unwrap(), "::flecs::common_test::Railgun"); assert_eq!( @@ -3388,12 +3370,12 @@ fn entity_prefab_hierarchy_w_root_types() { let turret = world.prefab_type::(); let turret_base = world .prefab_type::() - .child_of::() - .slot_of::(); + .child_of(id::()) + .slot_of(id::()); assert!(turret.is_valid()); assert!(turret_base.is_valid()); - assert!(turret_base.has_id((*flecs::ChildOf, turret))); + assert!(turret_base.has((*flecs::ChildOf, turret))); assert_eq!(turret.path().unwrap(), "::flecs::common_test::Turret"); assert_eq!( @@ -3404,7 +3386,7 @@ fn entity_prefab_hierarchy_w_root_types() { assert_eq!(turret.symbol(), "flecs::common_test::Turret"); assert_eq!(turret_base.symbol(), "flecs::common_test::Base"); - let inst = world.entity().is_a::(); + let inst = world.entity().is_a(id::()); assert!(inst.is_valid()); let inst_base = inst.lookup_recursive("Base"); @@ -3418,11 +3400,11 @@ fn entity_entity_array() { let entities = [world.entity(), world.entity(), world.entity()]; for e in entities.iter() { - e.add::().add::(); + e.add(id::()).add(id::()); } - assert_eq!(world.count::(), 3); - assert_eq!(world.count::(), 3); + assert_eq!(world.count(id::()), 3); + assert_eq!(world.count(id::()), 3); } #[test] @@ -3437,7 +3419,7 @@ fn entity_entity_w_type_defer() { assert_eq!(e.name(), "Tag"); assert_eq!(e.symbol(), "flecs::common_test::Tag"); - assert_eq!(world.id_from::(), e); + assert_eq!(world.id_view_from(id::()), e); } #[test] @@ -3446,8 +3428,8 @@ fn entity_add_if_true_t() { let e = world.entity(); - e.add_if::(true); - assert!(e.has::()); + e.add_if(id::(), true); + assert!(e.has(id::())); } #[test] @@ -3456,13 +3438,13 @@ fn entity_add_if_false_t() { let e = world.entity(); - e.add_if::(false); - assert!(!e.has::()); + e.add_if(id::(), false); + assert!(!e.has(id::())); - e.add::(); - assert!(e.has::()); - e.add_if::(false); - assert!(!e.has::()); + e.add(id::()); + assert!(e.has(id::())); + e.add_if(id::(), false); + assert!(!e.has(id::())); } #[test] @@ -3472,8 +3454,8 @@ fn entity_add_if_true_id() { let e = world.entity(); let t = world.entity(); - e.add_id_if(t, true); - assert!(e.has_id(t)); + e.add_if(t, true); + assert!(e.has(t)); } #[test] @@ -3483,13 +3465,13 @@ fn entity_add_if_false_id() { let e = world.entity(); let t = world.entity(); - e.add_id_if(t, false); - assert!(!e.has_id(t)); + e.add_if(t, false); + assert!(!e.has(t)); - e.add_id(t); - assert!(e.has_id(t)); - e.add_id_if(t, false); - assert!(!e.has_id(t)); + e.add(t); + assert!(e.has(t)); + e.add_if(t, false); + assert!(!e.has(t)); } #[test] @@ -3498,8 +3480,8 @@ fn entity_add_if_true_r_o() { let e = world.entity(); - e.add_if::<(Rel, Obj)>(true); - assert!(e.has::<(Rel, Obj)>()); + e.add_if((id::(), id::()), true); + assert!(e.has((id::(), id::()))); } #[test] @@ -3507,12 +3489,12 @@ fn entity_add_if_false_r_o() { let world = World::new(); let e = world.entity(); - e.add_if::<(Rel, Obj2)>(false); - assert!(!e.has::<(Rel, Obj2)>()); - e.add::<(Rel, Obj2)>(); - assert!(e.has::<(Rel, Obj2)>()); - e.add_if::<(Rel, Obj2)>(false); - assert!(!e.has::<(Rel, Obj2)>()); + e.add_if((id::(), id::()), false); + assert!(!e.has((id::(), id::()))); + e.add((id::(), id::())); + assert!(e.has((id::(), id::()))); + e.add_if((id::(), id::()), false); + assert!(!e.has((id::(), id::()))); } #[test] @@ -3522,8 +3504,8 @@ fn entity_add_if_true_r_o_2() { let e = world.entity(); let o = world.entity(); - e.add_first_if::(o, true); - assert!(e.has_first::(o)); + e.add_if((id::(), o), true); + assert!(e.has((id::(), o))); } #[test] @@ -3533,12 +3515,12 @@ fn entity_add_if_false_r_o_2() { let e = world.entity(); let o = world.entity(); - e.add_first_if::(o, false); - assert!(!e.has_first::(o)); - e.add_first::(o); - assert!(e.has_first::(o)); - e.add_first_if::(o, false); - assert!(!e.has_first::(o)); + e.add_if((id::(), o), false); + assert!(!e.has((id::(), o))); + e.add((id::(), o)); + assert!(e.has((id::(), o))); + e.add_if((id::(), o), false); + assert!(!e.has((id::(), o))); } #[test] @@ -3549,8 +3531,8 @@ fn entity_add_if_true_r_o_3() { let r = world.entity(); let o = world.entity(); - e.add_id_if((r, o), true); - assert!(e.has_id((r, o))); + e.add_if((r, o), true); + assert!(e.has((r, o))); } #[test] @@ -3561,12 +3543,12 @@ fn entity_add_if_false_r_o_3() { let r = world.entity(); let o = world.entity(); - e.add_id_if((r, o), false); - assert!(!e.has_id((r, o))); - e.add_id((r, o)); - assert!(e.has_id((r, o))); - e.add_id_if((r, o), false); - assert!(!e.has_id((r, o))); + e.add_if((r, o), false); + assert!(!e.has((r, o))); + e.add((r, o)); + assert!(e.has((r, o))); + e.add_if((r, o), false); + assert!(!e.has((r, o))); } #[test] @@ -3574,62 +3556,62 @@ fn entity_add_if_exclusive_r_o() { let world = World::new(); let e = world.entity(); - let r = world.entity().add::(); + let r = world.entity().add(flecs::Exclusive::ID); let o_1 = world.entity(); let o_2 = world.entity(); - e.add_id((r, o_1)); - assert!(e.has_id((r, o_1))); + e.add((r, o_1)); + assert!(e.has((r, o_1))); - e.add_id_if((r, o_2), true); - assert!(!e.has_id((r, o_1))); - assert!(e.has_id((r, o_2))); + e.add_if((r, o_2), true); + assert!(!e.has((r, o_1))); + assert!(e.has((r, o_2))); - e.add_id_if((r, o_1), false); - assert!(!e.has_id((r, o_1))); - assert!(!e.has_id((r, o_2))); + e.add_if((r, o_1), false); + assert!(!e.has((r, o_1))); + assert!(!e.has((r, o_2))); } #[test] fn entity_add_if_exclusive_r_o_2() { let world = World::new(); - world.component::().add::(); + world.component::().add(flecs::Exclusive::ID); let e = world.entity(); let o_1 = world.entity(); let o_2 = world.entity(); - e.add_first::(o_1); - assert!(e.has_first::(o_1)); + e.add((id::(), o_1)); + assert!(e.has((id::(), o_1))); - e.add_first_if::(o_2, true); - assert!(!e.has_first::(o_1)); - assert!(e.has_first::(o_2)); + e.add_if((id::(), o_2), true); + assert!(!e.has((id::(), o_1))); + assert!(e.has((id::(), o_2))); - e.add_first_if::(o_1, false); - assert!(!e.has_first::(o_1)); - assert!(!e.has_first::(o_2)); + e.add_if((id::(), o_1), false); + assert!(!e.has((id::(), o_1))); + assert!(!e.has((id::(), o_2))); } #[test] fn entity_add_if_exclusive_r_o_3() { let world = World::new(); - world.component::().add::(); + world.component::().add(id::()); let e = world.entity(); - e.add::<(Rel, Obj)>(); - assert!(e.has::<(Rel, Obj)>()); + e.add((id::(), id::())); + assert!(e.has((id::(), id::()))); - e.add_if::<(Rel, Obj2)>(true); - assert!(!e.has::<(Rel, Obj)>()); - assert!(e.has::<(Rel, Obj2)>()); + e.add_if((id::(), id::()), true); + assert!(!e.has((id::(), id::()))); + assert!(e.has((id::(), id::()))); - e.add_if::<(Rel, Obj)>(false); - assert!(!e.has::<(Rel, Obj)>()); - assert!(!e.has::<(Rel, Obj2)>()); + e.add_if((id::(), id::()), false); + assert!(!e.has((id::(), id::()))); + assert!(!e.has((id::(), id::()))); } #[test] @@ -3640,12 +3622,12 @@ fn entity_add_if_pair_w_0_object() { let r = world.entity(); let o_1 = world.entity(); - e.add_id((r, o_1)); - assert!(e.has_id((r, o_1))); + e.add((r, o_1)); + assert!(e.has((r, o_1))); - e.add_id_if((r, 0), false); - assert!(!e.has_id((r, o_1))); - assert!(!e.has_id((r, *flecs::Wildcard))); + e.add_if((r, 0), false); + assert!(!e.has((r, o_1))); + assert!(!e.has((r, *flecs::Wildcard))); } #[test] @@ -3655,15 +3637,15 @@ fn entity_children_w_custom_relation() { let rel = world.entity(); let parent = world.entity(); - let child_1 = world.entity().add_id((rel, parent)); - let child_2 = world.entity().add_id((rel, parent)); - world.entity().child_of_id(parent); + let child_1 = world.entity().add((rel, parent)); + let child_2 = world.entity().add((rel, parent)); + world.entity().child_of(parent); let mut child_1_found = false; let mut child_2_found = false; let mut count = 0; - parent.each_child_of_id(rel, |child| { + parent.each_child_of(rel, |child| { if child == child_1 { child_1_found = true; } else if child == child_2 { @@ -3682,15 +3664,15 @@ fn entity_children_w_custom_relation_type() { let world = World::new(); let parent = world.entity(); - let child_1 = world.entity().add_first::(parent); - let child_2 = world.entity().add_first::(parent); - world.entity().child_of_id(parent); + let child_1 = world.entity().add((id::(), parent)); + let child_2 = world.entity().add((id::(), parent)); + world.entity().child_of(parent); let mut child_1_found = false; let mut child_2_found = false; let mut count = 0; - parent.each_child_of::(|child| { + parent.each_child_of(id::(), |child| { if child == child_1 { child_1_found = true; } else if child == child_2 { @@ -3766,31 +3748,31 @@ fn entity_get_depth() { let world = World::new(); let e1 = world.entity(); - let e2 = world.entity().child_of_id(e1); - let e3 = world.entity().child_of_id(e2); - let e4 = world.entity().child_of_id(e3); + let e2 = world.entity().child_of(e1); + let e3 = world.entity().child_of(e2); + let e4 = world.entity().child_of(e3); - assert_eq!(e1.depth_id(*flecs::ChildOf), 0); - assert_eq!(e2.depth_id(*flecs::ChildOf), 1); - assert_eq!(e3.depth_id(*flecs::ChildOf), 2); - assert_eq!(e4.depth_id(*flecs::ChildOf), 3); + assert_eq!(e1.depth(*flecs::ChildOf), 0); + assert_eq!(e2.depth(*flecs::ChildOf), 1); + assert_eq!(e3.depth(*flecs::ChildOf), 2); + assert_eq!(e4.depth(*flecs::ChildOf), 3); } #[test] fn entity_get_depth_w_type() { let world = World::new(); - world.component::().add::(); + world.component::().add(id::()); let e1 = world.entity(); - let e2 = world.entity().add_first::(e1); - let e3 = world.entity().add_first::(e2); - let e4 = world.entity().add_first::(e3); + let e2 = world.entity().add((id::(), e1)); + let e3 = world.entity().add((id::(), e2)); + let e4 = world.entity().add((id::(), e3)); - assert_eq!(e1.depth::(), 0); - assert_eq!(e2.depth::(), 1); - assert_eq!(e3.depth::(), 2); - assert_eq!(e4.depth::(), 3); + assert_eq!(e1.depth(id::()), 0); + assert_eq!(e2.depth(id::()), 1); + assert_eq!(e3.depth(id::()), 2); + assert_eq!(e4.depth(id::()), 3); } #[test] @@ -3810,15 +3792,15 @@ fn entity_insert_w_observer() { world .observer::() - .with::() + .with(id::()) .each_entity(|e, _| { e.set(Velocity { x: 1, y: 2 }); }); let e = world.entity().set(Position { x: 10, y: 20 }); - assert!(e.has::()); - assert!(e.has::()); + assert!(e.has(id::())); + assert!(e.has(id::())); e.get::<(&Position, &Velocity)>(|(pos, vel)| { assert_eq!(pos.x, 10); assert_eq!(pos.y, 20); @@ -3849,14 +3831,14 @@ fn entity_world_lookup_not_recursive() { fn entity_override_sparse() { let world = World::new(); - world.component::().add::(); + world.component::().add(id::()); let base = world.entity().set(Velocity { x: 1, y: 2 }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); - assert!(e.has::()); - assert!(e.owns::()); + assert!(e.has(id::())); + assert!(e.owns(id::())); e.get::<&Velocity>(|v| { assert_eq!(v.x, 1); @@ -3868,14 +3850,14 @@ fn entity_override_sparse() { fn entity_delete_w_override_sparse() { let world = World::new(); - world.component::().add::(); + world.component::().add(id::()); let base = world.entity().set(Velocity { x: 1, y: 2 }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); - assert!(e.has::()); - assert!(e.owns::()); + assert!(e.has(id::())); + assert!(e.owns(id::())); e.get::<&Velocity>(|v| { assert_eq!(v.x, 1); @@ -3889,7 +3871,7 @@ fn entity_delete_w_override_sparse() { fn entity_iter_type() { let world = World::new(); - let e = world.entity().add::().add::(); + let e = world.entity().add(id::()).add(id::()); let mut count = 0; let mut pos_found = false; @@ -3897,10 +3879,10 @@ fn entity_iter_type() { for id in e.archetype().as_slice() { count += 1; - if *id == world.id_from::() { + if *id == world.id_view_from(flecs_ecs::core::id::()) { pos_found = true; } - if *id == world.id_from::() { + if *id == world.id_view_from(flecs_ecs::core::id::()) { velocity_found = true; } } diff --git a/flecs_ecs/tests/flecs/eq_test.rs b/flecs_ecs/tests/flecs/eq_test.rs index b495d62d..90a3ce73 100644 --- a/flecs_ecs/tests/flecs/eq_test.rs +++ b/flecs_ecs/tests/flecs/eq_test.rs @@ -14,7 +14,7 @@ fn entity_eq_test() { let e1_id: Id = e1_entity.into(); let comp1 = world.component::(); - let comp_untyped1 = world.component_untyped_from::(); + let comp_untyped1 = world.component_untyped_from(id::()); assert_eq!(e1_id, e1_id); assert_eq!(e1_id, e1_entity); @@ -119,9 +119,9 @@ fn entity_eq_test() { fn table_eq_test() { let world = World::new(); - let ent1 = world.entity().add::(); - let ent2 = world.entity().add::(); - let ent3 = world.entity().add::().add::(); + let ent1 = world.entity().add(id::()); + let ent2 = world.entity().add(id::()); + let ent3 = world.entity().add(id::()).add(id::()); let table1 = ent1.table().unwrap(); let table2 = ent2.table().unwrap(); @@ -130,7 +130,7 @@ fn table_eq_test() { assert_eq!(table1, table2); assert_ne!(table1, table3); - ent1.add::(); + ent1.add(id::()); let table1 = ent1.table().unwrap(); assert_ne!(table1, table2); diff --git a/flecs_ecs/tests/flecs/flecs_docs_test.rs b/flecs_ecs/tests/flecs/flecs_docs_test.rs index 9c549160..c759a5a9 100644 --- a/flecs_ecs/tests/flecs/flecs_docs_test.rs +++ b/flecs_ecs/tests/flecs/flecs_docs_test.rs @@ -150,7 +150,7 @@ fn flecs_system_docs_compile_test() { world .system_named::<(&mut Position, &Velocity)>("Move") - .kind_id(0) + .kind(0) .each(|(p, v)| { p.x += v.x; p.y += v.y; @@ -259,7 +259,7 @@ fn flecs_system_docs_compile_test() { .system_named::<&Game>("PrintTime") .term_at(0) .singleton() - .kind::() + .kind(id::()) .run(|mut it| { while it.next() { println!("Time: {}", it.field::(0).unwrap()[9].time); @@ -268,7 +268,7 @@ fn flecs_system_docs_compile_test() { world .system_named::<(&mut Position, &Velocity)>("Move") - .kind::() + .kind(id::()) .each(|(p, v)| { // ... }); @@ -278,9 +278,11 @@ fn flecs_system_docs_compile_test() { struct Physics; // a component to represent the phase - let physics = world.component::().add::(); + let physics = world + .component::() + .add(id::()); // a (dynamic) entity to represent the phase - let collisions = world.entity().add::(); + let collisions = world.entity().add(id::()); // Phases can (but don't have to) depend on other phases which forces ordering physics.add_trait::<(flecs::DependsOn, flecs::pipeline::OnUpdate)>(); @@ -289,36 +291,36 @@ fn flecs_system_docs_compile_test() { // Custom phases can be used just like regular phases world .system_named::<(&Position, &Velocity)>("Collide") - .kind_id(collisions) // .kind::() + .kind(collisions) // .has(id::()) .each(|(p, v)| { // ... }); world .pipeline() - .with::() - .with::() - .cascade_type::() - .without::() - .up_type::() - .without::() - .up_type::() + .with(id::()) + .with(id::()) + .cascade_id(id::()) + .without(id::()) + .up_id(id::()) + .without(id::()) + .up_id(id::()) .build(); // Create custom pipeline let pipeline = world .pipeline() - .with::() - .with::() // or `.with_id(foo) if an id` + .with(id::()) + .with(id::()) // or `.with(foo) if an id` .build(); // Configure the world to use the custom pipeline - world.set_pipeline_id(pipeline); + world.set_pipeline(pipeline); // Create system world .system_named::<(&mut Position, &Velocity)>("Move") - .kind::() // or `.kind_id(foo) if an id` + .kind(id::()) // or `.kind(foo) if an id` .each(|(p, v)| { p.x += v.x; p.y += v.y; @@ -329,15 +331,21 @@ fn flecs_system_docs_compile_test() { sys.disable_self(); sys.enable_self(); - sys.add::(); + sys.add(id::()); - world.system::<&Position>().write::().each(|p| { - // ... - }); + world + .system::<&Position>() + .with(id::<&mut Transform>()) + .each(|p| { + // ... + }); - world.system::<&Position>().read::().each(|p| { - // ... - }); + world + .system::<&Position>() + .with(id::<&Transform>()) + .each(|p| { + // ... + }); world .system_named::<&Plate>("AssignPlate") @@ -434,10 +442,10 @@ fn flecs_query_docs_compile_test() { let add_npc = true; let mut q = world.query::<(&mut Position, &Velocity)>(); - q.with::<&Velocity>(); + q.with(id::<&Velocity>()); if add_npc { - q.with::<&Foo>(); // Conditionally add + q.with(id::<&Foo>()); // Conditionally add } q.build(); // Create query @@ -452,11 +460,15 @@ fn flecs_query_docs_compile_test() { let q = world .query::<&Position>() - .with::<(&Likes, &flecs::Wildcard)>() + .read((id::(), id::())) .build(); q.each_iter(|it, index, p| { - println!("Entity: {}: {}", it.entity(index).name(), it.id(1).to_str()); + println!( + "Entity: {}: {}", + it.entity(index).unwrap().name(), + it.id(1).to_str() + ); }); #[derive(Component, Default)] @@ -466,7 +478,7 @@ fn flecs_query_docs_compile_test() { world .query::<()>() - .with::<&Tag>() + .with(id::<&Tag>()) .build() .each_entity(|e, _| { /* */ }); @@ -479,7 +491,7 @@ fn flecs_query_docs_compile_test() { for i in it.iter() { p[i].x += v[i].x; p[i].y += v[i].y; - println!("Entity: {}", it.entity(i).name()); + println!("Entity: {}", it.entity(i).unwrap().name()); } } }); @@ -487,14 +499,14 @@ fn flecs_query_docs_compile_test() { let q = world.new_query::<&Position>(); q.each_entity(|e, p| { - e.add::(); // OK + e.add(id::()); // OK }); let q = world.new_query::<&Position>(); world.defer(|| { q.each_entity(|e, p| { - e.add::(); // OK + e.add(id::()); // OK }); }); // operations are executed here @@ -503,7 +515,7 @@ fn flecs_query_docs_compile_test() { world.defer_begin(); q.each_entity(|e, p| { - e.add::(); // OK + e.add(id::()); // OK }); world.defer_end(); // operations are executed here @@ -512,15 +524,18 @@ fn flecs_query_docs_compile_test() { q.each(|(p, v)| { /* */ }); - let q = world.query::<&mut Position>().with::<&Velocity>().build(); + let q = world + .query::<&mut Position>() + .with(id::<&Velocity>()) + .build(); let npc = world.entity(); let platoon_01 = world.entity(); let q = world .query::<(&mut Position, &Velocity)>() - .with_id(npc) - .with_id(platoon_01) + .with(npc) + .with(platoon_01) .build(); // Register component type so we can look it up by name @@ -531,17 +546,17 @@ fn flecs_query_docs_compile_test() { let q = world .query::<(&Position, &Npc)>() - .with_name("npc") - .with_name("Position") + .with("npc") + .with("Position") .build(); - let e = world.entity().add::().add::(); + let e = world.entity().add(id::()).add(id::()); - let q = world.query::<()>().with::().build(); + let q = world.query::<()>().with(id::()).build(); - let e = world.entity().add::().add::(); + let e = world.entity().add(id::()).add(id::()); - let q = world.query::<()>().with::().build(); + let q = world.query::<()>().with(id::()).build(); #[derive(Component, Default)] struct Eats { @@ -560,35 +575,38 @@ fn flecs_query_docs_compile_test() { let eats = world.component::(); let apples = world.component::(); - let q1 = world.query::<()>().with::<(Eats, Apples)>().build(); + let q1 = world + .query::<()>() + .with((id::(), id::())) + .build(); - let q2 = world.query::<()>().with_first::(apples).build(); + let q2 = world.query::<()>().with((id::(), apples)).build(); - let q3 = world.query::<()>().with_id((eats, apples)).build(); + let q3 = world.query::<()>().with((eats, apples)).build(); let q = world .query::<()>() .term() - .set_first::() - .set_second_id(apples) + .set_first(id::()) + .set_second(apples) .build(); let q = world .query::<()>() .term() - .set_first_name("Eats") - .set_second_name("Apples") + .set_first("Eats") + .set_second("Apples") .build(); let q = world .query::<()>() - .with::<(Eats, flecs::Wildcard)>() + .with((id::(), id::())) .build(); q.each_iter(|it, index, _| { let pair = it.pair(0).unwrap(); let second = pair.second_id(); - let e = it.entity(index); + let e = it.entity(index).unwrap(); println!("Entity {} likes {}", e.name(), second.name()); }); @@ -596,15 +614,15 @@ fn flecs_query_docs_compile_test() { // The following two queries are the same: let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .set_inout_kind(InOutKind::In) .build(); let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .set_in() // shorthand for .set_inout_kind(InOutKind::In) .build(); @@ -613,14 +631,14 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::<&mut Position>() - .with::<&Velocity>() // uses InOutKind::In modifier + .with(id::<&mut Position>()) + .with(id::<&Velocity>()) // uses InOutKind::In modifier .build(); let q = world .query::<()>() - .with::<&mut Position>() - .with::<&Velocity>() + .with(id::<&mut Position>()) + .with(id::<&Velocity>()) .build(); q.run(|mut it| { @@ -632,17 +650,17 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() + .with(id::()) .set_inout() - .with::() + .with(id::()) .set_in() .build(); let q = world .query::<()>() - .with::() + .with(id::()) .and() - .with::() + .with(id::()) .and() .build(); @@ -650,26 +668,26 @@ fn flecs_query_docs_compile_test() { let q2 = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .build(); let q3 = world .query::<()>() - .with::() + .with(id::()) .set_oper(OperKind::And) - .with::() + .with(id::()) .set_oper(OperKind::And) .build(); // Position, Velocity || Speed, Mass let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .set_oper(OperKind::Or) - .with::() - .with::() + .with(id::()) + .with(id::()) .build(); q.run(|mut it| { @@ -692,31 +710,31 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .or() - .with::() - .with::() + .with(id::()) + .with(id::()) .build(); let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .set_oper(OperKind::Not) .build(); let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .not() .build(); let q = world .query::<()>() - .with::() - .without::() + .with(id::()) + .without(id::()) .build(); let q = world.new_query::<(&Position, Option<&Velocity>)>(); @@ -729,8 +747,8 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .set_oper(OperKind::Optional) .build(); @@ -745,69 +763,69 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .optional() .build(); world .query::<()>() // $this == Foo - .with::<(flecs::PredEq, Foo)>() + .with((id::(), id::())) // $this != Foo - .without::<(flecs::PredEq, Bar)>() + .without((id::(), id::())) // $this == "Foo" - .with::() - .set_second_name("Foo") + .with(id::()) + .set_second("Foo") .flags(sys::EcsIsName) // $this ~= "Fo" - .with::() - .set_second_name("Fo") + .with(id::()) + .set_second("Fo") .flags(sys::EcsIsName) .build(); - let type_list = world.prefab().add::().add::(); + let type_list = world.prefab().add(id::()).add(id::()); let q = world .query::<()>() - .with_id(type_list) + .with(type_list) .set_oper(OperKind::AndFrom) // match Position, Velocity - .with_id(type_list) + .with(type_list) .set_oper(OperKind::OrFrom) // match Position || Velocity - .with_id(type_list) + .with(type_list) .set_oper(OperKind::NotFrom) // match !Position, !Velocity .build(); let q = world .query::<()>() - .with_id(type_list) + .with(type_list) .and_from() - .with_id(type_list) + .with(type_list) .or_from() - .with_id(type_list) + .with(type_list) .not_from() .build(); world .query::<()>() // Position, !{ Velocity || Speed } - .with::() + .with(id::()) .scope_open() .not() - .with::() + .with(id::()) .or() - .with::() + .with(id::()) .scope_close() .build(); - let game = world.entity().add::(); + let game = world.entity().add(id::()); let q = world .query::<()>() - .with::() // normal term, uses $this source - .with::() // normal term, uses $this source - .with::() - .set_src_id(game) // fixed source, match SimTime on Game + .with(id::()) // normal term, uses $this source + .with(id::()) // normal term, uses $this source + .with(id::()) + .set_src(game) // fixed source, match SimTime on Game .build(); q.run(|mut it| { @@ -826,7 +844,7 @@ fn flecs_query_docs_compile_test() { let q = world .query::<(&mut Position, &Velocity, &SimTime)>() .term_at(2) - .set_src_id(game) // fixed source for 3rd template argument (SimTime) + .set_src(game) // fixed source for 3rd template argument (SimTime) .build(); // Because all components are now part of the query type, we can use each @@ -835,14 +853,14 @@ fn flecs_query_docs_compile_test() { p.y += v.y * st.value; }); - let cfg = world.entity().add::(); + let cfg = world.entity().add(id::()); let q = world .query::<(&SimConfig, &mut SimTime)>() .term_at(0) - .set_src_id(cfg) + .set_src(cfg) .term_at(1) - .set_src_id(game) + .set_src(game) .build(); // Ok (note that it.count() will be 0) @@ -872,20 +890,20 @@ fn flecs_query_docs_compile_test() { let q = world .query::<(&SimConfig, &SimTime)>() .term_at(0) - .set_src_name("cfg") + .set_src("cfg") .term_at(1) - .set_src_name("game") + .set_src("game") .build(); let q = world .query::<(&Player, &Position)>() - .with::() - .set_src::() // match Input on itself + .with(id::()) + .set_src(id::()) // match Input on itself .build(); let q = world .query::<(&Player, &Position)>() - .with::() + .with(id::()) .singleton() // match Input on itself .build(); @@ -898,19 +916,19 @@ fn flecs_query_docs_compile_test() { // These three queries are the same: let q1 = world .query::<()>() - .with::() - .up_type::() + .with(id::()) + .up_id(id::()) .build(); let q2 = world .query::<()>() - .with::() + .with(id::()) .up() // defaults to .up(flecs::ChildOf) .build(); let q3 = world .query::<()>() - .with::() + .with(id::()) .parent() // shortcut for .up(flecs::ChildOf) .build(); @@ -922,14 +940,14 @@ fn flecs_query_docs_compile_test() { // These two queries are the same: let q1 = world .query::<()>() - .with::() + .with(id::()) .self_() - .up_type::() + .up_id(id::()) .build(); let q2 = world .query::<()>() - .with::() // defaults to .self().up(flecs::IsA) + .with(id::()) // defaults to .self().up(flecs::IsA) .build(); // Register an inheritable component 'Mass' @@ -937,16 +955,16 @@ fn flecs_query_docs_compile_test() { .component::() .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); - let base = world.entity().add::(); + let base = world.entity().add(id::()); - let parent = world.entity().is_a_id(base); // inherits Mass + let parent = world.entity().is_a(base); // inherits Mass - let child = world.entity().child_of_id(parent); + let child = world.entity().child_of(parent); // Matches 'child', because parent inherits Mass from prefab let q = world .query::<()>() - .with::() + .with(id::()) .up() // traverses ChildOf upwards .build(); @@ -955,9 +973,9 @@ fn flecs_query_docs_compile_test() { .component::() .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); - let base = world.entity().add::(); + let base = world.entity().add(id::()); - let inst = world.entity().is_a_id(base); // short for .add(flecs::IsA, base); + let inst = world.entity().is_a(base); // short for .add(flecs::IsA, base); // The following two queries are the same: let q1 = world.new_query::<&Position>(); @@ -969,18 +987,18 @@ fn flecs_query_docs_compile_test() { .up_id(flecs::IsA::ID) .build(); - let parent = world.entity().add::(); + let parent = world.entity().add(id::()); - let child = world.entity().child_of_id(parent); // short for .add_id((flecs::ChildOf::ID, base)); + let child = world.entity().child_of(parent); // short for .add((flecs::ChildOf::ID, base)); let q = world.query::<&Position>().term_at(0).up().build(); // Create a new traversable relationship - let contained_by = world.entity().add::(); + let contained_by = world.entity().add(id::()); - let parent = world.entity().add::(); + let parent = world.entity().add(id::()); - let child = world.entity().add_id((contained_by, parent)); + let child = world.entity().add((contained_by, parent)); let q = world .query::<&Position>() @@ -1018,20 +1036,20 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() - .with::() - .set_second_name("$Location") - .with::() - .set_src_name("$Location") + .with(id::()) + .with(id::()) + .set_second("$Location") + .with(id::()) + .set_src("$Location") .build(); let q = world .query::<()>() - .with::() - .with::() + .with(id::()) + .with(id::()) .second() .set_var("$Location") - .with::() + .with(id::()) .src() .set_var("$Location") .build(); @@ -1129,7 +1147,7 @@ fn flecs_query_docs_compile_test() { let q = world .query::<&Position>() - .with_id(depth_id) + .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) }; @@ -1151,11 +1169,11 @@ fn flecs_query_docs_compile_test() { struct Unit; let unit = world.component::(); - let melee_unit = world.entity().is_a::(); - let ranged_unit = world.entity().is_a::(); + let melee_unit = world.entity().is_a(id::()); + let ranged_unit = world.entity().is_a(id::()); - let unit_01 = world.entity().add_id(melee_unit); - let unit_02 = world.entity().add_id(ranged_unit); + let unit_01 = world.entity().add(melee_unit); + let unit_02 = world.entity().add(ranged_unit); // Matches entities with Unit, MeleeUnit and RangedUnit let q = world.query::<&Unit>(); @@ -1166,17 +1184,19 @@ fn flecs_query_docs_compile_test() { #[derive(Component)] struct LocatedIn; - world.component::().add::(); + world + .component::() + .add(id::()); let new_york = world.entity(); - let manhattan = world.entity().add_first::(new_york); - let central_park = world.entity().add_first::(manhattan); - let bob = world.entity().add_first::(central_park); + let manhattan = world.entity().add((id::(), new_york)); + let central_park = world.entity().add((id::(), manhattan)); + let bob = world.entity().add((id::(), central_park)); // Matches ManHattan, CentralPark, bob let q = world .query::<()>() - .with_first::(new_york) + .with((id::(), new_york)) .build(); // Iterate as usual @@ -1187,15 +1207,15 @@ fn flecs_query_docs_compile_test() { // - bob (Place = CentralPark, ManHattan, newyork) let q = world .query::<()>() - .with::() - .set_second_name("$Place") + .with(id::()) + .set_second("$Place") .build(); #[derive(Component)] struct City; // Add City property to newyork - new_york.add::(); + new_york.add(id::()); // Matches: // - ManHattan (Place = newyork) @@ -1204,17 +1224,17 @@ fn flecs_query_docs_compile_test() { let q = world .query::<()>() - .with::() - .set_second_name("$Place") - .with::() - .set_src_name("$Place") + .with(id::()) + .set_second("$Place") + .with(id::()) + .set_src("$Place") .build(); let tree = world.entity(); - let oak = world.entity().is_a_id(tree); + let oak = world.entity().is_a(tree); // Matches Tree, Oak - let q = world.query::<()>().with_first::(tree).build(); + let q = world.query::<()>().with((id::(), tree)).build(); // Iterate as usual } @@ -1230,9 +1250,9 @@ fn flecs_entities_components_docs_compile_test() { e1.destruct(); // Recycles 500 let e2 = world.entity(); // Returns 500v1 // Fails, 500v0 is not alive - e1.add::(); + e1.add(id::()); // OK, 500v1 is alive - e2.add::(); + e2.add(id::()); let e1 = world.entity(); e1.destruct(); @@ -1270,19 +1290,19 @@ fn flecs_entities_components_docs_compile_test() { println!("{}", e.name()); let p = world.entity_named("Parent"); - let e = world.entity_named("Child").child_of_id(p); + let e = world.entity_named("Child").child_of(p); if e == world.lookup("Parent::Child") { // true } let p = world.entity_named("Parent"); - let e = world.entity_named("Child").child_of_id(p); + let e = world.entity_named("Child").child_of(p); if e == p.lookup("Child") { // true } let p = world.entity_named("Parent"); - let e = world.entity_named("Child").child_of_id(p); + let e = world.entity_named("Child").child_of(p); // Returns entity name, does not allocate println!("{}", e.name()); // Child // Returns entity path, does allocate @@ -1313,9 +1333,9 @@ fn flecs_entities_components_docs_compile_test() { let e3 = world.entity(); // Create prefab that has the three entities let p = world.prefab(); - p.add_id(e1); - p.add_id(e2); - p.add_id(e3); + p.add(e1); + p.add(e2); + p.add(e3); // Disable entities p.disable_self(); // Enable entities @@ -1327,8 +1347,8 @@ fn flecs_entities_components_docs_compile_test() { let e3 = world.entity(); // Create prefab hierarchy with the three entities - let p1 = world.prefab().add_id(e1); - let p2 = world.prefab().is_a_id(p1).add_id(e2).add_id(e3); + let p1 = world.prefab().add(e1); + let p2 = world.prefab().is_a(p1).add(e2).add(e3); // Disable e1, e2, e3 p2.disable_self(); @@ -1336,7 +1356,7 @@ fn flecs_entities_components_docs_compile_test() { // Enable e1 p1.enable_self(); - e.add::(); + e.add(id::()); // Get the entity for the Position component let pos = world.component::(); @@ -1411,7 +1431,7 @@ fn flecs_entities_components_docs_compile_test() { let pos = world.component::(); // Create entity with Position - let e = world.entity().add::(); + let e = world.entity().add(id::()); // Unregister the component pos.destruct(); @@ -1435,11 +1455,11 @@ fn flecs_entities_components_docs_compile_test() { let e = world.entity().set(Position { x: 10.0, y: 20.0 }); // Disable component - e.disable::(); - assert!(!e.is_enabled::()); // False + e.disable(id::()); + assert!(!e.is_enabled(id::())); // False // Enable component - e.enable::(); - assert!(e.is_enabled::()); // True + e.enable(id::()); + assert!(e.is_enabled(id::())); // True } fn flecs_docs_relationships_compile_test() { @@ -1450,43 +1470,43 @@ fn flecs_docs_relationships_compile_test() { let alice = world.entity(); // bob likes alice - bob.add_id((likes, alice)); + bob.add((likes, alice)); // bob likes alice no more - bob.remove_id((likes, alice)); + bob.remove((likes, alice)); let bob = world.entity(); let eats = world.entity(); let apples = world.entity(); let pears = world.entity(); - bob.add_id((eats, apples)); - bob.add_id((eats, pears)); - bob.has_id((eats, apples)); // true - bob.has_id((eats, pears)); // true + bob.add((eats, apples)); + bob.add((eats, pears)); + bob.has((eats, apples)); // true + bob.has((eats, pears)); // true // Find all entities that eat apples let q = world.query::<()>().expr("(Eats, Apples)").build(); // Find all entities that eat anything let q = world.query::<()>().expr("(Eats, *)").build(); // With the query builder API: - let q = world.query::<()>().with_id((eats, apples)).build(); + let q = world.query::<()>().with((eats, apples)).build(); // Or when using pair types, when both relationship & target are compile time types, they can be represented as a tuple: let q = world.new_query::<&(Eats, Apples)>(); - bob.has_id((eats, apples)); + bob.has((eats, apples)); - bob.has_id((eats, flecs::Wildcard::ID)); + bob.has((eats, flecs::Wildcard::ID)); let parent = bob.parent(); - let food = bob.target_id(eats, 0); // first target + let food = bob.target(eats, 0); // first target let mut index = 0; - while bob.target_id(eats, index).is_some() { + while bob.target(eats, index).is_some() { index += 1; } - let parent = bob.target_for::(flecs::ChildOf::ID); + let parent = bob.target_for(id::(), flecs::ChildOf::ID); bob.each_component(|id| { if id.is_pair() { @@ -1497,7 +1517,7 @@ fn flecs_docs_relationships_compile_test() { world .query::<()>() - .with_id((eats, apples)) + .with((eats, apples)) .build() .each_entity(|e, _| { // Iterate as usual @@ -1505,11 +1525,11 @@ fn flecs_docs_relationships_compile_test() { world .query::<()>() - .with_id((eats, flecs::Wildcard::ID)) + .with((eats, flecs::Wildcard::ID)) .build() .each_iter(|it, i, _| { let food = it.pair(0).unwrap().second_id(); // Apples, ... - let e = it.entity(i); + let e = it.entity(i).unwrap(); // Iterate as usual }); @@ -1529,7 +1549,7 @@ fn flecs_docs_relationships_compile_test() { let apples = world.entity(); let e = world.entity(); // Both likes and Apples are tags, so (likes, Apples) is a tag - e.add_id((likes, apples)); + e.add((likes, apples)); // Eats is a type and Apples is a tag, so (Eats, Apples) has type Eats e.set_pair::(Eats { amount: 1 }); // Begin is a tags and Position is a type, so (Begin, Position) has type Position @@ -1537,8 +1557,8 @@ fn flecs_docs_relationships_compile_test() { e.set_pair::(Position { x: 100.0, y: 20.0 }); // Same for End // ChildOf has the Tag property, so even though Position is a type, the pair // does not assume the Position type - e.add_id((flecs::ChildOf::ID, world.component_id::())); - e.add::<(flecs::ChildOf, Position)>(); + e.add((flecs::ChildOf::ID, world.component_id::())); + e.add((id::(), id::())); let e = world.entity(); let first = world.entity(); @@ -1551,12 +1571,12 @@ fn flecs_docs_relationships_compile_test() { let q = world .query::<()>() - .with_id((likes, flecs::Wildcard::ID)) + .with((likes, flecs::Wildcard::ID)) .build(); q.each_iter(|it, i, _| { println!( "entity {} has relationship {} {}", - it.entity(i), + it.entity(i).unwrap(), it.pair(0).unwrap().first_id().name(), it.pair(0).unwrap().second_id().name() ); @@ -1569,25 +1589,25 @@ fn flecs_docs_relationships_compile_test() { let eats = world.entity(); let apples = world.entity(); let pears = world.entity(); - bob.add_id((eats, apples)); - bob.add_id((eats, pears)); + bob.add((eats, apples)); + bob.add((eats, pears)); // Find all (Eats, *) relationships in bob's type bob.each_pair(eats, flecs::Wildcard::ID, |id| { println!("bob eats {}", id.second_id().name()); }); - // For target wildcard pairs, each_target_id() can be used: - bob.each_target_id(eats, |entity| { + // For target wildcard pairs, each_target() can be used: + bob.each_target(eats, |entity| { println!("bob eats {}", entity.name()); }); let apple = world.entity(); let fruit = world.entity(); - apple.add_id((flecs::IsA::ID, fruit)); + apple.add((flecs::IsA::ID, fruit)); - apple.is_a_id(fruit); + apple.is_a(fruit); let granny_smith = world.entity(); - granny_smith.add_id((flecs::IsA::ID, apple)); + granny_smith.add((flecs::IsA::ID, apple)); let spaceship = world .entity() @@ -1595,7 +1615,7 @@ fn flecs_docs_relationships_compile_test() { .set(Defense { value: 50 }); let frigate = world .entity() - .is_a_id(spaceship) // shorthand for .add(flecs::IsA, Spaceship) + .is_a(spaceship) // shorthand for .add(flecs::IsA, Spaceship) .set(Defense { value: 75 }); // Obtain the inherited component from Spaceship @@ -1608,7 +1628,7 @@ fn flecs_docs_relationships_compile_test() { v.value == 75 // True }); - let fast_frigate = world.entity().is_a_id(frigate).set(MaxSpeed { value: 200 }); + let fast_frigate = world.entity().is_a(frigate).set(MaxSpeed { value: 200 }); // Obtain the overridden component from FastFrigate let is_200 = fast_frigate.get::<&mut MaxSpeed>(|v| { v.value == 200 // True @@ -1620,29 +1640,29 @@ fn flecs_docs_relationships_compile_test() { let spaceship = world.entity(); let cockpit = world.entity(); - cockpit.add_id((flecs::ChildOf::ID, spaceship)); + cockpit.add((flecs::ChildOf::ID, spaceship)); - cockpit.child_of_id(spaceship); + cockpit.child_of(spaceship); let parent = world.entity_named("Parent"); - let child = world.entity_named("Child").child_of_id(parent); + let child = world.entity_named("Child").child_of(parent); child == world.lookup("Parent::Child"); // true child == parent.lookup("Child"); // true let parent = world.entity(); - let prev = world.set_scope_id(parent); + let prev = world.set_scope(parent); let child_a = world.entity(); let child_b = world.entity(); // Restore the previous scope - world.set_scope_id(prev); - child_a.has_id((flecs::ChildOf::ID, parent)); // true - child_b.has_id((flecs::ChildOf::ID, parent)); // true + world.set_scope(prev); + child_a.has((flecs::ChildOf::ID, parent)); // true + child_b.has((flecs::ChildOf::ID, parent)); // true let parent = world.entity().run_in_scope(|| { let child_a = world.entity(); let child_b = world.entity(); - child_a.has_id((flecs::ChildOf::ID, parent)); // true - child_b.has_id((flecs::ChildOf::ID, parent)); // true + child_a.has((flecs::ChildOf::ID, parent)); // true + child_b.has((flecs::ChildOf::ID, parent)); // true }); } @@ -1673,7 +1693,7 @@ fn flecs_docs_quick_start_compile_test() { // Add a component. This creates the component in the ECS storage, but does not // assign it with a value. - e.add::(); + e.add(id::()); // Set the value for the Position & Velocity components. A component will be // added if the entity doesn't have it yet. @@ -1686,7 +1706,7 @@ fn flecs_docs_quick_start_compile_test() { }); // Remove component - e.remove::(); + e.remove(id::()); //Rust applications can use the `world::entity_from` function. @@ -1694,7 +1714,7 @@ fn flecs_docs_quick_start_compile_test() { println!("Name: {}", pos_e.name()); // outputs 'Name: Position' // It's possible to add components like you would for any entity - pos_e.add::(); + pos_e.add(id::()); let pos_e = world.entity_from::(); @@ -1707,21 +1727,21 @@ fn flecs_docs_quick_start_compile_test() { struct Enemy; // Create entity, add Enemy tag - let e = world.entity().add::(); - e.has::(); // true! + let e = world.entity().add(id::()); + e.has(id::()); // true! - e.remove::(); - e.has::(); // false! + e.remove(id::()); + e.has(id::()); // false! // Option 2: create Tag as entity let enemy = world.entity(); // Create entity, add Enemy tag - let e = world.entity().add_id(enemy); - e.has_id(enemy); // true! + let e = world.entity().add(enemy); + e.has(enemy); // true! - e.remove_id(enemy); - e.has_id(enemy); // false! + e.remove(enemy); + e.has(enemy); // false! // Create Likes relationship as empty type (tag) #[derive(Component)] @@ -1731,41 +1751,39 @@ fn flecs_docs_quick_start_compile_test() { let bob = world.entity(); let alice = world.entity(); - bob.add_first::(alice); // bob likes alice - alice.add_first::(bob); // alice likes bob - bob.has_first::(alice); // true! - - bob.remove_first::(alice); - bob.has_first::(alice); // false! + bob.add((id::(), alice)); // bob likes alice + alice.add((id::(), bob)); // alice likes bob + bob.has((id::(), alice)); // true! - let id = world.id_first::(bob); + bob.remove((id::(), alice)); + bob.has((id::(), alice)); // false! - let id = world.id_from::<(Likes, Apples)>(); - if id.is_pair() { - let relationship = id.first_id(); - let target = id.second_id(); + let id_likes_apples = world.id_view_from((id::(), 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_id((eats, apples)); - bob.add_id((eats, pears)); - bob.add_id((grows, pears)); + bob.add((eats, apples)); + bob.add((eats, pears)); + bob.add((grows, pears)); - bob.has_id((eats, apples)); // true! - bob.has_id((eats, pears)); // true! - bob.has_id((grows, pears)); // true! + bob.has((eats, apples)); // true! + bob.has((eats, pears)); // true! + bob.has((grows, pears)); // true! - let alice = world.entity().add_first::(bob); - let o = alice.target::(0); // Returns bob + let alice = world.entity().add((id::(), bob)); + let o = alice.target(id::(), 0); // Returns bob let parent = world.entity(); - let child = world.entity().child_of_id(parent); + let child = world.entity().child_of(parent); // Deleting the parent also deletes its children parent.destruct(); let parent = world.entity_named("parent"); - let child = world.entity_named("child").child_of_id(parent); + let child = world.entity_named("child").child_of(parent); println!("Child path: {}", child.path().unwrap()); // output: 'parent::child' world.lookup("parent::child"); // returns child @@ -1782,7 +1800,7 @@ fn flecs_docs_quick_start_compile_test() { // Do the thing }); - let e = world.entity().add::().add::(); + let e = world.entity().add(id::()).add(id::()); println!("Components: {}", e.archetype().to_string().unwrap()); // output: 'Position,Velocity' @@ -1824,7 +1842,7 @@ fn flecs_docs_quick_start_compile_test() { // More complex queries can first be created, then iterated let q = world .query::<&Position>() - .with_id((flecs::ChildOf::ID, parent)) + .with((flecs::ChildOf::ID, parent)) .build(); // Option 1: the each() callback iterates over each entity @@ -1838,15 +1856,15 @@ fn flecs_docs_quick_start_compile_test() { let p = it.field::(0).unwrap(); for i in it.iter() { - println!("{}: ({}, {})", it.entity(i).name(), p[i].x, p[i].y); + println!("{}: ({}, {})", it.entity(i).unwrap().name(), p[i].x, p[i].y); } } }); let q = world .query::<()>() - .with::<(flecs::ChildOf, flecs::Wildcard)>() - .with::() + .with((id::(), id::())) + .with(id::()) .set_oper(OperKind::Not) .build(); @@ -1866,7 +1884,7 @@ fn flecs_docs_quick_start_compile_test() { move_sys.run(); println!("System: {}", move_sys.name()); - move_sys.add::(); + move_sys.add(id::()); move_sys.destruct(); flecs::pipeline::OnLoad; @@ -1880,21 +1898,21 @@ fn flecs_docs_quick_start_compile_test() { world .system_named::<(&mut Position, &Velocity)>("Move") - .kind::() + .kind(id::()) .each(|(p, v)| {}); world .system_named::<(&mut Position, &Transform)>("Transform") - .kind::() + .kind(id::()) .each(|(p, t)| {}); world .system_named::<(&Transform, &mut Mesh)>("Render") - .kind::() + .kind(id::()) .each(|(t, m)| {}); world.progress(); - move_sys.add::(); - move_sys.remove::(); + move_sys.add(id::()); + move_sys.remove(id::()); world .observer_named::("OnSetPosition") @@ -1935,10 +1953,10 @@ fn flecs_docs_observers_compile_test() { let e = world.entity(); // OnAdd observer fires - e.add::(); + e.add(id::()); // OnAdd observer doesn't fire, entity already has component - e.add::(); + e.add(id::()); let e = world.entity(); @@ -1951,45 +1969,45 @@ fn flecs_docs_observers_compile_test() { let p = world.prefab().set(Position { x: 10.0, y: 20.0 }); // Produces OnSet event for Position - let i = world.entity().is_a_id(p); + let i = world.entity().is_a(p); let p = world.prefab().set(Position { x: 10.0, y: 20.0 }); // Produces OnSet event for inherited Position component - let i = world.entity().is_a_id(p); + let i = world.entity().is_a(p); // Override component. Produces regular OnSet event. i.set(Position { x: 20.0, y: 30.0 }); // Reexposes inherited component, produces OnSet event - i.remove::(); + i.remove(id::()); let p = world.prefab().set(Position { x: 10.0, y: 20.0 }); // Produces OnSet event for Position - let i = world.entity().is_a_id(p); + let i = world.entity().is_a(p); let e = world.entity().set(Position { x: 10.0, y: 20.0 }); // OnRemove observer fires - e.remove::(); + e.remove(id::()); // OnRemove observer doesn't fire, entity doesn't have the component - e.remove::(); + e.remove(id::()); // Observer that listens for both OnAdd and OnRemove events world .observer::() - .with::() - .add_event::() + .with(id::()) + .add_event(id::()) .each_entity(|e, p| { // ... }); world .observer::() - .add_event::() - .with::() + .add_event(id::()) + .with(id::()) .each_iter(|it, i, p| { if it.event() == flecs::OnAdd::ID { // ... @@ -2008,8 +2026,8 @@ fn flecs_docs_observers_compile_test() { // Observer that listens for entities with both Position and Velocity world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .each_entity(|e, _| { // ... }); @@ -2017,16 +2035,16 @@ fn flecs_docs_observers_compile_test() { let e = world.entity(); // Does not trigger "Position, Velocity" observer - e.add::(); + e.add(id::()); // Entity now matches "Position, Velocity" query, triggers observer - e.add::(); + e.add(id::()); // Observer that only triggers on Position, not on Velocity world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .filter() .each_entity(|e, p| { // ... @@ -2046,7 +2064,7 @@ fn flecs_docs_observers_compile_test() { // OnSet observer with both component and tag world .observer::() - .with::() // Tag + .with(id::()) // Tag .each_entity(|e, p| { // ... }); @@ -2057,7 +2075,7 @@ fn flecs_docs_observers_compile_test() { e.set(Position { x: 10.0, y: 20.0 }); // Produces and OnAdd event & triggers observer - e.add::(); + e.add(id::()); // Produces an OnSet event & triggers observer e.set(Position { x: 20.0, y: 30.0 }); @@ -2065,8 +2083,8 @@ fn flecs_docs_observers_compile_test() { // Observer with a Not term world .observer::() - .with::() - .without::() + .with(id::()) + .without(id::()) .each_entity(|e, p| { // ... }); @@ -2080,7 +2098,7 @@ fn flecs_docs_observers_compile_test() { e.set(Velocity { x: 1.0, y: 2.0 }); // Triggers the observer, as the Velocity term was inverted to OnRemove - e.remove::(); + e.remove(id::()); // Monitor observer world @@ -2102,7 +2120,7 @@ fn flecs_docs_observers_compile_test() { e.set(Velocity { x: 1.0, y: 2.0 }); // Entity no longer matches, triggers monitor with OnRemove event - e.remove::(); + e.remove(id::()); // Entity created before the observer let e1 = world.entity().set(Position { x: 10.0, y: 20.0 }); @@ -2110,8 +2128,8 @@ fn flecs_docs_observers_compile_test() { // Yield existing observer world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .yield_existing() .each_iter(|it, i, _| { // ... @@ -2129,7 +2147,7 @@ fn flecs_docs_observers_compile_test() { world .observer::() .term_at(0) - .set_src_id(game) // Match TimeOfDay on game + .set_src(game) // Match TimeOfDay on game .each_iter(|it, i, time| { // ... }); @@ -2168,7 +2186,7 @@ fn flecs_docs_observers_compile_test() { }); let parent = world.entity(); - let child = world.entity().child_of_id(parent); + let child = world.entity().child_of(parent); // Invokes observer twice: once for the parent and once for the child parent.set(Position { x: 10.0, y: 20.0 }); @@ -2176,7 +2194,7 @@ fn flecs_docs_observers_compile_test() { // Create an observer that matches OnAdd(Position) events on a parent world .observer::() - .with::() + .with(id::()) .term_at(0) .up() // .trav(flecs::ChildOf) (default) .each_entity(|e, _| { @@ -2186,7 +2204,7 @@ fn flecs_docs_observers_compile_test() { let parent = world.entity().set(Position { x: 10.0, y: 20.0 }); // Forwards OnAdd event for Position to child - let child = world.entity().child_of_id(parent); + let child = world.entity().child_of(parent); // Create a custom event #[derive(Component)] @@ -2207,7 +2225,7 @@ fn flecs_docs_observers_compile_test() { // Emit custom event world .event() - .add::() + .add(id::()) .entity(e) .emit(&Synchronized); @@ -2274,27 +2292,30 @@ fn flecs_docs_prefabs_compile_test() { let spaceship = world.prefab_named("spaceship").set(Defense { value: 50 }); // Create two prefab instances - let inst_1 = world.entity().is_a_id(spaceship); - let inst_2 = world.entity().is_a_id(spaceship); + let inst_1 = world.entity().is_a(spaceship); + let inst_2 = world.entity().is_a(spaceship); // Get instantiated component inst_1.get::<&Defense>(|defense| { println!("Defense value: {}", defense.value); }); - let myprefab = world.entity().add::(); + let myprefab = world.entity().add(id::()); // or the shortcut let myprefab = world.prefab(); // Only match prefab entities - world.query::<&Position>().with::().build(); + world + .query::<&Position>() + .with(id::()) + .build(); // Only match prefab entities world .query::<&Position>() - .with::() + .with(id::()) .optional() .build(); @@ -2316,7 +2337,7 @@ fn flecs_docs_prefabs_compile_test() { .set(Defense { value: 50 }); // Create prefab instance - let inst = world.entity().is_a_id(spaceship); + let inst = world.entity().is_a(spaceship); // Component is retrieved from instance inst.get::<&Health>(|health| { @@ -2328,11 +2349,11 @@ fn flecs_docs_prefabs_compile_test() { println!("Defense value: {}", defense.value); }); - if inst.owns::() { + if inst.owns(id::()) { // not inherited } - let inherited_from = inst.target::(0); + let inherited_from = inst.target(id::(), 0); if inherited_from.is_none() { // not inherited } @@ -2346,8 +2367,8 @@ fn flecs_docs_prefabs_compile_test() { let spaceship = world.prefab().set(Defense { value: 50 }); // Create prefab instance - let inst_a = world.entity().is_a_id(spaceship); - let inst_b = world.entity().is_a_id(spaceship); + let inst_a = world.entity().is_a(spaceship); + let inst_b = world.entity().is_a(spaceship); // Override Defense only for inst_a inst_a.set(Defense { value: 75 }); @@ -2361,11 +2382,11 @@ fn flecs_docs_prefabs_compile_test() { let spaceship = world.prefab().set(Defense { value: 50 }); // Create prefab instance - let inst_a = world.entity().is_a_id(spaceship); - let inst_b = world.entity().is_a_id(spaceship); + let inst_a = world.entity().is_a(spaceship); + let inst_b = world.entity().is_a(spaceship); // Override Defense only for inst_a - inst_a.add::(); // Initialized with value 50 + inst_a.add(id::()); // Initialized with value 50 // Make Defense component inheritable world @@ -2376,8 +2397,8 @@ fn flecs_docs_prefabs_compile_test() { let spaceship = world.prefab().set_auto_override(Defense { value: 50 }); // Set & let override Defense // Create prefab instance - let inst = world.entity().is_a_id(spaceship); - inst.owns::(); // true + let inst = world.entity().is_a(spaceship); + inst.owns(id::()); // true // Create prefab let spaceship = world @@ -2388,11 +2409,11 @@ fn flecs_docs_prefabs_compile_test() { // Create prefab variant let freighter = world .prefab_named("Freighter") - .is_a_id(spaceship) + .is_a(spaceship) .set(Health { value: 150 }); // Override the Health component of the freighter // Create prefab instance - let inst = world.entity().is_a_id(freighter); + let inst = world.entity().is_a(freighter); inst.get::<&Health>(|health| { println!("Health value: {}", health.value); // 150 }); @@ -2401,22 +2422,22 @@ fn flecs_docs_prefabs_compile_test() { }); let spaceship = world.prefab_named("Spaceship"); - let cockpit = world.prefab_named("Cockpit").child_of_id(spaceship); + let cockpit = world.prefab_named("Cockpit").child_of(spaceship); // Instantiate the prefab hierarchy - let inst = world.entity().is_a_id(spaceship); + let inst = world.entity().is_a(spaceship); // Lookup instantiated child let inst_cockpit = inst.lookup("Cockpit"); let spaceship = world.prefab_named("Spaceship"); - let cockpit = world.prefab_named("Cockpit").child_of_id(spaceship).slot(); // Defaults to (SlotOf, spaceship) + let cockpit = world.prefab_named("Cockpit").child_of(spaceship).slot(); // Defaults to (SlotOf, spaceship) // Instantiate the prefab hierarchy - let inst = world.entity().is_a_id(spaceship); + let inst = world.entity().is_a(spaceship); // Lookup instantiated child - let inst_cockpit = inst.target_id(cockpit, 0); + let inst_cockpit = inst.target(cockpit, 0); #[derive(Component)] struct Spaceship; @@ -2428,7 +2449,7 @@ fn flecs_docs_prefabs_compile_test() { .set(Health { value: 100 }); // Instantiate prefab with type - let inst = world.entity().is_a::(); + let inst = world.entity().is_a(id::()); // Lookup prefab handle let prefab = world.lookup("spaceship"); @@ -2445,20 +2466,20 @@ fn flecs_docs_component_traits_compile_test() { e: Entity, // Not covered by cleanup traits } - e.child_of_id(parent); // Covered by cleanup traits + e.child_of(parent); // Covered by cleanup traits - world.remove_all_id(archer); + world.remove_all(archer); - world.remove_all_id(archer); - world.remove_all_id((archer, flecs::Wildcard::ID)); - world.remove_all_id((flecs::Wildcard::ID, archer)); + world.remove_all(archer); + world.remove_all((archer, flecs::Wildcard::ID)); + world.remove_all((flecs::Wildcard::ID, archer)); // Remove Archer from entities when Archer is deleted world .component::() .add_trait::<(flecs::OnDelete, flecs::Remove)>(); - let e = world.entity().add::(); + let e = world.entity().add(id::()); // This will remove Archer from e world.component::().destruct(); @@ -2468,7 +2489,7 @@ fn flecs_docs_component_traits_compile_test() { .component::() .add_trait::<(flecs::OnDelete, flecs::Delete)>(); - let e = world.entity().add::(); + let e = world.entity().add(id::()); // This will delete e world.component::().destruct(); @@ -2479,7 +2500,7 @@ fn flecs_docs_component_traits_compile_test() { .add_trait::<(flecs::OnDeleteTarget, flecs::Delete)>(); let p = world.entity(); - let e = world.entity().add_first::(p); + let e = world.entity().add((id::(), p)); // This will delete both p and e p.destruct(); @@ -2490,8 +2511,8 @@ fn flecs_docs_component_traits_compile_test() { // This observer will be invoked when a Node is removed }); - let p = world.entity().add::(); - let c = world.entity().add::().child_of_id(p); + let p = world.entity().add(id::()); + let c = world.entity().add(id::()).child_of(p); { #[derive(Component)] @@ -2514,9 +2535,9 @@ fn flecs_docs_component_traits_compile_test() { let e = world .entity() - .add::() // Panic, 'Likes' is not used as relationship - .add::<(Apples, Likes)>() // Panic, 'Likes' is not used as relationship, but as target - .add::<(Likes, Apples)>(); // OK + .add(id::()) // Panic, 'Likes' is not used as relationship + .add((id::(), id::())) // Panic, 'Likes' is not used as relationship, but as target + .add((id::(), id::())); // OK } { #[derive(Component)] @@ -2544,9 +2565,9 @@ fn flecs_docs_component_traits_compile_test() { let e = world .entity() - .add::() // Panic, 'Apples' is not used as target - .add::<(Apples, Likes)>() // Panic, 'Apples' is not used as target, but as relationship - .add::<(Likes, Apples)>(); // OK + .add(id::()) // Panic, 'Apples' is not used as target + .add((id::(), id::())) // Panic, 'Apples' is not used as target, but as relationship + .add((id::(), id::())); // OK #[derive(Component)] struct Serializable; // Tag, contains no data @@ -2578,7 +2599,7 @@ fn flecs_docs_component_traits_compile_test() { let e = world.entity().add_trait::(); - let i = world.entity().is_a_id(e); // not allowed + let i = world.entity().is_a(e); // not allowed // Register component with trait. Optional, since this is the default behavior. world @@ -2586,9 +2607,9 @@ fn flecs_docs_component_traits_compile_test() { .add_trait::<(flecs::OnInstantiate, flecs::Override)>(); let base = world.entity().set(Mass { value: 100.0 }); - let inst = world.entity().is_a_id(base); // Mass is copied to inst + let inst = world.entity().is_a(base); // Mass is copied to inst - assert!(inst.owns::()); + assert!(inst.owns(id::())); assert!(base.cloned::<&Mass>() != inst.cloned::<&Mass>()); // Register component with trait @@ -2597,10 +2618,10 @@ fn flecs_docs_component_traits_compile_test() { .add_trait::<(flecs::OnInstantiate, flecs::Inherit)>(); let base = world.entity().set(Mass { value: 100.0 }); - let inst = world.entity().is_a_id(base); + let inst = world.entity().is_a(base); - assert!(inst.has::()); - assert!(!inst.owns::()); + assert!(inst.has(id::())); + assert!(!inst.owns(id::())); assert!(base.cloned::<&Mass>() != inst.cloned::<&Mass>()); // Register component with trait @@ -2609,10 +2630,10 @@ fn flecs_docs_component_traits_compile_test() { .add_trait::<(flecs::OnInstantiate, flecs::DontInherit)>(); let base = world.entity().set(Mass { value: 100.0 }); - let inst = world.entity().is_a_id(base); + let inst = world.entity().is_a(base); - assert!(!inst.has::()); - assert!(!inst.owns::()); + assert!(!inst.has(id::())); + assert!(!inst.owns(id::())); assert!(inst.try_get::<&Mass>(|mass| {}).is_none()); let locatedin = world.entity(); @@ -2620,15 +2641,15 @@ fn flecs_docs_component_traits_compile_test() { let newyork = world.entity(); let usa = world.entity(); - manhattan.add_id((locatedin, newyork)); - newyork.add_id((locatedin, usa)); + manhattan.add((locatedin, newyork)); + newyork.add((locatedin, usa)); locatedin.add_trait::(); let parent_a = world.entity(); let parent_b = world.entity(); - e.child_of_id(parent_a); - e.child_of_id(parent_b); // replaces (ChildOf, parent_a) + e.child_of(parent_a); + e.child_of(parent_b); // replaces (ChildOf, parent_a) let married_to = world.entity().add_trait::(); @@ -2638,61 +2659,61 @@ fn flecs_docs_component_traits_compile_test() { let e = world.entity().set(Position { x: 10.0, y: 20.0 }); - e.disable::(); // Disable component - assert!(!e.is_enabled::()); + e.disable(id::()); // Disable component + assert!(!e.is_enabled(id::())); - e.enable::(); // Enable component - assert!(e.is_enabled::()); + e.enable(id::()); // Enable component + assert!(e.is_enabled(id::())); // Updated to use id::() let movement = world.entity().add_trait::(); let walking = world.entity(); let running = world.entity(); - let e = world.entity().add_id((movement, running)); - e.add_id((movement, walking)); // replaces (Movement, Running) + let e = world.entity().add((movement, running)); + e.add((movement, walking)); // replaces (Movement, Running) world.component::().add_trait::(); let married_to = world.entity().add_trait::(); let bob = world.entity(); let alice = world.entity(); - bob.add_id((married_to, alice)); // Also adds (MarriedTo, Bob) to Alice + bob.add((married_to, alice)); // Also adds (MarriedTo, Bob) to Alice let responsibility = world.entity(); - let power = world.entity().add_first::(responsibility); + let power = world.entity().add((id::(), responsibility)); // Create new entity that has both Power and Responsibility - let e = world.entity().add_id(power); + let e = world.entity().add(power); let likes = world.entity(); let loves = world.entity().add_trait::<(flecs::With, Likes)>(); let pears = world.entity(); // Create new entity with both (Loves, Pears) and (Likes, Pears) - let e = world.entity().add_id((loves, pears)); + let e = world.entity().add((loves, pears)); // Enforce that target of relationship is child of Food let food = world.entity().add_trait::(); - let apples = world.entity().child_of_id(food); + let apples = world.entity().child_of(food); let fork = world.entity(); // This is ok, Apples is a child of Food - let a = world.entity().add_id((food, apples)); + let a = world.entity().add((food, apples)); // This is not ok, Fork is not a child of Food - let b = world.entity().add_id((food, fork)); + let b = world.entity().add((food, fork)); // Enforce that target of relationship is child of Food let food = world.entity(); - let eats = world.entity().add_first::(food); - let apples = world.entity().child_of_id(food); + let eats = world.entity().add((id::(), food)); + let apples = world.entity().child_of(food); let fork = world.entity(); // This is ok, Apples is a child of Food - let a = world.entity().add_id((eats, apples)); + let a = world.entity().add((eats, apples)); // This is not ok, Fork is not a child of Food - let b = world.entity().add_id((eats, fork)); + let b = world.entity().add((eats, fork)); } // app.world.set(flecs::rest::Rest::default()); diff --git a/flecs_ecs/tests/flecs/meta_macro_test.rs b/flecs_ecs/tests/flecs/meta_macro_test.rs index 052e9642..9bc42080 100644 --- a/flecs_ecs/tests/flecs/meta_macro_test.rs +++ b/flecs_ecs/tests/flecs/meta_macro_test.rs @@ -84,7 +84,7 @@ fn meta_struct() { let a = c.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::I32); @@ -92,7 +92,7 @@ fn meta_struct() { let b = c.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); b.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::F32); @@ -121,7 +121,7 @@ fn meta_nested_struct() { let a = n.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, t.id()); @@ -154,7 +154,7 @@ fn meta_struct_w_portable_type() { let a = t.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::UPtr); @@ -162,7 +162,7 @@ fn meta_struct_w_portable_type() { let b = t.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); // b.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::UPtr); @@ -170,7 +170,7 @@ fn meta_struct_w_portable_type() { // let c = t.lookup("c"); // assert_ne!(c.id(), 0); - // assert!(c.has::()); + // assert!(c.has(id::())); // c.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::Entity); @@ -178,7 +178,7 @@ fn meta_struct_w_portable_type() { // let d = t.lookup("d"); // assert_!(d.id(), 0); - // assert!(d.has::()); + // assert!(d.has(id::())); // d.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::Entity); @@ -210,7 +210,7 @@ fn meta_partial_struct() { let xe = c.lookup("x"); assert_ne!(xe.id(), 0); - assert!(xe.has::()); + assert!(xe.has(id::())); xe.get::<&flecs::meta::Member>(|x| { assert_eq!(x.type_, flecs::meta::F32); assert_eq!(x.offset, 0); @@ -238,7 +238,7 @@ fn meta_partial_struct_custom_offset() { let xe = c.lookup("y"); assert_ne!(xe.id(), 0); - assert!(xe.has::()); + assert!(xe.has(id::())); xe.get::<&flecs::meta::Member>(|x| { assert_eq!(x.type_, flecs::meta::F32); assert_eq!(x.offset, 4); @@ -509,7 +509,7 @@ fn meta_struct_member_ptr() { let x = t.lookup("x"); assert_ne!(x.id(), 0); - assert!(x.has::()); + assert!(x.has(id::())); x.get::<&flecs::meta::Member>(|xm| { assert_eq!(xm.type_, flecs::meta::I32); assert_eq!(xm.offset, offset_of!(Test, x) as i32); @@ -520,7 +520,7 @@ fn meta_struct_member_ptr() { let y = t2.lookup("y"); assert_ne!(y.id(), 0); - assert!(y.has::()); + assert!(y.has(id::())); y.get::<&flecs::meta::Member>(|ym| { assert_eq!(ym.type_, flecs::meta::F64); assert_eq!(ym.offset, offset_of!(Test2, y) as i32); @@ -531,7 +531,7 @@ fn meta_struct_member_ptr() { let a = n.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|am| { assert_eq!(am.type_, t.id()); let offset = offset_of!(Nested, a) as i32; @@ -540,7 +540,7 @@ fn meta_struct_member_ptr() { let b = n.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); b.get::<&flecs::meta::Member>(|bm| { assert_eq!(bm.type_, t2.id()); assert_eq!(bm.offset, offset_of!(Nested, b) as i32); @@ -563,7 +563,7 @@ fn meta_struct_field_order() { assert_ne!(t.id(), 0); let a = t.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|am| { assert_eq!(am.type_, flecs::meta::U32); assert_eq!(am.offset, offset_of!(Test, a) as i32); @@ -572,7 +572,7 @@ fn meta_struct_field_order() { assert_ne!(t.id(), 0); let b = t.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); b.get::<&flecs::meta::Member>(|bm| { assert_eq!(bm.type_, flecs::meta::I32); assert_eq!(bm.offset, offset_of!(Test, b) as i32); diff --git a/flecs_ecs/tests/flecs/meta_test.rs b/flecs_ecs/tests/flecs/meta_test.rs index c8a2abbe..eaa32f7d 100644 --- a/flecs_ecs/tests/flecs/meta_test.rs +++ b/flecs_ecs/tests/flecs/meta_test.rs @@ -81,14 +81,14 @@ fn meta_struct() { let c = world .component::() - .member::("a") - .member::("b"); + .member(id::(), "a") + .member(id::(), "b"); assert_ne!(c.id(), 0); let a = c.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::I32); @@ -96,7 +96,7 @@ fn meta_struct() { let b = c.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); b.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::F32); @@ -117,15 +117,15 @@ fn meta_nested_struct() { a: Test, } - let t = world.component::().member::("x"); + let t = world.component::().member(id::(), "x"); - let n = world.component::().member_id(t, "a"); + let n = world.component::().member(t, "a"); assert_ne!(n.id(), 0); let a = n.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, t.id()); @@ -195,16 +195,16 @@ fn meta_struct_w_portable_type() { let t = world .component::() - .member::("a") - .member::("b") - .member::("c") - .member::("d"); + .member(id::(), "a") + .member(id::(), "b") + .member(id::(), "c") + .member(id::(), "d"); assert_ne!(t.id(), 0); let a = t.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|mem| { assert_eq!(mem.type_, flecs::meta::UPtr); @@ -212,7 +212,7 @@ fn meta_struct_w_portable_type() { let b = t.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); // b.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::UPtr); @@ -220,7 +220,7 @@ fn meta_struct_w_portable_type() { // let c = t.lookup("c"); // assert_ne!(c.id(), 0); - // assert!(c.has::()); + // assert!(c.has(id::())); // c.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::Entity); @@ -228,7 +228,7 @@ fn meta_struct_w_portable_type() { // let d = t.lookup("d"); // assert_ne!(d.id(), 0); - // assert!(d.has::()); + // assert!(d.has(id::())); // d.get::<&flecs::meta::Member>(|mem| { // assert_eq!(mem.type_, flecs::meta::Entity); @@ -249,7 +249,7 @@ fn meta_partial_struct() { x: f32, } - let c = world.component::().member::("x"); + let c = world.component::().member(id::(), "x"); assert_ne!(c.id(), 0); @@ -260,7 +260,7 @@ fn meta_partial_struct() { let xe = c.lookup("x"); assert_ne!(xe.id(), 0); - assert!(xe.has::()); + assert!(xe.has(id::())); xe.get::<&flecs::meta::Member>(|x| { assert_eq!(x.type_, flecs::meta::F32); assert_eq!(x.offset, 0); @@ -279,7 +279,7 @@ fn meta_partial_struct_custom_offset() { let c = world .component::() - .member::(("y", Count(1), offset_of!(Position, y))); + .member(id::(), ("y", Count(1), offset_of!(Position, y))); assert_ne!(c.id(), 0); @@ -290,7 +290,7 @@ fn meta_partial_struct_custom_offset() { let xe = c.lookup("y"); assert_ne!(xe.id(), 0); - assert!(xe.has::()); + assert!(xe.has(id::())); xe.get::<&flecs::meta::Member>(|x| { assert_eq!(x.type_, flecs::meta::F32); assert_eq!(x.offset, 4); @@ -359,11 +359,10 @@ fn meta_bitmask() { .bit("lettuce", Toppings::LETTUCE) .bit("tomato", Toppings::TOMATO); - world.component::().member::(( - "toppings", - Count(1), - offset_of!(Sandwich, toppings), - )); + world.component::().member( + id::(), + ("toppings", Count(1), offset_of!(Sandwich, toppings)), + ); // Create entity with Sandwich as usual let e = world.entity().set(Sandwich { @@ -440,7 +439,9 @@ fn meta_world_ser_deser_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); let e1 = world.entity_named("ent1"); let e2 = world @@ -457,7 +458,9 @@ fn meta_world_ser_deser_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); world.from_json_world(json.as_str(), None); @@ -480,7 +483,9 @@ fn meta_new_world_ser_deser_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); let e1 = world.entity_named("ent1"); let e2 = world @@ -497,7 +502,9 @@ fn meta_new_world_ser_deser_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); world.from_json_world(json.as_str(), None); @@ -526,7 +533,9 @@ fn meta_new_world_ser_deser_empty_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); let e1 = Entity::null(); let e2 = world.entity_named("ent2").set(RustEntity { entity: e1 }); @@ -541,7 +550,9 @@ fn meta_new_world_ser_deser_empty_flecs_entity() { let world = World::new(); - world.component::().member::("entity"); + world + .component::() + .member(id::(), "entity"); world.from_json_world(json.as_str(), None); @@ -650,13 +661,13 @@ fn meta_enum_w_bits() { world .component::() - .member::("bits"); + .member(id::(), "bits"); for _ in 0..30 { world .entity() - .child_of_id(world.entity()) - .add::(); + .child_of(world.entity()) + .add(id::()); } let q = world.new_query::<&EnumWithBitsStruct>(); @@ -676,14 +687,14 @@ fn meta_value_range() { let c = world .component::() - .member::("x") + .member(id::(), "x") .range(-1.0, 1.0) - .member::("y") + .member(id::(), "y") .range(-2.0, 2.0); let x = c.lookup("x"); assert_ne!(x.id(), 0); - assert!(x.has::()); + assert!(x.has(id::())); x.get::<&flecs::meta::MemberRanges>(|ranges| { assert_eq!(ranges.value.min, -1.0); @@ -692,7 +703,7 @@ fn meta_value_range() { let y = c.lookup("y"); assert_ne!(y.id(), 0); - assert!(y.has::()); + assert!(y.has(id::())); y.get::<&flecs::meta::MemberRanges>(|ranges| { assert_eq!(ranges.value.min, -2.0); @@ -712,14 +723,14 @@ fn meta_warning_range() { let c = world .component::() - .member::("x") + .member(id::(), "x") .warning_range(-1.0, 1.0) - .member::("y") + .member(id::(), "y") .warning_range(-2.0, 2.0); let x = c.lookup("x"); assert_ne!(x.id(), 0); - assert!(x.has::()); + assert!(x.has(id::())); x.get::<&flecs::meta::MemberRanges>(|range| { assert_eq!(range.warning.min, -1.0); @@ -728,7 +739,7 @@ fn meta_warning_range() { let y = c.lookup("y"); assert_ne!(y.id(), 0); - assert!(y.has::()); + assert!(y.has(id::())); y.get::<&flecs::meta::MemberRanges>(|range| { assert_eq!(range.warning.min, -2.0); @@ -748,14 +759,14 @@ fn meta_error_range() { let c = world .component::() - .member::("x") + .member(id::(), "x") .error_range(-1.0, 1.0) - .member::("y") + .member(id::(), "y") .error_range(-2.0, 2.0); let x = c.lookup("x"); assert_ne!(x.id(), 0); - assert!(x.has::()); + assert!(x.has(id::())); x.get::<&flecs::meta::MemberRanges>(|range| { assert_eq!(range.error.min, -1.0); @@ -764,7 +775,7 @@ fn meta_error_range() { let y = c.lookup("y"); assert_ne!(y.id(), 0); - assert!(y.has::()); + assert!(y.has(id::())); y.get::<&flecs::meta::MemberRanges>(|range| { assert_eq!(range.error.min, -2.0); @@ -793,21 +804,21 @@ fn meta_struct_member_ptr() { b: [Test2; 2], } - let t = world.component::().member::("x"); + let t = world.component::().member(id::(), "x"); - let t2 = world.component::().member::("y"); + let t2 = world.component::().member(id::(), "y"); let n = world .component::() - .member::(("a", Count(1), offset_of!(Nested, a))) - .member_id(t2, ("b", Count(2), offset_of!(Nested, b))); + .member(id::(), ("a", Count(1), offset_of!(Nested, a))) + .member(t2, ("b", Count(2), offset_of!(Nested, b))); //validate Test #1 assert_ne!(t.id(), 0); let x = t.lookup("x"); assert_ne!(x.id(), 0); - assert!(x.has::()); + assert!(x.has(id::())); x.get::<&flecs::meta::Member>(|xm| { assert_eq!(xm.type_, flecs::meta::I32); assert_eq!(xm.offset, offset_of!(Test, x) as i32); @@ -818,7 +829,7 @@ fn meta_struct_member_ptr() { let y = t2.lookup("y"); assert_ne!(y.id(), 0); - assert!(y.has::()); + assert!(y.has(id::())); y.get::<&flecs::meta::Member>(|ym| { assert_eq!(ym.type_, flecs::meta::F64); assert_eq!(ym.offset, offset_of!(Test2, y) as i32); @@ -829,7 +840,7 @@ fn meta_struct_member_ptr() { let a = n.lookup("a"); assert_ne!(a.id(), 0); - assert!(a.has::()); + assert!(a.has(id::())); a.get::<&flecs::meta::Member>(|am| { assert_eq!(am.type_, t.id()); let offset = offset_of!(Nested, a) as i32; @@ -838,7 +849,7 @@ fn meta_struct_member_ptr() { let b = n.lookup("b"); assert_ne!(b.id(), 0); - assert!(b.has::()); + assert!(b.has(id::())); b.get::<&flecs::meta::Member>(|bm| { assert_eq!(bm.type_, t2.id()); assert_eq!(bm.offset, offset_of!(Nested, b) as i32); @@ -858,7 +869,7 @@ fn meta_component_as_array() { let c = world.component::().array::(2); - assert!(c.has::()); + assert!(c.has(id::())); c.get::<&flecs::meta::Array>(|ptr| { assert_eq!(ptr.type_, world.component_id::()); diff --git a/flecs_ecs/tests/flecs/meta_test_rust.rs b/flecs_ecs/tests/flecs/meta_test_rust.rs index 4b82595d..59326915 100644 --- a/flecs_ecs/tests/flecs/meta_test_rust.rs +++ b/flecs_ecs/tests/flecs/meta_test_rust.rs @@ -16,11 +16,11 @@ fn meta_struct_field_order() { world .component::() - .member::(("a", Count(1), offset_of!(Test, a))) - .member::(("b", Count(1), offset_of!(Test, b))) - .member::(("c", Count(1), offset_of!(Test, c))) - .member::(("d", Count(1), offset_of!(Test, d))) - .member::(("e", Count(1), offset_of!(Test, e))); + .member(id::(), ("a", Count(1), offset_of!(Test, a))) + .member(id::(), ("b", Count(1), offset_of!(Test, b))) + .member(id::(), ("c", Count(1), offset_of!(Test, c))) + .member(id::(), ("d", Count(1), offset_of!(Test, d))) + .member(id::(), ("e", Count(1), offset_of!(Test, e))); let e = world.entity().set(Test { a: 10, diff --git a/flecs_ecs/tests/flecs/meta_trait_test.rs b/flecs_ecs/tests/flecs/meta_trait_test.rs index 90cb2203..3583397d 100644 --- a/flecs_ecs/tests/flecs/meta_trait_test.rs +++ b/flecs_ecs/tests/flecs/meta_trait_test.rs @@ -97,7 +97,11 @@ fn test_enum() { // Register the TypeWithEnum component world.component::().meta(); - assert!(world.component::().has::()); + assert!( + world + .component::() + .has(id::()) + ); // Create a new entity let e = world @@ -134,7 +138,7 @@ fn test_type_w_string() { assert!( world .component::() - .has::() + .has(id::()) ); // Create a new entity @@ -167,7 +171,7 @@ fn test_type_w_vec_string() { assert!( world .component::() - .has::() + .has(id::()) ); // Create a new entity diff --git a/flecs_ecs/tests/flecs/observer_rust_test.rs b/flecs_ecs/tests/flecs/observer_rust_test.rs index ab241352..97a519bc 100644 --- a/flecs_ecs/tests/flecs/observer_rust_test.rs +++ b/flecs_ecs/tests/flecs/observer_rust_test.rs @@ -11,7 +11,7 @@ fn observer_panic_on_add_1() { world .observer::() - .with::<&Position>() + .with(id::<&Position>()) .each_entity(|_, _| {}); world.entity().set(Position { x: 10, y: 20 }); @@ -24,7 +24,7 @@ fn observer_panic_on_add_2() { world .observer::() - .with::<&mut Position>() + .with(id::<&mut Position>()) .each_entity(|_, _| {}); world.entity().set(Position { x: 10, y: 20 }); diff --git a/flecs_ecs/tests/flecs/observer_test.rs b/flecs_ecs/tests/flecs/observer_test.rs index 7642044b..c9a4c108 100644 --- a/flecs_ecs/tests/flecs/observer_test.rs +++ b/flecs_ecs/tests/flecs/observer_test.rs @@ -16,8 +16,8 @@ fn observer_2_terms_on_add() { world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .each_entity(|e, _| { let world = e.world(); world.get::<&mut Count>(|count| { @@ -70,11 +70,11 @@ fn observer_2_terms_on_remove() { world.get::<&mut Count>(|count| { assert_eq!(count, 0); }); - e.remove::(); + e.remove(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); - e.remove::(); + e.remove(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); @@ -124,36 +124,36 @@ fn observer_10_terms() { world .observer::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) .each_iter(move |it, _i, _| { let world = it.world(); assert_eq!(it.count(), 1); - assert!(it.entity(0) == e_id); + assert!(it.entity(0).unwrap() == e_id); assert_eq!(it.field_count(), 10); world.get::<&mut Count>(|count| { count.0 += 1; }); }); - e.add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::(); + e.add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -171,52 +171,52 @@ fn observer_16_terms() { world .observer::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() - .with::() + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) + .with(id::()) .each_iter(move |it, _i, _| { let world = it.world(); assert_eq!(it.count(), 1); - assert!(it.entity(0) == e_id); + assert!(it.entity(0).unwrap() == e_id); assert_eq!(it.field_count(), 16); world.get::<&mut Count>(|count| { count.0 += 1; }); }); - e.add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::(); + e.add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -247,10 +247,10 @@ fn observer_2_entities_iter() { world.get::<&mut Count>(|count| { count.0 += 1; }); - if it.entity(i) == e1_id { + if it.entity(i).unwrap() == e1_id { assert_eq!(p[i].x, 10); assert_eq!(p[i].y, 20); - } else if it.entity(i) == e2_id { + } else if it.entity(i).unwrap() == e2_id { assert_eq!(p[i].x, 30); assert_eq!(p[i].y, 40); } else { @@ -258,7 +258,7 @@ fn observer_2_entities_iter() { } world.get::<&mut LastEntity>(|last| { - last.0 = it.entity(i).id(); + last.0 = it.entity(i).unwrap().id(); }); } } @@ -299,17 +299,17 @@ fn observer_2_entities_table_column() { .run(move |mut it| { let world = it.world(); while it.next() { - let table_range = it.range().unwrap(); + let mut table_range = it.range().unwrap(); let p = table_range.get_mut::().unwrap(); for i in it.iter() { world.get::<&mut Count>(|count| { count.0 += 1; }); - if it.entity(i) == e1_id { + if it.entity(i).unwrap() == e1_id { assert_eq!(p[i].x, 10); assert_eq!(p[i].y, 20); - } else if it.entity(i) == e2_id { + } else if it.entity(i).unwrap() == e2_id { assert_eq!(p[i].x, 30); assert_eq!(p[i].y, 40); } else { @@ -317,7 +317,7 @@ fn observer_2_entities_table_column() { } world.get::<&mut LastEntity>(|last| { - last.0 = it.entity(i).id(); + last.0 = it.entity(i).unwrap().id(); }); } } @@ -402,7 +402,7 @@ fn observer_create_w_no_template_args() { world .observer::() - .with::() + .with(id::()) .each_entity(move |e, _| { let world = e.world(); assert!(e == e1_id); @@ -422,9 +422,9 @@ fn observer_create_w_no_template_args() { fn observer_yield_existing() { let world = World::new(); - let e1 = world.entity().add::(); - let e2 = world.entity().add::(); - let e3 = world.entity().add::().add::(); + let e1 = world.entity().add(id::()); + let e2 = world.entity().add(id::()); + let e3 = world.entity().add(id::()).add(id::()); let e1_id = e1.id(); let e2_id = e2.id(); @@ -433,12 +433,12 @@ fn observer_yield_existing() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .yield_existing() .run(move |mut it| { while it.next() { for i in it.iter() { - let e = it.entity(i); + let e = it.entity(i).unwrap(); let world = e.world(); world.get::<&mut Count>(|count| { if e == e1_id { @@ -462,22 +462,26 @@ fn observer_yield_existing() { fn observer_yield_existing_2_terms() { let world = World::new(); - let e1 = world.entity().add::().add::(); - let e2 = world.entity().add::().add::(); - let e3 = world.entity().add::().add::().add::(); + let e1 = world.entity().add(id::()).add(id::()); + let e2 = world.entity().add(id::()).add(id::()); + let e3 = world + .entity() + .add(id::()) + .add(id::()) + .add(id::()); let e1_id = e1.id(); let e2_id = e2.id(); let e3_id = e3.id(); - world.entity().add::(); - world.entity().add::(); + world.entity().add(id::()); + world.entity().add(id::()); world.set(Count(0)); world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .yield_existing() .each_entity(move |e, _| { let world = e.world(); @@ -503,7 +507,7 @@ fn observer_on_add() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .each_entity(|e, _| { let world = e.world(); world.get::<&mut Count>(|count| { @@ -511,7 +515,7 @@ fn observer_on_add() { }); }); - world.entity().add::(); + world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -529,13 +533,13 @@ fn observer_on_remove() { count.0 += 1; }); }); - let e = world.entity().add::(); + let e = world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 0); }); - e.remove::(); + e.remove(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -548,7 +552,7 @@ fn observer_on_add_tag_action() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .run(|mut it| { let world = it.world(); while it.next() { @@ -557,7 +561,7 @@ fn observer_on_add_tag_action() { }); } }); - world.entity().add::(); + world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -570,7 +574,7 @@ fn observer_on_add_tag_iter() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .run(|mut it| { let world = it.world(); while it.next() { @@ -579,7 +583,7 @@ fn observer_on_add_tag_iter() { }); } }); - world.entity().add::(); + world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); @@ -591,7 +595,7 @@ fn observer_on_add_tag_each() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .run(|mut it| { while it.next() { for _ in it.iter() { @@ -601,7 +605,7 @@ fn observer_on_add_tag_each() { } } }); - world.entity().add::(); + world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); @@ -620,11 +624,11 @@ fn observer_on_add_expr() { count.0 += 1; }); }); - let e = world.entity().add::(); + let e = world.entity().add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); - e.remove::(); + e.remove(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); @@ -638,8 +642,8 @@ fn observer_observer_w_filter_term() { world.set(Count(0)); world .observer::() - .with_id(tag_a) - .with_id(tag_b) + .with(tag_a) + .with(tag_b) .filter() .each_entity(|e, _| { e.world().get::<&mut Count>(|count| { @@ -652,25 +656,25 @@ fn observer_observer_w_filter_term() { assert_eq!(count, 0); }); - e.add_id(tag_b); + e.add(tag_b); world.get::<&mut Count>(|count| { assert_eq!(count, 0); }); - e.add_id(tag_a); + e.add(tag_a); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); - e.remove_id(tag_b); + e.remove(tag_b); world.get::<&mut Count>(|count| { assert_eq!(count, 1); }); - e.add_id(tag_b); + e.add(tag_b); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -682,7 +686,7 @@ fn observer_observer_w_filter_term() { assert_eq!(count, 1); }); - e.add_id(tag_a); + e.add(tag_a); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -696,7 +700,7 @@ fn observer_run_callback() { world.set(Count(0)); world .observer::() - .with::() + .with(id::()) .run_each_entity( |mut it| { while it.next() { @@ -714,7 +718,7 @@ fn observer_run_callback() { assert_eq!(count, 0); }); - e.add::(); + e.add(id::()); world.get::<&mut Count>(|count| { assert_eq!(count, 1); @@ -869,7 +873,7 @@ fn observer_on_add_pair_singleton() { let tgt = world.entity(); world .observer::() - .with_first::(tgt) + .with((id::(), tgt)) .singleton() .run(|mut it| { let world = it.world(); @@ -928,7 +932,7 @@ fn observer_on_add_with_pair_singleton() { let tgt = world.entity(); world .observer::() - .with_first::(tgt) + .with((id::(), tgt)) .singleton() .each_iter(|it, _, _| { it.world().get::<&mut Count>(|count| { @@ -949,18 +953,18 @@ fn observer_add_in_yield_existing() { let e3 = world.entity().set(Position::default()); world .observer::() - .with::() + .with(id::()) .yield_existing() .each_entity(|e, _| { - e.add::(); + e.add(id::()); }); - assert!(e1.has::()); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e2.has::()); - assert!(e3.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); + assert!(e3.has(id::())); } #[test] @@ -971,21 +975,21 @@ fn observer_add_in_yield_existing_multi() { let e3 = world.entity().set(Position::default()).set(Mass::default()); world .observer::() - .with::() - .with::() + .with(id::()) + .with(id::()) .yield_existing() .each_entity(|e, _| { - e.add::(); + e.add(id::()); }); - assert!(e1.has::()); - assert!(e1.has::()); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e2.has::()); - assert!(e2.has::()); - assert!(e3.has::()); - assert!(e3.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e1.has(id::())); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e2.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); + assert!(e3.has(id::())); + assert!(e3.has(id::())); } #[test] @@ -1007,8 +1011,8 @@ fn observer_name_from_root() { // struct Tag; // let world = World::new(); -// world.observer::().with::().run(|_| panic!()); -// world.add::(); +// world.observer::().with(id::()).run(|_| panic!()); +// world.add(id::()); // } #[test] diff --git a/flecs_ecs/tests/flecs/query_builder_test.rs b/flecs_ecs/tests/flecs/query_builder_test.rs index 0b2ed7c5..56d0a883 100644 --- a/flecs_ecs/tests/flecs/query_builder_test.rs +++ b/flecs_ecs/tests/flecs/query_builder_test.rs @@ -60,8 +60,8 @@ fn query_builder_builder_assign_from_empty() { let q = world .query::<()>() .set_cache_kind(QueryCacheKind::Auto) - .with::<&Position>() - .with::<&Velocity>() + .with(id::<&Position>()) + .with(id::<&Velocity>()) .build(); let e1 = world @@ -132,8 +132,8 @@ fn query_builder_builder_build_n_statements() { let world = World::new(); let mut q = world.query::<()>(); - q.with::<&Position>(); - q.with::<&Velocity>(); + q.with(id::<&Position>()); + q.with(id::<&Velocity>()); q.set_cache_kind(QueryCacheKind::Auto); let q = q.build(); @@ -209,13 +209,13 @@ fn query_builder_id_term() { let tag = world.entity(); - let e1 = world.entity().add_id(tag); + let e1 = world.entity().add(tag); world.entity().set(Velocity { x: 10, y: 20 }); let r = world .query::<()>() - .with_id(tag) + .with(tag) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -238,7 +238,7 @@ fn query_builder_type_term() { let r = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -259,13 +259,13 @@ fn query_builder_id_pair_term() { let apples = world.entity(); let pears = world.entity(); - let e1 = world.entity().add_id((likes, apples)); + let e1 = world.entity().add((likes, apples)); - world.entity().add_id((likes, pears)); + world.entity().add((likes, pears)); let r = world .query::<()>() - .with_id((likes, apples)) + .with((likes, apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -286,24 +286,24 @@ fn query_builder_id_pair_wildcard_term() { let apples = world.entity(); let pears = world.entity(); - let e1 = world.entity().add_id((likes, apples)); + let e1 = world.entity().add((likes, apples)); - let e2 = world.entity().add_id((likes, pears)); + let e2 = world.entity().add((likes, pears)); let r = world .query::<()>() - .with_id((likes, *flecs::Wildcard)) + .with((likes, *flecs::Wildcard)) .set_cache_kind(QueryCacheKind::Auto) .build(); let mut count = 0; r.each_iter(|it, index, ()| { - if it.entity(index) == e1 { - assert_eq!(it.id(0), world.id_from_id((likes, apples))); + if it.entity(index).unwrap() == e1 { + assert_eq!(it.id(0), world.id_view_from((likes, apples))); count += 1; } - if it.entity(index) == e2 { - assert_eq!(it.id(0), world.id_from_id((likes, pears))); + if it.entity(index).unwrap() == e2 { + assert_eq!(it.id(0), world.id_view_from((likes, pears))); count += 1; } }); @@ -314,24 +314,27 @@ fn query_builder_id_pair_wildcard_term() { fn query_builder_type_pair_term() { let world = World::new(); - let e1 = world.entity().add::<(Likes, Apples)>(); + let e1 = world.entity().add((id::(), id::())); - let e2 = world.entity().add::<(Likes, Pears)>(); + let e2 = world.entity().add((id::(), id::())); let r = world .query::<()>() - .with_first::<&Likes>(*flecs::Wildcard) + .with((id::<&Likes>(), *flecs::Wildcard)) .set_cache_kind(QueryCacheKind::Auto) .build(); let mut count = 0; r.each_iter(|it, index, ()| { - if it.entity(index) == e1 { - assert_eq!(it.id(0), world.id_from::<(Likes, Apples)>()); + if it.entity(index).unwrap() == e1 { + assert_eq!( + it.id(0), + world.id_view_from((id::(), id::())) + ); count += 1; } - if it.entity(index) == e2 { - assert_eq!(it.id(0), world.id_from::<(Likes, Pears)>()); + if it.entity(index).unwrap() == e2 { + assert_eq!(it.id(0), world.id_view_from((id::(), id::()))); count += 1; } }); @@ -342,13 +345,13 @@ fn query_builder_type_pair_term() { fn query_builder_pair_term_w_var() { let world = World::new(); - let e1 = world.entity().add::<(Likes, Apples)>(); + let e1 = world.entity().add((id::(), id::())); - let e2 = world.entity().add::<(Likes, Pears)>(); + let e2 = world.entity().add((id::(), id::())); let r = world .query::<()>() - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Food") .set_cache_kind(QueryCacheKind::Auto) @@ -358,16 +361,25 @@ fn query_builder_pair_term_w_var() { let mut count = 0; r.each_iter(|it, index, ()| { - if it.entity(index) == e1 { - assert_eq!(it.id(0), world.id_from::<(Likes, Apples)>()); - assert_eq!(it.get_var_by_name("Food"), world.id_from::()); - assert_eq!(it.get_var(foo_d_var), world.id_from::()); + if it.entity(index).unwrap() == e1 { + assert_eq!( + it.id(0), + world.id_view_from((id::(), id::())) + ); + assert_eq!( + it.get_var_by_name("Food"), + world.id_view_from(id::()) + ); + assert_eq!(it.get_var(foo_d_var), world.id_view_from(id::())); count += 1; } - if it.entity(index) == e2 { - assert_eq!(it.id(0), world.id_from::<(Likes, Pears)>()); - assert_eq!(it.get_var_by_name("Food"), world.id_from::()); - assert_eq!(it.get_var(foo_d_var), world.id_from::()); + if it.entity(index).unwrap() == e2 { + assert_eq!(it.id(0), world.id_view_from((id::(), id::()))); + assert_eq!( + it.get_var_by_name("Food"), + world.id_view_from(id::()) + ); + assert_eq!(it.get_var(foo_d_var), world.id_view_from(id::())); count += 1; } }); @@ -378,21 +390,21 @@ fn query_builder_pair_term_w_var() { fn query_builder_2_pair_terms_w_var() { let world = World::new(); - let bob = world.entity().add::<(Eats, Apples)>(); + let bob = world.entity().add((id::(), id::())); let alice = world .entity() - .add::<(Eats, Pears)>() - .add_first::(bob); + .add((id::(), id::())) + .add((id::(), bob)); - bob.add_first::(alice); + bob.add((id::(), alice)); let r = world .query::<()>() - .with::<&Eats>() + .with(id::<&Eats>()) .second() .set_var("Food") - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Person") .set_cache_kind(QueryCacheKind::Auto) @@ -403,22 +415,28 @@ fn query_builder_2_pair_terms_w_var() { let mut count = 0; r.each_iter(|it, index, ()| { - if it.entity(index) == bob { - assert_eq!(it.id(0), world.id_from::<(Eats, Apples)>()); - assert_eq!(it.get_var_by_name("Food"), world.id_from::()); - assert_eq!(it.get_var(foo_d_var), world.id_from::()); - - assert_eq!(it.id(1), world.id_first::(alice)); + if it.entity(index).unwrap() == bob { + assert_eq!(it.id(0), world.id_view_from((id::(), id::()))); + assert_eq!( + it.get_var_by_name("Food"), + world.id_view_from(id::()) + ); + assert_eq!(it.get_var(foo_d_var), world.id_view_from(id::())); + + assert_eq!(it.id(1), world.id_view_from((id::(), alice))); assert_eq!(it.get_var_by_name("Person"), alice); assert_eq!(it.get_var(person_var), alice); count += 1; } - if it.entity(index) == alice { - assert_eq!(it.id(0), world.id_from::<(Eats, Pears)>()); - assert_eq!(it.get_var_by_name("Food"), world.id_from::()); - assert_eq!(it.get_var(foo_d_var), world.id_from::()); - - assert_eq!(it.id(1), world.id_first::(bob)); + if it.entity(index).unwrap() == alice { + assert_eq!(it.id(0), world.id_view_from((id::(), id::()))); + assert_eq!( + it.get_var_by_name("Food"), + world.id_view_from(id::()) + ); + assert_eq!(it.get_var(foo_d_var), world.id_view_from(id::())); + + assert_eq!(it.id(1), world.id_view_from((id::(), bob))); assert_eq!(it.get_var_by_name("Person"), bob); assert_eq!(it.get_var(person_var), bob); count += 1; @@ -434,13 +452,13 @@ fn query_builder_set_var() { let apples = world.entity(); let pears = world.entity(); - world.entity().add_first::(apples); + world.entity().add((id::(), apples)); - let e2 = world.entity().add_first::(pears); + let e2 = world.entity().add((id::(), pears)); let r = world .query::<()>() - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Food") .set_cache_kind(QueryCacheKind::Auto) @@ -452,8 +470,8 @@ fn query_builder_set_var() { r.iterable() .set_var(foo_d_var, pears) .each_iter(|it, index, ()| { - assert_eq!(it.entity(index), e2); - assert_eq!(it.id(0), world.id_first::(pears)); + assert_eq!(it.entity(index).unwrap(), e2); + assert_eq!(it.id(0), world.id_view_from((id::(), pears))); assert_eq!(it.get_var_by_name("Food"), pears); assert_eq!(it.get_var(foo_d_var), pears); count += 1; @@ -469,21 +487,21 @@ fn query_builder_set_2_vars() { let apples = world.entity(); let pears = world.entity(); - let bob = world.entity().add_first::(apples); + let bob = world.entity().add((id::(), apples)); let alice = world .entity() - .add_first::(pears) - .add_first::(bob); + .add((id::(), pears)) + .add((id::(), bob)); - bob.add_first::(alice); + bob.add((id::(), alice)); let r = world .query::<()>() - .with::<&Eats>() + .with(id::<&Eats>()) .second() .set_var("Food") - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Person") .set_cache_kind(QueryCacheKind::Auto) @@ -497,9 +515,9 @@ fn query_builder_set_2_vars() { .set_var(foo_d_var, pears) .set_var(person_var, bob) .each_iter(|it, index, ()| { - assert_eq!(it.entity(index), alice); - assert_eq!(it.id(0), world.id_first::(pears)); - assert_eq!(it.id(1), world.id_first::(bob)); + assert_eq!(it.entity(index).unwrap(), alice); + assert_eq!(it.id(0), world.id_view_from((id::(), pears))); + assert_eq!(it.id(1), world.id_view_from((id::(), bob))); assert_eq!(it.get_var_by_name("Food"), pears); assert_eq!(it.get_var(foo_d_var), pears); assert_eq!(it.get_var_by_name("Person"), bob); @@ -516,13 +534,13 @@ fn query_builder_set_var_by_name() { let apples = world.entity(); let pears = world.entity(); - world.entity().add_first::(apples); + world.entity().add((id::(), apples)); - let e2 = world.entity().add_first::(pears); + let e2 = world.entity().add((id::(), pears)); let r = world .query::<()>() - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Food") .set_cache_kind(QueryCacheKind::Auto) @@ -532,8 +550,8 @@ fn query_builder_set_var_by_name() { r.iterable() .set_var_expr("Food", pears) .each_iter(|it, index, ()| { - assert_eq!(it.entity(index), e2); - assert_eq!(it.id(0), world.id_first::(pears)); + assert_eq!(it.entity(index).unwrap(), e2); + assert_eq!(it.id(0), world.id_view_from((id::(), pears))); count += 1; }); assert_eq!(count, 1); @@ -546,21 +564,21 @@ fn query_builder_set_2_vars_by_name() { let apples = world.entity(); let pears = world.entity(); - let bob = world.entity().add_first::(apples); + let bob = world.entity().add((id::(), apples)); let alice = world .entity() - .add_first::(pears) - .add_first::(bob); + .add((id::(), pears)) + .add((id::(), bob)); - bob.add_first::(alice); + bob.add((id::(), alice)); let r = world .query::<()>() - .with::<&Eats>() + .with(id::<&Eats>()) .second() .set_var("Food") - .with::<&Likes>() + .with(id::<&Likes>()) .second() .set_var("Person") .set_cache_kind(QueryCacheKind::Auto) @@ -574,9 +592,9 @@ fn query_builder_set_2_vars_by_name() { .set_var_expr("Food", pears) .set_var_expr("Person", bob) .each_iter(|it, index, ()| { - assert_eq!(it.entity(index), alice); - assert_eq!(it.id(0), world.id_first::(pears)); - assert_eq!(it.id(1), world.id_first::(bob)); + assert_eq!(it.entity(index).unwrap(), alice); + assert_eq!(it.id(0), world.id_view_from((id::(), pears))); + assert_eq!(it.id(1), world.id_view_from((id::(), bob))); assert_eq!(it.get_var_by_name("Food"), pears); assert_eq!(it.get_var(foo_d_var), pears); assert_eq!(it.get_var_by_name("Person"), bob); @@ -592,7 +610,7 @@ fn query_builder_expr_w_var() { let rel = world.entity_named("Rel"); let obj = world.entity(); - let e = world.entity().add_id((rel, obj)); + let e = world.entity().add((rel, obj)); let r = world .query::<()>() @@ -605,7 +623,7 @@ fn query_builder_expr_w_var() { let mut count = 0; r.each_iter(|it, index, ()| { - assert_eq!(it.entity(index), e); + assert_eq!(it.entity(index).unwrap(), e); assert_eq!(it.pair(0).unwrap().second_id(), obj); count += 1; }); @@ -619,7 +637,7 @@ fn query_builder_add_1_type() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -641,8 +659,8 @@ fn query_builder_add_2_types() { let q = world .query::<()>() - .with::<&Position>() - .with::<&Velocity>() + .with(id::<&Position>()) + .with(id::<&Velocity>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -667,7 +685,7 @@ fn query_builder_add_1_type_w_1_type() { let q = world .query::<&Position>() - .with::<&Velocity>() + .with(id::<&Velocity>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -692,8 +710,8 @@ fn query_builder_add_2_types_w_1_type() { let q = world .query::<&Position>() - .with::<&Velocity>() - .with::<&Mass>() + .with(id::<&Velocity>()) + .with(id::<&Mass>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -723,12 +741,12 @@ fn query_builder_add_pair() { let q = world .query::<()>() - .with_id((likes, bob)) + .with((likes, bob)) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e1 = world.entity().add_id((likes, bob)); - world.entity().add_id((likes, alice)); + let e1 = world.entity().add((likes, bob)); + world.entity().add((likes, alice)); let mut count = 0; q.each_entity(|e, _| { @@ -745,7 +763,7 @@ fn query_builder_add_not() { let q = world .query::<&Position>() - .with::<&Velocity>() + .with(id::<&Velocity>()) .set_oper(OperKind::Not) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -771,9 +789,9 @@ fn query_builder_add_or() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_oper(OperKind::Or) - .with::<&Velocity>() + .with(id::<&Velocity>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -796,8 +814,8 @@ fn query_builder_add_optional() { let q = world .query::<()>() - .with::<&Position>() - .with::<&Velocity>() + .with(id::<&Position>()) + .with(id::<&Velocity>()) .set_oper(OperKind::Optional) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -902,7 +920,7 @@ fn query_builder_singleton_term() { let q = world .query::<&SelfRef>() - .with::<&Other>() + .with(id::<&Other>()) .singleton() .set_inout() .set_cache_kind(QueryCacheKind::Auto) @@ -924,7 +942,7 @@ fn query_builder_singleton_term() { assert_eq!(o.value, 10); for i in it.iter() { - assert_eq!(it.entity(i), it.entity(i).id()); + assert_eq!(it.entity(i).unwrap(), it.entity(i).unwrap().id()); count += 1; } } @@ -939,11 +957,11 @@ fn query_builder_isa_superset_term() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<&SelfRef>() - .with::<&Other>() + .with(id::<&Other>()) .src() .up_id(*flecs::IsA) .set_in() @@ -952,11 +970,11 @@ fn query_builder_isa_superset_term() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -968,7 +986,7 @@ fn query_builder_isa_superset_term() { assert_eq!(o.value, 10); for i in it.iter() { - assert_eq!(it.entity(i), it.entity(i).id()); + assert_eq!(it.entity(i).unwrap(), it.entity(i).unwrap().id()); count += 1; } } @@ -983,11 +1001,11 @@ fn query_builder_isa_self_superset_term() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<&SelfRef>() - .with::<&Other>() + .with(id::<&Other>()) .src() .self_() .up_id(*flecs::IsA) @@ -997,11 +1015,11 @@ fn query_builder_isa_self_superset_term() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 20 }); e.set(SelfRef { value: e.id() }); @@ -1025,7 +1043,7 @@ fn query_builder_isa_self_superset_term() { } for i in it.iter() { - assert_eq!(it.entity(i), it.entity(i).id()); + assert_eq!(it.entity(i).unwrap(), it.entity(i).unwrap().id()); count += 1; } } @@ -1041,7 +1059,7 @@ fn query_builder_childof_superset_term() { let q = world .query::<&SelfRef>() - .with::<&Other>() + .with(id::<&Other>()) .src() .up() .set_in() @@ -1050,11 +1068,11 @@ fn query_builder_childof_superset_term() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -1066,7 +1084,7 @@ fn query_builder_childof_superset_term() { assert_eq!(o.value, 10); for i in it.iter() { - assert_eq!(it.entity(i), it.entity(i).id()); + assert_eq!(it.entity(i).unwrap(), it.entity(i).unwrap().id()); count += 1; } } @@ -1081,7 +1099,7 @@ fn query_builder_childof_self_superset_term() { let q = world .query::<&SelfRef>() - .with::<&Other>() + .with(id::<&Other>()) .src() .self_() .up() @@ -1091,11 +1109,11 @@ fn query_builder_childof_self_superset_term() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 20 }); e.set(SelfRef { value: e.id() }); @@ -1119,7 +1137,7 @@ fn query_builder_childof_self_superset_term() { } for i in it.iter() { - assert_eq!(it.entity(i), it.entity(i).id()); + assert_eq!(it.entity(i).unwrap(), it.entity(i).unwrap().id()); count += 1; } } @@ -1135,7 +1153,7 @@ fn query_builder_isa_superset_term_w_each() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<(&SelfRef, &Other)>() @@ -1147,11 +1165,11 @@ fn query_builder_isa_superset_term_w_each() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -1171,7 +1189,7 @@ fn query_builder_isa_self_superset_term_w_each() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<(&SelfRef, &Other)>() @@ -1184,11 +1202,11 @@ fn query_builder_isa_self_superset_term_w_each() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((*flecs::IsA, base)); + let e = world.entity().add((*flecs::IsA, base)); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 10 }); e.set(SelfRef { value: e.id() }); @@ -1220,11 +1238,11 @@ fn query_builder_childof_superset_term_w_each() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -1253,11 +1271,11 @@ fn query_builder_childof_self_superset_term_w_each() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 10 }); e.set(SelfRef { value: e.id() }); @@ -1281,7 +1299,7 @@ fn query_builder_isa_superset_shortcut() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<(&SelfRef, &Other)>() @@ -1292,11 +1310,11 @@ fn query_builder_isa_superset_shortcut() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -1316,7 +1334,7 @@ fn query_builder_isa_superset_shortcut_w_self() { world .component::() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let q = world .query::<(&SelfRef, &Other)>() @@ -1328,11 +1346,11 @@ fn query_builder_isa_superset_shortcut_w_self() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().is_a_id(base); + let e = world.entity().is_a(base); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 10 }); e.set(SelfRef { value: e.id() }); @@ -1363,11 +1381,11 @@ fn query_builder_childof_superset_shortcut() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let mut count = 0; @@ -1395,11 +1413,11 @@ fn query_builder_childof_superset_shortcut_w_self() { let base = world.entity().set(Other { value: 10 }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); - let e = world.entity().child_of_id(base); + let e = world.entity().child_of(base); e.set(SelfRef { value: e.id() }); let e = world.entity().set(Other { value: 10 }); e.set(SelfRef { value: e.id() }); @@ -1427,18 +1445,18 @@ fn query_builder_relation() { let q = world .query::<&SelfRef>() - .with_id((likes, bob)) + .with((likes, bob)) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add_id((likes, bob)); + let e = world.entity().add((likes, bob)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, bob)); + let e = world.entity().add((likes, bob)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, alice)); + let e = world.entity().add((likes, alice)); e.set(SelfRef { value: Entity(0) }); - let e = world.entity().add_id((likes, alice)); + let e = world.entity().add((likes, alice)); e.set(SelfRef { value: Entity(0) }); let mut count = 0; @@ -1461,18 +1479,18 @@ fn query_builder_relation_w_object_wildcard() { let q = world .query::<&SelfRef>() - .with_id((likes, *flecs::Wildcard)) + .with((likes, *flecs::Wildcard)) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add_id((likes, bob)); + let e = world.entity().add((likes, bob)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, bob)); + let e = world.entity().add((likes, bob)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, alice)); + let e = world.entity().add((likes, alice)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, alice)); + let e = world.entity().add((likes, alice)); e.set(SelfRef { value: e.id() }); let e = world.entity(); @@ -1501,18 +1519,18 @@ fn query_builder_relation_w_predicate_wildcard() { let q = world .query::<&SelfRef>() - .with_id((*flecs::Wildcard, alice)) + .with((*flecs::Wildcard, alice)) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add_id((likes, alice)); + let e = world.entity().add((likes, alice)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((dislikes, alice)); + let e = world.entity().add((dislikes, alice)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((likes, bob)); + let e = world.entity().add((likes, bob)); e.set(SelfRef { value: Entity(0) }); - let e = world.entity().add_id((dislikes, bob)); + let e = world.entity().add((dislikes, bob)); e.set(SelfRef { value: Entity(0) }); let mut count = 0; @@ -1535,18 +1553,18 @@ fn query_builder_add_pair_w_rel_type() { let q = world .query::<&SelfRef>() - .with_first::<&Likes>(*flecs::Wildcard) + .with((id::<&Likes>(), *flecs::Wildcard)) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add_first::(alice); + let e = world.entity().add((id::(), alice)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((dislikes, alice)); + let e = world.entity().add((dislikes, alice)); e.set(SelfRef { value: Entity(0) }); - let e = world.entity().add_first::(bob); + let e = world.entity().add((id::(), bob)); e.set(SelfRef { value: e.id() }); - let e = world.entity().add_id((dislikes, bob)); + let e = world.entity().add((dislikes, bob)); e.set(SelfRef { value: Entity(0) }); let mut count = 0; @@ -1565,7 +1583,7 @@ fn query_builder_template_term() { let q = world .query::<&Position>() - .with::<&Template>() + .with(id::<&Template>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -1590,7 +1608,7 @@ fn query_builder_explicit_subject_w_id() { let q = world .query::<&Position>() - .with::<&Position>() + .with(id::<&Position>()) .set_id(*flecs::This_) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -1618,8 +1636,8 @@ fn query_builder_explicit_subject_w_type() { let q = world .query::<&Position>() - .with::<&Position>() - .set_src::() + .with(id::<&Position>()) + .set_src(id::()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -1644,13 +1662,13 @@ fn query_builder_explicit_object_w_id() { let q = world .query::<()>() - .with_id(likes) - .set_second_id(alice) + .with(likes) + .set_second(alice) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e1 = world.entity().add_id((likes, alice)); - world.entity().add_id((likes, bob)); + let e1 = world.entity().add((likes, alice)); + world.entity().add((likes, bob)); let mut count = 0; q.each_entity(|e, _| { @@ -1670,15 +1688,15 @@ fn query_builder_explicit_object_w_type() { let q = world .query::<()>() - .with_id(likes) - .set_second::() + .with(likes) + .set_second(id::()) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() - .add_id((likes, *world.id_from::().id())); - world.entity().add_id((likes, bob)); + .add((likes, *world.id_view_from(id::()).id())); + world.entity().add((likes, bob)); let mut count = 0; q.each_entity(|e, _| { @@ -1696,7 +1714,7 @@ fn query_builder_explicit_term() { // let q = world // .query::<()>() - // .with(world.term(world.id_from::())) + // .with(world.term(world.id_view_from(id::()))) // .set_cache_kind(QueryCacheKind::Auto) // .build(); @@ -1740,12 +1758,12 @@ fn query_builder_explicit_term_w_pair_type() { // let world = create_world(); // let q = world.query::<()>() - // .with_id((world.term())) + // .with((world.term())) // .set_cache_kind(QueryCacheKind::Auto) // .build(); - // let e1 = world.entity().add::<(Likes, alice)>(); - // world.entity().add::<(Likes, bob)>(); + // let e1 = world.entity().add((id::(), id::())); + // world.entity().add((id::(), id::())); // let mut count = 0; // q.each_entity(|e, _| { @@ -1769,8 +1787,8 @@ fn query_builder_explicit_term_w_id() { // .set_cache_kind(QueryCacheKind::Auto) // .build(); - // let e1 = world.entity().add_id(apples); - // world.entity().add_id(pears); + // let e1 = world.entity().add(apples); + // world.entity().add(pears); // let mut count = 0; // q.each_entity(|e, _| { @@ -1794,8 +1812,8 @@ fn query_builder_explicit_term_w_pair_id() { // .set_cache_kind(QueryCacheKind::Auto) // .build(); - // let e1 = world.entity().add_id((likes,apples)); - // world.entity().add_id((likes,pears)); + // let e1 = world.entity().add((likes,apples)); + // world.entity().add((likes,pears)); // let mut count = 0; // q.each_entity(|e, _| { @@ -1814,14 +1832,15 @@ fn query_builder_1_term_to_empty() { let apples = world.entity(); let mut q = world.query::<()>(); - q.with::<&Position>().set_cache_kind(QueryCacheKind::Auto); - q.with_id((likes, apples)); + q.with(id::<&Position>()) + .set_cache_kind(QueryCacheKind::Auto); + q.with((likes, apples)); let q = q.build(); assert_eq!(q.field_count(), 2); - assert_eq!(q.term(0).id(), world.id_from::()); - assert_eq!(q.term(1).id(), world.id_from_id((likes, apples))); + assert_eq!(q.term(0).id(), world.id_view_from(id::())); + assert_eq!(q.term(1).id(), world.id_view_from((likes, apples))); } #[test] @@ -1857,14 +1876,14 @@ fn query_builder_optional_tag_is_set() { let q = world .query::<()>() - .with::<&TagA>() - .with::<&TagB>() + .with(id::<&TagA>()) + .with(id::<&TagB>()) .set_oper(OperKind::Optional) .set_cache_kind(QueryCacheKind::Auto) .build(); - let e_1 = world.entity().add::().add::(); - let e_2 = world.entity().add::(); + let e_1 = world.entity().add(id::()).add(id::()); + let e_2 = world.entity().add(id::()); let mut count = 0; @@ -1874,11 +1893,11 @@ fn query_builder_optional_tag_is_set() { count += it.count(); - if it.entity(0) == e_1 { + if it.entity(0).unwrap() == e_1 { assert!(it.is_set(0)); assert!(it.is_set(1)); } else { - assert_eq!(it.entity(0), e_2); + assert_eq!(it.entity(0).unwrap(), e_2); assert!(it.is_set(0)); assert!(!it.is_set(1)); } @@ -1894,16 +1913,16 @@ fn query_builder_10_terms() { let f = world .query::<()>() - .with::<&TagA>() - .with::<&TagB>() - .with::<&TagC>() - .with::<&TagD>() - .with::<&TagE>() - .with::<&TagF>() - .with::<&TagG>() - .with::<&TagH>() - .with::<&TagI>() - .with::<&TagJ>() + .with(id::<&TagA>()) + .with(id::<&TagB>()) + .with(id::<&TagC>()) + .with(id::<&TagD>()) + .with(id::<&TagE>()) + .with(id::<&TagF>()) + .with(id::<&TagG>()) + .with(id::<&TagH>()) + .with(id::<&TagI>()) + .with(id::<&TagJ>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -1911,23 +1930,23 @@ fn query_builder_10_terms() { let e = world .entity() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::(); + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()); let mut count = 0; f.run(|mut it| { while it.next() { - assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); assert_eq!(it.field_count(), 10); + assert_eq!(it.entity(0).unwrap(), e); + assert_eq!(it.count(), 1); count += 1; } }); @@ -1941,22 +1960,22 @@ fn query_builder_16_terms() { let f = world .query::<()>() - .with::<&TagA>() - .with::<&TagB>() - .with::<&TagC>() - .with::<&TagD>() - .with::<&TagE>() - .with::<&TagF>() - .with::<&TagG>() - .with::<&TagH>() - .with::<&TagI>() - .with::<&TagJ>() - .with::<&TagK>() - .with::<&TagL>() - .with::<&TagM>() - .with::<&TagN>() - .with::<&TagO>() - .with::<&TagP>() + .with(id::<&TagA>()) + .with(id::<&TagB>()) + .with(id::<&TagC>()) + .with(id::<&TagD>()) + .with(id::<&TagE>()) + .with(id::<&TagF>()) + .with(id::<&TagG>()) + .with(id::<&TagH>()) + .with(id::<&TagI>()) + .with(id::<&TagJ>()) + .with(id::<&TagK>()) + .with(id::<&TagL>()) + .with(id::<&TagM>()) + .with(id::<&TagN>()) + .with(id::<&TagO>()) + .with(id::<&TagP>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -1964,32 +1983,32 @@ fn query_builder_16_terms() { let e = world .entity() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::() - .add::(); + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()) + .add(id::()); let mut count = 0; f.run(|mut it| { while it.next() { assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); + assert_eq!(it.entity(0).unwrap(), e); assert_eq!(it.field_count(), 16); count += 1; } @@ -2030,19 +2049,19 @@ fn query_builder_group_by_raw() { let q = world .query::<()>() - .with::<&TagX>() - .group_by_id_fn(world.entity_from::(), Some(group_by_first_id)) + .with(id::<&TagX>()) + .group_by_fn(world.entity_from::(), Some(group_by_first_id)) .build(); let q_reverse = world .query::<()>() - .with::<&TagX>() - .group_by_id_fn(world.entity_from::(), Some(group_by_first_id_negated)) + .with(id::<&TagX>()) + .group_by_fn(world.entity_from::(), Some(group_by_first_id_negated)) .build(); - let e3 = world.entity().add::().add::(); - let e2 = world.entity().add::().add::(); - let e1 = world.entity().add::().add::(); + let e3 = world.entity().add(id::()).add(id::()); + let e2 = world.entity().add(id::()).add(id::()); + let e1 = world.entity().add(id::()).add(id::()); let mut count = 0; @@ -2050,11 +2069,11 @@ fn query_builder_group_by_raw() { while it.next() { assert_eq!(it.count(), 1); if count == 0 { - assert!(it.entity(0) == e1); + assert!(it.entity(0).unwrap() == e1); } else if count == 1 { - assert!(it.entity(0) == e2); + assert!(it.entity(0).unwrap() == e2); } else if count == 2 { - assert!(it.entity(0) == e3); + assert!(it.entity(0).unwrap() == e3); } else { panic!(); } @@ -2068,11 +2087,11 @@ fn query_builder_group_by_raw() { while it.next() { assert_eq!(it.count(), 1); if count == 0 { - assert!(it.entity(0) == e3); + assert!(it.entity(0).unwrap() == e3); } else if count == 1 { - assert!(it.entity(0) == e2); + assert!(it.entity(0).unwrap() == e2); } else if count == 2 { - assert!(it.entity(0) == e1); + assert!(it.entity(0).unwrap() == e1); } else { panic!(); } @@ -2093,19 +2112,19 @@ fn query_builder_group_by_template() { let q = world .query::<()>() - .with::<&TagX>() - .group_by_fn::(Some(group_by_first_id)) + .with(id::<&TagX>()) + .group_by_fn(id::(), Some(group_by_first_id)) .build(); let q_reverse = world .query::<()>() - .with::<&TagX>() - .group_by_fn::(Some(group_by_first_id_negated)) + .with(id::<&TagX>()) + .group_by_fn(id::(), Some(group_by_first_id_negated)) .build(); - let e3 = world.entity().add::().add::(); - let e2 = world.entity().add::().add::(); - let e1 = world.entity().add::().add::(); + let e3 = world.entity().add(id::()).add(id::()); + let e2 = world.entity().add(id::()).add(id::()); + let e1 = world.entity().add(id::()).add(id::()); let mut count = 0; @@ -2113,11 +2132,11 @@ fn query_builder_group_by_template() { while it.next() { assert_eq!(it.count(), 1); if count == 0 { - assert!(it.entity(0) == e1); + assert!(it.entity(0).unwrap() == e1); } else if count == 1 { - assert!(it.entity(0) == e2); + assert!(it.entity(0).unwrap() == e2); } else if count == 2 { - assert!(it.entity(0) == e3); + assert!(it.entity(0).unwrap() == e3); } else { panic!(); } @@ -2131,11 +2150,11 @@ fn query_builder_group_by_template() { while it.next() { assert_eq!(it.count(), 1); if count == 0 { - assert!(it.entity(0) == e3); + assert!(it.entity(0).unwrap() == e3); } else if count == 1 { - assert!(it.entity(0) == e2); + assert!(it.entity(0).unwrap() == e2); } else if count == 2 { - assert!(it.entity(0) == e1); + assert!(it.entity(0).unwrap() == e1); } else { panic!(); } @@ -2155,7 +2174,7 @@ unsafe extern "C-unwind" fn group_by_rel( let mut id_matched: u64 = 0; let ref_id = &mut id_matched; if sys::ecs_search(world, table, ecs_pair(id, *flecs::Wildcard), ref_id) != -1 { - return *ecs_second(id_matched); + return *ecs_second(id_matched, world); } 0 } @@ -2171,26 +2190,26 @@ fn query_builder_group_by_iter_one() { let tgt_c = world.entity(); let tag = world.entity(); - world.entity().add_id((rel, tgt_a)); - let e2 = world.entity().add_id((rel, tgt_b)); - world.entity().add_id((rel, tgt_c)); + world.entity().add((rel, tgt_a)); + let e2 = world.entity().add((rel, tgt_b)); + world.entity().add((rel, tgt_c)); - world.entity().add_id((rel, tgt_a)).add_id(tag); - let e5 = world.entity().add_id((rel, tgt_b)).add_id(tag); - world.entity().add_id((rel, tgt_c)).add_id(tag); + world.entity().add((rel, tgt_a)).add(tag); + let e5 = world.entity().add((rel, tgt_b)).add(tag); + world.entity().add((rel, tgt_c)).add(tag); let q = world .query::<()>() - .with_id((rel, *flecs::Wildcard)) - .group_by_id_fn(rel, Some(group_by_rel)) + .with((rel, *flecs::Wildcard)) + .group_by_fn(rel, Some(group_by_rel)) .build(); let mut e2_found = false; let mut e5_found = false; let mut count = 0; - q.iterable().set_group_id(tgt_b).each_iter(|it, size, ()| { - let e = it.entity(size); + q.iterable().set_group(tgt_b).each_iter(|it, size, ()| { + let e = it.entity(size).unwrap(); assert_eq!(it.group_id(), tgt_b); if e == e2 { @@ -2211,36 +2230,47 @@ fn query_builder_group_by_iter_one() { fn query_builder_group_by_iter_one_template() { let world = World::new(); - world.entity().add::<(Rel, TagA)>(); - let e2 = world.entity().add::<(Rel, TagB)>(); - world.entity().add::<(Rel, TagC)>(); + world.entity().add((id::(), id::())); + let e2 = world.entity().add((id::(), id::())); + world.entity().add((id::(), id::())); - world.entity().add::<(Rel, TagA)>().add::(); - let e5 = world.entity().add::<(Rel, TagB)>().add::(); - world.entity().add::<(Rel, TagC)>().add::(); + world + .entity() + .add((id::(), id::())) + .add(id::()); + let e5 = world + .entity() + .add((id::(), id::())) + .add(id::()); + world + .entity() + .add((id::(), id::())) + .add(id::()); let q = world .query::<()>() - .with_first::<&Rel>(*flecs::Wildcard) - .group_by_fn::(Some(group_by_rel)) + .with((id::<&Rel>(), *flecs::Wildcard)) + .group_by_fn(id::(), Some(group_by_rel)) .build(); let mut e2_found = false; let mut e5_found = false; let mut count = 0; - q.iterable().set_group::().each_iter(|it, size, ()| { - let e = it.entity(size); - assert_eq!(it.group_id(), world.id_from::()); + q.iterable() + .set_group(id::()) + .each_iter(|it, size, ()| { + let e = it.entity(size).unwrap(); + assert_eq!(it.group_id(), world.id_view_from(id::())); - if e == e2 { - e2_found = true; - } - if e == e5 { - e5_found = true; - } - count += 1; - }); + if e == e2 { + e2_found = true; + } + if e == e5 { + e5_found = true; + } + count += 1; + }); assert_eq!(2, count); assert!(e2_found); @@ -2257,18 +2287,18 @@ fn query_builder_group_by_iter_one_all_groups() { let tgt_c = world.entity(); let tag = world.entity(); - let e1 = world.entity().add_id((rel, tgt_a)); - let e2 = world.entity().add_id((rel, tgt_b)); - let e3 = world.entity().add_id((rel, tgt_c)); + let e1 = world.entity().add((rel, tgt_a)); + let e2 = world.entity().add((rel, tgt_b)); + let e3 = world.entity().add((rel, tgt_c)); - let e4 = world.entity().add_id((rel, tgt_a)).add_id(tag); - let e5 = world.entity().add_id((rel, tgt_b)).add_id(tag); - let e6 = world.entity().add_id((rel, tgt_c)).add_id(tag); + let e4 = world.entity().add((rel, tgt_a)).add(tag); + let e5 = world.entity().add((rel, tgt_b)).add(tag); + let e6 = world.entity().add((rel, tgt_c)).add(tag); let q = world .query::<()>() - .with_id((rel, *flecs::Wildcard)) - .group_by_id_fn(rel, Some(group_by_rel)) + .with((rel, *flecs::Wildcard)) + .group_by_fn(rel, Some(group_by_rel)) .build(); let group_id = Cell::new(0u64); @@ -2281,7 +2311,7 @@ fn query_builder_group_by_iter_one_all_groups() { let e6_found = Cell::new(false); let func = |it: TableIter, size: usize, ()| { - let e = it.entity(size); + let e = it.entity(size).unwrap(); if it.group_id() == group_id.get() { if e == e1 { e1_found.set(true); @@ -2306,19 +2336,19 @@ fn query_builder_group_by_iter_one_all_groups() { }; group_id.set(*tgt_b.id()); - q.iterable().set_group_id(tgt_b).each_iter(func); + q.iterable().set_group(tgt_b).each_iter(func); assert_eq!(2, count.get()); assert!(e2_found.get()); assert!(e5_found.get()); group_id.set(*tgt_a.id()); - q.iterable().set_group_id(tgt_a).each_iter(func); + q.iterable().set_group(tgt_a).each_iter(func); assert_eq!(4, count.get()); assert!(e1_found.get()); assert!(e4_found.get()); group_id.set(*tgt_c.id()); - q.iterable().set_group_id(tgt_c).each_iter(func); + q.iterable().set_group(tgt_c).each_iter(func); assert_eq!(6, count.get()); assert!(e3_found.get()); assert!(e6_found.get()); @@ -2333,14 +2363,14 @@ fn query_builder_group_by_default_func_w_id() { let tgt_b = world.entity(); let tgt_c = world.entity(); - let e1 = world.entity().add_id((rel, tgt_c)); - let e2 = world.entity().add_id((rel, tgt_b)); - let e3 = world.entity().add_id((rel, tgt_a)); + let e1 = world.entity().add((rel, tgt_c)); + let e2 = world.entity().add((rel, tgt_b)); + let e3 = world.entity().add((rel, tgt_a)); let q = world .query::<()>() - .with_id((rel, *flecs::Wildcard)) - .group_by_id(rel) + .with((rel, *flecs::Wildcard)) + .group_by(rel) .build(); let mut e1_found = false; @@ -2349,7 +2379,7 @@ fn query_builder_group_by_default_func_w_id() { let mut count = 0; q.each_iter(|it: TableIter, size: usize, ()| { - let e = it.entity(size); + let e = it.entity(size).unwrap(); if e == e1 { assert_eq!(it.group_id(), tgt_c); assert!(!e1_found); @@ -2388,14 +2418,14 @@ fn query_builder_group_by_default_func_w_type() { let tgt_b = world.entity(); let tgt_c = world.entity(); - let e1 = world.entity().add_first::(tgt_c); - let e2 = world.entity().add_first::(tgt_b); - let e3 = world.entity().add_first::(tgt_a); + let e1 = world.entity().add((id::(), tgt_c)); + let e2 = world.entity().add((id::(), tgt_b)); + let e3 = world.entity().add((id::(), tgt_a)); let q = world .query::<()>() - .with_first::<&Rel>(*flecs::Wildcard) - .group_by::() + .with((id::(), id::())) + .group_by(id::()) .build(); let mut e1_found = false; @@ -2404,7 +2434,7 @@ fn query_builder_group_by_default_func_w_type() { let mut count = 0; q.each_iter(|it: TableIter, size: usize, ()| { - let e = it.entity(size); + let e = it.entity(size).unwrap(); if e == e1 { assert_eq!(it.group_id(), tgt_c); assert!(!e1_found); @@ -2474,14 +2504,14 @@ fn query_builder_group_by_callbacks() { let tgt_b = world.entity(); let tgt_c = world.entity(); - let e1 = world.entity().add_first::(tgt_c); - let e2 = world.entity().add_first::(tgt_b); - let e3 = world.entity().add_first::(tgt_a); + let e1 = world.entity().add((id::(), tgt_c)); + let e2 = world.entity().add((id::(), tgt_b)); + let e3 = world.entity().add((id::(), tgt_a)); let q = world .query::<()>() - .with_first::<&Rel>(*flecs::Wildcard) - .group_by::() + .with((id::<&Rel>(), *flecs::Wildcard)) + .group_by(id::()) .group_by_ctx(cell_count_group_ctx.as_ptr() as *mut c_void, None) .on_group_create(Some(callback_group_create)) .on_group_delete(Some(callback_group_delete)) @@ -2493,7 +2523,7 @@ fn query_builder_group_by_callbacks() { let mut count = 0; q.each_iter(|it: TableIter, size: usize, ()| { - let e = it.entity(size); + let e = it.entity(size).unwrap(); if e == e1 { assert_eq!(it.group_id(), tgt_c); assert!(!e1_found); @@ -2536,7 +2566,7 @@ fn query_builder_create_w_no_template_args() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -2559,11 +2589,11 @@ fn query_builder_any_wildcard() { let apple = world.entity(); let mango = world.entity(); - let e1 = world.entity().add_id((likes, apple)).add_id((likes, mango)); + let e1 = world.entity().add((likes, apple)).add((likes, mango)); let q = world .query::<()>() - .with_id((likes, *flecs::Any)) + .with((likes, *flecs::Any)) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -2582,25 +2612,25 @@ fn query_builder_cascade() { let tag = world .entity() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let foo_ = world.entity(); let bar = world.entity(); - let e0 = world.entity().add_id(tag); - let e1 = world.entity().is_a_id(e0); - let e2 = world.entity().is_a_id(e1); - let e3 = world.entity().is_a_id(e2); + let e0 = world.entity().add(tag); + let e1 = world.entity().is_a(e0); + let e2 = world.entity().is_a(e1); + let e3 = world.entity().is_a(e2); let q = world .query::<()>() - .with_id(tag) + .with(tag) .cascade_id(*flecs::IsA) .set_cached() .build(); - e1.add_id(bar); - e2.add_id(foo_); + e1.add(bar); + e2.add(foo_); let mut e1_found = false; let mut e2_found = false; @@ -2642,26 +2672,26 @@ fn query_builder_cascade_desc() { let tag = world .entity() - .add_id((flecs::OnInstantiate::ID, flecs::Inherit::ID)); + .add((flecs::OnInstantiate::ID, flecs::Inherit::ID)); let foo_ = world.entity(); let bar = world.entity(); - let e0 = world.entity().add_id(tag); - let e1 = world.entity().is_a_id(e0); - let e2 = world.entity().is_a_id(e1); - let e3 = world.entity().is_a_id(e2); + let e0 = world.entity().add(tag); + let e1 = world.entity().is_a(e0); + let e2 = world.entity().is_a(e1); + let e3 = world.entity().is_a(e2); let q = world .query::<()>() - .with_id(tag) + .with(tag) .cascade_id(*flecs::IsA) .desc() .set_cached() .build(); - e1.add_id(bar); - e2.add_id(foo_); + e1.add(bar); + e2.add(foo_); let mut e1_found = false; let mut e2_found = false; @@ -2705,20 +2735,20 @@ fn query_builder_cascade_w_relationship() { let foo_ = world.entity(); let bar = world.entity(); - let e0 = world.entity().add_id(tag); - let e1 = world.entity().child_of_id(e0); - let e2 = world.entity().child_of_id(e1); - let e3 = world.entity().child_of_id(e2); + let e0 = world.entity().add(tag); + let e1 = world.entity().child_of(e0); + let e2 = world.entity().child_of(e1); + let e3 = world.entity().child_of(e2); let q = world .query::<()>() - .with_id(tag) + .with(tag) .cascade_id(*flecs::ChildOf) .set_cached() .build(); - e1.add_id(bar); - e2.add_id(foo_); + e1.add(bar); + e2.add(foo_); let mut e1_found = false; let mut e2_found = false; @@ -2758,24 +2788,24 @@ fn query_builder_cascade_w_relationship() { fn query_builder_up_w_type() { let world = World::new(); - world.component::().add_id(*flecs::Traversable); + world.component::().add(*flecs::Traversable); let q = world .query::<&SelfRef2>() - .with::<&Other>() + .with(id::<&Other>()) .src() - .up_type::() + .up_id(id::()) .set_in() .set_cache_kind(QueryCacheKind::Auto) .build(); let base = world.entity().set(Other { value: 10 }); - let e = world.entity().add_first::(base); + let e = world.entity().add((id::(), base)); e.set(SelfRef2 { value: e.id() }); - let e = world.entity().add_first::(base); + let e = world.entity().add((id::(), base)); e.set(SelfRef2 { value: e.id() }); - let e = world.entity().add_first::(base); + let e = world.entity().add((id::(), base)); e.set(SelfRef2 { value: e.id() }); let mut count = 0; @@ -2788,7 +2818,7 @@ fn query_builder_up_w_type() { assert_eq!(o.value, 10); for i in it.iter() { - assert_eq!(it.entity(i), s[i].value); + assert_eq!(it.entity(i).unwrap(), s[i].value); count += 1; } } @@ -2801,26 +2831,26 @@ fn query_builder_up_w_type() { fn query_builder_cascade_w_type() { let world = World::new(); - world.component::().add_id(*flecs::Traversable); + world.component::().add(*flecs::Traversable); let tag = world.entity(); let foo_ = world.entity(); let bar = world.entity(); - let e0 = world.entity().add_id(tag); - let e1 = world.entity().add_first::(e0); - let e2 = world.entity().add_first::(e1); - let e3 = world.entity().add_first::(e2); + let e0 = world.entity().add(tag); + let e1 = world.entity().add((id::(), e0)); + let e2 = world.entity().add((id::(), e1)); + let e3 = world.entity().add((id::(), e2)); let q = world .query::<()>() - .with_id(tag) - .cascade_type::() + .with(tag) + .cascade_id(id::()) .set_cached() .build(); - e1.add_id(bar); - e2.add_id(foo_); + e1.add(bar); + e2.add(foo_); let mut e1_found = false; let mut e2_found = false; @@ -2865,7 +2895,7 @@ fn query_builder_named_query() { let q = world .query_named::<()>("my_query") - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -2887,10 +2917,10 @@ fn query_builder_term_w_write() { let q = world .query::<()>() - .with::<&Position>() - .with::<&Position>() + .with(id::<&Position>()) + .with(id::<&Position>()) .write_curr() - .with::<&mut Position>() + .with(id::<&mut Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -2908,8 +2938,8 @@ fn query_builder_term_w_read() { let q = world .query::<()>() - .with::<&Position>() - .with::<&Position>() + .with(id::<&Position>()) + .with(id::<&Position>()) .read_curr() .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -2935,7 +2965,7 @@ fn query_builder_iter_w_stage() { // let mut count = 0; // q.each(stage, [&](flecs::iter& it, size_t i, Position&) { // assert_eq!(it.world(), stage); - // assert_eq!(it.entity(i), e1); + // assert_eq!(it.entity(i).unwrap(), e1); // count += 1; // }); @@ -2958,7 +2988,7 @@ fn query_builder_builder_force_assign_operator() { // let q = world // .query::<()>() - // .with::<&Position>() + // .with(id::<&Position>()) // .set_cache_kind(QueryCacheKind::Auto) // .build(); // let entity_query = q.entity().id(); @@ -3209,15 +3239,19 @@ fn query_builder_world_each_query_2_components_no_entity() { fn query_builder_term_after_arg() { let world = World::new(); - let e_1 = world.entity().add::().add::().add::(); + let e_1 = world + .entity() + .add(id::()) + .add(id::()) + .add(id::()); - world.entity().add::().add::(); + world.entity().add(id::()).add(id::()); let f = world .query::<(&TagA, &TagB)>() .term_at(0) - .set_src_id(*flecs::This_) // dummy - .with::<&TagC>() + .set_src(*flecs::This_) // dummy + .with(id::<&TagC>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3227,7 +3261,7 @@ fn query_builder_term_after_arg() { f.run(|mut it| { while it.next() { for i in it.iter() { - assert_eq!(it.entity(i), e_1); + assert_eq!(it.entity(i).unwrap(), e_1); count += 1; } } @@ -3273,7 +3307,7 @@ fn query_builder_const_in_term() { let f = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3297,8 +3331,11 @@ fn query_builder_const_in_term() { fn query_builder_const_optional() { let world = World::new(); - world.entity().set(Position { x: 10, y: 20 }).add::(); - world.entity().add::(); + world + .entity() + .set(Position { x: 10, y: 20 }) + .add(id::()); + world.entity().add(id::()); let f = world .query::<(&TagD, Option<&Position>)>() @@ -3332,7 +3369,7 @@ fn query_builder_2_terms_w_expr() { let a = world.entity_named("A"); let b = world.entity_named("B"); - let e1 = world.entity().add_id(a).add_id(b); + let e1 = world.entity().add(a).add(b); let f = world .query::<()>() @@ -3344,7 +3381,7 @@ fn query_builder_2_terms_w_expr() { let mut count = 0; f.each_iter(|it, index, ()| { - if it.entity(index) == e1 { + if it.entity(index).unwrap() == e1 { assert_eq!(it.id(0), a); assert_eq!(it.id(1), b); count += 1; @@ -3386,20 +3423,20 @@ fn query_builder_operator_shortcuts() { let query = world .query::<()>() - .with_id(a) + .with(a) .and() - .with_id(b) + .with(b) .or() - .with_id(c) - .with_id(d) + .with(c) + .with(d) .not() - .with_id(e) + .with(e) .optional() - .with_id(f) + .with(f) .and_from() - .with_id(g) + .with(g) .or_from() - .with_id(h) + .with(h) .not_from() .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3448,13 +3485,13 @@ fn query_builder_inout_shortcuts() { let query = world .query::<()>() - .with_id(a) + .with(a) .set_in() - .with_id(b) + .with(b) .set_out() - .with_id(c) + .with(c) .set_inout() - .with_id(d) + .with(d) .set_inout_none() .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3524,8 +3561,8 @@ fn query_builder_iter_column_w_const_as_ptr() { .build(); let base = world.prefab().set(Position { x: 10, y: 20 }); - world.entity().is_a_id(base); - world.entity().is_a_id(base); + world.entity().is_a(base); + world.entity().is_a(base); let mut count = 0; f.run(|mut it| { @@ -3543,13 +3580,13 @@ fn query_builder_iter_column_w_const_as_ptr() { } #[test] -fn query_builder_with_id() { +fn query_builder_with() { let world = World::new(); let q = world .query::<()>() - .with_id(world.id_from::()) - .with_id(world.id_from::()) + .with(world.id_view_from(id::())) + .with(world.id_view_from(id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3576,8 +3613,8 @@ fn query_builder_with_name() { let q = world .query::<()>() - .with::<&Position>() - .with_name("flecs.common_test.Velocity") + .with(id::<&Position>()) + .with("flecs.common_test.Velocity") .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3602,8 +3639,8 @@ fn query_builder_with_component() { let q = world .query::<()>() - .with::<&Position>() - .with::<&Velocity>() + .with(id::<&Position>()) + .with(id::<&Velocity>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3632,19 +3669,19 @@ fn query_builder_with_pair_id() { let q = world .query::<()>() - .with::<&Position>() - .with_id((likes, apples)) + .with(id::<&Position>()) + .with((likes, apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3665,19 +3702,19 @@ fn query_builder_with_pair_name() { let q = world .query::<()>() - .with::<&Position>() - .with_names("likes", "Apples") + .with(id::<&Position>()) + .with(("likes", "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3694,19 +3731,19 @@ fn query_builder_with_pair_components() { let q = world .query::<()>() - .with::<&Position>() - .with::<(Likes, Apples)>() + .with(id::<&Position>()) + .with((id::(), id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add::<(Likes, Apples)>(); + .add((id::(), id::())); world .entity() .set(Position { x: 0, y: 0 }) - .add::<(Likes, Pears)>(); + .add((id::(), id::())); let mut count = 0; q.each_entity(|e, _| { @@ -3726,19 +3763,19 @@ fn query_builder_with_pair_component_id() { let q = world .query::<()>() - .with::<&Position>() - .with_first::<&Likes>(apples) + .with(id::<&Position>()) + .with((id::<&Likes>(), apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(apples); + .add((id::(), apples)); world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(pears); + .add((id::(), pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3759,19 +3796,19 @@ fn query_builder_with_pair_name_component_id() { let q = world .query::<()>() - .with::() - .with_second_id("Likes", apples) + .with(id::()) + .with(("Likes", apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3791,19 +3828,19 @@ fn query_builder_with_pair_component_name() { let q = world .query::<()>() - .with::<&Position>() - .with_first_name::<&Likes>("Apples") + .with(id::<&Position>()) + .with((id::(), "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); let e1 = world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(apples); + .add((id::(), apples)); world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(pears); + .add((id::(), pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3828,7 +3865,7 @@ fn query_builder_with_enum() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .with_enum(Color::Green) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3852,13 +3889,13 @@ fn query_builder_with_enum() { } #[test] -fn query_builder_without_id() { +fn query_builder_without() { let world = World::new(); let q = world .query::<()>() - .with_id(world.id_from::()) - .without_id(world.id_from::()) + .with(world.id_view_from(id::())) + .without(world.id_view_from(id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3885,8 +3922,8 @@ fn query_builder_without_name() { let q = world .query::<()>() - .with_id(world.id_from::()) - .without_name("flecs.common_test.Velocity") + .with(world.id_view_from(id::())) + .without("flecs.common_test.Velocity") .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3911,8 +3948,8 @@ fn query_builder_without_component() { let q = world .query::<()>() - .with::<&Position>() - .without::<&Velocity>() + .with(id::<&Position>()) + .without(id::()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -3941,19 +3978,19 @@ fn query_builder_without_pair_id() { let q = world .query::<()>() - .with::<&Position>() - .without_id((likes, apples)) + .with(id::<&Position>()) + .without((likes, apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -3974,19 +4011,19 @@ fn query_builder_without_pair_name() { let q = world .query::<()>() - .with::<&Position>() - .without_names("likes", "Apples") + .with(id::<&Position>()) + .without(("likes", "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -4003,19 +4040,19 @@ fn query_builder_without_pair_components() { let q = world .query::<()>() - .with::<&Position>() - .without::<(Likes, Apples)>() + .with(id::<&Position>()) + .without((id::(), id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add::<(Likes, Apples)>(); + .add((id::(), id::())); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add::<(Likes, Pears)>(); + .add((id::(), id::())); let mut count = 0; q.each_entity(|e, _| { @@ -4035,19 +4072,19 @@ fn query_builder_without_pair_component_id() { let q = world .query::<()>() - .with::<&Position>() - .without_first::<&Likes>(apples) + .with(id::<&Position>()) + .without((id::<&Likes>(), apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(apples); + .add((id::(), apples)); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(pears); + .add((id::(), pears)); let mut count = 0; q.each_entity(|e, _| { @@ -4067,19 +4104,19 @@ fn query_builder_without_pair_component_name() { let q = world .query::<()>() - .with::<&Position>() - .without_first_name::<&Likes>("Apples") + .with(id::<&Position>()) + .without((id::(), "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(apples); + .add((id::(), apples)); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add_first::(pears); + .add((id::(), pears)); let mut count = 0; q.each_entity(|e, _| { @@ -4100,19 +4137,19 @@ fn query_builder_without_pair_name_component_id() { let q = world .query::<()>() - .with::<&Position>() - .without_second_id("Likes", apples) + .with(id::<&Position>()) + .without(("Likes", apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, apples)); + .add((likes, apples)); let e2 = world .entity() .set(Position { x: 0, y: 0 }) - .add_id((likes, pears)); + .add((likes, pears)); let mut count = 0; q.each_entity(|e, _| { @@ -4137,7 +4174,7 @@ fn query_builder_without_enum() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .without_enum(Color::Green) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4161,18 +4198,18 @@ fn query_builder_without_enum() { } #[test] -fn query_builder_write_id() { +fn query_builder_write() { let world = World::new(); let q = world .query::<()>() - .with::<&Position>() - .write_id(world.id_from::()) + .with(id::<&Position>()) + .write(world.id_view_from(id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4184,13 +4221,13 @@ fn query_builder_write_name() { let q = world .query::<()>() - .with::<&Position>() - .write_name("flecs.common_test.Position") + .with(id::<&Position>()) + .write("flecs.common_test.Position") .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4202,13 +4239,13 @@ fn query_builder_write_component() { let q = world .query::<()>() - .with::<&Position>() - .write::() + .with(id::<&Position>()) + .write(id::()) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4221,8 +4258,8 @@ fn query_builder_write_pair_id() { let q = world .query::<()>() - .with::<&Position>() - .write_id((likes, apples)) + .with(id::<&Position>()) + .write((likes, apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4241,8 +4278,8 @@ fn query_builder_write_pair_name() { let q = world .query::<()>() - .with::<&Position>() - .write_names("likes", "Apples") + .with(id::<&Position>()) + .write(("likes", "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4258,14 +4295,14 @@ fn query_builder_write_pair_components() { let q = world .query::<()>() - .with::<&Position>() - .write::<(Likes, Apples)>() + .with(id::<&Position>()) + .write((id::(), id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); - assert_eq!(q.term(1).second_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); + assert_eq!(q.term(1).second_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4277,13 +4314,13 @@ fn query_builder_write_pair_component_id() { let q = world .query::<()>() - .with::<&Position>() - .write_first::<&Likes>(apples) + .with(id::<&Position>()) + .write((id::<&Likes>(), apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), apples); assert_eq!(q.term(1).src_id(), 0); } @@ -4296,13 +4333,13 @@ fn query_builder_write_pair_component_name() { let q = world .query::<()>() - .with::<&Position>() - .write_first_name::<&Likes>("Apples") + .with(id::<&Position>()) + .write((id::(), "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), apples); assert_eq!(q.term(1).src_id(), 0); } @@ -4321,30 +4358,30 @@ fn query_builder_write_enum() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .write_enum(Color::Green) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::Out); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), world.entity_from_enum(Color::Green)); assert_eq!(q.term(1).src_id(), 0); } #[test] -fn query_builder_read_id() { +fn query_builder_read() { let world = World::new(); let q = world .query::<()>() - .with::<&Position>() - .read_id(world.id_from::()) + .with(id::<&Position>()) + .read(world.id_view_from(id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4356,13 +4393,13 @@ fn query_builder_read_name() { let q = world .query::<()>() - .with::<&Position>() - .read_name("flecs.common_test.Position") + .with(id::<&Position>()) + .read("flecs.common_test.Position") .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4374,13 +4411,13 @@ fn query_builder_read_component() { let q = world .query::<()>() - .with::<&Position>() - .read::<&Position>() + .with(id::<&Position>()) + .read(id::()) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4393,8 +4430,8 @@ fn query_builder_read_pair_id() { let q = world .query::<()>() - .with::<&Position>() - .read_id((likes, apples)) + .with(id::<&Position>()) + .read((likes, apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4413,8 +4450,8 @@ fn query_builder_read_pair_name() { let q = world .query::<()>() - .with::<&Position>() - .read_names("likes", "Apples") + .with(id::<&Position>()) + .read(("likes", "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4430,14 +4467,14 @@ fn query_builder_read_pair_components() { let q = world .query::<()>() - .with::<&Position>() - .read::<(Likes, Apples)>() + .with(id::<&Position>()) + .read((id::(), id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); - assert_eq!(q.term(1).second_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); + assert_eq!(q.term(1).second_id(), world.id_view_from(id::())); assert_eq!(q.term(1).src_id(), 0); } @@ -4449,13 +4486,13 @@ fn query_builder_read_pair_component_id() { let q = world .query::<()>() - .with::<&Position>() - .read_first::<&Likes>(apples) + .with(id::<&Position>()) + .read((id::(), apples)) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), apples); assert_eq!(q.term(1).src_id(), 0); } @@ -4468,13 +4505,13 @@ fn query_builder_read_pair_component_name() { let q = world .query::<()>() - .with::<&Position>() - .read_first_name::<&Likes>("Apples") + .with(id::<&Position>()) + .read((id::(), "Apples")) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), apples); assert_eq!(q.term(1).src_id(), 0); @@ -4494,13 +4531,13 @@ fn query_builder_read_enum() { let q = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .read_enum(Color::Green) .set_cache_kind(QueryCacheKind::Auto) .build(); assert_eq!(q.term(1).inout(), InOutKind::In); - assert_eq!(q.term(1).first_id(), world.id_from::()); + assert_eq!(q.term(1).first_id(), world.id_view_from(id::())); assert_eq!(q.term(1).second_id(), world.entity_from_enum(Color::Green)); assert_eq!(q.term(1).src_id(), 0); } @@ -4512,7 +4549,7 @@ fn query_builder_assign_after_init() { #[allow(unused_assignments)] let mut f: Query<()> = world.new_query::<()>(); let mut fb = world.query::<()>(); - fb.with::<&Position>(); + fb.with(id::<&Position>()); fb.set_cache_kind(QueryCacheKind::Auto); f = fb.build(); @@ -4533,7 +4570,7 @@ fn query_builder_with_t_inout() { let f = world .query::<()>() - .with_id(world.id_from::()) + .with(world.id_view_from(id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4546,7 +4583,7 @@ fn query_builder_with_t_inout_1() { let f = world .query::<()>() - .with::<&Position>() + .with(id::<&Position>()) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4559,7 +4596,7 @@ fn query_builder_with_r_t_inout_2() { let f = world .query::<()>() - .with::<(Position, Velocity)>() + .with((id::(), id::())) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4572,7 +4609,7 @@ fn query_builder_with_r_t_inout_3() { let f = world .query::<()>() - .with_first::<&Position>(world.entity_from::()) + .with((id::(), world.entity_from::())) .set_cache_kind(QueryCacheKind::Auto) .build(); @@ -4585,7 +4622,7 @@ fn query_builder_with_r_t_inout() { let f = world .query::<()>() - .with_id(( + .with(( world.entity_from::(), world.entity_from::(), )) @@ -4805,12 +4842,12 @@ fn query_builder_var_src_w_prefixed_name() { let r = world .query::<()>() - .with::<&Foo>() - .set_src_name("$Var") + .with(id::<&Foo>()) + .set_src("$Var") .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add::(); + let e = world.entity().add(id::()); let mut count = 0; r.run(|mut it| { @@ -4829,20 +4866,20 @@ fn query_builder_var_first_w_prefixed_name() { let r = world .query::<()>() - .with::<&Foo>() + .with(id::<&Foo>()) .term() - .set_first_name("$Var") + .set_first("$Var") .set_cache_kind(QueryCacheKind::Auto) .build(); - let e = world.entity().add::(); + let e = world.entity().add(id::()); let mut count = 0; r.run(|mut it| { while it.next() { assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); - assert_eq!(it.get_var_by_name("Var"), world.id_from::()); + assert_eq!(it.entity(0).unwrap(), e); + assert_eq!(it.get_var_by_name("Var"), world.id_view_from(id::())); count += 1; } }); @@ -4856,19 +4893,19 @@ fn query_builder_var_second_w_prefixed_name() { let r = world .query::<()>() - .with::<&Foo>() - .set_second_name("$Var") + .with(id::<&Foo>()) + .set_second("$Var") .set_cache_kind(QueryCacheKind::Auto) .build(); let t = world.entity(); - let e = world.entity().add_first::(t); + let e = world.entity().add((id::(), t)); let mut count = 0; r.run(|mut it| { while it.next() { assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); + assert_eq!(it.entity(0).unwrap(), e); assert_eq!(it.get_var_by_name("Var"), t); count += 1; } @@ -4885,18 +4922,18 @@ fn query_builder_term_w_second_var_string() { let r = world .query::<()>() - .with_first_id(foo_, "$Var") + .with((foo_, "$Var")) .set_cache_kind(QueryCacheKind::Auto) .build(); let t = world.entity(); - let e = world.entity().add_id((foo_, t)); + let e = world.entity().add((foo_, t)); let mut count = 0; r.run(|mut it| { while it.next() { assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); + assert_eq!(it.entity(0).unwrap(), e); assert_eq!(it.get_var_by_name("Var"), t); count += 1; } @@ -4911,18 +4948,18 @@ fn query_builder_term_type_w_second_var_string() { let r = world .query::<()>() - .with_first_name::<&Foo>("$Var") + .with((id::(), "$Var")) .set_cache_kind(QueryCacheKind::Auto) .build(); let t = world.entity(); - let e = world.entity().add_first::(t); + let e = world.entity().add((id::(), t)); let mut count = 0; r.run(|mut it| { while it.next() { assert_eq!(it.count(), 1); - assert_eq!(it.entity(0), e); + assert_eq!(it.entity(0).unwrap(), e); assert_eq!(it.get_var_by_name("Var"), t); count += 1; } @@ -5022,21 +5059,21 @@ fn query_builder_scope() { let tag_a = world.entity(); let tag_b = world.entity(); - world.entity().add_id(root).add_id(tag_a).add_id(tag_b); + world.entity().add(root).add(tag_a).add(tag_b); - let e2 = world.entity().add_id(root).add_id(tag_a); + let e2 = world.entity().add(root).add(tag_a); - world.entity().add_id(root).add_id(tag_b); + world.entity().add(root).add(tag_b); - world.entity().add_id(root); + world.entity().add(root); let r = world .query::<()>() - .with_id(root) + .with(root) .scope_open() .not() - .with_id(tag_a) - .without_id(tag_b) + .with(tag_a) + .without(tag_b) .scope_close() .set_cache_kind(QueryCacheKind::Auto) .build(); diff --git a/flecs_ecs/tests/flecs/query_rust_test.rs b/flecs_ecs/tests/flecs/query_rust_test.rs index 5e39e269..aefae6cf 100644 --- a/flecs_ecs/tests/flecs/query_rust_test.rs +++ b/flecs_ecs/tests/flecs/query_rust_test.rs @@ -105,7 +105,7 @@ fn test_trait_query() { query.run(|mut it| { while it.next() { for i in it.iter() { - let e = it.entity(i); + let e = it.entity(i).unwrap(); let id = it.id(0); // cast the component to the Shapes trait let shape: &dyn Shapes = ShapesTrait::cast(e, id); diff --git a/flecs_ecs/tests/flecs/query_test.rs b/flecs_ecs/tests/flecs/query_test.rs index 4752f325..80c4abca 100644 --- a/flecs_ecs/tests/flecs/query_test.rs +++ b/flecs_ecs/tests/flecs/query_test.rs @@ -169,15 +169,18 @@ fn query_iter_targets() { let likes = world.entity(); let pizza = world.entity(); let salad = world.entity(); - let alice = world.entity().add_id((likes, pizza)).add_id((likes, salad)); + let alice = world.entity().add((likes, pizza)).add((likes, salad)); - let q = world.query::<()>().with_second::(likes).build(); + let q = world + .query::<()>() + .with((likes, id::())) + .build(); let mut count = 0; let mut tgt_count = 0; q.each_iter(|mut it, row, _| { - let e = it.entity(row); + let e = it.entity(row).unwrap(); assert_eq!(e, alice); it.targets(0, |tgt| { @@ -206,20 +209,20 @@ fn query_iter_targets_second_field() { let salad = world.entity(); let alice = world .entity() - .add::() - .add_id((likes, pizza)) - .add_id((likes, salad)); + .add(id::()) + .add((likes, pizza)) + .add((likes, salad)); let q = world .query::<&Position>() - .with_second::(likes) + .with((likes, id::())) .build(); let mut count = 0; let mut tgt_count = 0; q.each_iter(|mut it, row, _| { - let e = it.entity(row); + let e = it.entity(row).unwrap(); assert_eq!(e, alice); it.targets(1, |tgt| { @@ -248,12 +251,15 @@ fn query_iter_targets_field_out_of_range() { let likes = world.entity(); let pizza = world.entity(); let salad = world.entity(); - let alice = world.entity().add_id((likes, pizza)).add_id((likes, salad)); + let alice = world.entity().add((likes, pizza)).add((likes, salad)); - let q = world.query::<()>().with_second::(likes).build(); + let q = world + .query::<()>() + .with((likes, id::())) + .build(); q.each_iter(|mut it, row, _| { - let e = it.entity(row); + let e = it.entity(row).unwrap(); assert_eq!(e, alice); it.targets(1, |_| {}); @@ -271,14 +277,14 @@ fn query_iter_targets_field_not_a_pair() { let salad = world.entity(); let alice = world .entity() - .add::() - .add_id((likes, pizza)) - .add_id((likes, salad)); + .add(id::()) + .add((likes, pizza)) + .add((likes, salad)); let q = world.query::<&Position>().build(); q.each_iter(|mut it, row, _| { - let e = it.entity(row); + let e = it.entity(row).unwrap(); assert_eq!(e, alice); it.targets(1, |_| {}); @@ -292,16 +298,16 @@ fn query_iter_targets_field_not_set() { let world = World::new(); let likes = world.entity(); - let alice = world.entity().add::(); + let alice = world.entity().add(id::()); let q = world .query::<&Position>() - .with_second::(likes) + .with((likes, id::())) .optional() .build(); q.each_iter(|mut it, row, _| { - let e = it.entity(row); + let e = it.entity(row).unwrap(); assert_eq!(e, alice); assert!(!it.is_set(1)); diff --git a/flecs_ecs/tests/flecs/system_test.rs b/flecs_ecs/tests/flecs/system_test.rs index b6674000..773103c1 100644 --- a/flecs_ecs/tests/flecs/system_test.rs +++ b/flecs_ecs/tests/flecs/system_test.rs @@ -120,7 +120,7 @@ fn system_iter_shared() { let e1 = world .entity() .set(Position { x: 10, y: 20 }) - .add_id((flecs::IsA::ID, base)); + .add((flecs::IsA::ID, base)); let e2 = world .entity() @@ -285,7 +285,7 @@ fn system_each_shared() { let e1 = world .entity() .set(Position { x: 10, y: 20 }) - .add_id((flecs::IsA::ID, base)); + .add((flecs::IsA::ID, base)); let e2 = world .entity() @@ -464,7 +464,7 @@ fn system_signature_shared() { let e1 = world .entity() .set(Position { x: 10, y: 20 }) - .add_id((flecs::IsA::ID, base)); + .add((flecs::IsA::ID, base)); let e2 = world .entity() @@ -647,7 +647,7 @@ fn system_iter_tag() { } }); - world.entity().add::(); + world.entity().add(id::()); world.progress(); @@ -673,7 +673,7 @@ fn system_each_tag() { } }); - world.entity().add::(); + world.entity().add(id::()); world.progress(); @@ -687,11 +687,7 @@ fn system_each_tag() { fn system_set_interval() { let world = World::new(); - let _sys = world - .system::<()>() - .kind_id(0) - .set_interval(1.0) - .run(|_it| {}); + let _sys = world.system::<()>().kind(0).set_interval(1.0).run(|_it| {}); // float i = sys.set_interval(); // assert_eq!(i, 1.0f); @@ -903,16 +899,16 @@ fn system_add_from_each() { let e3 = world.entity().set(Position { x: 2, y: 0 }); world.system::<&Position>().each_entity(|e, _p| { - e.add::(); + e.add(id::()); // Add is deferred - assert!(!e.has::()); + assert!(!e.has(id::())); }); world.progress(); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); } #[test] @@ -953,24 +949,24 @@ fn system_add_from_each_world_handle() { world.system::<&EntityRef>().each_entity(|e, c| { let world = e.world(); let e = world.entity_from_id(c.value); - e.mut_stage_of(e).add::(); + e.mut_stage_of(e).add(id::()); }); world.progress(); e1.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); e2.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); e3.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); } @@ -984,26 +980,26 @@ fn system_new_from_each() { world.system::<&Position>().each_entity(|e, _p| { e.set(EntityRef { - value: e.world().entity().add::().id(), + value: e.world().entity().add(id::()).id(), }); }); world.progress(); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); e1.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); e2.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); e3.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); } @@ -1018,17 +1014,17 @@ fn system_add_from_iter() { world.system::<&Position>().run(|mut it| { while it.next() { for i in it.iter() { - it.entity(i).add::(); - assert!(!it.entity(i).has::()); + it.entity(i).unwrap().add(id::()); + assert!(!it.entity(i).unwrap().has(id::())); } } }); world.progress(); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); } #[test] @@ -1042,9 +1038,9 @@ fn system_delete_from_iter() { world.system::<&Position>().run(|mut it| { while it.next() { for i in it.iter() { - it.entity(i).destruct(); + it.entity(i).unwrap().destruct(); // Delete is deferred - assert!(it.entity(i).is_alive()); + assert!(it.entity(i).unwrap().is_alive()); } } }); @@ -1078,7 +1074,7 @@ fn system_add_from_iter_world_handle() { world .entity_from_id(c[i].value) .mut_current_stage(it.world()) - .add::(); + .add(id::()); } } }); @@ -1087,17 +1083,17 @@ fn system_add_from_iter_world_handle() { e1.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); e2.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); e3.get::<&EntityRef>(|c| { let e = world.entity_from_id(c.value); - assert!(e.has::()); + assert!(e.has(id::())); }); } @@ -1112,8 +1108,8 @@ fn system_new_from_iter() { world.system::<&Position>().run(|mut it| { while it.next() { for i in it.iter() { - it.entity(i).set(EntityRef { - value: it.world().entity().add::().id(), + it.entity(i).unwrap().set(EntityRef { + value: it.world().entity().add(id::()).id(), }); } } @@ -1121,20 +1117,20 @@ fn system_new_from_iter() { world.progress(); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); e1.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); e2.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); e3.get::<&EntityRef>(|c| { - assert!(world.entity_from_id(c.value).has::()); + assert!(world.entity_from_id(c.value).has(id::())); }); } @@ -1143,18 +1139,9 @@ fn system_each_w_mut_children_it() { let world = World::new(); let parent = world.entity().set(Position { x: 0, y: 0 }); - let e1 = world - .entity() - .set(Position { x: 0, y: 0 }) - .child_of_id(parent); - let e2 = world - .entity() - .set(Position { x: 0, y: 0 }) - .child_of_id(parent); - let e3 = world - .entity() - .set(Position { x: 0, y: 0 }) - .child_of_id(parent); + let e1 = world.entity().set(Position { x: 0, y: 0 }).child_of(parent); + let e2 = world.entity().set(Position { x: 0, y: 0 }).child_of(parent); + let e3 = world.entity().set(Position { x: 0, y: 0 }).child_of(parent); world.set(Count(0)); @@ -1162,8 +1149,8 @@ fn system_each_w_mut_children_it() { let world = it.world(); while it.next() { for i in it.iter() { - it.entity(i).each_child(|child| { - child.add::(); + it.entity(i).unwrap().each_child(|child| { + child.add(id::()); world.get::<&mut Count>(|c| { c.0 += 1; }); @@ -1178,9 +1165,9 @@ fn system_each_w_mut_children_it() { assert_eq!(c.0, 3); }); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); } #[test] @@ -1189,18 +1176,9 @@ fn system_readonly_children_iter() { let parent = world.entity(); world.entity().set(EntityRef { value: parent.id() }); - world - .entity() - .set(Position { x: 1, y: 0 }) - .child_of_id(parent); - world - .entity() - .set(Position { x: 1, y: 0 }) - .child_of_id(parent); - world - .entity() - .set(Position { x: 1, y: 0 }) - .child_of_id(parent); + world.entity().set(Position { x: 1, y: 0 }).child_of(parent); + world.entity().set(Position { x: 1, y: 0 }).child_of(parent); + world.entity().set(Position { x: 1, y: 0 }).child_of(parent); world.set(Count(0)); @@ -1450,27 +1428,27 @@ fn system_update_rate_filter() { fn system_test_let_defer_each() { let world = World::new(); - let e1 = world.entity().add::().set(Value { value: 10 }); - let e2 = world.entity().add::().set(Value { value: 20 }); - let e3 = world.entity().add::().set(Value { value: 30 }); + let e1 = world.entity().add(id::()).set(Value { value: 10 }); + let e2 = world.entity().add(id::()).set(Value { value: 20 }); + let e3 = world.entity().add(id::()).set(Value { value: 30 }); let s = world .system::<&mut Value>() - .with::() + .with(id::()) .each_entity(|e, v| { v.value += 1; - e.remove::(); + e.remove(id::()); }); s.run(); - assert!(!e1.has::()); - assert!(!e2.has::()); - assert!(!e3.has::()); + assert!(!e1.has(id::())); + assert!(!e2.has(id::())); + assert!(!e3.has(id::())); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); e1.get::<&Value>(|v| { assert_eq!(v.value, 11); @@ -1489,29 +1467,32 @@ fn system_test_let_defer_each() { fn system_test_let_defer_iter() { let world = World::new(); - let e1 = world.entity().add::().set(Value { value: 10 }); - let e2 = world.entity().add::().set(Value { value: 20 }); - let e3 = world.entity().add::().set(Value { value: 30 }); + let e1 = world.entity().add(id::()).set(Value { value: 10 }); + let e2 = world.entity().add(id::()).set(Value { value: 20 }); + let e3 = world.entity().add(id::()).set(Value { value: 30 }); - let s = world.system::<&mut Value>().with::().run(|mut it| { - while it.next() { - let mut v = it.field::(0).unwrap(); - for i in it.iter() { - v[i].value += 1; - it.entity(i).remove::(); + let s = world + .system::<&mut Value>() + .with(id::()) + .run(|mut it| { + while it.next() { + let mut v = it.field::(0).unwrap(); + for i in it.iter() { + v[i].value += 1; + it.entity(i).unwrap().remove(id::()); + } } - } - }); + }); s.run(); - assert!(!e1.has::()); - assert!(!e2.has::()); - assert!(!e3.has::()); + assert!(!e1.has(id::())); + assert!(!e2.has(id::())); + assert!(!e3.has(id::())); - assert!(e1.has::()); - assert!(e2.has::()); - assert!(e3.has::()); + assert!(e1.has(id::())); + assert!(e2.has(id::())); + assert!(e3.has(id::())); e1.get::<&Value>(|v| { assert_eq!(v.value, 11); @@ -1531,13 +1512,13 @@ fn system_test_let_defer_iter() { fn system_custom_pipeline() { // let world = World::new(); - // let mut preFrame = world.entity().add::(); - // let OnFrame = world.entity().add::().depends_on(PreFrame); - // let mut postFrame = world.entity().add::().depends_on(OnFrame); + // let mut preFrame = world.entity().add(id::()); + // let OnFrame = world.entity().add(id::()).depends_on(PreFrame); + // let mut postFrame = world.entity().add(id::()).depends_on(OnFrame); // let tag = world.entity(); // let pip = world.pipeline() - // .with::() + // .with(id::()) // .with(flecs::pipeline::Phase).cascade(flecs::DependsOn) // .with(Tag) // .build(); @@ -1586,7 +1567,7 @@ fn system_custom_pipeline() { // assert_eq!(count, 0); - // world.set_pipeline_id(pip); + // world.set_pipeline(pip); // world.progress(); @@ -1603,13 +1584,13 @@ fn system_custom_pipeline_w_kind() { let pip = world .pipeline() - .with::() - .with_id(tag) + .with(id::()) + .with(tag) .build(); world.set(Count(0)); - world.system::<()>().kind_id(tag).run(|mut it| { + world.system::<()>().kind(tag).run(|mut it| { while it.next() { let world = it.world(); world.get::<&mut Count>(|c| { @@ -1619,7 +1600,7 @@ fn system_custom_pipeline_w_kind() { } }); - world.system::<()>().kind_id(tag).run(|mut it| { + world.system::<()>().kind(tag).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count>(|c| { @@ -1629,7 +1610,7 @@ fn system_custom_pipeline_w_kind() { } }); - world.system::<()>().kind_id(tag).run(|mut it| { + world.system::<()>().kind(tag).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count>(|c| { @@ -1643,7 +1624,7 @@ fn system_custom_pipeline_w_kind() { assert_eq!(c.0, 0); }); - world.set_pipeline_id(pip.id()); + world.set_pipeline(pip.id()); world.progress(); @@ -1663,7 +1644,7 @@ fn system_create_w_no_template_args() { let s = world .system::<()>() - .with::() + .with(id::()) .each_entity(move |e, _| { let world = e.world(); assert!(e == entity_id); @@ -1692,51 +1673,61 @@ fn system_system_w_type_kind_type_pipeline() { world .component::() - .add::() - .depends_on_id(world.component::().add::()); + .add(id::()) + .depends_on( + world + .component::() + .add(id::()), + ); world .pipeline_type::() - .with::() - .with::() - .cascade_type::() + .with(id::()) + .with(id::()) + .cascade_id(id::()) .build(); - world.set_pipeline::(); + world.set_pipeline(id::()); - let entity = world.entity().add::(); + let entity = world.entity().add(id::()); let entity_id = entity.id(); world.set(Count2 { a: 0, b: 0 }); - world.system::<&Tag>().kind::().run(move |mut it| { - while it.next() { - for i in it.iter() { - let e = it.entity(i); - let world = e.world(); - assert!(e == entity_id); - world.get::<&mut Count2>(|c| { - assert_eq!(c.a, 0); - assert_eq!(c.b, 1); - c.a += 1; - }); + world + .system::<&Tag>() + .kind(id::()) + .run(move |mut it| { + while it.next() { + for i in it.iter() { + let e = it.entity(i).unwrap(); + let world = e.world(); + assert!(e == entity_id); + world.get::<&mut Count2>(|c| { + assert_eq!(c.a, 0); + assert_eq!(c.b, 1); + c.a += 1; + }); + } } - } - }); + }); - world.system::<&Tag>().kind::().run(move |mut it| { - while it.next() { - for i in it.iter() { - let world = it.world(); - let e = it.entity(i); - assert!(e == entity_id); - world.get::<&mut Count2>(|c| { - assert_eq!(c.b, 0); - c.b += 1; - }); + world + .system::<&Tag>() + .kind(id::()) + .run(move |mut it| { + while it.next() { + for i in it.iter() { + let world = it.world(); + let e = it.entity(i).unwrap(); + assert!(e == entity_id); + world.get::<&mut Count2>(|c| { + assert_eq!(c.b, 0); + c.b += 1; + }); + } } - } - }); + }); world.progress(); @@ -2014,7 +2005,7 @@ fn system_startup_system() { world .system::<()>() - .kind_id(flecs::pipeline::OnStart::ID) + .kind(flecs::pipeline::OnStart::ID) .run(|mut it| { let world = it.world(); while it.next() { @@ -2027,7 +2018,7 @@ fn system_startup_system() { world .system::<()>() - .kind_id(flecs::pipeline::OnUpdate::ID) + .kind(flecs::pipeline::OnUpdate::ID) .run(|mut it| { let world = it.world(); while it.next() { @@ -2062,7 +2053,7 @@ fn system_interval_tick_source() { world.set(Count2 { a: 0, b: 0 }); - world.system::<()>().set_tick_source_id(t).run(|mut it| { + world.system::<()>().set_tick_source(t).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count2>(|c| { @@ -2071,7 +2062,7 @@ fn system_interval_tick_source() { } }); - world.system::<()>().set_tick_source_id(t).run(|mut it| { + world.system::<()>().set_tick_source(t).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count2>(|c| { @@ -2104,7 +2095,7 @@ fn system_rate_tick_source() { world.set(Count2 { a: 0, b: 0 }); - world.system::<()>().set_tick_source_id(t).run(|mut it| { + world.system::<()>().set_tick_source(t).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count2>(|c| { @@ -2113,7 +2104,7 @@ fn system_rate_tick_source() { } }); - world.system::<()>().set_tick_source_id(t).run(|mut it| { + world.system::<()>().set_tick_source(t).run(|mut it| { let world = it.world(); while it.next() { world.get::<&mut Count2>(|c| { @@ -2200,9 +2191,9 @@ fn system_nested_rate_tick_source() { // flecs::entity e2 = world.entity().set(Position{x: 20, y: 30}); // let s = world.system::<()>() -// .with::() +// .with(id::()) // .each([&](flecs::iter& iter, size_t index) { -// let e = iter.entity(index); +// let e = iter.entity(index).unwrap(); // &Position *p = &iter.table().get()[index]; // assert_ne!(p, nullptr); // assert!(e == e1 || e == e2); @@ -2225,9 +2216,9 @@ fn system_nested_rate_tick_source() { // flecs::entity e2 = world.entity().set(Position{x: 20, y: 30}); // let s = world.system::<()>() -// .with::() +// .with(id::()) // .each([&](flecs::iter& iter, size_t index) { -// let e = iter.entity(index); +// let e = iter.entity(index).unwrap(); // &Position *p = &iter.range().get()[index]; // assert_ne!(p, nullptr); // assert!(e == e1 || e == e2); @@ -2291,7 +2282,7 @@ fn system_run_w_0_src_query() { world.set(Count(0)); - world.system::<()>().write::().run(|it| { + world.system::<()>().write(id::()).run(|it| { let world = it.world(); world.get::<&mut Count>(|c| { c.0 += 1; diff --git a/flecs_ecs/tests/flecs/world_test.rs b/flecs_ecs/tests/flecs/world_test.rs index 72eb1a6a..24ecf3c8 100644 --- a/flecs_ecs/tests/flecs/world_test.rs +++ b/flecs_ecs/tests/flecs/world_test.rs @@ -61,7 +61,7 @@ fn world_finis_reentrancy() { // therefore, world destroy will be called again wreaking havoc. }); - world.entity().add::(); + world.entity().add(id::()); // world will be destroyed here, and hook above will be called. } diff --git a/flecs_ecs_derive/Cargo.toml b/flecs_ecs_derive/Cargo.toml index 961e12a2..40dd9703 100644 --- a/flecs_ecs_derive/Cargo.toml +++ b/flecs_ecs_derive/Cargo.toml @@ -15,9 +15,9 @@ name = "flecs_ecs_derive" workspace = true [dependencies] -syn = "2.0.33" -quote = "1.0.33" -proc-macro2 = "1.0.67" +syn = "2.0.101" +quote = "1.0.40" +proc-macro2 = "1.0.95" [dev-dependencies] flecs_ecs = { version = "*", path = "../flecs_ecs" } diff --git a/flecs_ecs_derive/src/lib.rs b/flecs_ecs_derive/src/lib.rs index 1ef7bdc4..c03f5e19 100644 --- a/flecs_ecs_derive/src/lib.rs +++ b/flecs_ecs_derive/src/lib.rs @@ -148,7 +148,7 @@ fn impl_meta(input: &DeriveInput, has_repr_c: bool, struct_name: Ident) -> Token if let Some(field_name) = field_name { meta_fields_impl.push(quote! { - .member_id(id!(world, #field_type), (stringify!(#field_name), flecs_ecs::addons::meta::Count(1), core::mem::offset_of!(#struct_name, #field_name))) + .member(id!(world, #field_type), (stringify!(#field_name), flecs_ecs::addons::meta::Count(1), core::mem::offset_of!(#struct_name, #field_name))) }); } else { meta_fields_impl.push( quote! { @@ -865,6 +865,24 @@ fn impl_cached_component_data_enum( } }; + let into_entity = quote! { + impl #impl_generics flecs_ecs::core::IntoEntity for #name #type_generics #where_clause { + const IS_TYPED_PAIR: bool = false; + const IS_TYPED: bool = true; + const IF_ID_IS_DEFAULT: bool = ::IMPLS_DEFAULT; + const IS_TYPED_SECOND: bool = true; + const IF_ID_IS_DEFAULT_SECOND: bool = false; + const IS_ENUM: bool = true; + const IS_TYPE_TAG: bool = true; + const IS_TYPED_REF: bool = false; + const IS_TYPED_MUT_REF: bool = false; + fn into_entity<'a>(self, world: impl flecs_ecs::core::WorldProvider<'a>) -> flecs_ecs::core::Entity { + let world = world.world(); + *::id_variant(&self, world) + } + } + }; + quote! { impl #impl_generics flecs_ecs::core::ComponentType for #name #type_generics #where_clause {} impl #impl_generics flecs_ecs::core::ComponentType for #name #type_generics #where_clause {} @@ -878,6 +896,8 @@ fn impl_cached_component_data_enum( #cached_enum_data #on_component_registration + + #into_entity } } @@ -1224,6 +1244,7 @@ impl Parse for TermId { } } +#[allow(clippy::large_enum_variant)] enum TermType { Pair(TermId, TermId), Component(TermId), @@ -1379,7 +1400,7 @@ fn expand_trav(term: &TermId) -> Vec { match &term.up_ident { Some(ident) => match ident { TermIdent::Local(ident) => ops.push(quote! { .up_id(#ident) }), - TermIdent::Type(ty) => ops.push(quote! { .up_type::<#ty>() }), + TermIdent::Type(ty) => ops.push(quote! { .up_id(id::<#ty>()) }), _ => ops .push(quote_spanned!(term.span => ; compile_error!("Invalid up traversal.") )), }, @@ -1390,7 +1411,7 @@ fn expand_trav(term: &TermId) -> Vec { match &term.cascade_ident { Some(ident) => match ident { TermIdent::Local(ident) => ops.push(quote! { .cascade_id(#ident) }), - TermIdent::Type(ty) => ops.push(quote! { .cascade_type::<#ty>() }), + TermIdent::Type(ty) => ops.push(quote! { .cascade_id(id::<#ty>()) }), _ => ops.push( quote_spanned!(term.span => ; compile_error!("Invalid cascade traversal.") ), ), @@ -1513,7 +1534,7 @@ fn expand_dsl(terms: &mut [Term]) -> (TokenStream, Vec) { TermIdent::Singleton => ops.push(quote_spanned!{ second.span => ; compile_error!("Unexpected singleton identifier.") }), _ => { if !iter_term { - ops.push(quote! { .set_second::<#second_ty>() }); + ops.push(quote! { .set_second(id::<#second_ty>()) }); } } }; @@ -1551,7 +1572,7 @@ fn expand_dsl(terms: &mut [Term]) -> (TokenStream, Vec) { }, _ => { if !iter_term { - term_accessor = quote! { .with::<#ty>() }; + term_accessor = quote! { .with(id::<#ty>()) }; needs_accessor = true; } }, @@ -1577,7 +1598,7 @@ fn expand_dsl(terms: &mut [Term]) -> (TokenStream, Vec) { TermIdent::Local(ident) => ops.push(quote! { .set_src_id(#ident) }), TermIdent::Literal(lit) => ops.push(quote! { .set_src_name(#lit) }), TermIdent::Singleton => ops.push(quote! { .singleton() }), - _ => ops.push(quote! { .set_src::<#ty>() }), + _ => ops.push(quote! { .set_src(id::<#ty>()) }), }; } @@ -1698,17 +1719,17 @@ fn expand_dsl(terms: &mut [Term]) -> (TokenStream, Vec) { /// let mut world = World::new(); /// /// // Basic -/// let builder = world.query::<(&Foo, &mut Bar)>().with::().build(); +/// let builder = world.query::<(&Foo, &mut Bar)>().with(id::()).build(); /// let dsl = query!(&mut world, &Foo, &mut Bar, Bazz).build(); /// assert_eq!(builder.to_string(), dsl.to_string()); /// /// // Logical modifiers /// let builder = world /// .query::<()>() -/// .with::() +/// .with(id::()) /// .or() -/// .with::() -/// .without::() +/// .with(id::()) +/// .without(id::()) /// .build(); /// /// let dsl = query!(&mut world, Foo || Bar, !Bazz).build(); @@ -1922,14 +1943,14 @@ pub fn observer(input: ProcMacroTokenStream) -> ProcMacroTokenStream { /// world.entity_named("square").set(Square { side: 5.0 }); /// world.entity_named("triangle").set(Triangle { side: 5.0 }); /// -/// let query = world.query::<()>().with::().build(); +/// let query = world.query::<()>().with(id::()).build(); /// /// query.run(|mut it| { /// it.next(); /// while it.next() { /// let world = it.world(); /// for i in it.iter() { -/// let e = it.entity(i); +/// let e = it.entity(i).unwrap(); /// let id = it.id(0); /// let shape = ShapesTrait::cast(e, id); /// let calc = shape.calculate(); @@ -1974,7 +1995,7 @@ pub fn ecs_rust_trait(input: ProcMacroTokenStream) -> ProcMacroTokenStream { let (_, vtable): (usize, usize) = unsafe { core::mem::transmute(trait_obj_ptr) }; let id = world.component::(); let id_self = world.component::(); - id.is_a_id(id_self); + id.is_a(id_self); id.set_id(Self::new(vtable), (id_self,id_self)); vtable } @@ -1983,7 +2004,7 @@ pub fn ecs_rust_trait(input: ProcMacroTokenStream) -> ProcMacroTokenStream { let data_ptr = entity.get_untyped(derived_id) as usize; let vtable_ptr = entity .world() - .component_untyped_from_id(*derived_id) + .component_untyped_from(*derived_id) .cloned::<&(Self,Self)>() .vtable;