Fixed particles
parent
7b1e14defd
commit
5015040226
|
@ -649,6 +649,7 @@ dependencies = [
|
|||
"galactica-systemsim",
|
||||
"galactica-util",
|
||||
"pollster",
|
||||
"rand",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
|
|
@ -28,6 +28,7 @@ galactica-systemsim = { workspace = true }
|
|||
galactica-galaxy = { workspace = true }
|
||||
galactica-playeragent = { workspace = true }
|
||||
|
||||
rand = { workspace = true }
|
||||
winit = { workspace = true }
|
||||
wgpu = { workspace = true }
|
||||
pollster = { workspace = true }
|
||||
|
|
|
@ -4,6 +4,7 @@ use galactica_galaxy::{ship::ShipPersonality, Galaxy, GxShipHandle};
|
|||
use galactica_playeragent::PlayerAgent;
|
||||
use galactica_systemsim::{ParticleBuilder, StepResources, SystemSim, Wrapper};
|
||||
use galactica_util::timing::Timing;
|
||||
use rand::seq::SliceRandom;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -26,6 +27,10 @@ pub struct Game {
|
|||
wrapper: Wrapper, // Physics computer
|
||||
time_scale: f32,
|
||||
last_update: Instant,
|
||||
|
||||
/// Particles to create this frame.
|
||||
/// Must be cleared at the start of every frame
|
||||
/// TODO: better way to handle this?
|
||||
new_particles: Vec<ParticleBuilder>,
|
||||
}
|
||||
|
||||
|
@ -107,9 +112,14 @@ impl<'a> Game {
|
|||
&self.state
|
||||
}
|
||||
|
||||
pub fn get_particles(&self) -> &Vec<ParticleBuilder> {
|
||||
&self.new_particles
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
self.state.timing.start_frame();
|
||||
let t: f32 = self.last_update.elapsed().as_secs_f32() * self.time_scale;
|
||||
self.new_particles.clear();
|
||||
|
||||
self.state.timing.start_galaxy();
|
||||
self.state.gx.step(t);
|
||||
|
@ -125,6 +135,7 @@ impl<'a> Game {
|
|||
});
|
||||
|
||||
self.last_update = Instant::now();
|
||||
self.new_particles.shuffle(&mut rand::thread_rng());
|
||||
self.state.timing.mark_frame();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,8 +55,7 @@ fn main() -> Result<()> {
|
|||
current_time: game.get_state().start_instant.elapsed().as_secs_f32(),
|
||||
ct: &content,
|
||||
systemsim: &game.get_state().systemsim,
|
||||
particles: &mut Vec::new(),
|
||||
//particles: &mut self.new_particles,
|
||||
particles: game.get_particles(),
|
||||
player_data: player.ship.unwrap(),
|
||||
gx: &game.get_state().gx,
|
||||
current_system: SystemHandle { index: 0 },
|
||||
|
|
|
@ -38,7 +38,7 @@ pub struct RenderInput<'a> {
|
|||
pub gx: &'a Galaxy,
|
||||
|
||||
/// Particles to spawn during this frame
|
||||
pub particles: &'a mut Vec<ParticleBuilder>,
|
||||
pub particles: &'a Vec<ParticleBuilder>,
|
||||
|
||||
/// Time we spent in each part of the game loop
|
||||
pub timing: Timing,
|
||||
|
|
|
@ -3,7 +3,6 @@ use bytemuck;
|
|||
use cgmath::Point2;
|
||||
use galactica_util::constants::PARTICLE_SPRITE_INSTANCE_LIMIT;
|
||||
use glyphon::Resolution;
|
||||
use rand::seq::SliceRandom;
|
||||
use std::iter;
|
||||
use wgpu;
|
||||
|
||||
|
@ -81,7 +80,6 @@ impl super::GPUState {
|
|||
);
|
||||
|
||||
// Write all new particles to GPU buffer
|
||||
input.particles.shuffle(&mut rand::thread_rng());
|
||||
for i in input.particles.iter() {
|
||||
self.state.queue.write_buffer(
|
||||
&self.state.vertex_buffers.particle.instances,
|
||||
|
@ -103,7 +101,6 @@ impl super::GPUState {
|
|||
self.state.vertex_buffers.particle_counter = 0;
|
||||
}
|
||||
}
|
||||
input.particles.clear();
|
||||
|
||||
// Create sprite instances
|
||||
|
||||
|
|
Loading…
Reference in New Issue