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;
60 for (
int map_index = world_start;
61 map_index < world_end && refresh_count < kMaxRefreshesPerFrame;
66 try_refresh_map(map_index);
71 if (!HasTextureContext(
ctx_) || map_index < 0 ||
77 const bool was_built = existing_map && existing_map->is_built();
81 LOG_ERROR(
"OverworldMapTextureCoordinator",
"Failed to build map %d: %s",
82 map_index, status.message());
91 const bool needs_bitmap_sync = !was_built || bitmap.modified();
93 if (!bitmap.is_active()) {
94 const auto& palette = map->current_palette();
98 bitmap.SetPalette(palette);
99 }
catch (
const std::bad_alloc& e) {
100 LOG_ERROR(
"OverworldMapTextureCoordinator",
101 "Error allocating bitmap for map %d: %s", map_index, e.what());
104 }
else if (needs_bitmap_sync) {
105 bitmap.set_data(map->bitmap_data());
106 bitmap.SetPalette(map->current_palette());
107 bitmap.set_modified(
false);
110 if (!bitmap.texture() && bitmap.is_active()) {
113 }
else if (needs_bitmap_sync && bitmap.texture() && bitmap.is_active()) {
120 int world,
bool process_texture_queue) {
121 if (!HasTextureContext(
ctx_)) {
125 const int clamped_world = std::clamp(world, 0, 2);
126 const int world_start = clamped_world * 0x40;
134 const int current_local_map =
135 (current_world == clamped_world) ? (current_map & 0x3F) : 0;
136 const int first_map = world_start + std::clamp(current_local_map, 0,
137 world_end - world_start - 1);
138 constexpr int kMaxMapsToPrime = 8;
139 const int prime_end = std::min(first_map + kMaxMapsToPrime, world_end);
140 for (
int map_index = first_map; map_index < prime_end; ++map_index) {
144 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.
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
constexpr int kNumOverworldMaps
std::function< void(int map_index)> refresh_map_on_demand
std::array< gfx::Bitmap, zelda3::kNumOverworldMaps > * maps_bmp
gfx::IRenderer * renderer
zelda3::Overworld * overworld