Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bxt_cap_time_* #68

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/modules/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use color_eyre::eyre::Context;

use super::cvars::CVar;
use super::{capture_video_per_demo, Module};
use crate::hooks::engine::{self, con_print};
use crate::hooks::engine::{self, con_print, prepend_command};
use crate::modules::commands::Command;
use crate::utils::*;
use crate::{gl, handler};
Expand Down Expand Up @@ -36,6 +36,8 @@ impl Module for Capture {
&BXT_CAP_FORCE_FALLBACK,
&BXT_CAP_OVERRIDE_FFMPEG_ARGS,
&BXT_CAP_SAMPLING_MIN_FPS,
&BXT_CAP_TIME_START,
&BXT_CAP_TIME_END,
];
CVARS
}
Expand Down Expand Up @@ -281,6 +283,7 @@ pub fn cap_stop(marker: MainThreadMarker) {
}

capture_video_per_demo::stop(marker);
TIME.set(marker, 0.);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be zeroed on cap start, not stop.

}

pub unsafe fn capture_frame(marker: MainThreadMarker) {
Expand Down Expand Up @@ -472,6 +475,12 @@ pub unsafe fn on_host_filter_time(marker: MainThreadMarker) -> bool {
}

let time = recorder.time_for_current_frame();

if TIME.get(marker) < BXT_CAP_TIME_START.as_f32(marker) as f64 {
*engine::realtime.get(marker) += *engine::host_frametime.get(marker);
return true;
}

*engine::host_frametime.get(marker) = time;
*engine::realtime.get(marker) += time;

Expand Down Expand Up @@ -515,13 +524,37 @@ pub fn prevent_toggle_console(marker: MainThreadMarker) -> bool {
INSIDE_KEY_EVENT.get(marker)
}

static BXT_CAP_TIME_START: CVar = CVar::new(
b"bxt_cap_time_start\0",
b"0\0",
"Skips some seconds into the demo to start capturing.",
);

static BXT_CAP_TIME_END: CVar = CVar::new(
b"bxt_cap_time_end\0",
b"0\0",
"Specifies how many seconds into the demo to stop capturing. `0` for full demo.",
);

static TIME: MainThreadCell<f64> = MainThreadCell::new(0.);

pub unsafe fn time_passed(marker: MainThreadMarker) {
let mut state = STATE.borrow_mut(marker);
let State::Recording(ref mut recorder) = *state else { return };

// Accumulate time for the last frame.
let time = *engine::host_frametime.get(marker);

if TIME.get(marker) < BXT_CAP_TIME_START.as_f32(marker) as f64 {
TIME.set(marker, TIME.get(marker) + time);
prepend_command(marker, "r_norefresh 1\n");
return;
}

prepend_command(marker, "r_norefresh 0\n");

// Accumulate time for the last frame.
recorder.time_passed(time);
TIME.set(marker, TIME.get(marker) + time);

// Capture sound ASAP.
//
Expand All @@ -531,4 +564,10 @@ pub unsafe fn time_passed(marker: MainThreadMarker) {
// video.
drop(state);
capture_sound(marker, SoundCaptureMode::Normal);

if BXT_CAP_TIME_END.as_f32(marker) != 0.
&& TIME.get(marker) >= BXT_CAP_TIME_END.as_f32(marker) as f64
{
cap_stop(marker);
}
}