Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Redraw on demand (#14): idle, the app draws nothing instead of 60+ frames a second
islandmed578e81d593fd
diff --git a/CMakeLists.txt b/CMakeLists.txtindex df673e72..87a38cf5 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -529,6 +529,9 @@ if(SCULPTFORGE_BUILD_TESTS)add_test(NAME ui_user_guide_1080 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/user_guide.sfui--size 1920x1080 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/user_guide_1080)set_tests_properties(ui_user_guide_1080 PROPERTIES LABELS ui TIMEOUT 300)+ # Idle, the app draws nothing (#14): --measure-idle fails when it keeps drawing frames.+ add_test(NAME ui_idle_redraw COMMAND sculptforge --measure-idle 4)+ set_tests_properties(ui_idle_redraw PROPERTIES LABELS ui TIMEOUT 60 ENVIRONMENT "SF_NO_UPDATE_CHECK=1")# The guide's keyboard table must match the app's default shortcuts (tools/guide/update_shortcuts.py).if(Python3_Interpreter_FOUND)sculptforge_runner(SCULPTFORGE_APP_RUNNER sculptforge)diff --git a/src/app/App.cpp b/src/app/App.cppindex fa54ff1a..f6ae72a3 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -26,6 +26,10 @@#include <imgui_impl_opengl3.h>#include <imgui_impl_sdl3.h>+#include <cstdio>+#include <ctime>+#include <cstdlib>+#include <functional>#include <algorithm>#include <chrono>#include <cfloat>@@ -554,16 +558,121 @@ int App::runRecording() {return status == 0 ? 0 : 1;}+namespace {++Uint32 g_wakeEvent = 0; // registered in App::run(); 0 before++constexpr int kIdleTickMs = 250; // asleep: wake this often to run the pollers (the Blender bridge, autosave)+constexpr int kCaretTickMs = 530; // a text field has the keyboard: redraw for the caret's blink+constexpr double kAfterChangeSeconds = 0.25; // a poller changed something: draw for this long++} // namespace++void wakeMainLoop() {+ if (g_wakeEvent == 0) return;+ SDL_Event e{};+ e.type = g_wakeEvent;+ SDL_PushEvent(&e);+}++bool App::backgroundBusy() const {+ auto running = [](const auto& f) { return f.valid() && f.wait_for(std::chrono::seconds(0)) != std::future_status::ready; };+ return running(pendingBrush_) || running(pendingGenerator_) || running(pendingModels_) || running(pendingUnreal_) ||+ running(pendingComfyCheck_) || galleryBusy() || thumbs_.busy() || libraryScanner_.busy() || autoUv_ ||+ bakeBusy() || qremesh_ || voxelRemesh_ || updateJob_ || splatTrainBusy() || sculptableBusy() || phoneBusy();+}++void App::redrawIn(double seconds) {+ const double at = double(SDL_GetTicksNS()) * 1e-9 + seconds;+ redrawAt_ = redrawAt_ > 0.0 ? std::min(redrawAt_, at) : at;+}++bool App::wantsFrames(double now) const {+ return now < activeUntil_ || drag_ != Drag::None || doc_.sculptor.strokeActive() || backgroundBusy() ||+ playingLayer_ >= 0 || faceTakePlaying_ ||+ perf_.framesStill < 10; // the view just moved: Fast Navigation's full-quality frame comes after it stops+}++uint64_t App::frameKey() const {+ uint64_t h = std::hash<std::string>{}(status_) ^ (std::hash<std::string>{}(updateStatus_) << 1);+ for (const uint64_t v : {uint64_t(doc_.undo.revision()), uint64_t(doc_.splatsVersion), uint64_t(doc_.modified),+ uint64_t(doc_.subtoolCount()), uint64_t(int64_t(doc_.activeSubtool))})+ h = h * 1099511628211ull ^ v;+ return h;+}+int App::run() {if (!options_.renderPath.empty()) return renderHeadless();if (!options_.recordPath.empty() || !options_.uiTest.empty()) return runRecording();+ if (g_wakeEvent == 0) g_wakeEvent = SDL_RegisterEvents(1);+ // SF_CONTINUOUS_REDRAW=1 draws every frame as before 0.9.5 (for comparison, or a driver that misbehaves).+ const char* continuousEnv = std::getenv("SF_CONTINUOUS_REDRAW");+ const bool continuous = continuousEnv && *continuousEnv && *continuousEnv != '0';+ const bool logRedraw = std::getenv("SF_REDRAW_LOG") != nullptr; // why each frame is drawn (bug reports)+ auto seconds = [] { return double(SDL_GetTicksNS()) * 1e-9; };+ // --measure-idle: let start-up settle (first frames, the LightBox's thumbnails), then count.+ constexpr double kMeasureSettle = 3.0;+ const double started = seconds();+ uint64_t framesDrawn = 0, wakeUps = 0, framesAtMeasure = 0, wakesAtMeasure = 0;+ std::clock_t cpuAtMeasure = 0; // processor time of every thread (the driver's included)+ bool measuring = false;Uint64 lastTicks = SDL_GetTicksNS();+ uint64_t lastKey = frameKey();+ bool draw = true;+ activeUntil_ = started + 1.0;while (running_) {+ const double t0 = seconds();+ if (options_.measureIdle > 0.0f) {+ if (!measuring && t0 - started >= kMeasureSettle) {+ measuring = true;+ framesAtMeasure = framesDrawn;+ wakesAtMeasure = wakeUps;+ cpuAtMeasure = std::clock();+ } else if (measuring && t0 - started >= kMeasureSettle + options_.measureIdle) {+ const double fps = double(framesDrawn - framesAtMeasure) / double(options_.measureIdle);+ const double cpu = 100.0 * double(std::clock() - cpuAtMeasure) / CLOCKS_PER_SEC / double(options_.measureIdle);+ std::printf("Idle: %llu frames, %llu wake-ups in %.1f s: %.2f fps, CPU %.1f%% of one core (%s redraw)\n",+ (unsigned long long)(framesDrawn - framesAtMeasure), (unsigned long long)(wakeUps - wakesAtMeasure),+ double(options_.measureIdle), fps, cpu, continuous ? "continuous" : "on-demand");+ std::fflush(stdout);+ // Idle is 0 fps; a pointer crossing the window draws about a second's worth. Every frame is 60+.+ return continuous || fps < 5.0 ? 0 : 1;+ }+ }+ // Nothing to draw: sleep until an event, or the next poller tick.+ const ImGuiIO& io = ImGui::GetIO();+ // Input keeps the frames coming a little while (hover highlights, tooltips after their delay); other+ // events (the window shown, moved, focused) need a frame or two.+ const auto onEvent = [&](const SDL_Event& ev) {+ handleEvent(ev);+ if (ev.type == SDL_EVENT_KEYMAP_CHANGED || ev.type == SDL_EVENT_KEYBOARD_ADDED ||+ ev.type == SDL_EVENT_KEYBOARD_REMOVED || ev.type == SDL_EVENT_MOUSE_ADDED ||+ ev.type == SDL_EVENT_MOUSE_REMOVED || ev.type == SDL_EVENT_CLIPBOARD_UPDATE)+ return; // nothing on screen changes+ draw = true;+ if (logRedraw) SDL_Log("redraw: event 0x%x", unsigned(ev.type));+ const bool input = (ev.type >= SDL_EVENT_KEY_DOWN && ev.type < SDL_EVENT_JOYSTICK_AXIS_MOTION) ||+ (ev.type >= SDL_EVENT_FINGER_DOWN && ev.type <= SDL_EVENT_FINGER_CANCELED) ||+ (ev.type >= SDL_EVENT_PEN_PROXIMITY_IN && ev.type <= SDL_EVENT_PEN_AXIS) ||+ ev.type == SDL_EVENT_DROP_FILE;+ const double t = seconds();+ activeUntil_ = std::max(activeUntil_, t + (input ? std::max(0.75, double(uiPrefs_.tooltipDelay) + 0.5) : 0.1));+ };+ SDL_Event e;+ if (!continuous && !draw) {+ int timeout = io.WantTextInput ? kCaretTickMs : kIdleTickMs;+ if (redrawAt_ > 0.0) timeout = std::clamp(int((redrawAt_ - t0) * 1000.0) + 1, 0, timeout);+ if (SDL_WaitEventTimeout(&e, timeout)) {+ onEvent(e);+ } else if (io.WantTextInput) {+ draw = true; // the caret blinks+ }+ ++wakeUps;+ }+ while (SDL_PollEvent(&e)) onEvent(e);Uint64 now = SDL_GetTicksNS();float dt = float(double(now - lastTicks) * 1e-9);lastTicks = now;- SDL_Event e;- while (SDL_PollEvent(&e)) handleEvent(e);processPendingFiles();animateLayers(dt);pollBrushRequest();@@ -577,12 +686,25 @@ int App::run() {pollQRemesh();pollSplatTrain();pollSculptable();+ tickProject(dt); // the title and autosave, asleep or not+ const double t = seconds();+ if (const uint64_t key = frameKey(); key != lastKey) { // a job finished, the Blender bridge sent a model...+ lastKey = key;+ draw = true;+ if (logRedraw) SDL_Log("redraw: changed (status \"%s\")", status_.c_str());+ activeUntil_ = std::max(activeUntil_, t + kAfterChangeSeconds);+ }+ if (redrawAt_ > 0.0 && t >= redrawAt_) {+ redrawAt_ = 0.0;+ draw = true;+ }+ if (!draw && !continuous && !wantsFrames(t)) continue;int fbW = 0, fbH = 0, winW = 0, winH = 0;SDL_GetWindowSizeInPixels(window_, &fbW, &fbH);SDL_GetWindowSize(window_, &winW, &winH);if (fbW <= 0 || fbH <= 0) {- SDL_Delay(16);+ draw = false; // minimised: the next event (restore) draws againcontinue;}updateCameraAspect();@@ -602,7 +724,12 @@ int App::run() {renderSettings_.motionProxy = false; // (other renders, e.g. project thumbnails, draw in full)ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());SDL_GL_SwapWindow(window_);- tickProject(dt);+ ++framesDrawn;+ lastKey = frameKey(); // what this frame changed is on screen already+ draw = continuous || wantsFrames(seconds());+ if (logRedraw && draw && !continuous)+ SDL_Log("redraw: keep drawing (input %d, drag %d, busy %d, view moved %d)", int(seconds() < activeUntil_),+ int(drag_ != Drag::None), int(backgroundBusy()), int(perf_.framesStill < 10));}finishProject();return 0;@@ -1132,6 +1259,7 @@ void App::runCommand(const std::string& name, const Args& args) {namespace {void SDLCALL onFileChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* req = static_cast<App::DialogRequest*>(userdata);req->app->queueFile(req->action, files[0]);diff --git a/src/app/App.h b/src/app/App.hindex 5608ae41..a62e63ed 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -70,10 +70,15 @@ struct AppOptions {std::string uiTest; // run this .sfui UI test script headless and exit (see UiTest.cpp)std::string uiOutDir; // where UI tests save screenshotsbool fullscreen = false; // start fullscreen (F11 toggles)+ float measureIdle = 0.0f; // --measure-idle S: after a settling pause, count the frames drawn in S idle seconds, exit};class Demo;+// Wakes the main loop from any thread (SDL_PushEvent): the app draws only when something changed (#14), so work+// that finishes off the main thread (a file dialog's answer, a phone message) calls this to be seen at once.+void wakeMainLoop();+class App {friend class Demo;// ZBrush-style shell modules (see ui-spec): they read and drive the app's state directly.@@ -88,6 +93,9 @@ public:~App();bool init(const AppOptions& options);int run(); // returns the process exit code+ // Redraw on demand (#14): the interactive loop sleeps in SDL_WaitEventTimeout until an event, a background+ // job or an animation needs a new frame. UI tests and recordings (runRecording) draw every frame as before.+ bool backgroundBusy() const; // a background job runs (also the UI tests' wait_idle)ActionRegistry& actions() { return actions_; }UiLayout& layout() { return layout_; }@@ -1109,6 +1117,14 @@ private:bool maskClickPending_ = false; // Ctrl+press on the model: a click blurs (Alt: sharpens), a drag paintsfloat maskClickX_ = 0.0f, maskClickY_ = 0.0f;// ---- end ZBrush feel ----+ // ---- Redraw on demand (App.cpp run()) ----+ bool wantsFrames(double now) const; // something animates or runs: keep drawing+ uint64_t frameKey() const; // changes when a poller changed what the window shows+ double activeUntil_ = 0.0; // seconds: keep drawing until then (after input: hover, tooltips)+ double redrawAt_ = 0.0; // seconds (SDL clock): draw one frame then, asleep or not (0: none)+public:+ void redrawIn(double seconds); // something on screen changes by itself later (an error colour fading)+private:// ---- Tablet (Tablet.cpp, core/Tablet.h, docs/tablet.md) ----// SDL turns pen tip contact into left mouse button events (SDL_PEN_MOUSEID); the pen's own events// add pressure, tilt, the eraser end and the side buttons, which are mapped in Preferences > Tablet.diff --git a/src/app/Config.cpp b/src/app/Config.cppindex 23c50a29..989e78f8 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -97,6 +97,7 @@ struct UiFileRequest {UiFileRequest g_requests[kUiFileKinds];void SDLCALL onUiFileChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* req = static_cast<UiFileRequest*>(userdata);req->app->queueUiFile(req->kind, files[0]);diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cppindex d778d423..dea39831 100644--- a/src/app/LightBox.cpp+++ b/src/app/LightBox.cpp@@ -105,6 +105,7 @@ const BrushAlpha& builtinAlpha(int i) {const char* const kAlphaNames[] = {"Round", "Square", "Noise"};void SDLCALL onFolderChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (files && files[0]) static_cast<LightBox*>(userdata)->folderChosen(files[0]);}diff --git a/src/app/PanelBake.cpp b/src/app/PanelBake.cppindex 91aafe1d..ae253c1a 100644--- a/src/app/PanelBake.cpp+++ b/src/app/PanelBake.cpp@@ -137,6 +137,7 @@ namespace {std::mutex g_folderMutex;std::string g_pickedFolder;void SDLCALL onBakeFolder(void*, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;std::lock_guard lock(g_folderMutex);g_pickedFolder = files[0];diff --git a/src/app/PanelBrushes.cpp b/src/app/PanelBrushes.cppindex 07760a9b..cdbd81f4 100644--- a/src/app/PanelBrushes.cpp+++ b/src/app/PanelBrushes.cpp@@ -15,6 +15,7 @@ namespace sf {void SDLCALL App::onAlphaChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* app = static_cast<App*>(userdata);std::lock_guard lock(app->alphaMutex_);diff --git a/src/app/PanelFace.cpp b/src/app/PanelFace.cppindex b815574c..39535c6e 100644--- a/src/app/PanelFace.cpp+++ b/src/app/PanelFace.cpp@@ -51,6 +51,7 @@ const ShapeGroup kGroups[] = {{"Eyes", {"eye"}}, {"Brows", {"brow"}},} // namespacevoid SDLCALL App::onFaceTakeChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* app = static_cast<App*>(userdata);std::lock_guard lock(app->faceTakeMutex_);diff --git a/src/app/PanelGoz.cpp b/src/app/PanelGoz.cppindex 66a6635f..f3c49471 100644--- a/src/app/PanelGoz.cpp+++ b/src/app/PanelGoz.cpp@@ -24,6 +24,7 @@ long long fileTime(const std::string& path) {} // namespacevoid SDLCALL App::onGozFileChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* req = static_cast<GozDialog*>(userdata);std::string path = files[0];diff --git a/src/app/PanelPhone.cpp b/src/app/PanelPhone.cppindex 8f26600b..68ba415d 100644--- a/src/app/PanelPhone.cpp+++ b/src/app/PanelPhone.cpp@@ -119,7 +119,10 @@ void App::setPhoneLinkOpen(bool open) {return;}if (phone_ && phone_->running()) return;- if (!phone_) phone_ = std::make_unique<link::PhoneLink>();+ if (!phone_) {+ phone_ = std::make_unique<link::PhoneLink>();+ phone_->setWake(wakeMainLoop); // the app sleeps while idle (#14): a phone message wakes it+ }phoneError_.clear();if (library_.user.empty()) {phoneError_ = "The phone link saves into your library's Captures folder: set a library in Preferences > LightBox.";diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex 471cc09e..c9709406 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -60,6 +60,7 @@ void readBool(const Json& j, const char* key, bool& v) { v = j[key].asBool(v); }// Save As dialog: a cancelled dialog is reported as an empty path so a pending// "save, then quit/open/new" is dropped instead of firing on a later save.void SDLCALL onProjectChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowauto* req = static_cast<App::DialogRequest*>(userdata);req->app->queueFile(req->action, files && files[0] ? std::string(files[0]) : std::string());}diff --git a/src/app/PanelSplatTrain.cpp b/src/app/PanelSplatTrain.cppindex 50e1edf6..cd62a44a 100644--- a/src/app/PanelSplatTrain.cpp+++ b/src/app/PanelSplatTrain.cpp@@ -53,6 +53,7 @@ enum class Pick { None, Video, Folder, Brush, Colmap };std::mutex g_pickMutex;std::vector<std::pair<Pick, std::string>> g_picked;void SDLCALL onPicked(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;std::lock_guard lock(g_pickMutex);g_picked.emplace_back(Pick(reinterpret_cast<intptr_t>(userdata)), files[0]);diff --git a/src/app/PanelSubTools.cpp b/src/app/PanelSubTools.cppindex 4f0dde66..7fe42d10 100644--- a/src/app/PanelSubTools.cpp+++ b/src/app/PanelSubTools.cpp@@ -32,6 +32,7 @@ const SDL_DialogFileFilter kAppendFilters[] = {{"Models and projects", "obj;fbx;glb;gltf;ply;stl;GoZ;goz;usda;usd;usdz;sfproj"}, {"All files", "*"}};void SDLCALL onAppendChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* req = static_cast<App::DialogRequest*>(userdata);req->app->queueFile(req->action, files[0]);diff --git a/src/app/PanelTexture.cpp b/src/app/PanelTexture.cppindex 5a5a30f3..a16115cf 100644--- a/src/app/PanelTexture.cpp+++ b/src/app/PanelTexture.cpp@@ -45,6 +45,7 @@ const SDL_DialogFileFilter kPngFilter[] = {{"PNG image", "png"}};const SDL_DialogFileFilter kImageFilters[] = {{"Images", "png;jpg;jpeg;tga;bmp;psd"}, {"All files", "*"}};void SDLCALL onTextureFile(void* user, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* d = static_cast<TextureDialog*>(user);std::string path = files[0];diff --git a/src/app/PanelVdm.cpp b/src/app/PanelVdm.cppindex 0e03c2b3..ae2efb06 100644--- a/src/app/PanelVdm.cpp+++ b/src/app/PanelVdm.cpp@@ -33,6 +33,7 @@ void actionButton(App& app, const char* id, float width = -1.0f) {} // namespacevoid SDLCALL App::onVdmChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* app = static_cast<App*>(userdata);std::lock_guard lock(app->vdmMutex_);@@ -40,6 +41,7 @@ void SDLCALL App::onVdmChosen(void* userdata, const char* const* files, int) {}void SDLCALL App::onVdmExportChosen(void* userdata, const char* const* files, int) {+ wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw nowif (!files || !files[0]) return;auto* app = static_cast<App*>(userdata);std::lock_guard lock(app->vdmMutex_);diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex d564847c..8fa2aa55 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -658,6 +658,7 @@ void App::drawShell() {if (status_ != statusShown_) {statusShown_ = status_;statusSince_ = ImGui::GetTime();+ if (!lastCommandOk_) redrawIn(6.05); // the error colour below goes after 6 s, idle or not}drawCanvasFrame();drawTitleStrip(shell_);diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 989f314b..b5ed9280 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -1116,11 +1116,7 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& e// between let the test run on before it started (ui_lightbox failed that way under a loaded ctest -j).auto idleFrames = std::make_shared<int>(0);steps_.push_back([this, line, timeout, idleFrames](float t) {- const bool idle = !busy(app_.pendingBrush_) && !busy(app_.pendingGenerator_) && !busy(app_.pendingModels_) &&- !busy(app_.pendingUnreal_) && !busy(app_.pendingComfyCheck_) && !app_.galleryBusy() &&- !app_.thumbs_.busy() && !app_.libraryScanner_.busy() && !app_.autoUv_ &&- !app_.bakeBusy() && !app_.qremesh_ && !app_.voxelRemesh_ && !app_.updateJob_ &&- !app_.splatTrainBusy() && !app_.sculptableBusy() && !app_.phoneBusy();+ const bool idle = !app_.backgroundBusy(); // (the same list keeps the app's loop drawing, #14)*idleFrames = idle ? *idleFrames + 1 : 0;if (*idleFrames >= 4) return true;if (idle) return false;diff --git a/src/app/main.cpp b/src/app/main.cppindex 1c757068..6b83ed79 100644--- a/src/app/main.cpp+++ b/src/app/main.cpp@@ -22,6 +22,8 @@ void usage() {" --render out.png Render headless and exit (thumbnails, review sheets)\n"" --turntable N With --render: N frames around the model (out_000.png ...)\n"" --size WxH Render size (default 1024x1024)\n"+ " --measure-idle S Sit idle, print the frames drawn per second over S seconds, exit\n"+ " (SF_CONTINUOUS_REDRAW=1 draws every frame, as before 0.9.5)\n"" --view YAW,PITCH Camera angles in degrees (default -30,-15)\n"" --zoom F Move the camera F times closer than the framed view (default 1)\n"" --wireframe Render with wireframe overlay\n"@@ -102,6 +104,7 @@ int main(int argc, char** argv) {else if (a == "--fullscreen") options.fullscreen = true;else if (a == "--blender") options.blender = true;else if (a == "--ui-out") options.uiOutDir = next();+ else if (a == "--measure-idle") options.measureIdle = std::max(0.5f, float(std::atof(next().c_str())));else if (a == "-h" || a == "--help") {usage();return 0;@@ -117,6 +120,7 @@ int main(int argc, char** argv) {if (!sizeGiven) options.width = 1600, options.height = 960;isolateSettings();}+ if (options.measureIdle > 0.0f) isolateSettings(); // a fresh start, no restore prompt, the user's files untouchedif (!options.recordPath.empty() && options.supersample > 1) { // the app renders large; the video keeps --sizeoptions.width *= options.supersample;options.height *= options.supersample;diff --git a/src/link/PhoneLink.cpp b/src/link/PhoneLink.cppindex 15c29de0..76e9fac6 100644--- a/src/link/PhoneLink.cpp+++ b/src/link/PhoneLink.cpp@@ -345,6 +345,7 @@ void PhoneLink::pushEvent(PhoneEvent event) {if (event.type == PhoneEvent::Type::Error) lastError_ = event.text;events_.push_back(std::move(event));while (events_.size() > 256) events_.pop_front();+ if (wake_) wake_();}std::vector<PhoneEvent> PhoneLink::takeEvents() {@@ -432,6 +433,7 @@ void PhoneLink::noteDevice(const HttpRequest& request) {}HttpResponse PhoneLink::route(const HttpRequest& request) {+ if (wake_) wake_(); // uploads, AR requests and progress show at onceconst std::string& path = request.path;const std::string& method = request.method;const bool get = method == "GET" || method == "HEAD";@@ -950,6 +952,7 @@ bool PhoneLink::receiveFaceMessage(const std::string& text, const std::string& tstd::lock_guard lock(mutex_);face_ = frame;++faceSerial_;+ if (wake_) wake_();lastFace_ = now;faceTimes_.push_back(now);while (!faceTimes_.empty() && now - faceTimes_.front() > std::chrono::seconds(1)) faceTimes_.pop_front();diff --git a/src/link/PhoneLink.h b/src/link/PhoneLink.hindex 896d0be3..7eb9931c 100644--- a/src/link/PhoneLink.h+++ b/src/link/PhoneLink.h@@ -28,6 +28,7 @@#include <map>#include <memory>#include <mutex>+#include <functional>#include <string>#include <thread>#include <vector>@@ -167,6 +168,9 @@ public:// Events for the main thread, oldest first.std::vector<PhoneEvent> takeEvents();+ // Called (from the server's threads) whenever the phone sends something: the app redraws only on demand+ // and uses it to wake up. Set it before start().+ void setWake(std::function<void()> wake) { wake_ = std::move(wake); }// The newest face frame (false when there is none newer than `serial`; updates `serial`).bool latestFace(FaceFrame& frame, uint64_t& serial) const;@@ -208,6 +212,7 @@ private:HttpResponse route(const HttpRequest& request);bool authorised(const HttpRequest& request);void noteDevice(const HttpRequest& request);+ std::function<void()> wake_;void pushEvent(PhoneEvent event);void newToken();std::string statusJson();