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