refactor: fase 5 — singletons a std::unique_ptr (elimina new/delete manual)
5 singletons afectats: Audio, Screen, Director, Resource::Cache, Resource::List. - static T* instance → static std::unique_ptr<T> instance - init(): new T() adoptat immediatament per unique_ptr (ownership RAII) - destroy(): instance.reset() (sense delete manual) - get(): retorna instance.get() - Destructors moguts a public perquè std::default_delete hi pugui accedir (ctors privats + copy/move deleted → encapsulació efectiva mantinguda) Ordre de destrucció preservat: SDL_AppQuit segueix cridant destroy() en l'ordre invers a init() — la RAII automàtica no s'activa fins al final del programa (LIFO de variables static). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,8 @@ class Screen {
|
||||
static void destroy();
|
||||
static auto get() -> Screen*;
|
||||
|
||||
~Screen(); // públic per a std::unique_ptr
|
||||
|
||||
// Presentació — rep el buffer ARGB de 320x200 de JD8
|
||||
void present(Uint32* pixel_data);
|
||||
|
||||
@@ -62,7 +64,6 @@ class Screen {
|
||||
|
||||
private:
|
||||
Screen();
|
||||
~Screen();
|
||||
|
||||
void adjustWindowSize();
|
||||
void calculateMaxZoom();
|
||||
@@ -70,7 +71,7 @@ class Screen {
|
||||
void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer
|
||||
void ensureFallbackInternalTexture(); // Recrea internal_texture_sdl_ si cal (fallback path)
|
||||
|
||||
static Screen* instance_;
|
||||
static std::unique_ptr<Screen> instance_;
|
||||
|
||||
SDL_Window* window_{nullptr};
|
||||
SDL_Renderer* renderer_{nullptr};
|
||||
|
||||
Reference in New Issue
Block a user