Update mapgen to custom fork.
This commit is contained in:
parent
b9ae909920
commit
24334ba511
|
@ -32,7 +32,7 @@ coord_2d = "0.3"
|
|||
derive_more = "0.99"
|
||||
futures-lite = "1"
|
||||
gilrs = "0.8"
|
||||
mapgen = "0.5"
|
||||
mapgen = { git = "https://github.com/ndarilek/mapgen.rs" }
|
||||
maze_generator = "1"
|
||||
once_cell = "1"
|
||||
pathfinding = "3"
|
||||
|
|
|
@ -243,11 +243,11 @@ fn exploration_type_changed_announcement(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn exploration_focus<S, A: 'static>(
|
||||
fn exploration_focus<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
config: Res<ExplorationConfig<S, A>>,
|
||||
input: Res<InputMap<A>>,
|
||||
map: Query<&Map>,
|
||||
map: Query<&Map<D>>,
|
||||
explorers: Query<(Entity, &Coordinates, Option<&Exploring>), With<Player>>,
|
||||
) where
|
||||
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
||||
|
@ -295,11 +295,11 @@ fn exploration_focus<S, A: 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
fn navigate_to_explored<S, A: 'static>(
|
||||
fn navigate_to_explored<S, A: 'static, D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
config: Res<ExplorationConfig<S, A>>,
|
||||
input: Res<InputMap<A>>,
|
||||
map: Query<(&Map, &RevealedTiles)>,
|
||||
map: Query<(&Map<D>, &RevealedTiles)>,
|
||||
explorers: Query<(Entity, &Exploring)>,
|
||||
) where
|
||||
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
||||
|
@ -321,10 +321,10 @@ fn navigate_to_explored<S, A: 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
fn exploration_changed_announcement(
|
||||
fn exploration_changed_announcement<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
mut tts: ResMut<Tts>,
|
||||
map: Query<(&Map, &RevealedTiles)>,
|
||||
map: Query<(&Map<D>, &RevealedTiles)>,
|
||||
explorer: Query<(&Coordinates, &Exploring, &Viewshed), Changed<Exploring>>,
|
||||
focused: Query<Entity, With<ExplorationFocused>>,
|
||||
explorable: Query<Entity, Or<(With<Visible>, With<Explorable>)>>,
|
||||
|
@ -442,18 +442,19 @@ impl<S, A> Default for ExplorationConfig<S, A> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ExplorationPlugin<'a, S, A>(PhantomData<&'a S>, PhantomData<&'a A>);
|
||||
pub struct ExplorationPlugin<'a, S, A, D>(PhantomData<&'a S>, PhantomData<&'a A>, PhantomData<D>);
|
||||
|
||||
impl<'a, S, A> Default for ExplorationPlugin<'a, S, A> {
|
||||
impl<'a, S, A, D> Default for ExplorationPlugin<'a, S, A, D> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData, PhantomData)
|
||||
Self(PhantomData, PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S, A> Plugin for ExplorationPlugin<'a, S, A>
|
||||
impl<'a, S, A, D> Plugin for ExplorationPlugin<'a, S, A, D>
|
||||
where
|
||||
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
||||
A: Hash + Eq + Clone + Send + Sync,
|
||||
D: 'static + Clone + Default + Send + Sync,
|
||||
'a: 'static,
|
||||
{
|
||||
fn build(&self, app: &mut App) {
|
||||
|
@ -470,13 +471,13 @@ where
|
|||
.register_type::<Mappable>()
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
exploration_changed_announcement.chain(error_handler),
|
||||
exploration_changed_announcement::<D>.chain(error_handler),
|
||||
);
|
||||
if config.exploration_control_states.is_empty() {
|
||||
app.add_system(exploration_focus::<S, A>)
|
||||
app.add_system(exploration_focus::<S, A, D>)
|
||||
.add_system(exploration_type_focus::<S, A>.chain(error_handler))
|
||||
.add_system(exploration_type_change::<S, A>.chain(error_handler))
|
||||
.add_system(navigate_to_explored::<S, A>)
|
||||
.add_system(navigate_to_explored::<S, A, D>)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
exploration_type_changed_announcement.chain(error_handler),
|
||||
|
@ -486,10 +487,10 @@ where
|
|||
for state in states {
|
||||
app.add_system_set(
|
||||
SystemSet::on_update(state.clone())
|
||||
.with_system(exploration_focus::<S, A>)
|
||||
.with_system(exploration_focus::<S, A, D>)
|
||||
.with_system(exploration_type_focus::<S, A>.chain(error_handler))
|
||||
.with_system(exploration_type_change::<S, A>.chain(error_handler))
|
||||
.with_system(navigate_to_explored::<S, A>)
|
||||
.with_system(navigate_to_explored::<S, A, D>)
|
||||
.with_system(exploration_type_changed_announcement.chain(error_handler)),
|
||||
)
|
||||
.add_system_set(SystemSet::on_exit(state).with_system(cleanup));
|
||||
|
|
51
src/map.rs
51
src/map.rs
|
@ -1,4 +1,7 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
@ -26,10 +29,10 @@ impl From<mapgen::geometry::Point> for Coordinates {
|
|||
pub struct Area(pub AABB);
|
||||
|
||||
#[derive(Component, Clone, Default, Deref, DerefMut)]
|
||||
pub struct Map(pub MapgenMap);
|
||||
pub struct Map<D: 'static + Clone + Default + Send + Sync>(pub MapgenMap<D>);
|
||||
|
||||
impl From<MapgenMap> for Map {
|
||||
fn from(v: MapgenMap) -> Self {
|
||||
impl<D: Clone + Default + Send + Sync> From<MapgenMap<D>> for Map<D> {
|
||||
fn from(v: MapgenMap<D>) -> Self {
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
@ -134,8 +137,8 @@ impl Default for PortalBundle {
|
|||
}
|
||||
|
||||
#[derive(Bundle, Clone, Default)]
|
||||
pub struct MapBundle {
|
||||
pub map: Map,
|
||||
pub struct MapBundle<D: 'static + Clone + Default + Send + Sync> {
|
||||
pub map: Map<D>,
|
||||
pub spawn_colliders: SpawnColliders,
|
||||
pub spawn_collider_per_tile: SpawnColliderPerTile,
|
||||
pub spawn_portals: SpawnPortals,
|
||||
|
@ -167,8 +170,8 @@ impl GridBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
impl MapFilter for GridBuilder {
|
||||
fn modify_map(&self, _rng: &mut StdRng, map: &MapgenMap) -> MapgenMap {
|
||||
impl<D: Clone + Default> MapFilter<D> for GridBuilder {
|
||||
fn modify_map(&self, _rng: &mut StdRng, map: &MapgenMap<D>) -> MapgenMap<D> {
|
||||
let mut map = map.clone();
|
||||
let mut generator = RbGenerator::new(None);
|
||||
let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32);
|
||||
|
@ -224,9 +227,9 @@ impl MapFilter for GridBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
fn spawn_colliders(
|
||||
fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
maps: Query<(Entity, &Map, &SpawnColliders, &SpawnColliderPerTile), Changed<SpawnColliders>>,
|
||||
maps: Query<(Entity, &Map<D>, &SpawnColliders, &SpawnColliderPerTile), Changed<SpawnColliders>>,
|
||||
) {
|
||||
for (map_entity, map, spawn_colliders, spawn_collider_per_tile) in maps.iter() {
|
||||
if **spawn_colliders {
|
||||
|
@ -325,7 +328,9 @@ fn spawn_colliders(
|
|||
let center = (bl.0 as f32 + half_width, br.1 as f32 + half_height);
|
||||
trace!(
|
||||
"Create shape at {:?} of width {:?} and height {:?}",
|
||||
center, width, height
|
||||
center,
|
||||
width,
|
||||
height
|
||||
);
|
||||
let id = commands
|
||||
.spawn_bundle(ColliderBundle {
|
||||
|
@ -367,9 +372,9 @@ fn spawn_colliders(
|
|||
}
|
||||
}
|
||||
|
||||
fn spawn_portals(
|
||||
fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
map: Query<(Entity, &Map, &SpawnPortals), Changed<SpawnPortals>>,
|
||||
map: Query<(Entity, &Map<D>, &SpawnPortals), Changed<SpawnPortals>>,
|
||||
) {
|
||||
for (entity, map, spawn_portals) in map.iter() {
|
||||
if **spawn_portals {
|
||||
|
@ -422,9 +427,9 @@ fn spawn_portals(
|
|||
}
|
||||
}
|
||||
|
||||
fn spawn_portal_colliders(
|
||||
fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
map: Query<(Entity, &SpawnColliders), With<Map>>,
|
||||
map: Query<(Entity, &SpawnColliders), With<Map<D>>>,
|
||||
portals: Query<(Entity, &Coordinates), Without<ColliderShapeComponent>>,
|
||||
) {
|
||||
for (map_entity, spawn_colliders) in map.iter() {
|
||||
|
@ -484,18 +489,24 @@ fn area_description(
|
|||
}
|
||||
}
|
||||
|
||||
pub struct MapPlugin;
|
||||
pub struct MapPlugin<D: 'static + Clone + Default + Send + Sync>(PhantomData<D>);
|
||||
|
||||
impl Plugin for MapPlugin {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Default for MapPlugin<D> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Plugin for MapPlugin<D> {
|
||||
fn build(&self, app: &mut App) {
|
||||
if !app.world.contains_resource::<MapConfig>() {
|
||||
app.insert_resource(MapConfig::default());
|
||||
}
|
||||
let config = app.world.get_resource::<MapConfig>().unwrap().clone();
|
||||
app.register_type::<Portal>()
|
||||
.add_system(spawn_colliders)
|
||||
.add_system(spawn_portals)
|
||||
.add_system(spawn_portal_colliders);
|
||||
.add_system(spawn_colliders::<D>)
|
||||
.add_system(spawn_portals::<D>)
|
||||
.add_system(spawn_portal_colliders::<D>);
|
||||
if config.speak_area_descriptions {
|
||||
app.add_system_to_stage(CoreStage::PostUpdate, area_description);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
|
||||
use bevy::{
|
||||
ecs::entity::Entities,
|
||||
|
@ -39,10 +39,10 @@ pub struct NoPath;
|
|||
#[reflect(Component)]
|
||||
pub struct Path(pub Vec<(i32, i32)>);
|
||||
|
||||
pub fn find_path(
|
||||
pub fn find_path<D: 'static + Clone + Default + Send + Sync>(
|
||||
start: &dyn PointLike,
|
||||
destination: &dyn PointLike,
|
||||
map: &Map,
|
||||
map: &Map<D>,
|
||||
) -> Option<(Vec<(i32, i32)>, u32)> {
|
||||
astar(
|
||||
&start.into(),
|
||||
|
@ -153,12 +153,12 @@ impl ComponentSetOption<ColliderPosition> for StaticColliderComponentsSet {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_path_for_shape(
|
||||
fn find_path_for_shape<D: 'static + Clone + Default + Send + Sync>(
|
||||
initiator: Entity,
|
||||
start: Coordinates,
|
||||
destination: Destination,
|
||||
query_pipeline: QueryPipeline,
|
||||
map: Map,
|
||||
map: Map<D>,
|
||||
collider_set: StaticColliderComponentsSet,
|
||||
shape: ColliderShape,
|
||||
) -> Option<Path> {
|
||||
|
@ -198,7 +198,7 @@ fn find_path_for_shape(
|
|||
}
|
||||
}
|
||||
|
||||
fn calculate_path(
|
||||
fn calculate_path<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
pool: Res<AsyncComputeTaskPool>,
|
||||
query_pipeline: Res<QueryPipeline>,
|
||||
|
@ -208,7 +208,7 @@ fn calculate_path(
|
|||
(Entity, &Destination, &Coordinates, &ColliderShapeComponent),
|
||||
Changed<Destination>,
|
||||
>,
|
||||
map: Query<&Map>,
|
||||
map: Query<&Map<D>>,
|
||||
) {
|
||||
for (entity, destination, coordinates, shape) in query.iter() {
|
||||
if coordinates.i32() == **destination {
|
||||
|
@ -325,11 +325,17 @@ fn negotiate_path(
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PathfindingPlugin;
|
||||
pub struct PathfindingPlugin<D: 'static + Clone + Default + Send + Sync>(PhantomData<D>);
|
||||
|
||||
impl Plugin for PathfindingPlugin {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Default for PathfindingPlugin<D> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Plugin for PathfindingPlugin<D> {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_system(calculate_path)
|
||||
app.add_system(calculate_path::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_destination)
|
||||
.add_system(poll_tasks)
|
||||
.add_system(negotiate_path);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{HashMap, HashSet},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use bevy::{core::FixedTimestep, prelude::*};
|
||||
|
@ -44,14 +45,14 @@ impl Viewshed {
|
|||
pub fn is_point_visible(&self, point: &dyn PointLike) -> bool {
|
||||
self.visible_points.contains(&point.into())
|
||||
}
|
||||
fn update(
|
||||
fn update<D: 'static + Clone + Default + Send + Sync>(
|
||||
&mut self,
|
||||
viewer_entity: &Entity,
|
||||
visible_entities: &mut VisibleEntities,
|
||||
start: &dyn PointLike,
|
||||
query_pipeline: &QueryPipeline,
|
||||
collider_query: &QueryPipelineColliderComponentsQuery,
|
||||
map: &Map,
|
||||
map: &Map<D>,
|
||||
visible_query: &Query<&Visible>,
|
||||
events: &mut EventWriter<VisibilityChanged>,
|
||||
) {
|
||||
|
@ -187,9 +188,9 @@ impl PointLike for Coord {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_visibility_indices(
|
||||
fn add_visibility_indices<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
query: Query<(Entity, &Map), (Added<Map>, Without<RevealedTiles>)>,
|
||||
query: Query<(Entity, &Map<D>), (Added<Map<D>>, Without<RevealedTiles>)>,
|
||||
map_config: Res<MapConfig>,
|
||||
) {
|
||||
for (entity, map) in query.iter() {
|
||||
|
@ -217,13 +218,17 @@ fn viewshed_removed(
|
|||
}
|
||||
}
|
||||
|
||||
pub struct VisibilityGrid<'a, F>(pub &'a Map, pub RefCell<Box<F>>);
|
||||
pub struct VisibilityGrid<'a, D: 'static + Clone + Default + Send + Sync, F>(
|
||||
pub &'a Map<D>,
|
||||
pub RefCell<Box<F>>,
|
||||
);
|
||||
|
||||
impl<'a, F> InputGrid for VisibilityGrid<'a, F>
|
||||
impl<'a, D, F> InputGrid for VisibilityGrid<'a, D, F>
|
||||
where
|
||||
D: 'static + Clone + Default + Send + Sync,
|
||||
F: FnMut(Coord) -> u8,
|
||||
{
|
||||
type Grid = VisibilityGrid<'a, F>;
|
||||
type Grid = VisibilityGrid<'a, D, F>;
|
||||
|
||||
type Opacity = u8;
|
||||
|
||||
|
@ -236,12 +241,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn update_viewshed(
|
||||
fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
||||
config: Res<RapierConfiguration>,
|
||||
positions: Query<(Entity, &RigidBodyPositionComponent), Changed<RigidBodyPositionComponent>>,
|
||||
visible: Query<&Visible>,
|
||||
mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>,
|
||||
map: Query<&Map>,
|
||||
map: Query<&Map<D>>,
|
||||
query_pipeline: Res<QueryPipeline>,
|
||||
collider_query: QueryPipelineColliderComponentsQuery,
|
||||
mut changed: EventWriter<VisibilityChanged>,
|
||||
|
@ -293,10 +298,10 @@ fn update_viewshed(
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_visible(
|
||||
fn remove_visible<D: 'static + Clone + Default + Send + Sync>(
|
||||
removed: RemovedComponents<Visible>,
|
||||
mut viewers: Query<(Entity, &mut Viewshed, &mut VisibleEntities, &Coordinates)>,
|
||||
map: Query<&Map>,
|
||||
map: Query<&Map<D>>,
|
||||
query_pipeline: Res<QueryPipeline>,
|
||||
collider_query: QueryPipelineColliderComponentsQuery,
|
||||
visible: Query<&Visible>,
|
||||
|
@ -324,8 +329,8 @@ fn remove_visible(
|
|||
}
|
||||
}
|
||||
|
||||
fn update_revealed_tiles(
|
||||
mut map: Query<(&Map, &mut RevealedTiles)>,
|
||||
fn update_revealed_tiles<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut map: Query<(&Map<D>, &mut RevealedTiles)>,
|
||||
viewers: Query<&Viewshed, With<Player>>,
|
||||
) {
|
||||
for (map, mut revealed_tiles) in map.iter_mut() {
|
||||
|
@ -395,16 +400,22 @@ fn log_visible(
|
|||
|
||||
pub const LOG_VISIBLE_LABEL: &str = "LOG_VISIBLE";
|
||||
|
||||
pub struct VisibilityPlugin;
|
||||
pub struct VisibilityPlugin<D: 'static + Clone + Default + Send + Sync>(PhantomData<D>);
|
||||
|
||||
impl Plugin for VisibilityPlugin {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Default for VisibilityPlugin<D> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<D> {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<VisibilityChanged>()
|
||||
.add_system(add_visibility_indices)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_viewshed)
|
||||
.add_system(add_visibility_indices::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_viewshed::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_visible)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_visible::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, log_visible);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user