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 PaletteChangeCallback
 

Public Member Functions

void Initialize (IRenderer *renderer)
 
 ~Arena ()
 
void QueueTextureCommand (TextureCommandType type, Bitmap *bitmap)
 
void ProcessTextureQueue (IRenderer *renderer)
 
void ClearTextureQueue ()
 
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 TextureQueueStatsGetTextureQueueStats () 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
 
std::array< gfx::Bitmap, 223 > & gfx_sheets ()
 Get reference to all graphics 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 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.
 
BitmapGetSheetWithCache (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 SheetCacheStatsGetSheetCacheStats () const
 Get sheet cache statistics.
 
void ResetSheetCacheStats ()
 Reset sheet cache statistics.
 

Static Public Member Functions

static ArenaGet ()
 

Private Member Functions

 Arena ()
 

Private Attributes

BackgroundBuffer bg1_
 
BackgroundBuffer bg2_
 
std::array< uint16_t, kTotalTileslayer1_buffer_
 
std::array< uint16_t, kTotalTileslayer2_buffer_
 
std::array< gfx::Bitmap, 223 > gfx_sheets_
 
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< TextureCommandtexture_command_queue_
 
IRendererrenderer_ = nullptr
 
TextureQueueStats texture_queue_stats_
 
std::unordered_map< int, PaletteChangeCallbackpalette_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

◆ 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 192 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 31 of file arena.cc.

References Shutdown().

Here is the call graph for this function:

◆ Arena()

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

Definition at line 26 of file arena.cc.

References layer1_buffer_, and layer2_buffer_.

Member Function Documentation

◆ Get()

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

Definition at line 21 of file arena.cc.

Referenced by yaze::editor::PixelEditorPanel::ApplyBrush(), yaze::editor::PixelEditorPanel::ApplyEraser(), yaze::editor::PixelEditorPanel::ApplyEyedropper(), yaze::editor::PixelEditorPanel::ApplyFill(), yaze::editor::MessageEditor::ApplyFontPalette(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::editor::PaletteControlsPanel::ApplyPaletteToAllSheets(), yaze::editor::Tile16Editor::ApplyPaletteToCurrentTile16Bitmap(), yaze::editor::PaletteControlsPanel::ApplyPaletteToSheet(), yaze::editor::PixelEditorPanel::ApplyPencil(), 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::CanvasNavigationManager::CheckForCurrentMap(), yaze::editor::OverworldEditor::Clear(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::test::TestManager::CollectResourceStats(), yaze::editor::Tile16Editor::CommitChangesToBlockset(), yaze::editor::Tile16Editor::CopyTile16ToAtlas(), yaze::editor::Tile16Editor::CopyTile16ToClipboard(), 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::Controller::DoRender(), yaze::editor::DungeonRoomGraphicsPanel::Draw(), yaze::editor::OverworldCanvasRenderer::DrawAreaGraphics(), yaze::gui::DrawBitmap(), yaze::gui::DrawBitmapPreview(), yaze::editor::GfxGroupEditor::DrawBlocksetViewer(), yaze::editor::PixelEditorPanel::DrawCanvas(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::PixelEditorPanel::DrawColorPicker(), yaze::editor::SpriteEditor::DrawCurrentSheets(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::PixelEditorPanel::DrawLine(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::PixelEditorPanel::DrawMiniMap(), yaze::editor::ScreenEditor::DrawOverworldMapEditor(), yaze::editor::PixelEditorPanel::DrawRectangle(), yaze::editor::DungeonCanvasViewer::DrawRoomBackgroundLayers(), yaze::editor::DungeonObjectSelector::DrawRoomGraphics(), yaze::editor::GfxGroupEditor::DrawRoomsetViewer(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::SheetBrowserPanel::DrawSheetGrid(), yaze::editor::LinkSpritePanel::DrawSheetThumbnail(), yaze::editor::GfxGroupEditor::DrawSpritesetViewer(), yaze::editor::OverworldCanvasRenderer::DrawTile8Selector(), yaze::editor::ScreenEditor::DrawTitleScreenBG1Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenBG2Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenCompositeCanvas(), yaze::editor::ScreenEditor::DrawTitleScreenEditor(), yaze::editor::Tile16Editor::DrawToCurrentTile16(), yaze::editor::PixelEditorPanel::EndSelection(), yaze::editor::MessageEditor::EnsureFontTexturesReady(), yaze::editor::EditorManager::EnsureGameDataLoaded(), yaze::editor::OverworldEditor::EnsureMapTexture(), yaze::cli::agent::tools::VisualAnalysisBase::ExtractTileAtPosition(), yaze::editor::PixelEditorPanel::FinalizeUndoAction(), getArenaStatus(), getGfxSheetInfo(), yaze::editor::DungeonObjectSelector::GetOrCreatePreview(), yaze::editor::PixelEditorPanel::HandleCanvasInput(), yaze::cli::HandleGfxExportLegacy(), yaze::cli::HandleGfxImportLegacy(), yaze::editor::Tile16Editor::Initialize(), yaze::editor::GraphicsEditor::Load(), yaze::editor::ScreenEditor::Load(), yaze::editor::OverworldEditor::Load(), yaze::editor::EditorManager::LoadAssets(), yaze::editor::ScreenEditor::LoadBinaryGfx(), yaze::zelda3::OverworldMapScreen::LoadCustomMap(), yaze::zelda3::LoadDungeonMapGfxFromBinary(), yaze::zelda3::LoadDungeonMapTile16(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::OverworldEditor::LoadSpriteGraphics(), yaze::editor::SpriteEditor::LoadSpriteGraphicsBuffer(), yaze::editor::Tile16Editor::LoadTile16FromScratchSpace(), yaze::editor::Tile16Editor::LoadTile8(), yaze::zelda3::TitleScreen::LoadTitleScreen(), yaze::Controller::OnEntry(), yaze::editor::ObjectEditorPanel::OpenStaticObjectEditor(), yaze::gfx::Bitmap::operator=(), yaze::gfx::Bitmap::operator=(), yaze::editor::PixelEditorPanel::PasteSelection(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::DungeonEditorV2::ProcessDeferredTextures(), yaze::editor::OverworldEditor::ProcessDeferredTextures(), yaze::editor::GraphicsPixelEditAction::Redo(), yaze::gfx::Bitmap::Reformat(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::MapRefreshCoordinator::RefreshChildMapOnDemand(), yaze::editor::MessageEditor::RefreshFontAtlasBitmap(), yaze::editor::MapRefreshCoordinator::RefreshMapPalette(), yaze::editor::MapRefreshCoordinator::RefreshMultiAreaMapsSafely(), yaze::editor::MapRefreshCoordinator::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::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::gfx::Bitmap::Resize(), yaze::editor::Tile16Editor::RestoreFromSnapshot(), 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::EditorManager::SaveRom(), yaze::editor::Tile16Editor::SaveTile16ToScratchSpace(), yaze::editor::PixelEditorPanel::SaveUndoState(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::platform::NullWindowBackend::Shutdown(), yaze::platform::SDL2WindowBackend::Shutdown(), yaze::core::ShutdownWindow(), yaze::editor::GraphicsPixelEditAction::Undo(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::MapRefreshCoordinator::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16Editor::UpdateLivePreview(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::Bitmap::UpdateTexture(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16Editor::UpdateTile16Edit(), yaze::editor::Tile16Editor::UpdateTile8Palette(), and yaze::gfx::UpdateTilemap().

◆ Initialize()

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

Definition at line 17 of file arena.cc.

References renderer_.

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

◆ QueueTextureCommand()

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

Definition at line 36 of file arena.cc.

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

Referenced by yaze::editor::MessageEditor::ApplyFontPalette(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::editor::Tile16Editor::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::Tile16Editor::CommitChangesToBlockset(), yaze::editor::Tile16Editor::CopyTile16ToAtlas(), yaze::editor::Tile16Editor::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::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::ScreenEditor::DrawOverworldMapEditor(), yaze::editor::DungeonCanvasViewer::DrawRoomBackgroundLayers(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::LinkSpritePanel::DrawSheetThumbnail(), yaze::editor::ScreenEditor::DrawTitleScreenBG1Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenBG2Canvas(), yaze::editor::ScreenEditor::DrawTitleScreenCompositeCanvas(), yaze::editor::ScreenEditor::DrawTitleScreenEditor(), yaze::editor::Tile16Editor::DrawToCurrentTile16(), yaze::editor::MessageEditor::EnsureFontTexturesReady(), yaze::editor::OverworldEditor::EnsureMapTexture(), EvictLRUSheets(), yaze::editor::DungeonObjectSelector::GetOrCreatePreview(), GetSheetWithCache(), yaze::editor::Tile16Editor::Initialize(), 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::Tile16Editor::LoadTile16FromScratchSpace(), yaze::editor::Tile16Editor::LoadTile8(), yaze::zelda3::TitleScreen::LoadTitleScreen(), NotifySheetModified(), yaze::editor::ObjectEditorPanel::OpenStaticObjectEditor(), yaze::gfx::Bitmap::operator=(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::MapRefreshCoordinator::RefreshChildMapOnDemand(), yaze::editor::MessageEditor::RefreshFontAtlasBitmap(), yaze::editor::MapRefreshCoordinator::RefreshMapPalette(), yaze::editor::MapRefreshCoordinator::RefreshMultiAreaMapsSafely(), yaze::editor::MapRefreshCoordinator::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::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::Tile16Editor::RestoreFromSnapshot(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::Tile16Editor::SaveTile16ToScratchSpace(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::MapRefreshCoordinator::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16Editor::UpdateLivePreview(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::Bitmap::UpdateTexture(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16Editor::UpdateTile16Edit(), yaze::editor::Tile16Editor::UpdateTile8Palette(), and yaze::gfx::UpdateTilemap().

Here is the call graph for this function:

◆ ProcessTextureQueue()

◆ ClearTextureQueue()

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

Definition at line 42 of file arena.cc.

References texture_command_queue_.

◆ 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 70 of file arena.h.

References texture_command_queue_.

◆ 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 46 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 261 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 119 of file arena.h.

References texture_queue_stats_.

◆ ResetTextureQueueStats()

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

Reset texture queue statistics.

Definition at line 126 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 135 of file arena.h.

References textures_.

◆ GetSurfaceCount()

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

Definition at line 136 of file arena.h.

References surfaces_.

◆ GetPooledTextureCount()

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

Definition at line 137 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 140 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 143 of file arena.h.

References texture_command_queue_.

◆ 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 159 of file arena.h.

References gfx_sheets_.

◆ 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 169 of file arena.h.

References gfx_sheets_.

◆ mutable_gfx_sheets()

◆ NotifySheetModified()

◆ 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 423 of file arena.cc.

References LOG_DEBUG, LOG_ERROR, and palette_listeners_.

Referenced by yaze::gfx::PaletteManager::ApplyPreviewChanges(), 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 441 of file arena.cc.

References LOG_DEBUG, next_palette_listener_id_, and palette_listeners_.

Referenced by yaze::editor::OverworldEditor::Load().

◆ UnregisterPaletteListener()

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

Unregister a palette change listener.

Parameters
listener_idThe ID returned from RegisterPaletteListener

Definition at line 448 of file arena.cc.

References LOG_DEBUG, and palette_listeners_.

Referenced by yaze::editor::OverworldEditor::Clear().

◆ bg1()

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

Get reference to background layer 1 buffer.

Returns
Reference to BackgroundBuffer for layer 1

Definition at line 222 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 228 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 458 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 476 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().

Here is the call graph for this function:

◆ 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 509 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 267 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 273 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 521 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 558 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 Shutdown().

◆ GetSheetCacheStats()

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

Get sheet cache statistics.

Returns
Reference to current statistics

Definition at line 318 of file arena.h.

References sheet_cache_stats_.

◆ ResetSheetCacheStats()

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

Reset sheet cache statistics.

Definition at line 325 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 330 of file arena.h.

Referenced by bg1().

◆ bg2_

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

Definition at line 331 of file arena.h.

Referenced by bg2().

◆ kTilesPerRow

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

Definition at line 333 of file arena.h.

◆ kTilesPerColumn

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

Definition at line 334 of file arena.h.

◆ kTotalTiles

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

Definition at line 335 of file arena.h.

◆ layer1_buffer_

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

Definition at line 337 of file arena.h.

Referenced by Arena().

◆ layer2_buffer_

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

Definition at line 338 of file arena.h.

Referenced by Arena().

◆ gfx_sheets_

std::array<gfx::Bitmap, 223> yaze::gfx::Arena::gfx_sheets_
private

◆ textures_

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

Definition at line 344 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 348 of file arena.h.

Referenced by AllocateSurface(), FreeSurface(), GetSurfaceCount(), 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_

◆ renderer_

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

◆ 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 370 of file arena.h.

Referenced by RegisterPaletteListener().

◆ sheet_lru_list_

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

Definition at line 374 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 377 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: