Fix recursive stuff

This commit is contained in:
altalk23 2022-12-14 10:42:06 +03:00
parent 643abe64ab
commit 950db7e474
6 changed files with 26 additions and 52 deletions

View file

@ -31,7 +31,7 @@ namespace geode {
~HandleToSaved();
};
inline GEODE_HIDDEN Mod* takeNextLoaderMod();
GEODE_HIDDEN Mod* takeNextLoaderMod();
/**
* @class Mod

View file

@ -42,18 +42,16 @@ static ModInfo getInternalModInfo() {
}
}
InternalMod::InternalMod() : Mod(ModInfo()) {}
Mod* InternalMod::get() {
auto& mod = Mod::sharedMod<>;
if (mod) return mod;
void InternalMod::setModInfo() {
m_info = getInternalModInfo();
m_saveDirPath = dirs::getModsSaveDir() / m_info.id;
ghc::filesystem::create_directories(m_saveDirPath);
}
InternalMod::~InternalMod() {}
InternalMod* InternalMod::get() {
static auto g_mod = new InternalMod;
g_mod->setup();
return g_mod;
mod = new Mod(getInternalModInfo());
auto setupRes = mod->setup();
if (!setupRes) {
log::error("Failed to setup internal mod! ({})", setupRes.unwrapErr());
return mod;
}
return mod;
}

View file

@ -7,12 +7,6 @@ class InternalMod;
USE_GEODE_NAMESPACE();
class InternalMod : public Mod {
protected:
InternalMod();
virtual ~InternalMod();
public:
static InternalMod* get();
void setModInfo();
static Mod* get();
};

View file

@ -190,8 +190,14 @@ Result<Mod*> Loader::Impl::loadModFromInfo(ModInfo const& info) {
// create Mod instance
auto mod = new Mod(info);
mod->setup();
auto setupRes = mod->setup();
if (!setupRes) {
return Err(fmt::format(
"Unable to setup mod '{}': {}",
info.id, setupRes.unwrapErr()
));
}
m_mods.insert({ info.id, mod });
mod->m_enabled = InternalMod::get()->getSavedValue<bool>(
"should-load-" + info.id, true
@ -589,38 +595,14 @@ void Loader::Impl::provideNextMod(Mod* mod) {
Mod* Loader::Impl::takeNextMod() {
if (!m_nextMod) {
// this means we're hopefully loading the internal mod
// TODO: make this less hacky
auto res = this->setupInternalMod();
if (!res) {
log::error("{}", res.unwrapErr());
return nullptr;
}
return m_nextMod;
return InternalMod::get();
}
auto ret = m_nextMod;
m_nextModCV.notify_all();
return ret;
}
void Loader::Impl::releaseNextMod() {
auto lock = std::unique_lock<std::mutex>(m_nextModAccessMutex);
m_nextModCV.wait(lock);
m_nextMod = nullptr;
m_nextModLock.unlock();
}
Result<> Loader::Impl::setupInternalMod() {
this->provideNextMod(InternalMod::get());
(void)Mod::get();
m_nextModLock.unlock();
InternalMod::get()->setModInfo();
auto sett = Mod::get()->loadData();
if (!sett) {
log::error("{}", sett.unwrapErr());
}
return Ok();
}

View file

@ -63,8 +63,6 @@ public:
std::mutex m_nextModAccessMutex;
Mod* m_nextMod = nullptr;
Result<> setupInternalMod();
void provideNextMod(Mod* mod);
Mod* takeNextMod();
void releaseNextMod();

View file

@ -25,7 +25,7 @@ Result<> Mod::setup() {
if (!loadRes) {
log::warn(
"Unable to load data for \"{}\": {}",
info.id, loadRes.unwrapErr()
m_info.id, loadRes.unwrapErr()
);
}
return Ok();
@ -285,6 +285,8 @@ Result<> Mod::loadBinary() {
GEODE_UNWRAP(this->loadPlatformBinary());
m_binaryLoaded = true;
LoaderImpl::get()->releaseNextMod();
// Call implicit entry point to place hooks etc.
m_implicitLoadFunc(this);