using new rust 1.26 match stuff, and fmt

This commit is contained in:
Dustin Carlino 2018-05-10 16:12:16 -07:00
parent 677f74770a
commit f2b7344940
16 changed files with 36 additions and 35 deletions

View File

@ -31,12 +31,12 @@ extern crate structopt;
extern crate svg; extern crate svg;
extern crate vecmath; extern crate vecmath;
use ezgui::input::UserInput;
use glutin_window::GlutinWindow; use glutin_window::GlutinWindow;
use opengl_graphics::{Filter, GlGraphics, GlyphCache, OpenGL, TextureSettings};
use piston::event_loop::{EventLoop, EventSettings, Events}; use piston::event_loop::{EventLoop, EventSettings, Events};
use piston::input::RenderEvent; use piston::input::RenderEvent;
use piston::window::{Window, WindowSettings}; use piston::window::{Window, WindowSettings};
use opengl_graphics::{Filter, GlGraphics, GlyphCache, OpenGL, TextureSettings};
use ezgui::input::UserInput;
use structopt::StructOpt; use structopt::StructOpt;
mod animation; mod animation;

View File

@ -35,7 +35,7 @@ impl SearchState {
} }
fn choose_color(&self, osm_tags: &[String]) -> Option<Color> { fn choose_color(&self, osm_tags: &[String]) -> Option<Color> {
if let SearchState::FilterOSM(ref filter) = *self { if let SearchState::FilterOSM(filter) = self {
for tag in osm_tags { for tag in osm_tags {
if tag.contains(filter) { if tag.contains(filter) {
return Some(render::SEARCH_RESULT_COLOR); return Some(render::SEARCH_RESULT_COLOR);
@ -78,7 +78,7 @@ impl SearchState {
} }
pub fn draw(&self, canvas: &Canvas, g: &mut GfxCtx) { pub fn draw(&self, canvas: &Canvas, g: &mut GfxCtx) {
if let SearchState::EnteringSearch(ref text_box) = *self { if let SearchState::EnteringSearch(text_box) = self {
canvas.draw_osd_notification(g, &vec![text_box.line.clone()]); canvas.draw_osd_notification(g, &vec![text_box.line.clone()]);
// TODO draw the cursor // TODO draw the cursor
} }

View File

@ -13,13 +13,13 @@
// limitations under the License. // limitations under the License.
use animation; use animation;
use control::ControlMap;
use ezgui::canvas::{Canvas, GfxCtx}; use ezgui::canvas::{Canvas, GfxCtx};
use ezgui::input::UserInput; use ezgui::input::UserInput;
use geom; use geom;
use graphics::types::Color; use graphics::types::Color;
use map_model; use map_model;
use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID}; use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID};
use control::ControlMap;
use piston::input::{Button, Key, ReleaseEvent}; use piston::input::{Button, Key, ReleaseEvent};
use render; use render;
use sim::CarID; use sim::CarID;
@ -156,7 +156,7 @@ impl SelectionState {
match *self { match *self {
SelectionState::Empty | SelectionState::SelectedTurn(_) => {} SelectionState::Empty | SelectionState::SelectedTurn(_) => {}
SelectionState::SelectedIntersection(id) => { SelectionState::SelectedIntersection(id) => {
if let Some(ref signal) = control_map.traffic_signals.get(&id) { if let Some(signal) = control_map.traffic_signals.get(&id) {
let (cycle, _) = signal.current_cycle_and_remaining_time(sim.time.as_time()); let (cycle, _) = signal.current_cycle_and_remaining_time(sim.time.as_time());
for t in &cycle.turns { for t in &cycle.turns {
draw_map.get_t(*t).draw_full(g, render::TURN_COLOR); draw_map.get_t(*t).draw_full(g, render::TURN_COLOR);

View File

@ -16,8 +16,8 @@ extern crate map_model;
use animation; use animation;
use ezgui::canvas::{Canvas, GfxCtx}; use ezgui::canvas::{Canvas, GfxCtx};
use graphics::types::Color;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use graphics::types::Color;
use map_model::{Map, Pt2D, Road, RoadID, TurnID}; use map_model::{Map, Pt2D, Road, RoadID, TurnID};
use piston::input::{Key, UpdateEvent}; use piston::input::{Key, UpdateEvent};
use piston::window::Size; use piston::window::Size;

View File

@ -14,16 +14,16 @@
extern crate map_model; extern crate map_model;
use control::ControlMap;
use control::stop_signs::TurnPriority; use control::stop_signs::TurnPriority;
use ezgui::canvas; use ezgui::canvas;
use ezgui::input::UserInput;
use geom::GeomMap; use geom::GeomMap;
use graphics::types::Color; use graphics::types::Color;
use map_model::{Map, Turn};
use plugins::selection::SelectionState;
use control::ControlMap;
use map_model::IntersectionID; use map_model::IntersectionID;
use ezgui::input::UserInput; use map_model::{Map, Turn};
use piston::input::Key; use piston::input::Key;
use plugins::selection::SelectionState;
pub struct StopSignEditor { pub struct StopSignEditor {
i: IntersectionID, i: IntersectionID,

View File

@ -16,15 +16,15 @@
extern crate map_model; extern crate map_model;
use ezgui::canvas;
use geom::GeomMap;
use map_model::Map;
use graphics::types::Color;
use plugins::selection::SelectionState;
use control::ControlMap; use control::ControlMap;
use map_model::{IntersectionID, Turn}; use ezgui::canvas;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use geom::GeomMap;
use graphics::types::Color;
use map_model::Map;
use map_model::{IntersectionID, Turn};
use piston::input::Key; use piston::input::Key;
use plugins::selection::SelectionState;
pub struct TrafficSignalEditor { pub struct TrafficSignalEditor {
i: IntersectionID, i: IntersectionID,

View File

@ -16,9 +16,9 @@
extern crate map_model; extern crate map_model;
use control::ControlMap;
use graphics::types::Color; use graphics::types::Color;
use map_model::{Turn, TurnID}; use map_model::{Turn, TurnID};
use control::ControlMap;
use std::collections::HashMap; use std::collections::HashMap;
const CYCLE_COLORS: [Color; 8] = [ const CYCLE_COLORS: [Color; 8] = [

View File

@ -17,8 +17,8 @@ extern crate map_model;
use aabb_quadtree::QuadTree; use aabb_quadtree::QuadTree;
use aabb_quadtree::geom::{Point, Rect}; use aabb_quadtree::geom::{Point, Rect};
use geom::geometry;
use geom::GeomMap; use geom::GeomMap;
use geom::geometry;
use map_model::{Bounds, BuildingID, IntersectionID, Map, ParcelID, Pt2D, RoadID, TurnID}; use map_model::{Bounds, BuildingID, IntersectionID, Map, ParcelID, Pt2D, RoadID, TurnID};
use render::building::DrawBuilding; use render::building::DrawBuilding;
use render::intersection::DrawIntersection; use render::intersection::DrawIntersection;

View File

@ -22,8 +22,8 @@ use geom::geometry;
use graphics; use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use graphics::types::Color; use graphics::types::Color;
use render::{BRIGHT_DEBUG_COLOR, DEBUG_COLOR, PARCEL_BOUNDARY_THICKNESS, ROAD_ORIENTATION_COLOR};
use map_model::{Bounds, Pt2D, RoadID}; use map_model::{Bounds, Pt2D, RoadID};
use render::{BRIGHT_DEBUG_COLOR, DEBUG_COLOR, PARCEL_BOUNDARY_THICKNESS, ROAD_ORIENTATION_COLOR};
use std::f64; use std::f64;
use svg; use svg;

View File

@ -18,8 +18,8 @@ extern crate map_model;
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use ezgui::canvas::GfxCtx; use ezgui::canvas::GfxCtx;
use geom; use geom;
use geom::geometry;
use geom::GeomMap; use geom::GeomMap;
use geom::geometry;
use graphics; use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use graphics::types::Color; use graphics::types::Color;

View File

@ -17,13 +17,13 @@
extern crate map_model; extern crate map_model;
use animation; use animation;
use control::ControlMap;
use ezgui::ToggleableLayer; use ezgui::ToggleableLayer;
use ezgui::canvas; use ezgui::canvas;
use ezgui::canvas::{Canvas, GfxCtx}; use ezgui::canvas::{Canvas, GfxCtx};
use ezgui::input::UserInput;
use geom; use geom;
use graphics::types::Color; use graphics::types::Color;
use control::ControlMap;
use ezgui::input::UserInput;
use piston::input::{Key, MouseCursorEvent}; use piston::input::{Key, MouseCursorEvent};
use piston::window::Size; use piston::window::Size;
use plugins::classification::OsmClassifier; use plugins::classification::OsmClassifier;

View File

@ -14,13 +14,13 @@
use aabb_quadtree::geom::{Point, Rect}; use aabb_quadtree::geom::{Point, Rect};
use graphics; use graphics;
use graphics::{Context, Image, Transformed};
use graphics::character::CharacterCache; use graphics::character::CharacterCache;
use graphics::types::Color; use graphics::types::Color;
use graphics::{Context, Image, Transformed};
use opengl_graphics::{GlGraphics, Texture};
use piston::input::{Button, Event, Key, MouseButton, MouseCursorEvent, MouseScrollEvent, use piston::input::{Button, Event, Key, MouseButton, MouseCursorEvent, MouseScrollEvent,
PressEvent, ReleaseEvent}; PressEvent, ReleaseEvent};
use piston::window::Size; use piston::window::Size;
use opengl_graphics::{GlGraphics, Texture};
//pub const WHITE: Color = [1.0, 1.0, 1.0, 1.0]; //pub const WHITE: Color = [1.0, 1.0, 1.0, 1.0];
pub const BLACK: Color = [0.0, 0.0, 0.0, 1.0]; pub const BLACK: Color = [0.0, 0.0, 0.0, 1.0];

View File

@ -19,8 +19,8 @@ extern crate serde;
extern crate serde_derive; extern crate serde_derive;
use ordered_float::NotNaN; use ordered_float::NotNaN;
use protobuf::{CodedInputStream, CodedOutputStream, Message};
use protobuf::error::ProtobufError; use protobuf::error::ProtobufError;
use protobuf::{CodedInputStream, CodedOutputStream, Message};
use std::collections::HashMap; use std::collections::HashMap;
use std::f64; use std::f64;
use std::fs::File; use std::fs::File;

View File

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
grep -R --exclude-dir=.git --exclude-dir=target --exclude-dir=data --exclude=Cargo.lock $@ grep -R --exclude-dir=.git --exclude-dir=target --exclude-dir=data --exclude=Cargo.lock "$@"

View File

@ -54,9 +54,9 @@ impl IntersectionPolicy {
} }
pub fn on_enter(&self, car: CarID) { pub fn on_enter(&self, car: CarID) {
match *self { match self {
IntersectionPolicy::StopSignPolicy(ref p) => p.on_enter(car), IntersectionPolicy::StopSignPolicy(p) => p.on_enter(car),
IntersectionPolicy::TrafficSignalPolicy(ref p) => p.on_enter(car), IntersectionPolicy::TrafficSignalPolicy(p) => p.on_enter(car),
} }
} }
pub fn on_exit(&mut self, car: CarID) { pub fn on_exit(&mut self, car: CarID) {

View File

@ -286,7 +286,8 @@ impl SimQueue {
pub struct Sim { pub struct Sim {
// This is slightly dangerous, but since we'll be using comparisons based on savestating (which // This is slightly dangerous, but since we'll be using comparisons based on savestating (which
// captures the RNG), this should be OK for now. // captures the RNG), this should be OK for now.
#[derivative(PartialEq = "ignore")] rng: XorShiftRng, #[derivative(PartialEq = "ignore")]
rng: XorShiftRng,
// TODO investigate slot map-like structures for performance // TODO investigate slot map-like structures for performance
// Using BTreeMap instead of HashMap so iteration is deterministic. Should be able to relax // Using BTreeMap instead of HashMap so iteration is deterministic. Should be able to relax
// this later after step() doesnt need a RNG. // this later after step() doesnt need a RNG.
@ -309,9 +310,9 @@ impl Sim {
let mut intersections: Vec<IntersectionPolicy> = Vec::new(); let mut intersections: Vec<IntersectionPolicy> = Vec::new();
for i in map.all_intersections() { for i in map.all_intersections() {
if i.has_traffic_signal { if i.has_traffic_signal {
intersections.push(IntersectionPolicy::TrafficSignalPolicy( intersections.push(IntersectionPolicy::TrafficSignalPolicy(TrafficSignal::new(
TrafficSignal::new(i.id), i.id,
)); )));
} else { } else {
intersections.push(IntersectionPolicy::StopSignPolicy(StopSign::new(i.id))); intersections.push(IntersectionPolicy::StopSignPolicy(StopSign::new(i.id)));
} }
@ -427,7 +428,7 @@ impl Sim {
// It might make more sense to push the conflict resolution down to SimQueue? // It might make more sense to push the conflict resolution down to SimQueue?
// TODO should shuffle deterministically here, to be more fair // TODO should shuffle deterministically here, to be more fair
let mut new_car_entered_this_step = HashSet::new(); let mut new_car_entered_this_step = HashSet::new();
for &(ref id, ref act) in &requested_moves { for (id, act) in &requested_moves {
match *act { match *act {
Action::Vanish => { Action::Vanish => {
self.cars.remove(&id); self.cars.remove(&id);