Restart the current breathing phase before stepping back

This commit is contained in:
waozi committed 2026-10-26 03:11:07 -03:00
1 parent 5f6c98425d
commit 5527db97d4
6 files changed
+159 -2

No files matched your search

+1 -1
View File
@@ -400,7 +400,7 @@ EMBEDDED_ASSET_FILES := apps/publishers.json $(INBE_BUNDLE) $(APPS_BUNDLE) asset
KRY_GEN_DIR := $(BUILD_DIR)/kryon/generated
# Dependencies are imported as PACKAGE/Module through their linked packages.
ZI_PACKAGE_PATHS := $(shell sh scripts/package-paths.sh)
ZI_SRCS := $(shell find src -type f -name '*.zi' 2>/dev/null | LC_ALL=C sort) apps/practice/hold_reminder.zi $(wildcard apps/practice/astral_projection*.zi) $(wildcard apps/practice/workout*.zi) $(wildcard apps/practice/sun_salutation*.zi)
ZI_SRCS := $(shell find src -type f -name '*.zi' 2>/dev/null | LC_ALL=C sort) apps/practice/hold_reminder.zi apps/practice/whm_controls.zi $(wildcard apps/practice/astral_projection*.zi) $(wildcard apps/practice/workout*.zi) $(wildcard apps/practice/sun_salutation*.zi)
GAME2D_DIR := build/packages/game2d
GAME2D_MODULES := $(wildcard $(GAME2D_DIR)/src/*/*.zi)
DAOCHI_CLIENT_DIR ?= build/packages/daochi-client
+26
View File
@@ -0,0 +1,26 @@
#import, file "../../src/core/types.zi";
#import, file "../../src/core/breath_timing.zi";
// At the beginning, Back may leave the phase even while its fractional
// timer advances. This keeps a second press usable without pausing first.
WhmBackRestartsPhase :: (session: BreathSession) -> bool {
if session.phase == BreathPhaseStarting {
return session.sectick >= 60
}
if session.phase == BreathPhaseBreathe ||
session.phase == BreathPhaseHold ||
session.phase == BreathPhaseRecover {
return BreathCountValue(session) > 0
}
return false
}
WhmRestartPhase :: (session: BreathSession) -> BreathSession {
session.dir = 0
session.r = session.rmin
session.breath_frame = 0
session.breathtick = 0
session.sectick = 0
session.halftick = 0
return BreathResetCount(session)
}
+5
View File
@@ -57,6 +57,11 @@ 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))
.PHONY: whm-controls-ui-test
whm-controls-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)) --back-only
.PHONY: lumi-narration-test
lumi-narration-test: $(ZI2C_BIN)
@env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
+14
View File
@@ -10,6 +10,7 @@
#import "toolbar"
#import "practice_types"
#import "hold_reminder"
#import "whm_controls"
c :: #system_library "c";
PI :: 3.14159265358979f;
WHM_LOG_INFO :: 3;
@@ -665,6 +666,19 @@ session_step_back :: (app: *InnerBreeze) {
return
}
whm_elapsed_remainder = 0.0
app.breath_tap_last_time = 0.0
if WhmBackRestartsPhase(app.breathing) {
if app.breathing.phase == BreathPhaseBreathe ||
app.breathing.phase == BreathPhaseHold {
clear_round_results_from(app, app.breathing.round)
}
app.breathing = WhmRestartPhase(app.breathing)
app.hold_reminder_last_bucket = 0
remember_sound_state(app)
return
}
if app.breathing.phase == BreathPhaseStarting {
if app.breathing.round > 0 {
session_enter_previous_round_last_step(app)
+47
View File
@@ -1,9 +1,53 @@
#import, file "../src/core/types.zi";
#import, file "../src/core/breath_timing.zi";
#import "hold_reminder"
#import "whm_controls"
using BreathAnimation;
CheckBackRestarts :: () -> bool {
phases: [4]s32 = .[BreathPhaseStarting, BreathPhaseBreathe,
BreathPhaseHold, BreathPhaseRecover]
for index: 0..3 {
session := BreathSessionInit()
session.phase = phases[index]
session.round = 2
unused BreathDigitsWrite(session.results[0][:], 78)
unused BreathDigitsWrite(session.results[2][:], 92)
if WhmBackRestartsPhase(session) {
return false
}
session.sectick = 120
session.breath_frame = 37
session.breathtick = 18
session.halftick = 1
session.dir = 1
session.r = session.rmax
unused BreathDigitsWrite(session.count[:], 8)
if !WhmBackRestartsPhase(session) {
return false
}
reset := WhmRestartPhase(session)
if reset.phase != session.phase || reset.round != 2 ||
BreathCountValue(reset) != 0 || reset.sectick != 0 ||
reset.breath_frame != 0 || reset.breathtick != 0 ||
reset.halftick != 0 || reset.dir != 0 || reset.r != reset.rmin ||
BreathDigitsRead(reset.results[0][:]) != 78 ||
BreathDigitsRead(reset.results[2][:]) != 92 ||
reset.speed_level != session.speed_level ||
reset.max_rounds != session.max_rounds {
return false
}
// A running timer must not prevent the next press going backward.
reset.sectick = 12
reset.breath_frame = 12
if WhmBackRestartsPhase(reset) {
return false
}
}
return true
}
CheckHoldReminders :: () -> bool {
intervals: [2]s32 = .[30, 60]
for index: 0..1 {
@@ -52,6 +96,9 @@ CheckHoldReminders :: () -> bool {
#program_export
Answer :: () -> s32 {
if !CheckBackRestarts() {
return -38
}
if !CheckHoldReminders() {
return -30
}
+66 -1
View File
@@ -24,6 +24,8 @@ DISPLAY_KEYS = ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_AD
assert all(not os.environ.get(key) for key in DISPLAY_KEYS), "Inherited desktop environment"
BINARY = Path(sys.argv[1]).resolve()
DESKTOP_ONLY = "--desktop-only" in sys.argv[2:]
BACK_ONLY = "--back-only" in sys.argv[2:]
EMBEDDED = "--embedded" in sys.argv[2:]
SCREEN_START, SCREEN_SESSION, SCREEN_HABITS, SCREEN_LUMI = 0, 1, 11, 23
SCREEN_SETTINGS, SCREEN_LISTS, SCREEN_DIARY = 6, 16, 22
PRACTICES = {"whm": 1, "meditation": 2, "sun_salutation": 3, "patterns": 4}
@@ -78,7 +80,9 @@ with tempfile.TemporaryDirectory(prefix="inbe-session-window-") as directory, co
def application(label, width, height):
log_path = OUTPUT / (label + ".log")
with log_path.open("w") as log:
app = subprocess.Popen([str(BINARY), "--bundle", str(ROOT / "build/inbe-full.zx")],
arguments = [str(BINARY)] if EMBEDDED else \
[str(BINARY), "--bundle", str(ROOT / "build/inbe-full.zx")]
app = subprocess.Popen(arguments,
cwd=ROOT, env=env, stdout=log, stderr=log)
driver.attach(app, log_path)
try:
@@ -264,6 +268,67 @@ with tempfile.TemporaryDirectory(prefix="inbe-session-window-") as directory, co
values.update({"app_used_" + name: "1" for name in ("lumi", "habits", "lists", "diary", "practices")})
save_settings(values)
if BACK_ONLY:
save_settings(dict(advanced_session_controls="1", double_tap_to_breathe="0",
pause_seconds="0", speed="8", progressive_speed="0"))
for width in (390, 900):
with application("back-controls-" + str(width), width, 720) as window:
action(window, "practice.whm.start", "back-start-" + str(width))
driver.press(label="Pause", role="button")
driver.press(label="Next", role="button")
def advance_counter():
driver.press(label="PLAY", role="button")
deadline = time.monotonic() + 10
while state(window)["breath"] < 2:
assert time.monotonic() < deadline, ("Counter did not advance", state(window))
time.sleep(.1)
driver.press(label="Pause", role="button")
def back_to_zero(expected_round, holding):
driver.press(label="Back", role="button",
index=len(shown(label="Back", role="button")) - 1)
driver.wait_idle(frames=2)
observed = state(window)
assert observed["breath"] == 0 and observed["round"] == expected_round, observed
assert observed["paused"], "Back changed the pause state"
assert bool(shown(label="BREATH", role="button")) == holding, \
"Back left the current phase instead of resetting it"
# Breathing and holding restart in place, including when paused.
advance_counter()
back_to_zero(0, False)
driver.press(label="Next", role="button")
driver.wait(label="BREATH", role="button")
advance_counter()
back_to_zero(0, True)
back_to_zero(0, False)
# Without a between-round countdown, the second press at zero
# still reaches the previous round, rather than trapping Back.
for step in range(4):
driver.press(label="Next", role="button")
assert state(window)["round"] == 1, state(window)
advance_counter()
back_to_zero(1, False)
back_to_zero(0, False)
# A running session stays running when its counter is reset.
driver.press(label="Next", role="button")
driver.press(label="Next", role="button")
driver.press(label="PLAY", role="button")
deadline = time.monotonic() + 10
while state(window)["breath"] < 1:
assert time.monotonic() < deadline, "Running counter did not advance"
time.sleep(.1)
driver.press(label="Back", role="button",
index=len(shown(label="Back", role="button")) - 1)
observed = state(window)
assert observed["round"] == 1 and observed["breath"] == 0, observed
assert not observed["paused"], "Back paused the running session"
print(f"PASS Back resets breathing and hold counters before moving backward at {width}px")
sys.exit(0)
# Every practice minimizes to Practice, where it was started, and keeps
# its live picture moving in the window until maximize returns to it.
for practice, screen in ({} if DESKTOP_ONLY else PRACTICES).items():