Skip to content

Commit

Permalink
chore: remove some useless codes
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jan 7, 2025
1 parent 3210714 commit 8858ad1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 43 deletions.
3 changes: 0 additions & 3 deletions src-client/ll/core/main_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src-server/ll/core/main_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ LL_AUTO_TYPE_INSTANCE_HOOK(

command::CommandRegistrar::getInstance().clear();

mod::ModRegistrar::getInstance().releaseAllMods();

origin();
}

Expand Down
8 changes: 4 additions & 4 deletions src/ll/api/base/Containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ template <
class Key,
class Hash = ::phmap::priv::hash_default_hash<Key>,
class Eq = ::phmap::priv::hash_default_eq<Key>,
class Alloc = ::phmap::priv::Allocator<Key>,
class Alloc = ::std::allocator<Key>,
size_t N = 4,
class Mutex = std::shared_mutex>
using ConcurrentDenseSet = ::phmap::parallel_flat_hash_set<Key, Hash, Eq, Alloc, N, Mutex>;
Expand All @@ -78,7 +78,7 @@ template <
class Value,
class Hash = ::phmap::priv::hash_default_hash<Key>,
class Eq = ::phmap::priv::hash_default_eq<Key>,
class Alloc = ::phmap::priv::Allocator<::phmap::priv::Pair<Key const, Value>>,
class Alloc = ::std::allocator<::std::pair<Key const, Value>>,
size_t N = 4,
class Mutex = std::shared_mutex>
using ConcurrentDenseMap = ::phmap::parallel_flat_hash_map<Key, Value, Hash, Eq, Alloc, N, Mutex>;
Expand All @@ -87,7 +87,7 @@ template <
class Key,
class Hash = ::phmap::priv::hash_default_hash<Key>,
class Eq = ::phmap::priv::hash_default_eq<Key>,
class Alloc = ::phmap::priv::Allocator<Key>,
class Alloc = ::std::allocator<Key>,
size_t N = 4,
class Mutex = std::shared_mutex>
using ConcurrentDenseNodeSet = ::phmap::parallel_node_hash_set<Key, Hash, Eq, Alloc, N, Mutex>;
Expand All @@ -96,7 +96,7 @@ template <
class Value,
class Hash = ::phmap::priv::hash_default_hash<Key>,
class Eq = ::phmap::priv::hash_default_eq<Key>,
class Alloc = ::phmap::priv::Allocator<::phmap::priv::Pair<Key const, Value>>,
class Alloc = ::std::allocator<::std::pair<Key const, Value>>,
size_t N = 4,
class Mutex = std::shared_mutex>
using ConcurrentDenseNodeMap = ::phmap::parallel_node_hash_map<Key, Value, Hash, Eq, Alloc, N, Mutex>;
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/mod/Mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ll::mod {

LLAPI std::filesystem::path const& getModsRoot();
LLNDAPI std::filesystem::path const& getModsRoot();

class ModManager;
class Mod {
Expand Down
9 changes: 0 additions & 9 deletions src/ll/api/mod/ModManagerRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 0 additions & 2 deletions src/ll/api/mod/ModManagerRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ModManagerRegistry {
ModManagerRegistry();
~ModManagerRegistry();

Expected<> releaseManagers() noexcept;

Expected<> loadMod(Manifest manifest) noexcept;

Expected<> unloadMod(std::string_view name) noexcept;
Expand Down
28 changes: 8 additions & 20 deletions src/ll/core/mod/ModRegistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace ll::mod {
struct ModRegistrar::Impl {
std::recursive_mutex mutex;
data::DependencyGraph<std::string> deps;
ModManagerRegistry& registry = ModManagerRegistry::getInstance();
};

ModRegistrar::ModRegistrar() : impl(std::make_unique<Impl>()) {}
Expand Down Expand Up @@ -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<NativeModManager>())) {
getLogger().error("Failed to create native mod manager"_tr());
Expand Down Expand Up @@ -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) {
Expand All @@ -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}))
);
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/ll/core/mod/ModRegistrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8858ad1

Please sign in to comment.