overworld housekeeping
This commit is contained in:
@@ -182,16 +182,19 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
overworld_map_canvas_.DrawBackground();
|
overworld_map_canvas_.DrawBackground();
|
||||||
overworld_map_canvas_.UpdateContext();
|
overworld_map_canvas_.UpdateContext();
|
||||||
overworld_map_canvas_.DrawGrid(64.f);
|
overworld_map_canvas_.DrawGrid(64.f);
|
||||||
// for (auto &map : overworld_.GetOverworldMaps()) {
|
if (overworld_.isLoaded()) {
|
||||||
// overworld_map_canvas_.GetDrawList()->AddImage(
|
auto map = overworld_.GetOverworldMap(0);
|
||||||
// (void *)map.GetBitmap().GetTexture(),
|
if (map.IsInitialized() && map.IsBuilt()) {
|
||||||
// ImVec2(overworld_map_canvas_.GetZeroPoint().x + 2,
|
overworld_map_canvas_.GetDrawList()->AddImage(
|
||||||
// overworld_map_canvas_.GetZeroPoint().y + 2),
|
(void *)map.GetBitmap().GetTexture(),
|
||||||
// ImVec2(overworld_map_canvas_.GetZeroPoint().x +
|
ImVec2(overworld_map_canvas_.GetZeroPoint().x + 2,
|
||||||
// (map.GetBitmap().GetWidth() * 2),
|
overworld_map_canvas_.GetZeroPoint().y + 2),
|
||||||
// overworld_map_canvas_.GetZeroPoint().y +
|
ImVec2(overworld_map_canvas_.GetZeroPoint().x +
|
||||||
// (map.GetBitmap().GetHeight() * 2)));
|
(map.GetBitmap().GetWidth() * 2),
|
||||||
// }
|
overworld_map_canvas_.GetZeroPoint().y +
|
||||||
|
(map.GetBitmap().GetHeight() * 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
overworld_map_canvas_.DrawOverlay();
|
overworld_map_canvas_.DrawOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class Bitmap {
|
|||||||
int data_size_ = 0;
|
int data_size_ = 0;
|
||||||
bool freed_ = false;
|
bool freed_ = false;
|
||||||
uchar *pixel_data_;
|
uchar *pixel_data_;
|
||||||
|
Bytes data_;
|
||||||
std::shared_ptr<SDL_Texture> texture_;
|
std::shared_ptr<SDL_Texture> texture_;
|
||||||
std::shared_ptr<SDL_Surface> surface_;
|
std::shared_ptr<SDL_Surface> surface_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,62 @@ OverworldMap::OverworldMap(int index, ROM& rom,
|
|||||||
bitmap_.Create(512, 512, 8, 512 * 512);
|
bitmap_.Create(512, 512, 8, 512 * 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
||||||
|
uchar* map_parent,
|
||||||
|
const OWBlockset & world_blockset) {
|
||||||
|
world_ = world;
|
||||||
|
if (large_map_) {
|
||||||
|
parent_ = map_parent[index_];
|
||||||
|
if (parent_ != index_ && !initialized_) {
|
||||||
|
if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) {
|
||||||
|
area_graphics_ =
|
||||||
|
rom_[core::overworldSpecialGFXGroup + (parent_ - 0x80)];
|
||||||
|
area_palette_ = rom_[core::overworldSpecialPALGroup + 1];
|
||||||
|
} else if (index_ == 0x88) {
|
||||||
|
area_graphics_ = 81;
|
||||||
|
area_palette_ = 0;
|
||||||
|
} else {
|
||||||
|
area_graphics_ = rom_[core::mapGfx + parent_];
|
||||||
|
area_palette_ = rom_[core::overworldMapPalette + parent_];
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int world_index = 0x20;
|
||||||
|
if (parent_ < 0x40) {
|
||||||
|
world_index = 0x20;
|
||||||
|
} else if (parent_ >= 0x40 && parent_ < 0x80) {
|
||||||
|
world_index = 0x21;
|
||||||
|
} else if (parent_ == 0x88) {
|
||||||
|
world_index = 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadAreaGraphics(game_state, world_index);
|
||||||
|
auto tileset_status = BuildTileset();
|
||||||
|
if (!tileset_status.ok()) {
|
||||||
|
return tileset_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto map_status = BuildTiles16Gfx(count);
|
||||||
|
if (!map_status.ok()) {
|
||||||
|
return map_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// int superY = ((index_ - (world * 64)) / 8);
|
||||||
|
// int superX = index_ - (world * 64) - (superY * 8);
|
||||||
|
// for (int y = 0; y < 32; y++) {
|
||||||
|
// for (int x = 0; x < 32; x++) {
|
||||||
|
// auto xt = x + (superX * 32);
|
||||||
|
// auto yt = y + (superY * 32);
|
||||||
|
// CopyTile8bpp16((x * 16), (y * 16), map_tiles_[xt][yt], ow_blockset);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
built_ = true;
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
void OverworldMap::LoadAreaInfo() {
|
void OverworldMap::LoadAreaInfo() {
|
||||||
if (index_ != 0x80 && index_ <= 150 &&
|
if (index_ != 0x80 && index_ <= 150 &&
|
||||||
rom_[core::overworldMapSize + (index_ & 0x3F)] != 0) {
|
rom_[core::overworldMapSize + (index_ & 0x3F)] != 0) {
|
||||||
@@ -102,66 +158,7 @@ void OverworldMap::LoadAreaInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildMap(int count, int game_state,
|
void OverworldMap::LoadAreaGraphics(int game_state, int world_index) {
|
||||||
uchar* map_parent) {
|
|
||||||
if (large_map_) {
|
|
||||||
parent_ = map_parent[index_];
|
|
||||||
if (parent_ != index_ && !initialized_) {
|
|
||||||
if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) {
|
|
||||||
area_graphics_ =
|
|
||||||
rom_[core::overworldSpecialGFXGroup + (parent_ - 0x80)];
|
|
||||||
area_palette_ = rom_[core::overworldSpecialPALGroup + 1];
|
|
||||||
} else if (index_ == 0x88) {
|
|
||||||
area_graphics_ = 81;
|
|
||||||
area_palette_ = 0;
|
|
||||||
} else {
|
|
||||||
area_graphics_ = rom_[core::mapGfx + parent_];
|
|
||||||
area_palette_ = rom_[core::overworldMapPalette + parent_];
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto tileset_status = BuildTileset(game_state);
|
|
||||||
if (!tileset_status.ok()) {
|
|
||||||
return tileset_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// int world = 0;
|
|
||||||
// if (index_ < 64) {
|
|
||||||
// map_tiles_ = map_tiles.light_world;
|
|
||||||
// } else if (index_ < 0x80 && index_ >= 0x40) {
|
|
||||||
// map_tiles_ = map_tiles.dark_world;
|
|
||||||
// world = 1;
|
|
||||||
// } else {
|
|
||||||
// map_tiles_ = map_tiles.special_world;
|
|
||||||
// world = 2;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int superY = ((index_ - (world * 64)) / 8);
|
|
||||||
// int superX = index_ - (world * 64) - (superY * 8);
|
|
||||||
// for (int y = 0; y < 32; y++) {
|
|
||||||
// for (int x = 0; x < 32; x++) {
|
|
||||||
// auto xt = x + (superX * 32);
|
|
||||||
// auto yt = y + (superY * 32);
|
|
||||||
// CopyTile8bpp16((x * 16), (y * 16), map_tiles_[xt][yt], ow_blockset);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildTileset(int game_state) {
|
|
||||||
int index_world = 0x20;
|
|
||||||
if (parent_ < 0x40) {
|
|
||||||
index_world = 0x20;
|
|
||||||
} else if (parent_ >= 0x40 && parent_ < 0x80) {
|
|
||||||
index_world = 0x21;
|
|
||||||
} else if (parent_ == 0x88) {
|
|
||||||
index_world = 36;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprites Blocksets
|
// Sprites Blocksets
|
||||||
static_graphics_[8] = 115 + 0;
|
static_graphics_[8] = 115 + 0;
|
||||||
static_graphics_[9] = 115 + 1;
|
static_graphics_[9] = 115 + 1;
|
||||||
@@ -176,7 +173,7 @@ absl::Status OverworldMap::BuildTileset(int game_state) {
|
|||||||
// Main Blocksets
|
// Main Blocksets
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
static_graphics_[i] =
|
static_graphics_[i] =
|
||||||
rom_[core::overworldgfxGroups2 + (index_world * 8) + i];
|
rom_[core::overworldgfxGroups2 + (world_index * 8) + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rom_[core::overworldgfxGroups + (area_graphics_ * 4)] != 0) {
|
if (rom_[core::overworldgfxGroups + (area_graphics_ * 4)] != 0) {
|
||||||
@@ -205,17 +202,43 @@ absl::Status OverworldMap::BuildTileset(int game_state) {
|
|||||||
} else {
|
} else {
|
||||||
static_graphics_[7] = 91;
|
static_graphics_[7] = 91;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// all gfx of the game pack of 2048 bytes (4bpp)
|
||||||
|
char* allgfxData = nullptr;
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status OverworldMap::BuildTiles16Gfx(int count) {
|
absl::Status OverworldMap::BuildTiles16Gfx(int count) {
|
||||||
auto gfx_tile8_data = nullptr; // rom_.GetMasterGraphicsBin();
|
|
||||||
|
|
||||||
int offsets[] = {0, 8, 1024, 1032};
|
int offsets[] = {0, 8, 1024, 1032};
|
||||||
auto yy = 0;
|
auto yy = 0;
|
||||||
auto xx = 0;
|
auto xx = 0;
|
||||||
@@ -229,12 +252,11 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) {
|
|||||||
gfx::TileInfo info = tiles16_[i].tiles_info[tile];
|
gfx::TileInfo info = tiles16_[i].tiles_info[tile];
|
||||||
int offset = offsets[tile];
|
int offset = offsets[tile];
|
||||||
|
|
||||||
// for (auto y = 0; y < 8; y++) {
|
for (auto y = 0; y < 8; y++) {
|
||||||
// for (auto x = 0; x < 4; x++) {
|
for (auto x = 0; x < 4; x++) {
|
||||||
// CopyTile(x, y, xx, yy, offset, info, gfx_tile16_data,
|
CopyTile(x, y, xx, yy, offset, info);
|
||||||
// gfx_tile8_data);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xx += 16;
|
xx += 16;
|
||||||
@@ -249,8 +271,9 @@ 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, uchar* gfx16Pointer,
|
gfx::TileInfo tile) {
|
||||||
uchar* gfx8Pointer) {
|
char* all_gfx_data = nullptr;
|
||||||
|
auto current_gfx_data = current_gfx_.data();
|
||||||
int mx = x;
|
int mx = x;
|
||||||
int my = y;
|
int my = y;
|
||||||
uchar r = 0;
|
uchar r = 0;
|
||||||
@@ -266,10 +289,12 @@ 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 * 0x80);
|
auto index = xx + yy + offset + (mx * 2) + (my * 0x80);
|
||||||
auto pixel = gfx8Pointer[tx + (y * 64) + x];
|
auto pixel = current_gfx_data[tx + (y * 64) + x];
|
||||||
|
|
||||||
gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
auto p1 = index + r ^ 1;
|
||||||
gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
all_gfx_data[p1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16);
|
||||||
|
auto p2 = index + r;
|
||||||
|
all_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, uchar* ow_blockset) {
|
||||||
|
|||||||
@@ -24,22 +24,24 @@ class OverworldMap {
|
|||||||
public:
|
public:
|
||||||
OverworldMap(int index, ROM& rom, const std::vector<gfx::Tile16>& tiles16);
|
OverworldMap(int index, ROM& rom, const std::vector<gfx::Tile16>& tiles16);
|
||||||
|
|
||||||
absl::Status BuildMap(int count, int game_state, uchar* map_parent);
|
absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent,
|
||||||
|
const OWBlockset & world_blockset);
|
||||||
|
|
||||||
auto GetBitmap() { return bitmap_; }
|
auto GetBitmap() const { return bitmap_; }
|
||||||
auto GetCurrentGraphicsSet() { return current_graphics_sheet_set; }
|
auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; }
|
||||||
auto SetLargeMap(bool is_set) { large_map_ = is_set; }
|
auto SetLargeMap(bool is_set) { large_map_ = is_set; }
|
||||||
auto IsLargeMap() { return large_map_; }
|
auto IsLargeMap() const { return large_map_; }
|
||||||
|
auto IsInitialized() const { return initialized_; }
|
||||||
|
auto IsBuilt() const { return built_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadAreaInfo();
|
void LoadAreaInfo();
|
||||||
|
void LoadAreaGraphics(int game_state, int world_index);
|
||||||
|
|
||||||
absl::Status BuildTileset(int game_state);
|
absl::Status BuildTileset();
|
||||||
absl::Status BuildTiles16Gfx(int count);
|
absl::Status BuildTiles16Gfx(int count);
|
||||||
|
|
||||||
// TODO: Find the SDL_Surface way to do this.
|
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,
|
|
||||||
uchar* gfx16Pointer, uchar* gfx8Pointer);
|
|
||||||
void CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset);
|
void CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset);
|
||||||
|
|
||||||
int parent_ = 0;
|
int parent_ = 0;
|
||||||
@@ -55,12 +57,13 @@ class OverworldMap {
|
|||||||
uchar static_graphics_[16];
|
uchar static_graphics_[16];
|
||||||
|
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
bool built_ = false;
|
||||||
bool large_map_ = false;
|
bool large_map_ = false;
|
||||||
|
|
||||||
ROM rom_;
|
ROM rom_;
|
||||||
OWMapTiles map_tiles_;
|
Bytes current_gfx_;
|
||||||
|
|
||||||
gfx::Bitmap bitmap_;
|
gfx::Bitmap bitmap_;
|
||||||
|
OWMapTiles map_tiles_;
|
||||||
|
|
||||||
std::vector<gfx::Tile16> tiles16_;
|
std::vector<gfx::Tile16> tiles16_;
|
||||||
absl::flat_hash_map<int, gfx::Bitmap> current_graphics_sheet_set;
|
absl::flat_hash_map<int, gfx::Bitmap> current_graphics_sheet_set;
|
||||||
|
|||||||
Reference in New Issue
Block a user