Skip to content

Commit

Permalink
Better compiler error message for tooManyTiles
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Aug 8, 2023
1 parent e6c052a commit 36540ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions include/errors_warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void fatalerror_tooManyUniqueColorsTotal(ErrorsAndWarnings &err, const InputPath
void fatalerror_animFrameDimensionsDoNotMatchOtherFrames(ErrorsAndWarnings &err, const InputPaths &inputs,
CompilerMode mode, std::string animName, std::string frame,
std::string dimensionName, png::uint_32 dimension);
void fatalerror_tooManyUniqueTiles(ErrorsAndWarnings &err, const InputPaths &inputs, CompilerMode mode,
std::size_t numTiles, std::size_t maxAllowedTiles);

// Compilation warnings
void warn_colorPrecisionLoss(ErrorsAndWarnings &err);
Expand Down
38 changes: 15 additions & 23 deletions src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ static NormalizedTile candidate(PtContext &ctx, const RGBA32 &transparencyColor,
for (std::size_t col = 0; col < TILE_SIDE_LENGTH; col++) {
std::size_t rowWithFlip = vFlip ? TILE_SIDE_LENGTH - 1 - row : row;
std::size_t colWithFlip = hFlip ? TILE_SIDE_LENGTH - 1 - col : col;
candidateTile.setPixel(frame, row, col,
insertRGBA(ctx, rgba, transparencyColor, candidateTile.palette,
rgba.getPixel(rowWithFlip, colWithFlip), row, col, errWarn));
std::size_t pixelValue = insertRGBA(ctx, rgba, transparencyColor, candidateTile.palette,
rgba.getPixel(rowWithFlip, colWithFlip), row, col, errWarn);
candidateTile.setPixel(frame, row, col, pixelValue);
}
}
frame++;
Expand Down Expand Up @@ -476,11 +476,6 @@ static void assignTilesPrimary(PtContext &ctx, CompiledTileset &compiled,
(tileIndexes.contains(representativeFrameTile) && tileIndexes.at(representativeFrameTile) == 0)) {
// Insert this tile's representative frame into the tiles.png
compiled.tiles.push_back(representativeFrameTile);
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInPrimary) {
// TODO : better error context
throw PtException{"too many tiles: " + std::to_string(compiled.tiles.size()) + " > " +
std::to_string(ctx.fieldmapConfig.numTilesInPrimary)};
}
compiled.paletteIndexesOfTile.push_back(paletteIndex);
// Fill out the anim structure
compiled.anims.at(index.animIndex)
Expand Down Expand Up @@ -529,18 +524,19 @@ static void assignTilesPrimary(PtContext &ctx, CompiledTileset &compiled,
auto inserted = tileIndexes.insert({gbaTile, compiled.tiles.size()});
if (inserted.second) {
compiled.tiles.push_back(gbaTile);
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInPrimary) {
// TODO : better error context
throw PtException{"too many tiles: " + std::to_string(compiled.tiles.size()) + " > " +
std::to_string(ctx.fieldmapConfig.numTilesInPrimary)};
}
compiled.paletteIndexesOfTile.push_back(paletteIndex);
}
std::size_t tileIndex = inserted.first->second;
compiled.assignments.at(index.tileIndex) = {tileIndex, paletteIndex, normTile.hFlip, normTile.vFlip};
}
compiled.tileIndexes = tileIndexes;

// error out if there were too many unique tiles
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInPrimary) {
fatalerror_tooManyUniqueTiles(ctx.err, ctx.inputPaths, ctx.compilerConfig.mode, compiled.tiles.size(),
ctx.fieldmapConfig.numTilesInPrimary);
}

// TODO : warn user if there are any representative tiles that did not appear in the assignments
}

Expand Down Expand Up @@ -607,11 +603,6 @@ static void assignTilesSecondary(PtContext &ctx, CompiledTileset &compiled,
ctx.compilerContext.pairedPrimaryTiles->tileIndexes.at(representativeFrameTile) == 0)) {
// Insert this tile's representative frame into the tiles.png
compiled.tiles.push_back(representativeFrameTile);
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInSecondary()) {
// TODO : better error context
throw PtException{"too many tiles: " + std::to_string(compiled.tiles.size()) + " > " +
std::to_string(ctx.fieldmapConfig.numTilesInSecondary())};
}
compiled.paletteIndexesOfTile.push_back(paletteIndex);
// Fill out the anim structure
compiled.anims.at(index.animIndex)
Expand Down Expand Up @@ -659,11 +650,6 @@ static void assignTilesSecondary(PtContext &ctx, CompiledTileset &compiled,
auto inserted = tileIndexes.insert({gbaTile, compiled.tiles.size()});
if (inserted.second) {
compiled.tiles.push_back(gbaTile);
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInSecondary()) {
// TODO : better error context
throw PtException{"too many tiles: " + std::to_string(compiled.tiles.size()) + " > " +
std::to_string(ctx.fieldmapConfig.numTilesInSecondary())};
}
compiled.paletteIndexesOfTile.push_back(paletteIndex);
}
std::size_t tileIndex = inserted.first->second;
Expand All @@ -674,6 +660,12 @@ static void assignTilesSecondary(PtContext &ctx, CompiledTileset &compiled,
}
compiled.tileIndexes = tileIndexes;

// error out if there were too many unique tiles
if (compiled.tiles.size() > ctx.fieldmapConfig.numTilesInSecondary()) {
fatalerror_tooManyUniqueTiles(ctx.err, ctx.inputPaths, ctx.compilerConfig.mode, compiled.tiles.size(),
ctx.fieldmapConfig.numTilesInSecondary());
}

// TODO : warn user if there are any representative tiles that did not appear in the assignments
}

Expand Down
11 changes: 11 additions & 0 deletions src/errors_warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ void fatalerror_animFrameDimensionsDoNotMatchOtherFrames(ErrorsAndWarnings &err,
fmt::format("anim {} frame {} dimension {} mismatch", animName, frame, dimensionName));
}

void fatalerror_tooManyUniqueTiles(ErrorsAndWarnings &err, const InputPaths &inputs, CompilerMode mode,
std::size_t numTiles, std::size_t maxAllowedTiles)
{
if (err.printErrors) {
pt_fatal_err("unique tile count '{}' exceeded limit of '{}'", fmt::styled(numTiles, fmt::emphasis::bold),
fmt::styled(maxAllowedTiles, fmt::emphasis::bold));
}
die_compilationTerminated(err, inputs.modeBasedInputPath(mode),
fmt::format("too many unique tiles in {} tileset", compilerModeString(mode)));
}

void warn_colorPrecisionLoss(ErrorsAndWarnings &err)
{
// TODO : better message
Expand Down

0 comments on commit 36540ac

Please sign in to comment.