Ask the client for frames between its steps
CI / build (push) Successful in 1m31s

The frame pacer repaints the client's 3D windows at the user's frame rate
(HKCU\Software\T5DE\Graphics\FrameRate: 30, the default, adds nothing; 60, 120,
240, 360; 0 uncapped), so the client draws frames between its 30-per-second
steps. Only when affordable: a window is asked once its last frame is drawn,
and only if its frames take under three quarters of the interval; uncapped,
the client is left idle a third of a frame between frames. The engine's stats
now log frames per second.

The extra frames show the same scene for now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-28 20:38:31 -07:00
1 parent 8055099920
commit 05a7be5d41
7 files changed
+233 -18

No files matched your search

+36 -9
View File
@@ -7,6 +7,7 @@
#include <cstring>
#include <vector>
#include "frame_pacer.hpp"
#include "log.hpp"
#include "resources.hpp"
@@ -29,12 +30,22 @@ protocol::SetTransform transform_command(const imvu::Transform& t)
} // namespace
Engine::Engine(imvu::SharedPtr<imvu::PiRenderEngine> inner, std::shared_ptr<Recorder> recorder)
: inner_(std::move(inner)), recorder_(std::move(recorder))
Engine::Engine(imvu::SharedPtr<imvu::PiRenderEngine> inner, std::shared_ptr<Recorder> recorder, HWND window)
: inner_(std::move(inner)), recorder_(std::move(recorder)), window_(window)
{
QueryPerformanceCounter(&statsStart_);
if (window_ != nullptr) {
frame_pacer::add(window_);
}
}
Engine::~Engine() { log::info("engine: destroyed after {} frames", frames_); }
Engine::~Engine()
{
if (window_ != nullptr) {
frame_pacer::remove(window_);
}
log::info("engine: destroyed after {} frames", frames_);
}
void Engine::setState(State state, std::uint32_t value)
{
@@ -249,6 +260,8 @@ imvu::SharedPtr<imvu::PiTextureRenderTarget> Engine::newTextureRenderTarget(imvu
void Engine::beginRendering(imvu::PiRenderTarget* target)
{
QueryPerformanceCounter(&frameStart_);
windowFrame_ = target == nullptr;
// Frames into our render targets are drawn by the renderer process only; the client's renderer doesn't know them.
ourTarget_ = ours(target) ? target : nullptr;
if (ourTarget_ == nullptr) {
@@ -286,15 +299,29 @@ void Engine::endRendering()
recorder_->flush(true);
if (auto* pixmap = dynamic_cast<PixmapTarget*>(ourTarget_)) {
pixmap->setPixels(recorder_->readBack());
} else if (windowFrame_ && window_ != nullptr) {
LARGE_INTEGER end, frequency;
QueryPerformanceCounter(&end);
QueryPerformanceFrequency(&frequency);
frame_pacer::frameDrawn(window_, static_cast<double>(end.QuadPart - frameStart_.QuadPart) /
static_cast<double>(frequency.QuadPart));
}
ourTarget_ = nullptr;
++frames_;
if (frames_ % 300 == 0 && statsLogged_ < 6) {
++statsLogged_;
log::info("engine: last 300 frames: drawTriangles {} (and {} with buffers not ours), drawTrianglesFromMemory {} "
"(and {} without indices), point sprites {}, lines {}, 2D projections {}",
stats_.triangles, stats_.foreignTriangles, stats_.indexed, stats_.unindexed, stats_.sprites, stats_.lines,
stats_.flat);
if (frames_ % 300 == 0) {
LARGE_INTEGER ended, frequency;
QueryPerformanceCounter(&ended);
QueryPerformanceFrequency(&frequency);
const double seconds =
static_cast<double>(ended.QuadPart - statsStart_.QuadPart) / static_cast<double>(frequency.QuadPart);
statsStart_ = ended;
if (statsLogged_ < 6 || frames_ % 3000 == 0) {
++statsLogged_;
log::info("engine: last 300 frames: {:.0f} per second; drawTriangles {} (and {} with buffers not ours), "
"drawTrianglesFromMemory {} (and {} without indices), point sprites {}, lines {}, 2D projections {}",
300 / seconds, stats_.triangles, stats_.foreignTriangles, stats_.indexed, stats_.unindexed,
stats_.sprites, stats_.lines, stats_.flat);
}
stats_ = {};
}
}