Skip to content

Commit

Permalink
fix: Remove the need to add a GlobalTransform component when primaril…
Browse files Browse the repository at this point in the history
…y using Transform (it will be done automatically).
  • Loading branch information
Rhuagh committed Aug 19, 2018
1 parent 093f2a0 commit 58c7eb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 14 additions & 2 deletions amethyst_core/src/transform/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use hibitset::BitSet;
use specs::prelude::{
Entities, InsertedFlag, Join, ModifiedFlag, ReadExpect, ReadStorage, ReaderId, Resources,
System, WriteStorage,
Entities, Entity, InsertedFlag, Join, ModifiedFlag, ReadExpect, ReadStorage, ReaderId,
Resources, System, WriteStorage,
};
use transform::{GlobalTransform, HierarchyEvent, Parent, ParentHierarchy, Transform};

Expand All @@ -17,6 +17,8 @@ pub struct TransformSystem {
modified_local_id: Option<ReaderId<ModifiedFlag>>,

parent_events_id: Option<ReaderId<HierarchyEvent>>,

scratch: Vec<Entity>,
}

impl TransformSystem {
Expand All @@ -28,6 +30,7 @@ impl TransformSystem {
parent_events_id: None,
local_modified: BitSet::default(),
global_modified: BitSet::default(),
scratch: Vec::new(),
}
}
}
Expand All @@ -44,6 +47,15 @@ impl<'a> System<'a> for TransformSystem {
#[cfg(feature = "profiler")]
profile_scope!("transform_system");

self.scratch.clear();
self.scratch
.extend((&*entities, &locals, !&globals).join().map(|d| d.0));
for entity in &self.scratch {
globals
.insert(*entity, GlobalTransform::default())
.expect("unreachable");
}

self.local_modified.clear();
self.global_modified.clear();

Expand Down
3 changes: 0 additions & 3 deletions examples/pong/pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ fn initialise_paddles(world: &mut World, sprite_sheet_handle: SpriteSheetHandle)
height: PADDLE_HEIGHT,
velocity: PADDLE_VELOCITY,
})
.with(GlobalTransform::default())
.with(left_transform)
.build();

Expand All @@ -205,7 +204,6 @@ fn initialise_paddles(world: &mut World, sprite_sheet_handle: SpriteSheetHandle)
height: PADDLE_HEIGHT,
velocity: PADDLE_VELOCITY,
})
.with(GlobalTransform::default())
.with(right_transform)
.build();
}
Expand Down Expand Up @@ -234,7 +232,6 @@ fn initialise_ball(world: &mut World, sprite_sheet_handle: SpriteSheetHandle) {
velocity: [BALL_VELOCITY_X, BALL_VELOCITY_Y],
})
.with(local_transform)
.with(GlobalTransform::default())
.build();
}

Expand Down

0 comments on commit 58c7eb7

Please sign in to comment.