Skip to content

Commit

Permalink
Lots of work on primer assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Jan 11, 2024
1 parent 7b43e0d commit d3af999
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 192 deletions.
2 changes: 1 addition & 1 deletion include/cli_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const std::string FORCE_ASSIGN_PARAM_MATRIX = "force-assign-param-matrix";
const std::string FORCE_ASSIGN_PARAM_MATRIX_DESC =
" -" + FORCE_ASSIGN_PARAM_MATRIX + "\n"
" Force the full palette assignment parameter search matrix to run. If `assign.cfg'\n"
" in either source folder, its contents will be ignored.\n";
" exists in either source folder, its contents will be ignored.\n";
constexpr int FORCE_ASSIGN_PARAM_MATRIX_VAL = 3007;

// Fieldmap override options
Expand Down
1 change: 1 addition & 0 deletions include/errors_warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern const char *const WARN_MISSING_ASSIGN_CONFIG;
void internalerror(std::string message);
void internalerror_unknownCompilerMode(std::string context);
void internalerror_unknownDecompilerMode(std::string context);
void internalerror_unknownSubcommand(std::string context);

/*
* Regular compilation errors (due to bad user input), regular errors try to die as late as possible
Expand Down
25 changes: 24 additions & 1 deletion include/importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace porytiles {
*/
DecompiledTileset importTilesFromPng(PtContext &ctx, const png::image<png::rgba_pixel> &png);

/**
* TODO : fill in doc comments
*/
DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx,
const std::unordered_map<std::size_t, Attributes> &attributesMap,
const png::image<png::rgba_pixel> &bottom,
Expand All @@ -33,24 +36,44 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx,
void importAnimTiles(PtContext &ctx, const std::vector<std::vector<AnimationPng<png::rgba_pixel>>> &rawAnims,
DecompiledTileset &tiles);

/**
* TODO : fill in doc comments
*/
std::pair<std::unordered_map<std::string, std::uint8_t>, std::unordered_map<std::uint8_t, std::string>>
importMetatileBehaviorMaps(PtContext &ctx, std::ifstream &behaviorFile);
importMetatileBehaviorHeader(PtContext &ctx, std::ifstream &behaviorFile);

/**
* TODO : fill in doc comments
*/
std::unordered_map<std::size_t, Attributes>
importAttributesFromCsv(PtContext &ctx, const std::unordered_map<std::string, std::uint8_t> &behaviorMap,
const std::string &filePath);

/**
* TODO : fill in doc comments
*/
void importPrimaryAssignmentConfigParameters(PtContext &ctx, std::ifstream &config);

/**
* TODO : fill in doc comments
*/
void importSecondaryAssignmentConfigParameters(PtContext &ctx, std::ifstream &config);

/**
* TODO : fill in doc comments
*/
std::pair<CompiledTileset, std::unordered_map<std::size_t, Attributes>>
importCompiledTileset(PtContext &ctx, std::ifstream &metatiles, std::ifstream &attributes,
const std::unordered_map<std::uint8_t, std::string> &behaviorReverseMap,
const png::image<png::index_pixel> &tilesheetPng,
const std::vector<std::shared_ptr<std::ifstream>> &paletteFiles,
const std::vector<std::vector<AnimationPng<png::index_pixel>>> &compiledAnims);

/**
* TODO : fill in doc comments
*/
RGBATile importPalettePrimer(PtContext &ctx, std::ifstream &paletteFile);

} // namespace porytiles

#endif // PORYTILES_IMPORTER_H
13 changes: 10 additions & 3 deletions include/palette_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ struct AssignState {
// The count of unassigned palettes
std::size_t unassignedCount;

// The count of unassigned primer palettes
std::size_t unassignedPrimerCount;

auto operator==(const AssignState &other) const
{
return this->hardwarePalettes == other.hardwarePalettes && this->unassignedCount == other.unassignedCount;
return this->hardwarePalettes == other.hardwarePalettes && this->unassignedCount == other.unassignedCount &&
this->unassignedPrimerCount == other.unassignedPrimerCount;
}
};

Expand All @@ -46,11 +50,14 @@ template <> struct std::hash<porytiles::AssignState> {

namespace porytiles {
AssignResult assignDepthFirst(PtContext &ctx, AssignState &state, std::vector<ColorSet> &solution,
const std::vector<ColorSet> &primaryPalettes, const std::vector<ColorSet> &unassigneds);
const std::vector<ColorSet> &primaryPalettes, const std::vector<ColorSet> &unassigneds,
const std::vector<ColorSet> &unassignedPrimers);
AssignResult assignBreadthFirst(PtContext &ctx, AssignState &initialState, std::vector<ColorSet> &solution,
const std::vector<ColorSet> &primaryPalettes, const std::vector<ColorSet> &unassigneds);
const std::vector<ColorSet> &primaryPalettes, const std::vector<ColorSet> &unassigneds,
const std::vector<ColorSet> &unassignedPrimers);
std::pair<std::vector<ColorSet>, std::vector<ColorSet>>
runPaletteAssignmentMatrix(PtContext &ctx, const std::vector<ColorSet> &colorSets,
const std::vector<ColorSet> &primerColorSets,
const std::unordered_map<BGR15, std::size_t> &colorToIndex);
} // namespace porytiles

Expand Down
9 changes: 8 additions & 1 deletion include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ BGR15 rgbaToBgr(const RGBA32 &rgba) noexcept;

RGBA32 bgrToRgba(const BGR15 &bgr) noexcept;

enum class TileType { FREESTANDING, LAYERED, ANIM };
enum class TileType { FREESTANDING, LAYERED, ANIM, PRIMER };

std::string tileTypeString(TileType type);

Expand Down Expand Up @@ -193,6 +193,9 @@ struct RGBATile {
std::string anim;
std::string frame;

// PRIMER specific metadata
std::string primer;

// Metatile attributes for this tile
Attributes attributes;

Expand Down Expand Up @@ -542,6 +545,9 @@ struct NormalizedTile {
// ANIM specific metadata
std::string anim;

// PRIMER specific metadata
std::string primer;

// Metatile attributes for this tile
Attributes attributes;

Expand All @@ -560,6 +566,7 @@ struct NormalizedTile {
this->metatileIndex = tile.metatileIndex;
this->subtile = tile.subtile;
this->anim = tile.anim;
this->primer = tile.primer;
this->attributes = tile.attributes;
}

Expand Down
2 changes: 2 additions & 0 deletions include/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ std::filesystem::path getTmpfilePath(const std::filesystem::path &parentDir, con

std::filesystem::path createTmpdir();

RGBA32 parseJascLine(PtContext &ctx, const std::string &jascLine);

} // namespace porytiles

#endif // PORYTILES_UTILITIES_H
Loading

0 comments on commit d3af999

Please sign in to comment.