PlayerProfile.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __PLAYERPROFILE_H__
  21. #define __PLAYERPROFILE_H__
  22. #include "Precompiled.h"
  23. #include "Serializer.h"
  24. //#include "SaveGameManager.h"
  25. #define MAX_PROFILE_SIZE ( 1024 * 1000 ) // High number for the key bindings
  26. #define SAVEGAME_PROFILE_FILENAME "_PROF"
  27. extern idCVar s_volume_sound;
  28. extern idCVar s_volume_midi;
  29. class idSaveGameProcessorSaveProfile;
  30. class idSaveGameProcessorLoadProfile;
  31. class idPlayerProfile;
  32. /*
  33. ================================================
  34. idProfileMgr
  35. ================================================
  36. */
  37. class idProfileMgr {
  38. public:
  39. idProfileMgr();
  40. ~idProfileMgr();
  41. // Called the first time it's asked to load
  42. void Init( idPlayerProfile * profile );
  43. void Pump();
  44. idPlayerProfile * GetProfile();
  45. private:
  46. void LoadSettings();
  47. void SaveSettings();
  48. private:
  49. idSaveGameProcessorSaveProfile * profileSaveProcessor;
  50. idSaveGameProcessorLoadProfile * profileLoadProcessor;
  51. idPlayerProfile * profile;
  52. saveGameHandle_t handle;
  53. };
  54. /*
  55. ================================================
  56. idSaveGameProcessorSaveProfile
  57. ================================================
  58. */
  59. class idSaveGameProcessorSaveProfile : public idSaveGameProcessor {
  60. public:
  61. DEFINE_CLASS( idSaveGameProcessorSaveProfile );
  62. idSaveGameProcessorSaveProfile();
  63. bool InitSaveProfile( idPlayerProfile * profile, const char * folder );
  64. virtual bool Process();
  65. private:
  66. idFile_Memory * profileFile;
  67. idFile_Memory * staticScreenshotFile;
  68. idPlayerProfile * profile;
  69. };
  70. /*
  71. ================================================
  72. idSaveGameProcessorLoadProfile
  73. ================================================
  74. */
  75. class idSaveGameProcessorLoadProfile: public idSaveGameProcessor {
  76. public:
  77. DEFINE_CLASS( idSaveGameProcessorLoadProfile );
  78. idSaveGameProcessorLoadProfile();
  79. ~idSaveGameProcessorLoadProfile();
  80. bool InitLoadProfile( idPlayerProfile * profile, const char * folder );
  81. virtual bool Process();
  82. virtual void PostProcess();
  83. private:
  84. idFile_Memory * profileFile;
  85. idPlayerProfile * profile;
  86. };
  87. /*
  88. ================================================
  89. profileStatValue_t
  90. ================================================
  91. */
  92. union profileStatValue_t {
  93. int i;
  94. float f;
  95. };
  96. /*
  97. ================================================
  98. idPlayerProfile
  99. The general rule for using cvars for settings is that if you want the player's profile settings to affect the startup
  100. of the game before there is a player associated with the game, use cvars. Example: video & volume settings.
  101. ================================================
  102. */
  103. class idPlayerProfile {
  104. public:
  105. static const int MAX_PLAYER_PROFILE_STATS = 500;
  106. enum state_t {
  107. IDLE = 0,
  108. SAVING,
  109. LOADING,
  110. SAVE_REQUESTED,
  111. LOAD_REQUESTED,
  112. ERR
  113. };
  114. enum displayMode_t {
  115. DISPLAY_INVALID = -1,
  116. DISPLAY_WINDOWED,
  117. DISPLAY_FULLSCREEN,
  118. MAX_DISPLAY_MODES
  119. };
  120. enum syncTypes_t {
  121. SYNC_INVALID = -1,
  122. SYNC_TEAR,
  123. SYNC_ON,
  124. SYNC_SMART,
  125. MAX_SYNC_COUNT,
  126. };
  127. public:
  128. idPlayerProfile(); // don't instantiate. we static_cast the child all over the place
  129. virtual ~idPlayerProfile();
  130. //------------------------
  131. // each game can override but call the parent serialize first
  132. //------------------------
  133. virtual void SetDefaults();
  134. virtual void Init();
  135. virtual bool SerializeSettings( idSerializer & ser );
  136. //------------------------
  137. // each game must override, not an abstract method because we have a static object as a hack... ugh.
  138. //------------------------
  139. virtual int32 GetProfileTag() { return -1; }
  140. int GetDeviceNumForProfile() { return deviceNum; }
  141. void SetDeviceNumForProfile( int num ) { deviceNum = num; }
  142. //------------------------
  143. void SaveSettings();
  144. void LoadSettings();
  145. state_t GetState() const { return state; }
  146. state_t GetRequestedState() const { return requestedState; }
  147. //------------------------
  148. // settings
  149. //------------------------
  150. float GetFrameScaleX() const { return frameScaleX; }
  151. float GetFrameScaleY() const { return frameScaleY; }
  152. void SetFrameScaleX( float scale ) { frameScaleX = scale; }
  153. void SetFrameScaleY( float scale ) { frameScaleY = scale; }
  154. int GetMusicVolume() const;
  155. int GetSoundVolume() const;
  156. void SetMusicVolume( int volume );
  157. void SetSoundVolume( int volume );
  158. bool GetAlwaysRun() const { return alwaysRun; }
  159. void SetAlwaysRun( bool set ) { alwaysRun = set; }
  160. //------------------------
  161. // misc
  162. //------------------------
  163. virtual int GetLevel() const;
  164. void ClearAchievementBit( const int id ); // Should only be called by idLocalUser
  165. bool GetAchievementBit( const int id ) const;
  166. void SetAchievementBit( const int id ); // Should only be called by idLocalUser
  167. bool GetSeenInstallMessage() const { return seenInstallMessage; }
  168. void SetSeenInstallMessage( bool seen ) { seenInstallMessage = seen; }
  169. bool HasSavedGame() const { return hasSavedGame; }
  170. void SetHasSavedGame() { hasSavedGame = true; }
  171. protected:
  172. friend class idLocalUser;
  173. friend class idProfileMgr;
  174. // used by idLocalUser and internally
  175. void StatSetInt( int s, int v );
  176. void StatSetFloat( int s, float v );
  177. int StatGetInt( int s ) const;
  178. float StatGetFloat( int s ) const;
  179. private:
  180. void SetState( state_t value ) { state = value; }
  181. void SetRequestedState( state_t value ) { requestedState = value; }
  182. protected:
  183. //------------------------
  184. // settings
  185. //------------------------
  186. bool alwaysRun;
  187. int musicVolume;
  188. int soundVolume;
  189. //------------------------
  190. // video settings
  191. //------------------------
  192. float frameScaleX;
  193. float frameScaleY;
  194. //------------------------
  195. // state management
  196. //------------------------
  197. state_t state;
  198. state_t requestedState;
  199. //------------------------
  200. // stats are stored in the profile
  201. //------------------------
  202. idStaticList< profileStatValue_t, MAX_PLAYER_PROFILE_STATS > stats;
  203. //------------------------
  204. // misc
  205. //------------------------
  206. int deviceNum;
  207. bool seenInstallMessage;
  208. uint64 achievementBits;
  209. bool hasSavedGame;
  210. };
  211. #endif