Merge pull request #878 from flowln/lazy_settings

This commit is contained in:
Sefa Eyeoglu 2022-08-20 12:50:56 +02:00 committed by GitHub
commit 92d7e44525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 111 additions and 70 deletions

View File

@ -53,15 +53,22 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
: QObject() : QObject()
{ {
m_settings = settings; m_settings = settings;
m_global_settings = globalSettings;
m_rootDir = rootDir; m_rootDir = rootDir;
m_settings->registerSetting("name", "Unnamed Instance"); m_settings->registerSetting("name", "Unnamed Instance");
m_settings->registerSetting("iconKey", "default"); m_settings->registerSetting("iconKey", "default");
m_settings->registerSetting("notes", ""); m_settings->registerSetting("notes", "");
m_settings->registerSetting("lastLaunchTime", 0); m_settings->registerSetting("lastLaunchTime", 0);
m_settings->registerSetting("totalTimePlayed", 0); m_settings->registerSetting("totalTimePlayed", 0);
m_settings->registerSetting("lastTimePlayed", 0); m_settings->registerSetting("lastTimePlayed", 0);
// Game time override
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false);
m_settings->registerOverride(globalSettings->getSetting("ShowGameTime"), gameTimeOverride);
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), gameTimeOverride);
// NOTE: Sometimees InstanceType is already registered, as it was used to identify the type of // NOTE: Sometimees InstanceType is already registered, as it was used to identify the type of
// a locally stored instance // a locally stored instance
if (!m_settings->getSetting("InstanceType")) if (!m_settings->getSetting("InstanceType"))
@ -149,7 +156,7 @@ void BaseInstance::setManagedPack(const QString& type, const QString& id, const
int BaseInstance::getConsoleMaxLines() const int BaseInstance::getConsoleMaxLines() const
{ {
auto lineSetting = settings()->getSetting("ConsoleMaxLines"); auto lineSetting = m_settings->getSetting("ConsoleMaxLines");
bool conversionOk = false; bool conversionOk = false;
int maxLines = lineSetting->get().toInt(&conversionOk); int maxLines = lineSetting->get().toInt(&conversionOk);
if(!conversionOk) if(!conversionOk)
@ -162,7 +169,7 @@ int BaseInstance::getConsoleMaxLines() const
bool BaseInstance::shouldStopOnConsoleOverflow() const bool BaseInstance::shouldStopOnConsoleOverflow() const
{ {
return settings()->get("ConsoleOverflowStop").toBool(); return m_settings->get("ConsoleOverflowStop").toBool();
} }
void BaseInstance::iconUpdated(QString key) void BaseInstance::iconUpdated(QString key)
@ -237,7 +244,7 @@ void BaseInstance::setRunning(bool running)
int64_t BaseInstance::totalTimePlayed() const int64_t BaseInstance::totalTimePlayed() const
{ {
qint64 current = settings()->get("totalTimePlayed").toLongLong(); qint64 current = m_settings->get("totalTimePlayed").toLongLong();
if(m_isRunning) if(m_isRunning)
{ {
QDateTime timeNow = QDateTime::currentDateTime(); QDateTime timeNow = QDateTime::currentDateTime();
@ -253,7 +260,7 @@ int64_t BaseInstance::lastTimePlayed() const
QDateTime timeNow = QDateTime::currentDateTime(); QDateTime timeNow = QDateTime::currentDateTime();
return m_timeStarted.secsTo(timeNow); return m_timeStarted.secsTo(timeNow);
} }
return settings()->get("lastTimePlayed").toLongLong(); return m_settings->get("lastTimePlayed").toLongLong();
} }
void BaseInstance::resetTimePlayed() void BaseInstance::resetTimePlayed()
@ -272,8 +279,10 @@ QString BaseInstance::instanceRoot() const
return m_rootDir; return m_rootDir;
} }
SettingsObjectPtr BaseInstance::settings() const SettingsObjectPtr BaseInstance::settings()
{ {
loadSpecificSettings();
return m_settings; return m_settings;
} }
@ -340,7 +349,7 @@ QString BaseInstance::windowTitle() const
} }
// FIXME: why is this here? move it to MinecraftInstance!!! // FIXME: why is this here? move it to MinecraftInstance!!!
QStringList BaseInstance::extraArguments() const QStringList BaseInstance::extraArguments()
{ {
return Commandline::splitArgs(settings()->get("JvmArgs").toString()); return Commandline::splitArgs(settings()->get("JvmArgs").toString());
} }

View File

