Skip to content

Commit

Permalink
Initialize Discord later, when user settings are loaded
Browse files Browse the repository at this point in the history
So that we can check if a user has disabled Discord status display and
not initialize Discord in this case.
This also speeds up splash screen showing
  • Loading branch information
Xottab-DUTY committed May 11, 2024
1 parent 606d5fb commit 1583242
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
88 changes: 43 additions & 45 deletions src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/x_ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ENGINE_API CApplication final
void ShowSplash(bool topmost);
void HideSplash();

void InitializeDiscord();
void UpdateDiscordStatus();

public:
Expand Down

0 comments on commit 1583242

Please sign in to comment.