Fix a possible bug
ci/woodpecker/push/build Pipeline was successful
Details
ci/woodpecker/push/build Pipeline was successful
Details
This commit is contained in:
parent
65467c5032
commit
e23d4dc731
|
@ -16,8 +16,12 @@ pub struct LightBuffer<U: Default + bytemuck::Pod + bytemuck::Zeroable> {
|
||||||
_phantom: PhantomData<U>,
|
_phantom: PhantomData<U>,
|
||||||
/// The max amount of light casters that could fit in this buffer.
|
/// The max amount of light casters that could fit in this buffer.
|
||||||
pub max_count: usize,
|
pub max_count: usize,
|
||||||
/// The current amount of light casters in this buffer.
|
/// The amount of light casters that are taking up space in the buffer.
|
||||||
pub current_count: usize,
|
///
|
||||||
|
/// This means that a light may be inactive in the buffer, by being replaced
|
||||||
|
/// with a default caster as to not affect lighting. Its easier this way than
|
||||||
|
/// to recreate the array and remove the gaps.
|
||||||
|
pub buffer_count: usize,
|
||||||
/// The buffer index for a specific entity/caster.
|
/// The buffer index for a specific entity/caster.
|
||||||
used_indexes: HashMap<edict::EntityId, usize>,
|
used_indexes: HashMap<edict::EntityId, usize>,
|
||||||
/// Indexes that were being used but are no longer needed.
|
/// Indexes that were being used but are no longer needed.
|
||||||
|
@ -29,7 +33,7 @@ impl<U: Default + bytemuck::Pod + bytemuck::Zeroable> LightBuffer<U> {
|
||||||
Self {
|
Self {
|
||||||
_phantom: PhantomData::default(),
|
_phantom: PhantomData::default(),
|
||||||
max_count,
|
max_count,
|
||||||
current_count: 0,
|
buffer_count: 0,
|
||||||
used_indexes: HashMap::new(),
|
used_indexes: HashMap::new(),
|
||||||
dead_indexes: VecDeque::new(),
|
dead_indexes: VecDeque::new(),
|
||||||
}
|
}
|
||||||
|
@ -52,8 +56,13 @@ impl<U: Default + bytemuck::Pod + bytemuck::Zeroable> LightBuffer<U> {
|
||||||
let buffer_idx = match self.dead_indexes.pop_front() {
|
let buffer_idx = match self.dead_indexes.pop_front() {
|
||||||
Some(i) => i,
|
Some(i) => i,
|
||||||
None => {
|
None => {
|
||||||
let i = self.current_count;
|
let i = self.buffer_count;
|
||||||
self.current_count += 1;
|
self.buffer_count += 1;
|
||||||
|
|
||||||
|
// If this assert triggers, you are hitting trying to exceed
|
||||||
|
// the max amount of lights
|
||||||
|
assert!(self.buffer_count <= self.max_count);
|
||||||
|
|
||||||
i
|
i
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -75,7 +84,7 @@ impl<U: Default + bytemuck::Pod + bytemuck::Zeroable> LightBuffer<U> {
|
||||||
pub fn remove_light(&mut self, lights_buffer: &mut [U; MAX_LIGHT_COUNT], entity: edict::EntityId) -> bool {
|
pub fn remove_light(&mut self, lights_buffer: &mut [U; MAX_LIGHT_COUNT], entity: edict::EntityId) -> bool {
|
||||||
if let Some(removed_idx) = self.used_indexes.remove(&entity) {
|
if let Some(removed_idx) = self.used_indexes.remove(&entity) {
|
||||||
self.dead_indexes.push_back(removed_idx);
|
self.dead_indexes.push_back(removed_idx);
|
||||||
self.current_count -= 1;
|
//self.current_count -= 1;
|
||||||
lights_buffer[removed_idx] = U::default();
|
lights_buffer[removed_idx] = U::default();
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -99,7 +108,7 @@ impl LightUniformBuffers {
|
||||||
&wgpu::BufferDescriptor {
|
&wgpu::BufferDescriptor {
|
||||||
label: Some("Lights Uniform buffer"),
|
label: Some("Lights Uniform buffer"),
|
||||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
size: mem::size_of::<LightsUniform>() as u64,
|
size: (mem::size_of::<LightsUniform>() * MAX_LIGHT_COUNT) as u64,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -129,7 +138,7 @@ impl LightUniformBuffers {
|
||||||
wgpu::BufferBinding {
|
wgpu::BufferBinding {
|
||||||
buffer: &buffer,
|
buffer: &buffer,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
size: Some(NonZeroU64::new(mem::size_of::<LightsUniform>() as u64).unwrap())
|
size: None, // use the full buffer
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -158,7 +167,7 @@ impl LightUniformBuffers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.lights_uniform.point_light_count = self.point_lights.current_count as u32;
|
self.lights_uniform.point_light_count = self.point_lights.buffer_count as u32;
|
||||||
queue.write_buffer(&self.buffer, 0, bytemuck::cast_slice(&[self.lights_uniform]));
|
queue.write_buffer(&self.buffer, 0, bytemuck::cast_slice(&[self.lights_uniform]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue