worked on adding tile16 for overworld support

This commit is contained in:
Justin Scofield
2022-06-20 19:21:41 -04:00
parent f11e8f2aac
commit 367fe3552f
10 changed files with 276 additions and 232 deletions

View File

@@ -23,176 +23,26 @@ Bitmap::Bitmap(int width, int height, int depth, char *data)
surface_->pixels = data; surface_->pixels = data;
} }
SDL_Texture *Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) { void Bitmap::Create(int width, int height, int depth, uchar *data) {
width_ = width;
height_ = height;
depth_ = depth;
pixel_data_ = (char *)data;
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
SDL_PIXELFORMAT_INDEX8);
// Default grayscale palette
for (int i = 0; i < 8; i++) {
surface_->format->palette->colors[i].r = i * 31;
surface_->format->palette->colors[i].g = i * 31;
surface_->format->palette->colors[i].b = i * 31;
}
surface_->pixels = pixel_data_;
}
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_); texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_);
} }
int GetPCGfxAddress(char *romData, char id) {
char **info1 = new char *[255];
int gfxPointer1 =
lorom_snes_to_pc((romData[core::constants::gfx_1_pointer + 1] << 8) +
(romData[core::constants::gfx_1_pointer]),
info1);
int gfxPointer2 =
lorom_snes_to_pc((romData[core::constants::gfx_2_pointer + 1] << 8) +
(romData[core::constants::gfx_2_pointer]),
info1);
int gfxPointer3 =
lorom_snes_to_pc((romData[core::constants::gfx_3_pointer + 1] << 8) +
(romData[core::constants::gfx_3_pointer]),
info1);
char gfxGamePointer1 = romData[gfxPointer1 + id];
char gfxGamePointer2 = romData[gfxPointer2 + id];
char gfxGamePointer3 = romData[gfxPointer3 + id];
return lorom_snes_to_pc(
yaze::app::rom::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
gfxGamePointer3),
info1);
}
char *CreateAllGfxDataRaw(char *romData) {
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
char *buffer = new char[346624];
int bufferPos = 0;
char *data = new char[2048];
unsigned int uncompressedSize = 0;
unsigned int compressedSize = 0;
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
(i >= 127 && i <= 217) // Compressed 3bpp sprites
);
// uncompressed sheets
if (i >= 115 && i <= 126) {
data = new char[core::constants::Uncompressed3BPPSize];
int startAddress = GetPCGfxAddress(romData, (char)i);
for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) {
data[j] = romData[j + startAddress];
}
} else {
data = alttp_decompress_gfx((char *)romData,
GetPCGfxAddress(romData, (char)i),
core::constants::UncompressedSheetSize,
&uncompressedSize, &compressedSize);
}
for (int j = 0; j < sizeof(data); j++) {
buffer[j + bufferPos] = data[j];
}
bufferPos += sizeof(data);
}
return buffer;
}
void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
char *data = CreateAllGfxDataRaw(romData);
char *newData = new char[0x6F800];
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
int sheetPosition = 0;
// 8x8 tile
for (int s = 0; s < core::constants::NumberOfSheets; s++) // Per Sheet
{
for (int j = 0; j < 4; j++) // Per Tile Line Y
{
for (int i = 0; i < 16; i++) // Per Tile Line X
{
for (int y = 0; y < 8; y++) // Per Pixel Line
{
if (isbpp3[s]) {
char lineBits0 =
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
char lineBits1 =
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
char lineBits2 =
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X
{
char pixdata = 0;
char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1;
}
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 2;
}
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 4;
}
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 1;
}
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 2;
}
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 4;
}
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(char)((pixdata << 4) | pixdata2);
}
} else {
char lineBits0 =
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
char lineBits1 =
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X
{
char pixdata = 0;
char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1;
}
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 2;
}
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 1;
}
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 2;
}
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(char)((pixdata << 4) | pixdata2);
}
}
}
}
}
if (isbpp3[s]) {
sheetPosition += core::constants::Uncompressed3BPPSize;
} else {
sheetPosition += core::constants::UncompressedSheetSize;
}
}
char *allgfx16Data = (char *)allgfx16Ptr;
for (int i = 0; i < 0x6F800; i++) {
allgfx16Data[i] = newData[i];
}
}
} // namespace gfx } // namespace gfx
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -16,9 +16,11 @@ class Bitmap {
Bitmap() = default; Bitmap() = default;
Bitmap(int width, int height, int depth, char *data); Bitmap(int width, int height, int depth, char *data);
void Create(int width, int height, int depth, uchar *data);
int GetWidth() const { return width_; } int GetWidth() const { return width_; }
int GetHeight() const { return height_; } int GetHeight() const { return height_; }
SDL_Texture *CreateTexture(std::shared_ptr<SDL_Renderer> renderer); void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
inline SDL_Texture *GetTexture() const { return texture_; }
private: private:
int width_; int width_;
@@ -29,12 +31,6 @@ class Bitmap {
SDL_Texture *texture_; SDL_Texture *texture_;
}; };
static bool isbpp3[core::constants::NumberOfSheets];
int GetPCGfxAddress(char *romData, char id);
char *CreateAllGfxDataRaw(char *romData);
void CreateAllGfxData(char *romData, char *allgfx16Ptr);
} // namespace gfx } // namespace gfx
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

