diff --git a/source/frontends/common2/fileregistry.cpp b/source/frontends/common2/fileregistry.cpp index 1176459e..6a70fbb0 100644 --- a/source/frontends/common2/fileregistry.cpp +++ b/source/frontends/common2/fileregistry.cpp @@ -110,7 +110,7 @@ namespace common2 } } - void InitializeFileRegistry(const EmulatorOptions & options) + std::shared_ptr CreateFileRegistry(const EmulatorOptions & options) { const std::string homeDir = getHomeDir(); @@ -131,7 +131,7 @@ namespace common2 std::shared_ptr config(new Configuration(filename, saveOnExit)); config->addExtraOptions(options.registryOptions); - Registry::instance = config; + return config; } } diff --git a/source/frontends/common2/fileregistry.h b/source/frontends/common2/fileregistry.h index 4d51a665..4fc73bde 100644 --- a/source/frontends/common2/fileregistry.h +++ b/source/frontends/common2/fileregistry.h @@ -1,6 +1,9 @@ #pragma once #include +#include + +class Registry; namespace common2 { @@ -8,6 +11,6 @@ namespace common2 struct EmulatorOptions; std::string GetConfigFile(const std::string & filename); - void InitializeFileRegistry(const EmulatorOptions & options); + std::shared_ptr CreateFileRegistry(const EmulatorOptions & options); } diff --git a/source/frontends/libretro/game.cpp b/source/frontends/libretro/game.cpp index 14706652..b512d0dd 100644 --- a/source/frontends/libretro/game.cpp +++ b/source/frontends/libretro/game.cpp @@ -60,7 +60,7 @@ namespace ra2 , mySpeed(true) , myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1) { - InitialiseRetroRegistry(); + Registry::instance = CreateRetroRegistry(); SetFrame(myFrame); myFrame->Initialize(); diff --git a/source/frontends/libretro/retroregistry.cpp b/source/frontends/libretro/retroregistry.cpp index da3f989d..30b65fd9 100644 --- a/source/frontends/libretro/retroregistry.cpp +++ b/source/frontends/libretro/retroregistry.cpp @@ -133,7 +133,7 @@ namespace ra2 environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, retroVariables.data()); } - void InitialiseRetroRegistry() + std::shared_ptr CreateRetroRegistry() { const auto registry = std::make_shared(); @@ -158,7 +158,7 @@ namespace ra2 } } - Registry::instance = registry; + return registry; } } diff --git a/source/frontends/libretro/retroregistry.h b/source/frontends/libretro/retroregistry.h index 1e21d09d..64580295 100644 --- a/source/frontends/libretro/retroregistry.h +++ b/source/frontends/libretro/retroregistry.h @@ -1,9 +1,13 @@ #pragma once +#include + +class Registry; + namespace ra2 { void SetupRetroVariables(); - void InitialiseRetroRegistry(); + std::shared_ptr CreateRetroRegistry(); } diff --git a/source/frontends/ncurses/main.cpp b/source/frontends/ncurses/main.cpp index 584b5822..53a1c59b 100644 --- a/source/frontends/ncurses/main.cpp +++ b/source/frontends/ncurses/main.cpp @@ -24,6 +24,7 @@ #include "frontends/common2/utils.h" #include "frontends/ncurses/world.h" #include "frontends/ncurses/nframe.h" +#include "frontends/ncurses/evdevpaddle.h" namespace { @@ -146,11 +147,13 @@ namespace return 1; const Logger logger(options.log); - InitializeFileRegistry(options); + const std::shared_ptr registry = CreateFileRegistry(options); g_nMemoryClearType = options.memclear; - const std::shared_ptr frame(new na2::NFrame(options.paddleDeviceName)); - const Initialisation init(frame); + 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); na2::SetCtrlCHandler(options.headless); applyOptions(options); diff --git a/source/frontends/ncurses/nframe.cpp b/source/frontends/ncurses/nframe.cpp index e3f0f24f..c2231a9f 100644 --- a/source/frontends/ncurses/nframe.cpp +++ b/source/frontends/ncurses/nframe.cpp @@ -3,7 +3,6 @@ #include "frontends/ncurses/colors.h" #include "frontends/ncurses/asciiart.h" #include "frontends/ncurses/evdevpaddle.h" - #include "Interface.h" #include "Memory.h" #include "Log.h" @@ -39,8 +38,8 @@ namespace na2 std::shared_ptr colors; }; - NFrame::NFrame(const std::string & paddleDevice) - : myPaddleDevice(paddleDevice) + NFrame::NFrame(const std::shared_ptr & paddle) + : myPaddle(paddle) , myRows(-1) , myColumns(-1) { @@ -54,8 +53,6 @@ namespace na2 myTextFlashCounter = 0; myTextFlashState = 0; myAsciiArt.reset(new ASCIIArt()); - myPaddle.reset(new EvDevPaddle(myPaddleDevice)); - Paddle::instance = myPaddle; } void NFrame::Destroy() @@ -67,9 +64,6 @@ namespace na2 myStatus.reset(); myAsciiArt.reset(); - myPaddle.reset(); - Paddle::instance.reset(); - myNCurses.reset(); } diff --git a/source/frontends/ncurses/nframe.h b/source/frontends/ncurses/nframe.h index eab965b8..fdfb912c 100644 --- a/source/frontends/ncurses/nframe.h +++ b/source/frontends/ncurses/nframe.h @@ -16,7 +16,7 @@ namespace na2 class NFrame : public common2::CommonFrame { public: - NFrame(const std::string & paddleDevice); + NFrame(const std::shared_ptr & paddle); WINDOW * GetWindow(); WINDOW * GetStatus(); @@ -35,7 +35,8 @@ namespace na2 private: - const std::string myPaddleDevice; + const std::shared_ptr myPaddle; + int myRows; int myColumns; int myTextFlashCounter; @@ -44,7 +45,6 @@ namespace na2 std::shared_ptr myFrame; std::shared_ptr myStatus; std::shared_ptr myAsciiArt; - std::shared_ptr myPaddle; std::shared_ptr myNCurses; LPBYTE myTextBank1; // Aux diff --git a/source/frontends/sdl/main.cpp b/source/frontends/sdl/main.cpp index dbf89c78..cb5d5607 100644 --- a/source/frontends/sdl/main.cpp +++ b/source/frontends/sdl/main.cpp @@ -91,8 +91,8 @@ void run_sdl(int argc, const char * argv []) return; const Logger logger(options.log); + const std::shared_ptr registry = CreateFileRegistry(options); g_nMemoryClearType = options.memclear; - InitializeFileRegistry(options); std::shared_ptr frame; if (options.imgui) @@ -104,8 +104,8 @@ void run_sdl(int argc, const char * argv []) frame.reset(new sa2::SDLRendererFrame(options)); } - Paddle::instance.reset(new sa2::Gamepad(0)); - const Initialisation init(frame); + std::shared_ptr paddle(new sa2::Gamepad(0)); + const Initialisation init(registry, frame, paddle); if (SDL_GL_SetSwapInterval(options.glSwapInterval)) { diff --git a/source/linux/context.cpp b/source/linux/context.cpp index 1fe950d8..00ad45aa 100644 --- a/source/linux/context.cpp +++ b/source/linux/context.cpp @@ -36,9 +36,16 @@ Video& GetVideo() return sg_Video; } -Initialisation::Initialisation(const std::shared_ptr & frame) +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; + frame->Initialize(); } diff --git a/source/linux/context.h b/source/linux/context.h index a9bce884..7bcac22f 100644 --- a/source/linux/context.h +++ b/source/linux/context.h @@ -3,6 +3,8 @@ #include class FrameBase; +class Paddle; +class Registry; void SetFrame(const std::shared_ptr & frame); @@ -10,7 +12,11 @@ void SetFrame(const std::shared_ptr & frame); class Initialisation { public: - Initialisation(const std::shared_ptr & frame); + Initialisation( + const std::shared_ptr & registry, + const std::shared_ptr & frame, + const std::shared_ptr & paddle + ); ~Initialisation(); };