6#include "absl/strings/str_format.h"
14 static std::atomic<uint64_t> counter{0};
37 absl::Span<const uint8_t> pixels,
40 return absl::OutOfRangeError(absl::StrFormat(
41 "Sheet 0x%02X is not in the graphics store (%zu bytes held)", sheet,
45 return absl::InvalidArgumentError(
46 absl::StrFormat(
"Sheet 0x%02X needs %zu pixels, got %zu", sheet,
51 [max_index](uint8_t v) { return v > max_index; });
52 if (high !=
pixels.end()) {
53 const size_t at =
static_cast<size_t>(high -
pixels.begin());
54 return absl::InvalidArgumentError(absl::StrFormat(
55 "Sheet 0x%02X pixel (%zu, %zu) uses color %d; the limit is %d", sheet,
60 return absl::OkStatus();
64 return absl::OkStatus();
69 revision = NextRevision();
85 before_.assign(current.begin(), current.end());
93 if (!ok() || x < 0 || y < 0 || x >= width() || y >= height()) {
100 if (!ok() || x < 0 || y < 0 || x >= width() || y >= height()) {
104 if (pixel == index) {
113 return ok() ? store_->Sheet(sheet_) : absl::Span<const uint8_t>();
117 if (!ok() || !uncommitted_) {
120 store_->revisions_[sheet_] = NextRevision();
121 uncommitted_ =
false;
GraphicsSheetStore * store_
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.
absl::Span< const uint8_t > pixels() const
The sheet now, including uncommitted pixels.
std::vector< uint8_t > before_
uint8_t Get(int x, int y) const
The pixel at (x, y), or 0 outside the sheet.
std::vector< uint8_t > pixels_
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)
static constexpr size_t kSheetWidth
static constexpr size_t kSheetBytes
One ROM session's graphics sheet pixels, with a revision per sheet.