sys_localuser.cpp 4.8 KB

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