Skip to content

Commit

Permalink
Enforce max value for assign-explore-cutoff option
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Oct 11, 2023
1 parent 586ed91 commit b36be75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/palette_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace porytiles {

constexpr std::size_t EXPLORATION_CUTOFF_MULTIPLIER = 1'000'000;
constexpr std::size_t EXPLORATION_MAX_CUTOFF = 100 * EXPLORATION_CUTOFF_MULTIPLIER;

struct AssignState {
/*
Expand Down
14 changes: 12 additions & 2 deletions src/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,19 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv)
// Color assignment config options
case ASSIGN_EXPLORE_CUTOFF_VAL:
cutoffFactor = parseIntegralOption<std::size_t>(ctx.err, ASSIGN_EXPLORE_CUTOFF, optarg);
// FIXME : error if this factor is too large
if (ctx.subcommand == Subcommand::COMPILE_PRIMARY) {
ctx.compilerConfig.primaryExploredNodeCutoff = cutoffFactor * EXPLORATION_CUTOFF_MULTIPLIER;
if (ctx.compilerConfig.primaryExploredNodeCutoff > EXPLORATION_MAX_CUTOFF) {
fatalerror(ctx.err, fmt::format("option '{}' argument cannot be > 100",
fmt::styled(ASSIGN_EXPLORE_CUTOFF, fmt::emphasis::bold)));
}
}
else if (ctx.subcommand == Subcommand::COMPILE_SECONDARY) {
ctx.compilerConfig.secondaryExploredNodeCutoff = cutoffFactor * EXPLORATION_CUTOFF_MULTIPLIER;
if (ctx.compilerConfig.secondaryExploredNodeCutoff > EXPLORATION_MAX_CUTOFF) {
fatalerror(ctx.err, fmt::format("option '{}' argument cannot be > 100",
fmt::styled(ASSIGN_EXPLORE_CUTOFF, fmt::emphasis::bold)));
}
}
break;
case ASSIGN_ALGO_VAL:
Expand Down Expand Up @@ -562,9 +569,12 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv)
break;
case PRIMARY_ASSIGN_EXPLORE_CUTOFF_VAL:
cutoffFactor = parseIntegralOption<std::size_t>(ctx.err, PRIMARY_ASSIGN_EXPLORE_CUTOFF, optarg);
// FIXME : error if this factor is too large
if (ctx.subcommand == Subcommand::COMPILE_SECONDARY) {
ctx.compilerConfig.primaryExploredNodeCutoff = cutoffFactor * EXPLORATION_CUTOFF_MULTIPLIER;
if (ctx.compilerConfig.primaryExploredNodeCutoff > EXPLORATION_MAX_CUTOFF) {
fatalerror(ctx.err, fmt::format("option '{}' argument cannot be > 100",
fmt::styled(PRIMARY_ASSIGN_EXPLORE_CUTOFF, fmt::emphasis::bold)));
}
}
break;
case PRIMARY_ASSIGN_ALGO_VAL:
Expand Down

0 comments on commit b36be75

Please sign in to comment.