Never make the client wait for drawing, or hold up its steps
CI / build (push) Successful in 1m15s

The renderer process now takes each view's chunks on a thread of its own as
they come, and draws the newest frame on its main thread: the client no longer
waits for the previous frame to be drawn (on a VM, 22 of a frame's 25 ms).

The adapter records the client's steps (SceneViewer::step, by replacing its
entry in the exported IFrameListener vtable, after checking it), and the frame
pacer doesn't ask for a frame that wouldn't end before the next step is due: a
late step made the client catch up two at once, which showed as hitches. While
the renderer process covers the view, the client's renderer doesn't begin or
present frames, which could wait for the display.

The engine's stats now include the time in the client renderer's methods.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-28 21:30:46 -07:00
1 parent 399d934a08
commit 065c7e9300
11 files changed
+280 -78

No files matched your search

+20 -2
View File
@@ -1,12 +1,14 @@
#include "frame_pacer.hpp"
#include <algorithm>
#include <cstdint>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include "log.hpp"
#include "scene_hooks.hpp"
namespace t5de::frame_pacer {
@@ -16,6 +18,10 @@ namespace {
constexpr DWORD clientRate = 30;
// The client is left idle at least this share of a frame's time between frames.
constexpr double idleShare = 1.0 / 3.0;
// The client's tick (SceneWindow.dll's millisecondsPerFrame).
constexpr double tickSeconds = 0.033;
// An extra frame must end at least this long before the next tick is due.
constexpr double tickMargin = 0.001;
// The user's frame rate, from the registry (unset or unreadable: the client's own).
DWORD read_rate()
@@ -29,16 +35,21 @@ DWORD read_rate()
return rate;
}
double now_seconds()
double seconds(std::int64_t counter)
{
static const double frequency = [] {
LARGE_INTEGER value;
QueryPerformanceFrequency(&value);
return static_cast<double>(value.QuadPart);
}();
return static_cast<double>(counter) / frequency;
}
double now_seconds()
{
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return static_cast<double>(counter.QuadPart) / frequency;
return seconds(counter.QuadPart);
}
class Pacer {
@@ -108,12 +119,19 @@ private:
continue;
}
const double interval = rate == 0 ? 0 : 1.0 / rate;
// The next tick, if known (scene_hooks.hpp): extra frames mustn't hold it up, or the client catches up two
// steps at once (visible hitches).
const std::int64_t lastStep = scene_hooks::lastStep();
const double untilTick = lastStep != 0 ? seconds(lastStep) + tickSeconds - now : tickSeconds;
{
const std::scoped_lock lock(mutex_);
for (Window& w : windows_) {
if (w.pending && now - w.askedAt < 0.25) {
continue; // not drawn yet (asked again after a while: the client may have skipped it)
}
if (untilTick > -tickSeconds && untilTick < w.frameTime + tickMargin) {
continue; // the tick is due: it draws a frame of its own
}
// Since the last frame ended: the rest of the interval since it began, and the idle time.
if (now - w.drawnAt >= std::max(interval - w.frameTime, w.frameTime * idleShare)) {
w.pending = true;