Begin LoadSprites, LoadChests, housekeeping

This commit is contained in:
scawful
2023-06-25 10:08:01 -04:00
parent 7d1dad3975
commit 3ada9988aa
18 changed files with 301 additions and 210 deletions

View File

@@ -190,7 +190,7 @@ absl::Status Controller::CreateRenderer() {
return absl::OkStatus(); return absl::OkStatus();
} }
absl::Status Controller::CreateGuiContext() { absl::Status Controller::CreateGuiContext() const {
ImGui::CreateContext(); ImGui::CreateContext();
// Initialize ImGui for SDL // Initialize ImGui for SDL

View File

@@ -38,7 +38,7 @@ class Controller {
absl::Status CreateWindow(); absl::Status CreateWindow();
absl::Status CreateRenderer(); absl::Status CreateRenderer();
absl::Status CreateGuiContext(); absl::Status CreateGuiContext() const;
void CloseWindow() { active_ = false; } void CloseWindow() { active_ = false; }
friend int ::main(int argc, char **argv); friend int ::main(int argc, char **argv);

View File

@@ -14,11 +14,11 @@
#include "app/editor/overworld_editor.h" #include "app/editor/overworld_editor.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/gui/widgets.h" #include "app/gui/widgets.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -54,22 +54,6 @@ bool BeginCentered(const char *name) {
return ImGui::Begin(name, nullptr, flags); return ImGui::Begin(name, nullptr, flags);
} }
void DisplayStatus(absl::Status &status) {
if (BeginCentered("StatusWindow")) {
ImGui::Text("%s", status.ToString().c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
if (ImGui::Button("OK", ImVec2(200, 0))) {
status = absl::OkStatus();
}
ImGui::End();
}
}
} // namespace } // namespace
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) { void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
@@ -114,7 +98,24 @@ void MasterEditor::DrawFileDialog() {
void MasterEditor::DrawStatusPopup() { void MasterEditor::DrawStatusPopup() {
if (!status_.ok()) { if (!status_.ok()) {
DisplayStatus(status_); show_status_ = true;
prev_status_ = status_;
}
if (show_status_) {
if (BeginCentered("StatusWindow")) {
ImGui::Text("%s", prev_status_.ToString().c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
if (ImGui::Button("OK", ImVec2(200, 0))) {
show_status_ = false;
}
ImGui::End();
}
} }
} }
@@ -167,23 +168,13 @@ void MasterEditor::DrawFileMenu() {
".sfc,.smc", "."); ".sfc,.smc", ".");
} }
MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(true); } MENU_ITEM2("Save", "Ctrl+S") { status_ = rom_.SaveToFile(backup_rom_); }
MENU_ITEM("Save As..") {} MENU_ITEM("Save As..") {}
ImGui::Separator(); ImGui::Separator();
// TODO: Make these options matter
if (ImGui::BeginMenu("Options")) { if (ImGui::BeginMenu("Options")) {
static bool enabled = true; ImGui::MenuItem("Backup ROM", "", &backup_rom_);
ImGui::MenuItem("Enabled", "", &enabled);
ImGui::BeginChild("child", ImVec2(0, 60), true);
for (int i = 0; i < 10; i++) ImGui::Text("Scrolling Text %d", i);
ImGui::EndChild();
static float f = 0.5f;
static int n = 0;
ImGui::SliderFloat("Value", &f, 0.0f, 1.0f);
ImGui::InputFloat("Input", &f, 0.1f);
ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0");
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::EndMenu(); ImGui::EndMenu();

View File

@@ -52,9 +52,12 @@ class MasterEditor {
bool about_ = false; bool about_ = false;
bool rom_info_ = false; bool rom_info_ = false;
bool backup_rom_ = true;
bool show_status_ = false;
std::shared_ptr<SDL_Renderer> sdl_renderer_; std::shared_ptr<SDL_Renderer> sdl_renderer_;
absl::Status status_; absl::Status status_;
absl::Status prev_status_;
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
DungeonEditor dungeon_editor_; DungeonEditor dungeon_editor_;

View File

@@ -13,10 +13,10 @@
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -88,8 +88,8 @@ void OverworldEditor::DrawOverworldMapSettings() {
ImGui::TableSetupColumn(name.data()); ImGui::TableSetupColumn(name.data());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::SetNextItemWidth(50.f); ImGui::SetNextItemWidth(100.f);
ImGui::InputInt("Current Map", &current_map_); ImGui::Combo("##world", &game_state_, "Part 0\0Part 1\0Part 2\0");
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::SetNextItemWidth(100.f); ImGui::SetNextItemWidth(100.f);
@@ -161,7 +161,25 @@ void OverworldEditor::DrawOverworldMaps() {
yy++; yy++;
xx = 0; xx = 0;
} }
DrawOverworldEntrances(); }
}
// ----------------------------------------------------------------------------
void OverworldEditor::DrawOverworldSprites() {
for (const auto &sprite : overworld_.Sprites(game_state_)) {
// Get the sprite's bitmap and real X and Y positions
auto id = sprite.id();
const gfx::Bitmap &sprite_bitmap = sprite_previews_[id];
int realX = sprite.GetRealX();
int realY = sprite.GetRealY();
// Draw the sprite's bitmap onto the canvas at its real X and Y positions
ow_map_canvas_.DrawBitmap(sprite_bitmap, realX, realY);
ow_map_canvas_.DrawRect(realX, realY, sprite.Width(), sprite.Height(),
ImVec4(255, 0, 0, 150));
std::string str = absl::StrFormat("%s", sprite.Name());
ow_map_canvas_.DrawText(str, realX - 4, realY - 2);
} }
} }
@@ -192,6 +210,8 @@ void OverworldEditor::DrawOverworldCanvas() {
ow_map_canvas_.DrawContextMenu(); ow_map_canvas_.DrawContextMenu();
if (overworld_.isLoaded()) { if (overworld_.isLoaded()) {
DrawOverworldMaps(); DrawOverworldMaps();
DrawOverworldEntrances();
DrawOverworldSprites();
// User has selected a tile they want to draw from the blockset. // User has selected a tile they want to draw from the blockset.
if (!blockset_canvas_.Points().empty()) { if (!blockset_canvas_.Points().empty()) {
int x = blockset_canvas_.Points().front().x / 32; int x = blockset_canvas_.Points().front().x / 32;
@@ -358,6 +378,18 @@ absl::Status OverworldEditor::LoadGraphics() {
rom_.RenderBitmap(&(maps_bmp_[i])); rom_.RenderBitmap(&(maps_bmp_[i]));
} }
// Render the sprites for each Overworld map
// for (int i = 0; i < 3; i++)
// for (auto &sprite : overworld_.Sprites(i)) {
// int width = sprite.Width();
// int height = sprite.Height();
// int depth = 0x40;
// auto spr_gfx = sprite.PreviewGraphics().data();
// sprite_previews_[sprite.id()].Create(width, height, depth, spr_gfx);
// sprite_previews_[sprite.id()].ApplyPalette(palette_);
// rom_.RenderBitmap(&(sprite_previews_[sprite.id()]));
// }
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -14,10 +14,11 @@
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/rom.h"
#include "app/zelda3/overworld.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -56,6 +57,7 @@ class OverworldEditor {
void DrawOverworldEntrances(); void DrawOverworldEntrances();
void DrawOverworldMaps(); void DrawOverworldMaps();
void DrawOverworldSprites();
void DrawOverworldEdits(); void DrawOverworldEdits();
void DrawOverworldCanvas(); void DrawOverworldCanvas();
@@ -69,6 +71,7 @@ class OverworldEditor {
int current_map_ = 0; int current_map_ = 0;
int current_tile16_ = 0; int current_tile16_ = 0;
int selected_tile_ = 0; int selected_tile_ = 0;
int game_state_ = 0;
char map_gfx_[3] = ""; char map_gfx_[3] = "";
char map_palette_[3] = ""; char map_palette_[3] = "";
char spr_gfx_[3] = ""; char spr_gfx_[3] = "";

View File

@@ -40,6 +40,16 @@ using namespace ImGui;
} // namespace } // namespace
absl::Status PaletteEditor::Update() {
for (int i = 0; i < kNumPalettes; ++i) {
if (ImGui::TreeNode(kPaletteCategoryNames[i].data())) {
DrawPaletteGroup(i);
ImGui::TreePop();
}
}
return absl::OkStatus();
}
void PaletteEditor::DrawPaletteGroup(int i) { void PaletteEditor::DrawPaletteGroup(int i) {
auto size = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()).size(); auto size = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()).size();
auto palettes = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()); auto palettes = rom_.GetPaletteGroup(kPaletteGroupNames[i].data());
@@ -61,7 +71,7 @@ void PaletteEditor::DrawPaletteGroup(int i) {
palette_button_flags)) palette_button_flags))
current_color_ = current_color_ =
ImVec4(palette[n].rgb.x, palette[n].rgb.y, palette[n].rgb.z, ImVec4(palette[n].rgb.x, palette[n].rgb.y, palette[n].rgb.z,
palette[n].rgb.w); // Preserve alpha! palette[n].rgb.w); // Prese rve alpha!
} }
if (ImGui::BeginPopupContextItem(popupId.c_str())) { if (ImGui::BeginPopupContextItem(popupId.c_str())) {
@@ -69,11 +79,8 @@ void PaletteEditor::DrawPaletteGroup(int i) {
if (ImGui::ColorEdit4( if (ImGui::ColorEdit4(
"Edit Color", col, "Edit Color", col,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha)) { ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha)) {
// palette[n].rgb.x = current_color_rgba.x; rom_.UpdatePaletteColor(kPaletteGroupNames[i].data(), j, n,
// palette[n].rgb.y = current_color_rgba.y; palette[n]);
// palette[n].rgb.z = current_color_rgba.z;
// rom_.UpdatePaletteColor(kPaletteGroupNames[groupIndex].data(), j,
// n, palette[n]);
} }
if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy"); if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy");
if (BeginPopup("Copy")) { if (BeginPopup("Copy")) {
@@ -100,16 +107,6 @@ void PaletteEditor::DrawPaletteGroup(int i) {
} }
} }
absl::Status PaletteEditor::Update() {
for (int i = 0; i < kNumPalettes; ++i) {
if (ImGui::TreeNode(kPaletteCategoryNames[i].data())) {
DrawPaletteGroup(i);
ImGui::TreePop();
}
}
return absl::OkStatus();
}
void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) { void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
static ImVec4 color = ImVec4(0, 0, 0, 255.f); static ImVec4 color = ImVec4(0, 0, 0, 255.f);
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
@@ -150,7 +147,6 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
ImGui::Text("Previous"); ImGui::Text("Previous");
if (ImGui::Button("Update Map Palette")) { if (ImGui::Button("Update Map Palette")) {
} }
ImGui::ColorButton( ImGui::ColorButton(
@@ -165,7 +161,7 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) {
ImVec2(60, 40))) ImVec2(60, 40)))
color = backup_color; color = backup_color;
// List of Colors in Overworld Palette // List of Colors in Overworld Palette
ImGui::Separator(); ImGui::Separator();
ImGui::Text("Palette"); ImGui::Text("Palette");
for (int n = 0; n < IM_ARRAYSIZE(saved_palette_); n++) { for (int n = 0; n < IM_ARRAYSIZE(saved_palette_); n++) {

View File

@@ -49,7 +49,7 @@ struct SNESColor {
auto RGB() { return ImVec4(rgb.x / 255, rgb.y / 255, rgb.z / 255, rgb.w); } auto RGB() { return ImVec4(rgb.x / 255, rgb.y / 255, rgb.z / 255, rgb.w); }
float* ToFloatArray() const { float* ToFloatArray() {
static std::vector<float> colorArray(4); static std::vector<float> colorArray(4);
colorArray[0] = rgb.x / 255.0f; colorArray[0] = rgb.x / 255.0f;
colorArray[1] = rgb.y / 255.0f; colorArray[1] = rgb.y / 255.0f;
@@ -86,6 +86,26 @@ class SNESPalette {
return colors[i]; return colors[i];
} }
void operator()(int i, const SNESColor& color) {
if (i >= size_) {
std::cout << "SNESPalette: Index out of bounds" << std::endl;
return;
}
colors[i] = color;
}
void operator()(int i, const ImVec4& color) {
if (i >= size_) {
std::cout << "SNESPalette: Index out of bounds" << std::endl;
return;
}
colors[i].rgb.x = color.x;
colors[i].rgb.y = color.y;
colors[i].rgb.z = color.z;
colors[i].rgb.w = color.w;
colors[i].modified = true;
}
char* encode(); char* encode();
SDL_Palette* GetSDL_Palette(); SDL_Palette* GetSDL_Palette();

View File

@@ -538,7 +538,7 @@ absl::StatusOr<Bytes> ROM::Decompress(int offset, int size, int mode) {
} break; } break;
case kCommandRepeatingBytes: { case kCommandRepeatingBytes: {
ushort s1 = ((rom_data_[offset + 1] & kSnesByteMax) << 8); ushort s1 = ((rom_data_[offset + 1] & kSnesByteMax) << 8);
ushort s2 = ((rom_data_[offset] & kSnesByteMax)); ushort s2 = (rom_data_[offset] & kSnesByteMax);
int addr = (s1 | s2); int addr = (s1 | s2);
if (mode == kNintendoMode1) { // Reversed byte order for overworld maps if (mode == kNintendoMode1) { // Reversed byte order for overworld maps
addr = (rom_data_[offset + 1] & kSnesByteMax) | addr = (rom_data_[offset + 1] & kSnesByteMax) |
@@ -766,6 +766,35 @@ void ROM::LoadAllPalettes() {
// ============================================================================ // ============================================================================
void ROM::UpdatePaletteColor(const std::string& groupName, size_t paletteIndex,
size_t colorIndex,
const gfx::SNESColor& newColor) {
// Check if the groupName exists in the palette_groups_ map
if (palette_groups_.find(groupName) != palette_groups_.end()) {
// Check if the paletteIndex is within the range of available palettes in
// the group
if (paletteIndex < palette_groups_[groupName].size()) {
// Check if the colorIndex is within the range of available colors in the
// palette
if (colorIndex < palette_groups_[groupName][paletteIndex].size()) {
// Update the color value in the palette
palette_groups_[groupName][paletteIndex][colorIndex] = newColor;
} else {
std::cerr << "Error: Invalid color index in UpdatePaletteColor."
<< std::endl;
}
} else {
std::cerr << "Error: Invalid palette index in UpdatePaletteColor."
<< std::endl;
}
} else {
std::cerr << "Error: Invalid group name in UpdatePaletteColor."
<< std::endl;
}
}
// ============================================================================
void ROM::SaveAllPalettes() { void ROM::SaveAllPalettes() {
// Iterate through all palette_groups_ // Iterate through all palette_groups_
for (auto& [groupName, palettes] : palette_groups_) { for (auto& [groupName, palettes] : palette_groups_) {
@@ -776,7 +805,6 @@ void ROM::SaveAllPalettes() {
// Iterate through all colors in the palette // Iterate through all colors in the palette
for (size_t j = 0; j < palette.size(); ++j) { for (size_t j = 0; j < palette.size(); ++j) {
gfx::SNESColor color = palette[j]; gfx::SNESColor color = palette[j];
// If the color is modified, save the color to the ROM // If the color is modified, save the color to the ROM
if (color.modified) { if (color.modified) {
WriteColor(GetPaletteAddress(groupName, i, j), color); WriteColor(GetPaletteAddress(groupName, i, j), color);
@@ -790,6 +818,10 @@ void ROM::SaveAllPalettes() {
// ============================================================================ // ============================================================================
absl::Status ROM::SaveToFile(bool backup) { absl::Status ROM::SaveToFile(bool backup) {
if (rom_data_.empty()) {
return absl::InternalError("ROM data is empty.");
}
// Check if backup is enabled // Check if backup is enabled
if (backup) { if (backup) {
// Create a backup file with timestamp in its name // Create a backup file with timestamp in its name

View File

@@ -26,6 +26,7 @@
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#define BUILD_HEADER(command, length) (command << 5) + (length - 1) #define BUILD_HEADER(command, length) (command << 5) + (length - 1)
@@ -137,7 +138,10 @@ class ROM {
absl::Status LoadFromBytes(const Bytes& data); absl::Status LoadFromBytes(const Bytes& data);
void LoadAllPalettes(); void LoadAllPalettes();
// Save functions
absl::Status SaveToFile(bool backup); absl::Status SaveToFile(bool backup);
void UpdatePaletteColor(const std::string& groupName, size_t paletteIndex,
size_t colorIndex, const gfx::SNESColor& newColor);
void SaveAllPalettes(); void SaveAllPalettes();
gfx::SNESColor ReadColor(int offset); gfx::SNESColor ReadColor(int offset);
@@ -157,6 +161,7 @@ class ROM {
gfx::BitmapTable GetGraphicsBin() const { return graphics_bin_; } gfx::BitmapTable GetGraphicsBin() const { return graphics_bin_; }
auto GetGraphicsBuffer() const { return graphics_buffer_; } auto GetGraphicsBuffer() const { return graphics_buffer_; }
auto GetPaletteGroup(const std::string& group) { auto GetPaletteGroup(const std::string& group) {
return palette_groups_[group]; return palette_groups_[group];
} }

View File

@@ -4,8 +4,8 @@
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -74,7 +74,22 @@ bool Room::SaveGroupsToROM() {
return false; return false;
} }
void Room::LoadChests() {} void Room::LoadChests() {
// ChestList.Clear();
// int cpos = rom_.Read24(core::constants::chests_data_pointer1).SNEStoPC();
// int clength = rom_.Read16(core::constants::chests_length_pointer);
// for (int i = 0; i < clength; i += 3) {
// ushort roomid = (ushort)(rom_.Read16(cpos) & 0x7FFF);
// cpos += 2;
// uchar item = rom_[cpos++]; // get now so cpos is incremented too
// if (roomid == RoomID) {
// ChestList.Add(new DungeonChestItem(ItemReceipt.GetTypeFromID(item)));
// }
// }
}
void Room::LoadBlocks() {} void Room::LoadBlocks() {}

View File

@@ -2,11 +2,12 @@
#define YAZE_APP_ZELDA3_DUNGEON_ROOM_H #define YAZE_APP_ZELDA3_DUNGEON_ROOM_H
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -122,6 +123,7 @@ class Room {
uchar Floor2Graphics; uchar Floor2Graphics;
uchar Layer2Mode; uchar Layer2Mode;
std::array<uchar, 16> blocks; std::array<uchar, 16> blocks;
std::array<uchar, 16> ChestList;
uint8_t mainGfx[37][8]; uint8_t mainGfx[37][8];
uint8_t roomGfx[82][4]; uint8_t roomGfx[82][4];

View File

@@ -39,7 +39,6 @@ absl::Status Overworld::Load(ROM &rom) {
FetchLargeMaps(); FetchLargeMaps();
LoadEntrances(); LoadEntrances();
LoadSprites();
auto size = tiles16.size(); auto size = tiles16.size();
std::vector<std::future<absl::Status>> futures; std::vector<std::future<absl::Status>> futures;
@@ -66,6 +65,8 @@ absl::Status Overworld::Load(ROM &rom) {
} }
} }
LoadSprites();
is_loaded_ = true; is_loaded_ = true;
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -555,107 +556,60 @@ void Overworld::LoadEntrances() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void Overworld::LoadSprites() { void Overworld::LoadSprites() {
// LW[0] = RainState 0 to 63 there's no data for DW
// LW[1] = ZeldaState 0 to 128 ; Contains LW and DW <128 or 144 wtf
// LW[2] = AgahState 0 to ?? ;Contains data for LW and DW
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
all_sprites_.emplace_back(std::vector<Sprite>()); all_sprites_.emplace_back();
} }
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if (map_parent_[i] == i) { all_sprites_[0].emplace_back();
// Beginning Sprites
int ptrPos = core::overworldSpritesBegining + (i * 2);
int spriteAddress = core::SnesToPc((0x09 << 0x10) + rom_.toint16(ptrPos));
while (true) {
uchar b1 = rom_[spriteAddress];
uchar b2 = rom_[spriteAddress + 1];
uchar b3 = rom_[spriteAddress + 2];
if (b1 == 0xFF) {
break;
}
int mapY = (i / 8);
int mapX = (i % 8);
int realX = ((b2 & 0x3F) * 16) + mapX * 512;
int realY = ((b1 & 0x3F) * 16) + mapY * 512;
all_sprites_[0].emplace_back(overworld_maps_[i].AreaGraphics(),
(uchar)i, b3, (uchar)(b2 & 0x3F),
(uchar)(b1 & 0x3F), realX, realY);
spriteAddress += 3;
}
}
} }
for (int i = 0; i < 144; i++) { for (int i = 0; i < 144; i++) {
if (map_parent_[i] == i) { all_sprites_[1].emplace_back();
// Zelda Saved Sprites }
int ptrPos = core::overworldSpritesZelda + (i * 2);
int spriteAddress = core::SnesToPc((0x09 << 0x10) + rom_.toint16(ptrPos));
while (true) {
uchar b1 = rom_[spriteAddress];
uchar b2 = rom_[spriteAddress + 1];
uchar b3 = rom_[spriteAddress + 2];
if (b1 == 0xFF) {
break;
}
int editorMapIndex = i; for (int i = 0; i < 144; i++) {
if (editorMapIndex >= 128) { all_sprites_[2].emplace_back();
editorMapIndex = i - 128; }
} else if (editorMapIndex >= 64) {
editorMapIndex = i - 64;
}
int mapY = (editorMapIndex / 8); LoadSpritesFromMap(core::overworldSpritesBegining, 64, 0);
int mapX = (editorMapIndex % 8); LoadSpritesFromMap(core::overworldSpritesZelda, 144, 1);
LoadSpritesFromMap(core::overworldSpritesAgahnim, 144, 2);
}
int realX = ((b2 & 0x3F) * 16) + mapX * 512; // ----------------------------------------------------------------------------
int realY = ((b1 & 0x3F) * 16) + mapY * 512;
all_sprites_[1].emplace_back(overworld_maps_[i].AreaGraphics(), void Overworld::LoadSpritesFromMap(int spriteStart, int spriteCount,
(uchar)i, b3, (uchar)(b2 & 0x3F), int spriteIndex) {
(uchar)(b1 & 0x3F), realX, realY); for (int i = 0; i < spriteCount; i++) {
if (map_parent_[i] != i) continue;
spriteAddress += 3; int ptrPos = spriteStart + (i * 2);
} int spriteAddress = core::SnesToPc((0x09 << 0x10) + rom_.toint16(ptrPos));
} while (true) {
uchar b1 = rom_[spriteAddress];
uchar b2 = rom_[spriteAddress + 1];
uchar b3 = rom_[spriteAddress + 2];
if (b1 == 0xFF) break;
// Agahnim Dead Sprites int editorMapIndex = i;
if (map_parent_[i] == i) { if (editorMapIndex >= 128)
int ptrPos = core::overworldSpritesAgahnim + (i * 2); editorMapIndex -= 128;
int spriteAddress = core::SnesToPc((0x09 << 0x10) + rom_.toint16(ptrPos)); else if (editorMapIndex >= 64)
while (true) { editorMapIndex -= 64;
uchar b1 = rom_[spriteAddress];
uchar b2 = rom_[spriteAddress + 1];
uchar b3 = rom_[spriteAddress + 2];
if (b1 == 0xFF) {
break;
}
int editorMapIndex = i; int mapY = (editorMapIndex / 8);
if (editorMapIndex >= 128) { int mapX = (editorMapIndex % 8);
editorMapIndex = i - 128;
} else if (editorMapIndex >= 64) {
editorMapIndex = i - 64;
}
int mapY = (editorMapIndex / 8); int realX = ((b2 & 0x3F) * 16) + mapX * 512;
int mapX = (editorMapIndex % 8); int realY = ((b1 & 0x3F) * 16) + mapY * 512;
auto graphics_bytes = overworld_maps_[i].AreaGraphics();
all_sprites_[spriteIndex][i].InitSprite(graphics_bytes, (uchar)i, b3,
(uchar)(b2 & 0x3F),
(uchar)(b1 & 0x3F), realX, realY);
all_sprites_[spriteIndex][i].Draw();
int realX = ((b2 & 0x3F) * 16) + mapX * 512; spriteAddress += 3;
int realY = ((b1 & 0x3F) * 16) + mapY * 512;
all_sprites_[2].emplace_back(overworld_maps_[i].AreaGraphics(),
(uchar)i, b3, (uchar)(b2 & 0x3F),
(uchar)(b1 & 0x3F), realX, realY);
spriteAddress += 3;
}
} }
} }
} }

View File

@@ -3,9 +3,9 @@
#include <SDL.h> #include <SDL.h>
#include <future>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <future>
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/constants.h" #include "app/core/constants.h"
@@ -78,7 +78,7 @@ class Overworld {
auto GetTiles16() const { return tiles16; } auto GetTiles16() const { return tiles16; }
auto GetOverworldMap(uint index) { return overworld_maps_[index]; } auto GetOverworldMap(uint index) { return overworld_maps_[index]; }
auto GetOverworldMaps() const { return overworld_maps_; } auto GetOverworldMaps() const { return overworld_maps_; }
auto Sprites() const { return all_sprites_[game_state_]; } auto Sprites(int state) const { return all_sprites_[state]; }
auto AreaGraphics() const { auto AreaGraphics() const {
return overworld_maps_[current_map_].AreaGraphics(); return overworld_maps_[current_map_].AreaGraphics();
} }
@@ -115,6 +115,7 @@ class Overworld {
void FetchLargeMaps(); void FetchLargeMaps();
void LoadEntrances(); void LoadEntrances();
void LoadSprites(); void LoadSprites();
void LoadSpritesFromMap(int spriteStart, int spriteCount, int spriteIndex);
void LoadOverworldMap(); void LoadOverworldMap();

View File

@@ -109,8 +109,8 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
k = 0; k = 0;
for (int y = 9; y < 13; y++) { for (int y = 9; y < 13; y++) {
for (int x = 1; x < 16; x++) { for (int x = 1; x < 16; x++) {
new_palette[x + (16 * y)] = new_palette[x + (16 * y)] = rom.GetPaletteGroup("global_sprites")[0][k];
rom.GetPaletteGroup("global_sprites")[0][k]; k++; k++;
} }
} }

View File

@@ -12,8 +12,8 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h" #include "app/rom.h"
namespace yaze { namespace yaze {
@@ -50,10 +50,9 @@ class OverworldMap {
void LoadPalette(); void LoadPalette();
void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size); void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size);
gfx::SNESPalette GetPalette(const std::string& group, int index, int previousIndex, int limit); gfx::SNESPalette GetPalette(const std::string& group, int index,
int previousIndex, int limit);
absl::Status BuildTileset(); absl::Status BuildTileset();
absl::Status BuildTiles16Gfx(int count); absl::Status BuildTiles16Gfx(int count);
@@ -86,6 +85,7 @@ class OverworldMap {
OWMapTiles map_tiles_; OWMapTiles map_tiles_;
gfx::SNESPalette current_palette_; gfx::SNESPalette current_palette_;
// std::vector<zelda3::Sprite> sprite_graphics_;
std::vector<gfx::Tile16> tiles16_; std::vector<gfx::Tile16> tiles16_;
}; };

View File

@@ -4,8 +4,15 @@ namespace yaze {
namespace app { namespace app {
namespace zelda3 { namespace zelda3 {
Sprite::Sprite(Bytes src, uchar mapid, uchar id, uchar x, uchar y, int map_x, Sprite::Sprite() {
int map_y) { preview_gfx_.reserve(64 * 64);
for (int i = 0; i < 64 * 64; i++) {
preview_gfx_.push_back(0xFF);
}
}
void Sprite::InitSprite(Bytes& src, uchar mapid, uchar id, uchar x, uchar y,
int map_x, int map_y) {
current_gfx_ = src; current_gfx_ = src;
overworld_ = true; overworld_ = true;
map_id_ = mapid; map_id_ = mapid;
@@ -17,12 +24,34 @@ Sprite::Sprite(Bytes src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
name_ = core::kSpriteDefaultNames[id]; name_ = core::kSpriteDefaultNames[id];
map_x_ = map_x; map_x_ = map_x;
map_y_ = map_y; map_y_ = map_y;
}
Sprite::Sprite(Bytes src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
int map_y)
: current_gfx_(src),
map_id_(mapid),
id_(id),
x_(x),
y_(y),
nx_(x),
ny_(y),
map_x_(map_x),
map_y_(map_y) {
current_gfx_ = src;
overworld_ = true;
name_ = core::kSpriteDefaultNames[id];
preview_gfx_.reserve(64 * 64); preview_gfx_.reserve(64 * 64);
for (int i = 0; i < 64 * 64; i++) { for (int i = 0; i < 64 * 64; i++) {
preview_gfx_.push_back(0xFF); preview_gfx_.push_back(0xFF);
} }
} }
void Sprite::updateCoordinates(int map_x, int map_y) {
map_x_ = map_x;
map_y_ = map_y;
}
void Sprite::updateBBox() { void Sprite::updateBBox() {
lowerX_ = 1; lowerX_ = 1;
lowerY_ = 1; lowerY_ = 1;
@@ -30,10 +59,9 @@ void Sprite::updateBBox() {
higherY_ = 15; higherY_ = 15;
} }
void Sprite::Draw(bool picker) { void Sprite::Draw() {
uchar x = nx_; uchar x = nx_;
uchar y = ny_; uchar y = ny_;
picker_ = picker;
if (overlord_ == 0x07) { if (overlord_ == 0x07) {
if (id_ == 0x1A) { if (id_ == 0x1A) {
@@ -288,11 +316,11 @@ void Sprite::Draw(bool picker) {
DrawSpriteTile((x * 16), (y * 16), 14, 22, 10); DrawSpriteTile((x * 16), (y * 16), 14, 22, 10);
} }
/* /*
else if (id_== 0x33) // Pull for rupees else if (id_== 0x33) // Pull for rupees
{ {
} }
*/ */
else if (id_ == 0x34) // Npcs else if (id_ == 0x34) // Npcs
{ {
DrawSpriteTile((x * 16), (y * 16), 14, 22, 10); DrawSpriteTile((x * 16), (y * 16), 14, 22, 10);
@@ -304,11 +332,11 @@ else if (id_== 0x33) // Pull for rupees
DrawSpriteTile((x * 16), (y * 16), 14, 22, 10); DrawSpriteTile((x * 16), (y * 16), 14, 22, 10);
} }
/* /*
else if (id_== 0x37) // Waterfall else if (id_== 0x37) // Waterfall
{ {
DrawSpriteTile((x*16), (y *16), 14, 6, 10); DrawSpriteTile((x*16), (y *16), 14, 6, 10);
} }
*/ */
else if (id_ == 0x38) // Arrowtarget else if (id_ == 0x38) // Arrowtarget
{ {
DrawSpriteTile((x * 16), (y * 16), 14, 22, 10); DrawSpriteTile((x * 16), (y * 16), 14, 22, 10);
@@ -602,9 +630,6 @@ DrawSpriteTile((x*16), (y *16), 14, 6, 10);
} else if (id_ == 0x79) // Bee } else if (id_ == 0x79) // Bee
{ {
DrawSpriteTile((x * 16), (y * 16), 4, 14, 11, false, false, 1, 1); DrawSpriteTile((x * 16), (y * 16), 4, 14, 11, false, false, 1, 1);
} else if (id_ == 0x7A) {
DrawSpriteTile((x * 16), (y * 16) - 16, 2, 24, 12, false, false, 2, 4);
DrawSpriteTile((x * 16) + 16, (y * 16) - 16, 2, 24, 12, true, false, 2, 4);
} else if (id_ == 0x7C) // Skull head } else if (id_ == 0x7C) // Skull head
{ {
DrawSpriteTile((x * 16), (y * 16), 0, 16, 10); DrawSpriteTile((x * 16), (y * 16), 0, 16, 10);
@@ -808,7 +833,7 @@ DrawSpriteTile((x*16), (y *16), 14, 6, 10);
DrawSpriteTile((x * 16), (y * 16), 12, 10, 10); DrawSpriteTile((x * 16), (y * 16), 12, 10, 10);
} else if (id_ == 0xBA) { } else if (id_ == 0xBA) {
DrawSpriteTile((x * 16), (y * 16), 14, 14, 6); DrawSpriteTile((x * 16), (y * 16), 14, 14, 6);
} else if (id_ == 0xC1) { } else if (id_ == 0xC1 || id_ == 0x7A) {
DrawSpriteTile((x * 16), (y * 16) - 16, 2, 24, 12, false, false, 2, 4); DrawSpriteTile((x * 16), (y * 16) - 16, 2, 24, 12, false, false, 2, 4);
DrawSpriteTile((x * 16) + 16, (y * 16) - 16, 2, 24, 12, true, false, 2, 4); DrawSpriteTile((x * 16) + 16, (y * 16) - 16, 2, 24, 12, true, false, 2, 4);
} else if (id_ == 0xC3) { } else if (id_ == 0xC3) {
@@ -871,7 +896,6 @@ DrawSpriteTile((x*16), (y *16), 14, 6, 10);
} else if (id_ == 0xF4) { } else if (id_ == 0xF4) {
DrawSpriteTile((x * 16), (y * 16), 12, 28, 5, false, false, 4, 4); DrawSpriteTile((x * 16), (y * 16), 12, 28, 5, false, false, 4, 4);
} else { } else {
// stringtodraw.Add(new SpriteName(x, (y *16), sprites_name.name[id]));
DrawSpriteTile((x * 16), (y * 16), 4, 4, 5); DrawSpriteTile((x * 16), (y * 16), 4, 4, 5);
} }
@@ -882,8 +906,13 @@ DrawSpriteTile((x*16), (y *16), 14, 6, 10);
} }
void Sprite::DrawSpriteTile(int x, int y, int srcx, int srcy, int pal, void Sprite::DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
bool mirror_x, bool mirror_y, int sizex, int sizey, bool mirror_x, bool mirror_y, int sizex,
bool iskey) { int sizey) {
if (current_gfx_.empty()) {
std::cout << "No gfx loaded" << std::endl;
return;
}
x += 16; x += 16;
y += 16; y += 16;
int drawid_ = (srcx + (srcy * 16)) + 512; int drawid_ = (srcx + (srcy * 16)) + 512;
@@ -896,7 +925,7 @@ void Sprite::DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
mx = (((sizex * 8) / 2) - 1) - xl; mx = (((sizex * 8) / 2) - 1) - xl;
} }
if (mirror_y) { if (mirror_y) {
my = (((sizey * 8)) - 1) - yl; my = ((sizey * 8) - 1) - yl;
} }
// Formula information to get tile index position in the array // Formula information to get tile index position in the array

View File

@@ -20,45 +20,53 @@ namespace zelda3 {
class Sprite { class Sprite {
public: public:
uchar x_, y_, id_; Sprite();
uchar nx_, ny_; Sprite(Bytes src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
uchar layer_ = 0; int map_y);
uchar subtype_ = 0; void InitSprite(Bytes& src, uchar mapid, uchar id, uchar x, uchar y,
int map_x, int map_y);
void updateBBox();
void Draw();
void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
bool mirror_x = false, bool mirror_y = false,
int sizex = 2, int sizey = 2);
// New methods
void updateCoordinates(int map_x, int map_y);
auto PreviewGraphics() const { return preview_gfx_; }
auto GetRealX() const { return bounding_box_.x; }
auto GetRealY() const { return bounding_box_.y; }
auto id() const { return id_; }
auto Width() const { return bounding_box_.w; }
auto Height() const { return bounding_box_.h; }
std::string Name() const { return name_; }
private:
Bytes current_gfx_;
bool overworld_;
uchar map_id_;
uchar id_;
uchar x_;
uchar y_;
uchar nx_;
uchar ny_;
uchar overlord_ = 0; uchar overlord_ = 0;
std::string name_; std::string name_;
uchar keyDrop_ = 0; int map_x_;
int sizeMap_ = 512; int map_y_;
bool overworld_ = false; Bytes preview_gfx_;
bool preview_ = false; uchar lowerX_;
uchar map_id_ = 0; uchar lowerY_;
int map_x_ = 0; uchar higherX_;
int map_y_ = 0; uchar higherY_;
short room_id_ = 0;
bool picker_ = false;
bool selected_ = false;
SDL_Rect bounding_box_; SDL_Rect bounding_box_;
Bytes current_gfx_;
Bytes preview_gfx_;
int lowerX_ = 32;
int lowerY_ = 32;
int higherX_ = 0;
int higherY_ = 0;
int width_ = 16; int width_ = 16;
int height_ = 16; int height_ = 16;
Sprite(Bytes src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
int map_y);
void updateBBox();
void Draw(bool picker = false);
void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
bool mirror_x = false, bool mirror_y = false,
int sizex = 2, int sizey = 2, bool iskey = false);
auto PreviewGraphics() { return preview_gfx_; }
}; };
} // namespace zelda3 } // namespace zelda3