1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/tools/darkroom/darkcult.py

66 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2013-09-25 06:22:41 +00:00
# =============================================================================
# Copyright (c) 2011-2013 Bolero MURAKAMI
# 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)
# =============================================================================
import sys
2013-09-25 06:22:41 +00:00
import optparse
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)
2013-09-25 06:22:41 +00:00
def main():
parser = optparse.OptionParser(description='darkcult.py')
parser.add_option('--src', type='string')
parser.add_option('--stagedir', type='string')
parser.add_option('--output', type='string')
parser.add_option('--compiler', type='string')
parser.add_option('--width', type='int')
parser.add_option('--height', type='int')
parser.add_option('--tile_width', type='int')
parser.add_option('--tile_height', type='int')
parser.add_option('--compile_options', type='string')
parser.add_option('--darkcult_cpp', type='string')
parser.add_option('--max_procs', type='int')
(opts, args) = parser.parse_args()
2013-09-25 06:22:41 +00:00
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
2013-09-25 06:22:41 +00:00
def format_command(x, y):
bin = "%s/%d/%d.out" % (opts.stagedir, y, x)
out = "%s/%d/%d.ppm" % (opts.stagedir, y, x)
return "%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" \
% (opts.compiler, bin,
opts.compile_options,
opts.src,
opts.width, opts.height,
opts.tile_width, opts.tile_height,
x, y,
opts.darkcult_cpp,
bin, out
)
2013-09-25 06:22:41 +00:00
return any(pool.map(
compile,
[format_command(x, y)
for y in range(0, opts.height, opts.tile_height)
for x in range(0, opts.width, opts.tile_width)
2013-09-25 06:22:41 +00:00
]
))
2013-09-25 06:22:41 +00:00
if __name__=="__main__":
sys.exit(main())