Skip to content

Commit

Permalink
Small fixes to compressor when outputing to a stat file.
Browse files Browse the repository at this point in the history
Added an acl_compressor python script to traverse a directory hierarchy and output stats.
  • Loading branch information
nfrechette committed Jun 12, 2017
1 parent 15eb63a commit d9461e4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 9 deletions.
71 changes: 71 additions & 0 deletions tools/acl_compressor/acl_compressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os
import sys

def parse_argv():
options = {}
options['acl'] = ""
options['stat'] = ""

for i in range(1, len(sys.argv)):
value = sys.argv[i]

# TODO: Strip trailing '/' or '\'
if value.startswith('-acl='):
options['acl'] = value[5:].replace('"', '')

if value.startswith('-stat='):
options['stat'] = value[6:].replace('"', '')

return options

def print_usage():
print('Usage: python acl_compressor.py -acl=<path to directory containing ACL files> -stat=<path to output directory for stats>')

if __name__ == "__main__":
options = parse_argv()

debug_exe_path = './x64/Debug/acl_compressor.exe'
release_exe_path = './x64/Release/acl_compressor.exe'

debug_exe_timestamp = os.path.getmtime(debug_exe_path)
release_exe_timestamp = os.path.getmtime(release_exe_path)

if release_exe_timestamp >= debug_exe_timestamp:
latest_exe_path = release_exe_path
else:
latest_exe_path = debug_exe_path

acl_dir = options['acl']
stat_dir = options['stat']

if not os.path.exists(acl_dir) or not os.path.isdir(acl_dir):
print('ACL input directory not found: {}'.format(acl_dir))
print_usage()
sys.exit(1)

if not os.path.exists(stat_dir):
os.makedirs(stat_dir)

if not os.path.isdir(stat_dir):
print('The output stat argument must be a directory')
print_usage()
sys.exit(1)

for (dirpath, dirnames, filenames) in os.walk(acl_dir):
stat_dirname = dirpath.replace(acl_dir, stat_dir)

for filename in filenames:
if not filename.endswith('.acl.js'):
continue

acl_filename = os.path.join(dirpath, filename)
stat_filename = os.path.join(stat_dirname, filename.replace('.acl.js', '_stats.txt'))

if not os.path.exists(stat_dirname):
os.makedirs(stat_dirname)

cmd = '{} -acl="{}" -stats="{}"'.format(latest_exe_path, acl_filename, stat_filename)
cmd = cmd.replace('/', '\\')

print('Compressing {}...'.format(acl_filename))
os.system(cmd)
47 changes: 39 additions & 8 deletions tools/acl_compressor/sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,48 @@ struct Options
bool output_stats;
const char* output_stats_filename;

//////////////////////////////////////////////////////////////////////////

std::FILE* output_stats_file;

Options()
: input_filename(nullptr),
output_stats(false)
, output_stats_filename(nullptr)
, output_stats_file(nullptr)
{}

Options(Options&& other)
: output_stats(other.output_stats)
, output_stats_filename(other.output_stats_filename)
, output_stats_file(other.output_stats_file)
{
new (&other) Options();
}

~Options()
{
if (output_stats_file != nullptr && output_stats_file != stdout)
std::fclose(output_stats_file);
}

Options& operator=(Options&& rhs)
{
std::swap(output_stats, rhs.output_stats);
std::swap(output_stats_filename, rhs.output_stats_filename);
std::swap(output_stats_file, rhs.output_stats_file);
}

Options(const Options&) = delete;
Options& operator=(const Options&) = delete;

void open_output_stats_file()
{
std::FILE* file = nullptr;
if (output_stats_filename != nullptr)
fopen_s(&file, output_stats_filename, "w");
output_stats_file = file != nullptr ? file : stdout;
}
};

constexpr char* FILE_OPTION = "-file=";
Expand All @@ -136,6 +173,7 @@ static bool parse_options(int argc, char** argv, Options& options)
{
options.output_stats = true;
options.output_stats_filename = argument[option_length] == '=' ? argument + option_length + 1 : nullptr;
options.open_output_stats_file();
continue;
}

Expand Down Expand Up @@ -260,10 +298,7 @@ static void print_stats(const Options& options, const acl::AnimationClip& clip,
QueryPerformanceFrequency(&frequency_cycles_per_sec);
double elapsed_time_sec = double(elapsed_cycles) / double(frequency_cycles_per_sec.QuadPart);

std::FILE* file = nullptr;
if (options.output_stats_filename != nullptr)
fopen_s(&file, options.output_stats_filename, "w");
file = file != nullptr ? file : stdout;
std::FILE* file = options.output_stats_file;

fprintf(file, "Clip algorithm: %s\n", get_algorithm_name(compressed_clip.get_algorithm_type()));
fprintf(file, "Clip rotation format: %s\n", get_rotation_format_name(rotation_format));
Expand All @@ -276,10 +311,6 @@ static void print_stats(const Options& options, const acl::AnimationClip& clip,
fprintf(file, "Clip num animated tracks: %u\n", clip.get_num_animated_tracks());
//fprintf(file, "Clip num segments: %u\n", 0); // TODO
fprintf(file, "\n");

if (file != stdout)
std::fclose(file);
file = nullptr;
}

static double find_max_error(acl::Allocator& allocator, const acl::AnimationClip& clip, const acl::RigidSkeleton& skeleton, const acl::CompressedClip& compressed_clip, acl::IAlgorithm& algorithm)
Expand Down
2 changes: 1 addition & 1 deletion tools/fbx2acl/fbx2acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ def convert_file(fbx_filename, acl_filename, zip):
if result:
sys.exit(0)
else:
sys.exit(1)
sys.exit(1)

0 comments on commit d9461e4

Please sign in to comment.