/
settings.rs
196 lines (184 loc) · 6.4 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
//! This example shows how to customize the appearance of your Perf UIs.
use bevy::prelude::*;
use iyes_perf_ui::prelude::*;
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(Camera2dBundle::default());
// 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::WHITE.with_a(0.75),
inner_background_color: Color::BLACK.with_a(0.25),
inner_background_color_highlight: Color::YELLOW.with_a(0.75),
text_err: "Unavailable!".into(),
err_color: Color::BLACK.with_a(0.25),
default_value_color: Color::DARK_GRAY,
label_color: Color::GRAY,
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: ZIndex::Global(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::RED)
.with_stop(240.0, Color::DARK_GREEN),
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::RED)
.with_stop(240.0, Color::DARK_GREEN),
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::CYAN), (8.0, Color::PURPLE)]),
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::CYAN), (8.0, Color::PURPLE)]),
threshold_highlight: Some(10.0),
digits: 2,
precision: 4,
..default()
},
));
// Perf UI #2: ECS stats + System CPU/RAM usage
commands.spawn((
PerfUiRoot {
position: PerfUiPosition::BottomLeft,
// always display this Perf UI below the other one
z_index: ZIndex::Global(i32::MAX - 1),
..root_config.clone()
},
PerfUiEntryEntityCount {
label: "Number of ECS Entities".into(),
// disable color and highlighting for this one
color_gradient: ColorGradient::default(),
threshold_highlight: None,
digits: 4,
..default()
},
PerfUiEntryCpuUsage {
label: "System CPU Utilization".into(),
color_gradient: ColorGradient::new()
.with_stops([(0.0, Color::BLUE), (100.0, Color::RED)]),
threshold_highlight: None,
precision: 1,
..default()
},
PerfUiEntryMemUsage {
label: "System RAM Utilization".into(),
color_gradient: ColorGradient::new()
.with_stops([(0.0, Color::BLUE), (100.0, Color::RED)]),
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: ZIndex::Global(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: ZIndex::Global(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()
},
));
}