mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add particle count to debug info
This commit is contained in:
parent
bb2a5c885b
commit
f9f9e9e190
@ -179,6 +179,7 @@ widget_ids! {
|
||||
entity_count,
|
||||
num_chunks,
|
||||
num_figures,
|
||||
num_particles,
|
||||
|
||||
// Game Version
|
||||
version,
|
||||
@ -247,6 +248,8 @@ pub struct DebugInfo {
|
||||
pub num_visible_chunks: u32,
|
||||
pub num_figures: u32,
|
||||
pub num_figures_visible: u32,
|
||||
pub num_particles: u32,
|
||||
pub num_particles_visible: u32,
|
||||
}
|
||||
|
||||
pub struct HudInfo {
|
||||
@ -1496,6 +1499,17 @@ impl Hud {
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.set(self.ids.num_figures, ui_widgets);
|
||||
|
||||
// Number of particles
|
||||
Text::new(&format!(
|
||||
"Particles: {} ({} visible)",
|
||||
debug_info.num_particles, debug_info.num_particles_visible,
|
||||
))
|
||||
.color(TEXT_COLOR)
|
||||
.down_from(self.ids.num_figures, 5.0)
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.set(self.ids.num_particles, ui_widgets);
|
||||
|
||||
// Help Window
|
||||
if let Some(help_key) = global_state.settings.controls.get_binding(GameInput::Help) {
|
||||
Text::new(
|
||||
@ -1505,7 +1519,7 @@ impl Hud {
|
||||
.replace("{key}", help_key.to_string().as_str()),
|
||||
)
|
||||
.color(TEXT_COLOR)
|
||||
.down_from(self.ids.num_figures, 5.0)
|
||||
.down_from(self.ids.num_particles, 5.0)
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.set(self.ids.help_info, ui_widgets);
|
||||
|
@ -435,8 +435,12 @@ impl Scene {
|
||||
scene_data.figure_lod_render_distance,
|
||||
);
|
||||
|
||||
self.particle_mgr
|
||||
.render(renderer, &self.globals, &self.lights, &self.shadows);
|
||||
self.particle_mgr.render(
|
||||
renderer,
|
||||
&self.globals,
|
||||
&self.lights,
|
||||
&self.shadows,
|
||||
);
|
||||
|
||||
// Render the skybox.
|
||||
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
|
||||
|
@ -20,12 +20,13 @@ use vek::Vec3;
|
||||
|
||||
struct Particles {
|
||||
alive_until: Instant, // created_at + lifespan
|
||||
instances: Instances<ParticleInstance>,
|
||||
instance: ParticleInstance,
|
||||
}
|
||||
|
||||
pub struct ParticleMgr {
|
||||
// keep track of lifespans
|
||||
particles: Vec<Particles>,
|
||||
instances: Instances<ParticleInstance>,
|
||||
model_cache: HashMap<&'static str, Model<ParticlePipeline>>,
|
||||
}
|
||||
|
||||
@ -54,21 +55,46 @@ impl ParticleMgr {
|
||||
model
|
||||
});
|
||||
|
||||
let insts = Vec::new();
|
||||
|
||||
let instances = renderer
|
||||
.create_instances(&insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
Self {
|
||||
particles: Vec::new(),
|
||||
instances,
|
||||
model_cache,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn particle_count(&self) -> usize { self.instances.count() }
|
||||
|
||||
pub fn particle_count_visible(&self) -> usize { self.instances.count() }
|
||||
|
||||
pub fn maintain(&mut self, renderer: &mut Renderer, scene_data: &SceneData) {
|
||||
let now = Instant::now();
|
||||
|
||||
// remove dead particles
|
||||
self.particles.retain(|p| p.alive_until > now);
|
||||
|
||||
// let zxc = scene_data.particle_render_distance;
|
||||
|
||||
self.maintain_body_particles(renderer, scene_data);
|
||||
|
||||
self.maintain_boost_particles(renderer, scene_data);
|
||||
|
||||
let all_cpu_instances = self
|
||||
.particles
|
||||
.iter()
|
||||
.map(|p| p.instance)
|
||||
.collect::<Vec<ParticleInstance>>();
|
||||
|
||||
// TODO: upload just the ones that were created and added to queue, not all of
|
||||
// them.
|
||||
self.instances = renderer
|
||||
.create_instances(&all_cpu_instances)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
}
|
||||
|
||||
fn maintain_body_particles(&mut self, renderer: &mut Renderer, scene_data: &SceneData) {
|
||||
@ -112,34 +138,14 @@ impl ParticleMgr {
|
||||
let now = Instant::now();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let fire_cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireFire,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(250),
|
||||
instances: renderer
|
||||
.create_instances(&fire_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!"),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
});
|
||||
|
||||
let smoke_cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
let smoke_cpu_insts = renderer
|
||||
.create_instances(&smoke_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(10),
|
||||
instances: smoke_cpu_insts,
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
}
|
||||
|
||||
@ -153,34 +159,14 @@ impl ParticleMgr {
|
||||
let now = Instant::now();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let fire_cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireFire,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(250),
|
||||
instances: renderer
|
||||
.create_instances(&fire_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!"),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
});
|
||||
|
||||
let smoke_cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
let smoke_cpu_insts = renderer
|
||||
.create_instances(&smoke_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(1),
|
||||
instances: smoke_cpu_insts,
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
}
|
||||
|
||||
@ -194,31 +180,28 @@ impl ParticleMgr {
|
||||
let now = Instant::now();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let fire_cpu_insts = vec![
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
];
|
||||
|
||||
// fire
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(250),
|
||||
instances: renderer
|
||||
.create_instances(&fire_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!"),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(250),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireFire, pos.0),
|
||||
});
|
||||
|
||||
let smoke_cpu_insts = vec![
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
];
|
||||
|
||||
let smoke_cpu_insts = renderer
|
||||
.create_instances(&smoke_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
// smoke
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(2),
|
||||
instances: smoke_cpu_insts,
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(2),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(2),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
}
|
||||
|
||||
@ -232,35 +215,32 @@ impl ParticleMgr {
|
||||
let now = Instant::now();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let fire_cpu_insts = vec![
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
];
|
||||
|
||||
// sparks
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(1500),
|
||||
instances: renderer
|
||||
.create_instances(&fire_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!"),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(1500),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(1500),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(1500),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
});
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_millis(1500),
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::GunPowderSpark, pos.0),
|
||||
});
|
||||
|
||||
let smoke_cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
let smoke_cpu_insts = renderer
|
||||
.create_instances(&smoke_cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
// smoke
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(2),
|
||||
instances: smoke_cpu_insts,
|
||||
instance: ParticleInstance::new(time, rng.gen(), ParticleMode::CampfireSmoke, pos.0),
|
||||
});
|
||||
}
|
||||
|
||||
@ -307,20 +287,14 @@ impl ParticleMgr {
|
||||
.enumerate()
|
||||
{
|
||||
if let CharacterState::Boost(_) = character_state {
|
||||
let cpu_insts = vec![ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0,
|
||||
)];
|
||||
|
||||
let gpu_insts = renderer
|
||||
.create_instances(&cpu_insts)
|
||||
.expect("Failed to upload particle instances to the GPU!");
|
||||
|
||||
self.particles.push(Particles {
|
||||
alive_until: now + Duration::from_secs(15),
|
||||
instances: gpu_insts,
|
||||
instance: ParticleInstance::new(
|
||||
time,
|
||||
rng.gen(),
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -338,8 +312,6 @@ impl ParticleMgr {
|
||||
.get(MODEL_KEY)
|
||||
.expect("Expected particle model in cache");
|
||||
|
||||
for particle in &self.particles {
|
||||
renderer.render_particles(model, globals, &particle.instances, lights, shadows);
|
||||
}
|
||||
renderer.render_particles(model, globals, &self.instances, lights, shadows);
|
||||
}
|
||||
}
|
||||
|
@ -689,6 +689,9 @@ impl PlayState for SessionState {
|
||||
num_visible_chunks: self.scene.terrain().visible_chunk_count() as u32,
|
||||
num_figures: self.scene.figure_mgr().figure_count() as u32,
|
||||
num_figures_visible: self.scene.figure_mgr().figure_count_visible() as u32,
|
||||
num_particles: self.scene.particle_mgr().particle_count() as u32,
|
||||
num_particles_visible: self.scene.particle_mgr().particle_count_visible()
|
||||
as u32,
|
||||
},
|
||||
&self.scene.camera(),
|
||||
global_state.clock.get_last_delta(),
|
||||
|
Loading…
Reference in New Issue
Block a user