-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-renders.sh
More file actions
executable file
·78 lines (71 loc) · 3 KB
/
Copy pathmake-renders.sh
File metadata and controls
executable file
·78 lines (71 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# Draw every screen of the app and put the pictures where docs/model reads them.
#
# ./make-renders.sh every screen
# ./make-renders.sh practice one screen, which is the difference between
# waiting for four minutes and waiting for twenty seconds
#
# The renderer paints the real composables off-screen with a written practice history, so a picture
# comes from the same code the app runs and cannot quietly stop matching it. Each screen is drawn
# upright and wide, light and dark.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
gallery="$here/composeApp/build/gallery"
model="$here/docs/model/img"
classpath="$here/composeApp/build/gallery-classpath.txt"
# Skiko loads libGL, X11 and fontconfig by soname, which on NixOS live in the store rather than in
# /usr/lib. The store paths carry a hash and change with every nixpkgs bump, so they are looked up
# by package name at run time; on a distribution with an ordinary /usr/lib nothing matches and the
# loader finds them itself.
if [ -d /nix/store ]; then
libs=""
for pattern in libglvnd libx11 libxcb libxau libxdmcp fontconfig freetype gcc; do
for dir in /nix/store/*-"$pattern"-*/lib; do
[ -d "$dir" ] || continue
# A -dev output carries headers and a stub; the library itself is in the plain one.
case "$dir" in */*-dev/lib) continue ;; esac
libs="$libs:$dir"
done
done
export LD_LIBRARY_PATH="${libs#:}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
only="${1:-}"
echo "Compiling…"
"$here/gradlew" :composeApp:galleryClasspath -q --console=plain
# Compose draws one scene at a time in a process, and a scene is a few seconds of software
# rasterising, so the scenes are dealt out to as many processes as the machine has cores to spare.
workers=$(nproc 2>/dev/null || echo 4)
workers=$(( workers > 8 ? 8 : workers ))
[ -n "$only" ] && workers=1
echo "Rendering ${only:-every screen} in $workers processes…"
pids=""
for shard in $(seq 0 $((workers - 1))); do
java \
-Dgallery.out="$gallery" \
-Dgallery.homes="$here/composeApp/build/gallery-home" \
-Dgallery.shard="$shard" \
-Dgallery.shards="$workers" \
${only:+-Dgallery.only="$only"} \
-Djava.awt.headless=true \
-Dskiko.renderApi=SOFTWARE \
-cp "$(cat "$classpath")" \
it.bosler.numeracy.gallery.GalleryKt &
pids="$pids $!"
done
for pid in $pids; do wait "$pid"; done
mkdir -p "$model" "$model/small" "$model/card"
count=0
for source in "$gallery"/*.png; do
[ -e "$source" ] || continue
cp "$source" "$model/$(basename "$source")"
count=$((count + 1))
done
# The book asks for a small copy where it shows one small and a card on the index; served the full
# picture instead, every thumbnail costs a quarter of a megabyte.
for sized in small card; do
for source in "$gallery/$sized"/*.png; do
[ -e "$source" ] || continue
cp "$source" "$model/$sized/$(basename "$source")"
done
done
echo "$count renders in docs/model/img, with small and card copies beside them"