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);
55
56 // Pixel sampling for debugging
57 ColorComparison SamplePixelAt(int x, int y) const;
58 std::vector<ColorComparison> GetColorComparisons() const {
59 return comparisons_;
60 }
61 void AddComparison(const ColorComparison& comp) {
63 }
64 void ClearComparisons() { comparisons_.clear(); }
65
66 // Compute checksum for palette integrity verification
67 uint32_t ComputePaletteChecksum(const gfx::SnesPalette& palette) const;
68
69 const std::vector<PaletteDebugEvent>& GetEvents() const { return events_; }
70 void Clear() {
71 events_.clear();
72 comparisons_.clear();
75 current_bitmap_ = nullptr;
76 }
77
78 // WASM exports
79#ifdef __EMSCRIPTEN__
80 std::string ExportToJSON() const;
81 std::string ExportColorComparisonsJSON() const;
82 std::string SamplePixelJSON(int x, int y) const;
83
84 // Full state dump for AI analysis (Gemini/Antigravity integration)
85 std::string ExportFullStateJSON() const;
86 std::string ExportPaletteDataJSON() const;
87 std::string ExportTimelineJSON() const;
88
89 // Analysis helpers
90 std::string GetDiagnosticSummary() const;
91 std::string GetHypothesisAnalysis() const;
92#endif
93
94 private:
95 PaletteDebugger() = default;
96
97 // Helper to add events with size limit enforcement
98 void AddEvent(const PaletteDebugEvent& event) {
99 if (events_.size() >= kMaxEvents) {
100 // Remove oldest half when at limit (keeps recent events)
101 events_.erase(events_.begin(), events_.begin() + kMaxEvents / 2);
102 }
103 events_.push_back(event);
104 }
105
106 // Helper to add comparisons with size limit enforcement
108 if (comparisons_.size() >= kMaxComparisons) {
109 comparisons_.erase(comparisons_.begin(),
110 comparisons_.begin() + kMaxComparisons / 2);
111 }
112 comparisons_.push_back(comp);
113 }
114
115 std::vector<PaletteDebugEvent> events_;
116 std::vector<ColorComparison> comparisons_;
118 std::vector<SDL_Color> current_render_palette_;
121};
122
123} // namespace yaze::zelda3
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
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 LogSurfaceState(const std::string &location, SDL_Surface *surface)
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