switch to tuple in PaintList

This commit is contained in:
charburgx 2022-12-19 00:46:36 -06:00
parent 7894cd4dfd
commit 26c3fa22cb

View file

@ -230,21 +230,9 @@ impl ZLayer {
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub struct ShapeIdx(usize); pub struct ShapeIdx(usize);
#[derive(Clone, PartialEq)]
struct PaintedShape {
shape: ClippedShape,
z: ZOrder,
}
impl PaintedShape {
pub fn new(shape: ClippedShape, z: ZOrder) -> Self {
Self { shape, z }
}
}
/// A list of [`Shape`]s paired with a clip rectangle. /// A list of [`Shape`]s paired with a clip rectangle.
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PaintList(Vec<PaintedShape>); pub struct PaintList(Vec<(ZOrder, ClippedShape)>);
impl PaintList { impl PaintList {
#[inline(always)] #[inline(always)]
@ -256,8 +244,7 @@ impl PaintList {
#[inline(always)] #[inline(always)]
pub fn add(&mut self, clip_rect: Rect, shape: Shape, z: ZOrder) -> ShapeIdx { pub fn add(&mut self, clip_rect: Rect, shape: Shape, z: ZOrder) -> ShapeIdx {
let idx = ShapeIdx(self.0.len()); let idx = ShapeIdx(self.0.len());
self.0 self.0.push((z, ClippedShape(clip_rect, shape)));
.push(PaintedShape::new(ClippedShape(clip_rect, shape), z));
idx idx
} }
@ -265,7 +252,7 @@ impl PaintList {
self.0.extend( self.0.extend(
shapes shapes
.into_iter() .into_iter()
.map(|shape| PaintedShape::new(ClippedShape(clip_rect, shape), z)), .map(|shape| (z, ClippedShape(clip_rect, shape))),
); );
} }
@ -278,16 +265,12 @@ impl PaintList {
/// and then later setting it using `paint_list.set(idx, cr, frame);`. /// and then later setting it using `paint_list.set(idx, cr, frame);`.
#[inline(always)] #[inline(always)]
pub fn set(&mut self, idx: ShapeIdx, clip_rect: Rect, shape: Shape) { pub fn set(&mut self, idx: ShapeIdx, clip_rect: Rect, shape: Shape) {
self.0[idx.0].shape = ClippedShape(clip_rect, shape); self.0[idx.0].1 = ClippedShape(clip_rect, shape);
} }
/// Translate each [`Shape`] and clip rectangle by this much, in-place /// Translate each [`Shape`] and clip rectangle by this much, in-place
pub fn translate(&mut self, delta: Vec2) { pub fn translate(&mut self, delta: Vec2) {
for PaintedShape { for (_z, ClippedShape(clip_rect, shape)) in &mut self.0 {
shape: ClippedShape(clip_rect, shape),
..
} in &mut self.0
{
*clip_rect = clip_rect.translate(delta); *clip_rect = clip_rect.translate(delta);
shape.translate(delta); shape.translate(delta);
} }
@ -315,7 +298,7 @@ impl GraphicLayers {
// Sort by z-order // Sort by z-order
for list in order_map.values_mut() { for list in order_map.values_mut() {
list.0.sort_by_key(|PaintedShape { z, .. }| *z); list.0.sort_by_key(|(z, ..)| *z);
} }
// If a layer is empty at the start of the frame // If a layer is empty at the start of the frame
@ -338,8 +321,6 @@ impl GraphicLayers {
} }
} }
all_shapes all_shapes.into_iter().map(|(_z, shape)| shape)
.into_iter()
.map(|PaintedShape { shape, .. }| shape)
} }
} }