-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
settings.rs
236 lines (224 loc) · 8.2 KB
/
settings.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//! This example shows how to customize the appearance of your Perf UIs.
use bevy::prelude::*;
use iyes_perf_ui::prelude::*;
use iyes_perf_ui::widgets::bar::{BarFillDirection, BarTextPosition};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// we want Bevy to measure these values for us:
.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin)
.add_plugins(PerfUiPlugin)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, ass: Res<AssetServer>) {
// spawn a camera to be able to see anything
commands.spawn(Camera2d);
// Let's create multiple Perf UIs!
// Put common values in a variable so we don't repeat ourselves
let root_config = PerfUiRoot {
background_color: Color::srgba(0.9, 0.95, 0.99, 0.75),
inner_background_color: Color::srgba(0.05, 0.1, 0.15, 0.25),
inner_background_color_highlight: Color::srgba(1.0, 0.9, 0.25, 0.75),
text_err: "Unavailable!".into(),
err_color: Color::srgba(0.15, 0.07, 0.03, 0.25),
default_value_color: Color::srgb(0.4, 0.4, 0.4),
label_color: Color::srgb(0.3, 0.4, 0.5),
fontsize_label: 20.0,
fontsize_value: 24.0,
margin: 4.0,
padding: 2.0,
inner_margin: 2.0,
inner_padding: 4.0,
values_col_width: Some(128.0),
font_label: ass.load("Ubuntu-B.ttf"),
font_value: ass.load("Ubuntu-R.ttf"),
font_highlight: ass.load("Ubuntu-RI.ttf"),
..default()
};
// Perf UI #1: Framerate/Frametime
commands.spawn((
PerfUiRoot {
position: PerfUiPosition::TopLeft,
z_index: GlobalZIndex(i32::MAX),
..root_config.clone()
},
PerfUiEntryFPS {
// provide a custom label string
label: "Frame Rate (current)".into(),
// let's say we *really* care about high framerates‼
color_gradient: ColorGradient::new()
.with_stop(90.0, Color::srgb(0.8, 0.0, 0.2))
.with_stop(240.0, Color::srgb(0.2, 0.9, 0.4)),
threshold_highlight: Some(60.0),
digits: 5,
precision: 2,
..default()
},
PerfUiEntryFPSWorst {
label: "Frame Rate (worst)".into(),
color_gradient: ColorGradient::new()
.with_stop(90.0, Color::srgb(0.8, 0.0, 0.2))
.with_stop(240.0, Color::srgb(0.2, 0.9, 0.4)),
threshold_highlight: Some(60.0),
digits: 5,
precision: 2,
..default()
},
PerfUiEntryFrameTime {
label: "Frame Duration (current)".into(),
color_gradient: ColorGradient::new().with_stops([
(1.0, Color::srgb(0.15, 0.8, 0.9)),
(8.0, Color::srgb(0.7, 0.15, 0.9))
]),
threshold_highlight: Some(10.0),
digits: 2,
precision: 4,
..default()
},
PerfUiEntryFrameTimeWorst {
label: "Frame Duration (worst)".into(),
color_gradient: ColorGradient::new().with_stops([
(1.0, Color::srgb(0.15, 0.8, 0.9)),
(8.0, Color::srgb(0.7, 0.15, 0.9))
]),
threshold_highlight: Some(10.0),
digits: 2,
precision: 4,
..default()
},
));
// Perf UI #2: ECS stats + System CPU/RAM usage
// (displayed using fancy Bar widgets)
commands.spawn((
PerfUiRoot {
position: PerfUiPosition::BottomLeft,
// always display this Perf UI below the other one
z_index: GlobalZIndex(i32::MAX - 1),
..root_config.clone()
},
PerfUiWidgetBar {
fill_direction: BarFillDirection::Center,
bar_background: Color::srgba(0.0, 0.0, 0.0, 0.5),
// The color gradient also affects the range of values for the bar
bar_color: ColorGradient::new().with_stops([
(0.0, Color::BLACK),
(200.0, Color::WHITE),
]),
bar_border_color: Color::WHITE,
bar_border_px: 2.0,
..PerfUiWidgetBar::new(PerfUiEntryEntityCount {
label: "Number of ECS Entities".into(),
threshold_highlight: None,
color_gradient: ColorGradient::single(Color::BLACK),
digits: 4,
..default()
})
},
PerfUiWidgetBar {
text_position: BarTextPosition::OutsideEnd,
bar_background: Color::srgba(0.0, 0.0, 0.0, 0.5),
bar_color: ColorGradient::new().with_stops([
(0.0, Color::srgb(0.0, 0.0, 1.0)),
(100.0, Color::srgb(1.0, 0.0, 0.0)),
]),
bar_border_color: Color::WHITE,
bar_border_px: 2.0,
..PerfUiWidgetBar::new(PerfUiEntryCpuUsage {
label: "System CPU Utilization".into(),
color_gradient: ColorGradient::new().with_stops([
(0.0, Color::srgb(0.0, 0.0, 1.0)),
(100.0, Color::srgb(1.0, 0.0, 0.0)),
]),
threshold_highlight: None,
precision: 1,
..default()
})
},
PerfUiWidgetBar {
text_position: BarTextPosition::OutsideEnd,
bar_background: Color::srgba(0.0, 0.0, 0.0, 0.5),
bar_color: ColorGradient::new().with_stops([
(0.0, Color::srgb(0.0, 0.0, 1.0)),
(100.0, Color::srgb(1.0, 0.0, 0.0)),
]),
bar_border_color: Color::WHITE,
bar_border_px: 2.0,
..PerfUiWidgetBar::new(PerfUiEntryMemUsage {
label: "System RAM Utilization".into(),
color_gradient: ColorGradient::new().with_stops([
(0.0, Color::srgb(0.0, 0.0, 1.0)),
(100.0, Color::srgb(1.0, 0.0, 0.0)),
]),
threshold_highlight: None,
precision: 1,
..default()
})
},
));
// Perf UI #3: Clock + running time
commands.spawn((
PerfUiRoot {
// let's not have labels for this one
display_labels: false,
position: PerfUiPosition::BottomRight,
// always display this Perf UI below the other two
z_index: GlobalZIndex(i32::MAX - 2),
..root_config.clone()
},
PerfUiEntryRunningTime {
format_hms: true,
precision: 3,
sort_key: 1, // we can manually control the order of the entries
..default()
},
PerfUiEntryClock {
// always show time in UTC
prefer_utc: true,
precision: 1,
sort_key: 0, // we can manually control the order of the entries
..default()
},
));
// Perf UI #4: Cursor Position, Window Properties
commands.spawn((
PerfUiRoot {
position: PerfUiPosition::TopRight,
// always display this Perf UI below the other three
z_index: GlobalZIndex(i32::MAX - 3),
..root_config.clone()
},
PerfUiEntryCursorPosition {
label: "Mouse".into(),
separator: "\n",
width: 0, // no padding with spaces
display_units: true,
display_axis: false,
physical_pixels: true,
..default()
},
PerfUiEntryWindowResolution {
label: "Window Size".into(),
separator: "\n",
width: 0, // no padding with spaces
display_units: true,
display_axis: false,
physical_pixels: true,
..default()
},
PerfUiEntryWindowScaleFactor {
label: "Window Scaling Factor".into(),
..default()
},
PerfUiEntryWindowMode {
label: "Mode".into(),
..default()
},
PerfUiEntryWindowPresentMode {
label: "VSync".into(),
..default()
},
));
}