Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Oct 3, 2023
1 parent bfc0d01 commit 331036b
Show file tree
Hide file tree
Showing 27 changed files with 172 additions and 58 deletions.
4 changes: 3 additions & 1 deletion geom/src/boldspline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ impl Intersect<Polygon> for BoldSpline {

let bbox = p.bbox().expand(self.radius);
while let Some(v) = points.next() {
let Some(&peek) = points.peek() else { return false; };
let Some(&peek) = points.peek() else {
return false;
};

let segment = Segment::new(v, peek);
if !bbox.intersects(&segment) {
Expand Down
48 changes: 36 additions & 12 deletions native_app/src/gui/inspect/inspect_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use simulation::souls::goods_company::{GoodsCompanyRegistry, Recipe};
/// Inspect a specific building, showing useful information about it
pub fn inspect_building(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: BuildingID) {
let map = sim.map();
let Some(building) = map.buildings().get(id) else { return; };
let Some(building) = map.buildings().get(id) else {
return;
};
let gregistry = sim.read::<GoodsCompanyRegistry>();

let title: &str = match building.kind {
Expand Down Expand Up @@ -72,8 +74,12 @@ pub fn inspect_building(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, i

fn render_house(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) {
let binfos = sim.read::<BuildingInfos>();
let Some(info) = binfos.get(b.id) else { return; };
let Some(SoulID::Human(owner)) = info.owner else { return; };
let Some(info) = binfos.get(b.id) else {
return;
};
let Some(SoulID::Human(owner)) = info.owner else {
return;
};

ui.horizontal(|ui| {
ui.label("Owner");
Expand All @@ -82,14 +88,20 @@ fn render_house(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Buildi

ui.label("Currently in the house:");
for &soul in info.inside.iter() {
let SoulID::Human(soul) = soul else { continue; };
let SoulID::Human(soul) = soul else {
continue;
};
entity_link(uiworld, sim, ui, soul);
}
}

fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) {
let Some(SoulID::FreightStation(owner)) = sim.read::<BuildingInfos>().owner(b.id) else { return; };
let Some(freight) = sim.world().get(owner) else { return; };
let Some(SoulID::FreightStation(owner)) = sim.read::<BuildingInfos>().owner(b.id) else {
return;
};
let Some(freight) = sim.world().get(owner) else {
return;
};

ui.label(format!("Waiting cargo: {}", freight.f.waiting_cargo));
ui.label(format!("Wanted cargo: {}", freight.f.wanted_cargo));
Expand Down Expand Up @@ -117,8 +129,12 @@ fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b
fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) {
let owner = sim.read::<BuildingInfos>().owner(b.id);

let Some(SoulID::GoodsCompany(c_id)) = owner else { return; };
let Some(c) = sim.world().companies.get(c_id) else { return; };
let Some(SoulID::GoodsCompany(c_id)) = owner else {
return;
};
let Some(c) = sim.world().companies.get(c_id) else {
return;
};
let goods = &c.comp;
let workers = &c.workers;

Expand Down Expand Up @@ -156,11 +172,15 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b:

let jobopening = itemregistry.id("job-opening");
for (&id, m) in market.iter() {
let Some(v) = m.capital(c_id.into()) else { continue };
let Some(v) = m.capital(c_id.into()) else {
continue;
};
if id == jobopening && v == 0 {
continue;
}
let Some(item) = itemregistry.get(id) else { continue };
let Some(item) = itemregistry.get(id) else {
continue;
};

item_icon(ui, uiworld, item, v);
}
Expand All @@ -179,7 +199,9 @@ fn render_recipe(ui: &mut Ui, uiworld: &UiWorld, sim: &Simulation, recipe: &Reci
});
ui.horizontal(|ui| {
for &(good, amount) in recipe.consumption.iter() {
let Some(item) = registry.get(good) else { continue };
let Some(item) = registry.get(good) else {
continue;
};
item_icon(ui, uiworld, item, amount);
}
});
Expand All @@ -195,7 +217,9 @@ fn render_recipe(ui: &mut Ui, uiworld: &UiWorld, sim: &Simulation, recipe: &Reci
});
ui.horizontal(|ui| {
for &(good, amount) in recipe.production.iter() {
let Some(item) = registry.get(good) else { continue };
let Some(item) = registry.get(good) else {
continue;
};
item_icon(ui, uiworld, item, amount);
}
});
Expand Down
12 changes: 9 additions & 3 deletions native_app/src/gui/inspect/inspect_human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::uiworld::UiWorld;

/// Inspect a specific building, showing useful information about it
pub fn inspect_human(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: HumanID) -> bool {
let Some(human) = sim.get(id) else { return false; };
let Some(human) = sim.get(id) else {
return false;
};

let mut is_open = true;
egui::Window::new("Human")
Expand Down Expand Up @@ -100,11 +102,15 @@ pub fn inspect_human(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id:

let jobopening = itemregistry.id("job-opening");
for (&item_id, m) in market.iter() {
let Some(v) = m.capital(id.into()) else { continue };
let Some(v) = m.capital(id.into()) else {
continue;
};
if item_id == jobopening {
continue;
}
let Some(item) = itemregistry.get(item_id) else { continue };
let Some(item) = itemregistry.get(item_id) else {
continue;
};

item_icon(ui, uiworld, item, v);
}
Expand Down
4 changes: 3 additions & 1 deletion native_app/src/gui/inspect/inspect_train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use egui::Context;
use simulation::{Simulation, TrainID};

pub fn inspect_train(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: TrainID) -> bool {
let Some(t) = sim.get(id) else { return false; };
let Some(t) = sim.get(id) else {
return false;
};

let mut is_open = true;
egui::Window::new("Train")
Expand Down
4 changes: 3 additions & 1 deletion native_app/src/gui/inspect/inspect_vehicle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub fn inspect_vehicle(
ui: &Context,
id: VehicleID,
) -> bool {
let Some(v) = sim.get(id) else { return false; };
let Some(v) = sim.get(id) else {
return false;
};

let name = format!("{:?}", v.vehicle.kind);

Expand Down
4 changes: 3 additions & 1 deletion native_app/src/gui/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub fn inspector(ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) {
is_open = inspect_vehicle(uiworld, sim, ui, id);
}
AnyEntity::WagonID(id) if !force_debug_inspect => {
let Some(w) = sim.world().get(id) else { return; };
let Some(w) = sim.world().get(id) else {
return;
};
let train_id = w.itfollower.leader;
uiworld.write::<InspectedEntity>().e = Some(AnyEntity::TrainID(train_id));
}
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/specialbuilding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn specialbuilding(sim: &Simulation, uiworld: &mut UiWorld) {
.min_by_key(move |p| OrderedFloat(p.points().project_dist2(mpos)));
let Some(closest_road) = closest_road else {
*uiworld.write::<ErrorTooltip>() = ErrorTooltip::new(Cow::Borrowed("No road nearby"));
return draw(hover_obb, true)
return draw(hover_obb, true);
};

let (proj, _, dir) = closest_road.points().project_segment_dir(mpos);
Expand Down
13 changes: 10 additions & 3 deletions native_app/src/gui/zoneedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ pub fn zoneedit(sim: &Simulation, uiworld: &mut UiWorld) {
let mut state = uiworld.write::<ZoneEditState>();
let mut potentialcommand = uiworld.write::<PotentialCommands>();

let Some(bid) = inspected_b.e else { state.offset = None; return; };
let Some(bid) = inspected_b.e else {
state.offset = None;
return;
};

let map = sim.map();
let Some(b) = map.buildings().get(bid) else { return; };
let Some(b) = map.buildings().get(bid) else {
return;
};

let Some(ref zone) = b.zone else { return; };
let Some(ref zone) = b.zone else {
return;
};
let filldir = zone.filldir;
let zone = &zone.poly;

Expand Down
5 changes: 4 additions & 1 deletion native_app/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ fn handle_singleplayer(state: &mut State) {
let mut net_state = state.uiw.write::<NetworkState>();

#[allow(irrefutable_let_patterns)]
let NetworkState::Singleplayer(ref mut step) = *net_state else { return; };
let NetworkState::Singleplayer(ref mut step) = *net_state
else {
return;
};

let mut commands_once = Some(commands.clone());
step.prepare_frame(timewarp);
Expand Down
4 changes: 3 additions & 1 deletion native_app/src/rendering/entity_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ impl InstancedRender {

self.path_not_found.clear();
for (_, (trans, itin)) in sim.world().query_trans_itin() {
let Some(wait) = itin.is_wait_for_reroute() else { continue };
let Some(wait) = itin.is_wait_for_reroute() else {
continue;
};
if wait == 0 {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion native_app/src/rendering/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ impl ImmediateDraw {
);
}
OrderKind::TexturedOBB { obb, ref path, z } => {
let Ok(tex) = ctx.gfx.try_texture(path, "some immediate obb") else { continue };
let Ok(tex) = ctx.gfx.try_texture(path, "some immediate obb") else {
continue;
};
ctx.objs.push(Box::new(
SpriteBatchBuilder::<false>::new(tex, ctx.gfx)
.push(obb.center().z(z), obb.axis()[0].z0(), *color, (1.0, 1.0))
Expand Down
8 changes: 6 additions & 2 deletions native_app/src/rendering/map_rendering/lamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ impl LampsRender {
for chunk in self.lamp_sub.take_updated_chunks() {
let lamp_chunk_memory = self.lamp_road_memory.entry(chunk).or_default();
for (chunk_id, lamp) in lamp_chunk_memory.drain(..) {
let Some(lamps) = self.lamp_memory.get_mut(&chunk_id) else { continue };
let Some(idx) = lamps.iter().position(|x| *x == lamp) else { continue };
let Some(lamps) = self.lamp_memory.get_mut(&chunk_id) else {
continue;
};
let Some(idx) = lamps.iter().position(|x| *x == lamp) else {
continue;
};
to_reupload.insert(chunk_id);
lamps.swap_remove(idx);
}
Expand Down
14 changes: 11 additions & 3 deletions native_app/src/rendering/map_rendering/map_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,12 @@ impl MapBuilders {
}

fn zone_mesh(&mut self, building: &Building) {
let Some(bzone) = &building.zone else { return; };
let Some((zone_mesh, filler, randomize)) = self.zonemeshes.get_mut(&building.kind) else { return; };
let Some(bzone) = &building.zone else {
return;
};
let Some((zone_mesh, filler, randomize)) = self.zonemeshes.get_mut(&building.kind) else {
return;
};
let zone = &bzone.poly;
let randomize = *randomize;

Expand All @@ -408,7 +412,11 @@ impl MapBuilders {

let principal_axis = building.obb.axis()[0].normalize().rotated_by(bzone.filldir);

let Some((mut min, mut max)) = minmax(zone.iter().map(|x| x.rotated_by(principal_axis.flipy()))) else { return; };
let Some((mut min, mut max)) =
minmax(zone.iter().map(|x| x.rotated_by(principal_axis.flipy())))
else {
return;
};
min = min.rotated_by(principal_axis);
max = max.rotated_by(principal_axis);

Expand Down
12 changes: 9 additions & 3 deletions native_app/src/rendering/map_rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ impl MapRenderer {
continue;
}
}
let Some(lane) = map.lanes().get(lane_id) else { continue };
let Some(lane) = map.lanes().get(lane_id) else {
continue;
};
Self::render_lane_signals(lane, draw, time);
}
}
Expand All @@ -131,8 +133,12 @@ impl MapRenderer {
.spatial_map()
.query(Circle::new(pos.xy(), 200.0), ProjectFilter::ROAD)
{
let ProjectKind::Road(id) = kind else { continue };
let Some(r) = map.roads().get(id) else { continue };
let ProjectKind::Road(id) = kind else {
continue;
};
let Some(r) = map.roads().get(id) else {
continue;
};
if !frustrum.intersects(&r.points.bbox().expand(r.width)) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion networking/src/connection_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl ConnectionClient {

pub fn recv_tcp(&mut self) -> Vec<Vec<u8>> {
let mut packets = Vec::new();
let Ok(v) = self.tcp_conn.1.try_recv() else { return packets };
let Ok(v) = self.tcp_conn.1.try_recv() else {
return packets;
};

self.tcp_conn.0.recv(&v, |d| {
packets.push(d);
Expand Down
8 changes: 6 additions & 2 deletions simulation/src/economy/government.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ impl Government {
zone: z,
} => {
let m = sim.map();
let Some(b) = m.buildings.get(*bid) else { return Money::ZERO; };
let Some(gc) = b.kind.as_goods_company() else { return Money::ZERO; };
let Some(b) = m.buildings.get(*bid) else {
return Money::ZERO;
};
let Some(gc) = b.kind.as_goods_company() else {
return Money::ZERO;
};
let registry = sim.read::<GoodsCompanyRegistry>();
let zonedescr = registry.descriptions[gc].zone.as_ref().unwrap();

Expand Down
12 changes: 9 additions & 3 deletions simulation/src/engine_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::transportation::train::{spawn_train, RailWagonKind};
use crate::transportation::{spawn_parked_vehicle_with_spot, unpark, VehicleKind};
use crate::utils::rand_provider::RandProvider;
use crate::utils::time::{GameTime, Tick};
use crate::{SimulationOptions, Replay, Simulation};
use crate::{Replay, Simulation, SimulationOptions};

#[derive(Clone, Default)]
pub struct WorldCommands {
Expand Down Expand Up @@ -314,11 +314,17 @@ impl WorldCommand {
let map = sim.map();
let mut rng = sim.write::<RandProvider>();

let Some(spot) = pm.reserve_random_free_spot(&map.parking, rng.next_u64()) else { continue; };
let Some(spot) = pm.reserve_random_free_spot(&map.parking, rng.next_u64())
else {
continue;
};

drop((map, pm, rng));

let Some(v_id) = spawn_parked_vehicle_with_spot(sim, VehicleKind::Car, spot) else { continue; };
let Some(v_id) = spawn_parked_vehicle_with_spot(sim, VehicleKind::Car, spot)
else {
continue;
};
unpark(sim, v_id);

sim.write::<RandomVehicles>().vehicles.insert(v_id);
Expand Down
12 changes: 9 additions & 3 deletions simulation/src/map/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl Map {
pub fn update_intersection(&mut self, id: IntersectionID, f: impl Fn(&mut Intersection)) {
info!("update_intersection {:?}", id);

let Some(inter) = self.intersections.get_mut(id) else { return; };
let Some(inter) = self.intersections.get_mut(id) else {
return;
};
f(inter);
self.invalidate(id);

Expand Down Expand Up @@ -156,10 +158,14 @@ impl Map {
}

pub fn update_zone(&mut self, id: BuildingID, f: impl FnOnce(&mut Zone)) {
let Some(b) = self.buildings.get_mut(id) else { return; };
let Some(b) = self.buildings.get_mut(id) else {
return;
};
self.subscribers.dispatch(UpdateType::Building, b);

let Some(ref mut z) = b.zone else { return; };
let Some(ref mut z) = b.zone else {
return;
};
f(z);

self.terrain.remove_near(&z.poly, |c| {
Expand Down
Loading

0 comments on commit 331036b

Please sign in to comment.