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