Skip to content

Commit

Permalink
feat: add splits to sar_timeline_show_completed
Browse files Browse the repository at this point in the history
  • Loading branch information
PortalRex authored Nov 24, 2024
1 parent b3eae9f commit 3937a28
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Features/SteamTimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ Timeline::Timeline() {
}

static std::chrono::time_point<std::chrono::system_clock> g_speedrunStart;
static std::vector<std::tuple<std::string, std::string, float>> g_pendingSplits;

void Timeline::StartSpeedrun() {
if (!steam->hasLoaded) return;
g_speedrunStart = std::chrono::system_clock::now();
g_pendingSplits.clear();

if (sar_timeline_show_completed.GetBool()) return;
steam->g_timeline->AddTimelineEvent("steam_timer", "Speedrun Start", "", 1, 0.0f, 0.0f, k_ETimelineEventClipPriority_Standard);
}

void Timeline::Split(std::string name, std::string time) {
if (!steam->hasLoaded) return;
if (!sar_timeline_splits.GetBool()) return;
steam->g_timeline->AddTimelineEvent("steam_bolt", name.c_str(), time.c_str(), 0, 0.0f, 0.0f, k_ETimelineEventClipPriority_None);
std::chrono::duration<float> currentOffset = std::chrono::system_clock::now() - g_speedrunStart;
if (sar_timeline_splits.GetBool()) {
steam->g_timeline->AddTimelineEvent("steam_bolt", name.c_str(), time.c_str(), 0, 0.0f, 0.0f, k_ETimelineEventClipPriority_None);
}

if (sar_timeline_show_completed.GetBool()) {
g_pendingSplits.push_back({name, time, currentOffset.count()});
}
}

ON_EVENT(SESSION_START) {
Expand All @@ -50,7 +58,20 @@ ON_EVENT(SPEEDRUN_FINISH) {

if (sar_timeline_show_completed.GetBool()) {
steam->g_timeline->AddTimelineEvent("steam_timer", "Speedrun Start", "", 1, -offset.count(), 0.0f, k_ETimelineEventClipPriority_Standard);

for (const auto &[splitName, splitTime, splitOffset] : g_pendingSplits) {
steam->g_timeline->AddTimelineEvent(
"steam_bolt",
splitName.c_str(),
splitTime.c_str(),
0,
splitOffset - offset.count(),
0.0f,
k_ETimelineEventClipPriority_None);
}
g_pendingSplits.clear();
}

steam->g_timeline->SetTimelineStateDescription(("Speedrun " + time).c_str(), -offset.count());
steam->g_timeline->ClearTimelineStateDescription(0.0f);
steam->g_timeline->AddTimelineEvent("steam_flag", "Speedrun Finish", time.c_str(), 1, 0.0f, 0.0f, k_ETimelineEventClipPriority_Standard);
Expand Down

0 comments on commit 3937a28

Please sign in to comment.