: ${del_src:=false}
: ${git_src_repo:=}
+selfprofile_t0=`date +%s`
+selfprofile_step=init
+selfprofile()
+{
+ selfprofile_t=`date +%s`
+ eval "selfprofile_counter_$selfprofile_step=\$((\$selfprofile_counter_$selfprofile_step+$selfprofile_t))"
+ selfprofile_step=$1
+ eval "selfprofile_counter_$selfprofile_step=\$((\$selfprofile_counter_$selfprofile_step-$selfprofile_t))"
+ selfprofile_t0=$selfprofile_t
+}
+
me=$0
case "$me" in
*/*)
trap 'exit 1' INT
trap 'rm -rf "$tmpdir"' EXIT
+
+use_magnet_to_acquire_checksum_faster()
+# ___________________
+# ,--'' ~~~~~~~^^^~._ '.
+# ,.-' ~~~~~~~~~~^^^^^~~~._._ \
+# | /^^^^^| /^^^^^^^^\\ \ \
+# ,/___ < o> < (OO) > _ \
+# /'/, |- . ----.\
+# |(|-'^^;,- ,| __ ^~~^^^^^^^; |\
+# \\` | <;_ __ |`--- ..-^^/- | ||
+# \`-|Oq-.____`________~='^^|__,/ ' //
+# \ || | | | | \ ..-;| / '/
+# | ||#|#|the|==|game!|'^` |/' /'
+# | \\\\^\***|***| \ ,,;' /
+# | `-=\_\__\___\__..-' ,.- - ,/
+# | . `-_ ------ _,-'^-'^,-'
+# | `-._________..--''^,-''^
+# \ ,...-'^
+# `----------'^ PROBLEM?
+{
+ magnet=`GIT_DIR="$git_src_repo/.git" git ls-files -s "$1"`
+ if [ -n "$magnet" ]; then
+ magnet=${magnet#* }
+ magnet=${magnet%% *}
+ sum=$sum$magnet
+ else
+ sum=$sum`git hash-object "$1"`
+ fi
+}
+
lastinfiles=
lastinfileshash=
cached()
keep=true
fi
options=`echo "$*" | git hash-object --stdin`
+ selfprofile convert_findchecksum
if [ x"$infile1/../$infile2" = x"$lastinfiles" ]; then
sum=$lastinfileshash
else
esac
done
if [ -n "$git_src_repo" ] && ! $evil; then
- sum=`( cd "$git_src_repo"; git ls-files -s "${infile1#./}" | cut -d ' ' -f 2 | grep . ) || { echo >&2 "git-ls-files failed on $infile1"; git hash-object "$infile1"; }`
+ sum=
+ use_magnet_to_acquire_checksum_faster "${infile1#./}"
if [ -n "$infile2" ]; then
- sum=$sum`( cd "$git_src_repo"; git ls-files -s "${infile2#./}" | cut -d ' ' -f 2 | grep . ) || { echo >&2 "git-ls-files failed on $infile2"; git hash-object "$infile2"; }`
+ use_magnet_to_acquire_checksum_faster "${infile2#./}"
fi
else
sum=`git hash-object "$infile1"`
fi
lastinfileshash=$sum
fi
+ selfprofile convert_makecachedir
mkdir -p "$CACHEDIR/$method-$options"
name1="$CACHEDIR/$method-$options/$sum-1.${outfile1##*.}"
[ -z "$outfile2" ] || name2="$CACHEDIR/$method-$options/$sum-2.${outfile2##*.}"
tempfile1="${name1%/*}/new-${name1##*/}"
[ -z "$outfile2" ] || tempfile2="${name2%/*}/new-${name2##*/}"
if [ -f "$name1" ] && { [ -z "$outfile2" ] || [ -f "$name2" ]; }; then
+ selfprofile convert_copyoutput
case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln -f "$name1" "$outfile1" 2>/dev/null || { rm -f "$outfile1" && cp "$name1" "$outfile1"; }; }
[ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln -f "$name2" "$outfile2" 2>/dev/null || { rm -f "$outfile2" && cp "$name2" "$outfile2"; }; }; }
conv=true
- elif "$method" "$infile1" "$infile2" "$tempfile1" "$tempfile2" "$@"; then
+ elif selfprofile convert_makeoutput; "$method" "$infile1" "$infile2" "$tempfile1" "$tempfile2" "$@"; then
mv "$tempfile1" "$name1"
[ -z "$outfile2" ] || mv "$tempfile2" "$name2"
case "$outfile1" in */*) mkdir -p "${outfile1%/*}"; esac && { ln -f "$name1" "$outfile1" 2>/dev/null || { rm -f "$outfile1" && cp "$name1" "$outfile1"; }; }
[ -z "$outfile2" ] || { case "$outfile2" in */*) mkdir -p "${outfile2%/*}"; esac && { ln -f "$name2" "$outfile2" 2>/dev/null || { rm -f "$outfile2" && cp "$name2" "$outfile2"; }; }; }
conv=true
else
+ selfprofile convert_cleartemp
rm -f "$tempfile1"
rm -f "$tempfile2"
+ selfprofile convert_finished
exit 1
fi
+ selfprofile convert_finished
}
reduce_jpeg2_dds()
to_delete=
for F in "$@"; do
+ selfprofile prepareconvert
f=${F%.*}
echo >&2 "Handling $F..."
will_jpeg=$do_jpeg
will_dds=$do_dds
+ will_ogg=$do_ogg
case "$f" in
+ ./sounds/misc/talk*.wav) will_ogg=false ;; # engine "feature"
*_bump) will_dds=false ;;
+ *_norm) will_dds=false ;; # bad quality
./models/player/*) will_dds=false ;;
./models/sprites/*) will_dds=false ;;
./textures/*) ;;
will_jpeg=true
fi
fi
-
+ selfprofile startconvert
case "$F" in
*_alpha.jpg)
# handle in *.jpg case
rm -f "$F.hasalpha"
;;
*.ogg)
- cached "$do_ogg" reduce_ogg_ogg "$F" "" "$F" "" "$ogg_qual"
+ cached "$will_ogg" reduce_ogg_ogg "$F" "" "$F" "" "$ogg_qual"
;;
./sound/misc/null.wav)
# never convert this one
;;
*.wav)
- cached "$do_ogg" reduce_wav_ogg "$F" "" "${f}.ogg" "" "$ogg_qual"
+ cached "$will_ogg" reduce_wav_ogg "$F" "" "${f}.ogg" "" "$ogg_qual"
;;
esac
+ selfprofile marktodelete
if $del_src; then
if $conv; then
if ! $keep; then
fi
fi
fi
+ selfprofile symlinkfixing
# fix up DDS paths by a symbolic link
if [ -f "dds/${f}.dds" ]; then
if [ -z "${f##./textures/*}" ]; then
fi
fi
fi
+ selfprofile looping
done
+
for F in $to_delete; do
rm -f "$F"
done
+selfprofile finished_time
+set | grep ^selfprofile_counter_ >&2