working on OverworldMap drawing
This commit is contained in:
@@ -17,15 +17,15 @@ namespace app {
|
|||||||
namespace zelda3 {
|
namespace zelda3 {
|
||||||
|
|
||||||
OverworldMap::OverworldMap(int index, ROM& rom,
|
OverworldMap::OverworldMap(int index, ROM& rom,
|
||||||
const std::vector<gfx::Tile16>& tiles16)
|
std::vector<gfx::Tile16>& tiles16)
|
||||||
: parent_(index), index_(index), rom_(rom), tiles16_(tiles16) {
|
: parent_(index), index_(index), rom_(rom), tiles16_(tiles16) {
|
||||||
LoadAreaInfo();
|
LoadAreaInfo();
|
||||||
bitmap_.Create(512, 512, 8, 512 * 512);
|
current_overworld_map_.resize(512 * 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
||||||
uchar* map_parent,
|
uchar* map_parent,
|
||||||
const OWBlockset & world_blockset) {
|
OWBlockset& world_blockset) {
|
||||||
world_ = world;
|
world_ = world;
|
||||||
if (large_map_) {
|
if (large_map_) {
|
||||||
parent_ = map_parent[index_];
|
parent_ = map_parent[index_];
|
||||||
@@ -59,15 +59,18 @@ absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
|||||||
RETURN_IF_ERROR(BuildTileset())
|
RETURN_IF_ERROR(BuildTileset())
|
||||||
RETURN_IF_ERROR(BuildTiles16Gfx(count))
|
RETURN_IF_ERROR(BuildTiles16Gfx(count))
|
||||||
|
|
||||||
// int superY = ((index_ - (world * 64)) / 8);
|
int superY = ((index_ - (world * 64)) / 8);
|
||||||
// int superX = index_ - (world * 64) - (superY * 8);
|
int superX = index_ - (world * 64) - (superY * 8);
|
||||||
// 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++) {
|
||||||
// auto xt = x + (superX * 32);
|
auto xt = x + (superX * 32);
|
||||||
// auto yt = y + (superY * 32);
|
auto yt = y + (superY * 32);
|
||||||
// CopyTile8bpp16((x * 16), (y * 16), map_tiles_[xt][yt], ow_blockset);
|
CopyTile8bpp16((x * 16), (y * 16), world_blockset[xt][yt]);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
bitmap_.Create(512, 512, 8, current_overworld_map_.data());
|
||||||
|
bitmap_.CreateTexture(rom_.GetRenderer());
|
||||||
built_ = true;
|
built_ = true;
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
@@ -197,35 +200,15 @@ void OverworldMap::LoadAreaGraphics(int game_state, int world_index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildTileset() {
|
absl::Status OverworldMap::BuildTileset() {
|
||||||
auto all_gfx_data = rom_.GetGraphicsBin();
|
auto all_gfx_data = rom_.GetGraphicsBin();
|
||||||
uint size = 0;
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
current_graphics_sheet_set[i] = all_gfx_data[static_graphics_[i]];
|
current_graphics_sheet_set[i] = all_gfx_data[static_graphics_[i]];
|
||||||
size += current_graphics_sheet_set.size();
|
|
||||||
}
|
}
|
||||||
current_gfx_.resize(size);
|
current_gfx_.reserve(16 * 2048);
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
// all gfx of the game pack of 2048 bytes (4bpp)
|
for (int j = 0; j < 2048; ++j) {
|
||||||
char* allgfxData = nullptr;
|
current_gfx_.emplace_back(current_graphics_sheet_set[i].GetByte(j));
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
for (int j = 0; j < 2048; j++) {
|
|
||||||
auto mapByte = allgfxData[j + (static_graphics_[i] * 2048)];
|
|
||||||
switch (i) {
|
|
||||||
case 0:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
mapByte += 0x88;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pos = (i * 2048) + j;
|
|
||||||
auto it = current_gfx_.begin() + pos;
|
|
||||||
current_gfx_.emplace(it, mapByte);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
@@ -239,10 +222,22 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) {
|
|||||||
// number of tiles16 3748?
|
// number of tiles16 3748?
|
||||||
for (auto i = 0; i < count; i++) {
|
for (auto i = 0; i < count; i++) {
|
||||||
// 8x8 tile draw, gfx8 = 4bpp so everyting is /2F
|
// 8x8 tile draw, gfx8 = 4bpp so everyting is /2F
|
||||||
auto tiles = tiles16_[i];
|
|
||||||
|
|
||||||
for (auto tile = 0; tile < 4; tile++) {
|
for (auto tile = 0; tile < 4; tile++) {
|
||||||
gfx::TileInfo info = tiles16_[i].tiles_info[tile];
|
gfx::TileInfo info;
|
||||||
|
switch (tile) {
|
||||||
|
case 0:
|
||||||
|
info = tiles16_[i].tile0_;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
info = tiles16_[i].tile1_;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
info = tiles16_[i].tile2_;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
info = tiles16_[i].tile3_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
int offset = offsets[tile];
|
int offset = offsets[tile];
|
||||||
|
|
||||||
for (auto y = 0; y < 8; y++) {
|
for (auto y = 0; y < 8; y++) {
|
||||||
@@ -265,7 +260,7 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) {
|
|||||||
// map,current
|
// 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,
|
||||||
gfx::TileInfo tile) {
|
gfx::TileInfo tile) {
|
||||||
char* all_gfx_data = nullptr;
|
auto map_gfx_data = current_overworld_map_.data();
|
||||||
auto current_gfx_data = current_gfx_.data();
|
auto current_gfx_data = current_gfx_.data();
|
||||||
int mx = x;
|
int mx = x;
|
||||||
int my = y;
|
int my = y;
|
||||||
@@ -285,18 +280,18 @@ void OverworldMap::CopyTile(int x, int y, int xx, int yy, int offset,
|
|||||||
auto pixel = current_gfx_data[tx + (y * 64) + x];
|
auto pixel = current_gfx_data[tx + (y * 64) + x];
|
||||||
|
|
||||||
auto p1 = index + r ^ 1;
|
auto p1 = index + r ^ 1;
|
||||||
all_gfx_data[p1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
map_gfx_data[p1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
||||||
auto p2 = index + r;
|
auto p2 = index + r;
|
||||||
all_gfx_data[p2] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
map_gfx_data[p2] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset) {
|
void OverworldMap::CopyTile8bpp16(int x, int y, int tile) {
|
||||||
// (sourceX * 16) + (sourceY * 0x80)
|
// (sourceX * 16) + (sourceY * 0x80)
|
||||||
int source_ptr_pos = ((tile - ((tile / 8) * 8)) * 16) + ((tile / 8) * 2048);
|
int source_ptr_pos = ((tile - ((tile / 8) * 8)) * 16) + ((tile / 8) * 2048);
|
||||||
auto source_ptr = ow_blockset;
|
auto source_ptr = current_gfx_.data();
|
||||||
|
|
||||||
int dest_ptr_pos = (x + (y * 512));
|
int dest_ptr_pos = (x + (y * 512));
|
||||||
auto dest_ptr = bitmap_.GetData();
|
auto dest_ptr = current_overworld_map_.data();
|
||||||
|
|
||||||
for (int ystrip = 0; ystrip < 16; ystrip++) {
|
for (int ystrip = 0; ystrip < 16; ystrip++) {
|
||||||
for (int xstrip = 0; xstrip < 16; xstrip++) {
|
for (int xstrip = 0; xstrip < 16; xstrip++) {
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ static constexpr int kTileOffsets[] = {0, 8, 4096, 4104};
|
|||||||
|
|
||||||
class OverworldMap {
|
class OverworldMap {
|
||||||
public:
|
public:
|
||||||
OverworldMap(int index, ROM& rom, const std::vector<gfx::Tile16>& tiles16);
|
OverworldMap(int index, ROM& rom, std::vector<gfx::Tile16> & tiles16);
|
||||||
|
|
||||||
absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent,
|
absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent,
|
||||||
const OWBlockset & world_blockset);
|
OWBlockset & world_blockset);
|
||||||
|
|
||||||
auto GetBitmap() const { return bitmap_; }
|
auto GetBitmap() const { return bitmap_; }
|
||||||
auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; }
|
auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; }
|
||||||
@@ -42,7 +42,7 @@ class OverworldMap {
|
|||||||
absl::Status BuildTiles16Gfx(int count);
|
absl::Status BuildTiles16Gfx(int count);
|
||||||
|
|
||||||
void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile);
|
void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile);
|
||||||
void CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset);
|
void CopyTile8bpp16(int x, int y, int tile);
|
||||||
|
|
||||||
int parent_ = 0;
|
int parent_ = 0;
|
||||||
int index_ = 0;
|
int index_ = 0;
|
||||||
@@ -62,6 +62,7 @@ class OverworldMap {
|
|||||||
|
|
||||||
ROM rom_;
|
ROM rom_;
|
||||||
Bytes current_gfx_;
|
Bytes current_gfx_;
|
||||||
|
Bytes current_overworld_map_;
|
||||||
gfx::Bitmap bitmap_;
|
gfx::Bitmap bitmap_;
|
||||||
OWMapTiles map_tiles_;
|
OWMapTiles map_tiles_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user