Game Development Reference
In-Depth Information
Listing 25-6. The Game::SetPlayerQuit and Game::SetPlayerWon Methods
void SetPlayerQuit()
{
m_finishedQueryLock.lock();
m_playerQuit = true;
m_finishedQueryLock.unlock();
}
void SetPlayerWon()
{
m_finishedQueryLock.lock();
m_playerWon = true;
m_finishedQueryLock.unlock();
}
bool GetPlayerWon()
{
m_finishedQueryLock.lock();
bool playerWon = m_playerWon;
m_finishedQueryLock.unlock();
return playerWon;
}
This means that we are required to update the Game::OnQuit method as shown in Listing 25-7.
Listing 25-7. The Game::OnQuit Method
void Game::OnQuit()
{
SerializationManager::GetSingleton().Save();
SetPlayerQuit();
}
The Game::OnQuit method now calls the SetPlayerQuit method, which uses the m_finishedQueryLock
to protect the variable access. The RunGame method needs to be updated to use the SetPlayerWon
and GetPlayerWon methods and is shown in Listing 25-8.
Listing 25-8. Updating Game::RunGame
void Game::RunGame()
{
InitializeRooms();
const bool loaded = SerializationManager::GetSingleton().Load();
WelcomePlayer(loaded);
while (!HasFinished())
{
GivePlayerOptions();
 
Search WWH ::




Custom Search