Files
breeze/tests/workout_behavior.zi
waozi 924553d6c2 Make the practice figures move naturally and show the VRoid figure
The owner picked pixiv's CC0 VRoid woman and man (practices
shared/figure). An audit of every practice at 30 frames a second (the
preview's new --audit) found 589 awkward moments; 9 small ones remain.

- Feet step and pivot instead of sliding: a stepping foot rises clear of
  the floor before it travels and lands after it arrives; a foot turning
  on the spot pivots on its heel or ball (the ball when it stands on its
  toes) with the other end raised first. One rule for Tai Chi's timeline,
  the Workout and Sun Salutation (TaiChiStepFoot); lunges no longer drag a
  foot 46 cm.
- Toes hanging from a lifted tiptoe foot bend up rather than go through
  the floor.
- Knees and elbows straighten smoothly over the last 1.2% of their reach
  instead of snapping straight.
- Each Tai Chi hand turns as one piece between keys, so its fingers and
  palm never blend through nothing and flip the hand (Snake Creeps Down).
- The side plank rolls over face down to the second side instead of
  jumping there.
- The course studio's solver and timeline match, and its parity reference
  is regenerated (export-app.mjs --reference).
- Workout and Sun Salutation tests check that planted feet stay within
  5 mm, nothing goes below the floor, nothing moves too fast and no knee
  bends backwards.
- The figure preview shows the woman or the man with hair on VRM spring
  bones and blinking eyes, and gains --audit, --shot, --video and --trace;
  it pins Kryon ac6c8f47 and practices d8b54df1.
2026-11-18 15:57:10 -03:00

250 lines
10 KiB
Ziran

#import, file "../apps/practice/workout_rules.zi";
#import, file "../apps/practice/workout_moves.zi";
#import, file "figure_test_support.zi";
#import, file "../src/practices/tai_chi/tai_chi_math.zi";
#import, file "../src/practices/tai_chi/tai_chi_solve.zi";
#import "math"
#import "file_linux"
#import "locale_parser"
#import "byte_text_linux"
StepIs :: (elapsed_ms: s64, phase: s32, exercise: s32, elapsed: s32) -> bool {
step := WorkoutStepAt(elapsed_ms)
return step.phase == phase && step.exercise == exercise && (phase == WORKOUT_PHASE_DONE || step.elapsed_ms == elapsed)
}
// The workout's words in one language: every name, tip and spoken line,
// none empty, and the tips and spoken lines in the language itself.
text_bytes: [65536]u8;
english_bytes: [65536]u8;
ReadText :: (code: string, output: []u8) -> string {
path: [128]u8
count: s64 = 0
parts: [3]string = .["../build/packages/practices/workout/text/", code, ".txt"]
for index: cast(s32)0..2 {
for byte: parts[index] {
path[count] = byte
count += 1
}
}
file := OpenRead(TextFromBytes(path[:count]))
size := FileSize(file)
if size <= 0 || size > cast(s64)output.count {
unused CloseFile(file)
return ""
}
read := ReadAt(file, output[:size], 0)
unused CloseFile(file)
return ifx read == size then TextFromBytes(output[:size]) else ""
}
TextComplete :: (code: string, english: string) -> bool {
catalog := ReadText(code, text_bytes[:])
if catalog.count == 0 {
return false
}
key: [64]u8
lines: s32 = 0
prefixes: [4]string = .["workout_name_", "workout_tip_", "workout_say_", "workout_say_next_"]
for exercise: cast(s32)0..WORKOUT_EXERCISE_COUNT - 1 {
for which: cast(s32)0..3 {
prefix := prefixes[which]
if prefix == "workout_say_next_" && exercise == 0 {
continue
}
name := WorkoutKeyFor(prefix, exercise, key[:])
value := LocaleFindText(catalog, name)
if !value.found || value.text.count == 0 {
return false
}
if code != "en" && prefix != "workout_name_" && value.text == LocaleFindText(english, name).text {
return false
}
lines += 1
}
}
others: [6]string = .["workout_say_start", "workout_say_switch", "workout_say_count_3",
"workout_say_count_2", "workout_say_count_1", "workout_say_go"]
for which: cast(s32)0..5 {
value := LocaleFindText(catalog, others[which])
if value.text.count == 0 {
return false
}
if code != "en" && value.text == LocaleFindText(english, others[which]).text {
return false
}
lines += 1
}
return lines == 53
}
// A squat's arms reach straight ahead at shoulder height, standing and at
// the bottom.
SquatArmsLevel :: (rig: *TaiChiRig) -> bool {
for index: cast(s32)0..1 {
pose := WorkoutKeyframe(WORKOUT_SQUATS, index).pose
solved := WorkoutSolve(*pose, rig)
for side: cast(s32)0..1 {
upper := TaiChiNormalize3(TaiChiSub3(solved.shoulders[side], solved.elbows[side]))
lower := TaiChiNormalize3(TaiChiSub3(solved.wrists[side], solved.elbows[side]))
// At least 165 degrees at the elbow.
if TaiChiDot3(upper, lower) > -0.966 {
return false
}
if !Near(solved.wrists[side].y, solved.shoulders[side].y, 0.06) ||
solved.wrists[side].z - solved.shoulders[side].z < 0.4 {
return false
}
}
}
return true
}
#program_export
// Every exercise moves as a person would: feet step and pivot instead of
// sliding, stay above the floor, and nothing snaps. The first exercise that does
// not, times ten, plus the bound it broke; or -1.
WorkoutMotionAwkward :: () -> s32 {
rig := WorkoutRig()
for exercise: cast(s32)0..WORKOUT_EXERCISE_COUNT - 1 {
check: MotionCheck
check.lowest = 1000.0
MotionStart(*check)
time: float64
while time < cast(float64)WORKOUT_WORK_MS / 1000.0 {
pose := WorkoutPoseAt(exercise, cast(s64)(time * 1000.0), *rig)
solved := WorkoutSolve(*pose, *rig)
// Rolling over between side planks the feet turn over on the
// floor, which the feet (soles only) cannot roll on; the roll
// is left out of the sliding measure.
switch := cast(float64)WORKOUT_SIDE_SWITCH_MS / 1000.0
if exercise == WORKOUT_SIDE_PLANK && time >= switch && time < switch + cast(float64)WORKOUT_SIDE_ROLL_MS / 1000.0 {
for slot: 0..3 {
check.crept[slot] = -1.0
}
}
MotionStep(*check, *solved)
time += MOTION_STEP
}
slide: float64 = 0.005
if !MotionWithin(*check, slide, 8.0) {
// Which bound it broke: sliding, the floor, speed or a knee.
broke: s32 = 4
if check.worst_slide > slide {
broke = 1
} else if check.lowest < -0.005 {
broke = 2
} else if check.fastest > 8.0 {
broke = 3
}
return exercise * 10 + broke
}
}
return -1
}
#program_export
Answer :: () -> s32 {
if WORKOUT_TOTAL_MS != WORKOUT_PREPARE_MS + WORKOUT_EXERCISE_COUNT * WORKOUT_WORK_MS +
(WORKOUT_EXERCISE_COUNT - 1) * WORKOUT_REST_MS {
return 1
}
if !StepIs(0, WORKOUT_PHASE_PREPARE, 0, 0) || !StepIs(9999, WORKOUT_PHASE_PREPARE, 0, 9999) ||
!StepIs(10000, WORKOUT_PHASE_WORK, 0, 0) || !StepIs(39999, WORKOUT_PHASE_WORK, 0, 29999) ||
!StepIs(40000, WORKOUT_PHASE_REST, 1, 0) || !StepIs(50000, WORKOUT_PHASE_WORK, 1, 0) ||
!StepIs(450000, WORKOUT_PHASE_WORK, 11, 0) || !StepIs(479999, WORKOUT_PHASE_WORK, 11, 29999) ||
!StepIs(480000, WORKOUT_PHASE_DONE, 11, 0) || !StepIs(-5, WORKOUT_PHASE_PREPARE, 0, 0) {
return 2
}
if WorkoutStepSecondsLeft(WorkoutStepAt(10000)) != 30 || WorkoutStepSecondsLeft(WorkoutStepAt(39001)) != 1 ||
WorkoutStepSecondsLeft(WorkoutStepAt(40000)) != 10 {
return 3
}
if WorkoutAdvance(1000, 500, true) != 1000 || WorkoutAdvance(1000, 500, false) != 1500 ||
WorkoutAdvance(479000, 5000, false) != 480000 || WorkoutAdvance(1000, -3, false) != 1000 {
return 4
}
if WorkoutExerciseSeconds(5000) != 0 || WorkoutExerciseSeconds(25000) != 15 ||
WorkoutExerciseSeconds(45000) != 30 || WorkoutExerciseSeconds(480000) != 360 {
return 5
}
key: [64]u8
if WorkoutCueKey(WorkoutStepAt(0), key[:]) != "workout_say_start" ||
WorkoutCueKey(WorkoutStepAt(6999), key[:]) != "workout_say_start" ||
WorkoutCueKey(WorkoutStepAt(7000), key[:]) != "workout_say_count_3" ||
WorkoutCueKey(WorkoutStepAt(8500), key[:]) != "workout_say_count_2" ||
WorkoutCueKey(WorkoutStepAt(9999), key[:]) != "workout_say_count_1" ||
WorkoutCueKey(WorkoutStepAt(10000), key[:]) != "workout_say_go" ||
WorkoutCueKey(WorkoutStepAt(40000), key[:]) != "workout_say_next_wall_sit" ||
WorkoutCueKey(WorkoutStepAt(47000), key[:]) != "workout_say_count_3" ||
WorkoutCueKey(WorkoutStepAt(49500), key[:]) != "workout_say_count_1" ||
WorkoutCueKey(WorkoutStepAt(50000), key[:]) != "workout_say_go" ||
WorkoutCueKey(WorkoutStepAt(450000), key[:]) != "workout_say_go" ||
WorkoutCueKey(WorkoutStepAt(465000), key[:]) != "workout_say_switch" ||
WorkoutCueKey(WorkoutStepAt(480000), key[:]) != "" {
return 6
}
// The countdown shows every second of getting ready and of each rest,
// then Go as the exercise starts, and nothing while it runs.
if WorkoutCountdownAt(WorkoutStepAt(0)) != 10 || WorkoutCountdownAt(WorkoutStepAt(9001)) != 1 ||
WorkoutCountdownAt(WorkoutStepAt(10000)) != WORKOUT_COUNT_GO ||
WorkoutCountdownAt(WorkoutStepAt(10799)) != WORKOUT_COUNT_GO ||
WorkoutCountdownAt(WorkoutStepAt(10800)) != WORKOUT_COUNT_NONE ||
WorkoutCountdownAt(WorkoutStepAt(40000)) != 10 || WorkoutCountdownAt(WorkoutStepAt(47500)) != 3 ||
WorkoutCountdownAt(WorkoutStepAt(480000)) != WORKOUT_COUNT_NONE {
return 12
}
if WorkoutKeyFor("workout_name_", 12, key[:]) != "" || WorkoutKeyFor("workout_name_", -1, key[:]) != "" ||
WorkoutKeyFor("workout_name_", 7, key[:]) != "workout_name_plank" {
return 7
}
rig := WorkoutRig()
if !Near(rig.height, 1.65, 0.0001) || !Near(rig.leg_length, 0.478 * 1.65, 0.0001) ||
!Near(rig.pelvis_height, (0.046 + 0.478 + 0.025) * 1.65, 0.0001) {
return 8
}
for exercise: cast(s32)0..WORKOUT_EXERCISE_COUNT - 1 {
rest := WorkoutRestPose(exercise, 1234, *rig)
if !FigureSound(*rest, *rig, exercise) {
return 100 + exercise
}
time: s64 = 0
while time < cast(s64)WORKOUT_WORK_MS {
pose := WorkoutPoseAt(exercise, time, *rig)
if !FigureSound(*pose, *rig, exercise) {
return 200 + exercise
}
time += 70
}
}
if !SquatArmsLevel(*rig) {
return 10
}
// Props stand only where they belong.
if !WorkoutPropsSound() {
return 9
}
// The side plank switches sides halfway by rolling over face down: the
// planted hand changes side, her head stays toward the same end and
// she faces the other way.
first := WorkoutPoseAt(WORKOUT_SIDE_PLANK, 7000, *rig)
second := WorkoutPoseAt(WORKOUT_SIDE_PLANK, 22000, *rig)
if first.hands[1].mode != WORKOUT_AT_WORLD || second.hands[0].mode != WORKOUT_AT_WORLD ||
!Near(first.hands[1].at.x, second.hands[0].at.x, 0.0001) || !Near(second.yaw, 180.0 - first.yaw, 0.0001) {
return 11
}
english := ReadText("en", english_bytes[:])
codes: [12]string = .["en", "cs", "de", "es", "fr", "id", "it", "ja", "ko", "pt", "ru", "zh"]
for index: cast(s32)0..11 {
if !TextComplete(codes[index], english) {
return 300 + index
}
}
awkward := WorkoutMotionAwkward()
if awkward >= 0 {
return 500 + awkward
}
return 42
}