16 static Arena instance;
40 if (!active_renderer) {
51 constexpr size_t kMaxTexturesPerFrame = 8;
56 const auto& command = *it;
57 bool should_remove =
true;
63 switch (command.type) {
67 if (command.bitmap && command.bitmap->surface() &&
68 command.bitmap->surface()->format &&
69 command.bitmap->is_active() &&
70 command.bitmap->width() > 0 && command.bitmap->height() > 0) {
73 auto texture = active_renderer->
CreateTexture(command.bitmap->width(),
74 command.bitmap->height());
76 command.bitmap->set_texture(texture);
80 should_remove =
false;
83 LOG_ERROR(
"Arena",
"Exception during texture creation");
91 if (command.bitmap->texture() &&
92 command.bitmap->surface() && command.bitmap->surface()->format &&
93 command.bitmap->is_active()) {
95 active_renderer->
UpdateTexture(command.bitmap->texture(), *command.bitmap);
98 LOG_ERROR(
"Arena",
"Exception during texture update");
104 if (command.bitmap->texture()) {
107 command.bitmap->set_texture(
nullptr);
110 LOG_ERROR(
"Arena",
"Exception during texture destruction");
130 if (std::get<0>(info) == width && std::get<1>(info) == height &&
131 std::get<2>(info) == depth && std::get<3>(info) == format) {
132 SDL_Surface* surface = *it;
140 SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, sdl_format);
143 auto surface_ptr = std::unique_ptr<SDL_Surface, util::SDL_Surface_Deleter>(surface);
144 surfaces_[surface] = std::move(surface_ptr);
152 if (!surface)
return;
184 if (sheet_index < 0 || sheet_index >= 223) {
185 LOG_WARN(
"Arena",
"Invalid sheet index %d, ignoring notification", sheet_index);
190 if (!sheet.is_active() || !sheet.surface()) {
191 LOG_DEBUG(
"Arena",
"Sheet %d not active or no surface, skipping notification", sheet_index);
196 if (sheet.texture()) {
198 LOG_DEBUG(
"Arena",
"Queued texture update for modified sheet %d", sheet_index);
202 LOG_DEBUG(
"Arena",
"Queued texture creation for modified sheet %d", sheet_index);
Resource management arena for efficient graphics memory handling.
std::unordered_map< SDL_Surface *, std::unique_ptr< SDL_Surface, util::SDL_Surface_Deleter > > surfaces_
void Initialize(IRenderer *renderer)
struct yaze::gfx::Arena::TexturePool texture_pool_
SDL_Surface * AllocateSurface(int width, int height, int depth, int format)
std::unordered_map< TextureHandle, std::unique_ptr< SDL_Texture, util::SDL_Texture_Deleter > > textures_
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
std::array< uint16_t, kTotalTiles > layer2_buffer_
void FreeSurface(SDL_Surface *surface)
void ProcessTextureQueue(IRenderer *renderer)
std::array< gfx::Bitmap, 223 > gfx_sheets_
std::vector< TextureCommand > texture_command_queue_
std::array< uint16_t, kTotalTiles > layer1_buffer_
void NotifySheetModified(int sheet_index)
Notify Arena that a graphics sheet has been modified.
struct yaze::gfx::Arena::SurfacePool surface_pool_
Represents a bitmap image optimized for SNES ROM hacking.
Defines an abstract interface for all rendering operations.
virtual TextureHandle CreateTexture(int width, int height)=0
Creates a new, empty texture.
virtual void UpdateTexture(TextureHandle texture, const Bitmap &bitmap)=0
Updates a texture with the pixel data from a Bitmap.
virtual void DestroyTexture(TextureHandle texture)=0
Destroys a texture and frees its associated resources.
#define LOG_DEBUG(category, format,...)
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
Uint32 GetSnesPixelFormat(int format)
Convert bitmap format enum to SDL pixel format.
Main namespace for the application.
static constexpr size_t MAX_POOL_SIZE
std::vector< SDL_Surface * > available_surfaces_
std::unordered_map< SDL_Surface *, std::tuple< int, int, int, int > > surface_info_
std::vector< TextureHandle > available_textures_
std::unordered_map< TextureHandle, std::pair< int, int > > texture_sizes_