Fix Tile32 unsigned long value cast constructor

This commit is contained in:
scawful
2024-01-29 16:11:07 -05:00
parent 319665621c
commit 0a388e60b4
5 changed files with 81 additions and 69 deletions

View File

@@ -314,20 +314,34 @@ TileInfo WordToTileInfo(uint16_t word) {
}
ushort TileInfoToShort(TileInfo tile_info) {
ushort result = 0;
// ushort result = 0;
// Copy the id_ value
result |= tile_info.id_ & 0x3FF; // ids are 10 bits
// // Copy the id_ value
// result |= tile_info.id_ & 0x3FF; // ids are 10 bits
// Set the vertical_mirror_, horizontal_mirror_, and over_ flags
result |= (tile_info.vertical_mirror_ ? 1 : 0) << 10;
result |= (tile_info.horizontal_mirror_ ? 1 : 0) << 11;
result |= (tile_info.over_ ? 1 : 0) << 12;
// // Set the vertical_mirror_, horizontal_mirror_, and over_ flags
// result |= (tile_info.vertical_mirror_ ? 1 : 0) << 10;
// result |= (tile_info.horizontal_mirror_ ? 1 : 0) << 11;
// result |= (tile_info.over_ ? 1 : 0) << 12;
// Set the palette_
result |= (tile_info.palette_ & 0x07) << 13; // palettes are 3 bits
// // Set the palette_
// result |= (tile_info.palette_ & 0x07) << 13; // palettes are 3 bits
return result;
ushort value = 0;
// vhopppcc cccccccc
if (tile_info.over_) {
value |= core::TilePriorityBit;
}
if (tile_info.horizontal_mirror_) {
value |= core::TileHFlipBit;
}
if (tile_info.vertical_mirror_) {
value |= core::TileVFlipBit;
}
value |= (ushort)((tile_info.palette_ << 10) & 0x1C00);
value |= (ushort)(tile_info.id_ & core::TileNameMask);
return value;
}
TileInfo GetTilesInfo(ushort tile) {

View File

@@ -90,10 +90,17 @@ class Tile32 {
// Constructor from packed value
Tile32(uint64_t packedVal) {
tile0_ = (packedVal >> 48) & 0xFFFF;
tile1_ = (packedVal >> 32) & 0xFFFF;
tile2_ = (packedVal >> 16) & 0xFFFF;
tile3_ = packedVal & 0xFFFF;
tile0_ = (ushort)packedVal;
tile1_ = (ushort)(packedVal >> 16);
tile2_ = (ushort)(packedVal >> 32);
tile3_ = (ushort)(packedVal >> 48);
}
// Get packed uint64_t representation
uint64_t GetPackedValue() const {
return static_cast<uint64_t>(tile3_) << 48 |
(static_cast<uint64_t>(tile2_) << 32) |
(static_cast<uint64_t>(tile1_) << 16) | tile0_;
}
// Equality operator
@@ -104,13 +111,6 @@ class Tile32 {
// Inequality operator
bool operator!=(const Tile32& other) const { return !(*this == other); }
// Get packed uint64_t representation
uint64_t GetPackedValue() const {
return static_cast<uint64_t>(tile3_) << 48 |
(static_cast<uint64_t>(tile2_) << 32) |
(static_cast<uint64_t>(tile1_) << 16) | tile0_;
}
};
class Tile16 {