yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
usage_preview_view.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_UI_USAGE_USAGE_PREVIEW_VIEW_H
2#define YAZE_APP_EDITOR_GRAPHICS_UI_USAGE_USAGE_PREVIEW_VIEW_H
3
4#include <array>
5#include <cstdint>
6#include <map>
7#include <optional>
8#include <string>
9#include <vector>
10
13#include "app/gfx/core/bitmap.h"
14#include "rom/rom.h"
15#include "zelda3/game_data.h"
17
18namespace yaze::editor {
19
31 public:
32 explicit UsagePreviewView(GraphicsEditorState* state) : state_(state) {}
33
34 void SetRom(Rom* rom);
35 void SetGameData(zelda3::GameData* game_data);
36 void SetHackName(std::string hack_name) { hack_name_ = std::move(hack_name); }
37
46 void Reset() { InvalidateTables(); }
47 void Draw();
48 // Both the inline view and Source tab use the same cache and renderer.
49 void DrawSourcePreview(bool show_controls = true);
50
51 static constexpr double kMinRenderInterval = 0.1; // 10 renders/s
52
53 private:
56 enum class Mode { kRoom, kSprite, kTile16 };
57
58 void EnsureTables();
60 void DrawRoomContext(bool render_now);
61 void DrawSpriteContext(bool render_now, float delta);
62 void DrawTile16Context(bool render_now);
63 void DrawSharedUses();
64 absl::Status ScanSharedUses(const usage_preview::LiveRoomContexts& rooms);
65 uint64_t SharedUsesHash(const usage_preview::LiveRoomContexts& rooms) const;
66 // Hash of the current, source-context, and modified session sheet pixels.
67 uint64_t HashWatchedSheets(bool include_room_context) const;
69 void ShowImage(gfx::Bitmap& bitmap, const usage_preview::PreviewImage& image);
70 void DrawBitmapFit(gfx::Bitmap& bitmap, const std::vector<SDL_Rect>& rects,
71 float max_scale, bool fit_height = false);
72 int SelectedTileIndex() const;
73 void InvalidateTables();
74
76 Rom* rom_ = nullptr;
78 std::string hack_name_;
79
81 bool live_ = true;
82 bool dirty_ = true;
83 uint64_t last_hash_ = 0;
84 double last_render_time_ = -1.0;
85 uint16_t last_sheet_ = 0xFFFF;
86 std::string status_;
87
88 // Group tables, built once per ROM.
89 bool tables_ready_ = false;
90 std::map<int, std::array<uint8_t, 16>> room_blocks_;
91 std::map<int, zelda3::RoomGfxInfo> room_gfx_;
92 std::optional<std::map<int, zelda3::OverworldAreaGfxInfo>> areas_;
93
97 std::map<int, std::array<uint8_t, 16>> fallback_room_blocks_;
98 std::map<int, uint64_t> live_room_revisions_;
99 uint64_t group_hash_ = 0;
101
102 // Room context.
104 std::vector<int> rooms_for_sheet_;
106 bool objects_only_ = false;
107 bool outline_objects_ = true;
108 std::vector<SDL_Rect> object_rects_;
109
110 // Sprite context.
112 std::vector<int> spritesets_for_sheet_;
115 int vanilla_sprite_id_ = 0xA7; // Stalfos
116 char zsm_path_[512] = {};
117 std::string zsm_loaded_path_;
118 std::optional<zsprite::ZSprite> zsm_;
120 bool playing_ = true;
122
123 // Tile16 context.
125 std::vector<int> areas_for_sheet_;
127 uint64_t live_tile16_hash_ = 0;
129 int tile_index_ = 0;
130 bool follow_selection_ = true;
131 std::vector<int> tile16s_;
132 std::vector<SDL_Rect> tile16_highlights_;
135 uint64_t palette_revision_ = 0;
140 uint64_t source_hash_ = 0;
141 std::optional<uint64_t> source_model_revision_;
142 double source_render_time_ = -1.0;
143 bool source_dirty_ = true;
144 std::string source_status_;
145
146 // Explicit loaded-room census. No background/full-ROM scan while drawing.
148 bool shared_scan_ready_ = false;
149 uint64_t shared_scan_hash_ = 0;
151 std::vector<GraphicsEditTarget> shared_targets_;
152 std::vector<usage_preview::LoadedRoomSourceUses> shared_uses_;
156};
157
158} // namespace yaze::editor
159
160#endif // YAZE_APP_EDITOR_GRAPHICS_UI_USAGE_USAGE_PREVIEW_VIEW_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:52
Shared state between GraphicsEditor panel components.
Shows how the game uses the current graphics sheet while it is edited: a room that loads it,...
std::optional< zsprite::ZSprite > zsm_
usage_preview::SheetPixels Snapshot() const
static constexpr double kMinRenderInterval
void DrawBitmapFit(gfx::Bitmap &bitmap, const std::vector< SDL_Rect > &rects, float max_scale, bool fit_height=false)
std::optional< uint64_t > source_model_revision_
usage_preview::RoomUsagePreview shared_room_preview_
usage_preview::LiveOverworldProvider live_overworld_provider_
usage_preview::LiveRoomProvider live_rooms_provider_
std::optional< std::map< int, zelda3::OverworldAreaGfxInfo > > areas_
std::vector< GraphicsEditTarget > shared_targets_
void ShowImage(gfx::Bitmap &bitmap, const usage_preview::PreviewImage &image)
absl::Status ScanSharedUses(const usage_preview::LiveRoomContexts &rooms)
void DrawSourcePreview(bool show_controls=true)
void SetHackName(std::string hack_name)
void DrawSpriteContext(bool render_now, float delta)
uint64_t HashWatchedSheets(bool include_room_context) const
void DrawRoomContext(bool render_now)
uint64_t SharedUsesHash(const usage_preview::LiveRoomContexts &rooms) const
std::map< int, uint64_t > live_room_revisions_
std::vector< SDL_Rect > tile16_highlights_
void SetLiveRoomProvider(usage_preview::LiveRoomProvider provider)
std::map< int, zelda3::RoomGfxInfo > room_gfx_
std::map< int, std::array< uint8_t, 16 > > room_blocks_
void SetGameData(zelda3::GameData *game_data)
void DrawTile16Context(bool render_now)
usage_preview::RoomUsagePreview room_preview_
std::map< int, std::array< uint8_t, 16 > > fallback_room_blocks_
void SetLiveOverworldProvider(usage_preview::LiveOverworldProvider provider)
UsagePreviewView(GraphicsEditorState *state)
std::vector< usage_preview::LoadedRoomSourceUses > shared_uses_
usage_preview::Tile16UsagePreview tile16_preview_
std::vector< SDL_Rect > object_rects_
usage_preview::SpriteUsagePreview sprite_preview_
usage_preview::LiveRoomContexts live_rooms_
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
Which graphics sheets exist, which tables use them, and which 16x16 blocks are free.
std::map< uint16_t, std::vector< uint8_t > > SheetPixels
Sheet id -> 4096 8bpp pixels (the GameData::graphics_buffer layout).
std::function< LiveRoomContexts()> LiveRoomProvider
std::map< int, LiveRoomContext > LiveRoomContexts
std::function< zelda3::Overworld *()> LiveOverworldProvider
Editors are the view controllers for the application.
Renders a graphics sheet the way the game uses it, from unsaved sheet pixels, without writing the ROM...