DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

sys_localuser.cpp (4951B)


      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 #pragma hdrstop
     29 #include "../idlib/precompiled.h"
     30 
     31 extern idCVar fs_savepath;
     32 
     33 /*
     34 ========================
     35 idLocalUser::idLocalUser
     36 ========================
     37 */
     38 idLocalUser::idLocalUser() {
     39 	memset( joiningLobby, 0, sizeof( joiningLobby ) );
     40 	profileMgr.Init( this );
     41 	syncAchievementsRequested = 0;
     42 }
     43 
     44 void idLocalUser::Pump() {
     45 	// Pump the profile
     46 	GetProfileMgr().Pump();
     47 
     48 	if ( GetProfileMgr().GetProfile() != NULL && GetProfileMgr().GetProfile()->GetState() == idPlayerProfile::IDLE ) {
     49 		// Pump achievements
     50 		if ( syncAchievementsRequested ) {
     51 			if ( session->GetAchievementSystem().IsInitialized() ) {
     52 				session->GetAchievementSystem().SyncAchievementBits( this );
     53 				syncAchievementsRequested = false;
     54 			}
     55 		}
     56 		session->GetAchievementSystem().Pump();
     57 	}
     58 
     59 	// Extra platform pump if necessary
     60 	PumpPlatform();
     61 }
     62 
     63 /*
     64 ========================
     65 idLocalUser::IsStorageDeviceAvailable
     66 ========================
     67 */
     68 bool idLocalUser::IsStorageDeviceAvailable() const {
     69 	return saveGame_enable.GetBool();
     70 }
     71 
     72 /*
     73 ========================
     74 idLocalUser::ResetStorageDevice
     75 ========================
     76 */
     77 void idLocalUser::ResetStorageDevice() {
     78 }
     79 
     80 /*
     81 ========================
     82 idLocalUser::StorageSizeAvailable
     83 ========================
     84 */
     85 bool idLocalUser::StorageSizeAvailable( uint64 minSizeInBytes, int64 & neededBytes ) {
     86 	int64 size = Sys_GetDriveFreeSpaceInBytes( fs_savepath.GetString() );
     87 
     88 	neededBytes = minSizeInBytes - size;
     89 	if ( neededBytes < 0 ) {
     90 		neededBytes = 0;
     91 	}
     92 
     93 	return neededBytes == 0;
     94 }
     95 
     96 /*
     97 ========================
     98 idLocalUser::SetStatInt
     99 ========================
    100 */
    101 void idLocalUser::SetStatInt( int s, int v ) {
    102 	idPlayerProfile * profile = GetProfile();
    103 	if ( profile != NULL ) {
    104 		return profile->StatSetInt( s, v );
    105 	}
    106 }
    107 
    108 /*
    109 ========================
    110 idLocalUser::SetStatFloat
    111 ========================
    112 */
    113 void idLocalUser::SetStatFloat( int s, float v ) {
    114 	idPlayerProfile * profile = GetProfile();
    115 	if ( profile != NULL ) {
    116 		return profile->StatSetFloat( s, v );
    117 	}
    118 }
    119 
    120 /*
    121 ========================
    122 idLocalUser::GetStatInt
    123 ========================
    124 */
    125 int	idLocalUser::GetStatInt( int s ) { 
    126 	const idPlayerProfile * profile = GetProfile();
    127 
    128 	if ( profile != NULL && s >= 0 ) {
    129 		return profile->StatGetInt( s );
    130 	}
    131 
    132 	return 0; 
    133 }
    134 
    135 /*
    136 ========================
    137 idLocalUser::GetStatFloat
    138 ========================
    139 */
    140 float idLocalUser::GetStatFloat( int s ) {
    141 	const idPlayerProfile * profile = GetProfile();
    142 
    143 	if ( profile != NULL ) {
    144 		return profile->StatGetFloat( s );
    145 	}
    146 
    147 	return 0.0f;
    148 }
    149 
    150 /*
    151 ========================
    152 idLocalUser::LoadProfileSettings
    153 ========================
    154 */
    155 void idLocalUser::LoadProfileSettings() {
    156 	idPlayerProfile * profile = GetProfileMgr().GetProfile();
    157 
    158 	// Lazy instantiation
    159 	if ( profile == NULL ) {
    160 		// Create a new profile
    161 		profile = idPlayerProfile::CreatePlayerProfile( GetInputDevice() );
    162 	}
    163 
    164 	if ( profile != NULL ) {
    165 		profile->LoadSettings();
    166 	}
    167 
    168 	return;
    169 }
    170 
    171 /*
    172 ========================
    173 idLocalUser::SaveProfileSettings
    174 ========================
    175 */
    176 void idLocalUser::SaveProfileSettings() {
    177 	idPlayerProfile * profile = GetProfileMgr().GetProfile();
    178 	if ( profile != NULL ) {
    179 		profile->SaveSettings( true );
    180 	}
    181 
    182 	return;
    183 }
    184 
    185 /*
    186 ========================
    187 localUserHandle_t::Serialize
    188 ========================
    189 */
    190 void localUserHandle_t::Serialize( idSerializer & ser ) {
    191 	ser.Serialize( handle );
    192 }