Tile properties to bitfield

This commit is contained in:
GriffinR 2022-08-26 19:30:40 -04:00
parent fd4ba874d2
commit aad1266e91
3 changed files with 8 additions and 25 deletions

View file

@ -8,17 +8,15 @@ class Tile
{ {
public: public:
Tile(); Tile();
Tile(int tileId, bool xflip, bool yflip, int palette); Tile(uint16_t tileId, uint16_t xflip, uint16_t yflip, uint16_t palette);
Tile(uint16_t raw); Tile(uint16_t raw);
public: public:
int tileId; uint16_t tileId:10;
bool xflip; uint16_t xflip:1;
bool yflip; uint16_t yflip:1;
int palette; uint16_t palette:4;
uint16_t rawValue() const; uint16_t rawValue() const;
void sanitize();
static int getIndexInTileset(int); static int getIndexInTileset(int);
}; };

View file

@ -8,7 +8,7 @@
palette(0) palette(0)
{ } { }
Tile::Tile(int tileId, bool xflip, bool yflip, int palette) : Tile::Tile(uint16_t tileId, uint16_t xflip, uint16_t yflip, uint16_t palette) :
tileId(tileId), tileId(tileId),
xflip(xflip), xflip(xflip),
yflip(yflip), yflip(yflip),
@ -30,17 +30,6 @@ uint16_t Tile::rawValue() const {
| ((this->palette & 0xF) << 12)); | ((this->palette & 0xF) << 12));
} }
void Tile::sanitize() {
if (tileId < 0 || tileId >= Project::getNumTilesTotal()) {
logWarn(QString("Resetting tile's invalid tile id '%1' to 0.").arg(tileId));
tileId = 0;
}
if (palette < 0 || palette >= Project::getNumPalettesTotal()) {
logWarn(QString("Resetting tile's invalid palette id '%1' to 0.").arg(palette));
palette = 0;
}
}
int Tile::getIndexInTileset(int tileId) { int Tile::getIndexInTileset(int tileId) {
if (tileId < Project::getNumTilesPrimary()) { if (tileId < Project::getNumTilesPrimary()) {
return tileId; return tileId;

View file

@ -991,11 +991,8 @@ void MainWindow::setMetatileTiles(int metatileId, QJSValue tilesObj, int tileSta
// Write to metatile using as many of the given Tiles as possible // Write to metatile using as many of the given Tiles as possible
int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles); int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles);
int i = 0; int i = 0;
for (; i < numTileObjs; i++, tileStart++) { for (; i < numTileObjs; i++, tileStart++)
Tile tile = Scripting::toTile(tilesObj.property(i)); metatile->tiles[tileStart] = Scripting::toTile(tilesObj.property(i));
tile.sanitize();
metatile->tiles[tileStart] = tile;
}
// Fill remainder of specified length with empty Tiles // Fill remainder of specified length with empty Tiles
for (; i < numTiles; i++, tileStart++) for (; i < numTiles; i++, tileStart++)
@ -1014,7 +1011,6 @@ void MainWindow::setMetatileTiles(int metatileId, int tileId, bool xflip, bool y
// Write to metatile using Tiles of the specified value // Write to metatile using Tiles of the specified value
Tile tile = Tile(tileId, xflip, yflip, palette); Tile tile = Tile(tileId, xflip, yflip, palette);
tile.sanitize();
for (int i = tileStart; i <= tileEnd; i++) for (int i = tileStart; i <= tileEnd; i++)
metatile->tiles[i] = tile; metatile->tiles[i] = tile;