@ -154,7 +154,7 @@ public:
return level; return level;
}; };
virtual QStringList extraArguments() const; virtual QStringList extraArguments();
/// Traits. Normally inside the version, depends on instance implementation. /// Traits. Normally inside the version, depends on instance implementation.
virtual QSet <QString> traits() const = 0; virtual QSet <QString> traits() const = 0;
@ -170,9 +170,18 @@ public:
/*! /*!
* \brief Gets this instance's settings object. * \brief Gets this instance's settings object.
* This settings object stores instance-specific settings. * This settings object stores instance-specific settings.
*
* Note that this method is not const.
* It may call loadSpecificSettings() to ensure those are loaded.
*
* \return A pointer to this instance's settings object. * \return A pointer to this instance's settings object.
*/ */
virtual SettingsObjectPtr settings() const; virtual SettingsObjectPtr settings();
/*!
* \brief Loads settings specific to an instance type if they're not already loaded.
*/
virtual void loadSpecificSettings() = 0;
/// returns a valid update task /// returns a valid update task
virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0; virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0;
@ -206,7 +215,7 @@ public:
virtual QString instanceConfigFolder() const = 0; virtual QString instanceConfigFolder() const = 0;
/// get variables this instance exports /// get variables this instance exports
virtual QMap<QString, QString> getVariables() const = 0; virtual QMap<QString, QString> getVariables() = 0;
virtual QString typeName() const = 0; virtual QString typeName() const = 0;
@ -268,6 +277,11 @@ public:
protected: protected:
void changeStatus(Status newStatus); void changeStatus(Status newStatus);
SettingsObjectPtr globalSettings() const { return m_global_settings.lock(); };
bool isSpecificSettingsLoaded() const { return m_specific_settings_loaded; }
void setSpecificSettingsLoaded(bool loaded) { m_specific_settings_loaded = loaded; }
signals: signals:
/*! /*!
* \brief Signal emitted when properties relevant to the instance view change * \brief Signal emitted when properties relevant to the instance view change
@ -296,6 +310,10 @@ private: /* data */
bool m_crashed = false; bool m_crashed = false;
bool m_hasUpdate = false; bool m_hasUpdate = false;
bool m_hasBrokenVersion = false; bool m_hasBrokenVersion = false;
SettingsObjectWeakPtr m_global_settings;
bool m_specific_settings_loaded = false;
}; };
Q_DECLARE_METATYPE(shared_qobject_ptr<BaseInstance>) Q_DECLARE_METATYPE(shared_qobject_ptr<BaseInstance>)

View File

