WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Driver_QuitChecker.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_QUIT_CHECKER_HPP
3 #define WORLDSIM_QUIT_CHECKER_HPP
4 
5 /* This object exploits the c++ guarantee that the destructor is always called, in order to deal with unanticipated shutdowns, such as the player clicking the X. However, it seems the destructor guarantee does not apply in some cases, such as ending the process using the task manager, or using ctrl+c from the console.
6 
7 It seems that threads are killed if the user uses CTRL+C on the cmd line however, which messes things up a bit.
8 
9 */
11 {
12  private:
13  Timer gameTime;
14 
15  public:
17  {
18  gameTime.init();
19  gameTime.start();
20 
21  // For now we will clear the savedata on startup because it can cause some instability.
22  std::cout<<"Deleting temporary data folder ("<<globalSettings.SAVE_FOLDER_PATH<<")\n";
23  if (globalSettings.SAVE_FOLDER_PATH.length() > 0 )
24  {
25  FileManager::deleteDirectory(globalSettings.SAVE_FOLDER_PATH,true);
26  }
27  }
29  {
30  QUIT_FLAG=true;
31  std::cout<<"Waiting to shutdown.\n";
32 #ifdef WILDCAT_THREADING
33  std::unique_lock lock(MUTEX_SHUTDOWN); // wait until threads are not doing anything critical.
34 #endif
35  std::cout<<"Shutting down.\n";
36  gameTime.update();
37  if (gameTime.seconds > 10 )
38  {
39  std::cout<<"Time played: "<<gameTime.seconds/60<<" minutes.\n";
40  }
41 
43  {
44  std::cout<<"Deleting temporary data folder ("<<globalSettings.SAVE_FOLDER_PATH<<")\n";
45  if (globalSettings.SAVE_FOLDER_PATH.length() > 0 )
46  {
47  FileManager::deleteDirectory(globalSettings.SAVE_FOLDER_PATH,true);
48  }
49  }
50  }
51 };
52 
53 #endif
bool QUIT_FLAG
Definition: Driver_Settings.cpp:307
bool CLEAN_SAVES_ON_EXIT
Definition: Driver_Settings.cpp:274
std::string SAVE_FOLDER_PATH
Definition: Driver_GlobalSettings.cpp:21
~QuitChecker()
Definition: Driver_QuitChecker.hpp:28
Definition: Driver_QuitChecker.hpp:10
QuitChecker()
Definition: Driver_QuitChecker.hpp:16
GlobalSettings globalSettings
Definition: Driver.cpp:12