yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::Arena Class Reference

Resource management arena for efficient graphics memory handling. More...

#include <arena.h>

Classes

struct  SheetCacheStats
 Statistics for sheet cache performance. More...
 
struct  SurfacePool
 
struct  TextureCommand
 
struct  TexturePool
 
struct  TextureQueueStats
 Statistics for texture queue processing. More...
 

Public Types

enum class  TextureCommandType { CREATE , UPDATE , DESTROY }
 
using GraphicsSheets = std::array<gfx::Bitmap, 223>
 Get reference to all graphics sheets.
 
using PaletteChangeCallback
 

Public Member Functions

void Initialize (IRenderer *renderer)
 
 ~Arena ()
 
void QueueTextureCommand (TextureCommandType type, Bitmap *bitmap)
 
bool HasPendingTextureCommand (TextureCommandType type, const Bitmap *bitmap) const
 
void ProcessTextureQueue (IRenderer *renderer)
 
void ClearTextureQueue ()
 
void RetireBitmap (Bitmap &bitmap)
 Explicitly retire resources owned by a bitmap that is being erased.
 
size_t DrainRetiredBitmaps (IRenderer *renderer)
 Destroy texture handles retired earlier in the frame.
 
bool HasPendingTextures () const
 Check if there are pending textures to process.
 
bool ProcessSingleTexture (IRenderer *renderer)
 Process a single texture command for frame-budget-aware loading.
 
bool ProcessTextureQueueWithBudget (IRenderer *renderer, float budget_ms)
 Process texture queue with a time budget.
 
const TextureQueueStats & GetTextureQueueStats () const
 Get texture queue processing statistics.
 
void ResetTextureQueueStats ()
 Reset texture queue statistics.
 
SDL_Surface * AllocateSurface (int width, int height, int depth, int format)
 
void FreeSurface (SDL_Surface *surface)
 
void Shutdown ()
 
size_t GetTextureCount () const
 
size_t GetSurfaceCount () const
 
size_t GetPooledTextureCount () const
 
size_t GetPooledSurfaceCount () const
 
size_t texture_command_queue_size () const
 
size_t retired_texture_handle_count () const
 
GraphicsSheets & gfx_sheets ()
 
auto gfx_sheet (int i)
 Get a specific graphics sheet by index.
 
auto mutable_gfx_sheet (int i)
 Get mutable reference to a specific graphics sheet.
 
auto mutable_gfx_sheets ()
 Get mutable reference to all graphics sheets.
 
void BindGraphicsSheets (GraphicsSheets *sheets, const void *owner)
 
void set_gfx_sheets_owner (const void *owner)
 
const void * gfx_sheets_owner () const
 
void NotifySheetModified (int sheet_index)
 Notify Arena that a graphics sheet has been modified.
 
void NotifyPaletteModified (const std::string &group_name, int palette_index=-1)
 Notify all listeners that a palette has been modified.
 
int RegisterPaletteListener (PaletteChangeCallback callback)
 Register a callback for palette change notifications.
 
void UnregisterPaletteListener (int listener_id)
 Unregister a palette change listener.
 
auto & bg1 ()
 Get reference to background layer 1 buffer.
 
auto & bg2 ()
 Get reference to background layer 2 buffer.
 
void TouchSheet (int sheet_index)
 Mark a graphics sheet as recently accessed.
 
Bitmap * GetSheetWithCache (int sheet_index)
 Get a sheet with automatic LRU tracking and texture creation.
 
void SetSheetCacheSize (size_t max_size)
 Set the maximum number of sheet textures to keep cached.
 
size_t GetSheetCacheSize () const
 Get current sheet cache size limit.
 
size_t GetCachedSheetCount () const
 Get number of sheets currently with textures.
 
size_t EvictLRUSheets (size_t count=0)
 Evict least recently used sheet textures.
 
void ClearSheetCache ()
 Clear all sheet texture cache tracking.
 
const SheetCacheStats & GetSheetCacheStats () const
 Get sheet cache statistics.
 
void ResetSheetCacheStats ()
 Reset sheet cache statistics.
 

Static Public Member Functions

static Arena & Get ()
 

Private Member Functions

 Arena ()
 

Private Attributes

BackgroundBuffer bg1_
 
BackgroundBuffer bg2_
 
std::array< uint16_t, kTotalTiles > layer1_buffer_
 
std::array< uint16_t, kTotalTiles > layer2_buffer_
 
GraphicsSheets gfx_sheets_
 
GraphicsSheets * active_gfx_sheets_ = &gfx_sheets_
 
const void * gfx_sheets_owner_ = nullptr
 
std::unordered_map< TextureHandle, std::unique_ptr< SDL_Texture, util::SDL_Texture_Deleter > > textures_
 
std::unordered_map< SDL_Surface *, std::unique_ptr< SDL_Surface, util::SDL_Surface_Deleter > > surfaces_
 
struct yaze::gfx::Arena::TexturePool texture_pool_
 
struct yaze::gfx::Arena::SurfacePool surface_pool_
 
std::vector< TextureCommand > texture_command_queue_
 
std::vector< TextureHandle > retired_texture_handles_
 
IRenderer * renderer_ = nullptr
 
bool is_shutdown_ = false
 
TextureQueueStats texture_queue_stats_
 
std::unordered_map< int, PaletteChangeCallback > palette_listeners_
 
int next_palette_listener_id_ = 1
 
std::list< int > sheet_lru_list_
 
std::unordered_map< int, std::list< int >::iterator > sheet_lru_map_
 
size_t sheet_cache_max_size_ = 64
 
