mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
toggle playing forwards or backwards
This commit is contained in:
parent
b547db43b6
commit
0eed17f81c
@ -43,8 +43,7 @@
|
||||
|
||||
## Discrete-event model
|
||||
|
||||
- make space toggle play for time travel or sim or simple model
|
||||
- Make cars cover an entire lane when it's short or long
|
||||
- Make cars cover an entire lane, even when it's short
|
||||
- avoid impossible accel/deaccel
|
||||
- Handle lead car being faster
|
||||
- The speed stated in the middle of intervals is clearly wrong for the follower car
|
||||
|
@ -1,11 +1,19 @@
|
||||
use crate::plugins::sim::des_model;
|
||||
use crate::plugins::PluginCtx;
|
||||
use ezgui::EventLoopMode;
|
||||
use map_model::{Map, Traversable};
|
||||
use sim::{CarID, DrawCarInput, DrawPedestrianInput, GetDrawAgents, PedestrianID, Tick};
|
||||
|
||||
enum AutoMode {
|
||||
Off,
|
||||
Forwards,
|
||||
Backwards,
|
||||
}
|
||||
|
||||
pub struct SimpleModelController {
|
||||
current_tick: Option<Tick>,
|
||||
world: Option<des_model::World>,
|
||||
mode: AutoMode,
|
||||
}
|
||||
|
||||
impl SimpleModelController {
|
||||
@ -13,6 +21,7 @@ impl SimpleModelController {
|
||||
SimpleModelController {
|
||||
current_tick: None,
|
||||
world: None,
|
||||
mode: AutoMode::Off,
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,12 +37,40 @@ impl SimpleModelController {
|
||||
format!("Simple Model at {}", tick),
|
||||
&ctx.canvas,
|
||||
);
|
||||
if tick != Tick::zero() && ctx.input.modal_action("rewind") {
|
||||
self.current_tick = Some(tick.prev());
|
||||
} else if ctx.input.modal_action("forwards") {
|
||||
self.current_tick = Some(tick.next());
|
||||
} else if ctx.input.modal_action("quit") {
|
||||
match self.mode {
|
||||
AutoMode::Off => {
|
||||
if tick != Tick::zero() && ctx.input.modal_action("rewind") {
|
||||
self.current_tick = Some(tick.prev());
|
||||
} else if ctx.input.modal_action("forwards") {
|
||||
self.current_tick = Some(tick.next());
|
||||
} else if ctx.input.modal_action("toggle forwards play") {
|
||||
self.mode = AutoMode::Forwards;
|
||||
ctx.hints.mode = EventLoopMode::Animation;
|
||||
} else if ctx.input.modal_action("toggle backwards play") {
|
||||
self.mode = AutoMode::Backwards;
|
||||
ctx.hints.mode = EventLoopMode::Animation;
|
||||
}
|
||||
}
|
||||
AutoMode::Forwards => {
|
||||
ctx.hints.mode = EventLoopMode::Animation;
|
||||
if ctx.input.modal_action("toggle forwards play") {
|
||||
self.mode = AutoMode::Off;
|
||||
} else if ctx.input.is_update_event() {
|
||||
self.current_tick = Some(tick.next());
|
||||
}
|
||||
}
|
||||
AutoMode::Backwards => {
|
||||
ctx.hints.mode = EventLoopMode::Animation;
|
||||
if tick == Tick::zero() || ctx.input.modal_action("toggle backwards play") {
|
||||
self.mode = AutoMode::Off;
|
||||
} else if ctx.input.is_update_event() {
|
||||
self.current_tick = Some(tick.prev());
|
||||
}
|
||||
}
|
||||
}
|
||||
if ctx.input.modal_action("quit") {
|
||||
self.current_tick = None;
|
||||
self.mode = AutoMode::Off;
|
||||
}
|
||||
} else if ctx.input.action_chosen("start simple model") {
|
||||
self.current_tick = Some(Tick::zero());
|
||||
|
@ -146,6 +146,8 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
(Key::Enter, "quit"),
|
||||
(Key::Comma, "rewind"),
|
||||
(Key::Dot, "forwards"),
|
||||
(Key::Space, "toggle forwards play"),
|
||||
(Key::M, "toggle backwards play"),
|
||||
],
|
||||
),
|
||||
ModalMenu::new(
|
||||
|
Loading…
Reference in New Issue
Block a user