Split registry from Initialisation to make is usable sooner.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-10-30 15:24:06 +01:00
parent 496a132211
commit c7bf4f5a39
6 changed files with 30 additions and 17 deletions

View file

@ -55,7 +55,7 @@ namespace ra2
unsigned Game::ourInputDevices[MAX_PADS] = {RETRO_DEVICE_NONE}; unsigned Game::ourInputDevices[MAX_PADS] = {RETRO_DEVICE_NONE};
Game::Game() Game::Game()
: myLogger(true) : myLoggerContext(true)
, myFrame(new ra2::RetroFrame()) , myFrame(new ra2::RetroFrame())
, mySpeed(true) , mySpeed(true)
, myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1) , myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1)

View file

@ -35,7 +35,7 @@ namespace ra2
static retro_usec_t ourFrameTime; static retro_usec_t ourFrameTime;
private: private:
const Logger myLogger; const LoggerContext myLoggerContext;
const std::shared_ptr<RetroFrame> myFrame; const std::shared_ptr<RetroFrame> myFrame;
common2::Speed mySpeed; // fixed speed common2::Speed mySpeed; // fixed speed

View file

@ -145,12 +145,12 @@ namespace
if (!run) if (!run)
return 1; return 1;
const Logger logger(options.log); const LoggerContext loggerContext(options.log);
const std::shared_ptr<Registry> registry = CreateFileRegistry(options); const RegistryContext registryContet(CreateFileRegistry(options));
const std::shared_ptr<na2::EvDevPaddle> paddle(new na2::EvDevPaddle(options.paddleDeviceName)); const std::shared_ptr<na2::EvDevPaddle> paddle(new na2::EvDevPaddle(options.paddleDeviceName));
const std::shared_ptr<na2::NFrame> frame(new na2::NFrame(paddle)); const std::shared_ptr<na2::NFrame> frame(new na2::NFrame(paddle));
const Initialisation init(registry, frame, paddle); const Initialisation init(frame, paddle);
applyOptions(options); applyOptions(options);
frame->Initialize(); frame->Initialize();

View file

@ -76,8 +76,8 @@ void run_sdl(int argc, const char * argv [])
if (!run) if (!run)
return; return;
const Logger logger(options.log); const LoggerContext logger(options.log);
const std::shared_ptr<Registry> registry = CreateFileRegistry(options); const RegistryContext registryContext(CreateFileRegistry(options));
std::shared_ptr<sa2::SDLFrame> frame; std::shared_ptr<sa2::SDLFrame> frame;
if (options.imgui) if (options.imgui)
@ -90,7 +90,7 @@ void run_sdl(int argc, const char * argv [])
} }
std::shared_ptr<Paddle> paddle(new sa2::Gamepad(0)); std::shared_ptr<Paddle> paddle(new sa2::Gamepad(0));
const Initialisation init(registry, frame, paddle); const Initialisation init(frame, paddle);
applyOptions(options); applyOptions(options);
frame->Initialize(); frame->Initialize();

View file

@ -37,12 +37,10 @@ Video& GetVideo()
} }
Initialisation::Initialisation( Initialisation::Initialisation(
const std::shared_ptr<Registry> & registry,
const std::shared_ptr<FrameBase> & frame, const std::shared_ptr<FrameBase> & frame,
const std::shared_ptr<Paddle> & paddle const std::shared_ptr<Paddle> & paddle
) )
{ {
Registry::instance = registry;
SetFrame(frame); SetFrame(frame);
Paddle::instance = paddle; Paddle::instance = paddle;
} }
@ -53,7 +51,6 @@ Initialisation::~Initialisation()
SetFrame(std::shared_ptr<FrameBase>()); SetFrame(std::shared_ptr<FrameBase>());
Paddle::instance.reset(); Paddle::instance.reset();
Registry::instance.reset();
CloseHandle(g_hCustomRomF8); CloseHandle(g_hCustomRomF8);
g_hCustomRomF8 = INVALID_HANDLE_VALUE; g_hCustomRomF8 = INVALID_HANDLE_VALUE;
@ -61,7 +58,7 @@ Initialisation::~Initialisation()
g_hCustomRom = INVALID_HANDLE_VALUE; g_hCustomRom = INVALID_HANDLE_VALUE;
} }
Logger::Logger(const bool log) LoggerContext::LoggerContext(const bool log)
{ {
if (log) if (log)
{ {
@ -69,7 +66,17 @@ Logger::Logger(const bool log)
} }
} }
Logger::~Logger() LoggerContext::~LoggerContext()
{ {
LogDone(); LogDone();
} }
RegistryContext::RegistryContext(const std::shared_ptr<Registry> & registry)
{
Registry::instance = registry;
}
RegistryContext::~RegistryContext()
{
Registry::instance.reset();
}

View file

@ -13,7 +13,6 @@ class Initialisation
{ {
public: public:
Initialisation( Initialisation(
const std::shared_ptr<Registry> & registry,
const std::shared_ptr<FrameBase> & frame, const std::shared_ptr<FrameBase> & frame,
const std::shared_ptr<Paddle> & paddle const std::shared_ptr<Paddle> & paddle
); );
@ -21,9 +20,16 @@ public:
}; };
// RAII around LogInit / LogDone. // RAII around LogInit / LogDone.
class Logger class LoggerContext
{ {
public: public:
Logger(const bool log); LoggerContext(const bool log);
~Logger(); ~LoggerContext();
};
class RegistryContext
{
public:
RegistryContext(const std::shared_ptr<Registry> & registry);
~RegistryContext();
}; };