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

Smart tile cache with LRU eviction for efficient memory management. More...

#include <tilemap.h>

Public Member Functions

BitmapGetTile (int tile_id)
 Get a cached tile by ID.
 
void CacheTile (int tile_id, const Bitmap &bitmap)
 Cache a tile bitmap by copying it.
 
void Clear ()
 Clear the cache.
 
size_t Size () const
 Get cache statistics.
 

Public Attributes

std::unordered_map< int, std::unique_ptr< Bitmap > > cache_
 
std::list< int > access_order_
 

Static Public Attributes

static constexpr size_t MAX_CACHE_SIZE = 1024
 

Detailed Description

Smart tile cache with LRU eviction for efficient memory management.

Performance Optimizations:

  • LRU eviction policy to keep frequently used tiles in memory
  • Configurable cache size to balance memory usage and performance
  • O(1) tile access and insertion
  • Automatic cache management with minimal overhead

Memory Safety:

  • Uses unique_ptr<Bitmap> to ensure stable pointers across map rehashing
  • Returned Bitmap* pointers remain valid until explicitly evicted or cleared

Definition at line 37 of file tilemap.h.

Member Function Documentation

◆ GetTile()

Bitmap * yaze::gfx::TileCache::GetTile ( int tile_id)
inline

Get a cached tile by ID.

Parameters
tile_idTile identifier
Returns
Pointer to cached tile bitmap or nullptr if not cached
Note
Returned pointer is stable and won't be invalidated by subsequent CacheTile calls (unless this specific tile is evicted)

Definition at line 50 of file tilemap.h.

References access_order_, and cache_.

Referenced by yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::gfx::RenderTile(), yaze::gfx::RenderTile16(), yaze::gfx::RenderTilesBatch(), and yaze::gfx::UpdateTile16().

◆ CacheTile()

void yaze::gfx::TileCache::CacheTile ( int tile_id,
const Bitmap & bitmap )
inline

Cache a tile bitmap by copying it.

Parameters
tile_idTile identifier
bitmapTile bitmap to cache (copied, not moved)
Note
Uses copy semantics to ensure the original bitmap remains valid

Definition at line 67 of file tilemap.h.

References access_order_, cache_, and MAX_CACHE_SIZE.

Referenced by yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::gfx::RenderTile(), yaze::gfx::RenderTile16(), and yaze::gfx::RenderTilesBatch().

◆ Clear()

void yaze::gfx::TileCache::Clear ( )
inline

Clear the cache.

Definition at line 82 of file tilemap.h.

References access_order_, and cache_.

◆ Size()

size_t yaze::gfx::TileCache::Size ( ) const
inline

Get cache statistics.

Returns
Number of cached tiles

Definition at line 91 of file tilemap.h.

References cache_.

Member Data Documentation

◆ MAX_CACHE_SIZE

constexpr size_t yaze::gfx::TileCache::MAX_CACHE_SIZE = 1024
staticconstexpr

Definition at line 38 of file tilemap.h.

Referenced by CacheTile().

◆ cache_

std::unordered_map<int, std::unique_ptr<Bitmap> > yaze::gfx::TileCache::cache_

Definition at line 40 of file tilemap.h.

Referenced by CacheTile(), Clear(), GetTile(), and Size().

◆ access_order_

std::list<int> yaze::gfx::TileCache::access_order_

Definition at line 41 of file tilemap.h.

Referenced by CacheTile(), Clear(), and GetTile().


The documentation for this struct was generated from the following file: