Rename RenderParams -> Options
This commit is contained in:
1 parent
de2c51376a
commit
6f8e3714da
9 files changed
+25
-25
No files matched your search
+4
-4
@@ -172,7 +172,7 @@ int Cli::handle_option(size_t flag_idx, const char * arg_value)
|
||||
{
|
||||
case flag_height:
|
||||
case flag_height_l:
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->params.height))
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->options.height))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
@@ -198,11 +198,11 @@ int Cli::handle_option(size_t flag_idx, const char * arg_value)
|
||||
|
||||
case flag_threads:
|
||||
case flag_threads_l:
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->params.threads))
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->options.threads))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (*this->params.threads == 0u)
|
||||
if (*this->options.threads == 0u)
|
||||
{
|
||||
fprintf(stderr, "Error: option %s must be at least 1\n", flag_defs[flag_idx].flag);
|
||||
return 2;
|
||||
@@ -211,7 +211,7 @@ int Cli::handle_option(size_t flag_idx, const char * arg_value)
|
||||
|
||||
case flag_width:
|
||||
case flag_width_l:
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->params.width))
|
||||
if (!parse_size(flag_defs[flag_idx].flag, arg_value, &this->options.width))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <fart/RenderParams.h>
|
||||
#include <fart/Options.h>
|
||||
|
||||
class Cli
|
||||
{
|
||||
public:
|
||||
RenderParams params;
|
||||
Options options;
|
||||
string_view input_file;
|
||||
opt<string_view> output_file;
|
||||
|
||||
|
||||
+5
-5
@@ -4,8 +4,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
Engine::Engine(const RenderParams & params)
|
||||
: params(params)
|
||||
Engine::Engine(const Options & options)
|
||||
: options(options)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ int Engine::run(string_view input_file, opt<string_view> output_file)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* CLI params take precedence over scene params; defaults fill the rest. */
|
||||
params.merge(scene->params);
|
||||
params.apply_defaults();
|
||||
/* CLI options take precedence over scene options; defaults fill the rest. */
|
||||
options.merge(scene->options);
|
||||
options.apply_defaults();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+3
-3
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <fart/ImageWriter.h>
|
||||
#include <fart/RenderParams.h>
|
||||
#include <fart/Options.h>
|
||||
#include <fart/Scene.h>
|
||||
#include <memory>
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
Engine(const RenderParams & params);
|
||||
Engine(const Options & options);
|
||||
~Engine();
|
||||
int run(string_view input_file, opt<string_view> output_file);
|
||||
|
||||
protected:
|
||||
RenderParams params;
|
||||
Options options;
|
||||
std::unique_ptr<ImageWriter> image_writer;
|
||||
Scene * scene = nullptr;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fart/RenderParams.h>
|
||||
#include <fart/Options.h>
|
||||
#include <thread>
|
||||
|
||||
void RenderParams::merge(const RenderParams & other)
|
||||
void Options::merge(const Options & other)
|
||||
{
|
||||
if (!width)
|
||||
{
|
||||
@@ -21,7 +21,7 @@ void RenderParams::merge(const RenderParams & other)
|
||||
}
|
||||
}
|
||||
|
||||
void RenderParams::apply_defaults()
|
||||
void Options::apply_defaults()
|
||||
{
|
||||
if (!width)
|
||||
{
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <fart/Color.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct RenderParams
|
||||
struct Options
|
||||
{
|
||||
opt<size_t> width;
|
||||
opt<size_t> height;
|
||||
@@ -11,7 +11,7 @@ struct RenderParams
|
||||
opt<Color> background;
|
||||
|
||||
/* Set each field that is not already set to the value from other. */
|
||||
void merge(const RenderParams & other);
|
||||
void merge(const Options & other);
|
||||
|
||||
/* Fill in any unset fields with default values. */
|
||||
void apply_defaults();
|
||||
+3
-3
@@ -124,15 +124,15 @@ Scene * Parser::build_scene(const string_view & input_file, PStart start)
|
||||
bool ok = true;
|
||||
if (PBackground background = item.pBackground(); p_node_valid(background))
|
||||
{
|
||||
scene->params.background = vector_to_color(background.pVector());
|
||||
scene->options.background = vector_to_color(background.pVector());
|
||||
}
|
||||
else if (PHeight height = item.pHeight(); p_node_valid(height))
|
||||
{
|
||||
ok = token_to_size(input_file, height.pToken2(), &scene->params.height);
|
||||
ok = token_to_size(input_file, height.pToken2(), &scene->options.height);
|
||||
}
|
||||
else if (PWidth width = item.pWidth(); p_node_valid(width))
|
||||
{
|
||||
ok = token_to_size(input_file, width.pToken2(), &scene->params.width);
|
||||
ok = token_to_size(input_file, width.pToken2(), &scene->options.width);
|
||||
}
|
||||
if (!ok)
|
||||
{
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <fart/RenderParams.h>
|
||||
#include <fart/Options.h>
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
RenderParams params;
|
||||
Options options;
|
||||
};
|
||||
+1
-1
@@ -15,6 +15,6 @@ int main(int argc, char * argv[])
|
||||
fprintf(stderr, "Error: no input file specified\n");
|
||||
return 1;
|
||||
}
|
||||
Engine engine(cli.params);
|
||||
Engine engine(cli.options);
|
||||
return engine.run(cli.input_file, cli.output_file);
|
||||
}
|
||||
Reference in new issue
Block a user