diff --git a/src/xrEngine/x_ray.cpp b/src/xrEngine/x_ray.cpp index baf9f5ec3af..f0f7a93c190 100644 --- a/src/xrEngine/x_ray.cpp +++ b/src/xrEngine/x_ray.cpp @@ -238,41 +238,6 @@ CApplication::CApplication(pcstr commandLine, GameModule* game) shortcuts.Disable(); #endif -#ifdef USE_DISCORD_INTEGRATION - discord::Activity activity{}; - { - ZoneScopedN("Init Discord"); - discord::Core::Create(DISCORD_APP_ID, discord::CreateFlags::NoRequireDiscord, &m_discord_core); - -# ifndef MASTER_GOLD - if (m_discord_core) - { - const auto level = xrDebug::DebuggerIsPresent() ? discord::LogLevel::Debug : discord::LogLevel::Info; - m_discord_core->SetLogHook(level, [](discord::LogLevel level, pcstr message) - { - switch (level) - { - case discord::LogLevel::Error: Log("!", message); break; - case discord::LogLevel::Warn: Log("~", message); break; - case discord::LogLevel::Info: Log("*", message); break; - case discord::LogLevel::Debug: Log("#", message); break; - } - }); - } -# endif - - activity.SetType(discord::ActivityType::Playing); - activity.SetApplicationId(DISCORD_APP_ID); - activity.SetState("Starting engine..."); - activity.GetAssets().SetLargeImage("logo"); - if (m_discord_core) - { - std::lock_guard guard{ m_discord_lock }; - m_discord_core->ActivityManager().UpdateActivity(activity, nullptr); - } - } -#endif - if (!strstr(commandLine, "-nosplash")) { const bool topmost = !strstr(commandLine, "-splashnotop"); @@ -324,17 +289,9 @@ CApplication::CApplication(pcstr commandLine, GameModule* game) Console->OnDeviceInitialize(); -#ifdef USE_DISCORD_INTEGRATION - const std::locale locale(""); - activity.SetState(StringToUTF8(Core.ApplicationTitle, locale).c_str()); - if (m_discord_core) - { - std::lock_guard guard{ m_discord_lock }; - m_discord_core->ActivityManager().UpdateActivity(activity, nullptr); - } -#endif - execUserScript(); + InitializeDiscord(); + TaskScheduler->Wait(createSoundDevicesList); Engine.Sound.Create(); @@ -557,6 +514,47 @@ void CApplication::HideSplash() SDL_FreeSurface(m_surface); } +void CApplication::InitializeDiscord() +{ +#ifdef USE_DISCORD_INTEGRATION + ZoneScoped; + discord::Core* core; + discord::Core::Create(DISCORD_APP_ID, discord::CreateFlags::NoRequireDiscord, &core); + +# ifndef MASTER_GOLD + if (core) + { + const auto level = xrDebug::DebuggerIsPresent() ? discord::LogLevel::Debug : discord::LogLevel::Info; + core->SetLogHook(level, [](discord::LogLevel level, pcstr message) + { + switch (level) + { + case discord::LogLevel::Error: Log("!", message); break; + case discord::LogLevel::Warn: Log("~", message); break; + case discord::LogLevel::Info: Log("*", message); break; + case discord::LogLevel::Debug: Log("#", message); break; + } + }); + } +# endif + + if (core) + { + const std::locale locale(""); + + discord::Activity activity{}; + activity.SetType(discord::ActivityType::Playing); + activity.SetApplicationId(DISCORD_APP_ID); + activity.SetState(StringToUTF8(Core.ApplicationTitle, locale).c_str()); + activity.GetAssets().SetLargeImage("logo"); + core->ActivityManager().UpdateActivity(activity, nullptr); + + std::lock_guard guard{ m_discord_lock }; + m_discord_core = core; + } +#endif +} + void CApplication::UpdateDiscordStatus() { #ifdef USE_DISCORD_INTEGRATION diff --git a/src/xrEngine/x_ray.h b/src/xrEngine/x_ray.h index d7bc129faba..2a698f6c420 100644 --- a/src/xrEngine/x_ray.h +++ b/src/xrEngine/x_ray.h @@ -35,6 +35,7 @@ class ENGINE_API CApplication final void ShowSplash(bool topmost); void HideSplash(); + void InitializeDiscord(); void UpdateDiscordStatus(); public: