Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(native): a bench lifts the pacer's frame-rate cap as well as its floor, so a phone's benched frame reads what it cost

yhha1fe1c8b4851
diff --git a/native/host/FramePacer.hpp b/native/host/FramePacer.hpp
index cc4603c13..75fda7553 100644
--- a/native/host/FramePacer.hpp
+++ b/native/host/FramePacer.hpp
@@ -27,7 +27,7 @@
* while a surface is torn down ("GetCurrentTexture was not called"),
* and a loop with nothing else to stop it once ran 11.5 million frames
* in a backgrounded app. No display needs more than kFloorFps here;
- * a bench that asked for an uncapped present lifts it.
+ * a bench that asked for an uncapped present lifts it, and the cap.
*
* The host loop asks untilDue(), serves input while it waits, and calls
* frameStarted() as it begins a frame. Plain data and steady_clock only:
@@ -60,14 +60,14 @@ public:
}
float target() const { return target_; }
- /// True while a bench measures uncapped frames: the floor would be what it measured.
+ /// True while a bench measures uncapped frames: the cap and the floor would be what it measured.
void setUnbounded(bool on) { unbounded_ = on; }
/// How long from @p now until a frame is due; zero when one is. A host stepped by a display callback, which cannot spin,
/// passes @p floor false: it needs the cap and nothing else.
Clock::duration untilDue(Clock::time_point now, bool floor = true) const {
Clock::time_point due = Clock::time_point{};
- if (interval_ > Clock::duration::zero() && nextAt_ != Clock::time_point{}) due = nextAt_;
+ if (!unbounded_ && interval_ > Clock::duration::zero() && nextAt_ != Clock::time_point{}) due = nextAt_;
if (floor && !unbounded_ && lastStart_ != Clock::time_point{}) {
const auto floorAt = lastStart_ + kFloor;
if (floorAt > due) due = floorAt;
diff --git a/tests/input/test_frame_pacer.cpp b/tests/input/test_frame_pacer.cpp
index b06170999..f1d164615 100644
--- a/tests/input/test_frame_pacer.cpp
+++ b/tests/input/test_frame_pacer.cpp
@@ -42,11 +42,14 @@ TEST_CASE("a display-stepped host asks for the cap alone") {
CHECK(ms(p.untilDue(at(26.7), false)) == doctest::Approx(16.67).epsilon(0.01));
}
-TEST_CASE("a bench lifts the floor") {
+TEST_CASE("a bench lifts the floor and the cap") {
FramePacer p;
p.setUnbounded(true);
p.frameStarted(at(0));
CHECK(p.untilDue(at(0.1)) == Clock::duration::zero());
+ p.setTarget(60.0f);
+ p.frameStarted(at(1));
+ CHECK(p.untilDue(at(1.1)) == Clock::duration::zero());
}
TEST_CASE("a cap is a cadence, not a gap") {
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index c7a6c1001..12ec5a998 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3838,4 +3838,6 @@ export const NOTED = {
{"note":"A native Android build shows CJK text from the system font."},
"perf(text): a new glyph is drawn and distance-transformed at 2x rather than 4x, and the transform skips what cannot change its bytes, so a phone pays a third of what it did":
{"note":"A new character costs a phone about a third of what it did."},
+ "fix(native): a bench lifts the pacer's frame-rate cap as well as its floor, so a phone's benched frame reads what it cost":
+ {"internal":"only the bench switches reach it; a game never runs with them on"},
};