From 874786cc57de3c2a89729642e0e04ca9e4ec65f3 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Sun, 24 Jul 2022 00:01:57 -0400 Subject: [PATCH] BuildTileset upgrades --- src/app/zelda3/overworld.cc | 7 +-- src/app/zelda3/overworld.h | 2 +- src/app/zelda3/overworld_map.cc | 82 +++++++++++++++++++++++++-------- src/app/zelda3/overworld_map.h | 13 +++++- 4 files changed, 79 insertions(+), 25 deletions(-) diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld.cc index 98f6fd72..975c2b7f 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld.cc @@ -7,7 +7,7 @@ namespace yaze { namespace app { namespace zelda3 { -void Overworld::Load(ROM &rom, uchar *ow_blockset, uchar *current_gfx) { +void Overworld::Load(ROM &rom, uchar *ow_blockset) { rom_ = rom; AssembleMap32Tiles(); @@ -20,8 +20,9 @@ void Overworld::Load(ROM &rom, uchar *ow_blockset, uchar *current_gfx) { FetchLargeMaps(); for (int i = 0; i < core::NumberOfOWMaps; i++) { - overworld_maps_[i].BuildMap(tiles16.size(), game_state_, map_parent_, - ow_blockset, current_gfx, map_tiles_); + // overworld_maps_[i].BuildMap(tiles16.size(), game_state_, map_parent_, + // ow_blockset, map_tiles_); + overworld_maps_[i].BuildMapV2(tiles16.size(), game_state_, map_parent_); } is_loaded_ = true; diff --git a/src/app/zelda3/overworld.h b/src/app/zelda3/overworld.h index 4787c307..22ff8db3 100644 --- a/src/app/zelda3/overworld.h +++ b/src/app/zelda3/overworld.h @@ -20,7 +20,7 @@ namespace zelda3 { class Overworld { public: - void Load(ROM &rom, uchar *ow_blockset, uchar *current_gfx); + void Load(ROM &rom, uchar *ow_blockset); auto GetTiles16() const { return tiles16; } auto GetOverworldMap(uint index) { return overworld_maps_[index]; } auto isLoaded() const { return is_loaded_; } diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index 46ab27c3..26140c9e 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -104,8 +104,7 @@ void OverworldMap::LoadAreaInfo() { } void OverworldMap::BuildMap(int count, int game_state, uchar* map_parent, - uchar* ow_blockset, uchar* current_gfx, - OWMapTiles& map_tiles) { + uchar* ow_blockset, OWMapTiles& map_tiles) { if (large_map_) { parent_ = map_parent[index_]; if (parent_ != index_ && !initialized_) { @@ -125,7 +124,7 @@ void OverworldMap::BuildMap(int count, int game_state, uchar* map_parent, } } - BuildTileset(game_state, current_gfx); + BuildTileset(game_state); BuildTiles16Gfx(count, ow_blockset); // build on GFX.mapgfx16Ptr int world = 0; @@ -150,7 +149,30 @@ void OverworldMap::BuildMap(int count, int game_state, uchar* map_parent, } } -void OverworldMap::BuildTileset(int game_state, uchar* current_gfx) { +void OverworldMap::BuildMapV2(int count, int game_state, uchar* map_parent) { + if (large_map_) { + parent_ = map_parent[index_]; + if (parent_ != index_ && !initialized_) { + if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) { + area_graphics_ = + rom_.data()[core::overworldSpecialGFXGroup + (parent_ - 128)]; + area_palette_ = rom_.data()[core::overworldSpecialPALGroup + 1]; + } else if (index_ == 0x88) { + area_graphics_ = 81; + area_palette_ = 0; + } else { + area_graphics_ = rom_.data()[core::mapGfx + parent_]; + area_palette_ = rom_.data()[core::overworldMapPalette + parent_]; + } + + initialized_ = true; + } + } + + BuildTileset(game_state); +} + +absl::Status OverworldMap::BuildTileset(int game_state) { int index_world = 0x20; if (parent_ < 0x40) { index_world = 0x20; @@ -206,23 +228,11 @@ void OverworldMap::BuildTileset(int game_state, uchar* current_gfx) { static_graphics_[7] = 91; } - auto all_gfx_data = rom_.GetMasterGraphicsBin(); + auto all_gfx_data = rom_.GetGraphicsBinV2(); for (int i = 0; i < 16; i++) { - for (int j = 0; j < 2048; j++) { - uchar mapByte = all_gfx_data[j + (static_graphics_[i] * 2048)]; - switch (i) { - case 0: - case 3: - case 4: - case 5: - mapByte += 0x88; - break; - } - - // Upload used gfx data - current_gfx[(i * 2048) + j] = mapByte; - } + current_graphics_sheet_set[i] = all_gfx_data[static_graphics_[i]]; } + return absl::OkStatus(); } void OverworldMap::BuildTiles16Gfx(int count, uchar* ow_blockset) { @@ -258,6 +268,40 @@ void OverworldMap::BuildTiles16Gfx(int count, uchar* ow_blockset) { } } +absl::Status OverworldMap::BuildTiles16GfxV2(int count) { + auto gfx_tile8_data = rom_.GetMasterGraphicsBin(); + + int offsets[] = {0, 8, 1024, 1032}; + auto yy = 0; + auto xx = 0; + + // number of tiles16 3748? + for (auto i = 0; i < count; i++) { + // 8x8 tile draw, gfx8 = 4bpp so everyting is /2F + auto tiles = tiles16_[i]; + + for (auto tile = 0; tile < 4; tile++) { + gfx::TileInfo info = tiles16_[i].tiles_info[tile]; + int offset = offsets[tile]; + + // for (auto y = 0; y < 8; y++) { + // for (auto x = 0; x < 4; x++) { + // CopyTile(x, y, xx, yy, offset, info, gfx_tile16_data, + // gfx_tile8_data); + // } + // } + } + + xx += 16; + if (xx >= 128) { + yy += 2048; + xx = 0; + } + } + + return absl::OkStatus(); +} + // map,current void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, uchar* gfx16Pointer, diff --git a/src/app/zelda3/overworld_map.h b/src/app/zelda3/overworld_map.h index 28674805..d85e76de 100644 --- a/src/app/zelda3/overworld_map.h +++ b/src/app/zelda3/overworld_map.h @@ -8,6 +8,7 @@ #include #include +#include "absl/status/status.h" #include "app/core/common.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" @@ -22,18 +23,24 @@ static constexpr int kTileOffsets[] = {0, 8, 4096, 4104}; class OverworldMap { public: OverworldMap(int index, ROM& rom, const std::vector& tiles16); + void BuildMap(int count, int game_state, uchar* map_parent, - uchar* ow_blockset, uchar* current_gfx, OWMapTiles& map_tiles); + uchar* ow_blockset, OWMapTiles& map_tiles); + + void BuildMapV2(int count, int game_state, uchar* map_parent); auto GetBitmap() { return bitmap_; } + auto GetCurrentGraphicsSet() { return current_graphics_sheet_set; } auto SetLargeMap(bool is_set) { large_map_ = is_set; } auto IsLargeMap() { return large_map_; } private: void LoadAreaInfo(); - void BuildTileset(int game_state, uchar* current_gfx); void BuildTiles16Gfx(int count, uchar* ow_blockset); + absl::Status BuildTileset(int game_state); + absl::Status BuildTiles16GfxV2(int count); + void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, uchar* gfx16Pointer, uchar* gfx8Pointer); @@ -63,6 +70,8 @@ class OverworldMap { std::vector tiles16_; std::vector> tiles_used_; + absl::flat_hash_map current_graphics_sheet_set; + ROM rom_; };