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
42 void Reset() { InvalidateTables(); }
43 void Draw();
44 // Both the inline view and Source tab use the same cache and renderer.
45 void DrawSourcePreview(bool show_controls = true);
46
47 static constexpr double kMinRenderInterval = 0.1; // 10 renders/s
48
49 private:
52 enum class Mode { kRoom, kSprite, kTile16 };
53
54 void EnsureTables();
56 void DrawRoomContext(bool render_now);
57 void DrawSpriteContext(bool render_now, float delta);
58 void DrawTile16Context(bool render_now);
59 void DrawSharedUses();
60 absl::Status ScanSharedUses(const usage_preview::LiveRoomContexts& rooms);
61 uint64_t SharedUsesHash(const usage_preview::LiveRoomContexts& rooms) const;
62 // Hash of the current, source-context, and modified session sheet pixels.
63 uint64_t HashWatchedSheets(bool include_room_context) const;
65 void ShowImage(gfx::Bitmap& bitmap, const usage_preview::PreviewImage& image);
66 void DrawBitmapFit(gfx::Bitmap& bitmap, const std::vector<SDL_Rect>& rects,
67 float max_scale, bool fit_height = false);
68 int SelectedTileIndex() const;
69 void InvalidateTables();
70
72 Rom* rom_ = nullptr;
74 std::string hack_name_;
75
77 bool live_ = true;
78 bool dirty_ = true;
79 uint64_t last_hash_ = 0;
80 double last_render_time_ = -1.0;
81 uint16_t last_sheet_ = 0xFFFF;
82 std::string status_;
83
84 // Group tables, built once per ROM.
85 bool tables_ready_ = false;
86 std::map<int, std::array<uint8_t, 16>> room_blocks_;
87 std::map<int, zelda3::RoomGfxInfo> room_gfx_;
88 std::optional<std::map<int, zelda3::OverworldAreaGfxInfo>> areas_;
89
92 std::map<int, std::array<uint8_t, 16>> fallback_room_blocks_;
93 std::map<int, uint64_t> live_room_revisions_;
94 uint64_t group_hash_ = 0;
96
97 // Room context.
99 std::vector<int> rooms_for_sheet_;
101 bool objects_only_ = false;
102 bool outline_objects_ = true;
103 std::vector<SDL_Rect> object_rects_;
104
105 // Sprite context.
107 std::vector<int> spritesets_for_sheet_;
110 int vanilla_sprite_id_ = 0xA7; // Stalfos
111 char zsm_path_[512] = {};
112 std::string zsm_loaded_path_;
113 std::optional<zsprite::ZSprite> zsm_;
115 bool playing_ = true;
117
118 // Tile16 context.
120 std::vector<int> areas_for_sheet_;
122 int tile_index_ = 0;
123 bool follow_selection_ = true;
124 std::vector<int> tile16s_;
125 std::vector<SDL_Rect> tile16_highlights_;
128 uint64_t palette_revision_ = 0;
133 uint64_t source_hash_ = 0;
134 double source_render_time_ = -1.0;
135 bool source_dirty_ = true;
136 std::string source_status_;
137
138 // Explicit loaded-room census. No background/full-ROM scan while drawing.
140 bool shared_scan_ready_ = false;
141 uint64_t shared_scan_hash_ = 0;
143 std::vector<GraphicsEditTarget> shared_targets_;
144 std::vector<usage_preview::LoadedRoomSourceUses> shared_uses_;
148};
149
150} // namespace yaze::editor
151
152#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:49
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)
usage_preview::RoomUsagePreview shared_room_preview_
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_
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
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...