Stupid attempt that gets me nothing because I'm still inserting a task for each tile - same problem
This commit is contained in:
parent
21cec093b9
commit
84bceda2a2
|
@ -102,7 +102,7 @@ fn main() -> AppExit {
|
||||||
OnEnter(View::LoadingGame),
|
OnEnter(View::LoadingGame),
|
||||||
(player::startup, statue::startup, map::spawn),
|
(player::startup, statue::startup, map::spawn),
|
||||||
)
|
)
|
||||||
.add_systems(OnEnter(View::InGame), (map::finalize))
|
.add_systems(OnEnter(View::InGame), map::finalize)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
OnExit(View::InGame),
|
OnExit(View::InGame),
|
||||||
(player::exit, statue::exit, map::exit),
|
(player::exit, statue::exit, map::exit),
|
||||||
|
|
26
src/map.rs
26
src/map.rs
|
@ -18,7 +18,7 @@ pub struct Tilemap;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct MapGenTask(Task<CommandQueue>);
|
struct MapGenTask(Task<CommandQueue>);
|
||||||
|
|
||||||
#[derive(Resource, Deref)]
|
#[derive(Resource, Deref, DerefMut)]
|
||||||
struct TileStorageHandle(TileStorage);
|
struct TileStorageHandle(TileStorage);
|
||||||
|
|
||||||
pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
|
@ -41,8 +41,7 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
let task = pool.spawn(async move {
|
let task = pool.spawn(async move {
|
||||||
let mut command_queue = CommandQueue::default();
|
let mut command_queue = CommandQueue::default();
|
||||||
command_queue.push(move |world: &mut World| {
|
command_queue.push(move |world: &mut World| {
|
||||||
let mut state = SystemState::<Res<TileStorageHandle>>::new(world);
|
let mut state = SystemState::<ResMut<TileStorageHandle>>::new(world);
|
||||||
let storage = state.get_mut(world);
|
|
||||||
let entity = world
|
let entity = world
|
||||||
.spawn((
|
.spawn((
|
||||||
HideFromInspector,
|
HideFromInspector,
|
||||||
|
@ -54,10 +53,13 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
|
let mut storage = state.get_mut(world);
|
||||||
storage.set(&position, entity);
|
storage.set(&position, entity);
|
||||||
});
|
});
|
||||||
command_queue
|
command_queue
|
||||||
});
|
});
|
||||||
|
commands.entity(tilemap).insert(MapGenTask(task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,19 +75,25 @@ fn load(mut commands: Commands, mut tasks: Query<&mut MapGenTask>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalize(
|
pub fn finalize(
|
||||||
mut commands: Commands,
|
// mut commands: Commands,
|
||||||
mut storage: Res<TileStorageHandle>,
|
// mut storage: Res<TileStorageHandle>,
|
||||||
tilemap: Query<Entity, With<Tilemap>>,
|
// tilemap: Query<Entity, With<Tilemap>>,
|
||||||
assets: Res<AssetServer>,
|
// assets: Res<AssetServer>,
|
||||||
|
world: &mut World,
|
||||||
) {
|
) {
|
||||||
|
let storage = world.remove_resource::<TileStorageHandle>().unwrap();
|
||||||
|
|
||||||
// TODO: dedupe with load
|
// TODO: dedupe with load
|
||||||
let size = TilemapSize::new(1024, 1024);
|
let size = TilemapSize::new(1024, 1024);
|
||||||
let texture = TilemapTexture::Single(assets.load("img/Tileset Grass.png"));
|
|
||||||
let tile_size = TilemapTileSize::new(16., 16.);
|
let tile_size = TilemapTileSize::new(16., 16.);
|
||||||
let grid_size = TilemapGridSize::new(16., 16.);
|
let grid_size = TilemapGridSize::new(16., 16.);
|
||||||
let map_type = TilemapType::Square;
|
let map_type = TilemapType::Square;
|
||||||
let storage = storage.0;
|
let storage = storage.0;
|
||||||
let tilemap = tilemap.single();
|
let mut query = world.query_filtered::<Entity, With<Tilemap>>();
|
||||||
|
let tilemap = query.single(world);
|
||||||
|
let assets = world.resource::<AssetServer>();
|
||||||
|
let texture = TilemapTexture::Single(assets.load("img/Tileset Grass.png"));
|
||||||
|
let mut commands = world.commands();
|
||||||
commands.entity(tilemap).insert(TilemapBundle {
|
commands.entity(tilemap).insert(TilemapBundle {
|
||||||
grid_size,
|
grid_size,
|
||||||
map_type,
|
map_type,
|
||||||
|
|
Loading…
Reference in a new issue