Revisit initialisation to drive it all from the FrameBase.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-03-27 18:47:40 +00:00
parent 8dc4c042a2
commit 11c44233b4
12 changed files with 51 additions and 51 deletions

View file

@ -1,5 +1,6 @@
#include "StdAfx.h"
#include "frontends/common2/commonframe.h"
#include "frontends/common2/utils.h"
#include "linux/resources.h"
#include <sys/stat.h>
@ -68,11 +69,17 @@ namespace common2
{
}
void CommonFrame::Initialize()
{
InitialiseEmulator();
LinuxFrame::Initialize();
}
void CommonFrame::Destroy()
{
LinuxFrame::Destroy();
myResource.clear();
DestroyEmulator();
}
BYTE* CommonFrame::GetResource(WORD id, LPCSTR lpType, DWORD expectedSize)

View file

@ -12,6 +12,7 @@ namespace common2
public:
CommonFrame();
void Initialize() override;
void Destroy() override;
BYTE* GetResource(WORD id, LPCSTR lpType, DWORD expectedSize) override;

View file

@ -59,7 +59,7 @@ namespace common2
}
}
Initialisation::Initialisation()
void InitialiseEmulator()
{
#ifdef RIFF_SPKR
RiffInitWriteFile("/tmp/Spkr.wav", SPKR_SAMPLE_RATE, 1);
@ -83,7 +83,6 @@ namespace common2
SpkrInitialize();
MemInitialize();
GetFrame().Initialize();
GetCardMgr().GetDisk2CardMgr().Reset();
HD_Reset();
@ -92,7 +91,7 @@ namespace common2
DebugInitialize();
}
Initialisation::~Initialisation()
void DestroyEmulator()
{
Snapshot_Shutdown();
CMouseInterface* pMouseCard = GetCardMgr().GetMouseCard();
@ -101,7 +100,6 @@ namespace common2
pMouseCard->Reset();
}
MemDestroy();
GetFrame().Destroy();
SpkrDestroy();
MB_Destroy();

View file

@ -7,11 +7,8 @@ namespace common2
void setSnapshotFilename(const std::string & filename, const bool load);
class Initialisation
{
public:
Initialisation();
~Initialisation();
};
// Do not call directly. Used in CommonFrame
void InitialiseEmulator();
void DestroyEmulator();
}

View file

@ -57,11 +57,10 @@ namespace ra2
Game::Game(const std::shared_ptr<RetroFrame> & frame)
: myFrame(frame), mySpeed(true), myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1)
{
SetFrame(myFrame);
LogInit();
InitialiseRetroRegistry();
myInit.reset(new common2::Initialisation);
SetFrame(myFrame);
myFrame->Initialize();
switch (ourInputDevices[0])
{
@ -83,7 +82,7 @@ namespace ra2
Game::~Game()
{
myInit.reset();
myFrame->Destroy();
SetFrame(std::shared_ptr<FrameBase>());
Paddle::instance.reset();
Registry::instance.reset();

View file

@ -6,11 +6,6 @@
#include <string>
#include <vector>
namespace common2
{
class Initialisation;
}
namespace ra2
{
@ -44,8 +39,6 @@ namespace ra2
std::vector<int> myButtonStates;
std::shared_ptr<common2::Initialisation> myInit;
bool checkButtonPressed(unsigned id);
void keyboardEmulation();

View file

@ -147,21 +147,17 @@ namespace
if (!run)
return 1;
std::shared_ptr<na2::NFrame> frame(new na2::NFrame(options.paddleDeviceName));
SetFrame(frame);
// does not seem to be a problem calling endwin() multiple times
std::atexit(na2::NFrame::Cleanup);
if (options.log)
{
LogInit();
}
InitializeFileRegistry(options);
g_nMemoryClearType = options.memclear;
common2::Initialisation init;
std::shared_ptr<na2::NFrame> frame(new na2::NFrame(options.paddleDeviceName));
Initialisation init(frame);
na2::SetCtrlCHandler(options.headless);
applyOptions(options);

View file

@ -50,7 +50,7 @@ namespace na2
void NFrame::Initialize()
{
LinuxFrame::Initialize();
CommonFrame::Initialize();
myTextFlashCounter = 0;
myTextFlashState = 0;
myAsciiArt.reset(new ASCIIArt());
@ -60,7 +60,7 @@ namespace na2
void NFrame::Destroy()
{
LinuxFrame::Destroy();
CommonFrame::Destroy();
myTextFlashCounter = 0;
myTextFlashState = 0;
myFrame.reset();
@ -359,11 +359,6 @@ namespace na2
return true;
}
void NFrame::Cleanup()
{
GetFrame().Destroy();
}
int NFrame::FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
LogFileOutput("MessageBox:\n%s\n%s\n\n", lpCaption, lpText);

View file

@ -33,8 +33,6 @@ namespace na2
void Init(int rows, int columns);
static void Cleanup();
private:
const std::string myPaddleDevice;

View file

@ -90,6 +90,16 @@ void run_sdl(int argc, const char * argv [])
if (!run)
return;
InitializeFileRegistry(options);
if (options.log)
{
LogInit();
}
g_nMemoryClearType = options.memclear;
Paddle::instance.reset(new sa2::Gamepad(0));
std::shared_ptr<sa2::SDLFrame> frame;
if (options.imgui)
@ -106,20 +116,8 @@ void run_sdl(int argc, const char * argv [])
throw std::runtime_error(SDL_GetError());
}
SetFrame(frame);
Initialisation init(frame);
if (options.log)
{
LogInit();
}
InitializeFileRegistry(options);
Paddle::instance.reset(new sa2::Gamepad(0));
g_nMemoryClearType = options.memclear;
common2::Initialisation init;
applyOptions(options);
const int fps = getRefreshRate();
@ -233,7 +231,6 @@ int main(int argc, const char * argv [])
// this must happen BEFORE the SDL_Quit() as otherwise we have a double free (of the game controller).
Paddle::instance.reset();
SetFrame(std::shared_ptr<FrameBase>());
SDL_Quit();
return exit;

View file

@ -32,3 +32,15 @@ Video& GetVideo()
static Video sg_Video;
return sg_Video;
}
Initialisation::Initialisation(const std::shared_ptr<FrameBase> & frame)
{
SetFrame(frame);
frame->Initialize();
}
Initialisation::~Initialisation()
{
GetFrame().Destroy();
SetFrame(std::shared_ptr<FrameBase>());
}

View file

@ -5,3 +5,10 @@
class FrameBase;
void SetFrame(const std::shared_ptr<FrameBase> & frame);
class Initialisation
{
public:
Initialisation(const std::shared_ptr<FrameBase> & frame);
~Initialisation();
};