|
|
|
|
@ -130,13 +130,9 @@ enum PlayerState {
|
|
|
|
|
// A tape tracking the bird's state every frame
|
|
|
|
|
#[derive(Component, Default)]
|
|
|
|
|
struct Tape {
|
|
|
|
|
accumulated_translations: Vec<AccumulatedTranslation>,
|
|
|
|
|
linear_velocities: Vec<LinearVelocity>,
|
|
|
|
|
angular_velocities: Vec<AngularVelocity>,
|
|
|
|
|
external_angular_impulses: Vec<ExternalAngularImpulse>,
|
|
|
|
|
external_forces: Vec<ExternalForce>,
|
|
|
|
|
external_impulses: Vec<ExternalImpulse>,
|
|
|
|
|
external_torques: Vec<ExternalTorque>,
|
|
|
|
|
positions: Vec<Position>,
|
|
|
|
|
rotations: Vec<Rotation>,
|
|
|
|
|
}
|
|
|
|
|
@ -418,7 +414,7 @@ struct RewindSfx;
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct RewindButton;
|
|
|
|
|
|
|
|
|
|
fn init_ui(mut commands: Commands, mut server: ResMut<AssetServer>) {
|
|
|
|
|
fn init_ui(mut commands: Commands, server: Res<AssetServer>) {
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
Node {
|
|
|
|
|
@ -525,10 +521,6 @@ fn init_ui(mut commands: Commands, mut server: ResMut<AssetServer>) {
|
|
|
|
|
})
|
|
|
|
|
.observe(hide_credits);
|
|
|
|
|
|
|
|
|
|
fn start_game(_trigger: Trigger<Pointer<Click>>, mut next: ResMut<NextState<PlayerState>>) {
|
|
|
|
|
next.set(PlayerState::Alive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Node {
|
|
|
|
|
align_self: AlignSelf::Center,
|
|
|
|
|
@ -738,13 +730,9 @@ fn record(
|
|
|
|
|
#[cfg(debug_assertions)] state: Res<State<PlayerState>>,
|
|
|
|
|
mut birds: Query<
|
|
|
|
|
(
|
|
|
|
|
&AccumulatedTranslation,
|
|
|
|
|
&LinearVelocity,
|
|
|
|
|
&AngularVelocity,
|
|
|
|
|
&ExternalAngularImpulse,
|
|
|
|
|
&ExternalForce,
|
|
|
|
|
&ExternalImpulse,
|
|
|
|
|
&ExternalTorque,
|
|
|
|
|
&Position,
|
|
|
|
|
&Rotation,
|
|
|
|
|
&mut Tape,
|
|
|
|
|
@ -760,14 +748,10 @@ fn record(
|
|
|
|
|
|
|
|
|
|
birds
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|(at, lv, av, eai, ef, ei, et, p, r, mut tape)| {
|
|
|
|
|
tape.accumulated_translations.push(*at);
|
|
|
|
|
.for_each(|(lv, av, ei, p, r, mut tape)| {
|
|
|
|
|
tape.linear_velocities.push(*lv);
|
|
|
|
|
tape.angular_velocities.push(*av);
|
|
|
|
|
tape.external_angular_impulses.push(*eai);
|
|
|
|
|
tape.external_forces.push(*ef);
|
|
|
|
|
tape.external_impulses.push(*ei);
|
|
|
|
|
tape.external_torques.push(*et);
|
|
|
|
|
tape.positions.push(*p);
|
|
|
|
|
tape.rotations.push(*r);
|
|
|
|
|
});
|
|
|
|
|
@ -778,13 +762,9 @@ fn rewind(
|
|
|
|
|
mut next: ResMut<NextState<PlayerState>>,
|
|
|
|
|
mut birds: Query<
|
|
|
|
|
(
|
|
|
|
|
&mut AccumulatedTranslation,
|
|
|
|
|
&mut LinearVelocity,
|
|
|
|
|
&mut AngularVelocity,
|
|
|
|
|
&mut ExternalAngularImpulse,
|
|
|
|
|
&mut ExternalForce,
|
|
|
|
|
&mut ExternalImpulse,
|
|
|
|
|
&mut ExternalTorque,
|
|
|
|
|
&mut Position,
|
|
|
|
|
&mut Rotation,
|
|
|
|
|
&mut Tape,
|
|
|
|
|
@ -800,26 +780,15 @@ fn rewind(
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
birds.iter_mut().for_each(
|
|
|
|
|
|(mut at, mut lv, mut av, mut eai, mut ef, mut ei, mut et, mut p, mut r, mut tape)| {
|
|
|
|
|
|(mut lv, mut av, mut ei, mut p, mut r, mut tape)| {
|
|
|
|
|
if tape.positions.is_empty() {
|
|
|
|
|
next.set(PlayerState::Pause);
|
|
|
|
|
} else {
|
|
|
|
|
// TODO: Only record/restore variables that we manage!
|
|
|
|
|
at.0 = tape.accumulated_translations.pop().unwrap().0;
|
|
|
|
|
lv.0 = tape.linear_velocities.pop().unwrap().0;
|
|
|
|
|
av.0 = tape.angular_velocities.pop().unwrap().0;
|
|
|
|
|
eai.set_impulse(tape.external_angular_impulses.pop().unwrap().impulse());
|
|
|
|
|
ef.set_force(tape.external_forces.pop().unwrap().force());
|
|
|
|
|
ei.set_impulse(tape.external_impulses.pop().unwrap().impulse());
|
|
|
|
|
et.set_torque(tape.external_torques.pop().unwrap().torque());
|
|
|
|
|
p.0 = tape.positions.pop().unwrap().0;
|
|
|
|
|
*r = {
|
|
|
|
|
let curr = tape.rotations.pop().unwrap();
|
|
|
|
|
Rotation {
|
|
|
|
|
cos: curr.cos,
|
|
|
|
|
sin: curr.sin,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
*r = tape.rotations.pop().unwrap();
|
|
|
|
|
frames.0 += 1;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|