Bellow is my code, as you can see, placement of labels and computation are in one large update function.
impl eframe::App for Application {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if self.checks[0] == 0 {
let john: Person = self.sim_data.create_person(0);
let john2: Person = self.sim_data.create_person(1);
self.sim_data.people.push(john);
self.sim_data.people.push(john2);
self.checks[0] = 1;
}
if self.checks[1] != 0 {
self.sim_data.update_sim(&self.world_data);
for id in 0..self.sim_data.people.len() - 1 {
if id < self.sim_data.people.len() && self.sim_data.people[id].love_vec[0] != -1
&& self.sim_data.people[id].age > 30 * 12
|| self.sim_data.people[id].stats[0] <= 0.0
{
self.sim_data.people[id].age = -1;
}
}
self.sim_data.people.retain(|person| person.age != -1);
self.checks[1] -= 1;
}
egui::CentralPanel::default().show(ctx, |ui| {
ui.label(egui::RichText::new(
format!("Population: {}", self.sim_data.people.len())).size(125.0));
ui.label(egui::RichText::new(
format!("Months Passed: {}", MONTHS_OF_POPULATING - self.checks[1])).size(25.0));
ui.label(egui::RichText::new(
format!("Months left: {}", self.checks[1])).size(15.0));
});
egui::TopBottomPanel::bottom("settings").show(ctx, |ui| {
egui::CollapsingHeader::new("THEME")
.show(ui, |ui| egui::
widgets::global_dark_light_mode_buttons(ui));
});
// println!("{:?}", self.sim_data.people);
ctx.request_repaint();
});
}
}
What should i do to decouple the computation code and display code into 2?
I know that I should use threads, but I have never done this before as I am relatively new to rust.
What would be the best implementation of a 2 thread approach?
Thank you