overworld sprite cleanup

This commit is contained in:
scawful
2024-08-20 13:06:35 -04:00
parent 49611d4944
commit e404eabe64
5 changed files with 101 additions and 116 deletions

View File

@@ -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;
}

View File

@@ -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));
}
}
}

View File

@@ -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