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 INFO,
15 WARNING,
16 ERROR
17};
18
20 std::string location; // e.g., "Room::RenderRoomGraphics"
21 std::string message; // What happened
23 int palette_id; // Which palette
24 int color_count; // How many colors
25 std::vector<uint8_t> sample_colors; // RGB of first 3 colors for verification
26 uint64_t timestamp_ms; // Timestamp for timeline analysis
27 int sequence_number; // Order of events
28};
29
30// Color comparison for debugging
32 int x, y; // Position sampled
33 uint8_t palette_index; // Palette index at position
34 uint8_t actual_r, actual_g, actual_b; // Actual rendered color
35 uint8_t expected_r, expected_g, expected_b; // Expected from palette
36 bool matches; // Do they match?
37};
38
40 public:
41 // Maximum number of events to store (prevents memory exhaustion in WASM)
42 static constexpr size_t kMaxEvents = 1000;
43 static constexpr size_t kMaxComparisons = 500;
44
45 static PaletteDebugger& Get();
46
47 void LogPaletteLoad(const std::string& location, int palette_id,
48 const gfx::SnesPalette& palette);
49 void LogPaletteApplication(const std::string& location, int palette_id,
50 bool success, const std::string& reason = "");
51 void LogTextureCreation(const std::string& location,
52 bool has_palette, int color_count);
53 void LogSurfaceState(const std::string& location, SDL_Surface* surface);
54
55 // Palette data access for comparison
56 void SetCurrentPalette(const gfx::SnesPalette& palette);
57 void SetCurrentBitmap(gfx::Bitmap* bitmap);
58
59 // Pixel sampling for debugging
60 ColorComparison SamplePixelAt(int x, int y) const;
61 std::vector<ColorComparison> GetColorComparisons() const { return comparisons_; }
63 void ClearComparisons() { comparisons_.clear(); }
64
65 // Compute checksum for palette integrity verification
66 uint32_t ComputePaletteChecksum(const gfx::SnesPalette& palette) const;
67
68 const std::vector<PaletteDebugEvent>& GetEvents() const { return events_; }
69 void Clear() { events_.clear(); comparisons_.clear(); }
70
71 // WASM exports
72#ifdef __EMSCRIPTEN__
73 std::string ExportToJSON() const;
74 std::string ExportColorComparisonsJSON() const;
75 std::string SamplePixelJSON(int x, int y) const;
76
77 // Full state dump for AI analysis (Gemini/Antigravity integration)
78 std::string ExportFullStateJSON() const;
79 std::string ExportPaletteDataJSON() const;
80 std::string ExportTimelineJSON() const;
81
82 // Analysis helpers
83 std::string GetDiagnosticSummary() const;
84 std::string GetHypothesisAnalysis() const;
85#endif
86
87 private:
88 PaletteDebugger() = default;
89
90 // Helper to add events with size limit enforcement
91 void AddEvent(const PaletteDebugEvent& event) {
92 if (events_.size() >= kMaxEvents) {
93 // Remove oldest half when at limit (keeps recent events)
94 events_.erase(events_.begin(), events_.begin() + kMaxEvents / 2);
95 }
96 events_.push_back(event);
97 }
98
99 // Helper to add comparisons with size limit enforcement
101 if (comparisons_.size() >= kMaxComparisons) {
102 comparisons_.erase(comparisons_.begin(), comparisons_.begin() + kMaxComparisons / 2);
103 }
104 comparisons_.push_back(comp);
105 }
106
107 std::vector<PaletteDebugEvent> events_;
108 std::vector<ColorComparison> comparisons_;
112};
113
114} // 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
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)
ColorComparison SamplePixelAt(int x, int y) const
Zelda 3 specific classes and functions.
Definition editor.h:35
std::vector< uint8_t > sample_colors