Skip to content

Commit

Permalink
add bxt_tas_studio_norefresh_until_stop_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Oct 27, 2023
1 parent 907146a commit 382c642
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/modules/tas_studio/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub struct Editor {
/// Whether the editor is in the camera editor mode.
in_camera_editor: bool,

/// Frame index calculated from bxt_tas_studio_norefresh_until_stop_frame.
norefresh_until_stop_frame_frame_idx: usize,

// ==============================================
// Movement-editor-specific state.
/// Index of the hovered frame bulk.
Expand Down Expand Up @@ -415,6 +418,7 @@ impl Editor {
smooth_window_s: 0.15,
smooth_small_window_s: 0.03,
smooth_small_window_multiplier: 3.,
norefresh_until_stop_frame_frame_idx: 0,
})
}

Expand Down Expand Up @@ -521,6 +525,10 @@ impl Editor {
self.show_player_bbox = value;
}

pub fn set_norefresh_until_stop_frame(&mut self, value: usize) {
self.norefresh_until_stop_frame_frame_idx = value;
}

/// Invalidates frames starting from given.
///
/// Erases cached frame data and adjusts the first predicted frame index if needed.
Expand Down Expand Up @@ -3361,6 +3369,9 @@ impl Editor {
let is_hovered = self.hovered_frame_idx == Some(idx);
// If frame is the stop frame.
let is_stop_frame = branch.branch.stop_frame as usize == idx;
// If frame is the end of norefresh for norefresh until stop frame.
let is_norefresh_until_stop_frame =
!is_stop_frame && self.norefresh_until_stop_frame_frame_idx == idx;

// If frame is in the smoothing input region.
let in_smoothing_input_region =
Expand Down Expand Up @@ -3681,6 +3692,24 @@ impl Editor {
});
}

// If bxt_tas_studio_norefresh_until_stop_frame is set, draw another indicator.
if is_norefresh_until_stop_frame {
let perp = perpendicular(prev_pos, pos) * 2.;
let diff = (pos - prev_pos).normalize_or_zero() * 2.;

// Draw the arrow.
draw(DrawLine {
start: pos - perp + diff,
end: pos,
color: Vec3::new(1., 1., 0.5),
});
draw(DrawLine {
start: pos,
end: pos + perp + diff,
color: Vec3::new(1., 1., 0.5),
});
}

if is_last_in_bulk {
// Reset flag for next iteration.
collided_this_bulk = false;
Expand Down
45 changes: 45 additions & 0 deletions src/modules/tas_studio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Module for TasStudio {
&BXT_TAS_STUDIO_SMOOTH_SMALL_WINDOW_S,
&BXT_TAS_STUDIO_SMOOTH_SMALL_WINDOW_MULTIPLIER,
&BXT_TAS_STUDIO_LINE_WIDTH,
&BXT_TAS_STUDIO_NOREFRESH_UNTIL_STOP_FRAME,
];
CVARS
}
Expand Down Expand Up @@ -385,6 +386,47 @@ fn convert_hltas_from_bxt_tas_new(marker: MainThreadMarker, mut path: String) {
)
}

static BXT_TAS_STUDIO_NOREFRESH_UNTIL_STOP_FRAME: CVar = CVar::new(
b"bxt_tas_studio_norefresh_until_stop_frame\0",
b"0\0",
"\
Specifies amount of frames before stop frame marker for playback.
This cvar will override the value bxt_tas_norefresh_until_last_frames. `0` will use the other one instead.",
);

fn norefresh_until_stop_frame_frame_idx(marker: MainThreadMarker, editor: &Editor) -> usize {
match (editor.stop_frame() as usize)
.checked_sub(BXT_TAS_STUDIO_NOREFRESH_UNTIL_STOP_FRAME.as_u64(marker) as usize)
{
Some(val) => val,
None => 0,
}
}

fn set_effective_norefresh_until_stop_frame(marker: MainThreadMarker, editor: &Editor) {
let is_norefresh_until_stop_frame =
BXT_TAS_STUDIO_NOREFRESH_UNTIL_STOP_FRAME.as_u64(marker) > 0;

if is_norefresh_until_stop_frame {
// Very sad
let value = match editor.branch().frames.len().checked_sub(1) {
Some(val) => {
match val.checked_sub(norefresh_until_stop_frame_frame_idx(marker, editor)) {
Some(val) => val,
None => 0,
}
}
None => 0,
};

engine::prepend_command(
marker,
&format!("bxt_tas_norefresh_until_last_frames {}\n", value),
);
}
}

static BXT_TAS_STUDIO_REPLAY: Command = Command::new(
b"bxt_tas_studio_replay\0",
handler!(
Expand All @@ -402,9 +444,11 @@ fn replay(marker: MainThreadMarker) {
mut editor, bridge, ..
} => {
editor.cancel_ongoing_adjustments();
set_effective_norefresh_until_stop_frame(marker, &editor);
State::PreparingToPlayToEditor(editor, bridge, true)
}
State::PlayingToEditor { editor, bridge, .. } => {
set_effective_norefresh_until_stop_frame(marker, &editor);
State::PreparingToPlayToEditor(editor, bridge, true)
}
other => other,
Expand Down Expand Up @@ -1767,6 +1811,7 @@ pub fn draw(marker: MainThreadMarker, tri: &TriangleApi) {
editor.set_smooth_small_window_multiplier(
BXT_TAS_STUDIO_SMOOTH_SMALL_WINDOW_MULTIPLIER.as_f32(marker),
);
editor.set_norefresh_until_stop_frame(norefresh_until_stop_frame_frame_idx(marker, editor));

// SAFETY: if we have access to TriangleApi, it's safe to do player tracing too.
let tracer = unsafe { Tracer::new(marker, true) }.unwrap();
Expand Down

0 comments on commit 382c642

Please sign in to comment.