@@ -17,7 +17,6 @@
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
namespace gfx { namespace gfx {
@@ -57,10 +56,6 @@ class Tile32 {
: tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {} : tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {}
}; };
void BuildTiles16Gfx();
void CopyTile16(int x, int y, int xx, int yy, int offset, TileInfo tile,
uchar* gfx16Pointer, uchar* gfx8Pointer);
class Tile16 { class Tile16 {
public: public:
TileInfo tile0_; TileInfo tile0_;
@@ -78,6 +73,16 @@ class Tile16 {
} }
}; };
static bool isbpp3[core::constants::NumberOfSheets];
int GetPCGfxAddress(char* romData, char id);
char* CreateAllGfxDataRaw(char* romData);
void CreateAllGfxData(char* romData, char* allgfx16Ptr);
void BuildTiles16Gfx(uchar* mapblockset16, uchar* currentOWgfx16Ptr,
std::vector<Tile16>& allTiles);
void CopyTile16(int x, int y, int xx, int yy, int offset, TileInfo tile,
uchar* gfx16Pointer, uchar* gfx8Pointer);
class TilePreset { class TilePreset {
public: public:
TilePreset() = default; TilePreset() = default;

View File

@@ -8,11 +8,176 @@ namespace yaze {
namespace app { namespace app {
namespace gfx { namespace gfx {
void BuildTiles16Gfx(std::shared_ptr<uchar> mapblockset16, int GetPCGfxAddress(char *romData, char id) {
std::shared_ptr<uchar> currentOWgfx16Ptr, char **info1 = new char *[255];
int gfxPointer1 =
lorom_snes_to_pc((romData[core::constants::gfx_1_pointer + 1] << 8) +
(romData[core::constants::gfx_1_pointer]),
info1);
int gfxPointer2 =
lorom_snes_to_pc((romData[core::constants::gfx_2_pointer + 1] << 8) +
(romData[core::constants::gfx_2_pointer]),
info1);
int gfxPointer3 =
lorom_snes_to_pc((romData[core::constants::gfx_3_pointer + 1] << 8) +
(romData[core::constants::gfx_3_pointer]),
info1);
char gfxGamePointer1 = romData[gfxPointer1 + id];
char gfxGamePointer2 = romData[gfxPointer2 + id];
char gfxGamePointer3 = romData[gfxPointer3 + id];
return lorom_snes_to_pc(
yaze::app::rom::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
gfxGamePointer3),
info1);
}
char *CreateAllGfxDataRaw(char *romData) {
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
char *buffer = new char[346624];
int bufferPos = 0;
char *data = new char[2048];
unsigned int uncompressedSize = 0;
unsigned int compressedSize = 0;
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
(i >= 127 && i <= 217) // Compressed 3bpp sprites
);
// uncompressed sheets
if (i >= 115 && i <= 126) {
data = new char[core::constants::Uncompressed3BPPSize];
int startAddress = GetPCGfxAddress(romData, (char)i);
for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) {
data[j] = romData[j + startAddress];
}
} else {
data = alttp_decompress_gfx((char *)romData,
GetPCGfxAddress(romData, (char)i),
core::constants::UncompressedSheetSize,
&uncompressedSize, &compressedSize);
}
for (int j = 0; j < sizeof(data); j++) {
buffer[j + bufferPos] = data[j];
}
bufferPos += sizeof(data);
}
return buffer;
}
void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
char *data = CreateAllGfxDataRaw(romData);
char *newData = new char[0x6F800];
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
int sheetPosition = 0;
// 8x8 tile
for (int s = 0; s < core::constants::NumberOfSheets; s++) // Per Sheet
{
for (int j = 0; j < 4; j++) // Per Tile Line Y
{
for (int i = 0; i < 16; i++) // Per Tile Line X
{
for (int y = 0; y < 8; y++) // Per Pixel Line
{
if (isbpp3[s]) {
char lineBits0 =
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
char lineBits1 =
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
char lineBits2 =
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X
{
char pixdata = 0;
char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1;
}
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 2;
}
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 4;
}
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 1;
}
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 2;
}
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 4;
}
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(char)((pixdata << 4) | pixdata2);
}
} else {
char lineBits0 =
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
char lineBits1 =
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X
{
char pixdata = 0;
char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1;
}
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 2;
}
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 1;
}
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
pixdata2 += 2;
}
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(char)((pixdata << 4) | pixdata2);
}
}
}
}
}
if (isbpp3[s]) {
sheetPosition += core::constants::Uncompressed3BPPSize;
} else {
sheetPosition += core::constants::UncompressedSheetSize;
}
}
char *allgfx16Data = (char *)allgfx16Ptr;
for (int i = 0; i < 0x6F800; i++) {
allgfx16Data[i] = newData[i];
}
}
void BuildTiles16Gfx(uchar* mapblockset16, uchar* currentOWgfx16Ptr,
std::vector<Tile16>& allTiles) { std::vector<Tile16>& allTiles) {
auto gfx16Data = mapblockset16.get(); uchar* gfx16Data = mapblockset16;
auto gfx8Data = currentOWgfx16Ptr.get(); uchar* gfx8Data = currentOWgfx16Ptr;
const int offsets[4] = {0, 8, 1024, 1032}; const int offsets[4] = {0, 8, 1024, 1032};
auto yy = 0; auto yy = 0;
auto xx = 0; auto xx = 0;
@@ -59,7 +224,7 @@ void CopyTile16(int x, int y, int xx, int yy, int offset, TileInfo tile,
int tx = ((tile.id_ / 16) * 512) + ((tile.id_ - ((tile.id_ / 16) * 16)) * 4); int tx = ((tile.id_ / 16) * 512) + ((tile.id_ - ((tile.id_ / 16) * 16)) * 4);
auto index = xx + yy + offset + (mx * 2) + (my * 128); auto index = xx + yy + offset + (mx * 2) + (my * 128);
auto pixel = gfx8Pointer[tx + (y * 64) + x]; uchar pixel = gfx8Pointer[tx + (y * 64) + x];
gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16); gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);

