Skip to content

Commit

Permalink
Working on primitive support for dual-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Aug 10, 2023
1 parent 84ec393 commit be82fae
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
27 changes: 26 additions & 1 deletion include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ enum class Subtile { NORTHWEST = 0, NORTHEAST = 1, SOUTHWEST = 2, SOUTHEAST = 3

std::string subtileString(Subtile subtile);

// Normal = Middle/Top
// Covered = Bottom/Middle
// Split = Bottom/Top
enum class LayerType { NORMAL, COVERED, SPLIT };

std::string layerTypeString(LayerType layerType);

/**
* A tile of RGBA32 colors.
*/
Expand All @@ -145,6 +152,7 @@ struct RGBATile {
std::size_t tileIndex;

// LAYERED specific metadata
LayerType layerType;
TileLayer layer;
std::size_t metatileIndex;
Subtile subtile;
Expand Down Expand Up @@ -441,7 +449,24 @@ struct NormalizedTile {
bool hFlip;
bool vFlip;

// TODO : should contain some kind of owning reference back to source RGBATiles
/*
* Metadata Fields:
* These are used by the various components to track metadata around the usage context of a NormalizedTile. Allows
* Porytiles to give much more detailed error messages.
*/
TileType type;

// raw tile index, used for FREESTANDING and ANIM types
std::size_t tileIndex;

// LAYERED specific metadata
LayerType layerType;
TileLayer layer;
std::size_t metatileIndex;
Subtile subtile;

// ANIM specific metadata
std::string anim;

explicit NormalizedTile(RGBA32 transparency) : frames{}, palette{}, hFlip{}, vFlip{}
{
Expand Down
36 changes: 26 additions & 10 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ std::string tileTypeString(TileType type)
default:
internalerror("types::tileTypeString unknown TileType");
}
// unreachable, here to satisfy compiler
return "";
// unreachable, here for compiler
throw std::runtime_error("types::tileTypeString reached unreachable code path");
}

std::string layerString(TileLayer layer)
Expand All @@ -85,8 +85,8 @@ std::string layerString(TileLayer layer)
default:
internalerror("types::layerString unknown TileLayer");
}
// unreachable, here to satisfy compiler
return "";
// unreachable, here for compiler
throw std::runtime_error("types::layerString reached unreachable code path");
}

std::string subtileString(Subtile subtile)
Expand All @@ -103,8 +103,24 @@ std::string subtileString(Subtile subtile)
default:
internalerror("types::subtileString unknown Subtile");
}
// unreachable, here to satisfy compiler
return "";
// unreachable, here for compiler
throw std::runtime_error("types::subtileString reached unreachable code path");
}

std::string layerTypeString(LayerType layerType)
{
switch (layerType) {
case LayerType::NORMAL:
return "normal";
case LayerType::COVERED:
return "covered";
case LayerType::SPLIT:
return "split";
default:
internalerror("types::layerTypeString unknown LayerType");
}
// unreachable, here for compiler
throw std::runtime_error("types::layerTypeString reached unreachable code path");
}

std::ostream &operator<<(std::ostream &os, const BGR15 &bgr)
Expand Down Expand Up @@ -198,8 +214,8 @@ std::filesystem::path InputPaths::modeBasedInputPath(CompilerMode mode) const
default:
internalerror_unknownCompilerMode("types::InputPaths::modeBasedInputPath");
}
// unreachable, here to satisfy compiler
return "";
// unreachable, here for compiler
throw std::runtime_error("types::modeBasedInputPath reached unreachable code path");
}

std::string compilerModeString(CompilerMode mode)
Expand All @@ -212,8 +228,8 @@ std::string compilerModeString(CompilerMode mode)
default:
internalerror_unknownCompilerMode("types::compilerModeString");
}
// unreachable, here to satisfy compiler
return "";
// unreachable, here for compiler
throw std::runtime_error("types::compilerModeString reached unreachable code path");
}

} // namespace porytiles
Expand Down

0 comments on commit be82fae

Please sign in to comment.