Compare commits

...

6 Commits

10 changed files with 92 additions and 100 deletions

View File

@ -13,24 +13,24 @@ speech_dispatcher_0_10 = ["bevy_tts/speech_dispatcher_0_10"]
speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"]
[dependencies.bevy]
version = "0.11"
version = "0.13"
default-features = false
features = [
"bevy_gilrs",
"bevy_winit",
"x11",
"wayland",
"multi-threaded",
"serialize",
]
[dependencies]
bevy_rapier2d = "0.22"
bevy_synthizer = "0.4"
bevy_tts = { version = "0.6", default-features = false, features = ["tolk"] }
bevy_rapier2d = "0.25"
bevy_synthizer = "0.6"
bevy_tts = { version = "0.8", default-features = false, features = ["tolk"] }
coord_2d = "0.3"
futures-lite = "1"
here_be_dragons = { version = "0.3", features = ["serde"] }
leafwing-input-manager = "0.10"
leafwing-input-manager = "0.13"
maze_generator = "2"
once_cell = "1"
pathfinding = "4"

View File

@ -521,7 +521,6 @@ impl GlobalTransformExt for GlobalTransform {
other: &GlobalTransform,
other_collider: &Collider,
) -> ClosestPoints {
use bevy::math::Vec3Swizzles;
let scale = PHYSICS_SCALE.read().unwrap();
let pos1 = Isometry::new(
(self.translation() / *scale).xy().into(),
@ -540,7 +539,6 @@ impl GlobalTransformExt for GlobalTransform {
other: &GlobalTransform,
other_collider: &Collider,
) -> String {
use bevy::math::Vec3Swizzles;
let scale = PHYSICS_SCALE.read().unwrap();
let pos1 = Isometry::new(
(self.translation() / *scale).xy().into(),
@ -632,7 +630,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
let mut rng = thread_rng();
self.0.shuffle(&mut rng);
self.0.get(0).cloned()
self.0.first().cloned()
}
}

View File

@ -72,7 +72,7 @@ where
types.dedup();
if types.is_empty() {
tts.speak("Nothing visible.", true)?;
} else if actions.just_pressed(ExplorationAction::SelectPrevType) {
} else if actions.just_pressed(&ExplorationAction::SelectPrevType) {
if let Some(t) = &focused.0 {
if let Some(i) = types.iter().position(|v| *v == *t) {
if i == 0 {
@ -89,7 +89,7 @@ where
let t = types.last().unwrap();
focused.0 = Some(*t);
}
} else if actions.just_pressed(ExplorationAction::SelectNextType) {
} else if actions.just_pressed(&ExplorationAction::SelectNextType) {
if let Some(t) = &focused.0 {
if let Some(i) = types.iter().position(|v| *v == *t) {
if i == types.len() - 1 {
@ -141,7 +141,7 @@ where
features.retain(|(_, t)| **t == *focused);
}
let mut target: Option<&((f32, f32), &ExplorationType)> = None;
if actions.just_pressed(ExplorationAction::FocusNext) {
if actions.just_pressed(&ExplorationAction::FocusNext) {
if let Some(exploring) = exploring {
target = features.iter().find(|(c, _)| *c > **exploring);
if target.is_none() {
@ -150,7 +150,7 @@ where
} else {
target = features.first();
}
} else if actions.just_pressed(ExplorationAction::FocusPrev) {
} else if actions.just_pressed(&ExplorationAction::FocusPrev) {
if let Some(exploring) = exploring {
features.reverse();
target = features.iter().find(|(c, _)| *c < **exploring);
@ -224,13 +224,13 @@ fn exploration_focus<MapData>(
(floor.x, floor.y)
};
let orig = exploring;
if actions.just_pressed(ExplorationAction::Forward) {
if actions.just_pressed(&ExplorationAction::Forward) {
exploring.1 += 1.;
} else if actions.just_pressed(ExplorationAction::Backward) {
} else if actions.just_pressed(&ExplorationAction::Backward) {
exploring.1 -= 1.;
} else if actions.just_pressed(ExplorationAction::Left) {
} else if actions.just_pressed(&ExplorationAction::Left) {
exploring.0 -= 1.;
} else if actions.just_pressed(ExplorationAction::Right) {
} else if actions.just_pressed(&ExplorationAction::Right) {
exploring.0 += 1.;
}
let dimensions = if let Ok(map) = map.get_single() {
@ -261,7 +261,7 @@ fn navigate_to_explored<MapData>(
let point = **exploring;
let idx = point.to_index(map.width);
let known = revealed_tiles[idx];
if actions.just_pressed(ExplorationAction::NavigateTo) && known {
if actions.just_pressed(&ExplorationAction::NavigateTo) && known {
commands
.entity(entity)
.insert(Destination((point.x_i32(), point.y_i32())));
@ -421,7 +421,7 @@ where
if !config.states.is_empty() {
let states = config.states;
for state in states {
app.configure_set(Update, Exploration.run_if(in_state(state.clone())))
app.configure_sets(Update, Exploration.run_if(in_state(state.clone())))
.add_systems(OnExit(state), cleanup);
}
}

View File

@ -11,7 +11,6 @@ pub use coord_2d;
pub mod core;
pub mod error;
pub mod exploration;
pub use futures_lite;
pub use here_be_dragons as mapgen;
pub use leafwing_input_manager;
pub mod log;

View File

@ -98,7 +98,7 @@ fn snap(
for (entity, actions, mut transform, direction) in &mut query {
if snap_timers.contains_key(&entity) {
continue;
} else if actions.just_pressed(NavigationAction::SnapLeft) {
} else if actions.just_pressed(&NavigationAction::SnapLeft) {
snap_timers.insert(entity, SnapTimer::default());
transform.rotation = Quat::from_rotation_z(match direction {
CardinalDirection::North => PI,
@ -106,7 +106,7 @@ fn snap(
CardinalDirection::South => 0.,
CardinalDirection::West => -PI / 2.,
});
} else if actions.just_pressed(NavigationAction::SnapRight) {
} else if actions.just_pressed(&NavigationAction::SnapRight) {
snap_timers.insert(entity, SnapTimer::default());
transform.rotation = Quat::from_rotation_z(match direction {
CardinalDirection::North => 0.,
@ -114,10 +114,10 @@ fn snap(
CardinalDirection::South => PI,
CardinalDirection::West => PI / 2.,
});
} else if actions.just_pressed(NavigationAction::SnapReverse) {
} else if actions.just_pressed(&NavigationAction::SnapReverse) {
snap_timers.insert(entity, SnapTimer::default());
transform.rotate(Quat::from_rotation_z(PI));
} else if actions.just_pressed(NavigationAction::SnapCardinal) {
} else if actions.just_pressed(&NavigationAction::SnapCardinal) {
let yaw: Angle = direction.into();
let yaw = yaw.radians();
transform.rotation = Quat::from_rotation_z(yaw);
@ -147,7 +147,7 @@ fn controls(
Option<&BackwardMovementFactor>,
Option<&ForwardMovementFactor>,
Option<&StrafeMovementFactor>,
&Transform,
&mut Transform,
Option<&mut KinematicCharacterController>,
)>,
exploration_focused: Query<Entity, With<ExplorationFocused>>,
@ -161,13 +161,13 @@ fn controls(
backward_movement_factor,
forward_movement_factor,
strafe_movement_factor,
transform,
mut transform,
character_controller,
) in &mut query
{
let mut cleanup = false;
if actions.pressed(NavigationAction::Move) {
if let Some(pair) = actions.clamped_axis_pair(NavigationAction::Move) {
if actions.pressed(&NavigationAction::Move) {
if let Some(pair) = actions.clamped_axis_pair(&NavigationAction::Move) {
cleanup = true;
let mut direction = pair.xy();
let forward_movement_factor =
@ -201,76 +201,83 @@ fn controls(
let velocity = direction * speed;
if character_controller.is_some() {
let translation = velocity * time.delta_seconds();
actions.press(NavigationAction::Translate);
actions.press(&NavigationAction::Translate);
actions
.action_data_mut(NavigationAction::Translate)
.action_data_mut_or_default(&NavigationAction::Translate)
.axis_pair = Some(DualAxisData::from_xy(translation));
} else {
// println!("{entity:?}: SetLinearVelocity: {velocity:?}");
actions.press(NavigationAction::SetLinearVelocity);
actions.press(&NavigationAction::SetLinearVelocity);
actions
.action_data_mut(NavigationAction::SetLinearVelocity)
.action_data_mut_or_default(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(velocity));
}
}
} else if actions.just_released(NavigationAction::Move) {
} else if actions.just_released(&NavigationAction::Move) {
trace!("{entity:?}: Stopped moving");
actions.release(NavigationAction::SetLinearVelocity);
actions.release(NavigationAction::Translate);
actions.action_data_mut(NavigationAction::Move).axis_pair =
Some(DualAxisData::from_xy(Vec2::ZERO));
actions.release(&NavigationAction::SetLinearVelocity);
actions.release(&NavigationAction::Translate);
actions
.action_data_mut_or_default(&NavigationAction::Move)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
}
if actions.pressed(NavigationAction::SetLinearVelocity) {
if let Some(pair) = actions.axis_pair(NavigationAction::SetLinearVelocity) {
if actions.pressed(&NavigationAction::SetLinearVelocity) {
if let Some(pair) = actions.axis_pair(&NavigationAction::SetLinearVelocity) {
// println!("{entity:?}: SetLinearVelocity: {pair:?}");
velocity.linvel = pair.into();
} else {
// println!("{entity:?}: SetLinearVelocity: 0");
velocity.linvel = Vec2::ZERO;
}
} else if actions.just_released(NavigationAction::SetLinearVelocity) {
} else if actions.just_released(&NavigationAction::SetLinearVelocity) {
// println!("{entity:?}: Released velocity");
velocity.linvel = Vec2::ZERO;
actions
.action_data_mut(NavigationAction::SetLinearVelocity)
.action_data_mut_or_default(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
}
if actions.pressed(NavigationAction::Translate) {
if let Some(pair) = actions.axis_pair(NavigationAction::Translate) {
if actions.pressed(&NavigationAction::Translate) {
if let Some(pair) = actions.axis_pair(&NavigationAction::Translate) {
if let Some(mut character_controller) = character_controller {
character_controller.translation = Some(pair.xy());
}
}
} else if actions.just_released(NavigationAction::Translate) {
} else if actions.just_released(&NavigationAction::Translate) {
if let Some(mut character_controller) = character_controller {
character_controller.translation = None;
}
actions
.action_data_mut(NavigationAction::Translate)
.action_data_mut_or_default(&NavigationAction::Translate)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
}
if !snap_timers.contains_key(&entity) {
if let Some(rotation_speed) = rotation_speed {
if actions.pressed(NavigationAction::Rotate) {
if actions.pressed(&NavigationAction::Rotate) {
cleanup = true;
let delta =
-rotation_speed.radians() * actions.clamped_value(NavigationAction::Rotate);
actions.press(NavigationAction::SetAngularVelocity);
let delta = -rotation_speed.radians()
* actions.clamped_value(&NavigationAction::Rotate);
actions.press(&NavigationAction::SetAngularVelocity);
actions
.action_data_mut(NavigationAction::SetAngularVelocity)
.action_data_mut_or_default(&NavigationAction::SetAngularVelocity)
.value = delta;
}
}
}
if actions.just_released(NavigationAction::Rotate) {
actions.release(NavigationAction::SetAngularVelocity);
actions.action_data_mut(NavigationAction::Rotate).value = 0.;
}
if actions.pressed(NavigationAction::SetAngularVelocity) {
velocity.angvel = actions.value(NavigationAction::SetAngularVelocity);
} else if actions.just_released(NavigationAction::SetAngularVelocity) {
if actions.just_released(&NavigationAction::Rotate) {
actions.release(&NavigationAction::SetAngularVelocity);
actions
.action_data_mut(NavigationAction::SetAngularVelocity)
.action_data_mut_or_default(&NavigationAction::Rotate)
.value = 0.;
}
if actions.pressed(&NavigationAction::SetAngularVelocity) {
// velocity.angvel =
// actions.value(&NavigationAction::SetAngularVelocity);
transform.rotation *= Quat::from_rotation_z(
actions.value(&NavigationAction::SetAngularVelocity) * time.delta_seconds(),
);
} else if actions.just_released(&NavigationAction::SetAngularVelocity) {
actions
.action_data_mut_or_default(&NavigationAction::SetAngularVelocity)
.value = 0.;
velocity.angvel = 0.;
}
@ -308,7 +315,7 @@ fn remove_direction(
mut removed: RemovedComponents<Transform>,
directions: Query<&CardinalDirection>,
) {
for entity in &mut removed {
for entity in removed.read() {
if directions.contains(entity) {
commands.entity(entity).remove::<CardinalDirection>();
}
@ -352,7 +359,7 @@ fn log_area_descriptions<State>(
if !config.log_area_descriptions {
return;
}
for event in events.iter() {
for event in events.read() {
let (entity1, entity2, started) = match event {
CollisionEvent::Started(collider1, collider2, _) => (collider1, collider2, true),
CollisionEvent::Stopped(collider1, collider2, _) => (collider1, collider2, false),

View File

@ -1,7 +1,7 @@
use bevy::{
ecs::entity::Entities,
prelude::*,
tasks::{prelude::*, Task},
tasks::{futures_lite::future, prelude::*, Task},
utils::HashMap,
};
use bevy_rapier2d::{
@ -9,7 +9,6 @@ use bevy_rapier2d::{
prelude::*,
rapier::prelude::{ColliderHandle, ColliderSet, QueryPipeline, RigidBodySet},
};
use futures_lite::future;
use leafwing_input_manager::{axislike::DualAxisData, plugin::InputManagerSystem, prelude::*};
use pathfinding::prelude::*;
@ -22,23 +21,7 @@ use crate::{
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
pub struct NegotiatePathAction;
impl Actionlike for NegotiatePathAction {
fn n_variants() -> usize {
1
}
fn get_at(index: usize) -> Option<Self> {
if index == 0 {
Some(Self)
} else {
None
}
}
fn index(&self) -> usize {
0
}
}
impl Actionlike for NegotiatePathAction {}
#[derive(Component, Debug, Deref, DerefMut)]
struct Calculating(Task<Option<Path>>);
@ -262,7 +245,7 @@ fn remove_destination(
entities: &Entities,
mut removed: RemovedComponents<Destination>,
) {
for entity in &mut removed {
for entity in removed.read() {
if entities.contains(entity) {
commands.entity(entity).remove::<Calculating>();
}
@ -326,6 +309,7 @@ fn negotiate_path(
direction,
collider,
rapier_context.integration_parameters.dt,
true,
QueryFilter::new()
.predicate(&|entity| obstructions.get(entity).is_ok())
.exclude_sensors()
@ -337,9 +321,10 @@ fn negotiate_path(
continue;
}
trace!("{entity:?}: path: direction: {direction:?}");
actions.press(NavigationAction::Move);
actions.action_data_mut(NavigationAction::Move).axis_pair =
Some(DualAxisData::from_xy(Vec2::new(-direction.y, direction.x)));
actions.press(&NavigationAction::Move);
actions
.action_data_mut_or_default(&NavigationAction::Move)
.axis_pair = Some(DualAxisData::from_xy(Vec2::new(-direction.y, direction.x)));
if rotation_speed.is_some() {
let angle = direction.y.atan2(direction.x);
transform.rotation = Quat::from_rotation_z(angle);
@ -351,7 +336,7 @@ fn negotiate_path(
.remove::<Path>()
.remove::<NoPath>()
.remove::<Destination>();
actions.release(NavigationAction::Move);
actions.release(&NavigationAction::Move);
trace!("{entity:?}: pathfinding: cleaned up");
}
}
@ -367,24 +352,25 @@ fn actions(
)>,
) {
for (entity, mut actions, mut navigation_action, destination) in &mut query {
if actions.pressed(NegotiatePathAction) {
if let Some(pair) = actions.axis_pair(NegotiatePathAction) {
if actions.pressed(&NegotiatePathAction) {
if let Some(pair) = actions.axis_pair(&NegotiatePathAction) {
trace!("Negotiating path to {pair:?}");
let dest = Destination((pair.x() as i32, pair.y() as i32));
if let Some(mut current_dest) = destination {
if *current_dest != dest {
trace!("{entity:?}: New destination, zeroing velocity");
navigation_action.press(NavigationAction::SetLinearVelocity);
navigation_action.press(&NavigationAction::SetLinearVelocity);
navigation_action
.action_data_mut(NavigationAction::SetLinearVelocity)
.action_data_mut_or_default(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
*current_dest = dest;
}
} else {
trace!("{entity:?}: Adding destination, zeroing velocity");
navigation_action.press(NavigationAction::SetLinearVelocity);
navigation_action.press(&NavigationAction::SetLinearVelocity);
navigation_action
.action_data_mut(NavigationAction::SetLinearVelocity)
.action_data_mut_or_default(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
commands.entity(entity).insert(dest);
}
@ -394,8 +380,10 @@ fn actions(
.remove::<Destination>()
.remove::<NoPath>();
}
actions.release(NegotiatePathAction);
actions.action_data_mut(NegotiatePathAction).axis_pair = None;
actions.release(&NegotiatePathAction);
actions
.action_data_mut_or_default(&NegotiatePathAction)
.axis_pair = None;
}
}
}

View File

@ -79,7 +79,7 @@ fn update<S>(
if interval.finished() {
interval.reset();
continue;
} else if interval.percent() == 0. {
} else if interval.fraction() == 0. {
sound.generator = None;
}
interval.tick(time.delta());
@ -139,7 +139,7 @@ fn exploration_focus_removed(
children: Query<&Children>,
) {
const ICON_GAIN: f64 = 3.;
for entity in &mut removed {
for entity in removed.read() {
if let Ok(mut icon) = query.get_mut(entity) {
icon.gain /= ICON_GAIN;
}

View File

@ -74,7 +74,7 @@ fn behind_removed(
mut sounds: Query<&mut Sound>,
) {
let downshift = 1. / config.downshift;
for entity in &mut removed {
for entity in removed.read() {
if let Ok(mut icon) = icons.get_mut(entity) {
icon.pitch *= downshift;
last_icon_pitch.remove(&entity);

View File

@ -44,7 +44,7 @@ fn removed(
mut removed: RemovedComponents<Volumetric>,
transforms: Query<Entity, (With<Transform>, With<GlobalTransform>)>,
) {
for entity in &mut removed {
for entity in removed.read() {
if transforms.get(entity).is_ok() {
commands.entity(entity).insert(TransformBundle::default());
}

View File

@ -267,13 +267,13 @@ fn viewshed_removed(
visible_entities: Query<&VisibleEntities>,
mut events: EventWriter<VisibilityChanged>,
) {
for entity in &mut query {
for entity in query.read() {
if let Ok(visible) = visible_entities.get(entity) {
for e in visible.iter() {
events.send(VisibilityChanged::Lost {
viewer: entity,
viewed: *e,
})
});
}
}
}
@ -344,7 +344,7 @@ fn remove_visible(
) {
if !removed.is_empty() {
let mut cache = HashMap::new();
for removed in &mut removed {
for removed in removed.read() {
for (viewer_entity, mut viewshed, mut visible_entities, start) in &mut viewers {
if !visible_entities.contains(&removed) {
continue;
@ -394,7 +394,7 @@ fn log_visible(
timer.tick(time.delta());
}
recently_lost.retain(|_entity, timer| !timer.finished());
for event in events.iter() {
for event in events.read() {
let viewer = match event {
VisibilityChanged::Gained { viewer, .. } => viewer,
VisibilityChanged::Lost { viewer, .. } => viewer,