mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
move some sim code
This commit is contained in:
parent
0e4ff75286
commit
c6ebab1e9c
@ -60,3 +60,14 @@
|
|||||||
- https://www.politesi.polimi.it/bitstream/10589/112826/4/2015_10_TOPTAS.pdf pg38
|
- https://www.politesi.polimi.it/bitstream/10589/112826/4/2015_10_TOPTAS.pdf pg38
|
||||||
|
|
||||||
- just make polygons around center lines, then intersect?
|
- just make polygons around center lines, then intersect?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
morning thoughts!
|
||||||
|
|
||||||
|
- trim lines based on outermost POLYGON border line, not lane center lines or anything
|
||||||
|
- the ascending angle and skipping existing lines in the thesis seems to make sense
|
||||||
|
- find where infinite line intersects line segment for some cases?
|
||||||
|
@ -5,7 +5,7 @@ use control::ControlMap;
|
|||||||
use ezgui::input::UserInput;
|
use ezgui::input::UserInput;
|
||||||
use map_model::Map;
|
use map_model::Map;
|
||||||
use piston::input::{Key, UpdateEvent};
|
use piston::input::{Key, UpdateEvent};
|
||||||
use sim::common;
|
use sim;
|
||||||
use sim::straw_model;
|
use sim::straw_model;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ impl SimController {
|
|||||||
// TODO https://gafferongames.com/post/fix_your_timestep/
|
// TODO https://gafferongames.com/post/fix_your_timestep/
|
||||||
let dt = tick.elapsed();
|
let dt = tick.elapsed();
|
||||||
let dt_s = dt.as_secs() as f64 + f64::from(dt.subsec_nanos()) * 1e-9;
|
let dt_s = dt.as_secs() as f64 + f64::from(dt.subsec_nanos()) * 1e-9;
|
||||||
if dt_s >= common::TIMESTEP.value_unsafe / self.desired_speed {
|
if dt_s >= sim::TIMESTEP.value_unsafe / self.desired_speed {
|
||||||
self.sim.step(map, control_map);
|
self.sim.step(map, control_map);
|
||||||
self.last_step = Some(Instant::now());
|
self.last_step = Some(Instant::now());
|
||||||
}
|
}
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
use dimensioned::si;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
|
||||||
pub struct CarID(pub usize);
|
|
||||||
|
|
||||||
use std;
|
|
||||||
pub const TIMESTEP: si::Second<f64> = si::Second {
|
|
||||||
value_unsafe: 0.1,
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
};
|
|
||||||
pub const SPEED_LIMIT: si::MeterPerSecond<f64> = si::MeterPerSecond {
|
|
||||||
value_unsafe: 8.9408,
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
|
||||||
pub struct Tick(u32);
|
|
||||||
|
|
||||||
impl Tick {
|
|
||||||
pub fn zero() -> Tick {
|
|
||||||
Tick(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_time(&self) -> si::Second<f64> {
|
|
||||||
(self.0 as f64) * TIMESTEP
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn increment(&mut self) {
|
|
||||||
self.0 += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::ops::Sub;
|
|
||||||
|
|
||||||
impl Sub for Tick {
|
|
||||||
type Output = Tick;
|
|
||||||
|
|
||||||
fn sub(self, other: Tick) -> Tick {
|
|
||||||
Tick(self.0 - other.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Tick {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
// TODO switch to minutes and hours when this gets big
|
|
||||||
write!(f, "{0:.1}s", (self.0 as f64) * TIMESTEP.value_unsafe)
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,8 +14,51 @@ extern crate serde;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
pub mod common;
|
|
||||||
mod straw_intersections;
|
mod straw_intersections;
|
||||||
pub mod straw_model;
|
pub mod straw_model;
|
||||||
|
|
||||||
pub use common::CarID;
|
use dimensioned::si;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
|
pub struct CarID(pub usize);
|
||||||
|
|
||||||
|
pub const TIMESTEP: si::Second<f64> = si::Second {
|
||||||
|
value_unsafe: 0.1,
|
||||||
|
_marker: std::marker::PhantomData,
|
||||||
|
};
|
||||||
|
pub const SPEED_LIMIT: si::MeterPerSecond<f64> = si::MeterPerSecond {
|
||||||
|
value_unsafe: 8.9408,
|
||||||
|
_marker: std::marker::PhantomData,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
|
pub struct Tick(u32);
|
||||||
|
|
||||||
|
impl Tick {
|
||||||
|
pub fn zero() -> Tick {
|
||||||
|
Tick(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_time(&self) -> si::Second<f64> {
|
||||||
|
(self.0 as f64) * TIMESTEP
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn increment(&mut self) {
|
||||||
|
self.0 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Sub for Tick {
|
||||||
|
type Output = Tick;
|
||||||
|
|
||||||
|
fn sub(self, other: Tick) -> Tick {
|
||||||
|
Tick(self.0 - other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Tick {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
// TODO switch to minutes and hours when this gets big
|
||||||
|
write!(f, "{0:.1}s", (self.0 as f64) * TIMESTEP.value_unsafe)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
use common::{CarID, Tick, SPEED_LIMIT};
|
|
||||||
use control::ControlMap;
|
use control::ControlMap;
|
||||||
use control::stop_signs::{ControlStopSign, TurnPriority};
|
use control::stop_signs::{ControlStopSign, TurnPriority};
|
||||||
use dimensioned::si;
|
use dimensioned::si;
|
||||||
use map_model::{IntersectionID, Map, TurnID};
|
use map_model::{IntersectionID, Map, TurnID};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use {CarID, Tick, SPEED_LIMIT};
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
const WAIT_AT_STOP_SIGN: si::Second<f64> = si::Second {
|
const WAIT_AT_STOP_SIGN: si::Second<f64> = si::Second {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
use common::{CarID, Tick, SPEED_LIMIT};
|
|
||||||
use control::ControlMap;
|
use control::ControlMap;
|
||||||
use dimensioned::si;
|
use dimensioned::si;
|
||||||
use ezgui::GfxCtx;
|
use ezgui::GfxCtx;
|
||||||
@ -15,6 +14,7 @@ use std::collections::{BTreeMap, HashSet};
|
|||||||
use std::f64;
|
use std::f64;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use straw_intersections::{IntersectionPolicy, StopSign, TrafficSignal};
|
use straw_intersections::{IntersectionPolicy, StopSign, TrafficSignal};
|
||||||
|
use {CarID, Tick, SPEED_LIMIT};
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
const FOLLOWING_DISTANCE: si::Meter<f64> = si::Meter {
|
const FOLLOWING_DISTANCE: si::Meter<f64> = si::Meter {
|
||||||
|
Loading…
Reference in New Issue
Block a user