diff --git a/tools/darkroom/darkcult.py b/tools/darkroom/darkcult.py new file mode 100755 index 00000000..5948856d --- /dev/null +++ b/tools/darkroom/darkcult.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import sys +import os +import subprocess +import multiprocessing + +def compile(command): + sys.stdout.write(".") + sys.stdout.flush() + return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + +if __name__=="__main__": + argv = sys.argv + argc = len(argv) + + src = argv[1] + stagedir = argv[2] + output = argv[3] + compiler = argv[4] + width = int(argv[5]) + height = int(argv[6]) + tile_width = int(argv[7]) + tile_height = int(argv[8]) + compile_options = argv[9] + darkcult_cpp = argv[10] + max_procs = int(argv[11]) + + commands = [] + for y in range(0, height, tile_height): + for x in range(0, width, tile_width): + bin = "%s/%d/%d.out" % (stagedir, y, x) + out = "%s/%d/%d.ppm" % (stagedir, y, x) + command = "%s -o %s" \ + " %s" \ + " -DDARKROOM_SOURCE=\'\"%s\"\'" \ + " -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \ + " -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \ + " -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \ + " %s" \ + " && %s > %s" \ + % (compiler, bin, + compile_options, + src, + width, height, + tile_width, tile_height, + x, y, + darkcult_cpp, + bin, out + ) + commands.append(command); + + pool = multiprocessing.Pool(max_procs) + sys.exit(any(pool.map(compile, commands))) diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh index 0dde1217..080adf07 100755 --- a/tools/darkroom/darkcult.sh +++ b/tools/darkroom/darkcult.sh @@ -21,10 +21,13 @@ declare -a user_macros user_macros=() declare -a include_paths include_paths=() +max_procs=1 force=0 use_help=0 +darkcult_cpp=$(cd $(dirname $0); pwd)/darkcult.cpp +darkcult_py=$(cd $(dirname $0); pwd)/darkcult.py -args=`getopt -o s:S:o:C:w:h:W:H:D:I:f -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,define:,include:,force,help -- "$@"` +args=`getopt -o s:S:o:C:w:h:W:H:D:I:P:f -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,define:,include:,max-procs:,force,help -- "$@"` if [ "$?" -ne 0 ]; then echo >&2 "error: options parse error. See 'darkcult.sh --help'" exit 1 @@ -42,6 +45,7 @@ while [ -n "$1" ]; do -H|--tile-height) tile_height=$2; shift 2;; -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; + -P|--max_procs) max_procs=$2; shift 2;; -f|--force) force=1; shift;; --help) use_help=1; shift;; --) shift; break;; @@ -80,6 +84,9 @@ if [ ${use_help} -ne 0 ]; then echo "" echo " -I, --include=