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>

Collaboration diagram for yaze::gfx::Arena:

Classes

struct  SurfacePool
 
struct  TextureCommand
 
struct  TexturePool
 

Public Types

enum class  TextureCommandType { CREATE , UPDATE , DESTROY }
 

Public Member Functions

void Initialize (IRenderer *renderer)
 
 ~Arena ()
 
void QueueTextureCommand (TextureCommandType type, Bitmap *bitmap)
 
void ProcessTextureQueue (IRenderer *renderer)
 
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
 
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.
 
auto & bg1 ()
 Get reference to background layer 1 buffer.
 
auto & bg2 ()
 Get reference to background layer 2 buffer.
 

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
 

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

Member Enumeration Documentation

◆ TextureCommandType

Enumerator
CREATE 
UPDATE 
DESTROY 

Definition at line 52 of file arena.h.

Constructor & Destructor Documentation

◆ ~Arena()

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

Definition at line 25 of file arena.cc.

References Shutdown().

Here is the call graph for this function:

◆ Arena()

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

Definition at line 20 of file arena.cc.

References layer1_buffer_, and layer2_buffer_.

Member Function Documentation

◆ Get()

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

Definition at line 15 of file arena.cc.

Referenced by yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::gui::PaletteWidget::ApplyROMPalette(), yaze::gfx::Bitmap::Bitmap(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::editor::Tile16Editor::ClearTile16(), yaze::test::TestManager::CollectResourceStats(), yaze::editor::Tile16Editor::CommitChangesToBlockset(), yaze::editor::Tile16Editor::CommitChangesToOverworld(), yaze::editor::Tile16Editor::CopyTile16ToClipboard(), yaze::gfx::Bitmap::Create(), yaze::gfx::Bitmap::CreateTexture(), yaze::gfx::CreateTilemap(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DecompressSuperDonkey(), yaze::core::Controller::DoRender(), yaze::editor::GfxGroupEditor::DrawBlocksetViewer(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::SpriteEditor::DrawCurrentSheets(), yaze::editor::DungeonEditorV2::DrawDebugControlsCard(), yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::GraphicsEditor::DrawGfxEditToolset(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::DungeonCanvasViewer::DrawRoomBackgroundLayers(), yaze::editor::DungeonObjectSelector::DrawRoomGraphics(), yaze::editor::DungeonEditorV2::DrawRoomGraphicsCard(), yaze::editor::GfxGroupEditor::DrawRoomsetViewer(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::GfxGroupEditor::DrawSpritesetViewer(), yaze::editor::OverworldEditor::DrawTile8Selector(), yaze::editor::Tile16Editor::DrawToCurrentTile16(), yaze::editor::OverworldEditor::EnsureMapTexture(), yaze::editor::Tile16Editor::FillTile16WithTile8(), yaze::editor::Tile16Editor::FlipTile16Horizontal(), yaze::editor::Tile16Editor::FlipTile16Vertical(), yaze::cli::HandleGfxExportLegacy(), yaze::cli::HandleGfxImportLegacy(), yaze::editor::MessageEditor::Initialize(), yaze::editor::GraphicsEditor::Load(), yaze::editor::ScreenEditor::Load(), yaze::editor::EditorManager::LoadAssets(), yaze::editor::ScreenEditor::LoadBinaryGfx(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::Tile16Editor::LoadTile16FromScratchSpace(), yaze::editor::Tile16Editor::LoadTile8(), yaze::core::Controller::OnEntry(), yaze::gfx::Bitmap::operator=(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::DungeonEditorV2::ProcessDeferredTextures(), yaze::editor::OverworldEditor::ProcessDeferredTextures(), yaze::editor::Tile16Editor::Redo(), yaze::gfx::Bitmap::Reformat(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::OverworldEditor::RefreshChildMapOnDemand(), yaze::editor::OverworldEditor::RefreshMultiAreaMapsSafely(), yaze::editor::OverworldEditor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RegenerateTile16BitmapFromROM(), yaze::gui::canvas::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::zelda3::Room::RenderRoomGraphics(), yaze::gfx::RenderTilesBatch(), yaze::gfx::Bitmap::Resize(), yaze::editor::Tile16Editor::RotateTile16(), 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::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::EditorManager::SaveRom(), yaze::editor::EditorManager::SaveRomAs(), yaze::editor::Tile16Editor::SaveTile16ToScratchSpace(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::gfx::GraphicsOptimizationBenchmarks::SetUp(), yaze::editor::test::Tile16EditorIntegrationTest::SetUp(), yaze::core::ShutdownWindow(), yaze::gfx::TEST_F(), yaze::gfx::TEST_F(), yaze::editor::Tile16Editor::Undo(), yaze::editor::GraphicsEditor::Update(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::GraphicsEditor::UpdateGfxSheetList(), yaze::editor::GraphicsEditor::UpdateGfxTabView(), yaze::editor::Tile16Editor::UpdateOverworldTilemap(), yaze::editor::GraphicsEditor::UpdatePaletteColumn(), 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 13 of file arena.cc.

References renderer_.

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

◆ QueueTextureCommand()

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

Definition at line 32 of file arena.cc.

References texture_command_queue_.

Referenced by yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::gui::PaletteWidget::ApplyROMPalette(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::editor::Tile16Editor::ClearTile16(), yaze::editor::Tile16Editor::CommitChangesToBlockset(), yaze::editor::Tile16Editor::CommitChangesToOverworld(), yaze::editor::Tile16Editor::CopyTile16ToClipboard(), yaze::gfx::Bitmap::CreateTexture(), yaze::gfx::CreateTilemap(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DecompressSuperDonkey(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::DungeonCanvasViewer::DrawRoomBackgroundLayers(), yaze::editor::DungeonEditorV2::DrawRoomGraphicsCard(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::editor::Tile16Editor::DrawToCurrentTile16(), yaze::editor::OverworldEditor::EnsureMapTexture(), yaze::editor::Tile16Editor::FillTile16WithTile8(), yaze::editor::Tile16Editor::FlipTile16Horizontal(), yaze::editor::Tile16Editor::FlipTile16Vertical(), yaze::editor::MessageEditor::Initialize(), yaze::editor::GraphicsEditor::Load(), yaze::editor::ScreenEditor::LoadBinaryGfx(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::Tile16Editor::LoadTile16FromScratchSpace(), yaze::editor::Tile16Editor::LoadTile8(), NotifySheetModified(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::Tile16Editor::Redo(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::OverworldEditor::RefreshChildMapOnDemand(), yaze::editor::OverworldEditor::RefreshMultiAreaMapsSafely(), yaze::editor::OverworldEditor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RefreshTile16Blockset(), yaze::editor::Tile16Editor::RegenerateTile16BitmapFromROM(), yaze::gui::canvas::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::zelda3::Room::RenderRoomGraphics(), yaze::gfx::RenderTilesBatch(), yaze::editor::Tile16Editor::RotateTile16(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::Tile16Editor::SaveTile16ToScratchSpace(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::editor::test::Tile16EditorIntegrationTest::SetUp(), yaze::gfx::TEST_F(), yaze::editor::Tile16Editor::Undo(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::GraphicsEditor::UpdateGfxSheetList(), yaze::editor::Tile16Editor::UpdateOverworldTilemap(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::Bitmap::UpdateTexture(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16Editor::UpdateTile16Edit(), yaze::editor::Tile16Editor::UpdateTile8Palette(), and yaze::gfx::UpdateTilemap().

◆ ProcessTextureQueue()

◆ AllocateSurface()

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

◆ FreeSurface()

void yaze::gfx::Arena::FreeSurface ( SDL_Surface *  surface)

◆ Shutdown()

◆ GetTextureCount()

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

Definition at line 68 of file arena.h.

References textures_.

◆ GetSurfaceCount()

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

Definition at line 69 of file arena.h.

References surfaces_.

◆ GetPooledTextureCount()

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

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

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

◆ 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

Definition at line 85 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

Definition at line 92 of file arena.h.

References gfx_sheets_.

◆ mutable_gfx_sheets()

auto yaze::gfx::Arena::mutable_gfx_sheets ( )
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 183 of file arena.cc.

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

Referenced by yaze::editor::GraphicsEditor::UpdateGfxTabView(), and yaze::editor::GraphicsEditor::UpdatePaletteColumn().

Here is the call graph for this function:

◆ bg1()

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

Get reference to background layer 1 buffer.

Returns
Reference to BackgroundBuffer for layer 1

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

References bg2_.

Member Data Documentation

◆ bg1_

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

Definition at line 123 of file arena.h.

Referenced by bg1().

◆ bg2_

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

Definition at line 124 of file arena.h.

Referenced by bg2().

◆ kTilesPerRow

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

Definition at line 126 of file arena.h.

◆ kTilesPerColumn

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

Definition at line 127 of file arena.h.

◆ kTotalTiles

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

Definition at line 128 of file arena.h.

◆ layer1_buffer_

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

Definition at line 130 of file arena.h.

Referenced by Arena().

◆ layer2_buffer_

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

Definition at line 131 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 137 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 141 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_

std::vector<TextureCommand> yaze::gfx::Arena::texture_command_queue_
private

Definition at line 156 of file arena.h.

Referenced by ProcessTextureQueue(), QueueTextureCommand(), and Shutdown().

◆ renderer_

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

Definition at line 157 of file arena.h.

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


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