Skip to content

Commit

Permalink
Merge pull request #4 from TheGrimsey/bevy-0.10
Browse files Browse the repository at this point in the history
Bevy 0.10
  • Loading branch information
TheGrimsey authored Mar 7, 2023
2 parents 6d48e67 + efbe5f1 commit b269726
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.0 (2023-03-07)

- Updated to Bevy 0.10
- Removed ``NavMeshGenerationState``, you can replicate the same functionality by using ``configure_set`` to add a run condition to the ``OxidizedNavigation`` SystemSet.

## 0.2.0 (2023-02-13)

- Implemented ``walkable_radius``. This will "pull-back" the nav-mesh from edges, which means anywhere on the nav-mesh should be fine to stand on for a character with a radius of ``walkable_radius * cell_width``
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "oxidized_navigation"
description = "A Nav-Mesh generation plugin for Bevy Engine."
version = "0.2.0"
version = "0.3.0"
edition = "2021"

authors = ["TheGrimsey"]
Expand All @@ -14,10 +14,10 @@ keywords = ["gamedev", "navmesh", "navmesh-generation", "bevy"]
categories = ["game-development"]

[dependencies]
bevy = { version = "0.9", default-features = false }
bevy_rapier3d = { version = "0.20" }
bevy = { version = "0.10", default-features = false }
bevy_rapier3d = { version = "0.21" }
smallvec = { version = "1.10", features = [ "union" ]}
[dev-dependencies]
bevy = { version = "0.9", default-features = false, features = [ "bevy_winit", "render", "x11" ] }
bevy_prototype_debug_lines = { version = "0.9", features = ["3d"] }
bevy = { version = "0.10", default-features = false, features = [ "bevy_winit", "bevy_render", "x11" ] }
#bevy_prototype_debug_lines = { version = "0.9", features = ["3d"] }
futures-lite = "1.12.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Takes in [Bevy Rapier3D](https://crates.io/crates/bevy_rapier3d) colliders from

| Crate Version | Bevy Version | Bevy Rapier 3D Version |
| ------------- | ------------ | ---------------------- |
| 0.2.0 | 0.10.0 | 0.21 |
| 0.2.0 | 0.9.X | 0.20 |
| 0.1.X | 0.9.X | 0.19 |

Expand Down
30 changes: 14 additions & 16 deletions examples/blocking_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ use bevy::{
tasks::{AsyncComputeTaskPool, Task},
DefaultPlugins,
};
use bevy_prototype_debug_lines::{DebugLines, DebugLinesPlugin};
//use bevy_prototype_debug_lines::{DebugLines, DebugLinesPlugin};
use bevy_rapier3d::prelude::{Collider, NoUserData, RapierConfiguration, RapierPhysicsPlugin};
use futures_lite::future;
use oxidized_navigation::{
query::{find_path, perform_string_pulling_on_path},
tiles::NavMeshTiles,
NavMesh, NavMeshAffector, NavMeshSettings, OxidizedNavigationPlugin, NavMeshGenerationState,
NavMesh, NavMeshAffector, NavMeshSettings, OxidizedNavigationPlugin,
};

fn main() {
App::new()
// Default Plugins
.add_plugins(DefaultPlugins)
// Debug Lines for drawing nav-mesh.
.add_plugin(DebugLinesPlugin::default())
//.add_plugin(DebugLinesPlugin::default())
.insert_resource(NavMeshSettings {
cell_width: 0.25,
cell_height: 0.1,
Expand All @@ -42,9 +42,7 @@ fn main() {
max_contour_simplification_error: 1.1,
max_edge_length: 80,
})
.add_plugin(OxidizedNavigationPlugin {
starting_state: NavMeshGenerationState::Running, // Generate tile updates.
})
.add_plugin(OxidizedNavigationPlugin)
// Rapier.
// The rapier plugin needs to be added for the scales of colliders to be correct if the scale of the entity is not uniformly 1.
// An example of this is the "Thin Wall" in [setup_world_system]. If you remove this plugin, it will not appear correctly.
Expand All @@ -59,7 +57,7 @@ fn main() {
.add_system(run_blocking_pathfinding)
.add_system(run_async_pathfinding)
.add_system(poll_pathfinding_tasks_system)
.add_system(draw_nav_mesh_system)
//.add_system(draw_nav_mesh_system)
.run();
}

Expand All @@ -73,7 +71,7 @@ fn run_blocking_pathfinding(
keys: Res<Input<KeyCode>>,
nav_mesh_settings: Res<NavMeshSettings>,
nav_mesh: Res<NavMesh>,
mut lines: ResMut<DebugLines>,
//mut lines: ResMut<DebugLines>,
) {
if !keys.just_pressed(KeyCode::B) {
return;
Expand All @@ -100,7 +98,7 @@ fn run_blocking_pathfinding(
match perform_string_pulling_on_path(&nav_mesh, start_pos, end_pos, &path) {
Ok(string_path) => {
info!("String path (BLOCKING): {:?}", string_path);
draw_path(&string_path, &mut lines, Color::RED);
//draw_path(&string_path, &mut lines, Color::RED);
}
Err(error) => error!("Error with string path: {:?}", error),
};
Expand Down Expand Up @@ -156,13 +154,13 @@ fn run_async_pathfinding(
// Poll existing tasks.
fn poll_pathfinding_tasks_system(
mut pathfinding_task: ResMut<AsyncPathfindingTasks>,
mut lines: ResMut<DebugLines>,
//mut lines: ResMut<DebugLines>,
) {
// Go through and remove completed tasks.
pathfinding_task.tasks.retain_mut(|task| {
if let Some(string_path) = future::block_on(future::poll_once(task)).unwrap_or(None) {
info!("Async path task finished with result: {:?}", string_path);
draw_path(&string_path, &mut lines, Color::BLUE);
//draw_path(&string_path, &mut lines, Color::BLUE);

false
} else {
Expand Down Expand Up @@ -212,19 +210,19 @@ async fn async_path_find(

// General use path draw.

fn draw_path(path: &[Vec3], lines: &mut DebugLines, color: Color) {
/*fn draw_path(path: &[Vec3], lines: &mut DebugLines, color: Color) {
for (a, b) in path.iter().zip(path.iter().skip(1)) {
lines.line_colored(*a, *b, 15.0, color);
}
}
}*/

//
// Draw Nav-mesh.
// Press M to run.
//
// This uses the crate ``bevy_prototype_debug_lines``.
//
fn draw_nav_mesh_system(
/*fn draw_nav_mesh_system(
keys: Res<Input<KeyCode>>,
nav_mesh: Res<NavMesh>,
mut lines: ResMut<DebugLines>,
Expand Down Expand Up @@ -258,7 +256,7 @@ fn draw_nav_mesh_system(
}
}
}
}
}*/

fn setup_world_system(
mut commands: Commands,
Expand All @@ -268,7 +266,7 @@ fn setup_world_system(
// Plane
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 50.0 })),
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 50.0, subdivisions: 0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
transform: Transform::IDENTITY,
..default()
Expand Down
2 changes: 1 addition & 1 deletion src/contour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn simplify_contour(
w: max_i,
},
);
},
}
_ => {
i += 1;
}
Expand Down
36 changes: 12 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
use std::sync::{Arc, RwLock};

use bevy::prelude::{
error, warn, Deref, DerefMut, IntoSystemDescriptor, Or, SystemLabel, SystemSet, Vec3, With,
error, warn, Deref, DerefMut, Or, SystemSet,
Vec3, With, IntoSystemConfigs,
};
use bevy::tasks::AsyncComputeTaskPool;
use bevy::{
Expand Down Expand Up @@ -55,25 +56,12 @@ pub mod query;
mod regions;
pub mod tiles;

/// State used to pause nav-mesh generation.
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum NavMeshGenerationState {
/// Operation as normal. Tiles are generated and updated.
#[default]
Running,
/// When this is set new tile update tasks won't be started but existing ones will finish.
Paused,
}


/// System label used by the crate's systems.
#[derive(SystemLabel)]
#[derive(SystemSet, Debug, PartialEq, Eq, Hash, Clone)]
pub struct OxidizedNavigation;

#[derive(Default)]
pub struct OxidizedNavigationPlugin {
pub starting_state: NavMeshGenerationState
}
pub struct OxidizedNavigationPlugin;

impl Plugin for OxidizedNavigationPlugin {
fn build(&self, app: &mut App) {
Expand All @@ -82,14 +70,14 @@ impl Plugin for OxidizedNavigationPlugin {
.insert_resource(NavMesh::default())
.insert_resource(GenerationTicker::default());

app.add_state(self.starting_state);

app.add_system_set(
SystemSet::on_update(NavMeshGenerationState::Running)
.label(OxidizedNavigation)
.with_system(update_navmesh_affectors_system)
.with_system(send_tile_rebuild_tasks_system.after(update_navmesh_affectors_system))
.with_system(clear_dirty_tiles_system.after(send_tile_rebuild_tasks_system)),
app.add_systems(
(
update_navmesh_affectors_system,
send_tile_rebuild_tasks_system,
clear_dirty_tiles_system,
)
.chain()
.in_set(OxidizedNavigation),
);
}
}
Expand Down

0 comments on commit b269726

Please sign in to comment.