sys_localuser.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 __SYS_LOCALUSER_H__
  21. #define __SYS_LOCALUSER_H__
  22. #include "sys_profile.h"
  23. struct achievementDescription_t;
  24. class idPlayerProfile;
  25. class idProfileMgr;
  26. enum onlineCaps_t {
  27. CAP_IS_ONLINE = BIT( 0 ),
  28. CAP_BLOCKED_PERMISSION = BIT( 1 ),
  29. CAP_CAN_PLAY_ONLINE = BIT( 2 ),
  30. };
  31. class idSerializer;
  32. /*
  33. ================================================
  34. localUserHandle_t
  35. ================================================
  36. */
  37. struct localUserHandle_t {
  38. public:
  39. typedef uint32 userHandleType_t;
  40. localUserHandle_t() : handle( 0 ) {}
  41. explicit localUserHandle_t( userHandleType_t handle_ ) : handle( handle_ ) {}
  42. bool operator == ( const localUserHandle_t & other ) const {
  43. return handle == other.handle;
  44. }
  45. bool operator < ( const localUserHandle_t & other ) const {
  46. return handle < other.handle;
  47. }
  48. bool IsValid() const { return handle > 0; }
  49. void WriteToMsg( idBitMsg & msg ) {
  50. msg.WriteLong( handle );
  51. }
  52. void ReadFromMsg( const idBitMsg & msg ) {
  53. handle = msg.ReadLong();
  54. }
  55. void Serialize( idSerializer & ser );
  56. private:
  57. userHandleType_t handle;
  58. };
  59. /*
  60. ================================================
  61. idLocalUser
  62. An idLocalUser is a user holding a controller.
  63. It represents someone controlling the menu or game.
  64. They may not necessarily be in a game (which would be a session user of TYPE_GAME).
  65. A controller user references an input device (which is a gamepad, keyboard, etc).
  66. ================================================
  67. */
  68. class idLocalUser {
  69. public:
  70. idLocalUser();
  71. virtual ~idLocalUser() {}
  72. void Pump();
  73. virtual void PumpPlatform() = 0;
  74. virtual bool IsPersistent() const { return IsProfileReady(); } // True if this user is a persistent user, and can save stats, etc (signed in)
  75. virtual bool IsProfileReady() const = 0; // True if IsPersistent is true AND profile is signed into LIVE service
  76. virtual bool IsOnline() const = 0; // True if this user has online capabilities
  77. virtual uint32 GetOnlineCaps() const = 0; // Returns combination of onlineCaps_t flags
  78. virtual bool HasOwnerChanged() const { return false; } // Whether or not the original persistent owner has changed since it was first registered
  79. virtual int GetInputDevice() const = 0; // Input device of controller
  80. virtual const char * GetGamerTag() const = 0; // Gamertag of user
  81. virtual bool IsInParty() const = 0; // True if the user is in a party (do we support this on pc and ps3? )
  82. virtual int GetPartyCount() const = 0; // Gets the amount of users in the party
  83. // Storage related
  84. virtual bool IsStorageDeviceAvailable() const; // Only false if the player has chosen to play without a storage device, only possible on 360, if available, everything needs to check for available space
  85. virtual void ResetStorageDevice();
  86. virtual bool StorageSizeAvailable( uint64 minSizeInBytes, int64 & neededBytes );
  87. // These set stats within the profile as a enum/value pair
  88. virtual void SetStatInt( int stat, int value );
  89. virtual void SetStatFloat( int stat, float value );
  90. virtual int GetStatInt( int stat );
  91. virtual float GetStatFloat( int stat);
  92. virtual idPlayerProfile * GetProfile() { return GetProfileMgr().GetProfile(); }
  93. const idPlayerProfile * GetProfile() const { return const_cast< idLocalUser * >( this )->GetProfile(); }
  94. idProfileMgr & GetProfileMgr() { return profileMgr; }
  95. // Helper state to determine if the user is joining a party lobby or not
  96. void SetJoiningLobby( int lobbyType, bool value ) { joiningLobby[lobbyType] = value; }
  97. bool IsJoiningLobby( int lobbyType ) const { return joiningLobby[lobbyType]; }
  98. bool CanPlayOnline() const { return ( GetOnlineCaps() & CAP_CAN_PLAY_ONLINE ) > 0; }
  99. localUserHandle_t GetLocalUserHandle() const { return localUserHandle; }
  100. void SetLocalUserHandle( localUserHandle_t newHandle ) { localUserHandle = newHandle; }
  101. // Creates a new profile if one not already there
  102. void LoadProfileSettings();
  103. void SaveProfileSettings();
  104. // Will attempt to sync the achievement bits between the server and the localUser when the achievement system is ready
  105. void RequestSyncAchievements() { syncAchievementsRequested = true; }
  106. private:
  107. bool joiningLobby[2];
  108. localUserHandle_t localUserHandle;
  109. idProfileMgr profileMgr;
  110. bool syncAchievementsRequested;
  111. };
  112. #endif // __SYS_LOCALUSER_H__