yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
arena.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_ARENA_H
2#define YAZE_APP_GFX_ARENA_H
3
4#include <array>
5#include <cstdint>
6#include <memory>
7#include <mutex>
8#include <tuple>
9#include <unordered_map>
10#include <vector>
11
12#include "util/sdl_deleter.h"
14#include "app/gfx/bitmap.h"
15
16namespace yaze {
17namespace gfx {
18
44class Arena {
45 public:
46 static Arena& Get();
47
48 void Initialize(IRenderer* renderer);
49 ~Arena();
50
51 // --- New Deferred Command System ---
55 Bitmap* bitmap; // The bitmap that needs a texture operation
56 };
57
59 void ProcessTextureQueue(IRenderer* renderer);
60
61 // --- Surface Management (unchanged) ---
62 SDL_Surface* AllocateSurface(int width, int height, int depth, int format);
63 void FreeSurface(SDL_Surface* surface);
64
65 void Shutdown();
66
67 // Resource tracking for debugging
68 size_t GetTextureCount() const { return textures_.size(); }
69 size_t GetSurfaceCount() const { return surfaces_.size(); }
72
73 // Graphics sheet access (223 total sheets in YAZE)
78 std::array<gfx::Bitmap, 223>& gfx_sheets() { return gfx_sheets_; }
79
85 auto gfx_sheet(int i) { return gfx_sheets_[i]; }
86
92 auto mutable_gfx_sheet(int i) { return &gfx_sheets_[i]; }
93
98 auto mutable_gfx_sheets() { return &gfx_sheets_; }
99
105 void NotifySheetModified(int sheet_index);
106
107 // Background buffer access for SNES layer rendering
112 auto& bg1() { return bg1_; }
113
118 auto& bg2() { return bg2_; }
119
120 private:
121 Arena();
122
125
126 static constexpr int kTilesPerRow = 64;
127 static constexpr int kTilesPerColumn = 64;
128 static constexpr int kTotalTiles = kTilesPerRow * kTilesPerColumn;
129
130 std::array<uint16_t, kTotalTiles> layer1_buffer_;
131 std::array<uint16_t, kTotalTiles> layer2_buffer_;
132
133 std::array<gfx::Bitmap, 223> gfx_sheets_;
134
135 std::unordered_map<TextureHandle,
136 std::unique_ptr<SDL_Texture, util::SDL_Texture_Deleter>>
138
139 std::unordered_map<SDL_Surface*,
140 std::unique_ptr<SDL_Surface, util::SDL_Surface_Deleter>>
142
143 // Resource pooling for efficient memory management
144 struct TexturePool {
145 std::vector<TextureHandle> available_textures_;
146 std::unordered_map<TextureHandle, std::pair<int, int>> texture_sizes_;
147 static constexpr size_t MAX_POOL_SIZE = 100;
149
150 struct SurfacePool {
151 std::vector<SDL_Surface*> available_surfaces_;
152 std::unordered_map<SDL_Surface*, std::tuple<int, int, int, int>> surface_info_;
153 static constexpr size_t MAX_POOL_SIZE = 100;
155
156 std::vector<TextureCommand> texture_command_queue_;
158};
159
160} // namespace gfx
161} // namespace yaze
162
163#endif // YAZE_APP_GFX_ARENA_H
Resource management arena for efficient graphics memory handling.
Definition arena.h:44
IRenderer * renderer_
Definition arena.h:157
size_t GetSurfaceCount() const
Definition arena.h:69
std::unordered_map< SDL_Surface *, std::unique_ptr< SDL_Surface, util::SDL_Surface_Deleter > > surfaces_
Definition arena.h:141
void Initialize(IRenderer *renderer)
Definition arena.cc:13
struct yaze::gfx::Arena::TexturePool texture_pool_
SDL_Surface * AllocateSurface(int width, int height, int depth, int format)
Definition arena.cc:125
std::unordered_map< TextureHandle, std::unique_ptr< SDL_Texture, util::SDL_Texture_Deleter > > textures_
Definition arena.h:137
BackgroundBuffer bg2_
Definition arena.h:124
size_t GetPooledSurfaceCount() const
Definition arena.h:71
auto gfx_sheet(int i)
Get a specific graphics sheet by index.
Definition arena.h:85
static constexpr int kTotalTiles
Definition arena.h:128
size_t GetTextureCount() const
Definition arena.h:68
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Definition arena.cc:32
std::array< uint16_t, kTotalTiles > layer2_buffer_
Definition arena.h:131
static constexpr int kTilesPerColumn
Definition arena.h:127
size_t GetPooledTextureCount() const
Definition arena.h:70
static constexpr int kTilesPerRow
Definition arena.h:126
auto mutable_gfx_sheets()
Get mutable reference to all graphics sheets.
Definition arena.h:98
void FreeSurface(SDL_Surface *surface)
Definition arena.cc:151
auto mutable_gfx_sheet(int i)
Get mutable reference to a specific graphics sheet.
Definition arena.h:92
BackgroundBuffer bg1_
Definition arena.h:123
void ProcessTextureQueue(IRenderer *renderer)
Definition arena.cc:36
std::array< gfx::Bitmap, 223 > gfx_sheets_
Definition arena.h:133
auto & bg2()
Get reference to background layer 2 buffer.
Definition arena.h:118
std::array< gfx::Bitmap, 223 > & gfx_sheets()
Get reference to all graphics sheets.
Definition arena.h:78
std::vector< TextureCommand > texture_command_queue_
Definition arena.h:156
std::array< uint16_t, kTotalTiles > layer1_buffer_
Definition arena.h:130
void NotifySheetModified(int sheet_index)
Notify Arena that a graphics sheet has been modified.
Definition arena.cc:183
auto & bg1()
Get reference to background layer 1 buffer.
Definition arena.h:112
struct yaze::gfx::Arena::SurfacePool surface_pool_
void Shutdown()
Definition arena.cc:164
static Arena & Get()
Definition arena.cc:15
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
Defines an abstract interface for all rendering operations.
Definition irenderer.h:35
void * TextureHandle
An abstract handle representing a texture.
Definition irenderer.h:24
Main namespace for the application.
static constexpr size_t MAX_POOL_SIZE
Definition arena.h:153
std::vector< SDL_Surface * > available_surfaces_
Definition arena.h:151
std::unordered_map< SDL_Surface *, std::tuple< int, int, int, int > > surface_info_
Definition arena.h:152
TextureCommandType type
Definition arena.h:54
static constexpr size_t MAX_POOL_SIZE
Definition arena.h:147
std::vector< TextureHandle > available_textures_
Definition arena.h:145
std::unordered_map< TextureHandle, std::pair< int, int > > texture_sizes_
Definition arena.h:146