Skip to content

Commit

Permalink
feat: improve render flow control when skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Aug 27, 2024
1 parent e43fb7d commit b7121e0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Features/Hud/AimPointHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static bool updateTrace(int slot) {
}

static void renderTrace(const CGameTrace &tr) {
if (engine->IsGamePaused() || engine->IsSkipping()) return;
if (engine->IsGamePaused()) return;

auto p = tr.endpos;
Vector norm = tr.plane.normal;
Expand Down
4 changes: 4 additions & 0 deletions src/Features/Hud/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ BaseHud::BaseHud(int type, bool drawSecondSplitScreen, int version)
, version(version) {
}
bool BaseHud::ShouldDraw() {
if (engine->IsForcingNoRendering()) {
return false;
}

if (engine->demoplayer->IsPlaying() || engine->IsOrange()) {
return this->type & HudType_InGame;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Features/PlayerTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ void PlayerTrace::ClearAll() {
traces.clear();
}
void PlayerTrace::DrawInWorld() const {
if (engine->IsSkipping()) return;

bool draw_through_walls = sar_trace_draw_through_walls.GetBool();

hovers.clear();
Expand Down Expand Up @@ -369,8 +367,6 @@ void PlayerTrace::DrawSpeedDeltas() const {
}
}
void PlayerTrace::DrawBboxAt(int tick) const {
if (engine->IsSkipping()) return;

static const Vector player_standing_size = {32, 32, 72};
static const Vector player_ducked_size = {32, 32, 36};

Expand Down Expand Up @@ -456,8 +452,6 @@ void PlayerTrace::DrawBboxAt(int tick) const {
}
}
void PlayerTrace::DrawPortalsAt(int tick) const {
if (engine->IsSkipping()) return;

for (const auto &[trace_idx, trace] : traces) {
if (!trace.draw) continue;
if (trace.portals.size() == 0) continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Routing/SeamshotFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CGameTrace TracePortalShot(const Vector &start, const Vector &dir, float length)
}

ON_EVENT(RENDER) {
if (sv_cheats.GetBool() && sar_seamshot_finder.GetBool() && !engine->IsSkipping()) {
if (sv_cheats.GetBool() && sar_seamshot_finder.GetBool()) {
void *player = server->GetPlayer(GET_SLOT() + 1);

if (player == nullptr || (int)player == -1)
Expand Down
1 change: 0 additions & 1 deletion src/Features/Speedrun/Categories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void SpeedrunTimer::ResetCategory() {
ON_EVENT(RENDER) {
if (!sar_speedrun_draw_triggers.GetBool()) return;
if (!sv_cheats.GetBool()) return;
if (engine->IsSkipping()) return;

for (std::string ruleName : g_categories[g_currentCategory].rules) {
auto rule = SpeedrunTimer::GetRule(ruleName);
Expand Down
11 changes: 9 additions & 2 deletions src/Modules/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ DETOUR(Engine::Frame) {
Renderer::Frame();
engine->demoplayer->HandlePlaybackFix();
Event::Trigger<Event::FRAME>({});
if (!engine->IsSkipping() && session->isRunning) Event::Trigger<Event::RENDER>({});

if (!engine->IsForcingNoRendering() && session->isRunning) {
Event::Trigger<Event::RENDER>({});
}

NetMessage::Update();

Expand Down Expand Up @@ -683,6 +686,10 @@ bool Engine::IsSkipping() {
return g_skipping;
}

bool Engine::IsForcingNoRendering() {
return g_skipping && !g_advancing && !engine->IsGamePaused();
}

static float *host_frametime;
static float *host_frametime_unbounded;
void Host_AccumulateTime_Detour(float dt);
Expand Down Expand Up @@ -791,7 +798,7 @@ void _Host_RunFrame_Render_Detour() {
uint64_t nframes = total_frames - init_frames;
g_cur_fps = (float)nframes / FPS_CHECK_WINDOW;
});
if (g_skipping && !g_advancing && !engine->IsGamePaused()) {
if (engine->IsForcingNoRendering()) {
// We need to do this or else the client doesn't update viewangles
// in response to portal teleportations (and it probably breaks some
// other stuff too). This would normally be done within
Expand Down
1 change: 1 addition & 0 deletions src/Modules/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Engine : public Module {
void AdvanceTick();
void SetSkipping(bool skipping);
bool IsSkipping();
bool IsForcingNoRendering();
Color GetLightAtPoint(Vector point);
bool GetPlayerInfo(int ent_num, player_info_t *pInfo);
std::string GetPartnerSteamID32();
Expand Down

0 comments on commit b7121e0

Please sign in to comment.