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
|
use egui::{Color32, Stroke, Ui, epaint::CircleShape};
use crate::{
Camera, Config, Diagnostics, Input,
content::materials::MaterialId,
sim::{rb_manager::DebugRenderMode, sim_manager::SimManager},
};
const DEBUG_RENDER_MODES: [(&str, DebugRenderMode); 6] = [
("Collider shapes", DebugRenderMode::COLLIDER_SHAPES),
("Collider AABBs", DebugRenderMode::COLLIDER_AABBS),
("Rigid body axes", DebugRenderMode::RIGID_BODY_AXES),
("Joints", DebugRenderMode::JOINTS),
("Contacts", DebugRenderMode::CONTACTS),
("Solver contacts", DebugRenderMode::SOLVER_CONTACTS),
];
pub fn draw_egui<'a>(
ui: &mut Ui,
config: &mut Config,
camera: &mut Camera,
diagnostics: &Diagnostics,
input: &Input,
sim: &SimManager,
) {
puffin::profile_function!();
ui.heading("Config");
ui.add(egui::Slider::new(&mut config.brush_radius, 1.0..=100.0).text("Brush radius"));
let material = config.brush_material.def();
// material combobox
egui::ComboBox::from_label("Select a brush material")
.selected_text(format!(
"Material: [{}, d={}]",
material.name, material.density,
))
.icon(move |ui, rect, _, _| {
ui.painter().add(egui::Shape::Circle(CircleShape {
center: rect.center(),
radius: rect.height() / 2.0,
stroke: Stroke::NONE,
fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
}));
})
.show_ui(ui, |ui| {
for material_id in MaterialId::ALL {
ui.selectable_value(
&mut config.brush_material,
material_id,
material_id.def().name,
);
}
});
let dropper_material = config.dropper_material.def();
egui::ComboBox::from_label("Select a dropper material")
.selected_text(format!(
"Material: [{}, d={}]",
dropper_material.name, dropper_material.density,
))
.icon(move |ui, rect, _, _| {
ui.painter().add(egui::Shape::Circle(CircleShape {
center: rect.center(),
radius: rect.height() / 2.0,
stroke: Stroke::NONE,
fill: Color32::from_rgb(
dropper_material.color.0,
dropper_material.color.1,
dropper_material.color.2,
),
}));
})
.show_ui(ui, |ui| {
for material_id in MaterialId::ALL {
ui.selectable_value(
&mut config.dropper_material,
material_id,
material_id.def().name,
);
}
});
ui.checkbox(&mut config.use_threading, "Use multithreading");
ui.checkbox(&mut config.cells_render, "Draw cells");
ui.checkbox(&mut config.debug_render, "Draw physics debug lines");
if config.debug_render {
ui.indent("debug_render_modes", |ui| {
for (name, flag) in DEBUG_RENDER_MODES {
let mut enabled = config.debug_render_mode.contains(flag);
if ui.checkbox(&mut enabled, name).changed() {
config.debug_render_mode.set(flag, enabled);
}
}
});
}
ui.label(format!("Real FPS: {}", diagnostics.fps));
ui.heading("Camera");
ui.add(egui::Slider::new(&mut camera.zoom, 0.0..=10.0).text("Zoom"));
ui.heading("Input");
input
.last_mouse_world_pos
.map(|p| ui.label(format!("Mouse (world): x,y=({x}, {y})", x = p.0, y = p.1,)));
if let Some(p) = input.last_mouse_chunk_pos {
ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,));
if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&p) {
ui.label(format!(
"Sleeping={}",
sim.cell_manager.chunks[chunk].sleeping
));
}
}
input
.last_mouse_local_pos
.map(|p| ui.label(format!("Mouse (local): x,y=({x}, {y})", x = p.0, y = p.1,)));
if let Some((x, y)) = input.last_mouse_world_pos {
ui.heading("Entity");
if let Some(cell) = sim
.cell_manager
.get_cell_from_game_position(x.round() as i32, y.round() as i32)
{
let material = cell.material.def();
let cell_label = ui.label(
egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),
);
ui.painter().add(egui::Shape::Circle(CircleShape {
center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0),
radius: cell_label.rect.height() / 2.5,
stroke: Stroke::NONE,
fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
}));
ui.label(
egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW),
);
ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED));
}
}
}
|