40 int refresh_count = 0;
41 constexpr int kMaxRefreshesPerFrame = 2;
43 const auto try_refresh_map = [&](
int map_index) {
45 refresh_count >= kMaxRefreshesPerFrame) {
49 if (bitmap.modified() && bitmap.is_active()) {
58 const int world_start = current_world * 0x40;
61 for (
int map_index = world_start;
62 map_index < world_end && refresh_count < kMaxRefreshesPerFrame;
67 try_refresh_map(map_index);
72 if (!HasTextureContext(
ctx_) || map_index < 0 ||
78 const bool was_built = existing_map && existing_map->is_built();
82 LOG_ERROR(
"OverworldMapTextureCoordinator",
"Failed to build map %d: %s",
83 map_index, status.message());
94 const bool needs_bitmap_sync = !was_built;
96 if (!bitmap.is_active()) {
97 const auto& palette = map->current_palette();
101 bitmap.SetPalette(palette);
102 }
catch (
const std::bad_alloc& e) {
103 LOG_ERROR(
"OverworldMapTextureCoordinator",
104 "Error allocating bitmap for map %d: %s", map_index, e.what());
107 }
else if (needs_bitmap_sync) {
108 bitmap.set_data(map->bitmap_data());
109 bitmap.SetPalette(map->current_palette());
110 bitmap.set_modified(
false);
113 if (!bitmap.texture() && bitmap.is_active()) {
116 }
else if (needs_bitmap_sync && bitmap.texture() && bitmap.is_active()) {
123 int world,
bool process_texture_queue) {
124 if (!HasTextureContext(
ctx_)) {
128 const int clamped_world = std::clamp(world, 0, 2);
129 const int world_start = clamped_world * 0x40;
130 const int world_end =
138 const int current_local_map =
139 (current_world == clamped_world) ? (current_map & 0x3F) : 0;
140 const int first_map = world_start + std::clamp(current_local_map, 0,
141 world_end - world_start - 1);
142 constexpr int kMaxMapsToPrime = 8;
143 const int prime_end = std::min(first_map + kMaxMapsToPrime, world_end);
144 for (
int map_index = first_map; map_index < prime_end; ++map_index) {
148 if (process_texture_queue) {
void EnsureMapTexture(int map_index)
void PrimeWorldMaps(int world, bool process_texture_queue=false)
void ProcessDeferredTextures()
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
void ProcessTextureQueue(IRenderer *renderer)
Represents a bitmap image optimized for SNES ROM hacking.
int inspected_map_count() const
auto overworld_map(int i) const
absl::Status EnsureMapBuilt(int map_index)
Build a map on-demand if it hasn't been built yet.
#define LOG_ERROR(category, format,...)
bool HasTextureContext(const MapTextureContext &ctx)
Editors are the view controllers for the application.
constexpr unsigned int kOverworldMapSize
std::function< void(int map_index)> refresh_map_on_demand
std::array< gfx::Bitmap, zelda3::kExpandedMapCount > * maps_bmp
gfx::IRenderer * renderer
zelda3::Overworld * overworld