Skip to content

Commit a18e12e

Browse files
removed Wrap
1 parent cd8560c commit a18e12e

File tree

1 file changed

+42
-61
lines changed

1 file changed

+42
-61
lines changed

crates/bevy_gizmos/src/gizmos.rs

Lines changed: 42 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{f32::consts::TAU, iter};
55
use bevy_app::FixedUpdateScheduleIsCurrentlyRunning;
66
use bevy_ecs::{
77
component::Tick,
8-
system::{Resource, SystemBuffer, SystemMeta, SystemParam},
8+
system::{Resource, SystemMeta, SystemParam},
99
world::{unsafe_world_cell::UnsafeWorldCell, World},
1010
};
1111
use bevy_math::{Mat2, Quat, Vec2, Vec3};
@@ -35,79 +35,63 @@ pub(crate) struct GizmoStorage {
3535

3636
/// A [`SystemParam`](bevy_ecs::system::SystemParam) for drawing gizmos.
3737
pub struct Gizmos<'s> {
38-
buffer: &'s mut GizmoBuffer,
39-
}
40-
41-
#[derive(Default)]
42-
struct GizmoBuffer {
43-
/// Which fixed update tick this belongs to, `None` if this isn't from a fixed update.
44-
fixed_time_update: Option<u64>,
45-
list_positions: Vec<PositionItem>,
46-
list_colors: Vec<ColorItem>,
47-
strip_positions: Vec<PositionItem>,
48-
strip_colors: Vec<ColorItem>,
49-
}
50-
51-
impl SystemBuffer for GizmoBuffer {
52-
fn apply(&mut self, _system_meta: &SystemMeta, world: &mut World) {
53-
let mut storages = world.resource_mut::<GizmoStorages>();
54-
55-
let storage = if let Some(tick) = self.fixed_time_update {
56-
// If a new fixed update has begun, clear gizmos from previous fixed update
57-
if storages.fixed_update_tick < tick {
58-
storages.fixed_update_tick = tick;
59-
storages.fixed_update.list_positions.clear();
60-
storages.fixed_update.list_colors.clear();
61-
storages.fixed_update.strip_positions.clear();
62-
storages.fixed_update.strip_colors.clear();
63-
}
64-
&mut storages.fixed_update
65-
} else {
66-
&mut storages.frame
67-
};
68-
69-
storage.list_positions.append(&mut self.list_positions);
70-
storage.list_colors.append(&mut self.list_colors);
71-
storage.strip_positions.append(&mut self.strip_positions);
72-
storage.strip_colors.append(&mut self.strip_colors);
73-
}
38+
buffer: &'s mut <Self as SystemParam>::State,
7439
}
7540

7641
// Wrap to keep GizmoBuffer hidden
7742
const _: () = {
78-
pub struct Wrap(GizmoBuffer);
43+
#[derive(Default)]
44+
pub struct GizmoBuffer {
45+
/// Which fixed update tick this belongs to, `None` if this isn't from a fixed update.
46+
fixed_time_update: Option<u64>,
47+
list_positions: Vec<PositionItem>,
48+
list_colors: Vec<ColorItem>,
49+
strip_positions: Vec<PositionItem>,
50+
strip_colors: Vec<ColorItem>,
51+
}
7952

8053
// SAFETY: Only local state is accessed.
8154
unsafe impl SystemParam for Gizmos<'_> {
82-
type State = Wrap;
55+
type State = GizmoBuffer;
8356
type Item<'w, 's> = Gizmos<'s>;
8457

85-
fn init_state(world: &mut World, _system_meta: &mut SystemMeta) -> Self::State {
86-
let fixed_time_update = world
87-
.get_resource::<FixedUpdateScheduleIsCurrentlyRunning>()
88-
.map(|current| current.update);
89-
Wrap(GizmoBuffer {
90-
fixed_time_update,
91-
list_positions: default(),
92-
list_colors: default(),
93-
strip_positions: default(),
94-
strip_colors: default(),
95-
})
58+
fn init_state(_: &mut World, _system_meta: &mut SystemMeta) -> Self::State {
59+
default()
9660
}
9761

98-
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World) {
99-
state.0.apply(system_meta, world);
62+
fn apply(state: &mut Self::State, _system_meta: &SystemMeta, world: &mut World) {
63+
let mut storages = world.resource_mut::<GizmoStorages>();
64+
65+
let storage = if let Some(tick) = state.fixed_time_update {
66+
// If a new fixed update has begun, clear gizmos from previous fixed update
67+
if storages.fixed_update_tick < tick {
68+
storages.fixed_update_tick = tick;
69+
storages.fixed_update.list_positions.clear();
70+
storages.fixed_update.list_colors.clear();
71+
storages.fixed_update.strip_positions.clear();
72+
storages.fixed_update.strip_colors.clear();
73+
}
74+
&mut storages.fixed_update
75+
} else {
76+
&mut storages.frame
77+
};
78+
79+
storage.list_positions.append(&mut state.list_positions);
80+
storage.list_colors.append(&mut state.list_colors);
81+
storage.strip_positions.append(&mut state.strip_positions);
82+
storage.strip_colors.append(&mut state.strip_colors);
10083
}
10184

10285
unsafe fn get_param<'w, 's>(
10386
state: &'s mut Self::State,
10487
_system_meta: &SystemMeta,
105-
_world: UnsafeWorldCell<'w>,
88+
world: UnsafeWorldCell<'w>,
10689
_change_tick: Tick,
10790
) -> Self::Item<'w, 's> {
108-
Gizmos {
109-
buffer: &mut state.0,
110-
}
91+
state.fixed_time_update = world
92+
.get_resource::<FixedUpdateScheduleIsCurrentlyRunning>()
93+
.map(|current| current.update);
94+
Gizmos { buffer: state }
11195
}
11296
}
11397
};
@@ -231,11 +215,8 @@ impl<'s> Gizmos<'s> {
231215
pub fn linestrip_gradient(&mut self, points: impl IntoIterator<Item = (Vec3, Color)>) {
232216
let points = points.into_iter();
233217

234-
let GizmoBuffer {
235-
strip_positions,
236-
strip_colors,
237-
..
238-
} = &mut *self.buffer;
218+
let strip_positions = &mut self.buffer.strip_positions;
219+
let strip_colors = &mut self.buffer.strip_colors;
239220

240221
let (min, _) = points.size_hint();
241222
strip_positions.reserve(min);

0 commit comments

Comments
 (0)