-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.sh
executable file
·255 lines (222 loc) · 6.33 KB
/
sample.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\t\n'
: "${F7D2D:?Please export F7D2D with 7D2D install folder}"
usage() {
cat >&2 <<-USAGE
$0 [options] [<size> [<seed>]]
Defaults to all features and topologies with size 6144 and random seed.
Options:
--features Generate variations of all six features below
--towns
--wilderness
--rivers
--craters
--cracks
--lakes
--terrain Generate variations of all four topologies below
--plains
--hills
--mountains
--random
USAGE
exit 1
}
if [[ $# == 0 || $1 != -* ]]; then
set -- --features --terrain "$@"
fi
declare -a FEATURES=( )
declare -a TERRAIN=( )
# TODO: towns and wilderness as a different category than features
# TODO: compare terrain and features without prefabs
# TODO: accept "reference" options to select the default to compare against
# TODO: accept options to change the "default" settings
while [[ $# -gt 0 && $1 == -* ]]; do
case "$1" in
--towns | --wilderness | --rivers | --craters | --cracks | --lakes)
FEATURES=( "${FEATURES[@]}" "${1:2}" )
;;
--plains | --hills | --mountains | --random)
TERRAIN=( "${TERRAIN[@]}" "${1:2}" )
;;
--features)
FEATURES=( towns wilderness rivers craters cracks lakes )
;;
--terrain)
TERRAIN=( plains hills mountains random )
;;
*)
usage
;;
esac
shift
done
if [[ $# -gt 2 ]]; then
usage
fi
SIZE="${1:-6144}"
SEED="${2:-$(seed.sh)}"
echo "Generating samples of seed ${SEED} size ${SIZE}"
OUTDIR="${F7D2D}/sample/${SEED}"
THUMBS="${OUTDIR}/thumbs"
DTM="${OUTDIR}/dtm"
mkdir -p "${OUTDIR}"
timeIt() {
duration=$SECONDS
echo "World generated in $((duration / 60)) minutes and $((duration % 60)) seconds"
}
genOpt() {
declare OPT_NAME
OPT_NAME="$1"
shift
declare -a OPTS
OPTS=( "$@" )
declare opt
for opt in "${OPTS[@]}"; do
[[ -f stop ]] && break
NAME="${OPT_NAME}-${opt}"
if [[ -f "${OUTDIR}/${NAME}.zip" ]]; then
echo >&2 "Skipping ${NAME}"
continue
fi
rm -fr "${F7D2D}/UserData"
SECONDS=0
startClient.sh "--${OPT_NAME}" "${opt}" --wilderness None "${SIZE}" "${SEED}"
timeIt
# shellcheck disable=SC2012
COUNTY=$( ls -1rt "${F7D2D}/UserData/GeneratedWorlds/" | tail -1 )
WORLD="${F7D2D}/UserData/GeneratedWorlds/${COUNTY}"
savePreview.sh --world "${WORLD}" --name "${NAME}" --output "${OUTDIR}/${NAME}.zip" \
--options "--${OPT_NAME}" "${opt}" --endoptions "${SIZE}" "${NAME}"
TASK_LIST="$(tasklist.exe)"
if grep -q ^7DaysToDie.exe <<<"${TASK_LIST}"; then
taskkill.exe /IM "7DaysToDie.exe" /F /T
fi
done
}
NAME="Default"
if [[ -f "${OUTDIR}/${NAME}.zip" ]]; then
echo >&2 "Skipping ${NAME}"
else
rm -fr "${F7D2D}/UserData"
SECONDS=0
startClient.sh --wilderness None "${SIZE}" "${SEED}"
timeIt
# shellcheck disable=SC2012
COUNTY=$( ls -1rt "${F7D2D}/UserData/GeneratedWorlds/" | tail -1 )
WORLD="${F7D2D}/UserData/GeneratedWorlds/${COUNTY}"
savePreview.sh --world "${WORLD}" --name "${NAME}" --output "${OUTDIR}/${NAME}.zip" \
"${SIZE}" "${NAME}"
TASK_LIST="$(tasklist.exe)"
if grep -q ^7DaysToDie.exe <<<"${TASK_LIST}"; then
taskkill.exe /IM "7DaysToDie.exe" /F /T
fi
fi
if [[ ${#FEATURES[@]} -gt 0 ]]; then
echo "Generating features ${FEATURES[*]}"
for feature in "${FEATURES[@]}"; do
[[ -f stop ]] && break
if [[ "$feature" == towns ]]; then
genOpt "${feature}" Few Many
else
genOpt "${feature}" None Few Many
fi
done
fi
if [[ ${#TERRAIN[@]} -gt 0 ]]; then
echo "Generating topologies ${TERRAIN[*]}"
declare -a SEQ
SEQ=( $( seq 0 10 ) )
for topology in "${TERRAIN[@]}"; do
[[ -f stop ]] && break
genOpt "${topology}" "${SEQ[@]}"
done
fi
if [[ ${#FEATURES[@]} -gt 0 && ! -f stop ]]; then
cd "${OUTDIR}"
find . -name '*.zip' -print0 | xargs -0 -x -n1 -i unzip -u {} 'thumbs/*'
cd "${THUMBS}"
declare -a FILES=( -label Default "Default-${SIZE}.png" -label '%c' null: null: )
for feature in "${FEATURES[@]}"; do
if [[ "$feature" == towns ]]; then
FILES=( "${FILES[@]}" null: "${feature}-"{Few,Many}"-${SIZE}.png" )
else
FILES=( "${FILES[@]}" "${feature}-"{None,Few,Many}"-${SIZE}.png" )
fi
done
montage -geometry "+4+3" \
-tile 3x \
-pointsize 48 \
"${FILES[@]}" \
features.png
cd "${OUTDIR}"
find . -name '*.zip' -print0 | xargs -0 -x -n1 -i unzip -d dtm -u {} '*-dtm.png'
cd "${DTM}"
for feature in "${FEATURES[@]}"; do
for level in None Few Many; do
[[ -f "${feature}-${level}-${SIZE}-diff.png" ]] && continue
[[ -f "${feature}-${level}-${SIZE}-dtm.png" ]] || continue
compare \
-highlight-color red \
-lowlight-color black \
-set label $level \
"Default-${SIZE}-dtm.png" \
"${feature}-${level}-${SIZE}-dtm.png" \
"${feature}-${level}-${SIZE}-diff.png" \
|| : # Do not fail if images are different
done
done
cd "${THUMBS}"
DIM=$((SIZE / 16))
for feature in "${FEATURES[@]}"; do
for level in None Few Many; do
[[ -f "${feature}-${level}-${SIZE}-diff.png" ]] && continue
[[ -f "${feature}-${level}-${SIZE}.png" ]] || continue
convert \
"${feature}-${level}-${SIZE}.png" \
\( \
"../dtm/${feature}-${level}-${SIZE}-diff.png" \
-channel rgba \
-fill 'rgba(255,0,0,0.25)' \
-opaque red \
-transparent black \
-resize ${DIM}x${DIM} \
\) \
-composite \
-set label "${feature^} ${level}" \
"${feature}-${level}-${SIZE}-diff.png"
done
done
FILES=( -label Default "Default-${SIZE}.png" -label '%c' null: null: )
for feature in "${FEATURES[@]}"; do
if [[ "$feature" == towns ]]; then
FILES=( "${FILES[@]}" null: "${feature}-"{Few,Many}"-${SIZE}-diff.png" )
else
FILES=( "${FILES[@]}" "${feature}-"{None,Few,Many}"-${SIZE}-diff.png" )
fi
done
montage -geometry "+4+3" \
-tile 3x \
-pointsize 48 \
"${FILES[@]}" \
features-diff.png
fi
if [[ ${#TERRAIN[@]} -gt 0 && ! -f stop ]]; then
cd "${OUTDIR}"
find . -name '*.zip' -print0 | xargs -0 -x -n1 -i unzip -u {} 'thumbs/*'
cd "${THUMBS}"
declare -a FILES=( )
FILES=( )
for topology in "${TERRAIN[@]}"; do
FILES=( "${FILES[@]}" "${topology}-"[0-9]"-${SIZE}.png" "${topology}-10-${SIZE}.png" )
done
montage -geometry "+4+3" \
-tile 11x \
-pointsize 48 -label '%c' \
"${FILES[@]}" \
terrain.png
fi
[[ -f stop ]] && rm -f stop
[[ -f "${THUMBS}/features.png" ]] && echo "${THUMBS}/features.png"
[[ -f "${THUMBS}/features-diff.png" ]] && echo "${THUMBS}/features-diff.png"
[[ -f "${THUMBS}/terrain.png" ]] && echo "${THUMBS}/terrain.png"