SheetCacheStats sheet_cache_stats_
 

Static Private Attributes

static constexpr int kTilesPerRow = 64
 
static constexpr int kTilesPerColumn = 64
 
static constexpr int kTotalTiles = kTilesPerRow * kTilesPerColumn
 

Detailed Description

Resource management arena for efficient graphics memory handling.

The Arena class provides centralized management of SDL textures and surfaces for the YAZE ROM hacking editor. It implements several key optimizations:

Key Features:

  • Singleton pattern for global access across all graphics components
  • Automatic resource cleanup with RAII-style management
  • Memory pooling to reduce allocation overhead
  • Support for 223 graphics sheets (YAZE's full graphics space)
  • Background buffer management for SNES layer rendering

Performance Optimizations:

  • Unique_ptr with custom deleters for automatic SDL resource cleanup
  • Hash map storage for O(1) texture/surface lookup
  • Batch resource management to minimize SDL calls
  • Pre-allocated graphics sheet array for fast access

ROM Hacking Specific:

  • Fixed-size graphics sheet array (223 sheets) matching YAZE's graphics space
  • Background buffer support for SNES layer 1 and layer 2 rendering
  • Tile buffer management for 64x64 tile grids
  • Integration with SNES graphics format requirements

Definition at line 47 of file arena.h.

Member Typedef Documentation

◆ GraphicsSheets

Get reference to all graphics sheets.

Returns
Reference to array of 223 Bitmap objects

Definition at line 177 of file arena.h.

◆ PaletteChangeCallback

Initial value:
std::function<void(const std::string& group_name, int palette_index)>

Callback type for palette change listeners

Parameters
group_nameThe palette group that changed (e.g., "ow_main")
palette_indexThe specific palette that changed, or -1 for all

Definition at line 230 of file arena.h.

Member Enumeration Documentation

◆ TextureCommandType

Enumerator
CREATE 
UPDATE 
DESTROY 

Definition at line 55 of file arena.h.

Constructor & Destructor Documentation

◆ ~Arena()

yaze::gfx::Arena::~Arena ( )

Definition at line 34 of file arena.cc.

References Shutdown().

Here is the call graph for this function:

◆ Arena()

yaze::gfx::Arena::Arena ( )
private

Definition at line 29 of file arena.cc.

References layer1_buffer_, and layer2_buffer_.

Member Function Documentation

◆ Get()

Arena & yaze::gfx::Arena::Get ( )
static

Definition at line 24 of file arena.cc.

Referenced by yaze::editor::RomSession::ActivateGraphicsDisplay(), yaze::editor::ActiveSheetStore(), yaze::editor::Tile16EditSession::ApplyDefinitions(), yaze::editor::PixelEditorPanel::ApplyEyedropper(), yaze::editor::MessageEditor::ApplyFontPalette(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::editor::Tile16EditSession::ApplyPaletteToCurrentTile16Bitmap(), yaze::gui::CanvasUtils::ApplyPendingPaletteUpdates(), yaze::gfx::PaletteManager::ApplyPreviewChanges(), yaze::gui::PaletteEditorWidget::ApplyROMPalette(), yaze::editor::LinkSpritePanel::ApplySelectedPalette(), yaze::gfx::Bitmap::Bitmap(), yaze::zelda3::Inventory::BuildTileset(), yaze::zelda3::TitleScreen::BuildTileset(), yaze::editor::anonymous_namespace{palette_controls_panel.cc}::CanPreview(), yaze::editor::CanvasNavigationManager::CheckForCurrentMap(), yaze::editor::PixelEditorPanel::ClampFloatingPaste(), yaze::editor::OverworldEditor::Clear(), yaze::editor::RoomGraphicsContent::ClearPickerPreviews(), yaze::editor::ObjectTileEditorPanel::ClearRenderedBitmaps(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::test::TestManager::CollectResourceStats(), yaze::editor::Tile16EditSession::CommitChangesToBlockset(), yaze::editor::Tile16EditSession::CopyTile16ToAtlas(), yaze::editor::Tile16EditSession::CopyTile16ToClipboard(), yaze::editor::PixelEditorPanel::CopyToSystemClipboard(), yaze::gfx::Bitmap::Create(), yaze::zelda3::OverworldMapScreen::Create(), yaze::zelda3::Inventory::Create(), yaze::gfx::Bitmap::CreateTexture(), yaze::gfx::CreateTilemap(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DecompressSuperDonkey(), yaze::editor::PixelEditorPanel::DisplayPalette(), yaze::editor::PixelEditorPanel::DisplaySheet(), yaze::Controller::DoRender(), yaze::editor::DungeonMapPanel::Draw(), yaze::editor::RoomGraphicsContent::Draw(), yaze::editor::RoomMatrixContent::Draw(), yaze::editor::OverworldCanvasRenderer::DrawAreaGraphics(), yaze::gui::DrawBitmap(), yaze::gui::DrawBitmapPreview(), yaze::editor::PixelEditorPanel::DrawCanvas(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::DungeonCanvasViewer::DrawConnectedRoomMatrix(), yaze::editor::SpriteEditor::DrawCurrentSheets(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::DungeonRoomSelector::DrawGroupedRoomList(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::MenuTilemapEditorUI::DrawOverlayControls(), yaze::editor::ScreenEditor::DrawOverworldMapEditor(), yaze::editor::SheetBrowserPanel::DrawPngTransfer(), yaze::editor::DungeonCanvasViewer::DrawProposalPreview(), yaze::editor::DungeonCanvasViewer::DrawRoomBackgroundLayers(), yaze::editor::DungeonRoomSelector::DrawRoomSelectorInternal(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::SheetBrowserPanel::DrawSheetGrid(), yaze::editor::LinkSpritePanel::DrawSheetThumbnail(), yaze::editor::DungeonCanvasViewer::DrawTextureDebugWindow(), yaze::editor::Tile16Editor::DrawTile16EditorWorkbenchColumn(), yaze::editor::OverworldCanvasRenderer::DrawTile8Selector(), yaze::editor::ScreenEditor::DrawTitleScreenBG1Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenBG2Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenCompositeCanvas(), yaze::editor::ScreenEditor::DrawTitleScreenEditor(), yaze::editor::Tile16EditSession::DrawToCurrentTile16Impl(), yaze::editor::PixelEditorPanel::EndSelection(), yaze::gfx::EnsureCompositeBitmapTextureQueued(), yaze::editor::MessageEditor::EnsureFontTexturesReady(), yaze::editor::OverworldMapTextureCoordinator::EnsureMapTexture(), yaze::editor::OverworldCanvasRenderer::EnsureOverlayLayer(), yaze::editor::internal::EnsureSheetTextureQueued(), yaze::cli::agent::tools::VisualAnalysisBase::ExtractTileAtPosition(), getArenaStatus(), getGfxSheetInfo(), yaze::editor::DungeonObjectSelector::GetOrCreatePreview(), yaze::editor::PixelEditorPanel::HandleCanvasInput(), yaze::cli::HandleGfxExportLegacy(), yaze::cli::HandleGfxImportLegacy(), yaze::editor::EditorManager::HandleSessionSwitched(), yaze::editor::Tile16EditSession::InitializeBitmaps(), yaze::editor::GraphicsEditor::Load(), yaze::editor::ScreenEditor::Load(), yaze::editor::OverworldEditor::Load(), yaze::editor::ScreenEditor::LoadBinaryGfx(), yaze::zelda3::OverworldMapScreen::LoadCustomMap(), yaze::zelda3::LoadDungeonMapGfxFromBinary(), yaze::zelda3::LoadDungeonMapTile16(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::OverworldEditor::LoadSpriteGraphics(), yaze::editor::Tile16EditSession::LoadTile16FromScratchSpaceImpl(), yaze::zelda3::TitleScreen::LoadTitleScreen(), yaze::gfx::PaletteManager::NotifyListeners(), yaze::Controller::OnEntry(), yaze::Controller::OnExit(), yaze::gfx::Bitmap::operator=(), yaze::gfx::Bitmap::operator=(), yaze::editor::TilePaintingManager::PaintPattern(), yaze::editor::PixelEditorPanel::PasteFromSystemClipboard(), yaze::editor::Tile16EditSession::PasteTile16FromClipboardImpl(), yaze::editor::GraphicsEditor::PlanGraphicsSave(), yaze::editor::GraphicsEditor::PrepareGraphicsSave(), yaze::editor::DungeonCanvasViewer::PrepareRoomStateForCanvas(), yaze::editor::Tile16EditSession::PreviewPaletteChange(), yaze::editor::DungeonEditorV2::ProcessDeferredTextures(), yaze::editor::OverworldMapTextureCoordinator::ProcessDeferredTextures(), yaze::editor::anonymous_namespace{usage_preview_view.cc}::QueueTexture(), yaze::editor::MenuTilemapEditorUI::RebuildRenderTextures(), yaze::editor::OverworldEditor::RebuildScratchBitmapFromTileData(), yaze::gfx::Bitmap::Reformat(), yaze::editor::Tile16EditSession::RefreshAllPalettes(), yaze::editor::RefreshArenaSheet(), yaze::editor::MapRefreshCoordinator::RefreshChildMapOnDemand(), yaze::editor::ScreenEditor::RefreshDungeonMapGraphicsFromSession(), yaze::editor::MessageEditor::RefreshFontAtlasBitmap(), yaze::editor::MapRefreshCoordinator::RefreshMultiAreaMapsSafely(), yaze::editor::MapRefreshCoordinator::RefreshPaletteUsers(), yaze::editor::RoomGraphicsContent::RefreshSheetPreviews(), yaze::editor::MapRefreshCoordinator::RefreshTile16Blockset(), yaze::editor::Tile16EditSession::RefreshTile16Blockset(), yaze::editor::ScreenEditor::RefreshTileCacheForReload(), yaze::editor::Tile16EditSession::RegenerateTile16BitmapFromROM(), yaze::editor::DungeonEditorV2::RegisterPaletteListener(), yaze::zelda3::TitleScreen::RenderBG1Layer(), yaze::zelda3::TitleScreen::RenderBG2Layer(), yaze::gui::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::zelda3::TitleScreen::RenderCompositeLayer(), yaze::editor::TileObjectHandler::RenderGhostPreviewBitmap(), yaze::editor::ObjectTileEditorPanel::RenderObjectPreview(), yaze::gui::RenderPreviewPanel(), yaze::zelda3::Room::RenderRoomGraphics(), yaze::editor::ObjectTileEditorPanel::RenderTile8Atlas(), yaze::gfx::RenderTilesBatch(), yaze::editor::TilePaintingManager::RenderUpdatedMapBitmap(), yaze::editor::RomSession::ResetGraphicsDisplay(), yaze::editor::GfxGroupEditor::ResetSheetPicker(), yaze::gfx::Bitmap::Resize(), yaze::editor::RoomCompositeOutput::Retire(), yaze::editor::DungeonObjectSelector::RetirePreviewCache(), yaze::test::ArenaTestSuite::RunArenaAllocationTest(), yaze::test::ArenaTestSuite::RunArenaCleanupTest(), yaze::test::IntegratedTestSuite::RunArenaIntegrityTest(), yaze::test::IntegratedTestSuite::RunArenaResourceManagementTest(), yaze::test::ArenaTestSuite::RunArenaResourceTrackingTest(), yaze::test::IntegratedTestSuite::RunGraphicsValidationTest(), yaze::test::PerformanceTestSuite::RunMemoryUsageTest(), yaze::test::PerformanceTestSuite::RunResourceLeakTest(), yaze::editor::GraphicsEditor::Save(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::gfx::PaletteManager::SaveGroup(), yaze::editor::Tile16EditSession::SaveTile16ToScratchSpace(), yaze::editor::SetGraphicsPreviewPalette(), yaze::platform::NullWindowBackend::Shutdown(), yaze::platform::SDL2WindowBackend::Shutdown(), yaze::core::ShutdownWindow(), yaze::editor::usage_preview::SnapshotArenaSheets(), yaze::editor::anonymous_namespace{map_refresh_coordinator.cc}::SyncCurrentGraphicsBitmapForTile16Editor(), yaze::editor::Tile16EditSession::UpdateBlocksetBitmap(), yaze::editor::MapRefreshCoordinator::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16EditSession::UpdateLivePreview(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::Bitmap::UpdateTexture(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16EditSession::UpdateTile8Palette(), yaze::gfx::UpdateTilemap(), yaze::editor::EditorManager::WantsContinuousFrames(), yaze::editor::DungeonEditorV2::~DungeonEditorV2(), yaze::editor::GfxGroupEditor::~GfxGroupEditor(), yaze::editor::OverworldEditor::~OverworldEditor(), yaze::editor::RoomCompositeOutput::~RoomCompositeOutput(), and yaze::editor::RoomGraphicsContent::~RoomGraphicsContent().

◆ Initialize()

void yaze::gfx::Arena::Initialize ( IRenderer * renderer)

Definition at line 17 of file arena.cc.

References is_shutdown_, and renderer_.

Referenced by yaze::Controller::OnEntry(), and yaze::Controller::OnExit().

◆ QueueTextureCommand()

void yaze::gfx::Arena::QueueTextureCommand ( TextureCommandType type,
Bitmap * bitmap )

Definition at line 39 of file arena.cc.

References yaze::gfx::Bitmap::generation(), and texture_command_queue_.

Referenced by yaze::editor::Tile16EditSession::ApplyDefinitions(), yaze::editor::MessageEditor::ApplyFontPalette(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::editor::Tile16EditSession::ApplyPaletteToCurrentTile16Bitmap(), yaze::gui::CanvasUtils::ApplyPendingPaletteUpdates(), yaze::gui::PaletteEditorWidget::ApplyROMPalette(), yaze::editor::LinkSpritePanel::ApplySelectedPalette(), yaze::zelda3::Inventory::BuildTileset(), yaze::zelda3::TitleScreen::BuildTileset(), yaze::editor::CanvasNavigationManager::CheckForCurrentMap(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::editor::Tile16EditSession::CommitChangesToBlockset(), yaze::editor::Tile16EditSession::CopyTile16ToAtlas(), yaze::editor::Tile16EditSession::CopyTile16ToClipboard(), yaze::zelda3::OverworldMapScreen::Create(), yaze::zelda3::Inventory::Create(), yaze::gfx::Bitmap::CreateTexture(), yaze::gfx::CreateTilemap(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DecompressSuperDonkey(), yaze::editor::PixelEditorPanel::DisplaySheet(), yaze::editor::OverworldCanvasRenderer::DrawAreaGraphics(), yaze::gui::DrawBitmap(), yaze::gui::DrawBitmapPreview(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::MenuTilemapEditorUI::DrawOverlayControls(), yaze::editor::ScreenEditor::DrawOverworldMapEditor(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::LinkSpritePanel::DrawSheetThumbnail(), yaze::editor::DungeonCanvasViewer::DrawTextureDebugWindow(), yaze::editor::Tile16Editor::DrawTile16EditorWorkbenchColumn(), yaze::editor::ScreenEditor::DrawTitleScreenBG1Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenBG2Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenCompositeCanvas(), yaze::editor::ScreenEditor::DrawTitleScreenEditor(), yaze::editor::Tile16EditSession::DrawToCurrentTile16Impl(), yaze::gfx::EnsureCompositeBitmapTextureQueued(), yaze::editor::MessageEditor::EnsureFontTexturesReady(), yaze::editor::OverworldMapTextureCoordinator::EnsureMapTexture(), yaze::editor::OverworldCanvasRenderer::EnsureOverlayLayer(), yaze::editor::internal::EnsureSheetTextureQueued(), EvictLRUSheets(), yaze::editor::DungeonObjectSelector::GetOrCreatePreview(), GetSheetWithCache(), yaze::editor::Tile16EditSession::InitializeBitmaps(), yaze::editor::GraphicsEditor::Load(), yaze::editor::ScreenEditor::Load(), yaze::editor::ScreenEditor::LoadBinaryGfx(), yaze::zelda3::OverworldMapScreen::LoadCustomMap(), yaze::zelda3::LoadDungeonMapGfxFromBinary(), yaze::zelda3::LoadDungeonMapTile16(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::OverworldEditor::LoadSpriteGraphics(), yaze::editor::Tile16EditSession::LoadTile16FromScratchSpaceImpl(), yaze::zelda3::TitleScreen::LoadTitleScreen(), NotifySheetModified(), yaze::gfx::Bitmap::operator=(), yaze::editor::TilePaintingManager::PaintPattern(), yaze::editor::Tile16EditSession::PasteTile16FromClipboardImpl(), yaze::editor::Tile16EditSession::PreviewPaletteChange(), yaze::editor::anonymous_namespace{usage_preview_view.cc}::QueueTexture(), yaze::editor::MenuTilemapEditorUI::RebuildRenderTextures(), yaze::editor::OverworldEditor::RebuildScratchBitmapFromTileData(), yaze::editor::Tile16EditSession::RefreshAllPalettes(), yaze::editor::MapRefreshCoordinator::RefreshChildMapOnDemand(), yaze::editor::ScreenEditor::RefreshDungeonMapGraphicsFromSession(), yaze::editor::MessageEditor::RefreshFontAtlasBitmap(), yaze::editor::MapRefreshCoordinator::RefreshMultiAreaMapsSafely(), yaze::editor::MapRefreshCoordinator::RefreshPaletteUsers(), yaze::editor::MapRefreshCoordinator::RefreshTile16Blockset(), yaze::editor::Tile16EditSession::RefreshTile16Blockset(), yaze::editor::ScreenEditor::RefreshTileCacheForReload(), yaze::editor::Tile16EditSession::RegenerateTile16BitmapFromROM(), yaze::zelda3::TitleScreen::RenderBG1Layer(), yaze::zelda3::TitleScreen::RenderBG2Layer(), yaze::gui::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::zelda3::TitleScreen::RenderCompositeLayer(), yaze::editor::TileObjectHandler::RenderGhostPreviewBitmap(), yaze::gui::RenderPreviewPanel(), yaze::zelda3::Room::RenderRoomGraphics(), yaze::gfx::RenderTilesBatch(), yaze::editor::TilePaintingManager::RenderUpdatedMapBitmap(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::Tile16EditSession::SaveTile16ToScratchSpace(), yaze::editor::anonymous_namespace{map_refresh_coordinator.cc}::SyncCurrentGraphicsBitmapForTile16Editor(), yaze::editor::Tile16EditSession::UpdateBlocksetBitmap(), yaze::editor::MapRefreshCoordinator::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16EditSession::UpdateLivePreview(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::Bitmap::UpdateTexture(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16EditSession::UpdateTile8Palette(), and yaze::gfx::UpdateTilemap().

Here is the call graph for this function:

◆ HasPendingTextureCommand()

bool yaze::gfx::Arena::HasPendingTextureCommand ( TextureCommandType type,
const Bitmap * bitmap ) const

Definition at line 45 of file arena.cc.

References yaze::gfx::Bitmap::generation(), and texture_command_queue_.

Referenced by yaze::gfx::EnsureCompositeBitmapTextureQueued().

Here is the call graph for this function:

◆ ProcessTextureQueue()

◆ ClearTextureQueue()

void yaze::gfx::Arena::ClearTextureQueue ( )

Definition at line 59 of file arena.cc.

References texture_command_queue_.

◆ RetireBitmap()

◆ DrainRetiredBitmaps()

size_t yaze::gfx::Arena::DrainRetiredBitmaps ( IRenderer * renderer)

Destroy texture handles retired earlier in the frame.

Call only after ImGui rendering/Present has completed, or immediately before renderer shutdown. Failed destroys remain queued for a later call.

Returns
Number of handles successfully destroyed.

Definition at line 91 of file arena.cc.

References yaze::gfx::IRenderer::DestroyTexture(), LOG_ERROR, renderer_, and retired_texture_handles_.

Referenced by yaze::Controller::DoRender(), yaze::Controller::OnExit(), and Shutdown().

Here is the call graph for this function:

◆ HasPendingTextures()

bool yaze::gfx::Arena::HasPendingTextures ( ) const
inline

Check if there are pending textures to process.

Returns
true if texture queue has pending commands

Definition at line 92 of file arena.h.

References texture_command_queue_.

Referenced by yaze::editor::EditorManager::WantsContinuousFrames().

◆ ProcessSingleTexture()

bool yaze::gfx::Arena::ProcessSingleTexture ( IRenderer * renderer)

Process a single texture command for frame-budget-aware loading.

Parameters
rendererThe renderer to use for texture operations
Returns
true if a texture was processed, false if queue was empty

Definition at line 112 of file arena.cc.

References CREATE, yaze::gfx::IRenderer::CreateTexture(), DESTROY, yaze::gfx::IRenderer::DestroyTexture(), LOG_DEBUG, LOG_ERROR, renderer_, texture_command_queue_, UPDATE, and yaze::gfx::IRenderer::UpdateTexture().

Referenced by ProcessTextureQueueWithBudget().

Here is the call graph for this function:

◆ ProcessTextureQueueWithBudget()

bool yaze::gfx::Arena::ProcessTextureQueueWithBudget ( IRenderer * renderer,
float budget_ms )

Process texture queue with a time budget.

Processes texture commands until either the queue is empty or the time budget is exceeded. Uses microsecond precision timing to avoid overshooting frame budgets.

Parameters
rendererThe renderer to use for texture operations
budget_msMaximum time in milliseconds to spend processing
Returns
true if queue is now empty, false if more work remains

Example usage for 60 FPS (16.67ms frame time): // Allow up to 4ms for texture loading per frame arena.ProcessTextureQueueWithBudget(renderer, 4.0f);

Definition at line 372 of file arena.cc.

References yaze::gfx::Arena::TextureQueueStats::avg_texture_time_ms, yaze::gfx::Arena::TextureQueueStats::frames_with_work, LOG_DEBUG, yaze::gfx::Arena::TextureQueueStats::max_frame_time_ms, ProcessSingleTexture(), renderer_, texture_command_queue_, texture_queue_stats_, yaze::gfx::Arena::TextureQueueStats::textures_processed, and yaze::gfx::Arena::TextureQueueStats::total_time_ms.

Referenced by yaze::Controller::DoRender().

Here is the call graph for this function:

◆ GetTextureQueueStats()

const TextureQueueStats & yaze::gfx::Arena::GetTextureQueueStats ( ) const
inline

Get texture queue processing statistics.

Returns
Reference to current statistics

Definition at line 141 of file arena.h.

References texture_queue_stats_.

◆ ResetTextureQueueStats()

void yaze::gfx::Arena::ResetTextureQueueStats ( )
inline

Reset texture queue statistics.

Definition at line 148 of file arena.h.

References yaze::gfx::Arena::TextureQueueStats::Reset(), and texture_queue_stats_.

Here is the call graph for this function:

◆ AllocateSurface()

SDL_Surface * yaze::gfx::Arena::AllocateSurface ( int width,
int height,
int depth,
int format )

◆ FreeSurface()

◆ Shutdown()

◆ GetTextureCount()

size_t yaze::gfx::Arena::GetTextureCount ( ) const
inline

Definition at line 157 of file arena.h.

References textures_.

◆ GetSurfaceCount()

size_t yaze::gfx::Arena::GetSurfaceCount ( ) const
inline

Definition at line 158 of file arena.h.

References surfaces_.

◆ GetPooledTextureCount()

size_t yaze::gfx::Arena::GetPooledTextureCount ( ) const
inline

Definition at line 159 of file arena.h.

References yaze::gfx::Arena::TexturePool::available_textures_, and texture_pool_.

◆ GetPooledSurfaceCount()

size_t yaze::gfx::Arena::GetPooledSurfaceCount ( ) const
inline

Definition at line 162 of file arena.h.

References yaze::gfx::Arena::SurfacePool::available_surfaces_, and surface_pool_.

◆ texture_command_queue_size()

size_t yaze::gfx::Arena::texture_command_queue_size ( ) const
inline

Definition at line 165 of file arena.h.

References texture_command_queue_.

◆ retired_texture_handle_count()

size_t yaze::gfx::Arena::retired_texture_handle_count ( ) const
inline

Definition at line 168 of file arena.h.

References retired_texture_handles_.

◆ gfx_sheets()

◆ gfx_sheet()

auto yaze::gfx::Arena::gfx_sheet ( int i)
inline

Get a specific graphics sheet by index.

Parameters
iSheet index (0-222)
Returns
Copy of the Bitmap at index i, or empty Bitmap if out of bounds

Definition at line 185 of file arena.h.

References gfx_sheets().

Here is the call graph for this function:

◆ mutable_gfx_sheet()

auto yaze::gfx::Arena::mutable_gfx_sheet ( int i)
inline

Get mutable reference to a specific graphics sheet.

Parameters
iSheet index (0-222)
Returns
Pointer to mutable Bitmap at index i, or nullptr if out of bounds

Definition at line 196 of file arena.h.

References gfx_sheets().

Here is the call graph for this function:

◆ mutable_gfx_sheets()

auto yaze::gfx::Arena::mutable_gfx_sheets ( )
inline

Get mutable reference to all graphics sheets.

Returns
Pointer to mutable array of 223 Bitmap objects

Definition at line 206 of file arena.h.

References active_gfx_sheets_.

Referenced by yaze::editor::PixelEditorPanel::DisplaySheet(), yaze::editor::PixelEditorPanel::HandleCanvasInput(), and yaze::editor::RefreshArenaSheet().

◆ BindGraphicsSheets()

void yaze::gfx::Arena::BindGraphicsSheets ( GraphicsSheets * sheets,
const void * owner )

Definition at line 522 of file arena.cc.

References active_gfx_sheets_, ClearSheetCache(), gfx_sheets_, and gfx_sheets_owner_.

Referenced by yaze::editor::RomSession::ActivateGraphicsDisplay(), and yaze::editor::EditorManager::HandleSessionSwitched().

Here is the call graph for this function:

◆ set_gfx_sheets_owner()

void yaze::gfx::Arena::set_gfx_sheets_owner ( const void * owner)
inline

Definition at line 215 of file arena.h.

References gfx_sheets_owner_.

◆ gfx_sheets_owner()

const void * yaze::gfx::Arena::gfx_sheets_owner ( ) const
inline

◆ NotifySheetModified()

void yaze::gfx::Arena::NotifySheetModified ( int sheet_index)

Notify Arena that a graphics sheet has been modified.

Parameters
sheet_indexIndex of the modified sheet (0-222)

This ensures textures are updated across all editors

Definition at line 532 of file arena.cc.

References CREATE, gfx_sheets(), LOG_DEBUG, LOG_WARN, QueueTextureCommand(), and UPDATE.

Referenced by yaze::editor::RefreshArenaSheet().

Here is the call graph for this function:

◆ NotifyPaletteModified()

void yaze::gfx::Arena::NotifyPaletteModified ( const std::string & group_name,
int palette_index = -1 )

Notify all listeners that a palette has been modified.

Parameters
group_nameThe palette group name (e.g., "ow_main", "dungeon_main")
palette_indexSpecific palette index, or -1 for entire group

This triggers bitmap refresh in editors using these palettes

Definition at line 562 of file arena.cc.

References LOG_DEBUG, LOG_ERROR, and palette_listeners_.

Referenced by yaze::gfx::PaletteManager::ApplyPreviewChanges(), yaze::gfx::PaletteManager::NotifyListeners(), and yaze::gfx::PaletteManager::SaveGroup().

◆ RegisterPaletteListener()

int yaze::gfx::Arena::RegisterPaletteListener ( PaletteChangeCallback callback)

Register a callback for palette change notifications.

Parameters
callbackFunction to call when palettes change
Returns
Unique ID for this listener (use to unregister)

Definition at line 580 of file arena.cc.

References LOG_DEBUG, next_palette_listener_id_, and palette_listeners_.

Referenced by yaze::editor::OverworldEditor::Load(), and yaze::editor::DungeonEditorV2::RegisterPaletteListener().

◆ UnregisterPaletteListener()

void yaze::gfx::Arena::UnregisterPaletteListener ( int listener_id)

Unregister a palette change listener.

Parameters
listener_idThe ID returned from RegisterPaletteListener

Definition at line 587 of file arena.cc.

References LOG_DEBUG, and palette_listeners_.

Referenced by yaze::editor::OverworldEditor::Clear(), yaze::editor::DungeonEditorV2::~DungeonEditorV2(), and yaze::editor::OverworldEditor::~OverworldEditor().

◆ bg1()

auto & yaze::gfx::Arena::bg1 ( )
inline

Get reference to background layer 1 buffer.

Returns
Reference to BackgroundBuffer for layer 1

Definition at line 260 of file arena.h.

References bg1_.

◆ bg2()

auto & yaze::gfx::Arena::bg2 ( )
inline

Get reference to background layer 2 buffer.

Returns
Reference to BackgroundBuffer for layer 2

Definition at line 266 of file arena.h.

References bg2_.

◆ TouchSheet()

void yaze::gfx::Arena::TouchSheet ( int sheet_index)

Mark a graphics sheet as recently accessed.

Parameters
sheet_indexIndex of the sheet being accessed (0-222)

Call this when a sheet is displayed or its texture is used. This moves the sheet to the front of the LRU list.

Definition at line 597 of file arena.cc.

References sheet_lru_list_, and sheet_lru_map_.

Referenced by GetSheetWithCache().

◆ GetSheetWithCache()

Bitmap * yaze::gfx::Arena::GetSheetWithCache ( int sheet_index)

Get a sheet with automatic LRU tracking and texture creation.

Parameters
sheet_indexIndex of the sheet (0-222)
Returns
Pointer to the Bitmap, or nullptr if out of bounds

This is the preferred way to access sheets when you need their textures. It automatically:

  • Marks the sheet as recently used
  • Queues texture creation if not yet created
  • Evicts LRU sheets if cache is full

Definition at line 615 of file arena.cc.

References CREATE, yaze::gfx::Arena::SheetCacheStats::current_size, EvictLRUSheets(), gfx_sheets(), yaze::gfx::Arena::SheetCacheStats::hits, yaze::gfx::Arena::SheetCacheStats::misses, QueueTextureCommand(), sheet_cache_max_size_, sheet_cache_stats_, sheet_lru_map_, yaze::gfx::Bitmap::texture(), and TouchSheet().

◆ SetSheetCacheSize()

void yaze::gfx::Arena::SetSheetCacheSize ( size_t max_size)

Set the maximum number of sheet textures to keep cached.

Parameters
max_sizeMaximum cache size (default 64, min 16, max 223)

When more sheets than this have textures, the least recently used textures will be destroyed to free GPU memory.

Definition at line 648 of file arena.cc.

References EvictLRUSheets(), LOG_INFO, sheet_cache_max_size_, and sheet_lru_map_.

Here is the call graph for this function:

◆ GetSheetCacheSize()

size_t yaze::gfx::Arena::GetSheetCacheSize ( ) const
inline

Get current sheet cache size limit.

Returns
Maximum number of cached sheet textures

Definition at line 305 of file arena.h.

References sheet_cache_max_size_.

◆ GetCachedSheetCount()

size_t yaze::gfx::Arena::GetCachedSheetCount ( ) const
inline

Get number of sheets currently with textures.

Returns
Count of sheets that have active textures

Definition at line 311 of file arena.h.

References sheet_lru_map_.

◆ EvictLRUSheets()

size_t yaze::gfx::Arena::EvictLRUSheets ( size_t count = 0)

Evict least recently used sheet textures.

Parameters
countNumber of textures to evict (0 = evict until under max)
Returns
Number of textures actually evicted

Useful for proactive memory management before loading new content.

Definition at line 660 of file arena.cc.

References yaze::gfx::Arena::SheetCacheStats::current_size, DESTROY, yaze::gfx::Arena::SheetCacheStats::evictions, gfx_sheets(), LOG_DEBUG, QueueTextureCommand(), sheet_cache_max_size_, sheet_cache_stats_, sheet_lru_list_, and sheet_lru_map_.

Referenced by GetSheetWithCache(), and SetSheetCacheSize().

Here is the call graph for this function:

◆ ClearSheetCache()

void yaze::gfx::Arena::ClearSheetCache ( )

Clear all sheet texture cache tracking.

Does NOT destroy textures - use this when manually managing textures or during shutdown.

Definition at line 697 of file arena.cc.

References yaze::gfx::Arena::SheetCacheStats::current_size, LOG_DEBUG, sheet_cache_stats_, sheet_lru_list_, and sheet_lru_map_.

Referenced by BindGraphicsSheets(), and Shutdown().

◆ GetSheetCacheStats()

const SheetCacheStats & yaze::gfx::Arena::GetSheetCacheStats ( ) const
inline

Get sheet cache statistics.

Returns
Reference to current statistics

Definition at line 356 of file arena.h.

References sheet_cache_stats_.

◆ ResetSheetCacheStats()

void yaze::gfx::Arena::ResetSheetCacheStats ( )
inline

Reset sheet cache statistics.

Definition at line 363 of file arena.h.

References yaze::gfx::Arena::SheetCacheStats::Reset(), and sheet_cache_stats_.

Here is the call graph for this function:

Member Data Documentation

◆ bg1_

BackgroundBuffer yaze::gfx::Arena::bg1_
private

Definition at line 368 of file arena.h.

Referenced by bg1().

◆ bg2_

BackgroundBuffer yaze::gfx::Arena::bg2_
private

Definition at line 369 of file arena.h.

Referenced by bg2().

◆ kTilesPerRow

constexpr int yaze::gfx::Arena::kTilesPerRow = 64
staticconstexprprivate

Definition at line 371 of file arena.h.

◆ kTilesPerColumn

constexpr int yaze::gfx::Arena::kTilesPerColumn = 64
staticconstexprprivate

Definition at line 372 of file arena.h.

◆ kTotalTiles

constexpr int yaze::gfx::Arena::kTotalTiles = kTilesPerRow * kTilesPerColumn
staticconstexprprivate

Definition at line 373 of file arena.h.

◆ layer1_buffer_

std::array<uint16_t, kTotalTiles> yaze::gfx::Arena::layer1_buffer_
private

Definition at line 375 of file arena.h.

Referenced by Arena().

◆ layer2_buffer_

std::array<uint16_t, kTotalTiles> yaze::gfx::Arena::layer2_buffer_
private

Definition at line 376 of file arena.h.

Referenced by Arena().

◆ gfx_sheets_

GraphicsSheets yaze::gfx::Arena::gfx_sheets_
private

Definition at line 378 of file arena.h.

Referenced by BindGraphicsSheets().

◆ active_gfx_sheets_

GraphicsSheets* yaze::gfx::Arena::active_gfx_sheets_ = &gfx_sheets_
private

Definition at line 379 of file arena.h.

Referenced by BindGraphicsSheets(), gfx_sheets(), and mutable_gfx_sheets().

◆ gfx_sheets_owner_

const void* yaze::gfx::Arena::gfx_sheets_owner_ = nullptr
private

Definition at line 380 of file arena.h.

Referenced by BindGraphicsSheets(), gfx_sheets_owner(), and set_gfx_sheets_owner().

◆ textures_

std::unordered_map<TextureHandle, std::unique_ptr<SDL_Texture, util::SDL_Texture_Deleter> > yaze::gfx::Arena::textures_
private

Definition at line 384 of file arena.h.

Referenced by GetTextureCount(), and Shutdown().

◆ surfaces_

std::unordered_map<SDL_Surface*, std::unique_ptr<SDL_Surface, util::SDL_Surface_Deleter> > yaze::gfx::Arena::surfaces_
private

Definition at line 388 of file arena.h.

Referenced by AllocateSurface(), FreeSurface(), GetSurfaceCount(), RetireBitmap(), and Shutdown().

◆ texture_pool_

struct yaze::gfx::Arena::TexturePool yaze::gfx::Arena::texture_pool_
private

Referenced by GetPooledTextureCount(), and Shutdown().

◆ surface_pool_

struct yaze::gfx::Arena::SurfacePool yaze::gfx::Arena::surface_pool_
private

◆ texture_command_queue_

◆ retired_texture_handles_

std::vector<TextureHandle> yaze::gfx::Arena::retired_texture_handles_
private

Definition at line 405 of file arena.h.

Referenced by DrainRetiredBitmaps(), RetireBitmap(), retired_texture_handle_count(), and Shutdown().

◆ renderer_

IRenderer* yaze::gfx::Arena::renderer_ = nullptr
private

◆ is_shutdown_

bool yaze::gfx::Arena::is_shutdown_ = false
private

Definition at line 407 of file arena.h.

Referenced by Initialize(), RetireBitmap(), and Shutdown().

◆ texture_queue_stats_

TextureQueueStats yaze::gfx::Arena::texture_queue_stats_
private

◆ palette_listeners_

std::unordered_map<int, PaletteChangeCallback> yaze::gfx::Arena::palette_listeners_
private

◆ next_palette_listener_id_

int yaze::gfx::Arena::next_palette_listener_id_ = 1
private

Definition at line 412 of file arena.h.

Referenced by RegisterPaletteListener().

◆ sheet_lru_list_

std::list<int> yaze::gfx::Arena::sheet_lru_list_
private

Definition at line 416 of file arena.h.

Referenced by ClearSheetCache(), EvictLRUSheets(), and TouchSheet().

◆ sheet_lru_map_

std::unordered_map<int, std::list<int>::iterator> yaze::gfx::Arena::sheet_lru_map_
private

◆ sheet_cache_max_size_

size_t yaze::gfx::Arena::sheet_cache_max_size_ = 64
private

Definition at line 419 of file arena.h.

Referenced by EvictLRUSheets(), GetSheetCacheSize(), GetSheetWithCache(), and SetSheetCacheSize().

◆ sheet_cache_stats_

SheetCacheStats yaze::gfx::Arena::sheet_cache_stats_
private

The documentation for this class was generated from the following files: