yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_sheet_store.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_GRAPHICS_SHEET_STORE_H
2#define YAZE_ZELDA3_GRAPHICS_SHEET_STORE_H
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <utility>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/types/span.h"
12
13namespace yaze {
14namespace zelda3 {
15
34 public:
35 static constexpr uint16_t kSheetCount = 223;
36 static constexpr size_t kSheetWidth = 128;
37 static constexpr size_t kSheetHeight = 32;
38 static constexpr size_t kSheetBytes = kSheetWidth * kSheetHeight;
39
42 const std::vector<uint8_t>& pixels() const { return pixels_; }
44 std::vector<uint8_t>& mutable_pixels() { return pixels_; }
45
47 bool HasSheet(uint16_t sheet) const;
49 absl::Span<const uint8_t> Sheet(uint16_t sheet) const;
52 uint64_t Revision(uint16_t sheet) const;
53
57 absl::Status WriteSheet(uint16_t sheet, absl::Span<const uint8_t> pixels,
58 uint8_t max_index = 0x0F);
59
63 void Clear();
64
69 class Edit {
70 public:
72 Edit(GraphicsSheetStore& store, uint16_t sheet);
73 ~Edit();
74 Edit(const Edit&) = delete;
75 Edit& operator=(const Edit&) = delete;
76
77 bool ok() const { return store_ != nullptr; }
78 uint16_t sheet() const { return sheet_; }
79 static constexpr int width() { return static_cast<int>(kSheetWidth); }
80 static constexpr int height() { return static_cast<int>(kSheetHeight); }
81
83 uint8_t Get(int x, int y) const;
86 bool Set(int x, int y, uint8_t index);
88 const std::vector<uint8_t>& before() const { return before_; }
90 absl::Span<const uint8_t> pixels() const;
92 void Commit();
93
94 private:
96 uint16_t sheet_ = 0;
97 std::vector<uint8_t> before_;
98 bool uncommitted_ = false;
99 };
100
101 private:
102 std::vector<uint8_t> pixels_;
103 std::array<uint64_t, kSheetCount> revisions_{};
104};
105
114 : sheet_store(std::move(other.sheet_store)) {}
116 sheet_store = other.sheet_store;
117 return *this;
118 }
120 GraphicsSheetStoreHolder&& other) noexcept {
121 sheet_store = std::move(other.sheet_store);
122 return *this;
123 }
124
127 std::vector<uint8_t>& graphics_buffer = sheet_store.mutable_pixels();
128};
129
130} // namespace zelda3
131} // namespace yaze
132
133#endif // YAZE_ZELDA3_GRAPHICS_SHEET_STORE_H
void Commit()
Bumps the revision once if any pixel changed since the last commit.
bool Set(int x, int y, uint8_t index)
Edit(GraphicsSheetStore &store, uint16_t sheet)
ok() is false when store does not hold sheet.
Edit & operator=(const Edit &)=delete
absl::Span< const uint8_t > pixels() const
The sheet now, including uncommitted pixels.
const std::vector< uint8_t > & before() const
The sheet as it was when the Edit began.
uint8_t Get(int x, int y) const
The pixel at (x, y), or 0 outside the sheet.
void MarkAllSheetsChanged()
Call after the loader refills the buffer: bumps every revision.
bool HasSheet(uint16_t sheet) const
True when the buffer holds all 4096 bytes of sheet.
void Clear()
Empties the buffer and bumps every revision.
const std::vector< uint8_t > & pixels() const
uint64_t Revision(uint16_t sheet) const
static constexpr uint16_t kSheetCount
std::array< uint64_t, kSheetCount > revisions_
absl::Span< const uint8_t > Sheet(uint16_t sheet) const
The sheet's 4096 pixels, or an empty span when it is not held.
absl::Status WriteSheet(uint16_t sheet, absl::Span< const uint8_t > pixels, uint8_t max_index=0x0F)
std::vector< uint8_t > & mutable_pixels()
For the graphics_buffer alias and the loader only.
GraphicsSheetStoreHolder & operator=(const GraphicsSheetStoreHolder &other)
GraphicsSheetStoreHolder(GraphicsSheetStoreHolder &&other) noexcept
GraphicsSheetStoreHolder & operator=(GraphicsSheetStoreHolder &&other) noexcept
GraphicsSheetStoreHolder(const GraphicsSheetStoreHolder &other)
std::vector< uint8_t > & graphics_buffer
Legacy name for sheet_store.mutable_pixels().