Overworld map saving epic
This commit is contained in:
@@ -109,10 +109,10 @@ struct SNESColor {
|
||||
bool transparent = false;
|
||||
};
|
||||
|
||||
gfx::SNESColor ReadColorFromROM(int offset, const uchar* rom);
|
||||
gfx::SNESColor ReadColorFromROM(int offset, const uint8_t* rom);
|
||||
|
||||
SNESColor GetCgxColor(uint16_t color);
|
||||
std::vector<SNESColor> GetColFileData(uchar* data);
|
||||
std::vector<SNESColor> GetColFileData(uint8_t* data);
|
||||
|
||||
class SNESPalette {
|
||||
public:
|
||||
@@ -202,7 +202,7 @@ class SNESPalette {
|
||||
std::vector<SNESColor> colors; /**< The colors in the palette. */
|
||||
};
|
||||
|
||||
SNESPalette ReadPaletteFromROM(int offset, int num_colors, const uchar* rom);
|
||||
SNESPalette ReadPaletteFromROM(int offset, int num_colors, const uint8_t* rom);
|
||||
uint32_t GetPaletteAddress(const std::string& group_name, size_t palette_index,
|
||||
size_t color_index);
|
||||
std::array<float, 4> ToFloatArray(const SNESColor& color);
|
||||
|
||||
@@ -28,13 +28,13 @@ tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||
bpp_pos[1] = offset + col * 2 + 1;
|
||||
char mask = 1 << (7 - row);
|
||||
tile.data[col * 8 + row] = (data[bpp_pos[0]] & mask) == mask;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[1]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[1]] & mask) == mask)
|
||||
<< 1;
|
||||
if (bpp == 3) {
|
||||
// When we have 3 bitplanes, the bytes for the third bitplane are after
|
||||
// the 16 bytes of the 2 bitplanes.
|
||||
bpp_pos[2] = offset + 16 + col;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[2]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask)
|
||||
<< 2;
|
||||
}
|
||||
if (bpp >= 4) {
|
||||
@@ -42,9 +42,9 @@ tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||
// two.
|
||||
bpp_pos[2] = offset + 16 + col * 2;
|
||||
bpp_pos[3] = offset + 16 + col * 2 + 1;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[2]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask)
|
||||
<< 2;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[3]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[3]] & mask) == mask)
|
||||
<< 3;
|
||||
}
|
||||
if (bpp == 8) {
|
||||
@@ -52,13 +52,13 @@ tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||
bpp_pos[5] = offset + 32 + col * 2 + 1;
|
||||
bpp_pos[6] = offset + 48 + col * 2;
|
||||
bpp_pos[7] = offset + 48 + col * 2 + 1;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[4]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[4]] & mask) == mask)
|
||||
<< 4;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[5]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[5]] & mask) == mask)
|
||||
<< 5;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[6]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[6]] & mask) == mask)
|
||||
<< 6;
|
||||
tile.data[col * 8 + row] |= (uchar)((data[bpp_pos[7]] & mask) == mask)
|
||||
tile.data[col * 8 + row] |= (uint8_t)((data[bpp_pos[7]] & mask) == mask)
|
||||
<< 7;
|
||||
}
|
||||
}
|
||||
@@ -68,68 +68,68 @@ tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||
|
||||
Bytes PackBppTile(const tile8& tile, const uint32_t bpp) {
|
||||
// Allocate memory for output data
|
||||
std::vector<uchar> output(bpp * 8, 0); // initialized with 0
|
||||
std::vector<uint8_t> output(bpp * 8, 0); // initialized with 0
|
||||
unsigned maxcolor = 2 << bpp;
|
||||
|
||||
// Iterate over all columns and rows of the tile
|
||||
for (unsigned int col = 0; col < 8; col++) {
|
||||
for (unsigned int row = 0; row < 8; row++) {
|
||||
uchar color = tile.data[col * 8 + row];
|
||||
uint8_t color = tile.data[col * 8 + row];
|
||||
if (color > maxcolor) {
|
||||
throw std::invalid_argument("Invalid color value.");
|
||||
}
|
||||
|
||||
// 1bpp format
|
||||
if (bpp == 1) output[col] += (uchar)((color & 1) << (7 - row));
|
||||
if (bpp == 1) output[col] += (uint8_t)((color & 1) << (7 - row));
|
||||
|
||||
// 2bpp format
|
||||
if (bpp >= 2) {
|
||||
output[col * 2] += (uchar)((color & 1) << (7 - row));
|
||||
output[col * 2 + 1] += (uchar)((uchar)((color & 2) == 2) << (7 - row));
|
||||
output[col * 2] += (uint8_t)((color & 1) << (7 - row));
|
||||
output[col * 2 + 1] += (uint8_t)((uint8_t)((color & 2) == 2) << (7 - row));
|
||||
}
|
||||
|
||||
// 3bpp format
|
||||
if (bpp == 3)
|
||||
output[16 + col] += (uchar)(((color & 4) == 4) << (7 - row));
|
||||
output[16 + col] += (uint8_t)(((color & 4) == 4) << (7 - row));
|
||||
|
||||
// 4bpp format
|
||||
if (bpp >= 4) {
|
||||
output[16 + col * 2] += (uchar)(((color & 4) == 4) << (7 - row));
|
||||
output[16 + col * 2 + 1] += (uchar)(((color & 8) == 8) << (7 - row));
|
||||
output[16 + col * 2] += (uint8_t)(((color & 4) == 4) << (7 - row));
|
||||
output[16 + col * 2 + 1] += (uint8_t)(((color & 8) == 8) << (7 - row));
|
||||
}
|
||||
|
||||
// 8bpp format
|
||||
if (bpp == 8) {
|
||||
output[32 + col * 2] += (uchar)(((color & 16) == 16) << (7 - row));
|
||||
output[32 + col * 2 + 1] += (uchar)(((color & 32) == 32) << (7 - row));
|
||||
output[48 + col * 2] += (uchar)(((color & 64) == 64) << (7 - row));
|
||||
output[32 + col * 2] += (uint8_t)(((color & 16) == 16) << (7 - row));
|
||||
output[32 + col * 2 + 1] += (uint8_t)(((color & 32) == 32) << (7 - row));
|
||||
output[48 + col * 2] += (uint8_t)(((color & 64) == 64) << (7 - row));
|
||||
output[48 + col * 2 + 1] +=
|
||||
(uchar)(((color & 128) == 128) << (7 - row));
|
||||
(uint8_t)(((color & 128) == 128) << (7 - row));
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<uchar> ConvertBpp(const std::vector<uchar>& tiles,
|
||||
std::vector<uint8_t> ConvertBpp(const std::vector<uint8_t>& tiles,
|
||||
uint32_t from_bpp, uint32_t to_bpp) {
|
||||
unsigned int nb_tile = tiles.size() / (from_bpp * 8);
|
||||
std::vector<uchar> converted(nb_tile * to_bpp * 8);
|
||||
std::vector<uint8_t> converted(nb_tile * to_bpp * 8);
|
||||
|
||||
for (unsigned int i = 0; i < nb_tile; i++) {
|
||||
tile8 tile = UnpackBppTile(tiles, i * from_bpp * 8, from_bpp);
|
||||
std::vector<uchar> packed_tile = PackBppTile(tile, to_bpp);
|
||||
std::vector<uint8_t> packed_tile = PackBppTile(tile, to_bpp);
|
||||
std::memcpy(converted.data() + i * to_bpp * 8, packed_tile.data(),
|
||||
to_bpp * 8);
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
std::vector<uchar> Convert3bppTo4bpp(const std::vector<uchar>& tiles) {
|
||||
std::vector<uint8_t> Convert3bppTo4bpp(const std::vector<uint8_t>& tiles) {
|
||||
return ConvertBpp(tiles, 3, 4);
|
||||
}
|
||||
|
||||
std::vector<uchar> Convert4bppTo3bpp(const std::vector<uchar>& tiles) {
|
||||
std::vector<uint8_t> Convert4bppTo3bpp(const std::vector<uint8_t>& tiles) {
|
||||
return ConvertBpp(tiles, 4, 3);
|
||||
}
|
||||
|
||||
@@ -313,8 +313,8 @@ TileInfo WordToTileInfo(uint16_t word) {
|
||||
return TileInfo(id, palette, vertical_mirror, horizontal_mirror, over);
|
||||
}
|
||||
|
||||
ushort TileInfoToShort(TileInfo tile_info) {
|
||||
// ushort result = 0;
|
||||
uint16_t TileInfoToShort(TileInfo tile_info) {
|
||||
// uint16_t result = 0;
|
||||
|
||||
// // Copy the id_ value
|
||||
// result |= tile_info.id_ & 0x3FF; // ids are 10 bits
|
||||
@@ -327,7 +327,7 @@ ushort TileInfoToShort(TileInfo tile_info) {
|
||||
// // Set the palette_
|
||||
// result |= (tile_info.palette_ & 0x07) << 13; // palettes are 3 bits
|
||||
|
||||
ushort value = 0;
|
||||
uint16_t value = 0;
|
||||
// vhopppcc cccccccc
|
||||
if (tile_info.over_) {
|
||||
value |= core::TilePriorityBit;
|
||||
@@ -338,23 +338,20 @@ ushort TileInfoToShort(TileInfo tile_info) {
|
||||
if (tile_info.vertical_mirror_) {
|
||||
value |= core::TileVFlipBit;
|
||||
}
|
||||
value |= (ushort)((tile_info.palette_ << 10) & 0x1C00);
|
||||
value |= (ushort)(tile_info.id_ & core::TileNameMask);
|
||||
value |= (uint16_t)((tile_info.palette_ << 10) & 0x1C00);
|
||||
value |= (uint16_t)(tile_info.id_ & core::TileNameMask);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
TileInfo GetTilesInfo(ushort tile) {
|
||||
TileInfo GetTilesInfo(uint16_t tile) {
|
||||
// vhopppcc cccccccc
|
||||
bool o = false;
|
||||
bool v = false;
|
||||
bool h = false;
|
||||
auto tid = (ushort)(tile & core::TileNameMask);
|
||||
auto p = (uchar)((tile >> 10) & 0x07);
|
||||
auto tid = (uint16_t)(tile & core::TileNameMask);
|
||||
auto p = (uint8_t)((tile >> 10) & 0x07);
|
||||
|
||||
o = ((tile & core::TilePriorityBit) == core::TilePriorityBit);
|
||||
h = ((tile & core::TileHFlipBit) == core::TileHFlipBit);
|
||||
v = ((tile & core::TileVFlipBit) == core::TileVFlipBit);
|
||||
bool o = ((tile & core::TilePriorityBit) == core::TilePriorityBit);
|
||||
bool h = ((tile & core::TileHFlipBit) == core::TileHFlipBit);
|
||||
bool v = ((tile & core::TileVFlipBit) == core::TileVFlipBit);
|
||||
|
||||
return TileInfo(tid, p, v, h, o);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace gfx {
|
||||
|
||||
constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
|
||||
constexpr uint8_t kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
|
||||
0x08, 0x04, 0x02, 0x01};
|
||||
|
||||
Bytes SnesTo8bppSheet(Bytes sheet, int bpp);
|
||||
@@ -29,24 +29,24 @@ tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||
|
||||
Bytes PackBppTile(const tile8& tile, const uint32_t bpp);
|
||||
|
||||
std::vector<uchar> ConvertBpp(const std::vector<uchar>& tiles,
|
||||
std::vector<uint8_t> ConvertBpp(const std::vector<uint8_t>& tiles,
|
||||
uint32_t from_bpp, uint32_t to_bpp);
|
||||
|
||||
std::vector<uchar> Convert3bppTo4bpp(const std::vector<uchar>& tiles);
|
||||
std::vector<uchar> Convert4bppTo3bpp(const std::vector<uchar>& tiles);
|
||||
std::vector<uint8_t> Convert3bppTo4bpp(const std::vector<uint8_t>& tiles);
|
||||
std::vector<uint8_t> Convert4bppTo3bpp(const std::vector<uint8_t>& tiles);
|
||||
|
||||
// vhopppcc cccccccc
|
||||
// [0, 1]
|
||||
// [2, 3]
|
||||
class TileInfo {
|
||||
public:
|
||||
ushort id_;
|
||||
uint16_t id_;
|
||||
uint8_t palette_;
|
||||
bool over_;
|
||||
bool vertical_mirror_;
|
||||
bool horizontal_mirror_;
|
||||
uchar palette_;
|
||||
TileInfo() = default;
|
||||
TileInfo(ushort id, uchar palette, bool v, bool h, bool o)
|
||||
TileInfo(uint16_t id, uint8_t palette, bool v, bool h, bool o)
|
||||
: id_(id),
|
||||
over_(o),
|
||||
vertical_mirror_(v),
|
||||
@@ -63,9 +63,9 @@ class TileInfo {
|
||||
|
||||
uint16_t TileInfoToWord(TileInfo tile_info);
|
||||
TileInfo WordToTileInfo(uint16_t word);
|
||||
ushort TileInfoToShort(TileInfo tile_info);
|
||||
uint16_t TileInfoToShort(TileInfo tile_info);
|
||||
|
||||
TileInfo GetTilesInfo(ushort tile);
|
||||
TileInfo GetTilesInfo(uint16_t tile);
|
||||
|
||||
class Tile32 {
|
||||
public:
|
||||
@@ -90,10 +90,10 @@ class Tile32 {
|
||||
|
||||
// Constructor from packed value
|
||||
Tile32(uint64_t packedVal) {
|
||||
tile0_ = (ushort)packedVal;
|
||||
tile1_ = (ushort)(packedVal >> 16);
|
||||
tile2_ = (ushort)(packedVal >> 32);
|
||||
tile3_ = (ushort)(packedVal >> 48);
|
||||
tile0_ = (uint16_t)packedVal;
|
||||
tile1_ = (uint16_t)(packedVal >> 16);
|
||||
tile2_ = (uint16_t)(packedVal >> 32);
|
||||
tile3_ = (uint16_t)(packedVal >> 48);
|
||||
}
|
||||
|
||||
// Get packed uint64_t representation
|
||||
@@ -145,15 +145,15 @@ class OAMTile {
|
||||
int mx_;
|
||||
int my_;
|
||||
int pal_;
|
||||
ushort tile_;
|
||||
uint16_t tile_;
|
||||
OAMTile() = default;
|
||||
OAMTile(int x, int y, ushort tile, int pal, bool upper = false, int mx = 0,
|
||||
OAMTile(int x, int y, uint16_t tile, int pal, bool upper = false, int mx = 0,
|
||||
int my = 0)
|
||||
: x_(x), y_(y), mx_(mx), my_(my), pal_(pal) {
|
||||
if (upper) {
|
||||
tile_ = (ushort)(tile + 512);
|
||||
tile_ = (uint16_t)(tile + 512);
|
||||
} else {
|
||||
tile_ = (ushort)(tile + 256 + 512);
|
||||
tile_ = (uint16_t)(tile + 256 + 512);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user