yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_debug.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
8
9struct SDL_Surface;
10
11namespace yaze::zelda3 {
12
14
16 std::string location; // e.g., "Room::RenderRoomGraphics"
17 std::string message; // What happened
19 int palette_id = -1; // Which palette
20 int color_count = 0; // How many colors
21 std::vector<uint8_t> sample_colors; // RGB of first 3 colors for verification
22 uint64_t timestamp_ms = 0; // Timestamp for timeline analysis
23 int sequence_number = 0; // Order of events
24};
25
26// Color comparison for debugging
28 int x, y; // Position sampled
29 uint8_t palette_index; // Palette index at position
30 uint8_t actual_r, actual_g, actual_b; // Actual rendered color
31 uint8_t expected_r, expected_g, expected_b; // Expected from palette
32 bool matches; // Do they match?
33};
34
36 public:
37 // Maximum number of events to store (prevents memory exhaustion in WASM)
38 static constexpr size_t kMaxEvents = 1000;
39 static constexpr size_t kMaxComparisons = 500;
40
41 static PaletteDebugger& Get();
42
43 void LogPaletteLoad(const std::string& location, int palette_id,
44 const gfx::SnesPalette& palette);
45 void LogPaletteApplication(const std::string& location, int palette_id,
46 bool success, const std::string& reason = "");
47 void LogTextureCreation(const std::string& location, bool has_palette,
48 int color_count);
49 void LogSurfaceState(const std::string& location, SDL_Surface* surface);
50
51 // Palette data access for comparison
52 void SetCurrentPalette(const gfx::SnesPalette& palette);
53 void SetCurrentRenderPalette(const std::vector<SDL_Color>& palette);
54 void SetCurrentBitmap(gfx::Bitmap* bitmap);
56 const gfx::SnesPalette& palette,
57 const std::vector<SDL_Color>& render_palette);
58 void ClearCurrentBitmapIf(const gfx::Bitmap* bitmap);
59
60 // Pixel sampling for debugging
61 ColorComparison SamplePixelAt(int x, int y) const;
62 std::vector<ColorComparison> GetColorComparisons() const {
63 return comparisons_;
64 }
65 void AddComparison(const ColorComparison& comp) {
67 }
68 void ClearComparisons() { comparisons_.clear(); }
69
70 // Compute checksum for palette integrity verification
71 uint32_t ComputePaletteChecksum(const gfx::SnesPalette& palette) const;
72
73 const std::vector<PaletteDebugEvent>& GetEvents() const { return events_; }
74 void Clear() {
75 events_.clear();
76 comparisons_.clear();
79 current_bitmap_ = nullptr;
80 }
81
82 // WASM exports
83#ifdef __EMSCRIPTEN__
84 std::string ExportToJSON() const;
85 std::string ExportColorComparisonsJSON() const;
86 std::string SamplePixelJSON(int x, int y) const;
87
88 // Full state dump for AI analysis (Gemini/Antigravity integration)
89 std::string ExportFullStateJSON() const;
90 std::string ExportPaletteDataJSON() const;
91 std::string ExportTimelineJSON() const;
92
93 // Analysis helpers
94 std::string GetDiagnosticSummary() const;
95 std::string GetHypothesisAnalysis() const;
96#endif
97
98 private:
99 PaletteDebugger() = default;
100
101 // Helper to add events with size limit enforcement
102 void AddEvent(const PaletteDebugEvent& event) {
103 if (events_.size() >= kMaxEvents) {
104 // Remove oldest half when at limit (keeps recent events)
105 events_.erase(events_.begin(), events_.begin() + kMaxEvents / 2);
106 }
107 events_.push_back(event);
108 }
109
110 // Helper to add comparisons with size limit enforcement
112 if (comparisons_.size() >= kMaxComparisons) {
113 comparisons_.erase(comparisons_.begin(),
114 comparisons_.begin() + kMaxComparisons / 2);
115 }
116 comparisons_.push_back(comp);
117 }
118
119 std::vector<PaletteDebugEvent> events_;
120 std::vector<ColorComparison> comparisons_;
122 std::vector<SDL_Color> current_render_palette_;
125};
126
127} // namespace yaze::zelda3
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:69
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void SetCurrentBitmap(gfx::Bitmap *bitmap)
void LogTextureCreation(const std::string &location, bool has_palette, int color_count)
uint32_t ComputePaletteChecksum(const gfx::SnesPalette &palette) const
void AddEvent(const PaletteDebugEvent &event)
static constexpr size_t kMaxEvents
std::vector< SDL_Color > current_render_palette_
static constexpr size_t kMaxComparisons
void LogPaletteLoad(const std::string &location, int palette_id, const gfx::SnesPalette &palette)
static PaletteDebugger & Get()
gfx::SnesPalette current_palette_
const std::vector< PaletteDebugEvent > & GetEvents() const
void LogPaletteApplication(const std::string &location, int palette_id, bool success, const std::string &reason="")
void SetCurrentPalette(const gfx::SnesPalette &palette)
void AddComparisonLimited(const ColorComparison &comp)
std::vector< PaletteDebugEvent > events_
std::vector< ColorComparison > comparisons_
void SetCurrentPresentation(gfx::Bitmap *bitmap, const gfx::SnesPalette &palette, const std::vector< SDL_Color > &render_palette)
void LogSurfaceState(const std::string &location, SDL_Surface *surface)
void ClearCurrentBitmapIf(const gfx::Bitmap *bitmap)
std::vector< ColorComparison > GetColorComparisons() const
void AddComparison(const ColorComparison &comp)
void SetCurrentRenderPalette(const std::vector< SDL_Color > &palette)
ColorComparison SamplePixelAt(int x, int y) const
Zelda 3 specific classes and functions.
std::vector< uint8_t > sample_colors