removing ezgui inline color parsing. pretty much unused, isn't helping

compile time. also fixing clippy issues
This commit is contained in:
Dustin Carlino 2019-08-22 12:53:30 -07:00
parent f86c1ac2d4
commit 9f897ef094
12 changed files with 138 additions and 146 deletions

View File

@ -2,6 +2,12 @@
Find packages to upgrade: `cargo outdated -R`
Deal with compile tile: `cargo bloat --time`
Find why two binary crates aren't sharing dependencies: https://old.reddit.com/r/rust/comments/cqceu4/common_crates_in_cargo_workspace_recompiled/
Where's a dependency coming from? `cargo tree -i -p syn`
Diff screencaps: http://www.imagemagick.org/Usage/compare/#methods
Debug OpenGL calls:

View File

@ -1,8 +1,10 @@
use crate::game::{State, Transition, WizardState};
use crate::ui::PerMapUI;
use crate::ui::UI;
use abstutil::prettyprint_usize;
use ezgui::{
hotkey, EventCtx, GfxCtx, HorizontalAlignment, Key, ModalMenu, Text, VerticalAlignment, Wizard,
hotkey, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, ModalMenu, Text, VerticalAlignment,
Wizard,
};
use geom::Duration;
use itertools::Itertools;
@ -28,16 +30,25 @@ impl Scoreboard {
let t2 = secondary.sim.get_finished_trips();
let mut summary = Text::new();
summary.push(format!(
"Score at [red:{}]... {} / {}",
primary.sim.time(),
primary.map.get_edits().edits_name,
secondary.map.get_edits().edits_name
));
summary.push(format!(
"[cyan:{}] | [red:{}] unfinished trips",
t1.unfinished_trips, t2.unfinished_trips
));
summary.add_line("Score at ".to_string());
summary.append(primary.sim.time().to_string(), Some(Color::RED));
summary.append(
format!(
"... {} / {}",
primary.map.get_edits().edits_name,
secondary.map.get_edits().edits_name
),
None,
);
summary.add_styled_line(
prettyprint_usize(t1.unfinished_trips),
Some(Color::CYAN),
None,
None,
);
summary.append(" | ".to_string(), None);
summary.append(prettyprint_usize(t2.unfinished_trips), Some(Color::RED));
summary.append(" unfinished trips".to_string(), None);
let cmp = CompareTrips::new(t1, t2);
for (mode, trips) in &cmp
@ -61,19 +72,41 @@ impl Scoreboard {
deltas.sort();
let len = deltas.len() as f64;
summary.push(format!(
"[cyan:{:?}] trips: {} same, {} different",
mode,
abstutil::prettyprint_usize(num_same),
abstutil::prettyprint_usize(deltas.len())
));
summary.add_styled_line(format!("{:?}", mode), Some(Color::CYAN), None, None);
summary.append(
format!(
" trips: {} same, {} different",
abstutil::prettyprint_usize(num_same),
abstutil::prettyprint_usize(deltas.len())
),
None,
);
if !deltas.is_empty() {
summary.push(format!(
" deltas: [red:50%ile] {}, [red:90%ile] {}, [red:99%ile] {}",
handle_negative(deltas[(0.5 * len).floor() as usize]),
handle_negative(deltas[(0.9 * len).floor() as usize]),
handle_negative(deltas[(0.99 * len).floor() as usize]),
));
summary.add_line(" deltas: ".to_string());
summary.append("50%ile".to_string(), Some(Color::RED));
summary.append(
format!(
" {}, ",
handle_negative(deltas[(0.5 * len).floor() as usize])
),
None,
);
summary.append("90%ile".to_string(), Some(Color::RED));
summary.append(
format!(
" {}, ",
handle_negative(deltas[(0.9 * len).floor() as usize])
),
None,
);
summary.append("99%ile".to_string(), Some(Color::RED));
summary.append(
format!(
" {}",
handle_negative(deltas[(0.99 * len).floor() as usize])
),
None,
);
}
}

View File

@ -248,6 +248,8 @@ fn tooltip_lines(id: ID, g: &mut GfxCtx, ctx: &PerMapUI) -> Text {
fn styled_kv(txt: &mut Text, tags: &BTreeMap<String, String>) {
for (k, v) in tags {
txt.push(format!("[red:{}] = [cyan:{}]", k, v));
txt.add_styled_line(k.to_string(), Some(Color::RED), None, None);
txt.append(" = ".to_string(), None);
txt.append(v.to_string(), Some(Color::CYAN));
}
}

View File

@ -146,7 +146,9 @@ impl State for DataVisualizer {
} else {
let mut txt = Text::new();
for (k, v) in kv {
txt.push(format!("[red:{}] = [cyan:{}]", k, v));
txt.add_styled_line(k.to_string(), Some(Color::RED), None, None);
txt.append(" = ".to_string(), None);
txt.append(v.to_string(), Some(Color::CYAN));
}
g.draw_blocking_text(&txt, (HorizontalAlignment::Left, VerticalAlignment::Top));
}

View File

@ -425,7 +425,7 @@ pub enum AgentColorScheme {
impl Cloneable for AgentColorScheme {}
impl AgentColorScheme {
pub fn unzoomed_color(&self, agent: &UnzoomedAgent, cs: &ColorScheme) -> Color {
pub fn unzoomed_color(self, agent: &UnzoomedAgent, cs: &ColorScheme) -> Color {
match self {
AgentColorScheme::VehicleTypes => match agent.vehicle_type {
Some(VehicleType::Car) => cs.get_def("unzoomed car", Color::RED.alpha(0.5)),
@ -439,7 +439,7 @@ impl AgentColorScheme {
}
}
pub fn zoomed_color_car(&self, input: &DrawCarInput, cs: &ColorScheme) -> Color {
pub fn zoomed_color_car(self, input: &DrawCarInput, cs: &ColorScheme) -> Color {
match self {
AgentColorScheme::VehicleTypes => {
if input.id.1 == VehicleType::Bus {
@ -459,7 +459,7 @@ impl AgentColorScheme {
}
}
pub fn zoomed_color_bike(&self, input: &DrawCarInput, cs: &ColorScheme) -> Color {
pub fn zoomed_color_bike(self, input: &DrawCarInput, cs: &ColorScheme) -> Color {
match self {
AgentColorScheme::VehicleTypes => match input.status {
CarStatus::Debug => cs.get_def("debug bike", Color::BLUE.alpha(0.8)),
@ -474,7 +474,7 @@ impl AgentColorScheme {
}
}
pub fn zoomed_color_ped(&self, input: &DrawPedestrianInput, cs: &ColorScheme) -> Color {
pub fn zoomed_color_ped(self, input: &DrawPedestrianInput, cs: &ColorScheme) -> Color {
match self {
AgentColorScheme::VehicleTypes => {
if input.preparing_bike {

View File

@ -1,7 +1,9 @@
use crate::game::{State, Transition, WizardState};
use crate::ui::UI;
use abstutil::prettyprint_usize;
use ezgui::{
hotkey, EventCtx, GfxCtx, HorizontalAlignment, Key, ModalMenu, Text, VerticalAlignment, Wizard,
hotkey, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, ModalMenu, Text, VerticalAlignment,
Wizard,
};
use geom::{Duration, DurationHistogram};
use itertools::Itertools;
@ -24,9 +26,15 @@ impl Scoreboard {
);
let t = ui.primary.sim.get_finished_trips();
let mut summary = Text::new();
summary.push(format!("Score at [red:{}]", ui.primary.sim.time()));
summary.push(format!("[cyan:{}] unfinished trips", t.unfinished_trips));
let mut summary = Text::from_line("Score at ".to_string());
summary.append(ui.primary.sim.time().to_string(), Some(Color::RED));
summary.add_styled_line(
prettyprint_usize(t.unfinished_trips),
Some(Color::CYAN),
None,
None,
);
summary.append(" unfinished trips".to_string(), None);
for (mode, trips) in &t
.finished_trips
@ -38,7 +46,8 @@ impl Scoreboard {
for (_, _, dt) in trips {
distrib.add(dt);
}
summary.push(format!("[cyan:{:?}] trips: {}", mode, distrib.describe()));
summary.add_styled_line(format!("{:?}", mode), Some(Color::CYAN), None, None);
summary.append(format!(" trips: {}", distrib.describe()), None);
}
Scoreboard { menu, summary }

View File

@ -10,7 +10,6 @@ geom = { path = "../geom" }
glium = "0.25.1"
glium-glyph = "0.6.0"
glutin = "0.21.0"
nom = "4.2.3"
ordered-float = "1.0.1"
serde = "1.0.98"
serde_derive = "1.0.98"

View File

@ -60,32 +60,6 @@ impl Color {
Color([self.0[0], self.0[1], self.0[2], a])
}
pub fn from_string(color: &str) -> Color {
match color {
"blue" => Color::BLUE,
"cyan" => Color::CYAN,
"green" => Color::GREEN,
"red" => Color::RED,
_ => panic!("Unknown color {}", color),
}
}
pub fn to_string(self) -> &'static str {
if self == Color::BLUE {
return "blue";
}
if self == Color::CYAN {
return "cyan";
}
if self == Color::GREEN {
return "green";
}
if self == Color::RED {
return "red";
}
panic!("Can't transform {} to a string", self);
}
pub fn from_hex(raw: &str) -> Color {
// Skip the leading '#'
let r = usize::from_str_radix(&raw[1..3], 16).unwrap();

View File

@ -4,8 +4,6 @@ use geom::{Distance, Polygon, Pt2D};
use glium_glyph::glyph_brush::rusttype::Scale;
use glium_glyph::glyph_brush::GlyphCruncher;
use glium_glyph::glyph_brush::{Section, SectionText, VariedSection};
use nom::types::CompleteStr;
use nom::{alt, char, do_parse, many1, named, separated_pair, take_till1, take_until};
use textwrap;
const FG_COLOR: Color = Color::WHITE;
@ -72,11 +70,6 @@ impl Text {
}
}
pub fn push(&mut self, line: String) {
self.lines.push((None, Vec::new()));
parse_style(self, line);
}
pub fn from_line(line: String) -> Text {
let mut txt = Text::new();
txt.add_line(line);
@ -313,59 +306,3 @@ pub fn draw_text_bubble_mapspace(
g.canvas.mapspace_glyphs.borrow_mut().queue(section);
}
}
#[derive(Debug)]
struct Append {
color: Option<Color>,
text: String,
}
named!(colored<CompleteStr, Append>,
do_parse!(
char!('[') >>
pair: separated_pair!(take_until!(":"), char!(':'), take_until!("]")) >>
char!(']')
>>
(Append {
color: Some(Color::from_string(&pair.0)),
text: pair.1.to_string(),
})
)
);
fn is_left_bracket(x: char) -> bool {
x == '['
}
named!(plaintext<CompleteStr, Append>,
do_parse!(
txt: take_till1!(is_left_bracket)
>>
(Append {
color: None,
text: txt.to_string(),
})
)
);
named!(chunk<CompleteStr, Append>,
alt!(colored | plaintext)
);
named!(chunks<CompleteStr, Vec<Append>>,
many1!(chunk)
);
fn parse_style(txt: &mut Text, line: String) {
match chunks(CompleteStr(&line)) {
Ok((rest, values)) => {
if !rest.is_empty() {
panic!("Parsing {} had leftover {}", line, rest);
}
for x in values {
txt.append(x.text, x.color);
}
}
x => panic!("Parsing {} broke: {:?}", line, x),
}
}

View File

@ -95,28 +95,36 @@ impl GUI for UI {
{
let len = self.hints.hints.len();
let mut txt = Text::prompt("Fix Map Geometry");
txt.push(format!(
"[cyan:{}] hints, [cyan:{}] parking overrides",
len,
self.hints.parking_overrides.len()
));
txt.add_styled_line(len.to_string(), Some(Color::CYAN), None, None);
txt.append(" hints, ".to_string(), None);
txt.append(
self.hints.parking_overrides.len().to_string(),
Some(Color::CYAN),
);
txt.append(" parking overrides".to_string(), None);
if let Some(ID::Road(r)) = selected {
txt.push(format!(
"[red:{}] is {} long",
r,
self.data.roads[&r].trimmed_center_pts.length()
));
txt.add_styled_line(r.to_string(), Some(Color::RED), None, None);
txt.append(
format!(
" is {} long",
self.data.roads[&r].trimmed_center_pts.length()
),
None,
);
if self.data.roads[&r].has_parking() {
txt.push("Has parking".to_string());
txt.add_line("Has parking".to_string());
} else {
txt.push("No parking".to_string());
txt.add_line("No parking".to_string());
}
for (k, v) in &self.raw.roads[&r].osm_tags {
txt.push(format!("[cyan:{}] = [red:{}]", k, v));
txt.add_styled_line(k.to_string(), Some(Color::RED), None, None);
txt.append(" = ".to_string(), None);
txt.append(v.to_string(), Some(Color::CYAN));
}
}
if let Some(ID::Intersection(i)) = selected {
txt.push(format!("[red:{}] OSM tag diffs:", i));
txt.add_styled_line(i.to_string(), Some(Color::RED), None, None);
txt.append(" OSM tag diffs:".to_string(), None);
let roads = &self.data.intersections[&i].roads;
if roads.len() == 2 {
let mut iter = roads.iter();
@ -126,18 +134,40 @@ impl GUI for UI {
for (k, v1) in r1_tags {
if let Some(v2) = r2_tags.get(k) {
if v1 != v2 {
txt.push(format!(
"[cyan:{}] = [red:{}] / [red:{}]",
k, v1, v2
));
txt.add_styled_line(
k.to_string(),
Some(Color::RED),
None,
None,
);
txt.append(" = ".to_string(), None);
txt.append(v1.to_string(), Some(Color::CYAN));
txt.append(" / ".to_string(), None);
txt.append(v2.to_string(), Some(Color::CYAN));
}
} else {
txt.push(format!("[cyan:{}] = [red:{}] / MISSING", k, v1));
txt.add_styled_line(
k.to_string(),
Some(Color::RED),
None,
None,
);
txt.append(" = ".to_string(), None);
txt.append(v1.to_string(), Some(Color::CYAN));
txt.append(" / MISSING".to_string(), None);
}
}
for (k, v2) in r2_tags {
if !r1_tags.contains_key(k) {
txt.push(format!("[cyan:{}] = MISSING / [red:{}] ", k, v2));
txt.add_styled_line(
k.to_string(),
Some(Color::RED),
None,
None,
);
txt.append(" = ".to_string(), None);
txt.append("MISSING / ".to_string(), None);
txt.append(v2.to_string(), Some(Color::CYAN));
}
}
}

View File

@ -179,7 +179,7 @@ impl Map {
timer.stop("setup rest of Pathfinder (walking with transit)");
timer.start("find parking blackholes");
for (l, redirect) in make::redirect_parking_blackholes(&mut m, timer) {
for (l, redirect) in make::redirect_parking_blackholes(&m, timer) {
m.lanes[l.0].parking_blackhole = Some(redirect);
}
timer.stop("find parking blackholes");

View File

@ -348,7 +348,7 @@ impl WalkingSimState {
front_path
.consume()
.values()
.map(|set| set.into_iter().cloned().collect::<Vec<_>>()),
.map(|set| set.iter().cloned().collect::<Vec<_>>()),
)
.enumerate()
{