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:
@@ -55,19 +55,18 @@ namespace {
|
||||
} // namespace
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
||||
Screen* Screen::instance_ = nullptr;
|
||||
std::unique_ptr<Screen> Screen::instance_;
|
||||
|
||||
void Screen::init() {
|
||||
instance_ = new Screen();
|
||||
instance_ = std::unique_ptr<Screen>(new Screen());
|
||||
}
|
||||
|
||||
void Screen::destroy() {
|
||||
delete instance_;
|
||||
instance_ = nullptr;
|
||||
instance_.reset();
|
||||
}
|
||||
|
||||
auto Screen::get() -> Screen* {
|
||||
return instance_;
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
Screen::Screen() {
|
||||
|
||||
Reference in New Issue
Block a user