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
2 changed files with 18 additions and 10 deletions
|
@ -102,7 +102,7 @@ fn main() -> AppExit {
|
|||
OnEnter(View::LoadingGame),
|
||||
(player::startup, statue::startup, map::spawn),
|
||||
)
|
||||
.add_systems(OnEnter(View::InGame), (map::finalize))
|
||||
.add_systems(OnEnter(View::InGame), map::finalize)
|
||||
.add_systems(
|
||||
OnExit(View::InGame),
|
||||
(player::exit, statue::exit, map::exit),
|
||||
|
|
26
src/map.rs
26
src/map.rs
|
@ -18,7 +18,7 @@ pub struct Tilemap;
|
|||
#[derive(Component)]
|
||||
struct MapGenTask(Task<CommandQueue>);
|
||||
|
||||
#[derive(Resource, Deref)]
|
||||
#[derive(Resource, Deref, DerefMut)]
|
||||
struct TileStorageHandle(TileStorage);
|
||||
|
||||
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 mut command_queue = CommandQueue::default();
|
||||
command_queue.push(move |world: &mut World| {
|
||||
let mut state = SystemState::<Res<TileStorageHandle>>::new(world);
|
||||
let storage = state.get_mut(world);
|
||||
let mut state = SystemState::<ResMut<TileStorageHandle>>::new(world);
|
||||
let entity = world
|
||||
.spawn((
|
||||
HideFromInspector,
|
||||
|
@ -54,10 +53,13 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
|||
},
|
||||
))
|
||||
.id();
|
||||
|
||||
let mut storage = state.get_mut(world);
|
||||
storage.set(&position, entity);
|
||||
});
|
||||
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(
|
||||
mut commands: Commands,
|
||||
mut storage: Res<TileStorageHandle>,
|
||||
tilemap: Query<Entity, With<Tilemap>>,
|
||||
assets: Res<AssetServer>,
|
||||
// mut commands: Commands,
|
||||
// mut storage: Res<TileStorageHandle>,
|
||||
// tilemap: Query<Entity, With<Tilemap>>,
|
||||
// assets: Res<AssetServer>,
|
||||
world: &mut World,
|
||||
) {
|
||||
let storage = world.remove_resource::<TileStorageHandle>().unwrap();
|
||||
|
||||
// TODO: dedupe with load
|
||||
let size = TilemapSize::new(1024, 1024);
|
||||
let texture = TilemapTexture::Single(assets.load("img/Tileset Grass.png"));
|
||||
let tile_size = TilemapTileSize::new(16., 16.);
|
||||
let grid_size = TilemapGridSize::new(16., 16.);
|
||||
let map_type = TilemapType::Square;
|
||||
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 {
|
||||
grid_size,
|
||||
map_type,
|
||||
|
|
Loading…
Reference in a new issue