@ -15,6 +15,10 @@ public:
void saveNow() override void saveNow() override
{ {
} }
void loadSpecificSettings() override
{
setSpecificSettingsLoaded(true);
}
QString getStatusbarDescription() override QString getStatusbarDescription() override
{ {
return tr("Unknown instance type"); return tr("Unknown instance type");
@ -43,7 +47,7 @@ public:
{ {
return QProcessEnvironment(); return QProcessEnvironment();
} }
QMap<QString, QString> getVariables() const override QMap<QString, QString> getVariables() override
{ {
return QMap<QString, QString>(); return QMap<QString, QString>();
} }

View File

@ -115,6 +115,19 @@ private:
MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: BaseInstance(globalSettings, settings, rootDir) : BaseInstance(globalSettings, settings, rootDir)
{ {
m_components.reset(new PackProfile(this));
}
void MinecraftInstance::saveNow()
{
m_components->saveNow();
}
void MinecraftInstance::loadSpecificSettings()
{
if (isSpecificSettingsLoaded())
return;
// Java Settings // Java Settings
auto javaOverride = m_settings->registerSetting("OverrideJava", false); auto javaOverride = m_settings->registerSetting("OverrideJava", false);
auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false); auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false);
@ -124,64 +137,58 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride); auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride);
auto javaOrArgs = std::make_shared<OrSetting>("JavaOrArgsOverride", javaOverride, argsOverride); auto javaOrArgs = std::make_shared<OrSetting>("JavaOrArgsOverride", javaOverride, argsOverride);
m_settings->registerOverride(globalSettings->getSetting("JavaPath"), javaOrLocation); if (auto global_settings = globalSettings()) {
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs); m_settings->registerOverride(global_settings->getSetting("JavaPath"), javaOrLocation);
m_settings->registerOverride(globalSettings->getSetting("IgnoreJavaCompatibility"), javaOrLocation); m_settings->registerOverride(global_settings->getSetting("JvmArgs"), javaOrArgs);
m_settings->registerOverride(global_settings->getSetting("IgnoreJavaCompatibility"), javaOrLocation);
// special! // special!
m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaTimestamp"), javaOrLocation);
m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaVersion"), javaOrLocation);
m_settings->registerPassthrough(globalSettings->getSetting("JavaArchitecture"), javaOrLocation); m_settings->registerPassthrough(global_settings->getSetting("JavaArchitecture"), javaOrLocation);
// Window Size // Window Size
auto windowSetting = m_settings->registerSetting("OverrideWindow", false); auto windowSetting = m_settings->registerSetting("OverrideWindow", false);
m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized"), windowSetting); m_settings->registerOverride(global_settings->getSetting("LaunchMaximized"), windowSetting);
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth"), windowSetting); m_settings->registerOverride(global_settings->getSetting("MinecraftWinWidth"), windowSetting);
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight"), windowSetting); m_settings->registerOverride(global_settings->getSetting("MinecraftWinHeight"), windowSetting);
// Memory // Memory
auto memorySetting = m_settings->registerSetting("OverrideMemory", false); auto memorySetting = m_settings->registerSetting("OverrideMemory", false);
m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc"), memorySetting); m_settings->registerOverride(global_settings->getSetting("MinMemAlloc"), memorySetting);
m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc"), memorySetting); m_settings->registerOverride(global_settings->getSetting("MaxMemAlloc"), memorySetting);
m_settings->registerOverride(globalSettings->getSetting("PermGen"), memorySetting); m_settings->registerOverride(global_settings->getSetting("PermGen"), memorySetting);
// Minecraft launch method // Minecraft launch method
auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false); auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false);
m_settings->registerOverride(globalSettings->getSetting("MCLaunchMethod"), launchMethodOverride); m_settings->registerOverride(global_settings->getSetting("MCLaunchMethod"), launchMethodOverride);
// Native library workarounds // Native library workarounds
auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false); auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false);
m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
// Peformance related options // Peformance related options
auto performanceOverride = m_settings->registerSetting("OverridePerformance", false); auto performanceOverride = m_settings->registerSetting("OverridePerformance", false);
m_settings->registerOverride(globalSettings->getSetting("EnableFeralGamemode"), performanceOverride); m_settings->registerOverride(global_settings->getSetting("EnableFeralGamemode"), performanceOverride);
m_settings->registerOverride(globalSettings->getSetting("EnableMangoHud"), performanceOverride); m_settings->registerOverride(global_settings->getSetting("EnableMangoHud"), performanceOverride);
m_settings->registerOverride(globalSettings->getSetting("UseDiscreteGpu"), performanceOverride); m_settings->registerOverride(global_settings->getSetting("UseDiscreteGpu"), performanceOverride);
// Game time // Miscellaneous
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false); auto miscellaneousOverride = m_settings->registerSetting("OverrideMiscellaneous", false);
m_settings->registerOverride(globalSettings->getSetting("ShowGameTime"), gameTimeOverride); m_settings->registerOverride(global_settings->getSetting("CloseAfterLaunch"), miscellaneousOverride);
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), gameTimeOverride); m_settings->registerOverride(global_settings->getSetting("QuitAfterGameStop"), miscellaneousOverride);
m_settings->set("InstanceType", "OneSix");
}
// Join server on launch, this does not have a global override // Join server on launch, this does not have a global override
m_settings->registerSetting("JoinServerOnLaunch", false); m_settings->registerSetting("JoinServerOnLaunch", false);
m_settings->registerSetting("JoinServerOnLaunchAddress", ""); m_settings->registerSetting("JoinServerOnLaunchAddress", "");
// Miscellaneous qDebug() << "Instance-type specific settings were loaded!";
auto miscellaneousOverride = m_settings->registerSetting("OverrideMiscellaneous", false);
m_settings->registerOverride(globalSettings->getSetting("CloseAfterLaunch"), miscellaneousOverride);
m_settings->registerOverride(globalSettings->getSetting("QuitAfterGameStop"), miscellaneousOverride);
m_settings->set("InstanceType", "OneSix"); setSpecificSettingsLoaded(true);
m_components.reset(new PackProfile(this));
}
void MinecraftInstance::saveNow()
{
m_components->saveNow();
} }
QString MinecraftInstance::typeName() const QString MinecraftInstance::typeName() const
@ -308,7 +315,7 @@ QDir MinecraftInstance::versionsPath() const
return QDir::current().absoluteFilePath("versions"); return QDir::current().absoluteFilePath("versions");
} }
QStringList MinecraftInstance::getClassPath() const QStringList MinecraftInstance::getClassPath()
{ {
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString(); auto javaArchitecture = settings()->get("JavaArchitecture").toString();
@ -323,7 +330,7 @@ QString MinecraftInstance::getMainClass() const
return profile->getMainClass(); return profile->getMainClass();
} }
QStringList MinecraftInstance::getNativeJars() const QStringList MinecraftInstance::getNativeJars()
{ {
QStringList jars, nativeJars; QStringList jars, nativeJars;
auto javaArchitecture = settings()->get("JavaArchitecture").toString(); auto javaArchitecture = settings()->get("JavaArchitecture").toString();
@ -332,7 +339,7 @@ QStringList MinecraftInstance::getNativeJars() const
return nativeJars; return nativeJars;
} }
QStringList MinecraftInstance::extraArguments() const QStringList MinecraftInstance::extraArguments()
{ {
auto list = BaseInstance::extraArguments(); auto list = BaseInstance::extraArguments();
auto version = getPackProfile(); auto version = getPackProfile();
@ -358,7 +365,7 @@ QStringList MinecraftInstance::extraArguments() const
return list; return list;
} }
QStringList MinecraftInstance::javaArguments() const QStringList MinecraftInstance::javaArguments()
{ {
QStringList args; QStringList args;
@ -415,7 +422,7 @@ QStringList MinecraftInstance::javaArguments() const
return args; return args;
} }
QMap<QString, QString> MinecraftInstance::getVariables() const QMap<QString, QString> MinecraftInstance::getVariables()
{ {
QMap<QString, QString> out; QMap<QString, QString> out;
out.insert("INST_NAME", name()); out.insert("INST_NAME", name());
@ -943,9 +950,9 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
process->appendStep(new CreateGameFolders(pptr)); process->appendStep(new CreateGameFolders(pptr));
} }
if (!serverToJoin && m_settings->get("JoinServerOnLaunch").toBool()) if (!serverToJoin && settings()->get("JoinServerOnLaunch").toBool())
{ {
QString fullAddress = m_settings->get("JoinServerOnLaunchAddress").toString(); QString fullAddress = settings()->get("JoinServerOnLaunchAddress").toString();
serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(fullAddress))); serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(fullAddress)));
} }
@ -1053,10 +1060,10 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
QString MinecraftInstance::launchMethod() QString MinecraftInstance::launchMethod()
{ {
return m_settings->get("MCLaunchMethod").toString(); return settings()->get("MCLaunchMethod").toString();
} }
JavaVersion MinecraftInstance::getJavaVersion() const JavaVersion MinecraftInstance::getJavaVersion()
{ {
return JavaVersion(settings()->get("JavaVersion").toString()); return JavaVersion(settings()->get("JavaVersion").toString());
} }

