Refactoring, remove sqlite from libretro build.

This commit is contained in:
Christian Speckner 2021-01-03 00:16:05 +01:00
parent 21b9667c5d
commit e373429ba2
17 changed files with 176 additions and 57 deletions

View File

@ -203,12 +203,11 @@ int main(int ac, char* av[])
// Create the parent OSystem object and initialize settings
theOSystem = MediaFactory::createOSystem();
theOSystem->loadConfig(globalOpts);
// Create the full OSystem after the settings, since settings are
// probably needed for defaults
Logger::debug("Creating the OSystem ...");
if(!theOSystem->create())
if(!theOSystem->initialize(globalOpts))
{
Logger::error("ERROR: Couldn't create OSystem");
return Cleanup();

View File

@ -84,14 +84,20 @@ const string StellaDb::databaseFileName() const
return myDb ? FilesystemNode(myDb->fileName()).getShortPath() : "[failed]";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StellaDb::isValid() const
{
return myDb.operator bool();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StellaDb::initializeDb()
{
importOldSettings();
FilesystemNode legacyPropertyFile{myDatabaseDirectory};
legacyPropertyFile /= "stella.pro";
if (legacyPropertyFile.exists() && legacyPropertyFile.isFile())
importOldPropset(legacyPropertyFile);
@ -103,7 +109,7 @@ void StellaDb::importOldSettings()
{
#ifdef BSPF_MACOS
Logger::info("importing old settings");
mySettingsRepository->save(SettingsRepositoryMACOS().load());
#else
#if defined(BSPF_WINDOWS)

View File

@ -38,6 +38,8 @@ class StellaDb
const string databaseFileName() const;
bool isValid() const;
private:
void initializeDb();

View File

@ -39,8 +39,6 @@
#include "TimeMachine.hxx"
#include "Widget.hxx"
#endif
#include "KeyValueRepositorySqlite.hxx"
#include "StellaDb.hxx"
#include "FSNode.hxx"
#include "MD5.hxx"
@ -115,8 +113,10 @@ OSystem::~OSystem()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::create()
bool OSystem::initialize(const Settings::Options& options)
{
loadConfig(options);
ostringstream buf;
buf << "Stella " << STELLA_VERSION << endl
<< " Features: " << myFeatures << endl
@ -127,8 +127,8 @@ bool OSystem::create()
<< myStateDir.getShortPath() << "'" << endl
<< "NVRam directory: '"
<< myNVRamDir.getShortPath() << "'" << endl
<< "Database file: '"
<< myStellaDb->databaseFileName() << "'" << endl
<< "Persistence: '"
<< describePresistence() << "'" << endl
<< "Cheat file: '"
<< myCheatFile.getShortPath() << "'" << endl
<< "Palette file: '"
@ -218,8 +218,7 @@ void OSystem::loadConfig(const Settings::Options& options)
if(!myHomeDir.isDirectory())
myHomeDir.makeDir();
myStellaDb = make_shared<StellaDb>(myBaseDir.getPath(), "stella");
myStellaDb->initialize();
initPersistence(myBaseDir);
mySettings->setRepository(getSettingsRepository());
myPropSet->setRepository(getPropertyRepository());
@ -869,18 +868,6 @@ void OSystem::mainLoop()
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<KeyValueRepository> OSystem::getSettingsRepository()
{
return shared_ptr<KeyValueRepository>(myStellaDb, &myStellaDb->settingsRepository());
}
shared_ptr<CompositeKeyValueRepository> OSystem::getPropertyRepository()
{
return shared_ptr<CompositeKeyValueRepository>(myStellaDb, &myStellaDb->propertyRepository());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string OSystem::ourOverrideBaseDir = "";
bool OSystem::ourOverrideBaseDirWithApp = false;

View File

@ -48,7 +48,6 @@ class AudioSettings;
#ifdef PNG_SUPPORT
class PNGLibrary;
#endif
class StellaDb;
#include <chrono>
@ -80,7 +79,7 @@ class OSystem
/**
Create all child objects which belong to this OSystem
*/
virtual bool create();
virtual bool initialize(const Settings::Options& options);
/**
Creates the various framebuffers/renderers available in this system.
@ -172,13 +171,6 @@ class OSystem
*/
TimerManager& timer() const { return *myTimerManager; }
/**
This method should be called to initiate the process of loading settings
from the config file. It takes care of loading settings, applying
commandline overrides, and finally validating all settings.
*/
void loadConfig(const Settings::Options& options);
/**
This method should be called to save the current settings. It first asks
each subsystem to update its settings, then it saves all settings to the
@ -447,9 +439,9 @@ class OSystem
*/
virtual void stateChanged(EventHandlerState state) { }
virtual shared_ptr<KeyValueRepository> getSettingsRepository();
virtual shared_ptr<KeyValueRepository> getSettingsRepository() = 0;
virtual shared_ptr<CompositeKeyValueRepository> getPropertyRepository();
virtual shared_ptr<CompositeKeyValueRepository> getPropertyRepository() = 0;
protected:
@ -473,6 +465,10 @@ class OSystem
virtual void getBaseDirAndConfig(string& basedir, string& homedir,
bool useappdir, const string& usedir) = 0;
virtual void initPersistence(FilesystemNode& basedir) = 0;
virtual string describePresistence() = 0;
protected:
// Pointer to the EventHandler object
unique_ptr<EventHandler> myEventHandler;
@ -568,9 +564,15 @@ class OSystem
static string ourOverrideBaseDir;
static bool ourOverrideBaseDirWithApp;
shared_ptr<StellaDb> myStellaDb;
private:
/**
This method should be called to initiate the process of loading settings
from the config file. It takes care of loading settings, applying
commandline overrides, and finally validating all settings.
*/
void loadConfig(const Settings::Options& options);
/**
Creates the various sound devices available in this system
*/

View File

@ -0,0 +1,44 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "OSystemStandalone.hxx"
#include "StellaDb.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystemStandalone::initPersistence(FilesystemNode& basedir)
{
myStellaDb = make_shared<StellaDb>(basedir.getPath(), "stella");
myStellaDb->initialize();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string OSystemStandalone::describePresistence()
{
return (myStellaDb && myStellaDb->isValid()) ? myStellaDb->databaseFileName() : "none";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<KeyValueRepository> OSystemStandalone::getSettingsRepository()
{
return shared_ptr<KeyValueRepository>(myStellaDb, &myStellaDb->settingsRepository());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<CompositeKeyValueRepository> OSystemStandalone::getPropertyRepository()
{
return shared_ptr<CompositeKeyValueRepository>(myStellaDb, &myStellaDb->propertyRepository());
}

View File

@ -0,0 +1,46 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef OSYSTEM_STANDALONE_HXX
#define OSYSTEM_STANDALONE_HXX
#include "OSystem.hxx"
class StellaDb;
class OSystemStandalone : public OSystem {
public:
OSystemStandalone() = default;
shared_ptr<KeyValueRepository> getSettingsRepository() override;
shared_ptr<CompositeKeyValueRepository> getPropertyRepository() override;
protected:
void initPersistence(FilesystemNode& basedir) override;
string describePresistence() override;
private:
shared_ptr<StellaDb> myStellaDb;
};
#endif // OSYSTEM_STANDALONE_HXX

View File

@ -75,6 +75,7 @@ MODULE_OBJS := \
src/emucore/MT24LC256.o \
src/emucore/MD5.o \
src/emucore/OSystem.o \
src/emucore/OSystemStandalone.o \
src/emucore/Paddles.o \
src/emucore/PlusROM.o \
src/emucore/PointingDevice.o \

View File

@ -39,13 +39,6 @@ SOURCES_CXX := \
$(CORE_DIR)/common/repository/KeyValueRepositoryConfigfile.cxx \
$(CORE_DIR)/common/repository/KeyValueRepositoryJsonFile.cxx \
$(CORE_DIR)/common/repository/KeyValueRepositoryPropertyFile.cxx \
$(CORE_DIR)/common/repository/sqlite/AbstractKeyValueRepositorySqlite.cxx \
$(CORE_DIR)/common/repository/sqlite/CompositeKeyValueRepositorySqlite.cxx \
$(CORE_DIR)/common/repository/sqlite/KeyValueRepositorySqlite.cxx \
$(CORE_DIR)/common/repository/sqlite/StellaDb.cxx \
$(CORE_DIR)/common/repository/sqlite/SqliteDatabase.cxx \
$(CORE_DIR)/common/repository/sqlite/SqliteStatement.cxx \
$(CORE_DIR)/common/repository/sqlite/SqliteTransaction.cxx \
$(CORE_DIR)/emucore/AtariVox.cxx \
$(CORE_DIR)/emucore/Bankswitch.cxx \
$(CORE_DIR)/emucore/Booster.cxx \
@ -149,5 +142,4 @@ SOURCES_CXX := \
$(CORE_DIR)/emucore/TIASurface.cxx \
$(CORE_DIR)/emucore/tia/TIA.cxx
SOURCES_C := \
$(CORE_DIR)/sqlite/sqlite3.c
SOURCES_C :=

View File

@ -17,6 +17,8 @@
#include "FSNode.hxx"
#include "OSystemLIBRETRO.hxx"
#include "repository/KeyValueRepositoryNoop.hxx"
#include "repository/CompositeKeyValueRepositoryNoop.hxx"
#ifdef _WIN32
const string slash = "\\";
@ -30,3 +32,25 @@ void OSystemLIBRETRO::getBaseDirAndConfig(string& basedir, string& homedir,
{
basedir = homedir = "." + slash;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystemLIBRETRO::initPersistence(FilesystemNode& basedir)
{}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string OSystemLIBRETRO::describePresistence()
{
return "none";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<KeyValueRepository> OSystemLIBRETRO::getSettingsRepository()
{
return make_shared<KeyValueRepositoryNoop>();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<CompositeKeyValueRepository> OSystemLIBRETRO::getPropertyRepository()
{
return make_shared<CompositeKeyValueRepositoryNoop>();
}

View File

@ -48,6 +48,16 @@ class OSystemLIBRETRO : public OSystem
*/
void getBaseDirAndConfig(string& basedir, string& homedir,
bool useappdir, const string& usedir) override;
shared_ptr<KeyValueRepository> getSettingsRepository() override;
shared_ptr<CompositeKeyValueRepository> getPropertyRepository() override;
protected:
void initPersistence(FilesystemNode& basedir) override;
string describePresistence() override;
};
#endif

View File

@ -47,9 +47,7 @@ bool StellaLIBRETRO::create(bool logging)
myOSystem = make_unique<OSystemLIBRETRO>();
Settings::Options options;
myOSystem->loadConfig(options);
myOSystem->create();
myOSystem->initialize(options);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -18,7 +18,7 @@
#ifndef OSYSTEM_MACOS_HXX
#define OSYSTEM_MACOS_HXX
#include "OSystem.hxx"
#include "OSystemStandalone.hxx"
/**
This class defines an OSystem object for UNIX-like OS's (macOS).
@ -27,7 +27,7 @@
@author Stephen Anthony
*/
class OSystemMACOS : public OSystem
class OSystemMACOS : public OSystemStandalone
{
public:
OSystemMACOS() = default;

View File

@ -705,6 +705,8 @@
E034A5EF209FB25D00C89E9E /* EmulationTiming.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E034A5ED209FB25C00C89E9E /* EmulationTiming.hxx */; };
E0406FB61F81A85400A82AE0 /* AbstractFrameManager.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0DFDD781F81A358000F3505 /* AbstractFrameManager.cxx */; };
E0406FB81F81A85400A82AE0 /* FrameManager.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0DFDD7B1F81A358000F3505 /* FrameManager.cxx */; };
E050876E25A1337400E4B62A /* OSystemStandalone.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E050876C25A1337400E4B62A /* OSystemStandalone.cxx */; };
E050876F25A1337400E4B62A /* OSystemStandalone.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E050876D25A1337400E4B62A /* OSystemStandalone.hxx */; };
E06508BE2272447200B341AC /* KeyValueRepositoryNoop.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E06508B82272447200B341AC /* KeyValueRepositoryNoop.hxx */; };
E06508BF2272447200B341AC /* KeyValueRepository.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E06508B92272447200B341AC /* KeyValueRepository.hxx */; };
E06508C02272447200B341AC /* KeyValueRepositoryConfigfile.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E06508BA2272447200B341AC /* KeyValueRepositoryConfigfile.hxx */; };
@ -1509,6 +1511,8 @@
E0306E0B1F93E916003DDD52 /* JitterEmulation.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = JitterEmulation.hxx; sourceTree = "<group>"; };
E034A5EC209FB25C00C89E9E /* EmulationTiming.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EmulationTiming.cxx; sourceTree = "<group>"; };
E034A5ED209FB25C00C89E9E /* EmulationTiming.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = EmulationTiming.hxx; sourceTree = "<group>"; };
E050876C25A1337400E4B62A /* OSystemStandalone.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSystemStandalone.cxx; sourceTree = "<group>"; };
E050876D25A1337400E4B62A /* OSystemStandalone.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = OSystemStandalone.hxx; sourceTree = "<group>"; };
E06508B82272447200B341AC /* KeyValueRepositoryNoop.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = KeyValueRepositoryNoop.hxx; sourceTree = "<group>"; };
E06508B92272447200B341AC /* KeyValueRepository.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = KeyValueRepository.hxx; sourceTree = "<group>"; };
E06508BA2272447200B341AC /* KeyValueRepositoryConfigfile.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = KeyValueRepositoryConfigfile.hxx; sourceTree = "<group>"; };
@ -1944,6 +1948,8 @@
2D6050CC0898776500C6DE89 /* emucore */ = {
isa = PBXGroup;
children = (
E050876C25A1337400E4B62A /* OSystemStandalone.cxx */,
E050876D25A1337400E4B62A /* OSystemStandalone.hxx */,
DC1B2EBE1E50036100F62837 /* AmigaMouse.hxx */,
DC1B2EC01E50036100F62837 /* AtariMouse.hxx */,
DC487FB40DA5350900E12499 /* AtariVox.cxx */,
@ -2858,6 +2864,7 @@
DCBDDE9B1D6A5F0E009DF1E9 /* Cart3EPlusWidget.hxx in Headers */,
DCCF4B0314BA27EB00814FAB /* DrivingWidget.hxx in Headers */,
DCCF4B0514BA27EB00814FAB /* KeyboardWidget.hxx in Headers */,
E050876F25A1337400E4B62A /* OSystemStandalone.hxx in Headers */,
DC5C768F14C26F7C0031EBC7 /* StellaKeys.hxx in Headers */,
DC36D2C914CAFAB0007DC821 /* CartFA2.hxx in Headers */,
DC56FCDF14CCCC4900A31CC3 /* MouseControl.hxx in Headers */,
@ -3195,6 +3202,7 @@
2D91750209BA90380026E9FF /* ToggleBitWidget.cxx in Sources */,
E0A3841B2589741A0062AA93 /* SqliteDatabase.cxx in Sources */,
E0A383FA2589732E0062AA93 /* sqlite3.c in Sources */,
E050876E25A1337400E4B62A /* OSystemStandalone.cxx in Sources */,
2D91750309BA90380026E9FF /* TogglePixelWidget.cxx in Sources */,
2D91750409BA90380026E9FF /* ToggleWidget.cxx in Sources */,
2D91750609BA90380026E9FF /* TiaZoomWidget.cxx in Sources */,

View File

@ -18,7 +18,7 @@
#ifndef OSYSTEM_UNIX_HXX
#define OSYSTEM_UNIX_HXX
#include "OSystem.hxx"
#include "OSystemStandalone.hxx"
/**
This class defines an OSystem object for UNIX-like OS's (Linux).
@ -27,7 +27,7 @@
@author Stephen Anthony
*/
class OSystemUNIX : public OSystem
class OSystemUNIX : public OSystemStandalone
{
public:
OSystemUNIX() = default;

View File

@ -18,7 +18,7 @@
#ifndef OSYSTEM_R77_HXX
#define OSYSTEM_R77_HXX
#include "OSystem.hxx"
#include "OSystemStandalone.hxx"
/**
This class defines an OSystem object for the Retron77 system.
@ -29,7 +29,7 @@
@author Stephen Anthony
*/
class OSystemR77 : public OSystem
class OSystemR77 : public OSystemStandalone
{
public:
OSystemR77() = default;

View File

@ -18,7 +18,7 @@
#ifndef OSYSTEM_WINDOWS_HXX
#define OSYSTEM_WINDOWS_HXX
#include "OSystem.hxx"
#include "OSystemStandalone.hxx"
/**
This class defines an OSystem object for Windows OS's.
@ -27,7 +27,7 @@
@author Stephen Anthony
*/
class OSystemWINDOWS : public OSystem
class OSystemWINDOWS : public OSystemStandalone
{
public:
OSystemWINDOWS() = default;