added maximum depth command-line argument (-d) and scene option (max_depth); prettified elapsed time output when greater than 60 seconds

git-svn-id: svn://anubis/fart/trunk@203 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-03-10 00:01:21 +00:00
parent 4716b200fd
commit 9f9ce1a8f5
8 changed files with 47 additions and 6 deletions

2
.todo
View File

@ -2,5 +2,3 @@ FART To-Do List
===============
- Shape definitions / reusability
- Add distribution infrastructure
- Add maximum recursion depth option / parameter
- Prettify elapsed time output

View File

@ -188,6 +188,10 @@ void Scene::processOptions(refptr<Node> node)
{
m_multisample_level = (*it)->getInteger();
}
else if ( typeid(**it) == typeid(MaxDepthNode) )
{
m_max_depth = (*it)->getInteger();
}
}
}

View File

@ -57,6 +57,10 @@ Scene::Scene(const map<string, const char *> & options,
{
m_output_file_name = it->second;
}
else if (it->first == "max-depth")
{
m_max_depth = atoi(it->second);
}
else if (it->first == "verbose")
{
m_verbose = true;

View File

@ -36,11 +36,12 @@ int main(int argc, char * argv[])
{ "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' },
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "o:w:h:m:f:v",
while ((opt = getopt_long(argc, argv, "o:w:h:m:f:d:v",
long_options, &option_index)) != -1)
{
switch (opt)
@ -63,6 +64,9 @@ int main(int argc, char * argv[])
case 'f':
scene_options["field-of-view"] = optarg;
break;
case 'd':
scene_options["max-depth"] = optarg;
break;
case 'v':
scene_options["verbose"] = optarg;
break;
@ -87,8 +91,27 @@ int main(int argc, char * argv[])
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
double diff = time_after - time_before;
cout << "Elapsed time: " << diff << " seconds." << endl;
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, ";
if (days || hours)
cout << hours << " hours, ";
cout << minutes << " minutes, ";
cout << seconds << " seconds)";
}
cout << endl;
return 0;
}

View File

@ -153,6 +153,12 @@ class MaterialRefNode : public IdentifierNode
bool isMaterial() { return true; }
};
class MaxDepthNode : public IntegerNode
{
public:
MaxDepthNode(int i) : IntegerNode(i) {}
};
class MultisampleNode : public IntegerNode
{
public:

View File

@ -51,6 +51,7 @@ intersect return INTERSECT;
light return LIGHT;
look_at return LOOKAT;
material return MATERIAL;
max_depth return MAXDEPTH;
multisample return MULTISAMPLE;
options return OPTIONS;
plane return PLANE;

View File

@ -70,6 +70,7 @@ static refptr<Node> parsed_scene_node;
%token LIGHT;
%token LOOKAT;
%token MATERIAL;
%token MAXDEPTH;
%token MULTISAMPLE;
%token OPTIONS;
%token PLANE;
@ -281,6 +282,9 @@ options_item: WIDTH DEC_NUMBER {
| MULTISAMPLE DEC_NUMBER {
$$ = new MultisampleNode($2->getInteger());
}
| MAXDEPTH DEC_NUMBER {
$$ = new MaxDepthNode($2->getInteger());
}
;
plane: PLANE LCURLY plane_items RCURLY {

View File

@ -3,9 +3,10 @@ scene
{
options
{
multisample 3
multisample 4
width 1024
height 768
max_depth 15
}
camera