View File

@ -20,6 +20,8 @@ public:
virtual ~MinecraftInstance() {}; virtual ~MinecraftInstance() {};
virtual void saveNow() override; virtual void saveNow() override;
void loadSpecificSettings() override;
// FIXME: remove // FIXME: remove
QString typeName() const override; QString typeName() const override;
// FIXME: remove // FIXME: remove
@ -79,15 +81,15 @@ public:
////// Launch stuff ////// ////// Launch stuff //////
Task::Ptr createUpdateTask(Net::Mode mode) override; Task::Ptr createUpdateTask(Net::Mode mode) override;
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) override; shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) override;
QStringList extraArguments() const override; QStringList extraArguments() override;
QStringList verboseDescription(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) override; QStringList verboseDescription(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) override;
QList<Mod*> getJarMods() const; QList<Mod*> getJarMods() const;
QString createLaunchScript(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin); QString createLaunchScript(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin);
/// get arguments passed to java /// get arguments passed to java
QStringList javaArguments() const; QStringList javaArguments();
/// get variables for launch command variable substitution/environment /// get variables for launch command variable substitution/environment
QMap<QString, QString> getVariables() const override; QMap<QString, QString> getVariables() override;
/// create an environment for launching processes /// create an environment for launching processes
QProcessEnvironment createEnvironment() override; QProcessEnvironment createEnvironment() override;
@ -103,16 +105,16 @@ public:
QString getStatusbarDescription() override; QString getStatusbarDescription() override;
// FIXME: remove // FIXME: remove
virtual QStringList getClassPath() const; virtual QStringList getClassPath();
// FIXME: remove // FIXME: remove
virtual QStringList getNativeJars() const; virtual QStringList getNativeJars();
// FIXME: remove // FIXME: remove
virtual QString getMainClass() const; virtual QString getMainClass() const;
// FIXME: remove // FIXME: remove
virtual QStringList processMinecraftArgs(AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) const; virtual QStringList processMinecraftArgs(AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) const;
virtual JavaVersion getJavaVersion() const; virtual JavaVersion getJavaVersion();
protected: protected:
QMap<QString, QString> createCensorFilterFromSession(AuthSessionPtr session); QMap<QString, QString> createCensorFilterFromSession(AuthSessionPtr session);

View File

@ -25,6 +25,7 @@ class Setting;
class SettingsObject; class SettingsObject;
typedef std::shared_ptr<SettingsObject> SettingsObjectPtr; typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;
typedef std::weak_ptr<SettingsObject> SettingsObjectWeakPtr;
/*! /*!
* \brief The SettingsObject handles communicating settings between the application and a * \brief The SettingsObject handles communicating settings between the application and a