Remove custom movement system.

This commit is contained in:
Nolan Darilek 2021-06-02 16:25:28 -05:00
parent 6c3db77e9e
commit 1c970a3f41
2 changed files with 5 additions and 70 deletions

View File

@ -99,6 +99,7 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
} }
} }
} }
fn movement_controls<S, A: 'static>( fn movement_controls<S, A: 'static>(
mut commands: Commands, mut commands: Commands,
config: Res<NavigationConfig<S, A>>, config: Res<NavigationConfig<S, A>>,
@ -233,50 +234,6 @@ fn movement_controls<S, A: 'static>(
} }
} }
fn movement(
time: Res<Time>,
mut collision_events: EventWriter<Collision>,
map: Query<(&Map, &MotionBlocked, &CollisionsMonitored)>,
mut entities: Query<(Entity, &Velocity, &mut Coordinates, Option<&BlocksMotion>)>,
) {
for (entity, velocity, mut coordinates, blocks_motion) in entities.iter_mut() {
if **velocity != Vec2::ZERO {
let displacement = **velocity * time.delta_seconds();
let mut point = **coordinates;
point.0 += displacement.x;
point.1 += displacement.y;
if let Ok((map, motion_blocked, collisions_monitored)) = map.single() {
let idx = point.to_index(map.width());
if idx < map.base.tiles.len() {
let current_entities = &map.entities[idx];
if blocks_motion.is_some()
&& motion_blocked[idx]
&& !current_entities.contains(&entity)
{
collision_events.send(Collision {
entity,
coordinates: point,
index: idx,
});
} else {
**coordinates = point;
let current_entities = &map.entities[idx];
if collisions_monitored[idx] && !current_entities.contains(&entity) {
collision_events.send(Collision {
entity,
coordinates: point,
index: idx,
});
}
}
}
} else {
**coordinates = point;
}
}
}
}
pub(crate) fn set_motion_blocked( pub(crate) fn set_motion_blocked(
map: &Map, map: &Map,
index: usize, index: usize,
@ -468,8 +425,6 @@ fn speak_direction(
Ok(()) Ok(())
} }
pub const MOVEMENT_LABEL: &str = "MOVEMENT";
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct NavigationConfig<S, A> { pub struct NavigationConfig<S, A> {
pub action_backward: Option<A>, pub action_backward: Option<A>,
@ -576,33 +531,17 @@ where
.add_system(speak_direction.system().chain(error_handler.system())) .add_system(speak_direction.system().chain(error_handler.system()))
.add_system_to_stage(CoreStage::PostUpdate, add_collision_indices.system()); .add_system_to_stage(CoreStage::PostUpdate, add_collision_indices.system());
if config.movement_states.is_empty() { if config.movement_states.is_empty() {
app.add_system(
movement
.system()
.label(MOVEMENT_LABEL)
.before(crate::map::UPDATE_ENTITY_INDEX_LABEL),
);
} else { } else {
let states = config.movement_states; let states = config.movement_states;
for state in states { for state in states {}
app.add_system_set(
SystemSet::on_update(state).with_system(
movement
.system()
.label(MOVEMENT_LABEL)
.before(crate::map::UPDATE_ENTITY_INDEX_LABEL),
),
);
}
} }
if config.movement_control_states.is_empty() { if config.movement_control_states.is_empty() {
app.add_system(movement_controls::<S, A>.system().before(MOVEMENT_LABEL)); app.add_system(movement_controls::<S, A>.system());
} else { } else {
let states = config.movement_control_states; let states = config.movement_control_states;
for state in states { for state in states {
app.add_system_set( app.add_system_set(
SystemSet::on_update(state) SystemSet::on_update(state).with_system(movement_controls::<S, A>.system()),
.with_system(movement_controls::<S, A>.system().before(MOVEMENT_LABEL)),
); );
} }
} }

View File

@ -210,10 +210,6 @@ pub struct PathfindingPlugin;
impl Plugin for PathfindingPlugin { impl Plugin for PathfindingPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut AppBuilder) {
app.add_system_to_stage(CoreStage::PostUpdate, calculate_path.system()) app.add_system_to_stage(CoreStage::PostUpdate, calculate_path.system())
.add_system( .add_system(negotiate_path.system());
negotiate_path
.system()
.before(crate::navigation::MOVEMENT_LABEL),
);
} }
} }