From b5bbe962edda6784f689f8a8f919cf48179d414f Mon Sep 17 00:00:00 2001 From: Roman Chojnacki Date: Mon, 9 Nov 2026 14:23:07 +0100 Subject: [PATCH] Skip unchanged frames by default A frame whose draw commands equal the last presented one is skipped, and on the software renderer a changed frame is redrawn only where it changed, for every app. The launch field .skip_same_frames becomes .draw_every_frame, which turns both off; bench sets it so it keeps measuring full frames. The launch struct an app sees changed, so libreaktor's SOVERSION is now 1, and the runtime package libreaktor0 becomes libreaktor1. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/bsd.yml | 2 +- .github/workflows/linux.yml | 4 ++-- .github/workflows/release.yml | 6 ++--- CLAUDE.md | 5 ++-- CMakeLists.txt | 2 +- README.md | 2 +- docs/DOCUMENTATION.md | 44 +++++++++++++++++------------------ include/reaktor/launch.h | 2 +- runtime/app.c | 2 +- samples/bench/bench.c | 13 ++++++----- samples/showcase/shell.c | 1 - tests/damagetest.c | 11 ++++----- tests/skiptest.c | 1 - tools/libreaktor-pkg.sh | 4 ++-- 14 files changed, 49 insertions(+), 50 deletions(-) diff --git a/.github/workflows/bsd.yml b/.github/workflows/bsd.yml index f98326c..c5a77ad 100644 --- a/.github/workflows/bsd.yml +++ b/.github/workflows/bsd.yml @@ -197,7 +197,7 @@ jobs: cmake --build build-arm64-shared --parallel 4 --target libreaktor -.tar.gz\` holds \`libreaktor.so.0\`, + \`libreaktor-shared-$v--.tar.gz\` holds \`libreaktor.so.1\`, our own SDL as \`libreaktor-sdl3.so.0\`, \`libreaktor-modules.a\` (the modules, which go into each app), everything the static one has, and \`reaktor-shared.pc\`. Link with \`reaktor::shared\` in CMake or \`pkg-config --cflags --libs reaktor-shared\`; the app records where the libraries are. As system packages it splits in three: - \`libreaktor-sdl3-0\` and \`libreaktor0\`, all an app needs to run, and + \`libreaktor-sdl3-0\` and \`libreaktor1\`, all an app needs to run, and \`libreaktor-shared\` to build one: - \`libreaktor0_${v}_.deb\`, \`libreaktor-sdl3-0_${v}_.deb\` and + \`libreaktor1_${v}_.deb\`, \`libreaktor-sdl3-0_${v}_.deb\` and the \`.rpm\`s beside them. The static library stays the default. **Upgrading:** the static package was \`libreaktor-dev\` as a \`.deb\` diff --git a/CLAUDE.md b/CLAUDE.md index 715cb63..5673dec 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,7 +15,7 @@ CMake options pass through: `./build.ps1 -DREAKTOR_A11Y=OFF`, `REAKTOR_SHARED=ON` left in `build/` makes every sample a shared one. Shipping: `tools/package.sh` packs a release folder, `tools/libreaktor-pkg.sh` -a system package (`libreaktor` static; with `-s`, `libreaktor0`, +a system package (`libreaktor` static; with `-s`, `libreaktor1`, `libreaktor-sdl3-0` and `libreaktor-shared`). A version tag such as `1.2.3` publishes through `release.yml`. @@ -62,7 +62,8 @@ on every run. the present; the Diagnostics page and `bench --no-vsync` split them. Vsync sits in the present, so a total that matches the refresh rate measures it. - **`--shot` never skips a frame.** It and a capture force the draw, so a pixel - diff cannot see what `.skip_same_frames` breaks; `tests/skiptest.c` can. + diff cannot see what skipping an unchanged frame breaks; `tests/skiptest.c` + can. Skipping is the default; `.draw_every_frame` turns it off. - **Text the atlas lacks is not Nuklear's.** Strings with Japanese, Arabic and the like are measured and drawn by `core/text/text.c` through a custom command. mojibake 0.5.0 records `byte_offset` at a character's last byte. diff --git a/CMakeLists.txt b/CMakeLists.txt index af03074..6ec6e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -710,7 +710,7 @@ if(REAKTOR_SHARED) file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor_so.c" CONTENT "") add_library(reaktor_shared SHARED "${CMAKE_BINARY_DIR}/reaktor_so.c") set_target_properties(reaktor_shared PROPERTIES - VERSION ${PROJECT_VERSION} SOVERSION 0 + VERSION ${PROJECT_VERSION} SOVERSION 1 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map") add_dependencies(reaktor_shared ${_so_parts}) diff --git a/README.md b/README.md index 316cd1b..79bfa4f 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ with `-DCMAKE_PREFIX_PATH=/opt/reaktor`, or `pkg-config` with `PKG_CONFIG_PATH=/opt/reaktor/lib/pkgconfig`. Remove it with the system's package manager: it is `libreaktor` everywhere. With `-s` it also builds `libreaktor.so` and packs three packages instead: `libreaktor-sdl3-0` -and `libreaktor0`, which an app needs to run, and `libreaktor-shared` to +and `libreaktor1`, which an app needs to run, and `libreaktor-shared` to build one. `libreaktor` and `libreaktor-shared` conflict; install one or the other. diff --git a/docs/DOCUMENTATION.md b/docs/DOCUMENTATION.md index a771f5e..5aa2ad1 100644 --- a/docs/DOCUMENTATION.md +++ b/docs/DOCUMENTATION.md @@ -1000,31 +1000,31 @@ While a mouse button is held, frames follow the display's refresh, with two more after the release. A turn of the wheel takes two frames, because Nuklear scrolls a panel after drawing it. -**A frame that draws what is already on screen** is still rendered and -presented, unless the launch sets `.skip_same_frames`. Then each frame's draw +**A frame that draws what is already on screen** is skipped. Each frame's draw commands are hashed field by field, and one that matches the last presented frame is neither rendered nor presented. A key nothing takes, or a focus change that moves no ring, then costs the build and nothing more. A window uncovered, shown, resized, restored or moved to another scale is always drawn, and so is a frame a `--shot` or a capture waits for. A tween that changes -nothing on screen follows the display's refresh. It is off by default; the -showcase turns it on, and its Diagnostics page counts the frames drawn and -skipped. +nothing on screen follows the display's refresh. A launch that sets +`.draw_every_frame` renders and presents every frame, whole; the bench sample +does, to measure drawing. The showcase's Diagnostics page counts the frames +drawn and skipped. -On the software renderer at a whole-number scale, a launch with -`.skip_same_frames` also redraws a changed frame only where its commands -changed. The window is drawn into a texture that keeps the last frame; the -commands that differ from it mark up to four rectangles, and only those are -cleared and drawn again, through every command, before the texture is copied -to the window. A frame that would redraw more than half the window, a new -window size, scale, theme or clear color, an evicted icon or a new font atlas, -the first frame, and a frame a `--shot` or a capture waits for are drawn whole. -Every frame comes out pixel for pixel as a full redraw would draw it; -`tests/damagetest.c` checks each one. A GPU renderer, whose back buffer is not -kept, or a fractional scale, draws every frame whole. A texture an app changes -in place through `reaktor_sdl_renderer` is not among the commands, so a frame -that only changes its pixels is skipped, or leaves them where they were: draw -it from a new texture, or at a new rectangle, for the change to show. +On the software renderer at a whole-number scale, a changed frame is redrawn +only where its commands changed. The window is drawn into a texture that keeps +the last frame; the commands that differ from it mark up to four rectangles, +and only those are cleared and drawn again, through every command, before the +texture is copied to the window. A frame that would redraw more than half the +window, a new window size, scale, theme or clear color, an evicted icon or a +new font atlas, the first frame, and a frame a `--shot` or a capture waits for +are drawn whole. Every frame comes out pixel for pixel as a full redraw would +draw it; `tests/damagetest.c` checks each one. A GPU renderer, whose back +buffer is not kept, or a fractional scale, draws every frame whole. A texture +an app changes in place through `reaktor_sdl_renderer` is not among the +commands, so a frame that only changes its pixels is skipped, or leaves them +where they were: draw it from a new texture, or at a new rectangle, or set +`.draw_every_frame`, for the change to show. A finger that moves mostly up or down, by more than 8 pixels, scrolls the panel under it: the runtime releases what the finger pressed away from every @@ -1147,7 +1147,7 @@ the library shared, so several apps map one copy: `libreaktor.so` with SDL as stay in each app, from `libreaktor-modules.a`. Link `reaktor::shared`, or on Linux and the BSDs `pkg-config --cflags --libs reaktor-shared`; the framework has no `.pc`. Releases carry it as -`libreaktor-shared---`. Its soname is `libreaktor.so.0` +`libreaktor-shared---`. Its soname is `libreaktor.so.1` (OpenBSD installs no unversioned `libreaktor.so`), and it exports only what `tools/reaktor.map` names: the public calls, with Nuklear's and NukAnim's, under `LIBREAKTOR_0`, and what the modules call under `LIBREAKTOR_PRIVATE_0`, @@ -1157,7 +1157,7 @@ which an application must not reach. it for the system it runs on: a `.deb` where `dpkg-deb` exists, an `.rpm` where `rpmbuild` does, a FreeBSD, OpenBSD or NetBSD package, or a `.tar.gz`. `-i` installs it, `-s` builds the shared library too and splits the package -in three: `libreaktor0` and `libreaktor-sdl3-0` to run an app +in three: `libreaktor1` and `libreaktor-sdl3-0` to run an app (`libreaktor-sdl3` on OpenBSD, whose package names read a dash before a digit as the version) and `libreaktor-shared`, with the headers and both libraries, to build one, @@ -1175,7 +1175,7 @@ apart from the system's include directory, because the package carries SDL's and Nuklear's headers. Point `CMAKE_PREFIX_PATH` or `PKG_CONFIG_PATH` (its `lib/pkgconfig`) there. No package depends on a system library — link the ones `pkg-config --libs reaktor` names — only on the others of a split: -`libreaktor0` needs `libreaktor-sdl3-0`, and `libreaktor-shared` both. +`libreaktor1` needs `libreaktor-sdl3-0`, and `libreaktor-shared` both. `libreaktor` and `libreaktor-shared` install the same headers, so each conflicts with the other. diff --git a/include/reaktor/launch.h b/include/reaktor/launch.h index 088d26d..5b186ae 100644 --- a/include/reaktor/launch.h +++ b/include/reaktor/launch.h @@ -103,7 +103,7 @@ typedef struct reaktor_launch { void *user; int remember_window; int single_instance; - int skip_same_frames; + int draw_every_frame; reaktor_save save_settings; int save_ms; const char *renderer; diff --git a/runtime/app.c b/runtime/app.c index 6c84439..b577c6b 100644 --- a/runtime/app.c +++ b/runtime/app.c @@ -1371,7 +1371,7 @@ same_frame(App *app, struct nk_context *ctx) unsigned h; int same; - if (!g_launch.skip_same_frames) return 0; + if (g_launch.draw_every_frame) return 0; h = reaktor_damage_collect(app, ctx); h = reaktor_fnv_n(h, &app->laid_w, sizeof app->laid_w); h = reaktor_fnv_n(h, &app->laid_h, sizeof app->laid_h); diff --git a/samples/bench/bench.c b/samples/bench/bench.c index 9a8eb17..8bd00a4 100644 --- a/samples/bench/bench.c +++ b/samples/bench/bench.c @@ -138,10 +138,11 @@ int main(int argc, char **argv) { return launchApp(argc, argv, &(reaktor_launch){ - .name = "Bench", - .window = { .w = 800, .h = 600 }, - .console = REAKTOR_CONSOLE_PARENT, - .page = page_shell, - .key = sample_key, - .start = sample_start }); + .name = "Bench", + .window = { .w = 800, .h = 600 }, + .console = REAKTOR_CONSOLE_PARENT, + .draw_every_frame = 1, + .page = page_shell, + .key = sample_key, + .start = sample_start }); } diff --git a/samples/showcase/shell.c b/samples/showcase/shell.c index 9ffd365..e80acad 100644 --- a/samples/showcase/shell.c +++ b/samples/showcase/shell.c @@ -806,7 +806,6 @@ main(int argc, char **argv) .font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } }, .confirm_close = SC_CLOSE_QUESTION, .single_instance = 1, - .skip_same_frames = 1, .inspector = { .attach = 1 }, .page = page_shell, .key = sample_key, diff --git a/tests/damagetest.c b/tests/damagetest.c index 453ba95..e57ecb1 100644 --- a/tests/damagetest.c +++ b/tests/damagetest.c @@ -511,10 +511,9 @@ int main(int argc, char **argv) { return reaktor_test_app(argc, argv, &(reaktor_launch){ - .name = "Damagetest", - .window = { .w = 640, .h = 480 }, - .console = REAKTOR_CONSOLE_PARENT, - .skip_same_frames = 1, - .font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } }, - .page = page }, script, NULL); + .name = "Damagetest", + .window = { .w = 640, .h = 480 }, + .console = REAKTOR_CONSOLE_PARENT, + .font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } }, + .page = page }, script, NULL); } diff --git a/tests/skiptest.c b/tests/skiptest.c index 808e375..12e1a56 100644 --- a/tests/skiptest.c +++ b/tests/skiptest.c @@ -65,6 +65,5 @@ main(int argc, char **argv) .name = "Skiptest", .window = { .w = 400, .h = 300 }, .console = REAKTOR_CONSOLE_PARENT, - .skip_same_frames = 1, .page = page }, script, NULL); } diff --git a/tools/libreaktor-pkg.sh b/tools/libreaktor-pkg.sh index a429d8e..4887b47 100755 --- a/tools/libreaktor-pkg.sh +++ b/tools/libreaktor-pkg.sh @@ -109,7 +109,7 @@ dev=libreaktor-shared # The runtime packages carry the SOVERSION, as Debian's do. OpenBSD reads a # package name's version from its first dash followed by a digit, so there # the SDL one has no dash before its 0. -lib=libreaktor0 +lib=libreaktor1 sdl=libreaktor-sdl3-0 [ "$format" = openbsd ] && sdl=libreaktor-sdl3 conflicts="" @@ -239,7 +239,7 @@ pack() { } # A REAKTOR_SHARED build splits in three, so an app can install the libraries -# alone: libreaktor-sdl3-0 (our SDL), libreaktor0 (libreaktor.so, which needs +# alone: libreaktor-sdl3-0 (our SDL), libreaktor1 (libreaktor.so, which needs # it) and the development package with everything else, which needs both. split=0 ls "$stage$prefix"/lib/libreaktor.so* >/dev/null 2>&1 && split=1