Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to reset GSDK in cppsdk #178

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cpp/cppsdk/gsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ namespace Microsoft
GSDKInternal::~GSDKInternal()
{
m_keepHeartbeatRunning = false;
m_heartbeatThread.join();
if (m_heartbeatThread.joinable())
{
m_heartbeatThread.join();
}
}

//Do not need to acquire lock for configuration becase startLog is only called from the constructor.
Expand Down Expand Up @@ -510,6 +513,18 @@ namespace Microsoft
GSDKInternal::get();
}

void GSDK::reset()
{
GSDKInternal::get().m_keepHeartbeatRunning = false;

if (GSDKInternal::get().m_heartbeatThread.joinable())
{
GSDKInternal::get().m_heartbeatThread.join();
}

GSDKInternal::m_instance.reset();
}

bool GSDK::readyForPlayers()
{
if (GSDKInternal::get().m_heartbeatRequest.m_currentGameState != GameState::Active)
Expand Down
3 changes: 3 additions & 0 deletions cpp/cppsdk/gsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ namespace Microsoft
/// <param name="debugLogs">Enables outputting additional logs to the GSDK log file.</param>
static void start(bool debugLogs = false);

/// <summary>Resets the GSDK state, joining all threads, requires start to be called before use again</summary>
static void reset();

/// <summary>Tells the Xcloud service information on who is connected.</summary>
/// <param name="currentlyConnectedPlayers"></param>
static void updateConnectedPlayers(const std::vector<ConnectedPlayer> &currentlyConnectedPlayers);
Expand Down