yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
pixel_index_command.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_PIXEL_INDEX_COMMAND_H_
2#define YAZE_APP_EDITOR_GRAPHICS_PIXEL_INDEX_COMMAND_H_
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <functional>
8#include <map>
9#include <optional>
10#include <string>
11#include <vector>
12
13#include "absl/status/statusor.h"
17
18namespace yaze::zelda3 {
19struct GameData;
20} // namespace yaze::zelda3
21
22namespace yaze::editor {
23class UndoManager;
24
25using PixelIndexPermutation = std::array<uint8_t, 8>;
26
27// Bit y * 8 + x selects a displayed pixel. H/V are the displayed tile's
28// orientation; planning maps the mask back to the physical, unflipped tile.
29// Aliases of the same physical tile are unioned before any pixels change.
31 uint16_t sheet_id = 0;
32 uint16_t tile_index = 0;
33 uint64_t pixel_mask = ~uint64_t{0};
34 bool hflip = false;
35 bool vflip = false;
36};
37
38// Pure helper for a rectangle within one 128x32 sheet. Does not clip bounds.
39absl::StatusOr<std::vector<PixelIndexTarget>> MakePixelIndexRectangleSelection(
40 uint16_t sheet_id, int x, int y, int width, int height);
41
43
44// Inspectable fixed-palette edit. Palette data is never part of the mutation.
45// Targets are canonical physical masks (H/V false). Full initial snapshots
46// also detect an in-progress writer whose store revision has not committed.
49 bool keep_transparency = true;
50 std::string description = "Remap selected pixel indices";
51 const zelda3::GameData* owner = nullptr;
53 std::map<uint16_t, uint64_t> sheet_revisions;
54 std::map<uint16_t, std::vector<uint8_t>> before_sheets;
55 std::vector<PixelIndexTarget> targets;
56 std::vector<SheetPixelDiff> sheets;
57 // Existing source context is retained only for a read-only live assignment
58 // guard. A palette address is never required. Unrelated sheet selections
59 // do not acquire a source guard.
60 std::optional<GraphicsEditContext> source;
61 std::vector<size_t> source_targets;
62 size_t physical_tiles = 0;
63 size_t selected_pixels = 0;
64};
65
66absl::StatusOr<PixelIndexPlan> PlanPixelIndexPermutation(
67 const GraphicsEditorState& state,
68 const std::vector<PixelIndexTarget>& targets,
69 const PixelIndexPermutation& permutation);
70
71// Stages new artwork through the same pixel transaction. Each selected sheet
72// needs one full 4096-byte result; any change outside the target masks is
73// refused. Explicit artwork replacement can change zero to/from nonzero.
74absl::StatusOr<PixelIndexPlan> PlanPixelIndexReplacement(
75 const GraphicsEditorState& state,
76 const std::vector<PixelIndexTarget>& targets,
77 const std::map<uint16_t, std::vector<uint8_t>>& after_sheets,
78 std::string description = "Apply art to object source");
79
81
82// All sheets preflight before mutation. A failed write restores the store
83// before refreshing Arena copies or publishing dirty callbacks.
84// Initial apply checks captured revisions; history replay checks the owner
85// and expected affected pixels, allowing ordinary later edits to be undone.
86// Source-bound edits also re-resolve physical assignments and logical cells.
87// after_sheet_write is a failure-injection seam; production callers omit it.
88absl::Status ExecutePixelIndexPlan(
89 GraphicsEditorState& state, const PixelIndexPlan& plan,
90 PixelIndexExecution execution,
91 const std::function<absl::Status(size_t)>& after_sheet_write = {});
92
93// Apply a staged plan and push exactly one Graphics history action. A no-op
94// performs no write, dirty notification, revision change, or history push.
95absl::Status ApplyPixelIndexPlan(GraphicsEditorState& state,
96 UndoManager& history,
97 const PixelIndexPlan& plan);
98
100 GraphicsEditorState& state, UndoManager& history,
101 const std::vector<PixelIndexTarget>& targets,
102 const PixelIndexPermutation& permutation);
103
104// Depth-aware entry for ROM sheets. Writable ROM sheets are 3bpp; 2bpp ROM
105// sheets are read-only and a permutation for any other depth is refused.
106// Accepted permutations produce exactly the 3bpp plan above.
107absl::StatusOr<PixelIndexPlan> PlanColorIdPermutation(
108 const GraphicsEditorState& state,
109 const std::vector<PixelIndexTarget>& targets,
110 const ColorIdPermutation& permutation);
111
112absl::Status ApplyColorIdPermutation(
113 GraphicsEditorState& state, UndoManager& history,
114 const std::vector<PixelIndexTarget>& targets,
115 const ColorIdPermutation& permutation);
116
117} // namespace yaze::editor
118
119#endif // YAZE_APP_EDITOR_GRAPHICS_PIXEL_INDEX_COMMAND_H_
Shared state between GraphicsEditor panel components.
The Graphics editor's path for sheet pixel writes.
Editors are the view controllers for the application.
absl::StatusOr< PixelIndexPlan > PlanColorIdPermutation(const GraphicsEditorState &state, const std::vector< PixelIndexTarget > &targets, const ColorIdPermutation &permutation)
absl::StatusOr< PixelIndexPlan > PlanPixelIndexReplacement(const GraphicsEditorState &state, const std::vector< PixelIndexTarget > &targets, const std::map< uint16_t, std::vector< uint8_t > > &after_sheets, std::string description)
absl::Status ApplyColorIdPermutation(GraphicsEditorState &state, UndoManager &history, const std::vector< PixelIndexTarget > &targets, const ColorIdPermutation &permutation)
absl::Status ExecutePixelIndexPlan(GraphicsEditorState &state, const PixelIndexPlan &plan, PixelIndexExecution execution, const std::function< absl::Status(size_t)> &after_sheet_write)
absl::Status ApplyPixelIndexPermutation(GraphicsEditorState &state, UndoManager &history, const std::vector< PixelIndexTarget > &targets, const PixelIndexPermutation &permutation)
absl::Status ApplyPixelIndexPlan(GraphicsEditorState &state, UndoManager &history, const PixelIndexPlan &plan)
absl::StatusOr< PixelIndexPlan > PlanPixelIndexPermutation(const GraphicsEditorState &state, const std::vector< PixelIndexTarget > &targets, const PixelIndexPermutation &permutation)
absl::StatusOr< std::vector< PixelIndexTarget > > MakePixelIndexRectangleSelection(uint16_t sheet_id, int x, int y, int width, int height)
std::array< uint8_t, 8 > PixelIndexPermutation
Zelda 3 specific classes and functions.
std::vector< SheetPixelDiff > sheets
std::vector< size_t > source_targets
std::vector< PixelIndexTarget > targets
std::map< uint16_t, uint64_t > sheet_revisions
std::map< uint16_t, std::vector< uint8_t > > before_sheets
const zelda3::GameData * owner
std::optional< GraphicsEditContext > source