-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced toecs
toyboot4e edited this page Mar 25, 2022
·
6 revisions
Both Comp<T>
and CompMut<T>
implements AsRef<ComponentPool<T>>
, so this is a useful tip:
pub fn walk_entity(
entity: Entity,
pos: mdl::Pos,
dir: mdl::Dir8,
body: &mut ComponentPool<mdl::Body>,
view_body: &mut ComponentPool<ViewBody>,
stage: &res::Stage,
) {
/* ~~~~ */
}
Entity hierarchy API automatically borrows their context automatically:
#[derive(GatBorrowWorld, Debug)]
pub struct HieMut<'w> {
root: Res<'w, tfm::RootNode>,
node: CompMut<'w, tfm::Node>,
}
pub fn update_hierarchy_system(
hie: &HieMut,
/* ~~~~ */
) { /* ~~~~ */ }
A.k.a. component bundle:
#[derive(Debug, Default, ComponentSet)]
pub struct NodeSet {
pub node: Node,
pub local: tfm::LocalTransform,
pub global: tfm::GlobalTransform,
}
world.insert_set(entity, NodeSet { /* ~~ */ }
#[derive(Debug, Componnet)]
A;
// set of component sets is a component set
world.insert_set(entity, ((
// set of components is a component set
(A, A ,A),
// component is a component set
A,
));
let resource = world.run(system);
world.insert(resource);
Use Commands
.
Use const generics:
pub fn render_map_layers<const I1: i32, const I2: i32>(mut draw: Draw, vp: Res<Camera2d>, stage: Res<Stage>) {
/* ~~~~ */
}
world.run(render_map_layers::<0, 10>);
Make use of World::borrow
:
pub fn ctrl_entity_system(
entity,
(input, vi, mut body, mut view_body, stage, interact, mut cutscene): (
Res<Input>,
Res<res::VInput>,
CompMut<mdl::Body>,
CompMut<view::actor::ViewBody>,
Res<res::Stage>,
Comp<mdl::Interact>,
ResMut<CutsceneState>,
),
) { /* ~~~ */
let entity = world.spawn( /* ~~~ */ ):
ctrl_entity_system(entity, &mut world);