View File

@@ -53,18 +53,19 @@ void Overworld::Load(app::rom::ROM& rom) {
AssembleMap16Tiles(); AssembleMap16Tiles();
DecompressAllMapTiles(); DecompressAllMapTiles();
// Map Initialization : // Map Initialization
// for (int i = 0; i < 160; i++) { for (int i = 0; i < 160; i++) {
// allmaps.push_back(OverworldMap(rom_, tiles16, (uchar)i)); overworld_maps_.push_back(OverworldMap(rom_, tiles16, (uchar)i));
// } }
// FetchLargeMaps(); FetchLargeMaps();
// LoadOverworldMap(); LoadOverworldMap();
// auto size = tiles16.size(); auto size = tiles16.size();
// for (int i = 0; i < 160; i++) { for (int i = 0; i < 160; i++) {
// allmaps[i].BuildMap(mapParent, size, gameState, allmapsTilesLW, overworld_maps_[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
// allmapsTilesDW, allmapsTilesSP); allmapsTilesDW, allmapsTilesSP,
// } currentOWgfx16Ptr);
}
isLoaded = true; isLoaded = true;
} }
@@ -250,7 +251,7 @@ void Overworld::FetchLargeMaps() {
mapParent[137] = 129; mapParent[137] = 129;
mapParent[138] = 129; mapParent[138] = 129;
mapParent[136] = 136; mapParent[136] = 136;
allmaps[136].largeMap = false; overworld_maps_[136].largeMap = false;
bool mapChecked[64]; bool mapChecked[64];
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
@@ -261,7 +262,7 @@ void Overworld::FetchLargeMaps() {
while (true) { while (true) {
int i = xx + (yy * 8); int i = xx + (yy * 8);
if (mapChecked[i] == false) { if (mapChecked[i] == false) {
if (allmaps[i].largeMap == true) { if (overworld_maps_[i].largeMap == true) {
mapChecked[i] = true; mapChecked[i] = true;
mapParent[i] = (uchar)i; mapParent[i] = (uchar)i;
mapParent[i + 64] = (uchar)(i + 64); mapParent[i + 64] = (uchar)(i + 64);
@@ -314,7 +315,7 @@ void Overworld::LoadOverworldMap() {
} }
} }
overworld_map_texture = overworldMapBitmap->CreateTexture(rom_.Renderer()); // overworld_map_texture = overworldMapBitmap->CreateTexture(rom_.Renderer());
} }
} // namespace zelda3 } // namespace zelda3

View File

@@ -23,11 +23,21 @@ class Overworld {
~Overworld(); ~Overworld();
void Load(app::rom::ROM& rom); void Load(app::rom::ROM& rom);
inline auto GetTiles16() const { return tiles16; }
inline auto GetCurrentGfxSetPtr() { return currentOWgfx16Ptr; }
inline auto GetMapBlockset16Ptr() { return mapblockset16; }
char* overworldMapPointer = new char[0x40000]; char* overworldMapPointer = new char[0x40000];
gfx::Bitmap* overworldMapBitmap; gfx::Bitmap* overworldMapBitmap;
private: private:
ushort GenerateTile32(int i, int k, int dimension);
void AssembleMap32Tiles();
void AssembleMap16Tiles();
void DecompressAllMapTiles();
void FetchLargeMaps();
void LoadOverworldMap();
app::rom::ROM rom_; app::rom::ROM rom_;
int gameState = 1; int gameState = 1;
bool isLoaded = false; bool isLoaded = false;
@@ -37,23 +47,19 @@ class Overworld {
ushort** allmapsTilesDW; // 64 maps * (32*32 tiles) ushort** allmapsTilesDW; // 64 maps * (32*32 tiles)
ushort** allmapsTilesSP; // 32 maps * (32*32 tiles) ushort** allmapsTilesSP; // 32 maps * (32*32 tiles)
std::vector<gfx::Tile16> tiles16;
std::vector<gfx::Tile32> tiles32;
std::vector<gfx::Tile32> map16tiles;
std::vector<OverworldMap> allmaps;
std::vector<ushort> tileLeftEntrance; std::vector<ushort> tileLeftEntrance;
std::vector<ushort> tileRightEntrance; std::vector<ushort> tileRightEntrance;
std::shared_ptr<uchar> mapblockset16; uchar* mapblockset16 = new uchar[1048576];
std::shared_ptr<uchar> currentOWgfx16Ptr; uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2];
gfx::Bitmap mapblockset16Bitmap;
SDL_Texture* overworld_map_texture; SDL_Texture* overworld_map_texture;
int map32address[4] = { std::vector<gfx::Tile16> tiles16;
std::vector<gfx::Tile32> tiles32;
std::vector<gfx::Tile32> map16tiles;
std::vector<OverworldMap> overworld_maps_;
const int map32address[4] = {
core::constants::map32TilesTL, core::constants::map32TilesTR, core::constants::map32TilesTL, core::constants::map32TilesTR,
core::constants::map32TilesBL, core::constants::map32TilesBR}; core::constants::map32TilesBL, core::constants::map32TilesBR};
@@ -63,13 +69,6 @@ class Overworld {
map32TilesBL = 2, map32TilesBL = 2,
map32TilesBR = 3 map32TilesBR = 3
}; };
ushort GenerateTile32(int i, int k, int dimension);
void AssembleMap32Tiles();
void AssembleMap16Tiles();
void DecompressAllMapTiles();
void FetchLargeMaps();
void LoadOverworldMap();
}; };
} // namespace zelda3 } // namespace zelda3

