diff options
author | Kitty Barnett <develop@catznip.com> | 2024-08-31 01:33:27 +0200 |
---|---|---|
committer | Erik Kundiman <erik@megapahit.org> | 2025-05-11 16:25:42 +0800 |
commit | 49567c97fd8416b9130b3af52055cf973d9aa894 (patch) | |
tree | 5a8c4824a56a0a5eb4bc8276272fabe4eae1958b | |
parent | 390ba2f4fdc8520192182f97d934c9f20367c6a1 (diff) |
Minimal code needed to add RLVa with an on/off toggle
-rw-r--r-- | indra/newview/CMakeLists.txt | 7 | ||||
-rw-r--r-- | indra/newview/app_settings/settings.xml | 11 | ||||
-rw-r--r-- | indra/newview/llappviewer.cpp | 7 | ||||
-rw-r--r-- | indra/newview/llstartup.cpp | 3 | ||||
-rw-r--r-- | indra/newview/rlvactions.cpp | 15 | ||||
-rw-r--r-- | indra/newview/rlvactions.h | 19 | ||||
-rw-r--r-- | indra/newview/rlvcommon.cpp | 40 | ||||
-rw-r--r-- | indra/newview/rlvcommon.h | 16 | ||||
-rw-r--r-- | indra/newview/rlvdefines.h | 51 | ||||
-rw-r--r-- | indra/newview/rlvhandler.cpp | 40 | ||||
-rw-r--r-- | indra/newview/rlvhandler.h | 25 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/strings.xml | 1 |
12 files changed, 235 insertions, 0 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index b6100c05bc..7762dd4d03 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -742,6 +742,9 @@ set(viewer_SOURCE_FILES llxmlrpctransaction.cpp noise.cpp pipeline.cpp + rlvactions.cpp + rlvcommon.cpp + rlvhandler.cpp ) if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) @@ -1410,6 +1413,10 @@ set(viewer_HEADER_FILES llxmlrpctransaction.h noise.h pipeline.h + rlvdefines.h + rlvactions.h + rlvcommon.h + rlvhandler.h roles_constants.h VertexCache.h VorbisFramework.h diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index f8487c020e..c33f23585f 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -10063,6 +10063,17 @@ <key>Value</key> <string>https://megapahit.com/enter_bug.cgi?product=Viewer</string> </map> + <key>RestrainedLove</key> + <map> + <key>Comment</key> + <string>Toggles RLVa features (requires restart)</string> + <key>Persist</key> + <integer>1</integer> + <key>Type</key> + <string>Boolean</string> + <key>Value</key> + <boolean>1</boolean> + </map> <key>RevokePermsOnStopAnimation</key> <map> <key>Comment</key> diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index c5190fe486..bbba964604 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -255,6 +255,9 @@ using namespace LL; #include "llviewereventrecorder.h" #include <chrono> +#include "rlvactions.h" +#include "rlvcommon.h" +#include "rlvhandler.h" // *FIX: These extern globals should be cleaned up. // The globals either represent state/config/resource-storage of either @@ -1710,6 +1713,9 @@ bool LLAppViewer::cleanup() //ditch LLVOAvatarSelf instance gAgentAvatarp = NULL; + // Sanity check to catch cases where someone forgot to do an RlvActions::isRlvEnabled() check + LL_ERRS_IF(!RlvHandler::isEnabled() && RlvHandler::instanceExists()) << "RLV handler instance exists even though RLVa is disabled" << LL_ENDL; + LLNotifications::instance().clear(); // workaround for DEV-35406 crash on shutdown @@ -3371,6 +3377,7 @@ LLSD LLAppViewer::getViewerInfo() const } #endif + info["RLV_VERSION"] = RlvActions::isRlvEnabled() ? RlvStrings::getVersionAbout() : "(disabled)"; info["OPENGL_VERSION"] = ll_safe_string((const char*)(glGetString(GL_VERSION))); // Settings diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 9a26ebc5f9..29ae386618 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -209,6 +209,7 @@ #include "threadpool.h" #include "llperfstats.h" +#include "rlvhandler.h" #if LL_WINDOWS #include "lldxhardware.h" @@ -934,6 +935,8 @@ bool idle_startup() return false; } + RlvHandler::setEnabled(gSavedSettings.get<bool>(Rlv::Settings::Main)); + // reset the values that could have come in from a slurl // DEV-42215: Make sure they're not empty -- gUserCredential // might already have been set from gSavedSettings, and it's too bad diff --git a/indra/newview/rlvactions.cpp b/indra/newview/rlvactions.cpp new file mode 100644 index 0000000000..1988c99ecf --- /dev/null +++ b/indra/newview/rlvactions.cpp @@ -0,0 +1,15 @@ +#include "llviewerprecompiledheaders.h" + +#include "rlvactions.h" +#include "rlvhandler.h" + +// ============================================================================ +// Helper functions +// + +bool RlvActions::isRlvEnabled() +{ + return RlvHandler::isEnabled(); +} + +// ============================================================================ diff --git a/indra/newview/rlvactions.h b/indra/newview/rlvactions.h new file mode 100644 index 0000000000..ac4fc73339 --- /dev/null +++ b/indra/newview/rlvactions.h @@ -0,0 +1,19 @@ +#pragma once + +// ============================================================================ +// RlvActions - developer-friendly non-RLVa code facing class, use in lieu of RlvHandler whenever possible +// + +class RlvActions +{ + // ================ + // Helper functions + // ================ +public: + /* + * Convenience function to check if RLVa is enabled without having to include rlvhandler.h + */ + static bool isRlvEnabled(); +}; + +// ============================================================================ diff --git a/indra/newview/rlvcommon.cpp b/indra/newview/rlvcommon.cpp new file mode 100644 index 0000000000..f641d56a85 --- /dev/null +++ b/indra/newview/rlvcommon.cpp @@ -0,0 +1,40 @@ +#include "llviewerprecompiledheaders.h" +#include "llversioninfo.h" + +#include "rlvdefines.h" +#include "rlvcommon.h" + +using namespace Rlv; + +// ============================================================================ +// RlvStrings +// + +std::string RlvStrings::getVersion(bool wants_legacy) +{ + return llformat("%s viewer v%d.%d.%d (RLVa %d.%d.%d)", + !wants_legacy ? "RestrainedLove" : "RestrainedLife", + SpecVersion::Major, SpecVersion::Minor, SpecVersion::Patch, + ImplVersion::Major, ImplVersion::Minor, ImplVersion::Patch); +} + +std::string RlvStrings::getVersionAbout() +{ + return llformat("RLV v%d.%d.%d / RLVa v%d.%d.%d.%d", + SpecVersion::Major, SpecVersion::Minor, SpecVersion::Patch, + ImplVersion::Major, ImplVersion::Minor, ImplVersion::Patch, LLVersionInfo::instance().getBuild()); +} + +std::string RlvStrings::getVersionNum() +{ + return llformat("%d%02d%02d%02d", + SpecVersion::Major, SpecVersion::Minor, SpecVersion::Patch, SpecVersion::Build); +} + +std::string RlvStrings::getVersionImplNum() +{ + return llformat("%d%02d%02d%02d", + ImplVersion::Major, ImplVersion::Minor, ImplVersion::Patch, ImplVersion::ImplId); +} + +// ============================================================================ diff --git a/indra/newview/rlvcommon.h b/indra/newview/rlvcommon.h new file mode 100644 index 0000000000..288d48e373 --- /dev/null +++ b/indra/newview/rlvcommon.h @@ -0,0 +1,16 @@ +#pragma once + +// ============================================================================ +// RlvStrings +// + +class RlvStrings +{ +public: + static std::string getVersion(bool wants_legacy); + static std::string getVersionAbout(); + static std::string getVersionImplNum(); + static std::string getVersionNum(); +}; + +// ============================================================================ diff --git a/indra/newview/rlvdefines.h b/indra/newview/rlvdefines.h new file mode 100644 index 0000000000..dc1e58f47c --- /dev/null +++ b/indra/newview/rlvdefines.h @@ -0,0 +1,51 @@ +#pragma once + +// ============================================================================ +// Defines +// + +namespace Rlv +{ + // Version of the specification we report + struct SpecVersion { + static constexpr S32 Major = 4; + static constexpr S32 Minor = 0; + static constexpr S32 Patch = 0; + static constexpr S32 Build = 0; + }; + + // RLVa implementation version + struct ImplVersion { + static constexpr S32 Major = 3; + static constexpr S32 Minor = 0; + static constexpr S32 Patch = 0; + static constexpr S32 ImplId = 2; /* Official viewer */ + }; +} + +// Defining these makes it easier if we ever need to change our tag +#define RLV_WARNS LL_WARNS("RLV") +#define RLV_INFOS LL_INFOS("RLV") +#define RLV_DEBUGS LL_DEBUGS("RLV") +#define RLV_ENDL LL_ENDL + +// ============================================================================ +// Settings +// + +namespace Rlv +{ + namespace Settings + { + constexpr char Main[] = "RestrainedLove"; + constexpr char Debug[] = "RestrainedLoveDebug"; + + constexpr char DebugHideUnsetDup[] = "RLVaDebugHideUnsetDuplicate"; + constexpr char EnableIMQuery[] = "RLVaEnableIMQuery"; + constexpr char EnableTempAttach[] = "RLVaEnableTemporaryAttachments"; + constexpr char TopLevelMenu[] = "RLVaTopLevelMenu"; + }; + +}; + +// ============================================================================ diff --git a/indra/newview/rlvhandler.cpp b/indra/newview/rlvhandler.cpp new file mode 100644 index 0000000000..3315ed1999 --- /dev/null +++ b/indra/newview/rlvhandler.cpp @@ -0,0 +1,40 @@ +#include "llviewerprecompiledheaders.h" +#include "llappviewer.h" +#include "llstartup.h" + +#include "rlvdefines.h" +#include "rlvcommon.h" +#include "rlvhandler.h" + +using namespace Rlv; + +// ============================================================================ +// Static variable initialization +// + +bool RlvHandler::mIsEnabled = false; + +// ============================================================================ +// Initialization helper functions +// + +bool RlvHandler::canEnable() +{ + return LLStartUp::getStartupState() <= STATE_LOGIN_CLEANUP; +} + +bool RlvHandler::setEnabled(bool enable) +{ + if (mIsEnabled == enable) + return enable; + + if (enable && canEnable()) + { + RLV_INFOS << "Enabling Restrained Love API support - " << RlvStrings::getVersionAbout() << RLV_ENDL; + mIsEnabled = true; + } + + return mIsEnabled; +} + +// ============================================================================ diff --git a/indra/newview/rlvhandler.h b/indra/newview/rlvhandler.h new file mode 100644 index 0000000000..0d4cbe98fb --- /dev/null +++ b/indra/newview/rlvhandler.h @@ -0,0 +1,25 @@ +#pragma once + +#include "llsingleton.h" + +#include "rlvdefines.h" + +// ============================================================================ +// RlvHandler class +// + +class RlvHandler : public LLSingleton<RlvHandler> +{ + LLSINGLETON_EMPTY_CTOR(RlvHandler); + +public: + // Initialization (deliberately static so they can safely be called in tight loops) + static bool canEnable(); + static bool isEnabled() { return mIsEnabled; } + static bool setEnabled(bool enable); + +private: + static bool mIsEnabled; +}; + +// ============================================================================ diff --git a/indra/newview/skins/default/xui/en/strings.xml b/indra/newview/skins/default/xui/en/strings.xml index 44da9a8dac..afaa126c9c 100644 --- a/indra/newview/skins/default/xui/en/strings.xml +++ b/indra/newview/skins/default/xui/en/strings.xml @@ -60,6 +60,7 @@ Disk cache: [DISK_CACHE_INFO] HiDPI display mode: [HIDPI] </string> <string name="AboutLibs"> +RestrainedLove API: [RLV_VERSION] J2C Decoder Version: [J2C_VERSION] Audio Driver Version: [AUDIO_DRIVER_VERSION] [LIBCEF_VERSION] |