overworld sprite cleanup
This commit is contained in:
@@ -420,8 +420,8 @@ void OverworldEditor::DrawOverworldEdits() {
|
||||
selected_world[index_x][index_y] = current_tile16_;
|
||||
}
|
||||
|
||||
void OverworldEditor::RenderUpdatedMapBitmap(const ImVec2 &click_position,
|
||||
const std::vector<uint8_t> &tile_data) {
|
||||
void OverworldEditor::RenderUpdatedMapBitmap(
|
||||
const ImVec2 &click_position, const std::vector<uint8_t> &tile_data) {
|
||||
// Calculate the tile position relative to the current active map
|
||||
constexpr int tile_size = 16; // Tile size is 16x16 pixels
|
||||
|
||||
@@ -771,7 +771,6 @@ void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
|
||||
for (auto &each : overworld_.entrances()) {
|
||||
if (each.map_id_ < 0x40 + (current_world_ * 0x40) &&
|
||||
each.map_id_ >= (current_world_ * 0x40) && !each.deleted) {
|
||||
// Make this yellow
|
||||
auto color = ImVec4(255, 255, 0, 100);
|
||||
if (each.is_hole_) {
|
||||
color = ImVec4(255, 255, 255, 200);
|
||||
@@ -936,13 +935,24 @@ void OverworldEditor::DrawOverworldItems() {
|
||||
void OverworldEditor::DrawOverworldSprites() {
|
||||
int i = 0;
|
||||
for (auto &sprite : *overworld_.mutable_sprites(game_state_)) {
|
||||
int map_id = sprite.map_id();
|
||||
int map_x = sprite.map_x();
|
||||
int map_y = sprite.map_y();
|
||||
if (!sprite.deleted()) {
|
||||
int map_id = sprite.map_id();
|
||||
// map x and map y are relative to the map
|
||||
// So we need to check if the map is large or small then add the offset
|
||||
|
||||
if (map_id < 0x40 + (current_world_ * 0x40) &&
|
||||
map_id >= (current_world_ * 0x40) && !sprite.deleted()) {
|
||||
ow_map_canvas_.DrawRect(map_x, map_y, 16, 16,
|
||||
// Calculate the superX and superY values
|
||||
int superY = map_id / 8;
|
||||
int superX = map_id % 8;
|
||||
|
||||
// Calculate the map_x and map_y values
|
||||
int map_x = sprite.map_x();
|
||||
int map_y = sprite.map_y();
|
||||
|
||||
// Calculate the actual map_x and map_y values
|
||||
map_x += superX * 512;
|
||||
map_y += superY * 512;
|
||||
|
||||
ow_map_canvas_.DrawRect(map_x, map_y, kTile16Size, kTile16Size,
|
||||
/*magenta*/ ImVec4(255, 0, 255, 150));
|
||||
if (current_mode == EditingMode::SPRITES) {
|
||||
HandleEntityDragging(&sprite, ow_map_canvas_.zero_point(),
|
||||
@@ -955,7 +965,6 @@ void OverworldEditor::DrawOverworldSprites() {
|
||||
current_sprite_ = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
ow_map_canvas_.DrawText(absl::StrFormat("%s", sprite.name()), map_x,
|
||||
map_y);
|
||||
}
|
||||
@@ -1002,7 +1011,8 @@ absl::Status OverworldEditor::LoadGraphics() {
|
||||
// Loop through the tiles and copy their pixel data into separate vectors
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
// Create a new vector for the pixel data of the current tile
|
||||
std::vector<uint8_t> tile_data(16 * 16, 0x00); // More efficient initialization
|
||||
std::vector<uint8_t> tile_data(16 * 16,
|
||||
0x00); // More efficient initialization
|
||||
|
||||
// Copy the pixel data for the current tile into the vector
|
||||
for (int ty = 0; ty < 16; ty++) {
|
||||
|
||||
@@ -178,7 +178,6 @@ class OverworldEditor : public Editor,
|
||||
|
||||
absl::Status UpdateUsageStats();
|
||||
void DrawUsageGrid();
|
||||
|
||||
void DrawDebugWindow();
|
||||
|
||||
auto gfx_group_editor() const { return gfx_group_editor_; }
|
||||
@@ -204,28 +203,16 @@ class OverworldEditor : public Editor,
|
||||
int current_exit_id_ = 0;
|
||||
int current_item_id_ = 0;
|
||||
int current_sprite_id_ = 0;
|
||||
int current_blockset_ = 0;
|
||||
int game_state_ = 1;
|
||||
int current_tile16_ = 0;
|
||||
int selected_tile_ = 0;
|
||||
int current_blockset_ = 0;
|
||||
int selected_entrance_ = 0;
|
||||
int selected_usage_map_ = 0xFFFF;
|
||||
|
||||
char map_gfx_[3] = "";
|
||||
char map_palette_[3] = "";
|
||||
char spr_gfx_[3] = "";
|
||||
char spr_palette_[3] = "";
|
||||
char message_id_[5] = "";
|
||||
char staticgfx[16];
|
||||
|
||||
bool opt_enable_grid = true;
|
||||
bool all_gfx_loaded_ = false;
|
||||
bool map_blockset_loaded_ = false;
|
||||
bool selected_tile_loaded_ = false;
|
||||
bool update_selected_tile_ = true;
|
||||
bool is_dragging_entrance_ = false;
|
||||
bool show_tile16_editor_ = false;
|
||||
bool show_gfx_group_editor_ = false;
|
||||
bool overworld_canvas_fullscreen_ = false;
|
||||
bool middle_mouse_dragging_ = false;
|
||||
bool is_dragging_entity_ = false;
|
||||
|
||||
@@ -223,7 +223,8 @@ void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
||||
world[position_x2][position_y2] = tiles32_unique_[tpos].tile3_;
|
||||
}
|
||||
|
||||
void Overworld::OrganizeMapTiles(std::vector<uint8_t> &bytes, std::vector<uint8_t> &bytes2, int i, int sx,
|
||||
void Overworld::OrganizeMapTiles(std::vector<uint8_t> &bytes,
|
||||
std::vector<uint8_t> &bytes2, int i, int sx,
|
||||
int sy, int &ttpos) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
@@ -487,13 +488,14 @@ absl::Status Overworld::LoadSprites() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Overworld::LoadSpritesFromMap(int sprite_start, int sprite_count,
|
||||
int sprite_index) {
|
||||
for (int i = 0; i < sprite_count; i++) {
|
||||
absl::Status Overworld::LoadSpritesFromMap(int sprites_per_gamestate_ptr,
|
||||
int num_maps_per_gamestate,
|
||||
int game_state) {
|
||||
for (int i = 0; i < num_maps_per_gamestate; i++) {
|
||||
if (map_parent_[i] != i) continue;
|
||||
|
||||
int ptrPos = sprite_start + (i * 2);
|
||||
ASSIGN_OR_RETURN(auto word_addr, rom()->ReadWord(ptrPos));
|
||||
int current_spr_ptr = sprites_per_gamestate_ptr + (i * 2);
|
||||
ASSIGN_OR_RETURN(auto word_addr, rom()->ReadWord(current_spr_ptr));
|
||||
int sprite_address = core::SnesToPc((0x09 << 0x10) | word_addr);
|
||||
while (true) {
|
||||
ASSIGN_OR_RETURN(uint8_t b1, rom()->ReadByte(sprite_address));
|
||||
@@ -502,7 +504,7 @@ absl::Status Overworld::LoadSpritesFromMap(int sprite_start, int sprite_count,
|
||||
if (b1 == 0xFF) break;
|
||||
|
||||
int editor_map_index = i;
|
||||
if (sprite_index != 0) {
|
||||
if (game_state != 0) {
|
||||
if (editor_map_index >= 128)
|
||||
editor_map_index -= 128;
|
||||
else if (editor_map_index >= 64)
|
||||
@@ -513,10 +515,10 @@ absl::Status Overworld::LoadSpritesFromMap(int sprite_start, int sprite_count,
|
||||
|
||||
int realX = ((b2 & 0x3F) * 16) + mapX * 512;
|
||||
int realY = ((b1 & 0x3F) * 16) + mapY * 512;
|
||||
all_sprites_[sprite_index].emplace_back(
|
||||
all_sprites_[game_state].emplace_back(
|
||||
overworld_maps_[i].current_graphics(), (uint8_t)i, b3,
|
||||
(uint8_t)(b2 & 0x3F), (uint8_t)(b1 & 0x3F), realX, realY);
|
||||
// all_sprites_[sprite_index][i].Draw();
|
||||
// all_sprites_[game_state][i].Draw();
|
||||
|
||||
sprite_address += 3;
|
||||
}
|
||||
|
||||
@@ -6,57 +6,13 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace zelda3 {
|
||||
|
||||
void Sprite::InitSprite(const std::vector<uint8_t>& src, uchar mapid, uchar id, uchar x,
|
||||
uchar y, int map_x, int map_y) {
|
||||
current_gfx_ = src;
|
||||
overworld_ = true;
|
||||
map_id_ = static_cast<int>(mapid);
|
||||
id_ = id;
|
||||
this->type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
||||
this->entity_id_ = id;
|
||||
this->x_ = map_x_;
|
||||
this->y_ = map_y_;
|
||||
nx_ = x;
|
||||
ny_ = y;
|
||||
name_ = core::kSpriteDefaultNames[id];
|
||||
map_x_ = map_x;
|
||||
map_y_ = map_y;
|
||||
preview_gfx_.reserve(64 * 64);
|
||||
for (int i = 0; i < 64 * 64; i++) {
|
||||
preview_gfx_.push_back(0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
Sprite::Sprite(std::vector<uint8_t> src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
|
||||
int map_y)
|
||||
: current_gfx_(src),
|
||||
map_id_(static_cast<int>(mapid)),
|
||||
id_(id),
|
||||
nx_(x),
|
||||
ny_(y),
|
||||
map_x_(map_x),
|
||||
map_y_(map_y) {
|
||||
this->type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
||||
this->entity_id_ = id;
|
||||
this->x_ = map_x_;
|
||||
this->y_ = map_y_;
|
||||
current_gfx_ = src;
|
||||
overworld_ = true;
|
||||
|
||||
name_ = core::kSpriteDefaultNames[id];
|
||||
preview_gfx_.reserve(64 * 64);
|
||||
for (int i = 0; i < 64 * 64; i++) {
|
||||
preview_gfx_.push_back(0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::UpdateMapProperties(short map_id) {
|
||||
map_x_ = x_;
|
||||
map_y_ = y_;
|
||||
name_ = core::kSpriteDefaultNames[id_];
|
||||
}
|
||||
|
||||
void Sprite::updateCoordinates(int map_x, int map_y) {
|
||||
void Sprite::UpdateCoordinates(int map_x, int map_y) {
|
||||
map_x_ = map_x;
|
||||
map_y_ = map_y;
|
||||
}
|
||||
@@ -69,8 +25,8 @@ void Sprite::updateBBox() {
|
||||
}
|
||||
|
||||
void Sprite::Draw() {
|
||||
uchar x = nx_;
|
||||
uchar y = ny_;
|
||||
uint8_t x = nx_;
|
||||
uint8_t y = ny_;
|
||||
|
||||
if (overlord_ == 0x07) {
|
||||
if (id_ == 0x1A) {
|
||||
@@ -123,22 +79,22 @@ void Sprite::Draw() {
|
||||
} else if (id_ == 0x02) {
|
||||
DrawSpriteTile((x * 16), (y * 16), 0, 16, 10);
|
||||
} else if (id_ == 0x04) {
|
||||
uchar p = 3;
|
||||
uint8_t p = 3;
|
||||
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
|
||||
} else if (id_ == 0x05) {
|
||||
uchar p = 3;
|
||||
uint8_t p = 3;
|
||||
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
|
||||
} else if (id_ == 0x06) {
|
||||
uchar p = 3;
|
||||
uint8_t p = 3;
|
||||
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
|
||||
} else if (id_ == 0x07) {
|
||||
uchar p = 3;
|
||||
uint8_t p = 3;
|
||||
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
|
||||
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
|
||||
@@ -948,7 +904,7 @@ void Sprite::DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
|
||||
int index = (x) + (y * 64) + (mx + (my * 0x80));
|
||||
|
||||
if (index >= 0 && index <= 4096) {
|
||||
preview_gfx_[index] = (uchar)((pixel & 0x0F) + 112 + (pal * 8));
|
||||
preview_gfx_[index] = (uint8_t)((pixel & 0x0F) + 112 + (pal * 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,42 @@ namespace zelda3 {
|
||||
class Sprite : public OverworldEntity {
|
||||
public:
|
||||
Sprite() = default;
|
||||
Sprite(std::vector<uint8_t> src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
|
||||
int map_y);
|
||||
void InitSprite(const std::vector<uint8_t>& src, uchar mapid, uchar id, uchar x, uchar y,
|
||||
int map_x, int map_y);
|
||||
Sprite(std::vector<uint8_t> src, uint8_t mapid, uint8_t id, uint8_t x,
|
||||
uint8_t y, int map_x, int map_y)
|
||||
: current_gfx_(src),
|
||||
map_id_(static_cast<int>(mapid)),
|
||||
id_(id),
|
||||
nx_(x),
|
||||
ny_(y),
|
||||
map_x_(map_x),
|
||||
map_y_(map_y) {
|
||||
type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
||||
entity_id_ = id;
|
||||
x_ = map_x_;
|
||||
y_ = map_y_;
|
||||
current_gfx_ = src;
|
||||
overworld_ = true;
|
||||
name_ = core::kSpriteDefaultNames[id];
|
||||
preview_gfx_.resize(64 * 64, 0xFF);
|
||||
}
|
||||
|
||||
void InitSprite(const std::vector<uint8_t>& src, uint8_t mapid, uint8_t id,
|
||||
uint8_t x, uint8_t y, int map_x, int map_y) {
|
||||
current_gfx_ = src;
|
||||
overworld_ = true;
|
||||
map_id_ = static_cast<int>(mapid);
|
||||
id_ = id;
|
||||
type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
||||
entity_id_ = id;
|
||||
x_ = map_x_;
|
||||
y_ = map_y_;
|
||||
nx_ = x;
|
||||
ny_ = y;
|
||||
name_ = core::kSpriteDefaultNames[id];
|
||||
map_x_ = map_x;
|
||||
map_y_ = map_y;
|
||||
preview_gfx_.resize(64 * 64, 0xFF);
|
||||
}
|
||||
void updateBBox();
|
||||
|
||||
void Draw();
|
||||
@@ -40,11 +72,11 @@ class Sprite : public OverworldEntity {
|
||||
void UpdateMapProperties(short map_id) override;
|
||||
|
||||
// New methods
|
||||
void updateCoordinates(int map_x, int map_y);
|
||||
void UpdateCoordinates(int map_x, int map_y);
|
||||
|
||||
auto PreviewGraphics() const { return preview_gfx_; }
|
||||
auto id() const { return id_; }
|
||||
auto set_id(uchar id) { id_ = id; }
|
||||
auto set_id(uint8_t id) { id_ = id; }
|
||||
auto x() const { return x_; }
|
||||
auto y() const { return y_; }
|
||||
auto nx() const { return nx_; }
|
||||
@@ -52,6 +84,7 @@ class Sprite : public OverworldEntity {
|
||||
auto map_id() const { return map_id_; }
|
||||
auto map_x() const { return map_x_; }
|
||||
auto map_y() const { return map_y_; }
|
||||
auto game_state() const { return game_state_; }
|
||||
|
||||
auto layer() const { return layer_; }
|
||||
auto subtype() const { return subtype_; }
|
||||
@@ -64,36 +97,33 @@ class Sprite : public OverworldEntity {
|
||||
auto set_deleted(bool deleted) { deleted_ = deleted; }
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> current_gfx_;
|
||||
bool overworld_;
|
||||
|
||||
uchar map_id_;
|
||||
uchar id_;
|
||||
// uchar x_;
|
||||
// uchar y_;
|
||||
uchar nx_;
|
||||
uchar ny_;
|
||||
uchar overlord_ = 0;
|
||||
std::string name_;
|
||||
|
||||
int subtype_;
|
||||
int layer_;
|
||||
|
||||
int map_x_;
|
||||
int map_y_;
|
||||
std::vector<uint8_t> preview_gfx_;
|
||||
uchar lowerX_;
|
||||
uchar lowerY_;
|
||||
uchar higherX_;
|
||||
uchar higherY_;
|
||||
SDL_Rect bounding_box_;
|
||||
uint8_t map_id_;
|
||||
uint8_t game_state_;
|
||||
uint8_t id_;
|
||||
uint8_t nx_;
|
||||
uint8_t ny_;
|
||||
uint8_t overlord_ = 0;
|
||||
uint8_t lowerX_;
|
||||
uint8_t lowerY_;
|
||||
uint8_t higherX_;
|
||||
uint8_t higherY_;
|
||||
|
||||
int width_ = 16;
|
||||
int height_ = 16;
|
||||
|
||||
int map_x_;
|
||||
int map_y_;
|
||||
int layer_;
|
||||
int subtype_;
|
||||
int key_drop_;
|
||||
|
||||
bool deleted_ = false;
|
||||
bool overworld_;
|
||||
|
||||
std::string name_;
|
||||
std::vector<uint8_t> preview_gfx_;
|
||||
std::vector<uint8_t> current_gfx_;
|
||||
|
||||
SDL_Rect bounding_box_;
|
||||
};
|
||||
|
||||
} // namespace zelda3
|
||||
|
||||
Reference in New Issue
Block a user