fart/main/fart.cc
Josh Holtrop 33f554d714 reworking distrib & Scene to work together
git-svn-id: svn://anubis/fart/trunk@226 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2009-04-06 18:38:30 +00:00

138 lines
4.3 KiB
C++

#include <iostream>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/time.h> /* gettimeofday() */
#include <string>
#include <map>
#include "Scene.h"
using namespace std;
void usage(const char * progname)
{
cout << "Usage: " << progname << " [options] <scene-file>" << endl;
cout << " Options:" << endl;
cout << " -o|--output-file <output-file-name>" << endl;
cout << " -w|--width <image-width>" << endl;
cout << " -h|--height <image-height>" << endl;
cout << " -m|--multisample <level>" << endl;
cout << " -f|--field-of-view <vertical-fov>" << endl;
cout << " -d|--max-depth <max-recursion-depth>" << endl;
cout << " --hosts <hosts-file>" << endl;
cout << " -v|--verbose" << endl;
exit(42);
}
int main(int argc, char * argv[])
{
int opt;
int option_index;
map<string, const char *> scene_options;
bool server = true;
static const struct option long_options[] = {
{ "output-file", required_argument, NULL, 'o' },
{ "width", required_argument, NULL, 'w' },
{ "height", required_argument, NULL, 'h' },
{ "multisample", required_argument, NULL, 'm' },
{ "field-of-view", required_argument, NULL, 'f' },
{ "max-depth", required_argument, NULL, 'd' },
{ "verbose", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 256 },
{ "host", required_argument, NULL, 257 },
{ "port", required_argument, NULL, 258 },
{ "hosts", required_argument, NULL, 259 },
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "o:w:h:m:f:d:v",
long_options, &option_index)) != -1)
{
switch (opt)
{
case 'o':
scene_options["output-file"] = optarg;
break;
case 'w':
scene_options["width"] = optarg;
break;
case 'h':
scene_options["height"] = optarg;
break;
case 'm':
scene_options["multisample"] = optarg;
break;
case 'f':
scene_options["field-of-view"] = optarg;
break;
case 'd':
scene_options["max-depth"] = optarg;
break;
case 'v':
scene_options["verbose"] = optarg;
break;
case 256:
usage(argv[0]);
break;
case 257:
scene_options["host"] = optarg;
server = false;
break;
case 258:
scene_options["port"] = optarg;
break;
case 259:
scene_options["hosts"] = optarg;
break;
default:
usage(argv[0]);
break;
}
}
if (optind >= argc)
{
usage(argv[0]);
}
Scene scene(scene_options, argv[optind]);
struct timeval before, after;
gettimeofday(&before, NULL); /* start timing */
scene.render();
gettimeofday(&after, NULL); /* stop timing */
if (server)
{
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
double total_seconds = time_after - time_before;
cout << "Elapsed time: " << total_seconds << " seconds";
double seconds = total_seconds;
int days = (int) (seconds / (60.0 * 60.0 * 24.0));
seconds -= days * 60.0 * 60.0 * 24.0;
int hours = (int) (seconds / (60.0 * 60.0));
seconds -= hours * 60.0 * 60.0;
int minutes = (int) (seconds / 60.0);
seconds -= minutes * 60.0;
if (days || hours || minutes)
{
cout << " (";
if (days)
cout << days << (days == 1 ? " day, " : " days, ");
if (days || hours)
cout << hours << (hours == 1 ? " hour, " : " hours, ");
cout << minutes << (minutes == 1 ? " minute, " : " minutes, ");
cout << seconds << (seconds == 1 ? " second)" : " seconds)");
}
cout << endl;
}
return 0;
}