Compare commits

..

No commits in common. "3a6ede042812f0fb9cac3369e5b493be0f90b9e6" and "f6855ff727141bb28f65c8c7f25cf2d5592225c1" have entirely different histories.

13 changed files with 108 additions and 138 deletions

View File

@ -8,7 +8,7 @@ steps:
commands:
- rustup component add clippy rustfmt
- apt-get update -qq
- apt-get install -qqy llvm-dev libspeechd-dev pkg-config libx11-dev libasound2-dev libudev-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev libvulkan-dev cmake
- apt-get install -qqy llvm-dev libclang-dev clang libspeechd-dev pkg-config libx11-dev libasound2-dev libudev-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev libvulkan-dev cmake
- cargo fmt --check
- cargo test --no-default-features --features=speech_dispatcher_0_10
- cargo clippy --no-default-features --features=speech_dispatcher_0_10

View File

@ -8,12 +8,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
speech_dispatcher_0_9 = ["bevy_tts/speech_dispatcher_0_9"]
speech_dispatcher_0_10 = ["bevy_tts/speech_dispatcher_0_10"]
speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"]
[dependencies.bevy]
version = "0.9"
version = "0.8"
default-features = false
features = [
"bevy_gilrs",
@ -26,18 +25,18 @@ features = [
[dependencies]
backtrace = "0.3"
bevy_rapier2d = "0.19"
bevy_synthizer = "0.1"
bevy_tts = { version = "0.2", default-features = false, features = ["tolk"] }
bevy_rapier2d = "0.17"
bevy_synthizer = { git = "https://labs.lightsout.games/projects/bevy_synthizer" }
bevy_tts = { version = "0.1", default-features = false, features = ["tolk"] }
coord_2d = "0.3"
futures-lite = "1"
gilrs = "0.10"
gilrs = "0.9"
here_be_dragons = "0.2"
leafwing-input-manager = "0.7"
leafwing_input_manager = { git = "https://github.com/leafwing-studios/leafwing-input-manager", branch = "dev" }
maze_generator = "2"
once_cell = "1"
pathfinding = "4"
pathfinding = "3"
rand = "0.8"
sentry = "0.29"
sentry = "0.27"
serde = "1"
shadowcast = "0.8"

View File

@ -7,11 +7,11 @@ use std::{
sync::RwLock,
};
use bevy::{app::PluginGroupBuilder, ecs::query::WorldQuery, prelude::*, utils::FloatOrd};
use bevy::{ecs::query::WorldQuery, prelude::*, utils::FloatOrd};
use bevy_rapier2d::{
parry::query::{closest_points, distance, ClosestPoints},
prelude::*,
rapier::{math::Isometry, prelude::Aabb},
rapier::{math::Isometry, prelude::AABB},
};
use once_cell::sync::Lazy;
use rand::prelude::*;
@ -143,7 +143,7 @@ impl Sub for Angle {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Reflect)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MovementDirection {
North,
NorthNortheast,
@ -222,10 +222,8 @@ impl Display for MovementDirection {
}
}
#[derive(Component, Clone, Copy, Default, Debug, Eq, PartialEq, Reflect)]
#[reflect(Component)]
#[derive(Component, Clone, Copy, Debug, Eq, PartialEq)]
pub enum CardinalDirection {
#[default]
North,
East,
South,
@ -572,7 +570,7 @@ impl GlobalTransformExt for GlobalTransform {
}
#[derive(Component, Copy, Clone, Debug, Deref, DerefMut, PartialEq)]
pub struct Area(pub Aabb);
pub struct Area(pub AABB);
#[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)]
@ -644,7 +642,7 @@ fn setup(core_config: Res<CoreConfig>) {
*mode = core_config.relative_direction_mode;
}
#[derive(Resource, Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct CoreConfig {
pub relative_direction_mode: RelativeDirectionMode,
pub pixels_per_unit: u8,
@ -680,8 +678,7 @@ impl<RapierUserData: 'static + WorldQuery + Send + Sync> Plugin for CorePlugin<R
app.insert_resource(CoreConfig::default());
}
let config = *app.world.get_resource::<CoreConfig>().unwrap();
app.register_type::<CardinalDirection>()
.add_plugin(RapierPhysicsPlugin::<RapierUserData>::pixels_per_meter(
app.add_plugin(RapierPhysicsPlugin::<RapierUserData>::pixels_per_meter(
config.pixels_per_unit as f32,
))
.add_startup_system(setup)
@ -700,10 +697,10 @@ impl<RapierUserData> Default for CorePlugins<RapierUserData> {
impl<RapierUserData: 'static + WorldQuery + Send + Sync> PluginGroup
for CorePlugins<RapierUserData>
{
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
fn build(&mut self, group: &mut bevy::app::PluginGroupBuilder) {
group
.add(crate::bevy_tts::TtsPlugin)
.add(crate::bevy_synthizer::SynthizerPlugin::default())
.add(CorePlugin::<RapierUserData>::default())
.add(crate::bevy_synthizer::SynthizerPlugin)
.add(CorePlugin::<RapierUserData>::default());
}
}

View File

@ -4,9 +4,6 @@ use std::{panic, thread};
use backtrace::Backtrace;
use bevy::prelude::*;
#[derive(Resource)]
struct Guard(sentry::ClientInitGuard);
pub fn error_handler(In(result): In<Result<(), Box<dyn Error>>>) {
if let Err(e) = result {
error!("{}", e);
@ -47,7 +44,7 @@ fn init_panic_handler() {
}));
}
#[derive(Resource, Clone, Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct ErrorConfig {
pub sentry_dsn: Option<String>,
pub version: Option<String>,
@ -60,7 +57,7 @@ impl Plugin for ErrorPlugin {
init_panic_handler();
if let Some(config) = app.world.get_resource::<ErrorConfig>() {
if let Some(dsn) = &config.sentry_dsn {
let release = config.version.clone().unwrap_or_default();
let release = config.version.clone().unwrap_or_else(|| "".to_string());
let guard = sentry::init((
dsn.as_str(),
sentry::ClientOptions {
@ -68,7 +65,7 @@ impl Plugin for ErrorPlugin {
..default()
},
));
app.insert_resource(Guard(guard));
app.insert_resource(guard);
}
}
}

View File

@ -41,9 +41,7 @@ pub struct Exploring(pub (f32, f32));
impl_pointlike_for_tuple_component!(Exploring);
#[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
pub struct FocusedExplorationType<T>(pub Option<T>)
where
T: Component + Default;
pub struct FocusedExplorationType<T>(pub Option<T>);
#[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)]
@ -59,7 +57,7 @@ fn exploration_type_change<T, S>(
features: Query<&T>,
) -> Result<(), Box<dyn Error>>
where
T: Component + Default + Copy + Ord,
T: Component + Copy + Ord,
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
{
for (actions, visible, mut focused) in explorers.iter_mut() {
@ -125,7 +123,7 @@ fn exploration_type_focus<T, S>(
features: Query<(Entity, &Transform, &T)>,
) -> Result<(), Box<dyn Error>>
where
T: Component + Default + PartialEq,
T: Component + PartialEq,
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
{
for (entity, actions, visible_entities, focused_type, exploring) in explorers.iter() {
@ -183,7 +181,7 @@ fn exploration_type_changed_announcement<T>(
>,
) -> Result<(), Box<dyn Error>>
where
T: Component + Default + Copy + Into<String>,
T: Component + Copy + Into<String>,
{
for (focused, changed) in focused.iter() {
if changed.is_added() {
@ -369,7 +367,7 @@ fn cleanup(
}
}
#[derive(Resource, Clone, Debug)]
#[derive(Clone, Debug)]
pub struct ExplorationConfig<S> {
pub exploration_control_states: Vec<S>,
}
@ -413,17 +411,16 @@ where
.clone();
app.register_type::<ExplorationFocused>()
.register_type::<Mappable>()
.register_type::<Explorable>()
.add_plugin(InputManagerPlugin::<ExplorationAction>::default())
.add_system(exploration_changed_announcement::<T, D>.pipe(error_handler));
.add_system(exploration_changed_announcement::<T, D>.chain(error_handler));
if config.exploration_control_states.is_empty() {
app.add_system(exploration_focus::<S, D>)
.add_system(exploration_type_focus::<T, S>.pipe(error_handler))
.add_system(exploration_type_change::<T, S>.pipe(error_handler))
.add_system(exploration_type_focus::<T, S>.chain(error_handler))
.add_system(exploration_type_change::<T, S>.chain(error_handler))
.add_system(navigate_to_explored::<S, D>)
.add_system_to_stage(
CoreStage::PostUpdate,
exploration_type_changed_announcement::<T>.pipe(error_handler),
exploration_type_changed_announcement::<T>.chain(error_handler),
);
} else {
let states = config.exploration_control_states;
@ -431,11 +428,11 @@ where
app.add_system_set(
SystemSet::on_update(state.clone())
.with_system(exploration_focus::<S, D>)
.with_system(exploration_type_focus::<T, S>.pipe(error_handler))
.with_system(exploration_type_change::<T, S>.pipe(error_handler))
.with_system(exploration_type_focus::<T, S>.chain(error_handler))
.with_system(exploration_type_change::<T, S>.chain(error_handler))
.with_system(navigate_to_explored::<S, D>)
.with_system(
exploration_type_changed_announcement::<T>.pipe(error_handler),
exploration_type_changed_announcement::<T>.chain(error_handler),
),
)
.add_system_set(SystemSet::on_exit(state).with_system(cleanup));

View File

@ -17,7 +17,7 @@ impl Log {
}
}
#[derive(Component, Clone, Debug, Reflect)]
#[derive(Component, Clone, Debug)]
pub struct LogEntry {
pub time: Instant,
pub message: String,
@ -33,7 +33,7 @@ impl From<String> for LogEntry {
}
fn setup(mut commands: Commands) {
commands.spawn(Log::default());
commands.spawn().insert(Log::default());
}
fn read_log(
@ -59,8 +59,7 @@ pub struct LogPlugin;
impl Plugin for LogPlugin {
fn build(&self, app: &mut App) {
app.register_type::<LogEntry>()
.add_startup_system(setup)
.add_system_to_stage(CoreStage::PostUpdate, read_log.pipe(error_handler));
app.add_startup_system(setup)
.add_system_to_stage(CoreStage::PostUpdate, read_log.chain(error_handler));
}
}

View File

@ -78,7 +78,7 @@ impl ITileType for Tile {
}
}
#[derive(Resource, Clone, Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct MapConfig {
pub start_revealed: bool,
}
@ -151,22 +151,22 @@ impl<D: Clone + Default> MapFilter<D> for GridBuilder {
if field.has_passage(&North) {
let x = x_offset + half_width;
let y = y_offset + self.room_height;
map.set_tile(x, y, Tile::floor());
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&South) {
let x = x_offset + half_width;
let y = y_offset;
map.set_tile(x, y, Tile::floor());
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&East) {
let x = x_offset + self.room_width;
let y = y_offset + half_height;
map.set_tile(x, y, Tile::floor());
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&West) {
let x = x_offset;
let y = y_offset + half_height;
map.set_tile(x, y, Tile::floor());
map.set_tile(x as usize, y as usize, Tile::floor());
}
}
}
@ -198,16 +198,13 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
for x in 0..map.width {
if let Some(tile) = map.at(x, y) {
if tile.blocks_motion() {
let id = commands
.spawn((
TransformBundle::from_transform(Transform::from_xyz(
x as f32 + 0.5,
y as f32 + 0.5,
0.,
)),
Collider::cuboid(0.5, 0.5),
MapObstruction,
let id =
commands
.spawn_bundle(TransformBundle::from_transform(
Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.),
))
.insert(Collider::cuboid(0.5, 0.5))
.insert(MapObstruction)
.id();
if tile.blocks_visibility() {
commands.entity(id).insert(Visible::opaque());
@ -226,18 +223,16 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
Isometry2::new(Vector2::new(room.center().x(), room.center().y()), 0.);
let aabb = shape.raw.compute_aabb(&position);
let id = commands
.spawn((
TransformBundle::from_transform(Transform::from_xyz(
.spawn_bundle(TransformBundle::from_transform(Transform::from_xyz(
position.translation.x,
position.translation.y,
0.,
)),
shape,
Sensor,
ActiveEvents::COLLISION_EVENTS,
Area(aabb),
Zone,
))
)))
.insert(shape)
.insert(Sensor)
.insert(ActiveEvents::COLLISION_EVENTS)
.insert(Area(aabb))
.insert(Zone)
.id();
commands.entity(map_entity).push_children(&[id]);
}
@ -286,7 +281,7 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
}
for (x, y) in portals {
let portal = commands
.spawn(PortalBundle {
.spawn_bundle(PortalBundle {
transform: Transform::from_translation(Vec3::new(x, y, 0.)),
..default()
})

View File

@ -49,22 +49,19 @@ pub struct RotationSpeed(pub Angle);
#[reflect(Component)]
pub struct Speed(pub f32);
#[derive(Deref, DerefMut)]
#[derive(Component, Deref, DerefMut)]
struct SnapTimer(Timer);
impl Default for SnapTimer {
fn default() -> Self {
Self(Timer::from_seconds(0.2, TimerMode::Once))
Self(Timer::from_seconds(0.2, false))
}
}
#[derive(Resource, Default, Deref, DerefMut)]
struct SnapTimers(HashMap<Entity, SnapTimer>);
fn movement_controls<S>(
mut commands: Commands,
config: Res<NavigationConfig<S>>,
snap_timers: Res<SnapTimers>,
snap_timers: Res<HashMap<Entity, SnapTimer>>,
mut query: Query<(
Entity,
&mut ActionState<NavigationAction>,
@ -121,14 +118,14 @@ fn movement_controls<S>(
.axis_pair = Some(DualAxisData::from_xy(v));
}
}
if actions.released(NavigationAction::Move)
&& actions.axis_pair(NavigationAction::Move).is_some()
{
if actions.released(NavigationAction::Move) {
if actions.axis_pair(NavigationAction::Move).is_some() {
actions.press(NavigationAction::SetLinearVelocity);
actions
.action_data_mut(NavigationAction::SetLinearVelocity)
.axis_pair = None;
}
}
if actions.pressed(NavigationAction::SetLinearVelocity) {
if let Some(pair) = actions.axis_pair(NavigationAction::SetLinearVelocity) {
velocity.linvel = pair.into();
@ -170,7 +167,7 @@ fn movement_controls<S>(
fn snap(
mut tts: ResMut<Tts>,
mut snap_timers: ResMut<SnapTimers>,
mut snap_timers: ResMut<HashMap<Entity, SnapTimer>>,
mut query: Query<
(
Entity,
@ -213,7 +210,7 @@ fn snap(
Ok(())
}
fn tick_snap_timers(time: Res<Time>, mut snap_timers: ResMut<SnapTimers>) {
fn tick_snap_timers(time: Res<Time>, mut snap_timers: ResMut<HashMap<Entity, SnapTimer>>) {
for timer in snap_timers.values_mut() {
timer.tick(time.delta());
}
@ -339,7 +336,7 @@ fn log_area_descriptions<S, A>(
}
}
#[derive(Resource, Clone, Debug)]
#[derive(Clone, Debug)]
pub struct NavigationConfig<S> {
pub forward_movement_factor: f32,
pub backward_movement_factor: f32,
@ -386,15 +383,14 @@ where
.get_resource::<NavigationConfig<S>>()
.unwrap()
.clone();
app.init_resource::<SnapTimers>()
app.init_resource::<HashMap<Entity, SnapTimer>>()
.register_type::<MaxSpeed>()
.register_type::<RotationSpeed>()
.register_type::<Speed>()
.add_plugin(InputManagerPlugin::<NavigationAction>::default())
.add_system_to_stage(CoreStage::PreUpdate, update_direction)
.add_system_to_stage(CoreStage::PostUpdate, remove_direction)
.add_system(tick_snap_timers)
.add_system(speak_direction.pipe(error_handler))
.add_system(speak_direction.chain(error_handler))
.add_system(add_speed)
.add_system(limit_speed)
.add_system_to_stage(CoreStage::PostUpdate, remove_speed)
@ -406,14 +402,14 @@ where
.label(MOVEMENT_CONTROLS)
.after(limit_speed),
)
.add_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS));
.add_system(snap.chain(error_handler).before(MOVEMENT_CONTROLS));
} else {
let states = config.movement_control_states;
for state in states {
app.add_system_set(
SystemSet::on_update(state)
.with_system(movement_controls::<S>.label(MOVEMENT_CONTROLS))
.with_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS)),
.with_system(snap.chain(error_handler).before(MOVEMENT_CONTROLS)),
);
}
}

View File

@ -59,7 +59,7 @@ impl CostMap {
}
pub fn set_modifier(&mut self, x: usize, y: usize, cost: f32) {
let idx = y * self.width + x;
let idx = (y as usize) * self.width + (x as usize);
self.costs[idx] = cost;
}
}
@ -109,8 +109,8 @@ fn find_path_for_shape(
&start.i32(),
|p| {
let mut successors: Vec<((i32, i32), u32)> = vec![];
let x = p.0;
let y = p.1;
let x = p.0 as i32;
let y = p.1 as i32;
let exits = vec![
((x - 1, y), 1.),
((x + 1, y), 1.),
@ -325,11 +325,7 @@ pub struct PathfindingPlugin;
impl Plugin for PathfindingPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Destination>()
.register_type::<NoPath>()
.register_type::<Path>()
.register_type::<CostMap>()
.add_system(calculate_path)
app.add_system(calculate_path)
.add_system_to_stage(CoreStage::PostUpdate, remove_destination)
.add_system(poll_tasks)
.add_system_to_stage(CoreStage::PostUpdate, negotiate_path);

View File

@ -8,11 +8,10 @@ use crate::{
sound::SoundIcon,
};
#[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)]
#[derive(Component, Clone, Copy, Debug, Default)]
struct Behind;
#[derive(Resource, Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct PitchShiftConfig {
pub downshift_behind: bool,
pub downshift: f64,
@ -64,10 +63,10 @@ fn tag_behind(
}
}
#[derive(Resource, Clone, Debug, Default, Deref, DerefMut)]
#[derive(Clone, Debug, Default, Deref, DerefMut)]
struct LastIconPitch(HashMap<Entity, f64>);
#[derive(Resource, Clone, Debug, Default, Deref, DerefMut)]
#[derive(Clone, Debug, Default, Deref, DerefMut)]
struct LastSoundPitch(HashMap<Entity, f64>);
fn behind_added(
@ -159,8 +158,7 @@ pub struct PitchShiftPlugin;
impl Plugin for PitchShiftPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Behind>()
.init_resource::<PitchShiftConfig>()
app.init_resource::<PitchShiftConfig>()
.init_resource::<LastIconPitch>()
.init_resource::<LastSoundPitch>()
.add_system_to_stage(CoreStage::PreUpdate, tag_behind)

View File

@ -12,8 +12,7 @@ use crate::{
visibility::{VisibilityChanged, Visible, VisibleEntities},
};
#[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component)]
#[derive(Component, Clone, Debug)]
pub struct SoundIcon {
pub buffer: Handle<Buffer>,
pub gain: f64,
@ -28,7 +27,7 @@ impl Default for SoundIcon {
buffer: default(),
gain: 1.,
pitch: 1.,
interval: Some(Timer::from_seconds(seconds, TimerMode::Repeating)),
interval: Some(Timer::from_seconds(seconds, true)),
};
if let Some(ref mut interval) = icon.interval {
let seconds = Duration::from_secs_f32(seconds - 0.1);
@ -72,7 +71,7 @@ fn update<S>(
) where
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
{
if !config.states.is_empty() && !config.states.contains(state.current()) {
if !(*config).states.is_empty() && !config.states.contains(state.current()) {
return;
}
for visible in viewers.iter() {
@ -167,7 +166,7 @@ fn reset_timer_on_visibility_gain(
if let Ok(children) = children.get(*viewed) {
for child in children.iter() {
if icons.get(*child).is_ok() {
targets.push(child);
targets.push(&*child);
}
}
}
@ -183,7 +182,7 @@ fn reset_timer_on_visibility_gain(
}
}
#[derive(Resource, Clone, Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct SoundIconConfig<S> {
pub states: Vec<S>,
}
@ -201,8 +200,7 @@ where
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
{
fn build(&self, app: &mut App) {
app.register_type::<SoundIcon>()
.add_system(added)
app.add_system(added)
.add_system_to_stage(CoreStage::PostUpdate, update::<S>)
.add_system_to_stage(
CoreStage::PostUpdate,

View File

@ -4,8 +4,7 @@ use bevy_synthizer::{Listener, Sound};
use crate::{commands::RunIfExistsExt, core::GlobalTransformExt};
#[derive(Component, Default, Reflect, Clone, Copy, Debug)]
#[reflect(Component)]
#[derive(Component, Clone, Copy, Debug)]
pub struct Volumetric;
fn update(
@ -42,7 +41,7 @@ fn update(
fn removed(mut commands: Commands, removed: RemovedComponents<Volumetric>) {
for entity in removed.iter() {
commands.run_if_exists(entity, |mut entity| {
entity.insert(TransformBundle::default());
entity.insert_bundle(TransformBundle::default());
});
}
}
@ -51,8 +50,7 @@ pub struct VolumetricPlugin;
impl Plugin for VolumetricPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Volumetric>()
.add_system_to_stage(
app.add_system_to_stage(
CoreStage::PostUpdate,
update.before(TransformSystem::TransformPropagate),
)

View File

@ -354,7 +354,7 @@ fn remove_visible(
&viewer_entity,
&mut visible_entities,
start,
&rapier_context,
&*rapier_context,
&visible,
&obstructions,
&mut changed,
@ -422,7 +422,7 @@ fn log_visible(
}
}
} else if let VisibilityChanged::Lost { viewed, .. } = event {
recently_lost.insert(*viewed, Timer::from_seconds(2., TimerMode::Once));
recently_lost.insert(*viewed, Timer::from_seconds(2., false));
}
}
}