Skip to content

Commit

Permalink
Add bxt-rs camera replay related hooks (#519)
Browse files Browse the repository at this point in the history
* Add bxt-rs camera replay related hooks

* change bxt_on_tas_playback_frame to bxt_on_tas_playback_frame_v2
  • Loading branch information
khanghugo authored Jul 12, 2024
1 parent 712bc7c commit ebdee93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
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!
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

0 comments on commit ebdee93

Please sign in to comment.