diff --git a/CHANGELOG.md b/CHANGELOG.md index c92db959f..0c3529b9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +## [2.1.25] - 2026-10-09 +### Fixed +- Animate the Wim Hof breathing circle smoothly between timer ticks, including its Customize preview. +- Keep Wim Hof timing accurate when the display frame rate varies. +- Avoid repeating account activity and sync queue checks on unchanged animation frames. + ## [2.1.24] - 2026-10-09 ### Fixed - Open the breathing animation, background music and other menus reliably again. diff --git a/Makefile b/Makefile index f5e19999e..56322200e 100644 --- a/Makefile +++ b/Makefile @@ -423,6 +423,11 @@ session-window-ui-test: $(TARGET) env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \ python3 tests/session_window_ui_test.py $(abspath $(TARGET)) +.PHONY: whm-frame-performance-test +whm-frame-performance-test: $(TARGET) + env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \ + python3 tests/whm_frame_performance_test.py $(abspath $(TARGET)) + $(CELL_BUNDLES) $(INBE_BUNDLE) $(INBE_FULL_BUNDLE) &: $(CELL_SOURCES) $(CELL_RESOURCES) ziran.lock apps/versions.json scripts/check-package-versions.py scripts/generate-package-versions.py scripts/prepare-package-assets.py scripts/animation_inventory.py scripts/build-cells.sh src/practices/sun_salutation/sun_salutation_assets.zi src/practices/sun_salutation/sun_salutation_inventory.zi $(IMAGE_FILES) $(SOUND_FILES) $(FONT_FILES) $(STYLE_FILES) $(LOCALE_FILES) $(ZIRAN_BIN) sh scripts/build-cells.sh $(ZIRAN_BIN) diff --git a/droid/app/build.gradle b/droid/app/build.gradle index d32253184..a1ff055b1 100644 --- a/droid/app/build.gradle +++ b/droid/app/build.gradle @@ -56,8 +56,8 @@ android { minSdk 21 targetSdk 36 testInstrumentationRunner "android.test.InstrumentationTestRunner" - versionCode 161 - versionName "2.1.24" + versionCode 162 + versionName "2.1.25" manifestPlaceholders = [ inbeAppLabel: "Inner Breeze", inbeUsesCleartextTraffic: "false" diff --git a/fastlane/metadata/android/en-US/changelogs/162.txt b/fastlane/metadata/android/en-US/changelogs/162.txt new file mode 100644 index 000000000..9008ecc13 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/162.txt @@ -0,0 +1,5 @@ +Fixed +--- +- Animate the Wim Hof breathing circle smoothly between timer ticks, including its Customize preview. +- Keep Wim Hof timing accurate when the display frame rate varies. +- Avoid repeating account activity and sync queue checks on unchanged animation frames. diff --git a/packaging/click/control b/packaging/click/control index 8b8fead57..a8d766fb5 100644 --- a/packaging/click/control +++ b/packaging/click/control @@ -1,5 +1,5 @@ Package: inbe.waozi -Version: 2.1.24 +Version: 2.1.25 Architecture: arm64 Maintainer: Waozi Click-Version: 0.4 diff --git a/packaging/click/inbe.metainfo.xml b/packaging/click/inbe.metainfo.xml index 820897358..6c8ec3170 100644 --- a/packaging/click/inbe.metainfo.xml +++ b/packaging/click/inbe.metainfo.xml @@ -28,7 +28,7 @@ inbe - + diff --git a/packaging/click/manifest.json b/packaging/click/manifest.json index 2c6a87497..2ebd4bc33 100644 --- a/packaging/click/manifest.json +++ b/packaging/click/manifest.json @@ -1,7 +1,7 @@ { "name": "inbe", "title": "Inner Breeze", - "version": "2.1.24", + "version": "2.1.25", "architecture": "arm64", "framework": "ubuntu-sdk-20.04", "description": "Syncable breathing, meditation, and habit practice app.", diff --git a/packaging/firefox-addons/manifest.json b/packaging/firefox-addons/manifest.json index 19daa1a9b..1d3496b27 100644 --- a/packaging/firefox-addons/manifest.json +++ b/packaging/firefox-addons/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Inner Breeze", "short_name": "Inbe", - "version": "2.1.24", + "version": "2.1.25", "description": "Breathing, meditation, habit tracking, and encrypted sync.", "permissions": [ "contextMenus" diff --git a/packaging/linux/appimage/inbe.appdata.xml b/packaging/linux/appimage/inbe.appdata.xml index 7ab2fce5a..c9a782fc1 100644 --- a/packaging/linux/appimage/inbe.appdata.xml +++ b/packaging/linux/appimage/inbe.appdata.xml @@ -22,7 +22,7 @@ inbe - + diff --git a/packaging/snap/snap/gui/inbe.metainfo.xml b/packaging/snap/snap/gui/inbe.metainfo.xml index be6b14714..f924d6463 100644 --- a/packaging/snap/snap/gui/inbe.metainfo.xml +++ b/packaging/snap/snap/gui/inbe.metainfo.xml @@ -22,7 +22,7 @@ inbe - + diff --git a/packaging/snap/snap/snapcraft.yaml b/packaging/snap/snap/snapcraft.yaml index 5b432200c..8efa838da 100644 --- a/packaging/snap/snap/snapcraft.yaml +++ b/packaging/snap/snap/snapcraft.yaml @@ -6,7 +6,7 @@ description: | meditation, and habit tracking with visual and audio cues, meditation timers, habit counters, session history, and optional sync. -version: '2.1.24' +version: '2.1.25' license: BSD-3-Clause base: core22 confinement: strict diff --git a/src/app/account_activity.zi b/src/app/account_activity.zi index 45b6561d9..211c36beb 100644 --- a/src/app/account_activity.zi +++ b/src/app/account_activity.zi @@ -45,6 +45,12 @@ ActivityState :: struct { } account_activity: ActivityState; +activity_availability_revision: s64 = -1; +activity_availability_delegate_generation: s64 = -1; +activity_availability_checked: float64 = -1.0; +activity_availability: bool; +activity_availability_delegated: bool; + ActivityCurrentTime :: () -> s64 { return ActivityNow(null) } @@ -61,9 +67,27 @@ ActivityRandomID :: (output: []u8, byte_count: s32) -> bool { } ActivityAvailable :: () -> bool { - return PreviewMode() == 0 && !DataTemporary() && storage_sync_enabled() != 0 && + if PreviewMode() != 0 || DataTemporary() { + return false + } + revision := storage_data_revision() + generation := StoredDelegateGeneration() + clock := ActivityFrameTime() + if revision == activity_availability_revision && generation == activity_availability_delegate_generation && + clock >= activity_availability_checked && clock - activity_availability_checked < 0.25 { + // Delegate expiry and identity checks remain live even when the + // owner's unchanged settings can be reused between frames. + return activity_availability && + (!activity_availability_delegated || StoredDelegateAvailable() != 0) + } + activity_availability_revision = revision + activity_availability_delegate_generation = generation + activity_availability_checked = clock + activity_availability_delegated = StoredAccountMode() == AccountModeDelegate + activity_availability = storage_sync_enabled() != 0 && storage_has_sync_account() != 0 && - (StoredAccountMode() != AccountModeDelegate || StoredDelegateAvailable() != 0) + (!activity_availability_delegated || StoredDelegateAvailable() != 0) + return activity_availability } ActivityInitialize :: () -> bool { @@ -173,14 +197,17 @@ ActivityApplyControl :: (app: *InnerBreeze, now: s64) -> bool { ActivityPump :: (app: *InnerBreeze) { activity_start_check = ActivityCanStart - if app == null || !ActivityInitialize() { + if app == null { + return + } + clock := ActivityFrameTime() + if clock >= account_activity.last_poll && clock - account_activity.last_poll < 0.25 { + return + } + if !ActivityInitialize() { return } state := *account_activity - clock := ActivityFrameTime() - if clock >= state.last_poll && clock - state.last_poll < 0.25 { - return - } state.last_poll = clock now := ActivityNow(null) // Read the shared record only after stored data changed, such as a sync diff --git a/src/app/app_profile.zi b/src/app/app_profile.zi index bd90918cc..03fdd7328 100644 --- a/src/app/app_profile.zi +++ b/src/app/app_profile.zi @@ -7,6 +7,11 @@ c :: #system_library "c"; ProfileGetEnv :: (name: *u8) -> *u8 #foreign c "app_getenv_bytes"; ProfileClock :: () -> float64 #foreign c "app_monotonic_seconds"; ProfileLogInfo :: (line: *u8) #foreign c "app_log_line"; +#if #defined(ANDROID_DEBUG) { + android_log :: #system_library "log"; + ProfileLogAndroid :: (priority: s32, tag: *u8, line: *u8) -> s32 + #foreign android_log "__android_log_write"; +} #scope_export #program_export @@ -16,6 +21,9 @@ app_profile_env_enabled :: () -> bool { return false } value: *u8 = ProfileGetEnv(*name[0]) + #if #defined(ANDROID_DEBUG) { + if value == null { return true } + } return value != null && value[0] != cast(u8)0 && value[0] != cast(u8)48 } @@ -76,7 +84,7 @@ ProfileAppendTwoDecimals :: (output: []u8, used: *s32, number: float64) -> bool app_profile_report :: (frame_avg: float64, frame_max: float64, update_avg: float64, update_max: float64, habits_avg: float64, habits_max: float64, - sync_avg: float64, sync_max: float64) { + sync_avg: float64, sync_max: float64, fps: float64) { line: [256]u8 used: s32 = 0 if !ProfileAppend(line[:], *used, "PROFILE: frame avg=") || @@ -94,17 +102,27 @@ app_profile_report :: (frame_avg: float64, frame_max: float64, !ProfileAppend(line[:], *used, " sync avg=") || !ProfileAppendTwoDecimals(line[:], *used, sync_avg) || !ProfileAppend(line[:], *used, " max=") || - !ProfileAppendTwoDecimals(line[:], *used, sync_max) { + !ProfileAppendTwoDecimals(line[:], *used, sync_max) || + !ProfileAppend(line[:], *used, " fps=") || + !ProfileAppendTwoDecimals(line[:], *used, fps) { return } line[used] = cast(u8)0 - ProfileLogInfo(*line[0]) + #if #defined(ANDROID_DEBUG) { + tag: [16]u8 + if CopyCString("InbePerformance", tag[:]) { + unused ProfileLogAndroid(4, *tag[0], *line[0]) + } + } else { + ProfileLogInfo(*line[0]) + } } ProfileStats :: struct { initialized: s32 enabled: s32 frames: s32 + report_started: float64 frame_total: float64 frame_max: float64 update_total: float64 @@ -168,17 +186,21 @@ app_profile_record_sync :: (start: float64) { #program_export app_profile_frame_end :: (start: float64) { if !enabled() || start <= 0.0 { return } - elapsed := (ProfileClock() - start) * 1000.0 + now := ProfileClock() + if stats.report_started <= 0.0 { stats.report_started = start } + elapsed := (now - start) * 1000.0 stats.frame_total += elapsed if elapsed > stats.frame_max { stats.frame_max = elapsed } stats.frames += 1 if stats.frames < 120 { return } count := cast(float64)stats.frames + fps: float64 = 0.0 + if now > stats.report_started { fps = count / (now - stats.report_started) } app_profile_report(stats.frame_total / count, stats.frame_max, stats.update_total / count, stats.update_max, stats.habits_total / count, stats.habits_max, - stats.sync_total / count, stats.sync_max) + stats.sync_total / count, stats.sync_max, fps) stats = ProfileStats.{0 } stats.initialized = 1 stats.enabled = 1 diff --git a/src/app/app_sync.zi b/src/app/app_sync.zi index d7f0617f2..61c2730a6 100644 --- a/src/app/app_sync.zi +++ b/src/app/app_sync.zi @@ -1113,6 +1113,26 @@ app_sync_review_pending :: () -> s32 { return sync_review_cache } +sync_queue_cache: SyncStatus; +sync_queue_cache_valid: bool; +sync_queue_cache_revision: s64 = -1; +sync_queue_cache_checked: float64 = -1.0; + +// The queue changes with stored data, not the render rate. A bounded +// fallback also picks up metadata changed outside the writing connection. +app_sync_queue_status :: (status: *SyncStatus, now: float64) -> bool { + if status == null { return false } + revision := storage_data_revision() + if revision != sync_queue_cache_revision || now < sync_queue_cache_checked || + now - sync_queue_cache_checked >= 0.25 { + sync_queue_cache_revision = revision + sync_queue_cache_checked = now + sync_queue_cache_valid = SyncStatusRead(*sync_queue_cache) + } + status.* = sync_queue_cache + return sync_queue_cache_valid +} + app_sync_pump :: (app: *InnerBreeze) { now: float64 should_sync: s32 = 0 @@ -1160,7 +1180,7 @@ app_sync_pump :: (app: *InnerBreeze) { should_sync = 1 dirty_due = 1 } - if SyncStatusRead(*sync_status) && sync_status.has_account != 0 && sync_status.enabled != 0 && (sync_status.queued_changes > 0 || sync_status.full_upload_done == 0 || sync_status.repair_pending != 0) && (g_sync.dirty_sync_at <= 0.0 || now >= g_sync.dirty_sync_at) { + if app_sync_queue_status(*sync_status, now) && sync_status.has_account != 0 && sync_status.enabled != 0 && (sync_status.queued_changes > 0 || sync_status.full_upload_done == 0 || sync_status.repair_pending != 0) && (g_sync.dirty_sync_at <= 0.0 || now >= g_sync.dirty_sync_at) { should_sync = 1 if sync_status.repair_pending != 0 { repair_due = 1 diff --git a/src/core/breath_timing.zi b/src/core/breath_timing.zi index fa5774259..d65f9ae3a 100644 --- a/src/core/breath_timing.zi +++ b/src/core/breath_timing.zi @@ -153,7 +153,58 @@ BreathAnimatedSpan :: (session: BreathSession, span: s32, #program_export BreathDrawRadius :: (session: BreathSession) -> float32 { - return cast(float32)session.r + return BreathDrawRadiusAt(session, 0.0) +} + +// Keep the portable session's integer fields, but paint its continuous +// curve rather than snapping the radius to whole layout units. +#program_export +BreathDrawRadiusAt :: (session: BreathSession, fraction: float32) -> float32 { + span := session.rmax - session.rmin + half_ticks := session.breath_half_ticks + shrinking := session.phase == BreathPhaseNext + if session.phase == BreathPhaseBreathe { + half_ticks = BreathEffectiveHalfTicks(session) + shrinking = session.dir != 0 + } else if session.phase != BreathPhaseNext && + (session.phase != BreathPhaseRecover || session.r >= session.rmax) { + return cast(float32)session.r + } + if span <= 0 || half_ticks <= 0 { + return cast(float32)session.r + } + if !(fraction >= 0.0) { fraction = 0.0 } + if fraction > 1.0 { fraction = 1.0 } + amount := (cast(float32)session.breath_frame + fraction) / + cast(float32)half_ticks + if amount < 0.0 { amount = 0.0 } + if amount > 1.0 { amount = 1.0 } + if session.breath_animation != BreathAnimationLinear { + amount = BreathSmoothstep(amount) + } + if shrinking { amount = 1.0 - amount } + return cast(float32)session.rmin + cast(float32)span * amount +} + +BreathClockStep :: struct { + ticks: s32 + remainder: float64 +} + +// Carry fractional ticks directly. Converting each 60 Hz tick back to a +// truncated number of milliseconds makes the clock run too fast. +#program_export +BreathClockAdvance :: (seconds: float64, remainder: float64) -> BreathClockStep { + result: BreathClockStep + if !(remainder >= 0.0) || remainder >= 1.0 { remainder = 0.0 } + result.remainder = remainder + if !(seconds > 0.0) { return result } + if seconds > 300.0 { seconds = 300.0 } + ticks := seconds * 60.0 + remainder + result.ticks = cast(s32)(ticks + 0.000000001) + result.remainder = ticks - cast(float64)result.ticks + if result.remainder < 0.0 { result.remainder = 0.0 } + return result } #program_export diff --git a/src/core/version.h b/src/core/version.h index 2eda48451..46c21a78b 100644 --- a/src/core/version.h +++ b/src/core/version.h @@ -3,7 +3,7 @@ #define APP_VERSION_MAJOR 2 #define APP_VERSION_MINOR 1 -#define APP_VERSION_PATCH 24 -#define APP_VERSION_STRING "2.1.24" +#define APP_VERSION_PATCH 25 +#define APP_VERSION_STRING "2.1.25" #endif diff --git a/src/core/version.zi b/src/core/version.zi index e9d520c11..c4253bb73 100644 --- a/src/core/version.zi +++ b/src/core/version.zi @@ -1,5 +1,5 @@ // Generated by update_version.sh from CHANGELOG.md. Do not edit by hand. VersionMajor :: 2 VersionMinor :: 1 -VersionPatch :: 24 -VersionString :: "2.1.24" +VersionPatch :: 25 +VersionString :: "2.1.25" diff --git a/src/practices/whm/whm_config.zi b/src/practices/whm/whm_config.zi index f9c82a64e..b75f1a889 100644 --- a/src/practices/whm/whm_config.zi +++ b/src/practices/whm/whm_config.zi @@ -51,8 +51,8 @@ using TextWrap; using ButtonTone; using ButtonEmphasis; -whm_config_preview_remainder: s32 = 0; -whm_start_speed_preview_remainder: s32 = 0; +whm_config_preview_remainder: float64 = 0.0; +whm_start_speed_preview_remainder: float64 = 0.0; WhmAnimationOptionCount :: 2 WhmConfigClamp :: (value: s32, minimum: s32, maximum: s32) -> s32 { @@ -83,7 +83,7 @@ whm_preview_needs_reset :: (preview: *BreathSession, speed: s32, max_rounds: s32 whm_preview_reset :: (preview: *BreathSession, speed: s32, max_rounds: s32, max_breaths: s32, pause_seconds: s32, animation: s32, content_w: s32, content_h: s32, - remainder: *s32) { + remainder: *float64) { if preview == null { return } @@ -99,39 +99,20 @@ whm_preview_reset :: (preview: *BreathSession, speed: s32, max_rounds: s32, } } -whm_preview_step_elapsed :: (preview: *BreathSession, remainder: *s32) { - elapsed_ms := cast(s32)(GetFrameTime() * 1000.0f + 0.5f) - total: s32 - frames: s32 - +whm_preview_step_elapsed :: (preview: *BreathSession, remainder: *float64) { if preview == null { return } - if elapsed_ms < 1 { - elapsed_ms = 17 - } - if elapsed_ms > 120 { - elapsed_ms = 120 - } - - if remainder == null { - preview.* = BreathSessionStep(preview.*) - return - } - - total = elapsed_ms * 60 + remainder.* - frames = total / 1000 - remainder.* = total % 1000 - if frames < 1 { - frames = 1 - } - if frames > 8 { - frames = 8 - } + seconds := cast(float64)GetFrameTime() + if seconds > 0.12 { seconds = 0.12 } + fraction: float64 = 0.0 + if remainder != null { fraction = remainder.* } + clock := BreathClockAdvance(seconds, fraction) + if remainder != null { remainder.* = clock.remainder } { i: s32 = 0 - while i < frames { + while i < clock.ticks { preview.* = BreathSessionStep(preview.*) if preview.phase != BreathPhaseBreathe { return @@ -146,7 +127,7 @@ whm_draw_exact_speed_preview :: (preview: *BreathSession, preview_speed: *s32, pause_seconds: s32, animation: s32, content_w: s32, content_h: s32, center_x: s32, center_y: s32, - remainder: *s32) { + remainder: *float64) { if preview == null || preview_speed == null { return } @@ -162,7 +143,9 @@ whm_draw_exact_speed_preview :: (preview: *BreathSession, preview_speed: *s32, } whm_preview_step_elapsed(preview, remainder) - draw_breath_preview(preview, center_x, center_y) + fraction: float32 = 0.0 + if remainder != null { fraction = cast(float32)remainder.* } + draw_breath_preview(preview, center_x, center_y, fraction) } whm_draw_progressive_start_speed_editor :: (app: *InnerBreeze) { @@ -328,7 +311,7 @@ whm_config_draw_breath_card :: (app: *InnerBreeze, content_x: s32, content_w: s3 } draw_breath_preview(*app.settings_preview, inner_x + inner_w / 2, - inner_y + preview_h / 2) + inner_y + preview_h / 2, cast(float32)whm_config_preview_remainder) inner_y += preview_h + AppScale(20) if commit_slider_row(app, 1, inner_x, inner_w, *inner_y, AppScale(78), diff --git a/src/practices/whm/whm_session.h b/src/practices/whm/whm_session.h index 97b9ebc69..eaad8fb28 100644 --- a/src/practices/whm/whm_session.h +++ b/src/practices/whm/whm_session.h @@ -18,6 +18,6 @@ void update_session_sounds(InnerBreeze*app); void session_background_start(InnerBreeze*app); void session_advance_elapsed(InnerBreeze*app, int elapsed_ms); void update_preview_bounds(BreathSession *breathing, int content_w, int max_h); -void draw_breath_preview(BreathSession *breathing, int center_x, int center_y); +void draw_breath_preview(BreathSession *breathing, int center_x, int center_y, float fraction); #endif diff --git a/src/practices/whm/whm_session.zi b/src/practices/whm/whm_session.zi index 0598d1c8d..9b07e6a99 100644 --- a/src/practices/whm/whm_session.zi +++ b/src/practices/whm/whm_session.zi @@ -98,7 +98,7 @@ whm_log :: (level: s32, message: string) { } } -whm_background_remainder_ms: s32 = 0; +whm_elapsed_remainder: float64 = 0.0; whm_last_notification_text: [96] u8; text_color_for_background :: (background: Color) -> Color { luma: s32 = cast(s32)background.r * 299 + cast(s32)background.g * 587 + cast(s32)background.b * 114 @@ -384,33 +384,30 @@ session_background_start :: (app: *InnerBreeze) { if app == null { return } - whm_background_remainder_ms = 0 + whm_elapsed_remainder = 0.0 whm_last_notification_text[0] = cast(u8)0 remember_sound_state(app) } session_advance_elapsed :: (app: *InnerBreeze, elapsed_ms: s32) { - elapsed_total: s32 - frame_count: s32 + session_advance_seconds(app, cast(float64)elapsed_ms / 1000.0) +} - if app == null || elapsed_ms <= 0 { +session_advance_seconds :: (app: *InnerBreeze, seconds: float64) { + + if app == null || !(seconds > 0.0) { return } if app_session_screen(app) != ScreenSession || app.session_paused != 0 { return } - elapsed_total = elapsed_ms + whm_background_remainder_ms - if elapsed_total > 5 * 60 * 1000 { - elapsed_total = 5 * 60 * 1000 - } - - frame_count = (elapsed_total * 60) / 1000 - whm_background_remainder_ms = elapsed_total - (frame_count * 1000) / 60 + clock := BreathClockAdvance(seconds, whm_elapsed_remainder) + whm_elapsed_remainder = clock.remainder { i: s32 = 0 - while i < frame_count && app_session_screen(app) == ScreenSession { + while i < clock.ticks && app_session_screen(app) == ScreenSession { step := PracticeRun(PracticeStepFor(app, PRACTICE_BREATH_STEP)) if !step.succeeded { app.request_quit = 1 @@ -435,11 +432,7 @@ session_advance_visible_frame :: (app: *InnerBreeze) { return } - elapsed_ms: s32 = cast(s32)(GetFrameTime() * 1000.0f + 0.5f) - if elapsed_ms < 1 { - elapsed_ms = 1 - } - session_advance_elapsed(app, elapsed_ms) + session_advance_seconds(app, cast(float64)GetFrameTime()) } #program_export @@ -455,6 +448,7 @@ session_start :: (app: *InnerBreeze) { // A fresh session keeps every choice made in Customize. app.breathing = BreathSessionInit() + whm_elapsed_remainder = 0.0 app.breathing.progressive_speed = progressive_speed app.breathing.progressive_start_speed = progressive_start_speed app.breathing.play_in_background = play_in_background @@ -943,7 +937,8 @@ draw_session_progress_circle :: (app: *InnerBreeze, center_x: s32, center_y: s32 } session_draw_inbe :: (app: *InnerBreeze, center_x: s32, center_y: s32) { - radius: float32 = BreathDrawRadius(app.breathing) + radius: float32 = BreathDrawRadiusAt(app.breathing, + cast(float32)whm_elapsed_remainder) draw_session_progress_circle(app, center_x, center_y, radius) draw_session_counter(app, center_x, center_y) @@ -1013,10 +1008,11 @@ session_draw_round_title_bar :: (app: *InnerBreeze, title: string, height: s32) #program_export // Painted into the current widget scope, so the preview stays above a modal // panel and inside a scrolled page's clip. -draw_breath_preview :: (breathing: *BreathSession, center_x: s32, center_y: s32) { +draw_breath_preview :: (breathing: *BreathSession, center_x: s32, center_y: s32, + fraction: float32) { r: float32 = 0.0f if breathing != null { - r = BreathDrawRadius(breathing.*) * 0.72f + r = BreathDrawRadiusAt(breathing.*, fraction) * 0.72f } if r <= 0.0f { return diff --git a/tests/account_activity_behavior.zi b/tests/account_activity_behavior.zi index 82e856fab..70b272f32 100644 --- a/tests/account_activity_behavior.zi +++ b/tests/account_activity_behavior.zi @@ -24,6 +24,8 @@ c :: #system_library "c"; FixtureAdvance :: (seconds: s64) #foreign c; FixtureSchedules :: () -> s32 #foreign c; +FixtureFrame :: () #foreign c; +FixtureQueries :: () -> s32 #foreign c; fixture_app: InnerBreeze; WriteControl :: (activity: AccountActivity, id: string, revision: s64, now: s64) { @@ -78,6 +80,14 @@ Check :: () -> s32 { check_true("fresh activity", ActivityFresh(first, ActivityCurrentTime())) check_true("stale activity is not fresh", !ActivityFresh(first, first.time + ActivityFreshSeconds + 1)) check_true("future activity is not fresh", !ActivityFresh(first, first.time - 6)) + queries_before := FixtureQueries() + for frame: cast(s32)0..cast(s32)11 { + FixtureFrame() + ActivityPump(*fixture_app) + unused ActivityRemoteVisible() + } + check_true("unchanged animation frames perform no activity SQL queries", + FixtureQueries() == queries_before) fixture_app.breathing.screen = ScreenSunSalutation fixture_app.sun_salutation.repetitions = 3 FixtureAdvance(1) diff --git a/tests/account_activity_zi_test.sh b/tests/account_activity_zi_test.sh index be033020d..5a1e60503 100644 --- a/tests/account_activity_zi_test.sh +++ b/tests/account_activity_zi_test.sh @@ -23,14 +23,26 @@ cat > "$work/generated/main.c" <<'C' #include #include #include +typedef struct sqlite3 sqlite3; +typedef struct sqlite3_stmt sqlite3_stmt; static int64_t fixture_now = 1791540000; +static double fixture_clock = 10.0; static int schedules; +static int queries; time_t __wrap_time(time_t *output) { if (output) *output = fixture_now; return fixture_now; } -double GetTime(void) { return (double)(fixture_now - 1791539990); } -void FixtureAdvance(int64_t seconds) { fixture_now += seconds; } +double GetTime(void) { return fixture_clock; } +void FixtureAdvance(int64_t seconds) { fixture_now += seconds; fixture_clock += seconds; } +void FixtureFrame(void) { fixture_clock += 1.0 / 60.0; } +int32_t FixtureQueries(void) { return queries; } +int __real_sqlite3_prepare_v2(sqlite3 *, const char *, int, sqlite3_stmt **, const char **); +int __wrap_sqlite3_prepare_v2(sqlite3 *db, const char *sql, int length, + sqlite3_stmt **statement, const char **tail) { + queries++; + return __real_sqlite3_prepare_v2(db, sql, length, statement, tail); +} int32_t FixtureSchedules(void) { return schedules; } int32_t app_auto_sync(void *app) { (void)app; schedules++; return 1; } int main(void) { @@ -46,6 +58,7 @@ monocypher=$root/build/packages/monocypher/src -I"$monocypher" -I"$monocypher/optional" \ "$work/generated"/*.c "$root/vendor-builds/sqlite/sqlite3.c" \ "$monocypher/monocypher.c" "$monocypher/optional/monocypher-ed25519.c" "$liboqs" \ - -Wl,--gc-sections -Wl,--wrap=time -ldl -lpthread -lz -lm -o "$work/test" + -Wl,--gc-sections -Wl,--wrap=time -Wl,--wrap=sqlite3_prepare_v2 \ + -ldl -lpthread -lz -lm -o "$work/test" APP_DATA_ROOT="$data" "$work/test" printf '%s\n' 'Account activity, private outbox, controls, freshness and account switching passed' diff --git a/tests/breath_timing_behavior.zi b/tests/breath_timing_behavior.zi index 929e63a56..da79bf1e7 100644 --- a/tests/breath_timing_behavior.zi +++ b/tests/breath_timing_behavior.zi @@ -145,5 +145,67 @@ Answer :: () -> s32 { if state.completed != 0 { return -18 } + // Every render can move by a fraction of a layout unit, including + // between simulation ticks and on both sides of a breath boundary. + smooth := BreathSessionInit() + smooth.phase = BreathPhaseBreathe + smooth.progressive_speed = 0 + smooth.speed_level = 3 + smooth.rmin = 80 + smooth.rmax = 160 + smooth.breath_frame = 1 + first_radius := BreathDrawRadius(smooth) + second_radius := BreathDrawRadiusAt(smooth, 0.5) + if !(first_radius > 80.5 && first_radius < 80.6 && + second_radius > first_radius && second_radius < 81.0) { return -25 } + smooth.dir = 1 + if !(BreathDrawRadiusAt(smooth, 0.5) < BreathDrawRadius(smooth)) { return -26 } + smooth.breath_frame = 0 + if BreathDrawRadius(smooth) != 160.0 { return -27 } + smooth.dir = 0 + smooth.breath_animation = BreathAnimationInOut + smooth.breath_frame = 36 + if BreathDrawRadius(smooth) != 92.5 { return -28 } + smooth.phase = BreathPhaseHold + smooth.r = 80 + if BreathDrawRadiusAt(smooth, 0.9) != 80.0 { return -29 } + smooth.phase = BreathPhaseRecover + smooth.breath_half_ticks = 120 + smooth.breath_frame = 60 + if BreathDrawRadiusAt(smooth, 0.0) != 120.0 { return -30 } + smooth.r = 160 + smooth.breath_frame = 0 + if BreathDrawRadiusAt(smooth, 0.5) != 160.0 { return -31 } + smooth.phase = BreathPhaseNext + smooth.breath_frame = 60 + if BreathDrawRadius(smooth) != 120.0 { return -32 } + + // Equal elapsed time must produce equal ticks at high, low and + // irregular rendering rates. The old millisecond carry ran too fast. + clock: BreathClockStep + total_ticks: s32 = 0 + for index: cast(s32)0..cast(s32)599 { + clock = BreathClockAdvance(0.016, clock.remainder) + total_ticks += clock.ticks + } + if total_ticks != 576 || clock.remainder > 0.000001 { return -33 } + total_ticks = 0 + clock = BreathClockStep.{} + for index: cast(s32)0..cast(s32)599 { + clock = BreathClockAdvance(0.017, clock.remainder) + total_ticks += clock.ticks + } + if total_ticks != 612 || clock.remainder > 0.000001 { return -34 } + total_ticks = 0 + clock = BreathClockStep.{} + for index: cast(s32)0..cast(s32)1439 { + clock = BreathClockAdvance(1.0 / 144.0, clock.remainder) + total_ticks += clock.ticks + } + if total_ticks != 600 || clock.remainder > 0.000001 { return -35 } + clock = BreathClockAdvance(0.0, 0.5) + if clock.ticks != 0 || clock.remainder != 0.5 { return -36 } + clock = BreathClockAdvance(301.0, 0.0) + if clock.ticks != 18000 || clock.remainder != 0.0 { return -37 } return 42 } diff --git a/tests/profile_host_test.c b/tests/profile_host_test.c index d74384ece..44f0e62f0 100644 --- a/tests/profile_host_test.c +++ b/tests/profile_host_test.c @@ -64,7 +64,7 @@ int main(int argc, char **argv) app_profile_frame_end(10.0); if(log_count != 1 || strcmp(log_text, - "PROFILE: frame avg=10.00 max=10.00 update avg=0.08 max=10.00 habits avg=0.08 max=10.00 sync avg=0.08 max=10.00")) + "PROFILE: frame avg=10.00 max=10.00 update avg=0.08 max=10.00 habits avg=0.08 max=10.00 sync avg=0.08 max=10.00 fps=12000.00")) return 6; app_profile_frame_end(10.0); if(log_count != 1) diff --git a/tests/sync_recovery_behavior.zi b/tests/sync_recovery_behavior.zi index 992897464..9bc57f0b6 100644 --- a/tests/sync_recovery_behavior.zi +++ b/tests/sync_recovery_behavior.zi @@ -3,6 +3,7 @@ #import, file "../src/app/sync_safety.zi"; #import, file "../src/app/sync_retry.zi"; #import, file "../src/app/app_types.zi"; +#import, file "../src/storage/sync_status.zi"; // Host state the C side provides: the clock, the account switch, and the // queue the status key reads. @@ -10,6 +11,7 @@ recovery_c :: #system_library "c"; recovery_set_time :: (seconds: float64) #foreign recovery_c; recovery_set_enabled :: (enabled: s32) #foreign recovery_c; recovery_set_queue :: (queued: s64, repair: s32, full_upload: s32) #foreign recovery_c; +recovery_status_reads :: () -> s32 #foreign recovery_c; Retry :: (attempt: s32) -> bool { return SettingsStoreInt("sync_retry_attempt", attempt) @@ -130,5 +132,21 @@ Answer :: () -> s32 { g_sync.retry_requested = false recovery_set_enabled(0) if app_request_sync(*app) != 0 || g_sync.retry_requested { return 40 } + recovery_set_enabled(1) + recovery_set_queue(1, 0, 1) + status: SyncStatus + if !app_sync_queue_status(*status, now) || status.queued_changes != 1 { return 41 } + reads := recovery_status_reads() + for frame: cast(s32)0..cast(s32)119 { + if !app_sync_queue_status(*status, now) { return 42 } + } + if recovery_status_reads() != reads { return 43 } + recovery_set_queue(2, 0, 1) + if !app_sync_queue_status(*status, now + 0.26) || status.queued_changes != 2 || + recovery_status_reads() != reads + 1 { return 44 } + // A data revision, including disconnect, invalidates immediately. + recovery_set_enabled(0) + if !app_sync_queue_status(*status, now + 0.27) || status.enabled != 0 || + recovery_status_reads() != reads + 2 { return 45 } return 0 } diff --git a/tests/sync_recovery_link_test.c b/tests/sync_recovery_link_test.c index a893146c2..18abac79e 100644 --- a/tests/sync_recovery_link_test.c +++ b/tests/sync_recovery_link_test.c @@ -13,6 +13,7 @@ static int enabled = 1; static int64_t queued; static int repair; static int full_upload; +static int status_reads; bool storage_sync_node_failover(void) { return false; } int32_t app_preview_mode(void) { return 0; } @@ -60,6 +61,7 @@ storage_sync_enabled(void) int32_t storage_sync_status(StorageSyncStatus *status) { + status_reads++; memset(status, 0, sizeof(*status)); status->has_account = 1; status->enabled = enabled; @@ -69,6 +71,8 @@ storage_sync_status(StorageSyncStatus *status) return 1; } +int32_t recovery_status_reads(void) { return status_reads; } + void recovery_set_time(double seconds) { diff --git a/tests/whm_frame_performance_test.py b/tests/whm_frame_performance_test.py new file mode 100644 index 000000000..1a2028790 --- /dev/null +++ b/tests/whm_frame_performance_test.py @@ -0,0 +1,98 @@ +"""Exercise WHM rendering with a synthetic profile and an owned private display.""" +import ast +import contextlib +import json +import os +from pathlib import Path +import re +import subprocess +import sys +import tempfile +import time + +ROOT = Path(__file__).resolve().parents[1] +OUTPUT = ROOT / "build/whm-animation-test" +OUTPUT.mkdir(parents=True, exist_ok=True) +DISPLAY_KEYS = ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS") +assert all(not os.environ.get(key) for key in DISPLAY_KEYS) +BINARY = Path(sys.argv[1]).resolve() + + +def stop(process): + if process.poll() is None: + process.terminate() + try: + process.wait(timeout=5) + except subprocess.TimeoutExpired: + process.kill() + process.wait(timeout=5) + + +with tempfile.TemporaryDirectory(prefix="inbe-whm-frames-") as temporary, contextlib.ExitStack() as stack: + env = {key: value for key, value in os.environ.items() if key not in DISPLAY_KEYS} + env.update(APP_DATA_ROOT=temporary, APP_NO_TRAY="1", APP_PROFILE="1", + SDL_AUDIODRIVER="dummy", SDL_VIDEODRIVER="x11", LIBGL_ALWAYS_SOFTWARE="1", + YUE_DESKTOP_RECOVERY="0", INBE_DEBUG_ROUTE="1") + log_path = OUTPUT / "frames.log" + log = stack.enter_context(log_path.open("w")) + display = subprocess.Popen(["Xvfb", "-displayfd", "1", "-screen", "0", "1080x1000x24", + "-nolisten", "tcp"], env=env, stdout=subprocess.PIPE, stderr=log) + stack.callback(stop, display) + number = display.stdout.readline().decode().strip() + display.stdout.close() + assert number.isdecimal(), "Private display did not start" + env["DISPLAY"] = ":" + number + app = subprocess.Popen([str(BINARY), "--bundle", str(ROOT / "build/inbe-full.zib")], + cwd=ROOT, env=env, stdout=log, stderr=log) + stack.callback(stop, app) + + def command(*arguments): + return subprocess.check_output(arguments, env=env, text=True, timeout=5).strip() + + def wait(read, predicate, label): + deadline = time.monotonic() + 20 + while time.monotonic() < deadline: + assert app.poll() is None, log_path.read_text()[-2000:] + try: + value = read() + if predicate(value): + return value + except (subprocess.CalledProcessError, ValueError, SyntaxError, IndexError): + pass + time.sleep(0.05) + raise AssertionError(label) + + window = wait(lambda: command("xdotool", "search", "--onlyvisible", "--pid", str(app.pid)) + .splitlines()[0], bool, "Owned app window") + command("xdotool", "windowsize", window, "390", "844") + command("xdotool", "windowfocus", window) + + def state(): + prop = command("xprop", "-id", window, "_HARMONY_APP_STATE") + return json.loads(ast.literal_eval(prop.split(" = ", 1)[1])) + + wait(state, lambda value: value.get("interface") == "harmony.app-state.v1", "App state") + command("xprop", "-id", window, "-f", "_HARMONY_APP_ACTION", "8s", "-set", + "_HARMONY_APP_ACTION", json.dumps({"control": "practice.whm.start", "request_id": "whm-frames"})) + started = wait(state, lambda value: value.get("last_request_id") == "whm-frames" and + value.get("last_request_ok") and value.get("practice_running"), "WHM start") + initial_reports = len(re.findall(r"PROFILE: frame", log_path.read_text())) + deadline = time.monotonic() + 14 + while time.monotonic() < deadline: + assert app.poll() is None, "Owned test app exited" + time.sleep(0.1) + progressed = state() + assert progressed["practice_running"] and not progressed["paused"] + assert (progressed["round"], progressed["breath"]) > (started["round"], started["breath"]) + reports = re.findall(r"PROFILE: frame avg=([\d.]+) max=([\d.]+).*?sync avg=([\d.]+) " + r"max=([\d.]+) fps=([\d.]+)", log_path.read_text())[initial_reports + 1:] + assert len(reports) >= 4, "Not enough measured animation frames" + measurements = [{"cpuAverageMs": float(cpu), "cpuMaxMs": float(peak), + "syncAverageMs": float(sync), "syncMaxMs": float(sync_peak), "fps": float(fps)} + for cpu, peak, sync, sync_peak, fps in reports] + assert min(row["fps"] for row in measurements) >= 55, measurements + assert max(row["cpuAverageMs"] for row in measurements) < 8, measurements + result = {"passed": True, "privateDisplay": True, "syntheticProfile": True, + "screenshots": False, "practiceContinued": True, "measurements": measurements} + (OUTPUT / "frames.json").write_text(json.dumps(result, indent=2) + "\n") + print(json.dumps(result)) diff --git a/windows/inbe.rc b/windows/inbe.rc index 81ed4e4d2..8cda588c8 100644 --- a/windows/inbe.rc +++ b/windows/inbe.rc @@ -6,8 +6,8 @@ IDI_APP_ICON ICON "inbe.ico" IDI_NOTIFICATION_ICON ICON "inbe.ico" VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,1,24,0 - PRODUCTVERSION 2,1,24,0 + FILEVERSION 2,1,25,0 + PRODUCTVERSION 2,1,25,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -24,11 +24,11 @@ BEGIN BEGIN VALUE "CompanyName", "waozi" VALUE "FileDescription", "Inner Breeze" - VALUE "FileVersion", "2.1.24" + VALUE "FileVersion", "2.1.25" VALUE "InternalName", "inbe" VALUE "OriginalFilename", "inbe-windows-x86_64.exe" VALUE "ProductName", "Inner Breeze" - VALUE "ProductVersion", "2.1.24" + VALUE "ProductVersion", "2.1.25" END END BLOCK "VarFileInfo"