2013-09-19 16:04:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# =============================================================================
|
2015-01-11 17:03:30 +00:00
|
|
|
# Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-09-19 16:04:30 +00:00
|
|
|
# https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
#
|
|
|
|
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
# =============================================================================
|
|
|
|
#
|
2013-09-21 04:56:23 +00:00
|
|
|
# requires: Netpbm (http://netpbm.sourceforge.net/)
|
2013-09-25 06:22:41 +00:00
|
|
|
# requires: Python (http://www.python.org/) if parallel mode
|
2013-09-19 16:04:30 +00:00
|
|
|
#
|
2013-09-19 17:40:19 +00:00
|
|
|
src="../../example/darkroom/two_spheres.hpp"
|
2013-09-19 16:04:30 +00:00
|
|
|
stagedir="darkroom"
|
2013-09-23 11:53:01 +00:00
|
|
|
output="out.ppm"
|
2013-09-23 12:10:58 +00:00
|
|
|
compiler="g++"
|
2013-09-19 16:04:30 +00:00
|
|
|
width=16
|
|
|
|
height=16
|
|
|
|
tile_width=16
|
|
|
|
tile_height=16
|
2013-09-29 05:47:04 +00:00
|
|
|
l=0
|
|
|
|
t=0
|
|
|
|
r=
|
|
|
|
b=
|
|
|
|
declare -a common_options=()
|
2013-09-26 14:09:53 +00:00
|
|
|
declare -a user_macros=()
|
|
|
|
declare -a include_paths=()
|
2013-09-29 05:47:04 +00:00
|
|
|
max_procs=
|
2013-09-19 16:04:30 +00:00
|
|
|
force=0
|
2013-09-29 05:47:04 +00:00
|
|
|
continuable=0
|
2014-02-20 03:02:48 +00:00
|
|
|
runtime=0
|
2013-09-23 09:56:57 +00:00
|
|
|
use_help=0
|
2013-09-24 12:51:05 +00:00
|
|
|
darkcult_cpp=$(cd $(dirname $0); pwd)/darkcult.cpp
|
|
|
|
darkcult_py=$(cd $(dirname $0); pwd)/darkcult.py
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2014-02-20 03:02:48 +00:00
|
|
|
args=`getopt -o s:S:o:C:w:h:W:H:l:t:r:b:O:D:I:P:fc -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,left:,top:,right:,bottom:,option:,define:,include:,max-procs:,force,continuable,runtime,help -- "$@"`
|
2013-09-19 16:04:30 +00:00
|
|
|
if [ "$?" -ne 0 ]; then
|
2013-09-24 01:05:47 +00:00
|
|
|
echo >&2 "error: options parse error. See 'darkcult.sh --help'"
|
2013-09-19 16:04:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
eval set -- ${args}
|
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
-s|--source) src=$2; shift 2;;
|
2013-09-20 07:38:27 +00:00
|
|
|
-S|--stagedir) stagedir=$2; shift 2;;
|
2013-09-23 11:53:01 +00:00
|
|
|
-o|--output) output=$2; shift 2;;
|
2013-09-23 12:10:58 +00:00
|
|
|
-C|--compiler) compiler=$2; shift 2;;
|
2013-09-19 16:04:30 +00:00
|
|
|
-w|--width) width=$2; shift 2;;
|
|
|
|
-h|--height) height=$2; shift 2;;
|
|
|
|
-W|--tile-width) tile_width=$2; shift 2;;
|
|
|
|
-H|--tile-height) tile_height=$2; shift 2;;
|
2013-09-29 05:47:04 +00:00
|
|
|
-l|--left) l=$2; shift 2;;
|
|
|
|
-t|--top) t=$2; shift 2;;
|
|
|
|
-r|--right) r=$2; shift 2;;
|
|
|
|
-b|--bottom) b=$2; shift 2;;
|
|
|
|
-O|--option) common_options=(${common_options[@]} "$2"); shift 2;;
|
2013-09-22 04:33:56 +00:00
|
|
|
-D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;;
|
2013-09-21 04:56:23 +00:00
|
|
|
-I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;;
|
2013-09-26 13:43:57 +00:00
|
|
|
-P|--max-procs) max_procs=$2; shift 2;;
|
2013-09-19 16:39:16 +00:00
|
|
|
-f|--force) force=1; shift;;
|
2013-09-29 05:47:04 +00:00
|
|
|
-c|--continuable) continuable=1; shift;;
|
2014-02-20 03:02:48 +00:00
|
|
|
--runtime) runtime=1; shift;;
|
2013-09-23 09:56:57 +00:00
|
|
|
--help) use_help=1; shift;;
|
2013-09-19 16:04:30 +00:00
|
|
|
--) shift; break;;
|
2013-09-23 09:56:57 +00:00
|
|
|
*) echo >&2 "error: unknown option($1) used."; exit 1;;
|
2013-09-19 16:04:30 +00:00
|
|
|
esac
|
|
|
|
done
|
2013-09-29 05:47:04 +00:00
|
|
|
: ${r:=${width}}
|
|
|
|
: ${b:=${height}}
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-23 09:56:57 +00:00
|
|
|
if [ ${use_help} -ne 0 ]; then
|
|
|
|
echo "help:"
|
|
|
|
echo ""
|
|
|
|
echo " -s, --source=<file> Indicates the source file."
|
2013-09-23 11:53:01 +00:00
|
|
|
echo " Default; '../../example/darkroom/two_spheres.hpp'"
|
2013-09-23 09:56:57 +00:00
|
|
|
echo ""
|
2013-09-24 07:04:19 +00:00
|
|
|
echo " -S, --stagedir=<dir> Output files here."
|
2013-09-23 11:53:01 +00:00
|
|
|
echo " Default; 'darkroom'"
|
|
|
|
echo ""
|
|
|
|
echo " -o, --output=<file> Output file of the result."
|
|
|
|
echo " Default; 'out.ppm'"
|
2013-09-23 09:56:57 +00:00
|
|
|
echo ""
|
2013-09-23 12:10:58 +00:00
|
|
|
echo " -C, --compiler=<command> Compiler to use."
|
|
|
|
echo " Default; 'g++'"
|
|
|
|
echo ""
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " -w, --width=<value> Output width of rendering."
|
|
|
|
echo " Default; 16"
|
|
|
|
echo ""
|
|
|
|
echo " -h, --height=<value> Output height of rendering."
|
|
|
|
echo " Default; 16"
|
|
|
|
echo ""
|
|
|
|
echo " -W, --tile-width=<value> Output width of divided rendering."
|
|
|
|
echo " Default; 16"
|
|
|
|
echo ""
|
|
|
|
echo " -H, --tile-height=<value> Output height of divided rendering."
|
|
|
|
echo " Default; 16"
|
|
|
|
echo ""
|
2013-09-29 05:47:04 +00:00
|
|
|
echo " -l, --left=<value> Left X position of rendering range."
|
|
|
|
echo " Default; 0"
|
|
|
|
echo ""
|
|
|
|
echo " -t, --top=<value> Top Y position of rendering range."
|
|
|
|
echo " Default; 0"
|
|
|
|
echo ""
|
|
|
|
echo " -r, --right=<value> Right X position of rendering range."
|
|
|
|
echo " Default; <width>"
|
|
|
|
echo ""
|
|
|
|
echo " -b, --bottom=<value> Bottom Y position of rendering range."
|
|
|
|
echo " Default; <height>"
|
|
|
|
echo ""
|
|
|
|
echo " -O, --option=<opt> Add compile option."
|
|
|
|
echo ""
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " -D, --define=<identifier> Define macro for preprocessor."
|
|
|
|
echo ""
|
2013-09-24 07:04:19 +00:00
|
|
|
echo " -I, --include=<dir> Add system include path."
|
2013-09-23 09:56:57 +00:00
|
|
|
echo ""
|
2013-09-24 12:51:05 +00:00
|
|
|
echo " -P, --max-procs=<value> The maximum number of process use."
|
2013-09-29 05:47:04 +00:00
|
|
|
echo " If other than null, processing in parallel mode."
|
2013-09-25 06:22:41 +00:00
|
|
|
echo " If 0, using the number of CPUs in the system."
|
2013-09-24 12:51:05 +00:00
|
|
|
echo ""
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " -f, --force Allow overwrite of <stagedir>."
|
|
|
|
echo ""
|
2013-09-29 05:47:04 +00:00
|
|
|
echo " -c, --continuable Enable break/continue mode."
|
|
|
|
echo " Press <Enter>; check finished."
|
|
|
|
echo " Press 'q' ; terminate compile."
|
|
|
|
echo ""
|
2014-02-20 03:02:48 +00:00
|
|
|
echo " --runtime Enable runtime mode."
|
|
|
|
echo ""
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " --help This message."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "settings:"
|
2013-09-23 12:10:58 +00:00
|
|
|
echo " source = '${src}'"
|
|
|
|
echo " stagedir = '${stagedir}'"
|
|
|
|
echo " output = '${output}'"
|
|
|
|
echo " compiler = '${compiler}'"
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " width = ${width}"
|
|
|
|
echo " height = ${height}"
|
|
|
|
echo " tile-width = ${tile_width}"
|
|
|
|
echo " tile-height = ${tile_height}"
|
2013-09-29 05:47:04 +00:00
|
|
|
echo " left = ${l}"
|
|
|
|
echo " top = ${t}"
|
|
|
|
echo " right = ${r}"
|
|
|
|
echo " bottom = ${b}"
|
2013-09-25 06:22:41 +00:00
|
|
|
echo " user-macros = (${user_macros[*]})"
|
|
|
|
echo " include-paths = (${include_paths[*]})"
|
2013-09-24 12:51:05 +00:00
|
|
|
echo " max-procs = ${max_procs}"
|
2013-09-23 09:56:57 +00:00
|
|
|
echo " force = ${force}"
|
2013-09-29 05:47:04 +00:00
|
|
|
echo " continuable = ${continuable}"
|
2014-02-20 03:02:48 +00:00
|
|
|
echo " runtime = ${runtime}"
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-19 17:40:19 +00:00
|
|
|
if [ ! -f "${src}" -a ! -f "$(cd $(dirname $0); pwd)/${src}" ]; then
|
2013-09-23 09:56:57 +00:00
|
|
|
echo >&2 "error: source(${src}) not exists."
|
2013-09-19 16:04:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-09-25 06:22:41 +00:00
|
|
|
for user_macro in ${user_macros}; do
|
|
|
|
define_options="${define_options} -D${user_macro}"
|
|
|
|
done
|
|
|
|
for include_path in ${include_paths}; do
|
|
|
|
include_options="${include_options} -I${include_path}"
|
|
|
|
done
|
2013-09-29 05:47:04 +00:00
|
|
|
compile_options="-std=c++11 ${define_options} ${include_options} ${common_options[*]}"
|
2014-02-20 03:02:48 +00:00
|
|
|
if [ ${runtime} -ne 0 ]; then
|
|
|
|
compile_options="${compile_options} -DDARKROOM_RUNTIME"
|
|
|
|
fi
|
2013-09-25 06:22:41 +00:00
|
|
|
|
2013-09-19 16:04:30 +00:00
|
|
|
if [ -d "${stagedir}" ]; then
|
|
|
|
if [ ${force} -eq 0 ]; then
|
2013-09-29 05:47:04 +00:00
|
|
|
if [ ${continuable} -eq 0 ]; then
|
|
|
|
echo >&2 "error: stagedir(${stagedir}) already exists."
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-09-19 16:04:30 +00:00
|
|
|
else
|
|
|
|
rm -f -r ${stagedir}/*
|
|
|
|
fi
|
2013-09-29 05:47:04 +00:00
|
|
|
rm -f ${stagedir}/*.ppm
|
2013-09-19 16:04:30 +00:00
|
|
|
else
|
|
|
|
mkdir -p ${stagedir}
|
|
|
|
fi
|
2013-09-24 12:51:05 +00:00
|
|
|
for ((y=0; y<height; y+=tile_height)); do
|
|
|
|
mkdir -p ${stagedir}/${y}/
|
|
|
|
done
|
|
|
|
|
2013-09-23 11:53:01 +00:00
|
|
|
echo "rendering:"
|
2013-09-20 07:38:27 +00:00
|
|
|
start=${SECONDS}
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-29 05:47:04 +00:00
|
|
|
if [ -z "${max_procs}" ]; then
|
|
|
|
for ((y=t; y<b; y+=tile_height)); do
|
2013-09-24 12:51:05 +00:00
|
|
|
echo " y = (${y}/${height})..."
|
|
|
|
y_start=${SECONDS}
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-24 12:51:05 +00:00
|
|
|
echo -n " x = "
|
2013-09-29 05:47:04 +00:00
|
|
|
for ((x=l; x<r; x+=tile_width)); do
|
2013-09-25 06:22:41 +00:00
|
|
|
echo -n "(${x}/${height})."
|
|
|
|
bin=${stagedir}/${y}/${x}.out
|
|
|
|
out=${stagedir}/${y}/${x}.ppm
|
2013-09-24 12:51:05 +00:00
|
|
|
${compiler} -o ${bin} \
|
|
|
|
${compile_options} \
|
|
|
|
-DDARKROOM_SOURCE="\"${src}\"" \
|
|
|
|
-DDARKROOM_TOTAL_WIDTH=${width} -DDARKROOM_TOTAL_HEIGHT=${height} \
|
|
|
|
-DDARKROOM_TILE_WIDTH=${tile_width} -DDARKROOM_TILE_HEIGHT=${tile_height} \
|
|
|
|
-DDARKROOM_OFFSET_X=${x} -DDARKROOM_OFFSET_Y=${y} \
|
2013-09-25 06:22:41 +00:00
|
|
|
${darkcult_cpp} \
|
|
|
|
&& ${bin} > ${out}
|
2013-09-24 12:51:05 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo ""
|
2013-09-29 05:47:04 +00:00
|
|
|
echo >&2 " error: compile(${y}/${x}) failed."
|
2013-09-24 12:51:05 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
|
2013-09-26 13:43:57 +00:00
|
|
|
let y_elapsed=${SECONDS}-${y_start}
|
2013-09-24 12:51:05 +00:00
|
|
|
echo " elapsed = ${y_elapsed}s"
|
2013-09-20 07:38:27 +00:00
|
|
|
done
|
2013-09-24 12:51:05 +00:00
|
|
|
else
|
|
|
|
echo " processing in parallel mode."
|
2013-09-29 05:47:04 +00:00
|
|
|
if [ ${continuable} -ne 0 ]; then
|
|
|
|
echo " enable break/continue mode."
|
|
|
|
fi
|
2013-09-24 12:51:05 +00:00
|
|
|
echo -n " "
|
|
|
|
python "${darkcult_py}" \
|
2013-09-29 05:47:04 +00:00
|
|
|
"--source=${src}" "--stagedir=${stagedir}" "--output=${output}" "--compiler=${compiler}" \
|
2013-09-25 06:22:41 +00:00
|
|
|
"--width=${width}" "--height=${height}" \
|
|
|
|
"--tile_width=${tile_width}" "--tile_height=${tile_height}"" "\
|
2013-09-29 05:47:04 +00:00
|
|
|
"--left=${l}" "--top=${t}" \
|
|
|
|
"--right=${r}" "--bottom=${b}" \
|
2013-09-25 06:22:41 +00:00
|
|
|
"--compile_options=${compile_options}" "--darkcult_cpp=${darkcult_cpp}" \
|
2013-09-29 05:47:04 +00:00
|
|
|
"--continuable=${continuable}" "--continue_file=${stagedir}/continue.log" \
|
2013-09-25 06:22:41 +00:00
|
|
|
"--max_procs=${max_procs}"
|
2013-09-29 05:47:04 +00:00
|
|
|
result=$?
|
2013-09-26 13:43:57 +00:00
|
|
|
echo ""
|
2013-09-29 05:47:04 +00:00
|
|
|
if [ ${result} -eq 2 ]; then
|
|
|
|
echo " compile terminated."
|
|
|
|
exit 0
|
|
|
|
elif [ ${result} -ne 0 ]; then
|
|
|
|
echo >&2 " error: compile failed."
|
2013-09-24 12:51:05 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-09-26 13:43:57 +00:00
|
|
|
let elapsed=${SECONDS}-${start}
|
2013-09-24 12:51:05 +00:00
|
|
|
echo " elapsed(total) = ${elapsed}s"
|
2013-09-23 11:53:01 +00:00
|
|
|
|
2013-09-24 12:51:05 +00:00
|
|
|
for ((y=0; y<height; y+=tile_height)); do
|
2013-09-20 07:38:27 +00:00
|
|
|
pushd ${stagedir}/${y}/ > /dev/null
|
2013-09-21 04:56:23 +00:00
|
|
|
pnmcat -lr $(ls *.ppm | sort -n) > ../${y}.ppm
|
2013-09-20 07:38:27 +00:00
|
|
|
popd > /dev/null
|
|
|
|
done
|
|
|
|
pushd ${stagedir} > /dev/null
|
2013-09-23 11:53:01 +00:00
|
|
|
pnmcat -tb $(ls *.ppm | sort -n) > ${output}
|
2013-09-20 07:38:27 +00:00
|
|
|
popd > /dev/null
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-23 09:56:57 +00:00
|
|
|
echo "finished."
|