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-rs camera replay related hooks #519

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 27 additions & 5 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct on_tas_playback_frame_data {
std::array<float, 4> prev_predicted_trace_fractions;
std::array<float, 4> prev_predicted_trace_normal_zs;
on_tas_playback_frame_max_accel_yaw_offset max_accel_yaw_offset;
std::array<float, 3> rendered_viewangles;
};

// Change the variable name if you change the parameters!
Copy link
Owner

Choose a reason for hiding this comment

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

I guess this is the time when we need to change the name. I already forgot what I meant by "variable", but we can change the function name to bxt_on_tas_playback_frame_v2 since the ABI changes with the addition of a field in the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, as soon as #521 is merged then I can make changes to this (without weird conflicts)

Expand All @@ -49,7 +50,7 @@ extern "C" {
// BXT will call this right before running HLStrafe for every played back frame of a TAS.
//
// Return value != 0 will cause BXT to stop TAS playback.
DLLEXPORT int (*bxt_on_tas_playback_frame)(on_tas_playback_frame_data data);
DLLEXPORT int (*bxt_on_tas_playback_frame_v2)(on_tas_playback_frame_data data);

// BXT will call this when the TAS playback stops.
DLLEXPORT void (*bxt_on_tas_playback_stopped)();
Expand Down Expand Up @@ -2474,11 +2475,31 @@ cvar_t* HwDLL::FindCVar(const char* name)
return ORIG_Cvar_FindVar(name);
}

std::array<float, 3> HwDLL::GetRenderedViewangles() {
std::array<float, 3> res = {player.Viewangles[0], player.Viewangles[1], player.Viewangles[2]};

if (!PitchOverrides.empty()) {
res[0] = PitchOverrides[PitchOverrideIndex];
}
if (!RenderPitchOverrides.empty()) {
res[0] = RenderPitchOverrides[RenderPitchOverrideIndex];
}

if (!TargetYawOverrides.empty()) {
res[1] = TargetYawOverrides[TargetYawOverrideIndex];
}
if (!RenderYawOverrides.empty()) {
res[1] = RenderYawOverrides[RenderYawOverrideIndex];
}

return res;
}

int HwDLL::CallOnTASPlaybackFrame() {
if (!bxt_on_tas_playback_frame)
if (!bxt_on_tas_playback_frame_v2)
return 0;

return bxt_on_tas_playback_frame(on_tas_playback_frame_data {
return bxt_on_tas_playback_frame_v2(on_tas_playback_frame_data {
StrafeState.StrafeCycleFrameCount,
PrevFractions,
PrevNormalzs,
Expand All @@ -2489,6 +2510,7 @@ int HwDLL::CallOnTASPlaybackFrame() {
StrafeState.MaxAccelYawOffsetAccel, // accel
static_cast<unsigned char>(StrafeState.MaxAccelYawOffsetDir), // dir
},
GetRenderedViewangles(),
});
}

Expand Down Expand Up @@ -6127,7 +6149,7 @@ void HwDLL::InsertCommands()
pushables,
});

if (bxt_on_tas_playback_frame) {
if (bxt_on_tas_playback_frame_v2) {
const auto stop = CallOnTASPlaybackFrame();
if (stop) {
ResetTASPlaybackState();
Expand Down Expand Up @@ -6661,7 +6683,7 @@ void HwDLL::InsertCommands()
RenderPitchOverrides.clear();
RenderPitchOverrideIndex = 0;

if (bxt_on_tas_playback_frame) {
if (bxt_on_tas_playback_frame_v2) {
// We don't use the return value here because we stop anyway.
CallOnTASPlaybackFrame();
}
Expand Down
2 changes: 2 additions & 0 deletions BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ class HwDLL : public IHookableNameFilterOrdered

bool is_cof_steam = false; // Cry of Fear-specific

// For bxt-rs rendered view playback.
std::array<float, 3> GetRenderedViewangles();
int CallOnTASPlaybackFrame();
void CallOnTASPlaybackStopped();
void ResetTASPlaybackState();
Expand Down