diff --git a/source/frontends/libretro/game.cpp b/source/frontends/libretro/game.cpp index b512d0dd..c7b23ad3 100644 --- a/source/frontends/libretro/game.cpp +++ b/source/frontends/libretro/game.cpp @@ -55,7 +55,7 @@ namespace ra2 unsigned Game::ourInputDevices[MAX_PADS] = {RETRO_DEVICE_NONE}; Game::Game() - : myLogger(true) + : myLoggerContext(true) , myFrame(new ra2::RetroFrame()) , mySpeed(true) , myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1) diff --git a/source/frontends/libretro/game.h b/source/frontends/libretro/game.h index 7f831cee..b1bf8f26 100644 --- a/source/frontends/libretro/game.h +++ b/source/frontends/libretro/game.h @@ -35,7 +35,7 @@ namespace ra2 static retro_usec_t ourFrameTime; private: - const Logger myLogger; + const LoggerContext myLoggerContext; const std::shared_ptr myFrame; common2::Speed mySpeed; // fixed speed diff --git a/source/frontends/ncurses/main.cpp b/source/frontends/ncurses/main.cpp index d9213348..1bbf619d 100644 --- a/source/frontends/ncurses/main.cpp +++ b/source/frontends/ncurses/main.cpp @@ -145,12 +145,12 @@ namespace if (!run) return 1; - const Logger logger(options.log); - const std::shared_ptr registry = CreateFileRegistry(options); + const LoggerContext loggerContext(options.log); + const RegistryContext registryContet(CreateFileRegistry(options)); const std::shared_ptr paddle(new na2::EvDevPaddle(options.paddleDeviceName)); const std::shared_ptr frame(new na2::NFrame(paddle)); - const Initialisation init(registry, frame, paddle); + const Initialisation init(frame, paddle); applyOptions(options); frame->Initialize(); diff --git a/source/frontends/sdl/main.cpp b/source/frontends/sdl/main.cpp index e6aa8751..d5d0a544 100644 --- a/source/frontends/sdl/main.cpp +++ b/source/frontends/sdl/main.cpp @@ -76,8 +76,8 @@ void run_sdl(int argc, const char * argv []) if (!run) return; - const Logger logger(options.log); - const std::shared_ptr registry = CreateFileRegistry(options); + const LoggerContext logger(options.log); + const RegistryContext registryContext(CreateFileRegistry(options)); std::shared_ptr frame; if (options.imgui) @@ -90,7 +90,7 @@ void run_sdl(int argc, const char * argv []) } std::shared_ptr paddle(new sa2::Gamepad(0)); - const Initialisation init(registry, frame, paddle); + const Initialisation init(frame, paddle); applyOptions(options); frame->Initialize(); diff --git a/source/linux/context.cpp b/source/linux/context.cpp index 01ec2836..d43c828b 100644 --- a/source/linux/context.cpp +++ b/source/linux/context.cpp @@ -37,12 +37,10 @@ Video& GetVideo() } Initialisation::Initialisation( - const std::shared_ptr & registry, const std::shared_ptr & frame, const std::shared_ptr & paddle ) { - Registry::instance = registry; SetFrame(frame); Paddle::instance = paddle; } @@ -53,7 +51,6 @@ Initialisation::~Initialisation() SetFrame(std::shared_ptr()); Paddle::instance.reset(); - Registry::instance.reset(); CloseHandle(g_hCustomRomF8); g_hCustomRomF8 = INVALID_HANDLE_VALUE; @@ -61,7 +58,7 @@ Initialisation::~Initialisation() g_hCustomRom = INVALID_HANDLE_VALUE; } -Logger::Logger(const bool log) +LoggerContext::LoggerContext(const bool log) { if (log) { @@ -69,7 +66,17 @@ Logger::Logger(const bool log) } } -Logger::~Logger() +LoggerContext::~LoggerContext() { LogDone(); } + +RegistryContext::RegistryContext(const std::shared_ptr & registry) +{ + Registry::instance = registry; +} + +RegistryContext::~RegistryContext() +{ + Registry::instance.reset(); +} \ No newline at end of file diff --git a/source/linux/context.h b/source/linux/context.h index 7bcac22f..6099d4b8 100644 --- a/source/linux/context.h +++ b/source/linux/context.h @@ -13,7 +13,6 @@ class Initialisation { public: Initialisation( - const std::shared_ptr & registry, const std::shared_ptr & frame, const std::shared_ptr & paddle ); @@ -21,9 +20,16 @@ public: }; // RAII around LogInit / LogDone. -class Logger +class LoggerContext { public: - Logger(const bool log); - ~Logger(); + LoggerContext(const bool log); + ~LoggerContext(); +}; + +class RegistryContext +{ +public: + RegistryContext(const std::shared_ptr & registry); + ~RegistryContext(); };