faster asteroid loading... maybe
This commit is contained in:
parent
8ef538bac3
commit
f19f343f54
18
src/world.rs
18
src/world.rs
|
@ -70,6 +70,8 @@ impl Plugin for WorldPlugin {
|
||||||
#[derive(Resource)] struct AsteroidUpdateTimer(Timer);
|
#[derive(Resource)] struct AsteroidUpdateTimer(Timer);
|
||||||
#[derive(Resource)] struct AsteroidDatabase(Vec<AsteroidData>);
|
#[derive(Resource)] struct AsteroidDatabase(Vec<AsteroidData>);
|
||||||
#[derive(Resource)] struct ActiveAsteroids(HashMap<I64Vec3, AsteroidData>);
|
#[derive(Resource)] struct ActiveAsteroids(HashMap<I64Vec3, AsteroidData>);
|
||||||
|
#[derive(Resource)] struct AsteroidModel1(Handle<Scene>);
|
||||||
|
#[derive(Resource)] struct AsteroidModel2(Handle<Scene>);
|
||||||
|
|
||||||
#[derive(Component)] struct Asteroid;
|
#[derive(Component)] struct Asteroid;
|
||||||
#[derive(Component)] pub struct DespawnOnPlayerDeath;
|
#[derive(Component)] pub struct DespawnOnPlayerDeath;
|
||||||
|
@ -112,7 +114,12 @@ pub fn setup(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut materials_custom: ResMut<Assets<RingMaterial>>,
|
mut materials_custom: ResMut<Assets<RingMaterial>>,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
|
// Load assets
|
||||||
|
commands.insert_resource(AsteroidModel1(asset_server.load(ASSET_ASTEROID1)));
|
||||||
|
commands.insert_resource(AsteroidModel2(asset_server.load(ASSET_ASTEROID2)));
|
||||||
|
|
||||||
// Generate starmap
|
// Generate starmap
|
||||||
let sphere_handle = meshes.add(Sphere::new(1.0));
|
let sphere_handle = meshes.add(Sphere::new(1.0));
|
||||||
let mut starcount = 0;
|
let mut starcount = 0;
|
||||||
|
@ -186,7 +193,8 @@ fn spawn_despawn_asteroids(
|
||||||
q_player: Query<&Position, With<actor::PlayerCamera>>,
|
q_player: Query<&Position, With<actor::PlayerCamera>>,
|
||||||
mut ew_despawn: EventWriter<DespawnEvent>,
|
mut ew_despawn: EventWriter<DespawnEvent>,
|
||||||
mut db: ResMut<ActiveAsteroids>,
|
mut db: ResMut<ActiveAsteroids>,
|
||||||
asset_server: Res<AssetServer>,
|
asteroid1_handle: Res<AsteroidModel1>,
|
||||||
|
asteroid2_handle: Res<AsteroidModel2>,
|
||||||
mut q_asteroid: Query<(Entity, &SceneInstance), With<Asteroid>>,
|
mut q_asteroid: Query<(Entity, &SceneInstance), With<Asteroid>>,
|
||||||
mut last_player_cell: Local<I64Vec3>,
|
mut last_player_cell: Local<I64Vec3>,
|
||||||
) {
|
) {
|
||||||
|
@ -316,12 +324,12 @@ fn spawn_despawn_asteroids(
|
||||||
Position::new(pos),
|
Position::new(pos),
|
||||||
Asteroid,
|
Asteroid,
|
||||||
));
|
));
|
||||||
let asset = match class {
|
let model = match class {
|
||||||
0 => ASSET_ASTEROID1,
|
0 => asteroid1_handle.0.clone(),
|
||||||
_ => ASSET_ASTEROID2,
|
_ => asteroid2_handle.0.clone(),
|
||||||
};
|
};
|
||||||
entity_commands.insert(SceneBundle {
|
entity_commands.insert(SceneBundle {
|
||||||
scene: asset_server.load(asset),
|
scene: model,
|
||||||
transform: Transform {
|
transform: Transform {
|
||||||
scale: Vec3::splat(size),
|
scale: Vec3::splat(size),
|
||||||
..default()
|
..default()
|
||||||
|
|
Loading…
Reference in a new issue