DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

sys_localuser.h (6031B)


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