Skip to content

Commit

Permalink
changes suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Apr 26, 2024
1 parent cedbf84 commit 171d197
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 145 deletions.
32 changes: 15 additions & 17 deletions bxt-strafe/src/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl<S: Step> Step for Strafe<S> {
frame_bulk.auto_actions.movement
{
let theta = match type_ {
StrafeType::MaxAccel | StrafeType::MaxAccelYawOffset(_, _, _) => match dir {
StrafeType::MaxAccel | StrafeType::MaxAccelYawOffset { .. } => match dir {
StrafeDir::Left => max_accel_theta(parameters, &state),
StrafeDir::Right => -max_accel_theta(parameters, &state),
StrafeDir::Yaw(yaw) => {
Expand Down Expand Up @@ -447,7 +447,7 @@ impl<S: Step> Step for Strafe<S> {
(camera_yaw, entry)
};

let camera_yaw = if matches!(type_, StrafeType::MaxAccelYawOffset(_, _, _)) {
let camera_yaw = if matches!(type_, StrafeType::MaxAccelYawOffset { .. }) {
// theta < 0. = is right
// If is right then we decreases yaw by offset.
// Therefore, positive offset in framebulk mean going more on that side.
Expand Down Expand Up @@ -560,12 +560,22 @@ impl<S: Step> Step for ResetFields<S> {
// If we have some acceleration, then this kicks in.
// It will preserve the final value across split segments.
if let Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(start, target, accel),
type_:
StrafeType::MaxAccelYawOffset {
start,
target,
accel,
},
dir,
})) = frame_bulk.auto_actions.movement
{
let right = matches!(dir, StrafeDir::Right);

// Flip start and target when accel is negative.
state.max_accel_yaw_offset_value = (state.max_accel_yaw_offset_value + accel)
.max(start)
.min(target);

// Reset value if we have different inputs.
// This means that if we split a s5x bulk,
// there won't be any side effects.
Expand All @@ -574,12 +584,10 @@ impl<S: Step> Step for ResetFields<S> {
|| accel != state.prev_max_accel_yaw_offset_accel
|| right != state.prev_max_accel_yaw_offset_right
{
// Terrible hack to have 0 as the start and target at the end and
// vice versa.
state.max_accel_yaw_offset_value = if accel.is_sign_negative() {
target - accel
target
} else {
start - accel
start
};

// Update so next time we know what to compare against.
Expand All @@ -588,16 +596,6 @@ impl<S: Step> Step for ResetFields<S> {
state.prev_max_accel_yaw_offset_accel = accel;
state.prev_max_accel_yaw_offset_right = right;
};

state.max_accel_yaw_offset_value = if accel.is_sign_negative() {
// accel is negative so addition is subtraction.
(state.max_accel_yaw_offset_value + accel).max(start)
} else {
// .max(start) to avoid negative and be consistent with HLStrafe.
(state.max_accel_yaw_offset_value + accel)
.max(start)
.min(target)
};
}

self.0
Expand Down
13 changes: 11 additions & 2 deletions src/hooks/bxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,17 @@ pub struct OnTasPlaybackFrameData {
pub strafe_cycle_frame_count: u32,
pub prev_predicted_trace_fractions: [f32; 4],
pub prev_predicted_trace_normal_zs: [f32; 4],
// [value, start, target, accel, dir]
pub accel_yawspeed: [f32; 5],
pub max_accel_yaw_offset: OnTasPlaybackFrameMaxAccelYawOffset,
}

#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct OnTasPlaybackFrameMaxAccelYawOffset {
pub value: f32,
pub start: f32,
pub target: f32,
pub accel: f32,
pub dir: u8,
}

unsafe extern "C" fn on_tas_playback_frame(data: OnTasPlaybackFrameData) -> c_int {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/tas_optimizer/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ impl Optimizer {
Line::Change(_) => (),
Line::TargetYawOverride(_) => (),
Line::RenderYawOverride(_) => (),
Line::PitchOverride(_) => (),
Line::RenderPitchOverride(_) => (),
}
}

Expand Down
50 changes: 42 additions & 8 deletions src/modules/tas_optimizer/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ impl<'a, T: Trace> Iterator for Simulator<'a, T> {
Line::Change(_) => (),
Line::TargetYawOverride(_) => (),
Line::RenderYawOverride(_) => (),
Line::PitchOverride(_) => (),
Line::RenderPitchOverride(_) => (),
}

// Advance to the next line for non-frame-bulks.
Expand Down Expand Up @@ -294,7 +296,11 @@ mod tests {
let lines = [Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 10.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 10.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand All @@ -319,7 +325,11 @@ mod tests {
Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 10.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 10.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand All @@ -338,7 +348,11 @@ mod tests {
Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 10.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 10.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand Down Expand Up @@ -369,7 +383,11 @@ mod tests {
let mut lines = vec![Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 200., 10.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 200.,
accel: 10.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand All @@ -393,7 +411,11 @@ mod tests {
lines.push(Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 10.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 10.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand All @@ -418,7 +440,11 @@ mod tests {
lines.push(Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 9.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 9.,
},
dir: StrafeDir::Left,
})),
leave_ground_action: None,
Expand All @@ -443,7 +469,11 @@ mod tests {
lines.push(Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(0., 210., 9.),
type_: StrafeType::MaxAccelYawOffset {
start: 0.,
target: 210.,
accel: 9.,
},
dir: StrafeDir::Right,
})),
leave_ground_action: None,
Expand All @@ -468,7 +498,11 @@ mod tests {
lines.push(Line::FrameBulk(FrameBulk {
auto_actions: AutoActions {
movement: Some(AutoMovement::Strafe(StrafeSettings {
type_: StrafeType::MaxAccelYawOffset(10., 210., 9.),
type_: StrafeType::MaxAccelYawOffset {
start: 10.,
target: 210.,
accel: 9.,
},
dir: StrafeDir::Right,
})),
leave_ground_action: None,
Expand Down
Loading

0 comments on commit 171d197

Please sign in to comment.