Stopping for now
This commit is contained in:
parent
d289460ced
commit
deabad05ee
|
@ -141,6 +141,7 @@ fn load_menu(mut app_state: ResMut<NextState<View>>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_game(mut app_state: ResMut<NextState<View>>) {
|
fn load_game(mut app_state: ResMut<NextState<View>>) {
|
||||||
|
// need to check if the map is fully loaded before switching
|
||||||
app_state.set(View::InGame);
|
app_state.set(View::InGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
45
src/map.rs
45
src/map.rs
|
@ -1,4 +1,8 @@
|
||||||
use crate::{inspector::HideFromInspector, prelude::*};
|
use crate::{inspector::HideFromInspector, prelude::*};
|
||||||
|
use bevy::{
|
||||||
|
ecs::world::CommandQueue,
|
||||||
|
tasks::{block_on, futures_lite::future, AsyncComputeTaskPool, Task},
|
||||||
|
};
|
||||||
// use bevy::{
|
// use bevy::{
|
||||||
// ecs::world::CommandQueue,
|
// ecs::world::CommandQueue,
|
||||||
// tasks::{AsyncComputeTaskPool, Task},
|
// tasks::{AsyncComputeTaskPool, Task},
|
||||||
|
@ -7,18 +11,16 @@ use bevy_ecs_tilemap::prelude::*;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand_pcg::Pcg64;
|
use rand_pcg::Pcg64;
|
||||||
use rand_seeder::Seeder;
|
use rand_seeder::Seeder;
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct Tilemap;
|
pub struct Tilemap;
|
||||||
|
|
||||||
// #[derive(Component)]
|
#[derive(Component)]
|
||||||
// struct MapGen(Task<CommandQueue>);
|
struct MapGen(Task<TileBundleBuilder>);
|
||||||
|
|
||||||
pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
// TODO: I'm pretty determined to not have this sieze up the game. Should work with a "loading" screen.
|
// TODO: I'm pretty determined to not have this sieze up the game despite the large number of entities being added. Should work with a "loading" screen and doing this in the background?
|
||||||
// let task_pool = AsyncComputeTaskPool::get();
|
|
||||||
|
|
||||||
// let task = task_pool.spawn(async move {});
|
|
||||||
|
|
||||||
let mut rng: Pcg64 = Seeder::from("default_seed").make_rng();
|
let mut rng: Pcg64 = Seeder::from("default_seed").make_rng();
|
||||||
let size = TilemapSize::new(1024, 1024);
|
let size = TilemapSize::new(1024, 1024);
|
||||||
|
@ -27,6 +29,11 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
let mut storage = TileStorage::empty(size);
|
let mut storage = TileStorage::empty(size);
|
||||||
// let mutex_storage = Mutex::new(storage);
|
// let mutex_storage = Mutex::new(storage);
|
||||||
|
|
||||||
|
let task_pool = AsyncComputeTaskPool::get();
|
||||||
|
|
||||||
|
let (tx, rx) = channel::<TileBundle>();
|
||||||
|
let tilebundlegenerator = task_pool.spawn(async move {
|
||||||
|
// this task is for generating tilebundles
|
||||||
for x in 0..size.x {
|
for x in 0..size.x {
|
||||||
for y in 0..size.y {
|
for y in 0..size.y {
|
||||||
let position = TilePos::new(x, y);
|
let position = TilePos::new(x, y);
|
||||||
|
@ -35,17 +42,19 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
});
|
});
|
||||||
let tile = commands
|
tx.send(TileBundle {
|
||||||
.spawn((
|
|
||||||
HideFromInspector,
|
|
||||||
TileBundle {
|
|
||||||
position,
|
position,
|
||||||
tilemap_id: TilemapId(tilemap),
|
tilemap_id: TilemapId(tilemap),
|
||||||
texture_index,
|
texture_index,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
});
|
||||||
))
|
}
|
||||||
.id();
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for x in 0..size.x {
|
||||||
|
for y in 0..size.y {
|
||||||
|
let tile = commands.spawn().id();
|
||||||
storage.set(&position, tile);
|
storage.set(&position, tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +142,16 @@ pub fn spawn(mut commands: Commands, assets: Res<AssetServer>) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
fn load(mut commands: Commands, mut tasks: Query<&mut MapGen>) {
|
||||||
|
// to avoid locking up the universe we only want to handle a certain number per iteration (Update)
|
||||||
|
for mut task in &mut tasks {
|
||||||
|
if let Some(mut commands_queue) = block_on(future::poll_once(&mut task.0)) {
|
||||||
|
// append the returned command queue to have it execute later
|
||||||
|
commands.append(&mut commands_queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn exit(mut commands: Commands, q: Query<Entity, With<Tilemap>>) {
|
pub fn exit(mut commands: Commands, q: Query<Entity, With<Tilemap>>) {
|
||||||
for id in q.iter() {
|
for id in q.iter() {
|
||||||
commands.entity(id).despawn_recursive();
|
commands.entity(id).despawn_recursive();
|
||||||
|
|
Loading…
Reference in a new issue