Skip to content

Commit

Permalink
Added pal assign cutoff option
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Aug 29, 2023
1 parent 5538635 commit 28ade10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 0 additions & 1 deletion Todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

+ Options changes
+ `-manage-metatiles-with-porymap` skips generation of `metatiles.bin` and `metatile_attributes.bin`
+ `-palette-assign-cutoff-threshold` (or another suitable name) to change the call limit for the palette assign algo

+ Set up more CI builds
+ Windows MSVC? MinGW?
Expand Down
12 changes: 10 additions & 2 deletions include/cli_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ constexpr int DUAL_LAYER_VAL = 2001;
const std::string TRANSPARENCY_COLOR = "transparency-color";
const std::string TRANSPARENCY_COLOR_DESC =
" -" + TRANSPARENCY_COLOR + "=<R,G,B>\n"
" Select RGB color <R,G,B> to represent transparency in your layer source PNGs. Defaults\n"
" to <255,0,255>.\n";
" Select RGB color <R,G,B> to represent transparency in your layer source PNGs.\n"
" Defaults to <255,0,255>.\n";
constexpr int TRANSPARENCY_COLOR_VAL = 2002;

const std::string PAL_ASSIGN_CUTOFF_FACTOR = "palette-assign-cutoff-factor";
const std::string PAL_ASSIGN_CUTOFF_FACTOR_DESC =
" -" + PAL_ASSIGN_CUTOFF_FACTOR + "=<FACTOR>\n"
" Select the cutoff FACTOR for palette assignment. Defaults to 2, which should be\n"
" sufficient for most cases. Increase the number to let the algorithm run for longer\n"
" before failing out.\n";
constexpr int PAL_ASSIGN_CUTOFF_FACTOR_VAL = 2003;


// Fieldmap override options

Expand Down
12 changes: 12 additions & 0 deletions src/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,17 @@ const std::string COMPILE_HELP =
" ... # you may specify an arbitrary number of additional animations\n"
"\n"
"OPTIONS\n" +
" For more detailed information about the options below, check out the options pages here:\n" +
" https://github.com/grunt-lucas/porytiles/wiki#advanced-usage\n" +
"\n" +
" Driver Options\n" +
OUTPUT_DESC + "\n" +
TILES_OUTPUT_PAL_DESC + "\n" +
" Tileset Generation Options\n" +
TARGET_BASE_GAME_DESC + "\n" +
DUAL_LAYER_DESC + "\n" +
TRANSPARENCY_COLOR_DESC + "\n" +
PAL_ASSIGN_CUTOFF_FACTOR_DESC + "\n" +
" Fieldmap Override Options\n" +
TILES_PRIMARY_OVERRIDE_DESC + "\n" +
TILES_TOTAL_OVERRIDE_DESC + "\n" +
Expand Down Expand Up @@ -350,6 +354,7 @@ static void parseCompile(PtContext &ctx, int argc, char *const *argv)
{TARGET_BASE_GAME.c_str(), required_argument, nullptr, TARGET_BASE_GAME_VAL},
{DUAL_LAYER.c_str(), no_argument, nullptr, DUAL_LAYER_VAL},
{TRANSPARENCY_COLOR.c_str(), required_argument, nullptr, TRANSPARENCY_COLOR_VAL},
{PAL_ASSIGN_CUTOFF_FACTOR.c_str(), required_argument, nullptr, PAL_ASSIGN_CUTOFF_FACTOR_VAL},

// Fieldmap override options
{TILES_PRIMARY_OVERRIDE.c_str(), required_argument, nullptr, TILES_PRIMARY_OVERRIDE_VAL},
Expand Down Expand Up @@ -436,6 +441,8 @@ static void parseCompile(PtContext &ctx, int argc, char *const *argv)
bool palettesTotalOverridden = false;
std::size_t palettesTotalOverride = 0;

std::size_t cutoffFactor;

while (true) {
const auto opt = getopt_long_only(argc, argv, shortOptions.c_str(), longOptions, nullptr);

Expand All @@ -462,6 +469,11 @@ static void parseCompile(PtContext &ctx, int argc, char *const *argv)
case TRANSPARENCY_COLOR_VAL:
ctx.compilerConfig.transparencyColor = parseRgbColor(ctx.err, TRANSPARENCY_COLOR, optarg);
break;
case PAL_ASSIGN_CUTOFF_FACTOR_VAL:
cutoffFactor = parseIntegralOption<std::size_t>(ctx.err, PAL_ASSIGN_CUTOFF_FACTOR, optarg);
// TODO : throw if this factor is too large
ctx.compilerConfig.paletteAssignCutoffThreshold = cutoffFactor * 1'000'000;
break;

// Fieldmap override options
case TILES_PRIMARY_OVERRIDE_VAL:
Expand Down
4 changes: 1 addition & 3 deletions src/errors_warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ void fatalerror_tooManyAssignmentRecurses(const ErrorsAndWarnings &err, const So
std::size_t maxRecurses)
{
if (err.printErrors) {
pt_fatal_err("palette assignment exceeded maximum depth '{}'", fmt::styled(maxRecurses, fmt::emphasis::bold));
// TODO : impl this CLI option
pt_note("you can increase this depth with the '-max-assign-depth' option");
pt_fatal_err("palette assignment exceeded maximum cutoff threshold '{}'", fmt::styled(maxRecurses, fmt::emphasis::bold));
}
die_compilationTerminated(err, srcs.modeBasedSrcPath(mode), "too many assignment recurses");
}
Expand Down

0 comments on commit 28ade10

Please sign in to comment.