Resource management arena for efficient graphics memory handling. More...
#include <arena.h>
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 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_ |
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< TextureCommand > | texture_command_queue_ |
IRenderer * | renderer_ = nullptr |
Static Private Attributes | |
static constexpr int | kTilesPerRow = 64 |
static constexpr int | kTilesPerColumn = 64 |
static constexpr int | kTotalTiles = kTilesPerRow * kTilesPerColumn |
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:
Performance Optimizations:
ROM Hacking Specific:
|
strong |
yaze::gfx::Arena::~Arena | ( | ) |
Definition at line 25 of file arena.cc.
References Shutdown().
|
private |
Definition at line 20 of file arena.cc.
References layer1_buffer_, and layer2_buffer_.
|
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().
void yaze::gfx::Arena::Initialize | ( | IRenderer * | renderer | ) |
Definition at line 13 of file arena.cc.
References renderer_.
Referenced by yaze::core::Controller::OnEntry().
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().
void yaze::gfx::Arena::ProcessTextureQueue | ( | IRenderer * | renderer | ) |
Definition at line 36 of file arena.cc.
References CREATE, yaze::gfx::IRenderer::CreateTexture(), DESTROY, yaze::gfx::IRenderer::DestroyTexture(), LOG_ERROR, renderer_, texture_command_queue_, UPDATE, and yaze::gfx::IRenderer::UpdateTexture().
Referenced by yaze::core::Controller::DoRender(), yaze::editor::DungeonEditorV2::DrawDebugControlsCard(), yaze::editor::DungeonCanvasViewer::DrawDungeonCanvas(), yaze::editor::DungeonEditorV2::DrawRoomGraphicsCard(), yaze::editor::DungeonEditorV2::ProcessDeferredTextures(), yaze::editor::OverworldEditor::ProcessDeferredTextures(), Shutdown(), and yaze::gfx::TEST_F().
SDL_Surface * yaze::gfx::Arena::AllocateSurface | ( | int | width, |
int | height, | ||
int | depth, | ||
int | format | ||
) |
Definition at line 125 of file arena.cc.
References yaze::gfx::Arena::SurfacePool::available_surfaces_, yaze::gfx::GetSnesPixelFormat(), yaze::gfx::Arena::SurfacePool::surface_info_, surface_pool_, and surfaces_.
Referenced by yaze::gfx::Bitmap::Bitmap(), yaze::gfx::Bitmap::Create(), yaze::gfx::Bitmap::operator=(), yaze::gfx::Bitmap::Reformat(), and yaze::gfx::Bitmap::Resize().
void yaze::gfx::Arena::FreeSurface | ( | SDL_Surface * | surface | ) |
Definition at line 151 of file arena.cc.
References yaze::gfx::Arena::SurfacePool::available_surfaces_, yaze::gfx::Arena::SurfacePool::MAX_POOL_SIZE, yaze::gfx::Arena::SurfacePool::surface_info_, surface_pool_, and surfaces_.
void yaze::gfx::Arena::Shutdown | ( | ) |
Definition at line 164 of file arena.cc.
References yaze::gfx::Arena::SurfacePool::available_surfaces_, yaze::gfx::Arena::TexturePool::available_textures_, ProcessTextureQueue(), renderer_, yaze::gfx::Arena::SurfacePool::surface_info_, surface_pool_, surfaces_, texture_command_queue_, texture_pool_, yaze::gfx::Arena::TexturePool::texture_sizes_, and textures_.
Referenced by yaze::core::ShutdownWindow(), and ~Arena().
|
inline |
|
inline |
|
inline |
Definition at line 70 of file arena.h.
References yaze::gfx::Arena::TexturePool::available_textures_, and texture_pool_.
|
inline |
Definition at line 71 of file arena.h.
References yaze::gfx::Arena::SurfacePool::available_surfaces_, and surface_pool_.
|
inline |
Get reference to all graphics sheets.
Definition at line 78 of file arena.h.
References gfx_sheets_.
Referenced by yaze::editor::GraphicsEditor::DrawGfxEditToolset(), yaze::editor::DungeonObjectSelector::DrawRoomGraphics(), yaze::editor::DungeonEditorV2::DrawRoomGraphicsCard(), yaze::editor::OverworldEditor::DrawTile8Selector(), yaze::editor::GraphicsEditor::Load(), and yaze::editor::GraphicsEditor::UpdateGfxSheetList().
|
inline |
Get a specific graphics sheet by index.
i | Sheet index (0-222) |
Definition at line 85 of file arena.h.
References gfx_sheets_.
|
inline |
Get mutable reference to a specific graphics sheet.
i | Sheet index (0-222) |
Definition at line 92 of file arena.h.
References gfx_sheets_.
|
inline |
Get mutable reference to all graphics sheets.
Definition at line 98 of file arena.h.
References gfx_sheets_.
Referenced by yaze::editor::GfxGroupEditor::DrawBlocksetViewer(), yaze::editor::GfxGroupEditor::DrawRoomsetViewer(), yaze::editor::GfxGroupEditor::DrawSpritesetViewer(), yaze::editor::GraphicsEditor::UpdateGfxTabView(), and yaze::editor::GraphicsEditor::UpdatePaletteColumn().
void yaze::gfx::Arena::NotifySheetModified | ( | int | sheet_index | ) |
Notify Arena that a graphics sheet has been modified.
sheet_index | Index 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().
|
inline |
Get reference to background layer 1 buffer.
Definition at line 112 of file arena.h.
References bg1_.
|
inline |
Get reference to background layer 2 buffer.
Definition at line 118 of file arena.h.
References bg2_.
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
private |
Definition at line 133 of file arena.h.
Referenced by gfx_sheet(), gfx_sheets(), mutable_gfx_sheet(), mutable_gfx_sheets(), and NotifySheetModified().
|
private |
Definition at line 137 of file arena.h.
Referenced by GetTextureCount(), and Shutdown().
|
private |
Definition at line 141 of file arena.h.
Referenced by AllocateSurface(), FreeSurface(), GetSurfaceCount(), and Shutdown().
|
private |
Referenced by GetPooledTextureCount(), and Shutdown().
|
private |
Referenced by AllocateSurface(), FreeSurface(), GetPooledSurfaceCount(), and Shutdown().
|
private |
Definition at line 156 of file arena.h.
Referenced by ProcessTextureQueue(), QueueTextureCommand(), and Shutdown().
|
private |
Definition at line 157 of file arena.h.
Referenced by Initialize(), ProcessTextureQueue(), and Shutdown().