From 8858ad1c41341089bf45056abafb0b5c81f4ee5b Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Tue, 7 Jan 2025 20:10:38 +0800 Subject: [PATCH] chore: remove some useless codes --- src-client/ll/core/main_win.cpp | 3 --- src-server/ll/core/main_win.cpp | 2 -- src/ll/api/base/Containers.h | 8 ++++---- src/ll/api/mod/Mod.h | 2 +- src/ll/api/mod/ModManagerRegistry.cpp | 9 --------- src/ll/api/mod/ModManagerRegistry.h | 2 -- src/ll/core/mod/ModRegistrar.cpp | 28 ++++++++------------------- src/ll/core/mod/ModRegistrar.h | 2 -- 8 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src-client/ll/core/main_win.cpp b/src-client/ll/core/main_win.cpp index 0d9d42e5e0..5d69a02364 100644 --- a/src-client/ll/core/main_win.cpp +++ b/src-client/ll/core/main_win.cpp @@ -124,9 +124,6 @@ LL_AUTO_TYPE_INSTANCE_HOOK( BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ulReasonForCall, LPVOID /*lpReserved*/) { using namespace ll; - if (ulReasonForCall == DLL_PROCESS_DETACH) { - mod::ModRegistrar::getInstance().releaseAllMods(); - } if (ulReasonForCall != DLL_PROCESS_ATTACH) return TRUE; setGamingStatus(GamingStatus::Default); diff --git a/src-server/ll/core/main_win.cpp b/src-server/ll/core/main_win.cpp index 7249eef442..eb02772a57 100644 --- a/src-server/ll/core/main_win.cpp +++ b/src-server/ll/core/main_win.cpp @@ -257,8 +257,6 @@ LL_AUTO_TYPE_INSTANCE_HOOK( command::CommandRegistrar::getInstance().clear(); - mod::ModRegistrar::getInstance().releaseAllMods(); - origin(); } diff --git a/src/ll/api/base/Containers.h b/src/ll/api/base/Containers.h index da4b66afcb..720e837cd8 100644 --- a/src/ll/api/base/Containers.h +++ b/src/ll/api/base/Containers.h @@ -69,7 +69,7 @@ template < class Key, class Hash = ::phmap::priv::hash_default_hash, class Eq = ::phmap::priv::hash_default_eq, - class Alloc = ::phmap::priv::Allocator, + class Alloc = ::std::allocator, size_t N = 4, class Mutex = std::shared_mutex> using ConcurrentDenseSet = ::phmap::parallel_flat_hash_set; @@ -78,7 +78,7 @@ template < class Value, class Hash = ::phmap::priv::hash_default_hash, class Eq = ::phmap::priv::hash_default_eq, - class Alloc = ::phmap::priv::Allocator<::phmap::priv::Pair>, + class Alloc = ::std::allocator<::std::pair>, size_t N = 4, class Mutex = std::shared_mutex> using ConcurrentDenseMap = ::phmap::parallel_flat_hash_map; @@ -87,7 +87,7 @@ template < class Key, class Hash = ::phmap::priv::hash_default_hash, class Eq = ::phmap::priv::hash_default_eq, - class Alloc = ::phmap::priv::Allocator, + class Alloc = ::std::allocator, size_t N = 4, class Mutex = std::shared_mutex> using ConcurrentDenseNodeSet = ::phmap::parallel_node_hash_set; @@ -96,7 +96,7 @@ template < class Value, class Hash = ::phmap::priv::hash_default_hash, class Eq = ::phmap::priv::hash_default_eq, - class Alloc = ::phmap::priv::Allocator<::phmap::priv::Pair>, + class Alloc = ::std::allocator<::std::pair>, size_t N = 4, class Mutex = std::shared_mutex> using ConcurrentDenseNodeMap = ::phmap::parallel_node_hash_map; diff --git a/src/ll/api/mod/Mod.h b/src/ll/api/mod/Mod.h index 5e739bb75e..26cb5b0688 100644 --- a/src/ll/api/mod/Mod.h +++ b/src/ll/api/mod/Mod.h @@ -11,7 +11,7 @@ namespace ll::mod { -LLAPI std::filesystem::path const& getModsRoot(); +LLNDAPI std::filesystem::path const& getModsRoot(); class ModManager; class Mod { diff --git a/src/ll/api/mod/ModManagerRegistry.cpp b/src/ll/api/mod/ModManagerRegistry.cpp index 1ea9854cbf..e8eec39b91 100644 --- a/src/ll/api/mod/ModManagerRegistry.cpp +++ b/src/ll/api/mod/ModManagerRegistry.cpp @@ -25,15 +25,6 @@ ModManagerRegistry& ModManagerRegistry::getInstance() { return instance; } -Expected<> ModManagerRegistry::releaseManagers() noexcept try { - std::lock_guard lock(impl->modMtx); - impl->loadedMods.clear(); - impl->managers.clear(); - return {}; -} catch (...) { - return makeExceptionError(); -} - Expected<> ModManagerRegistry::loadMod(Manifest manifest) noexcept try { std::lock_guard lock(impl->modMtx); if (hasManager(manifest.type)) { diff --git a/src/ll/api/mod/ModManagerRegistry.h b/src/ll/api/mod/ModManagerRegistry.h index 68645292b0..c93cad9568 100644 --- a/src/ll/api/mod/ModManagerRegistry.h +++ b/src/ll/api/mod/ModManagerRegistry.h @@ -17,8 +17,6 @@ class ModManagerRegistry { ModManagerRegistry(); ~ModManagerRegistry(); - Expected<> releaseManagers() noexcept; - Expected<> loadMod(Manifest manifest) noexcept; Expected<> unloadMod(std::string_view name) noexcept; diff --git a/src/ll/core/mod/ModRegistrar.cpp b/src/ll/core/mod/ModRegistrar.cpp index 17ce60b230..538cc22974 100644 --- a/src/ll/core/mod/ModRegistrar.cpp +++ b/src/ll/core/mod/ModRegistrar.cpp @@ -38,6 +38,7 @@ namespace ll::mod { struct ModRegistrar::Impl { std::recursive_mutex mutex; data::DependencyGraph deps; + ModManagerRegistry& registry = ModManagerRegistry::getInstance(); }; ModRegistrar::ModRegistrar() : impl(std::make_unique()) {} @@ -82,7 +83,7 @@ void ModRegistrar::loadAllMods() noexcept try { getLogger().info("Loading mods..."_tr()); - auto& registry = ModManagerRegistry::getInstance(); + auto& registry = impl->registry; if (!registry.addManager(std::make_shared())) { getLogger().error("Failed to create native mod manager"_tr()); @@ -269,7 +270,7 @@ void ModRegistrar::enableAllMods() noexcept try { auto begin = std::chrono::steady_clock::now(); size_t count{}; for (auto& name : names) { - auto mod = ModManagerRegistry::getInstance().getMod(name); + auto mod = impl->registry.getMod(name); if (!mod || mod->isEnabled()) continue; getLogger().info("Enabling {0} v{1}"_tr(name, mod->getManifest().version.value_or(data::Version{0, 0, 0}))); if (auto res = enableMod(name); res) { @@ -295,7 +296,7 @@ void ModRegistrar::disableAllMods() noexcept try { if (!names.empty()) { getLogger().info("Disabling mods..."_tr()); for (auto& name : std::ranges::reverse_view(names)) { - auto mod = ModManagerRegistry::getInstance().getMod(name); + auto mod = impl->registry.getMod(name); if (!mod || mod->isDisabled()) continue; getLogger().info("Disabling {0} v{1}"_tr(name, mod->getManifest().version.value_or(data::Version{0, 0, 0})) ); @@ -307,17 +308,6 @@ void ModRegistrar::disableAllMods() noexcept try { } catch (...) { error_utils::printCurrentException(getLogger()); } -void ModRegistrar::releaseAllMods() noexcept try { - // TODO: check lifetime - // std::lock_guard lock(impl->mutex); - // if (auto res = ModManagerRegistry::getInstance().releaseManagers(); !res) { - // res.error().log(getLogger(), io::LogLevel::Warn); - // } - // impl->deps.clear(); - return; -} catch (...) { - error_utils::printCurrentException(getLogger()); -} Expected<> ModRegistrar::loadMod(std::string_view name) noexcept { std::lock_guard lock(impl->mutex); @@ -332,7 +322,7 @@ Expected<> ModRegistrar::loadMod(std::string_view name) noexcept { } } auto& manifest = *res; - auto& reg = ModManagerRegistry::getInstance(); + auto& reg = impl->registry; if (manifest.dependencies) { for (auto& dependency : *manifest.dependencies) { if (!reg.hasMod(dependency.name) || !checkVersion(reg.getMod(dependency.name)->getManifest(), dependency)) { @@ -364,13 +354,11 @@ Expected<> ModRegistrar::unloadMod(std::string_view name) noexcept { if (!dependents.empty()) { return makeStringError("{0} still depends on {1}"_tr(dependents, name)); } - return ModManagerRegistry::getInstance().unloadMod(name).transform([&, this]() { - impl->deps.erase(std::string{name}); - }); + return impl->registry.unloadMod(name).transform([&, this]() { impl->deps.erase(std::string{name}); }); } Expected<> ModRegistrar::enableMod(std::string_view name) noexcept { std::lock_guard lock(impl->mutex); - auto& registry = ModManagerRegistry::getInstance(); + auto& registry = impl->registry; auto dependents = impl->deps.dependentOn(std::string{name}); erase_if(dependents, [&](auto& name) { if (auto ptr = registry.getMod(name); ptr) { @@ -385,7 +373,7 @@ Expected<> ModRegistrar::enableMod(std::string_view name) noexcept { } Expected<> ModRegistrar::disableMod(std::string_view name) noexcept { std::lock_guard lock(impl->mutex); - auto& registry = ModManagerRegistry::getInstance(); + auto& registry = impl->registry; auto dependents = impl->deps.dependentBy(std::string{name}); erase_if(dependents, [&](auto& name) { if (auto ptr = registry.getMod(name); ptr) { diff --git a/src/ll/core/mod/ModRegistrar.h b/src/ll/core/mod/ModRegistrar.h index a11036b8e5..d7174a9b1a 100644 --- a/src/ll/core/mod/ModRegistrar.h +++ b/src/ll/core/mod/ModRegistrar.h @@ -34,8 +34,6 @@ class ModRegistrar { void disableAllMods() noexcept; - void releaseAllMods() noexcept; - Expected<> loadMod(std::string_view name) noexcept; Expected<> unloadMod(std::string_view name) noexcept;