yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_matrix_census.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_WORKSPACE_ROOM_MATRIX_CENSUS_H_
2#define YAZE_APP_EDITOR_DUNGEON_WORKSPACE_ROOM_MATRIX_CENSUS_H_
3
4#include <functional>
5#include <future>
6#include <memory>
7#include <optional>
8#include <set>
9#include <string>
10
11#include "absl/status/statusor.h"
12#include "imgui/imgui.h"
13#include "util/stop_token.h"
15
16namespace yaze {
17class Rom;
18namespace core {
19class HackManifest;
20}
21
22namespace editor {
23
33 public:
34 using ManifestProvider = std::function<const core::HackManifest*()>;
35
38
40 manifest_provider_ = std::move(provider);
41 Invalidate();
42 }
43
44 bool enabled() const { return enabled_; }
45 void SetEnabled(bool enabled) {
47 if (!enabled && pending_.valid()) {
48 Invalidate();
49 }
50 }
51
52 // Starts a computation when enabled and the ROM changed; polls a running
53 // one. Call once per frame before drawing.
54 void Update(Rom* rom);
55 void Invalidate() {
57 stale_ = true;
58 census_.reset();
59 largest_block_.clear();
60 error_.clear();
61 }
62
63 // Toggle, status line, summary, and wrapping legend/filter chips.
64 void DrawControls(Rom* rom);
65
66 const zelda3::RoomCensus* census() const {
67 return enabled_ && census_.has_value() ? &*census_ : nullptr;
68 }
69 bool computing() const { return pending_.valid(); }
70
71 // Cell styling. Only meaningful when census() is non-null.
72 ImU32 FillColor(int room_id) const;
73 // Outline color and whether one applies (free / reclaimable).
74 std::optional<ImU32> StatusOutline(int room_id) const;
75 bool InLargestFreeBlock(int room_id) const;
76 static ImU32 OrphanMarkColor();
77 static ImU32 BlockHaloColor(float alpha);
78 bool IsOrphan(int room_id) const;
79 // True when no chip is active or the room matches an active chip.
80 bool MatchesChips(int room_id) const;
81 bool HasActiveChips() const {
83 !filter_owners_.empty();
84 }
85
86 // Census block for the hovered cell's tooltip.
87 void DrawTooltip(int room_id) const;
88
89 // Test hooks.
90 void SetFilterFree(bool on) { filter_free_ = on; }
92 void ToggleOwnerFilter(int owner_index);
93 static ImVec4 OwnerColor(int owner_index, bool interior);
94
95 private:
97 void StartComputation(Rom* rom);
98 // Places the next chip on this line or wraps; returns false when it wraps.
99 static void WrapBeforeItem(float item_width, bool first);
100 bool DrawChip(const char* id, const std::string& label, ImVec4 swatch,
101 bool outline_only, bool active, bool first);
102
104 bool enabled_ = false;
105 bool stale_ = true;
106 const Rom* computed_for_ = nullptr;
110 std::optional<zelda3::RoomCensus> census_;
111 std::string error_;
112 std::future<absl::StatusOr<zelda3::RoomCensus>> pending_;
114 std::set<int> largest_block_;
115
116 bool filter_free_ = false;
118 bool filter_orphan_ = false;
119 std::set<int> filter_owners_;
120};
121
122} // namespace editor
123} // namespace yaze
124
125#endif // YAZE_APP_EDITOR_DUNGEON_WORKSPACE_ROOM_MATRIX_CENSUS_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
Loads and queries the hack manifest JSON for yaze-ASM integration.
"Census" overlay for the Room Matrix.
static void WrapBeforeItem(float item_width, bool first)
bool DrawChip(const char *id, const std::string &label, ImVec4 swatch, bool outline_only, bool active, bool first)
const zelda3::RoomCensus * census() const
std::function< const core::HackManifest *()> ManifestProvider
std::optional< ImU32 > StatusOutline(int room_id) const
void SetManifestProvider(ManifestProvider provider)
std::future< absl::StatusOr< zelda3::RoomCensus > > pending_
static ImVec4 OwnerColor(int owner_index, bool interior)
std::optional< zelda3::RoomCensus > census_
bool request_stop() noexcept
Definition stop_token.h:40
constexpr NoStopStateTag kNoStopState
Definition stop_token.h:11