Skip to content

Commit 2a47a4c

Browse files
committed
feat: sar_trace_playback_rate
this one's definitely only for cinematics (unless?)
1 parent 4913f17 commit 2a47a4c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/cvars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@
657657
|sar_trace_font_size|3.0|The size of text overlaid on recorded traces.|
658658
|sar_trace_hide|cmd|sar_trace_hide [trace name] - hide the trace with the given name|
659659
|sar_trace_override|1|Clears old trace when you start recording to it instead of recording on top of it.|
660+
|sar_trace_playback_rate|0|Playback rate of the trace bbox. Loops upon finishing.|
660661
|sar_trace_portal_opacity|100|Opacity of trace portal previews.|
661662
|sar_trace_portal_oval|0|Draw trace portals as ovals rather than rectangles.|
662663
|sar_trace_portal_record|1|Record portal locations.|

src/Features/PlayerTrace.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Variable sar_trace_font_size("sar_trace_font_size", "3.0", 0.1, "The size of tex
4040
Variable sar_trace_vphys_record("sar_trace_vphys_record", "1", 0, 1, "Record vphysics locations of dynamic entities for analysis.\n");
4141

4242
Variable sar_trace_reveal("sar_trace_reveal", "0", "Only draw traces until the specified tick. Set to bbox to draw until the bbox tick.\n");
43+
Variable sar_trace_playback_rate("sar_trace_playback_rate", "0", "Playback rate of the trace bbox. Loops upon finishing.\n");
4344

4445
Variable sar_trace_bbox_at("sar_trace_bbox_at", "-1", -1, "Display a player-sized bbox at the given tick.\n");
4546
Variable sar_trace_bbox_use_hover("sar_trace_bbox_use_hover", "0", 0, 1, "Move trace bbox to hovered trace point tick on given trace.\n");
@@ -828,6 +829,28 @@ ON_EVENT(SESSION_START) {
828829
playerTrace->ClearAll();
829830
}
830831

832+
ON_EVENT(PRE_TICK) {
833+
if (sar_trace_playback_rate.GetFloat() > 0) {
834+
playerTrace->Playback();
835+
}
836+
}
837+
838+
void PlayerTrace::Playback() {
839+
float tick = sar_trace_bbox_at.GetFloat() + sar_trace_playback_rate.GetFloat();
840+
841+
size_t max_tick = 0;
842+
for (auto it = playerTrace->traces.begin(); it != playerTrace->traces.end(); ++it) {
843+
const Trace &trace = it->second;
844+
max_tick = (std::max)(max_tick, trace.positions[0].size());
845+
max_tick = (std::max)(max_tick, trace.positions[1].size());
846+
}
847+
848+
if ((size_t)tick > max_tick) {
849+
tick = 0;
850+
}
851+
sar_trace_bbox_at.SetValue(tick);
852+
}
853+
831854
void PlayerTrace::DrawTraceHud(HudContext *ctx) {
832855
for (auto it = playerTrace->traces.begin(); it != playerTrace->traces.end(); ++it) {
833856
const char *name = it->first.c_str();

src/Features/PlayerTrace.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class PlayerTrace : public Feature {
104104
VphysLocationList ConstructVphysLocationList() const;
105105
// Construct a list of all portals in the map
106106
PortalLocations ConstructPortalLocations() const;
107+
// Increases bbox tick at the given speed
108+
void Playback();
107109
// Draw info about all traces to a HUD context
108110
void DrawTraceHud(HudContext *ctx);
109111
// Corrects latest eye offset according to given CMoveData, to make it correct for portal shooting preview

0 commit comments

Comments
 (0)