|
|
|
@ -150,7 +150,14 @@ impl Tape {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn push(&mut self, lv: LinearVelocity, av: AngularVelocity, ei: ExternalImpulse, p: Position, r: Rotation) {
|
|
|
|
fn push(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
lv: LinearVelocity,
|
|
|
|
|
|
|
|
av: AngularVelocity,
|
|
|
|
|
|
|
|
ei: ExternalImpulse,
|
|
|
|
|
|
|
|
p: Position,
|
|
|
|
|
|
|
|
r: Rotation,
|
|
|
|
|
|
|
|
) {
|
|
|
|
// If we are at capacity, make room
|
|
|
|
// If we are at capacity, make room
|
|
|
|
if self.linear_velocities.len() == self.capacity {
|
|
|
|
if self.linear_velocities.len() == self.capacity {
|
|
|
|
self.linear_velocities.pop_front().unwrap();
|
|
|
|
self.linear_velocities.pop_front().unwrap();
|
|
|
|
@ -167,7 +174,15 @@ impl Tape {
|
|
|
|
self.rotations.push_back(r);
|
|
|
|
self.rotations.push_back(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn pop(&mut self) -> Option<(LinearVelocity, AngularVelocity, ExternalImpulse, Position, Rotation)> {
|
|
|
|
fn pop(
|
|
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
) -> Option<(
|
|
|
|
|
|
|
|
LinearVelocity,
|
|
|
|
|
|
|
|
AngularVelocity,
|
|
|
|
|
|
|
|
ExternalImpulse,
|
|
|
|
|
|
|
|
Position,
|
|
|
|
|
|
|
|
Rotation,
|
|
|
|
|
|
|
|
)> {
|
|
|
|
if self.linear_velocities.is_empty() {
|
|
|
|
if self.linear_velocities.is_empty() {
|
|
|
|
None
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -194,8 +209,7 @@ fn init_bird(mut commands: Commands, bird_assets: Res<BirdAssets>) {
|
|
|
|
MaxLinearSpeed(500.0),
|
|
|
|
MaxLinearSpeed(500.0),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 60fps * 60 seconds
|
|
|
|
// 60fps * 5 seconds
|
|
|
|
// let tape = Tape::new_with_capacity(60 * 60);
|
|
|
|
|
|
|
|
const REWIND_SECONDS: usize = 5;
|
|
|
|
const REWIND_SECONDS: usize = 5;
|
|
|
|
let tape = Tape::new_with_capacity(60 * REWIND_SECONDS);
|
|
|
|
let tape = Tape::new_with_capacity(60 * REWIND_SECONDS);
|
|
|
|
|
|
|
|
|
|
|
|
@ -611,8 +625,15 @@ fn init_ui(mut commands: Commands, server: Res<AssetServer>) {
|
|
|
|
RewindButton,
|
|
|
|
RewindButton,
|
|
|
|
children![
|
|
|
|
children![
|
|
|
|
(
|
|
|
|
(
|
|
|
|
ImageNode { color: BLACK.into(), image: rewind_image, ..default() },
|
|
|
|
ImageNode {
|
|
|
|
Node { height: Val::Px(50.0), ..default() },
|
|
|
|
color: BLACK.into(),
|
|
|
|
|
|
|
|
image: rewind_image,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Node {
|
|
|
|
|
|
|
|
height: Val::Px(50.0),
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
(
|
|
|
|
Text::new("Rewind! (R)"),
|
|
|
|
Text::new("Rewind! (R)"),
|
|
|
|
@ -648,8 +669,15 @@ fn init_ui(mut commands: Commands, server: Res<AssetServer>) {
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
(
|
|
|
|
ImageNode { color: BLACK.into(), image: play_image, ..default() },
|
|
|
|
ImageNode {
|
|
|
|
Node { height: Val::Px(50.0), ..default() },
|
|
|
|
color: BLACK.into(),
|
|
|
|
|
|
|
|
image: play_image,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Node {
|
|
|
|
|
|
|
|
height: Val::Px(50.0),
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
))
|
|
|
|
))
|
|
|
|
@ -667,7 +695,7 @@ fn init_ui(mut commands: Commands, server: Res<AssetServer>) {
|
|
|
|
SyncResource::<Score>::default(),
|
|
|
|
SyncResource::<Score>::default(),
|
|
|
|
Text::default(),
|
|
|
|
Text::default(),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
TextLayout::new_with_justify(JustifyText::Center),
|
|
|
|
)]
|
|
|
|
)],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -793,11 +821,9 @@ fn record(
|
|
|
|
"Only record in the alive state"
|
|
|
|
"Only record in the alive state"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
birds
|
|
|
|
birds.iter_mut().for_each(|(lv, av, ei, p, r, mut tape)| {
|
|
|
|
.iter_mut()
|
|
|
|
tape.push(*lv, *av, *ei, *p, *r);
|
|
|
|
.for_each(|(lv, av, ei, p, r, mut tape)| {
|
|
|
|
});
|
|
|
|
tape.push(*lv, *av, *ei, *p, *r);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn rewind(
|
|
|
|
fn rewind(
|
|
|
|
@ -822,8 +848,9 @@ fn rewind(
|
|
|
|
"Only rewind in the rewinding state"
|
|
|
|
"Only rewind in the rewinding state"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
birds.iter_mut().for_each(
|
|
|
|
birds
|
|
|
|
|(mut lv, mut av, mut ei, mut p, mut r, mut tape)| {
|
|
|
|
.iter_mut()
|
|
|
|
|
|
|
|
.for_each(|(mut lv, mut av, mut ei, mut p, mut r, mut tape)| {
|
|
|
|
if let Some((new_lv, new_av, new_ei, new_p, new_r)) = tape.pop() {
|
|
|
|
if let Some((new_lv, new_av, new_ei, new_p, new_r)) = tape.pop() {
|
|
|
|
lv.0 = new_lv.0;
|
|
|
|
lv.0 = new_lv.0;
|
|
|
|
av.0 = new_av.0;
|
|
|
|
av.0 = new_av.0;
|
|
|
|
@ -834,8 +861,7 @@ fn rewind(
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
next.set(PlayerState::Pause);
|
|
|
|
next.set(PlayerState::Pause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PERF: May run more than necessary, should be event-driven on aabb intersection
|
|
|
|
// PERF: May run more than necessary, should be event-driven on aabb intersection
|
|
|
|
|