Remove resources created by entities after they die
This commit is contained in:
parent
ef4426a991
commit
25aff0cc1f
|
@ -1,5 +1,5 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::collections::{HashMap, VecDeque, HashSet};
|
||||
use std::mem;
|
||||
use std::num::NonZeroU64;
|
||||
use std::sync::Arc;
|
||||
|
@ -551,13 +551,16 @@ impl BasicRenderer {
|
|||
impl Renderer for BasicRenderer {
|
||||
fn prepare(&mut self, main_world: &mut edict::World) {
|
||||
let last_epoch = main_world.epoch();
|
||||
// render_limits.max_uniform_buffer_binding_size
|
||||
|
||||
let mut alive_entities = HashSet::new();
|
||||
|
||||
for (entity, model, model_epoch, transform) in main_world.query::<(Entities, &MeshComponent, EpochOf<MeshComponent>, &TransformComponent)>().iter() {
|
||||
// Create the render job and push it to the queue
|
||||
let job = RenderJob::new(model.mesh.clone(), model.material.clone(), entity, transform.transform, None);
|
||||
self.render_jobs.push_back(job);
|
||||
|
||||
// TODO: Delete dead entites from buffer_storage
|
||||
alive_entities.insert(entity);
|
||||
|
||||
if self.buffer_storage.get(&entity).is_none() {
|
||||
// check if the transform buffers need to be expanded
|
||||
if self.transform_buffers.should_expand() {
|
||||
|
@ -586,6 +589,12 @@ impl Renderer for BasicRenderer {
|
|||
// collect dead entities
|
||||
self.transform_buffers.tick();
|
||||
|
||||
// when buffer storage length does not match the amount of iterated entities,
|
||||
// remove all dead entities, and their buffers, if they weren't iterated over
|
||||
if self.buffer_storage.len() != alive_entities.len() {
|
||||
self.buffer_storage.retain(|e, _| alive_entities.contains(e));
|
||||
}
|
||||
|
||||
if let Some(camera) = main_world.query_mut::<(&mut CameraComponent,)>().into_iter().next() {
|
||||
let view_proj = self.inuse_camera.update_view_projection(camera);
|
||||
self.queue.write_buffer(&self.camera_buffer, 0, bytemuck::cast_slice(&[view_proj.clone()]));
|
||||
|
|
Loading…
Reference in New Issue