Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
tried to implement other thread method for weather and added thread p…
Browse files Browse the repository at this point in the history
…ause.... It's broken xD
  • Loading branch information
SkyHorizon3 committed Oct 3, 2023
1 parent a2a02a4 commit 749fd56
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
5 changes: 4 additions & 1 deletion include/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,7 @@ inline std::mutex timeMutexInterior;
inline std::mutex timeMutexWeather;

inline std::mutex threadMutex;
inline std::map<std::thread::id, std::shared_ptr<std::condition_variable>> threadConditions;
inline std::map<std::thread::id, std::shared_ptr<std::condition_variable>> threadConditions;

inline std::thread weatherThread;
inline bool ispaused = false;
39 changes: 26 additions & 13 deletions src/Processor.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "../include/Processor.h"
#include "../include/ReshadeIntegration.h"
#include "../src/ReshadeToggler.cpp"

void PauseThread(std::thread& threadToPause);
void ResumeThread(std::thread& threadToResume);

RE::BSEventNotifyControl Processor::ProcessEvent(const RE::MenuOpenCloseEvent* event, RE::BSTEventSource<RE::MenuOpenCloseEvent>*)
{

const auto& menuName = event->menuName;
auto& opening = event->opening;

Expand All @@ -19,35 +22,45 @@ RE::BSEventNotifyControl Processor::ProcessEvent(const RE::MenuOpenCloseEvent* e
return RE::BSEventNotifyControl::kContinue; // Skip if no open menus
}

bool enableReshadeMenu = true;
for (const Info& menu : menuList)
{
if (m_OpenMenus.find(menu.Name) != m_OpenMenus.end())
{
if (EnableWeather)
{
PauseThread(weatherThread);

bool enableReshade = [this]()
DEBUG_LOG(g_Logger, "PauseThreadWorked", nullptr);
ispaused = true;
}
enableReshadeMenu = false;
}
else
{
for (const Info& menu : menuList)
if (ispaused)
{
if (m_OpenMenus.find(menu.Name) != m_OpenMenus.end())
{
//PauseThread(weatherThread);
return false;
}
ResumeThread(weatherThread);
DEBUG_LOG(g_Logger, "ResumeThreadWorked", nullptr);
}
return true;
}
();
}



if (s_pRuntime != nullptr)
{
if (ToggleStateMenus.find("All") != std::string::npos)
{
ReshadeIntegration::ApplyReshadeState(enableReshade, ToggleAllStateMenus);
ReshadeIntegration::ApplyReshadeState(enableReshadeMenu, ToggleAllStateMenus);
}
else if (ToggleStateMenus.find("Specific") != std::string::npos)
{
ReshadeIntegration::ApplySpecificReshadeStates(enableReshade, Categories::Menu);
ReshadeIntegration::ApplySpecificReshadeStates(enableReshadeMenu, Categories::Menu);
}

DEBUG_LOG(g_Logger, "Menu {} {}", menuName, opening ? "open" : "closed");
DEBUG_LOG(g_Logger, "Reshade {}", enableReshade ? "enabled" : "disabled");
DEBUG_LOG(g_Logger, "Reshade {}", enableReshadeMenu ? "enabled" : "disabled");
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/ReshadeToggler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void WeatherThread()

if (!EnableWeather)
{
std::thread(WeatherThread).join();
weatherThread.join();
g_Logger->info("Detaching WeatherThread");
}
}
Expand Down Expand Up @@ -577,7 +577,7 @@ void MessageListener(SKSE::MessagingInterface::Message* message)
if (EnableWeather)
{
processor.ProcessWeatherBasedToggling();
std::thread(WeatherThread).detach();
weatherThread = std::thread(WeatherThread);
}

break;
Expand Down Expand Up @@ -668,7 +668,7 @@ int __stdcall DllMain(HMODULE hModule, uint32_t fdwReason, void*)
}
if (EnableWeather)
{
std::thread(WeatherThread).join();
weatherThread.join();
}

unregister_addon_events();
Expand Down

0 comments on commit 749fd56

Please sign in to comment.