faster asteroid loading... maybe

This commit is contained in:
yuni 2024-04-07 18:35:19 +02:00
parent 8ef538bac3
commit f19f343f54

View file

@ -70,6 +70,8 @@ impl Plugin for WorldPlugin {
#[derive(Resource)] struct AsteroidUpdateTimer(Timer);
#[derive(Resource)] struct AsteroidDatabase(Vec<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)] pub struct DespawnOnPlayerDeath;
@ -112,7 +114,12 @@ pub fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
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
let sphere_handle = meshes.add(Sphere::new(1.0));
let mut starcount = 0;
@ -186,7 +193,8 @@ fn spawn_despawn_asteroids(
q_player: Query<&Position, With<actor::PlayerCamera>>,
mut ew_despawn: EventWriter<DespawnEvent>,
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 last_player_cell: Local<I64Vec3>,
) {
@ -316,12 +324,12 @@ fn spawn_despawn_asteroids(
Position::new(pos),
Asteroid,
));
let asset = match class {
0 => ASSET_ASTEROID1,
_ => ASSET_ASTEROID2,
let model = match class {
0 => asteroid1_handle.0.clone(),
_ => asteroid2_handle.0.clone(),
};
entity_commands.insert(SceneBundle {
scene: asset_server.load(asset),
scene: model,
transform: Transform {
scale: Vec3::splat(size),
..default()