View File

@@ -14,8 +14,8 @@ namespace zelda3 {
using namespace core; using namespace core;
using namespace gfx; using namespace gfx;
OverworldMap::OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> tiles16, OverworldMap::OverworldMap(app::rom::ROM& rom,
uchar index) const std::vector<gfx::Tile16> tiles16, uchar index)
: rom_(rom), index(index), tiles16_(tiles16), parent(index) { : rom_(rom), index(index), tiles16_(tiles16), parent(index) {
if (index != 0x80) { if (index != 0x80) {
if (index <= 150) { if (index <= 150) {
@@ -111,8 +111,9 @@ OverworldMap::OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> ti
void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState, void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState,
ushort** allmapsTilesLW, ushort** allmapsTilesDW, ushort** allmapsTilesLW, ushort** allmapsTilesDW,
ushort** allmapsTilesSP) { ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr) {
tilesUsed = new ushort*[32]; tilesUsed = new ushort*[32];
currentOWgfx16Ptr_ = currentOWgfx16Ptr;
for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort; for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort;
if (largeMap) { if (largeMap) {
@@ -333,7 +334,7 @@ void OverworldMap::BuildTileset(int gameState) {
staticgfx[7] = 91; staticgfx[7] = 91;
} }
uchar* currentmapgfx8Data = new uchar[(128 * 512) / 2]; uchar* currentmapgfx8Data = currentOWgfx16Ptr_;
// (uchar*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current // (uchar*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current
// // map (empty at this point) // // map (empty at this point)
uchar* allgfxData = new uchar[(128 * 7136) / 2]; uchar* allgfxData = new uchar[(128 * 7136) / 2];

View File

@@ -29,7 +29,7 @@ class OverworldMap {
int* gfxPtr = new int[512 * 512]; int* gfxPtr = new int[512 * 512];
int* mapblockset16 = new int[1048576]; int* mapblockset16 = new int[1048576];
gfx::Bitmap mapblockset16Bitmap; uchar* currentOWgfx16Ptr_ = nullptr;
gfx::Bitmap gfxBitmap; gfx::Bitmap gfxBitmap;
uchar* staticgfx = uchar* staticgfx =
@@ -42,10 +42,11 @@ class OverworldMap {
uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2]; uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2];
std::vector<gfx::Tile16> tiles16_; std::vector<gfx::Tile16> tiles16_;
OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> tiles16, uchar index); OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> tiles16,
uchar index);
void BuildMap(uchar* mapParent, int count, int gameState, void BuildMap(uchar* mapParent, int count, int gameState,
ushort** allmapsTilesLW, ushort** allmapsTilesDW, ushort** allmapsTilesLW, ushort** allmapsTilesDW,
ushort** allmapsTilesSP); ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr);
void CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr, void CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
int* sourcebmpPtr); int* sourcebmpPtr);
void CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr, void CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr,

View File

@@ -37,7 +37,7 @@ void OverworldEditor::SetupROM(app::rom::ROM &rom) { rom_ = rom; }
void OverworldEditor::Update() { void OverworldEditor::Update() {
if (rom_.isLoaded()) { if (rom_.isLoaded()) {
if (!all_gfx_loaded_) { if (!all_gfx_loaded_) {
Loadgfx(); LoadGraphics();
// overworld_.Load(rom_); // overworld_.Load(rom_);
all_gfx_loaded_ = true; all_gfx_loaded_ = true;
} }
@@ -134,6 +134,7 @@ void OverworldEditor::DrawToolset() {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Button(ICON_MD_UPDATE)) { if (ImGui::Button(ICON_MD_UPDATE)) {
overworld_.Load(rom_); overworld_.Load(rom_);
LoadBlockset();
} }
ImGui::EndTable(); ImGui::EndTable();
@@ -285,7 +286,13 @@ void OverworldEditor::DrawOverworldCanvas() {
void OverworldEditor::DrawTileSelector() { void OverworldEditor::DrawTileSelector() {
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) { if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Tile16")) { if (ImGui::BeginTabItem("Tile16")) {
DrawTile16Selector(); ImGuiStyle &style = ImGui::GetStyle();
bool child_is_visible =
ImGui::BeginChild("#Tile16Child", ImGui::GetContentRegionAvail(),
true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
if (child_is_visible) DrawTile16Selector();
ImGui::EndChild();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
if (ImGui::BeginTabItem("Tile8")) { if (ImGui::BeginTabItem("Tile8")) {
@@ -294,9 +301,7 @@ void OverworldEditor::DrawTileSelector() {
bool child_is_visible = bool child_is_visible =
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar); ImGuiWindowFlags_AlwaysVerticalScrollbar);
if (child_is_visible) // Avoid calling SetScrollHereY when running with if (child_is_visible) {
// culled items
{
DrawTile8Selector(); DrawTile8Selector();
} }
float scroll_x = ImGui::GetScrollX(); float scroll_x = ImGui::GetScrollX();
@@ -337,11 +342,19 @@ void OverworldEditor::DrawTile16Selector() {
// Context menu (under default mouse threshold) // Context menu (under default mouse threshold)
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right); ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
if (drag_delta.x == 0.0f && drag_delta.y == 0.0f) if (drag_delta.x == 0.0f && drag_delta.y == 0.0f)
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); ImGui::OpenPopupOnItemClick("contextTile16",
ImGuiPopupFlags_MouseButtonRight);
if (ImGui::BeginPopup("context")) { if (ImGui::BeginPopup("context")) {
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (map_blockset_loaded_) {
draw_list->AddImage((void *)(SDL_Texture *)mapblockset16Bitmap.GetTexture(),
ImVec2(canvas_p0.x + 2, canvas_p0.y + 2),
ImVec2(canvas_p0.x + (mapblockset16Bitmap.GetWidth() * 2),
canvas_p0.y + (mapblockset16Bitmap.GetHeight() * 2)));
}
// Draw grid + all lines in the canvas // Draw grid + all lines in the canvas
draw_list->PushClipRect(canvas_p0, canvas_p1, true); draw_list->PushClipRect(canvas_p0, canvas_p1, true);
if (opt_enable_grid) { if (opt_enable_grid) {
@@ -434,7 +447,16 @@ void OverworldEditor::DrawChangelist() {
ImGui::End(); ImGui::End();
} }
void OverworldEditor::Loadgfx() { void OverworldEditor::LoadBlockset() {
auto tiles = overworld_.GetTiles16();
app::gfx::BuildTiles16Gfx(overworld_.GetMapBlockset16Ptr(),
overworld_.GetCurrentGfxSetPtr(), tiles);
mapblockset16Bitmap.Create(128, 8192, 128, overworld_.GetMapBlockset16Ptr());
mapblockset16Bitmap.CreateTexture(rom_.Renderer());
map_blockset_loaded_ = true;
}
void OverworldEditor::LoadGraphics() {
for (int i = 0; i < kNumSheetsToLoad; i++) { for (int i = 0; i < kNumSheetsToLoad; i++) {
all_texture_sheet_[i] = rom_.DrawGraphicsSheet(i); all_texture_sheet_[i] = rom_.DrawGraphicsSheet(i);
} }

View File

@@ -30,11 +30,14 @@ class OverworldEditor {
void DrawChangelist(); void DrawChangelist();
void Loadgfx(); void LoadBlockset();
void LoadGraphics();
app::rom::ROM rom_; app::rom::ROM rom_;
app::zelda3::Overworld overworld_; app::zelda3::Overworld overworld_;
app::gfx::Bitmap allgfxBitmap; app::gfx::Bitmap allgfxBitmap;
app::gfx::Bitmap mapblockset16Bitmap;
app::gfx::SNESPalette palette_; app::gfx::SNESPalette palette_;
app::gfx::TilePreset current_set_; app::gfx::TilePreset current_set_;
std::unordered_map<unsigned int, SDL_Texture *> all_texture_sheet_; std::unordered_map<unsigned int, SDL_Texture *> all_texture_sheet_;
@@ -61,6 +64,7 @@ class OverworldEditor {
bool opt_enable_grid = true; bool opt_enable_grid = true;
bool show_changelist_ = false; bool show_changelist_ = false;
bool all_gfx_loaded_ = false; bool all_gfx_loaded_ = false;
bool map_blockset_loaded_ = false;
constexpr static int kByteSize = 3; constexpr static int kByteSize = 3;
constexpr static int kMessageIdSize = 5; constexpr static int kMessageIdSize = 5;