Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Oct 30, 2023
1 parent 69587e7 commit 624c4a9
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 179 deletions.
11 changes: 5 additions & 6 deletions src/star_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy::prelude::{Camera, Children, Component, in_state, IntoSystemConfigs, Pa
use bevy::scene::SceneInstance;

use crate::body::Star;
use crate::camera::PanOrbitCamera;
use crate::SimState;

const STAR_IMPOSTER_THRESHOLD: f32 = 4_000.0;
Expand All @@ -25,13 +24,13 @@ impl Plugin for StarRendererPlugin {
pub struct StarBillboard;

fn change_sun_renderer(
camera: Query<(&Transform, &PanOrbitCamera, &Camera, Without<Star>, Without<StarBillboard>)>,
mut stars: Query<(&Transform, &Children, &mut Star, Without<Camera>, Without<StarBillboard>)>,
camera: Query<(&Transform, &Camera, Without<Star>, Without<StarBillboard>)>,
mut stars: Query<(&Transform, &Children, Without<Camera>, Without<StarBillboard>)>,
mut star_billboards: Query<(&mut Transform, &mut Visibility, &Parent, With<StarBillboard>, Without<Camera>, Without<Star>)>,
mut scenes: Query<(&SceneInstance, &mut Visibility, Without<StarBillboard>, Without<Star>)>,
) {
let (c_transform, pan_orbit, camera, _, _) = camera.single();
for (transform, children, mut star, _, _) in &mut stars {
let (c_transform, camera, _, _) = camera.single();
for (transform, children, _, _) in &mut stars {
let distance = c_transform.translation.distance(transform.translation);
for child in children.iter() {
if let Ok((_, mut visibility, _ , _)) = scenes.get_mut(*child) {
Expand All @@ -52,7 +51,7 @@ fn change_sun_renderer(
}

for (mut b_transform, _, parent, _, _, _) in &mut star_billboards {
let (transform, _, _, _, _) = stars.get(**parent).unwrap();
let (transform, _, _, _) = stars.get(**parent).unwrap();
let distance = c_transform.translation.distance(transform.translation);
b_transform.look_at(-c_transform.translation, Vec3::Y);
b_transform.scale = Vec3::splat(distance / STAR_IMPOSTER_DIVIDER);
Expand Down
Loading

0 comments on commit 624c4a9

Please sign in to comment.