refactor overworld data

This commit is contained in:
scawful
2022-06-22 23:13:51 -04:00
parent 02a836caeb
commit 377c548f73
4 changed files with 138 additions and 194 deletions

View File

@@ -10,28 +10,13 @@ namespace zelda3 {
using namespace core; using namespace core;
using namespace gfx; using namespace gfx;
Overworld::~Overworld() {
if (isLoaded) {
for (int i = 0; i < (int)tiles32.size(); i++) {
free(allmapsTilesLW[i]);
free(allmapsTilesDW[i]);
free(allmapsTilesSP[i]);
}
free(allmapsTilesLW);
free(allmapsTilesDW);
free(allmapsTilesSP);
delete[] overworldMapPointer;
}
}
static TileInfo GetTilesInfo(ushort tile) { static TileInfo GetTilesInfo(ushort tile) {
// vhopppcc cccccccc // vhopppcc cccccccc
ushort o = 0; ushort o = 0;
ushort v = 0; ushort v = 0;
ushort h = 0; ushort h = 0;
ushort tid = (ushort)(tile & 0x3FF); auto tid = (ushort)(tile & 0x3FF);
uchar p = (uchar)((tile >> 10) & 0x07); auto p = (uchar)((tile >> 10) & 0x07);
o = (ushort)((tile & 0x2000) >> 13); o = (ushort)((tile & 0x2000) >> 13);
h = (ushort)((tile & 0x4000) >> 14); h = (ushort)((tile & 0x4000) >> 14);
@@ -43,12 +28,6 @@ static TileInfo GetTilesInfo(ushort tile) {
void Overworld::Load(app::rom::ROM& rom, uchar* allGfxPtr) { void Overworld::Load(app::rom::ROM& rom, uchar* allGfxPtr) {
rom_ = rom; rom_ = rom;
allGfx16Ptr = allGfxPtr; allGfx16Ptr = allGfxPtr;
for (int i = 0; i < 0x2B; i++) {
tileLeftEntrance.push_back(constants::overworldEntranceAllowedTilesLeft +
(i * 2));
tileRightEntrance.push_back(constants::overworldEntranceAllowedTilesRight +
(i * 2));
}
AssembleMap32Tiles(); AssembleMap32Tiles();
AssembleMap16Tiles(); AssembleMap16Tiles();
@@ -56,7 +35,7 @@ void Overworld::Load(app::rom::ROM& rom, uchar* allGfxPtr) {
// Map Initialization // Map Initialization
for (int i = 0; i < constants::NumberOfOWMaps; i++) { for (int i = 0; i < constants::NumberOfOWMaps; i++) {
overworld_maps_.push_back(OverworldMap(rom_, tiles16, i)); overworld_maps_.emplace_back(rom_, tiles16, i);
} }
FetchLargeMaps(); FetchLargeMaps();
LoadOverworldMap(); LoadOverworldMap();
@@ -65,16 +44,17 @@ void Overworld::Load(app::rom::ROM& rom, uchar* allGfxPtr) {
for (int i = 0; i < 160; i++) { for (int i = 0; i < 160; i++) {
overworld_maps_[i].BuildMap(mapParent, size, gameState, allmapsTilesLW, overworld_maps_[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
allmapsTilesDW, allmapsTilesSP, allmapsTilesDW, allmapsTilesSP,
currentOWgfx16Ptr, allGfx16Ptr, mapblockset16); currentOWgfx16Ptr.get(), allGfx16Ptr,
mapblockset16.get());
} }
isLoaded = true; isLoaded = true;
} }
ushort Overworld::GenerateTile32(int i, int k, int dimension) { ushort Overworld::GenerateTile32(int i, int k, int dimension) {
return (ushort)(rom_.GetRawData()[map32address[dimension] + k + (i)] + return (ushort)(rom_.data()[map32address[dimension] + k + (i)] +
(((rom_.GetRawData()[map32address[dimension] + (i) + (((rom_.data()[map32address[dimension] + (i) +
(k <= 1 ? 4 : 5)] >> (k <= 1 ? 4 : 5)] >>
(k % 2 == 0 ? 4 : 0)) & (k % 2 == 0 ? 4 : 0)) &
0x0F) * 0x0F) *
256)); 256));
@@ -92,22 +72,19 @@ void Overworld::AssembleMap32Tiles() {
} }
} }
allmapsTilesLW = (ushort**)malloc(tiles32.size() * sizeof(ushort*)); allmapsTilesLW.resize(tiles32.size());
for (int i = 0; i < tiles32.size(); i++) allmapsTilesDW.resize(tiles32.size());
allmapsTilesLW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort)); allmapsTilesSP.resize(tiles32.size());
for (int i = 0; i < tiles32.size(); i++) {
allmapsTilesDW = (ushort**)malloc(tiles32.size() * sizeof(ushort*)); allmapsTilesLW[i].resize(tiles32.size());
for (int i = 0; i < tiles32.size(); i++) allmapsTilesDW[i].resize(tiles32.size());
allmapsTilesDW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort)); allmapsTilesSP[i].resize(tiles32.size());
}
allmapsTilesSP = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
for (int i = 0; i < tiles32.size(); i++)
allmapsTilesSP[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
} }
void Overworld::AssembleMap16Tiles() { void Overworld::AssembleMap16Tiles() {
int tpos = core::constants::map16Tiles; int tpos = core::constants::map16Tiles;
auto rom_data = rom_.GetRawData(); auto rom_data = rom_.data();
for (int i = 0; i < 4096; i += 1) // 3760 for (int i = 0; i < 4096; i += 1) // 3760
{ {
TileInfo t0 = GetTilesInfo((uintptr_t)(rom_data + tpos)); TileInfo t0 = GetTilesInfo((uintptr_t)(rom_data + tpos));
@@ -118,7 +95,7 @@ void Overworld::AssembleMap16Tiles() {
tpos += 2; tpos += 2;
TileInfo t3 = GetTilesInfo((uintptr_t)(rom_data + tpos)); TileInfo t3 = GetTilesInfo((uintptr_t)(rom_data + tpos));
tpos += 2; tpos += 2;
tiles16.push_back(Tile16(t0, t1, t2, t3)); tiles16.emplace_back(t0, t1, t2, t3);
} }
} }
@@ -129,26 +106,22 @@ void Overworld::DecompressAllMapTiles() {
int sy = 0; int sy = 0;
int c = 0; int c = 0;
for (int i = 0; i < 160; i++) { for (int i = 0; i < 160; i++) {
int p1 = (rom_.GetRawData()[(constants::compressedAllMap32PointersHigh) + int p1 =
2 + (int)(3 * i)] (rom_.data()[(constants::compressedAllMap32PointersHigh) + 2 + (3 * i)]
<< 16) + << 16) +
(rom_.GetRawData()[(constants::compressedAllMap32PointersHigh) + (rom_.data()[(constants::compressedAllMap32PointersHigh) + 1 + (3 * i)]
1 + (int)(3 * i)] << 8) +
<< 8) + (rom_.data()[(constants::compressedAllMap32PointersHigh + (3 * i))]);
(rom_.GetRawData()[(constants::compressedAllMap32PointersHigh +
(int)(3 * i))]);
char* tmp = new char[256]; auto* tmp = new char[256];
p1 = lorom_snes_to_pc(p1, &tmp); p1 = lorom_snes_to_pc(p1, &tmp);
std::cout << tmp << std::endl; std::cout << tmp << std::endl;
int p2 = (rom_.GetRawData()[(constants::compressedAllMap32PointersLow) + 2 + int p2 =
(int)(3 * i)] (rom_.data()[(constants::compressedAllMap32PointersLow) + 2 + (3 * i)]
<< 16) + << 16) +
(rom_.GetRawData()[(constants::compressedAllMap32PointersLow) + 1 + (rom_.data()[(constants::compressedAllMap32PointersLow) + 1 + (3 * i)]
(int)(3 * i)] << 8) +
<< 8) + (rom_.data()[(constants::compressedAllMap32PointersLow + (3 * i))]);
(rom_.GetRawData()[(constants::compressedAllMap32PointersLow +
(int)(3 * i))]);
p2 = lorom_snes_to_pc(p2, &tmp); p2 = lorom_snes_to_pc(p2, &tmp);
std::cout << tmp << std::endl; std::cout << tmp << std::endl;
delete[] tmp; delete[] tmp;
@@ -166,23 +139,17 @@ void Overworld::DecompressAllMapTiles() {
highest = p2; highest = p2;
} }
if (p1 <= lowest) { if (p1 <= lowest && p1 > 0x0F8000) {
if (p1 > 0x0F8000) { lowest = p1;
lowest = p1;
}
} }
if (p2 <= lowest) { if (p2 <= lowest && p2 > 0x0F8000) {
if (p2 > 0x0F8000) { lowest = p2;
lowest = p2;
}
} }
auto bytes = auto bytes = alttp_decompress_overworld(
alttp_decompress_overworld((char*)rom_.GetRawData(), p2, 1000, (char*)rom_.data(), p2, 1000, &compressedSize1, &compressedLength1);
&compressedSize1, &compressedLength1); auto bytes2 = alttp_decompress_overworld(
auto bytes2 = (char*)rom_.data(), p1, 1000, &compressedSize2, &compressedLength2);
alttp_decompress_overworld((char*)rom_.GetRawData(), p1, 1000,
&compressedSize2, &compressedLength2);
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
@@ -256,8 +223,8 @@ void Overworld::FetchLargeMaps() {
overworld_maps_[136].large_map_ = false; overworld_maps_[136].large_map_ = false;
bool mapChecked[64]; bool mapChecked[64];
for (int i = 0; i < 64; i++) { for (auto& each : mapChecked) {
mapChecked[i] = false; each = false;
} }
int xx = 0; int xx = 0;
int yy = 0; int yy = 0;
@@ -300,7 +267,7 @@ void Overworld::FetchLargeMaps() {
} }
void Overworld::LoadOverworldMap() { void Overworld::LoadOverworldMap() {
overworldMapBitmap.Create(128, 128, 8, overworldMapPointer); overworldMapBitmap.Create(128, 128, 8, overworldMapPointer.get());
auto ptr = overworldMapPointer; auto ptr = overworldMapPointer;
@@ -310,7 +277,7 @@ void Overworld::LoadOverworldMap() {
for (int y = 0; y < 8; y++) { for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
ptr[x + (sx * 8) + (y * 128) + (sy * 1024)] = ptr[x + (sx * 8) + (y * 128) + (sy * 1024)] =
rom_.GetRawData()[0x0C4000 + pos]; rom_.data()[0x0C4000 + pos];
pos++; pos++;
} }
} }

View File

@@ -19,15 +19,12 @@ namespace zelda3 {
class Overworld { class Overworld {
public: public:
Overworld() = default;
~Overworld();
void Load(app::rom::ROM& rom, uchar* allGfxPtr); void Load(app::rom::ROM& rom, uchar* allGfxPtr);
inline auto GetTiles16() const { return tiles16; } inline auto GetTiles16() const { return tiles16; }
inline auto GetCurrentGfxSetPtr() { return currentOWgfx16Ptr; } inline auto GetCurrentGfxSetPtr() { return currentOWgfx16Ptr; }
inline auto GetMapBlockset16Ptr() { return mapblockset16; } inline auto GetMapBlockset16Ptr() { return mapblockset16; }
uchar* overworldMapPointer = new uchar[0x40000]; std::shared_ptr<uchar[]> overworldMapPointer = std::make_shared<uchar>(0x40000);
gfx::Bitmap overworldMapBitmap; gfx::Bitmap overworldMapBitmap;
private: private:
@@ -43,17 +40,14 @@ class Overworld {
bool isLoaded = false; bool isLoaded = false;
uchar mapParent[160]; uchar mapParent[160];
ushort** allmapsTilesLW; // 64 maps * (32*32 tiles) std::vector<std::vector<ushort>> allmapsTilesLW; // 64 maps * (32*32 tiles)
ushort** allmapsTilesDW; // 64 maps * (32*32 tiles) std::vector<std::vector<ushort>> allmapsTilesDW; // 64 maps * (32*32 tiles)
ushort** allmapsTilesSP; // 32 maps * (32*32 tiles) std::vector<std::vector<ushort>> allmapsTilesSP; // 32 maps * (32*32 tiles)
std::vector<ushort> tileLeftEntrance;
std::vector<ushort> tileRightEntrance;
uchar* allGfx16Ptr = nullptr; uchar* allGfx16Ptr = nullptr;
uchar* mapblockset16 = new uchar[1048576]; std::shared_ptr<uchar[]> mapblockset16 = std::make_shared<uchar>(1048576);
uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2]; std::shared_ptr<uchar[]> currentOWgfx16Ptr =
SDL_Texture* overworld_map_texture; std::make_shared<uchar>((128 * 512) / 2);
std::vector<gfx::Tile16> tiles16; std::vector<gfx::Tile16> tiles16;
std::vector<gfx::Tile32> tiles32; std::vector<gfx::Tile32> tiles32;

View File

@@ -15,54 +15,48 @@ using namespace core;
using namespace gfx; using namespace gfx;
OverworldMap::OverworldMap(app::rom::ROM& rom, OverworldMap::OverworldMap(app::rom::ROM& rom,
const std::vector<gfx::Tile16> tiles16, int index_) const std::vector<gfx::Tile16>& tiles16, int index_)
: rom_(rom), index_(index_), tiles16_(tiles16), parent_(index_) { : parent_(index_), index_(index_), rom_(rom), tiles16_(tiles16) {
if (index_ != 0x80) { if (index_ != 0x80 && index_ <= 150 &&
if (index_ <= 150) { rom_.data()[constants::overworldMapSize + (index_ & 0x3F)] != 0) {
if (rom_.GetRawData()[constants::overworldMapSize + (index_ & 0x3F)] != large_map_ = true;
0) {
large_map_ = true;
}
}
} }
if (index_ < 64) { if (index_ < 64) {
sprite_graphics_[0] = sprite_graphics_[0] = rom_.data()[constants::overworldSpriteset + parent_];
rom_.GetRawData()[constants::overworldSpriteset + parent_];
sprite_graphics_[1] = sprite_graphics_[1] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 64]; rom_.data()[constants::overworldSpriteset + parent_ + 64];
sprite_graphics_[2] = sprite_graphics_[2] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
gfx_ = rom_.GetRawData()[constants::mapGfx + parent_]; gfx_ = rom_.data()[constants::mapGfx + parent_];
palette_ = rom_.GetRawData()[constants::overworldMapPalette + parent_]; palette_ = rom_.data()[constants::overworldMapPalette + parent_];
sprite_palette_[0] = sprite_palette_[0] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_]; rom_.data()[constants::overworldSpritePalette + parent_];
sprite_palette_[1] = sprite_palette_[1] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 64]; rom_.data()[constants::overworldSpritePalette + parent_ + 64];
sprite_palette_[2] = sprite_palette_[2] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
musics[0] = rom_.GetRawData()[constants::overworldMusicBegining + parent_]; musics[0] = rom_.data()[constants::overworldMusicBegining + parent_];
musics[1] = rom_.GetRawData()[constants::overworldMusicZelda + parent_]; musics[1] = rom_.data()[constants::overworldMusicZelda + parent_];
musics[2] = musics[2] = rom_.data()[constants::overworldMusicMasterSword + parent_];
rom_.GetRawData()[constants::overworldMusicMasterSword + parent_]; musics[3] = rom_.data()[constants::overworldMusicAgahim + parent_];
musics[3] = rom_.GetRawData()[constants::overworldMusicAgahim + parent_];
} else if (index_ < 128) { } else if (index_ < 128) {
sprite_graphics_[0] = sprite_graphics_[0] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
sprite_graphics_[1] = sprite_graphics_[1] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
sprite_graphics_[2] = sprite_graphics_[2] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
gfx_ = rom_.GetRawData()[constants::mapGfx + parent_]; gfx_ = rom_.data()[constants::mapGfx + parent_];
palette_ = rom_.GetRawData()[constants::overworldMapPalette + parent_]; palette_ = rom_.data()[constants::overworldMapPalette + parent_];
sprite_palette_[0] = sprite_palette_[0] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
sprite_palette_[1] = sprite_palette_[1] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
sprite_palette_[2] = sprite_palette_[2] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
musics[0] = rom_.GetRawData()[constants::overworldMusicDW + (parent_ - 64)]; musics[0] = rom_.data()[constants::overworldMusicDW + (parent_ - 64)];
} else { } else {
if (index_ == 0x94) { if (index_ == 0x94) {
parent_ = 128; parent_ = 128;
@@ -86,69 +80,63 @@ OverworldMap::OverworldMap(app::rom::ROM& rom,
parent_ = 136; parent_ = 136;
} }
message_id_ = rom_.GetRawData()[constants::overworldMessages + parent_]; message_id_ = rom_.data()[constants::overworldMessages + parent_];
sprite_graphics_[0] = sprite_graphics_[0] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
sprite_graphics_[1] = sprite_graphics_[1] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
sprite_graphics_[2] = sprite_graphics_[2] =
rom_.GetRawData()[constants::overworldSpriteset + parent_ + 128]; rom_.data()[constants::overworldSpriteset + parent_ + 128];
sprite_palette_[0] = sprite_palette_[0] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
sprite_palette_[1] = sprite_palette_[1] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
sprite_palette_[2] = sprite_palette_[2] =
rom_.GetRawData()[constants::overworldSpritePalette + parent_ + 128]; rom_.data()[constants::overworldSpritePalette + parent_ + 128];
palette_ = palette_ = rom_.data()[constants::overworldSpecialPALGroup + parent_ - 128];
rom_.GetRawData()[constants::overworldSpecialPALGroup + parent_ - 128];
if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) { if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) {
gfx_ = rom_.GetRawData()[constants::overworldSpecialGFXGroup + gfx_ = rom_.data()[constants::overworldSpecialGFXGroup + (parent_ - 128)];
(parent_ - 128)]; palette_ = rom_.data()[constants::overworldSpecialPALGroup + 1];
palette_ = rom_.GetRawData()[constants::overworldSpecialPALGroup + 1];
} else if (index_ == 0x88) { } else if (index_ == 0x88) {
gfx_ = 81; gfx_ = 81;
palette_ = 0; palette_ = 0;
} else // pyramid bg use 0x5B map } else // pyramid bg use 0x5B map
{ {
gfx_ = rom_.GetRawData()[constants::mapGfx + parent_]; gfx_ = rom_.data()[constants::mapGfx + parent_];
palette_ = rom_.GetRawData()[constants::overworldMapPalette + parent_]; palette_ = rom_.data()[constants::overworldMapPalette + parent_];
} }
} }
} }
void OverworldMap::BuildMap(uchar* mapparent_, int count, int gameState, void OverworldMap::BuildMap(uchar* mapparent_, int count, int gameState,
ushort** allmapsTilesLW, ushort** allmapsTilesDW, std::vector<std::vector<ushort>>& allmapsTilesLW,
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr, std::vector<std::vector<ushort>>& allmapsTilesDW,
uchar* allGfxPtr, uchar* mapblockset16) { std::vector<std::vector<ushort>>& allmapsTilesSP,
tilesUsed = new ushort*[32]; uchar* currentOWgfx16Ptr, uchar* allGfxPtr,
uchar* mapblockset16) {
currentOWgfx16Ptr_ = currentOWgfx16Ptr; currentOWgfx16Ptr_ = currentOWgfx16Ptr;
allGfx16Ptr_ = allGfxPtr; allGfx16Ptr_ = allGfxPtr;
mapblockset16_ = mapblockset16; mapblockset16_ = mapblockset16;
for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort;
if (large_map_) { if (large_map_) {
this->parent_ = mapparent_[index_]; this->parent_ = mapparent_[index_];
if (parent_ != index_) { if (parent_ != index_ && !initialized_) {
if (!initialized_) { if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) {
if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) { gfx_ = rom_.data()[core::constants::overworldSpecialGFXGroup +
gfx_ = rom_.GetRawData()[core::constants::overworldSpecialGFXGroup + (parent_ - 128)];
(parent_ - 128)]; palette_ = rom_.data()[core::constants::overworldSpecialPALGroup + 1];
palette_ = } else if (index_ == 0x88) {
rom_.GetRawData()[core::constants::overworldSpecialPALGroup + 1]; gfx_ = 81;
} else if (index_ == 0x88) { palette_ = 0;
gfx_ = 81; } else {
palette_ = 0; gfx_ = rom_.data()[core::constants::mapGfx + parent_];
} else { palette_ = rom_.data()[core::constants::overworldMapPalette + parent_];
gfx_ = rom_.GetRawData()[core::constants::mapGfx + parent_];
palette_ =
rom_.GetRawData()[core::constants::overworldMapPalette + parent_];
}
initialized_ = true;
} }
initialized_ = true;
} }
} }
@@ -158,12 +146,12 @@ void OverworldMap::BuildMap(uchar* mapparent_, int count, int gameState,
int world = 0; int world = 0;
if (index_ < 64) { if (index_ < 64) {
tilesUsed = allmapsTilesLW; tiles_used_ = allmapsTilesLW;
} else if (index_ < 128 && index_ >= 64) { } else if (index_ < 128 && index_ >= 64) {
tilesUsed = allmapsTilesDW; tiles_used_ = allmapsTilesDW;
world = 1; world = 1;
} else { } else {
tilesUsed = allmapsTilesSP; tiles_used_ = allmapsTilesSP;
world = 2; world = 2;
} }
@@ -173,7 +161,7 @@ void OverworldMap::BuildMap(uchar* mapparent_, int count, int gameState,
for (int y = 0; y < 32; y++) { for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) { for (int x = 0; x < 32; x++) {
CopyTile8bpp16((x * 16), (y * 16), CopyTile8bpp16((x * 16), (y * 16),
tilesUsed[x + (superX * 32)][y + (superY * 32)], gfxPtr, tiles_used_[x + (superX * 32)][y + (superY * 32)], gfxPtr,
mapblockset16); mapblockset16);
} }
} }
@@ -181,10 +169,8 @@ void OverworldMap::BuildMap(uchar* mapparent_, int count, int gameState,
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr, void OverworldMap::CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr,
uchar* sourcebmpPtr) { uchar* sourcebmpPtr) {
int sourceY = (tile / 8);
int sourceX = (tile) - ((sourceY)*8);
int sourcePtrPos = ((tile - ((tile / 8) * 8)) * 16) + int sourcePtrPos = ((tile - ((tile / 8) * 8)) * 16) +
((tile / 8) * 2048); //(sourceX * 16) + (sourceY * 128); ((tile / 8) * 2048); // (sourceX * 16) + (sourceY * 128)
auto sourcePtr = sourcebmpPtr; auto sourcePtr = sourcebmpPtr;
int destPtrPos = (x + (y * 512)); int destPtrPos = (x + (y * 512));
@@ -252,10 +238,10 @@ void OverworldMap::BuildTiles16Gfx(int count) {
} }
} }
// map,current
void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset, void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset,
TileInfo tile, uchar* gfx16Pointer, TileInfo tile, uchar* gfx16Pointer,
uchar* gfx8Pointer) // map,current uchar* gfx8Pointer) {
{
int mx = x; int mx = x;
int my = y; int my = y;
uchar r = 0; uchar r = 0;
@@ -270,18 +256,17 @@ void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset,
} }
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]; auto 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] = gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
(uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
} }
// map,current
void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset, void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset,
TileInfo tile, uchar* gfx16Pointer, TileInfo tile, uchar* gfx16Pointer,
uchar* gfx8Pointer) // map,current uchar* gfx8Pointer) {
{
int mx = x; int mx = x;
int my = y; int my = y;
uchar r = 0; uchar r = 0;
@@ -320,32 +305,28 @@ void OverworldMap::BuildTileset(int gameState) {
staticgfx[11] = 115 + 7; staticgfx[11] = 115 + 7;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
staticgfx[12 + i] = staticgfx[12 + i] =
(uchar)(rom_.GetRawData()[constants::sprite_blockset_pointer + (uchar)(rom_.data()[constants::sprite_blockset_pointer +
(sprite_graphics_[gameState] * 4) + i] + (sprite_graphics_[gameState] * 4) + i] +
115); 115);
} }
// Main Blocksets // Main Blocksets
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
staticgfx[i] = rom_.GetRawData()[constants::overworldgfxGroups2 + staticgfx[i] =
(indexWorld * 8) + i]; rom_.data()[constants::overworldgfxGroups2 + (indexWorld * 8) + i];
} }
if (rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4)] != 0) { if (rom_.data()[constants::overworldgfxGroups + (gfx_ * 4)] != 0) {
staticgfx[3] = staticgfx[3] = rom_.data()[constants::overworldgfxGroups + (gfx_ * 4)];
rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4)];
} }
if (rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 1] != 0) { if (rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 1] != 0) {
staticgfx[4] = staticgfx[4] = rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 1];
rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 1];
} }
if (rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 2] != 0) { if (rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 2] != 0) {
staticgfx[5] = staticgfx[5] = rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 2];
rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 2];
} }
if (rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 3] != 0) { if (rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 3] != 0) {
staticgfx[6] = staticgfx[6] = rom_.data()[constants::overworldgfxGroups + (gfx_ * 4) + 3];
rom_.GetRawData()[constants::overworldgfxGroups + (gfx_ * 4) + 3];
} }
// Hardcoded overworld GFX Values, for death mountain // Hardcoded overworld GFX Values, for death mountain
@@ -360,7 +341,7 @@ void OverworldMap::BuildTileset(int gameState) {
} }
uchar* currentmapgfx8Data = currentOWgfx16Ptr_; uchar* currentmapgfx8Data = currentOWgfx16Ptr_;
uchar* allgfxData = allGfx16Ptr_; uchar const* allgfxData = allGfx16Ptr_;
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
for (int j = 0; j < 2048; j++) { for (int j = 0; j < 2048; j++) {

View File

@@ -35,14 +35,16 @@ class OverworldMap {
std::vector<gfx::Tile16> tiles16_; std::vector<gfx::Tile16> tiles16_;
uchar* staticgfx = new uchar[16]; uchar* staticgfx = new uchar[16];
ushort** tilesUsed; std::vector<std::vector<ushort>> tiles_used_;
OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> tiles16, OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16>& tiles16,
int index); int index);
void BuildMap(uchar* mapParent, int count, int gameState, void BuildMap(uchar* mapParent, int count, int gameState,
ushort** allmapsTilesLW, ushort** allmapsTilesDW, std::vector<std::vector<ushort>>& allmapsTilesLW,
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr, std::vector<std::vector<ushort>>& allmapsTilesDW,
uchar* allGfxPtr, uchar* mapblockset16); std::vector<std::vector<ushort>>& allmapsTilesSP,
uchar* currentOWgfx16Ptr, uchar* allGfxPtr,
uchar* mapblockset16);
void CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr, void CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr,
uchar* sourcebmpPtr); uchar* sourcebmpPtr);
void CopyTile8bpp16From8(int xP, int yP, int tileID, uchar* destbmpPtr, void CopyTile8bpp16From8(int xP, int yP, int tileID, uchar* destbmpPtr,