sys_voicechat.h (5722B)
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_VOICECHATMGR_H__ 29 #define __SYS_VOICECHATMGR_H__ 30 31 #include "sys_lobby_backend.h" 32 33 /* 34 ================================================ 35 idVoiceChatMgr 36 ================================================ 37 */ 38 class idVoiceChatMgr { 39 public: 40 idVoiceChatMgr() : activeLobbyType( -1 ), activeGroupIndex( 0 ), sendFrame( 0 ), disableVoiceReasons( 0 ), sendGlobal( false ) {} 41 42 virtual void Init( void * pXAudio2 ); 43 virtual void Shutdown(); 44 45 void RegisterTalker( lobbyUser_t * user, int lobbyType, bool isLocal ); 46 void UnregisterTalker( lobbyUser_t * user, int lobbyType, bool isLocal ); 47 void GetActiveLocalTalkers( idStaticList< int, MAX_PLAYERS > & localTalkers ); 48 void GetRecipientsForTalker( int talkerIndex, idStaticList< const lobbyAddress_t *, MAX_PLAYERS > & recipients ); 49 50 void SetTalkerGroup( const lobbyUser_t * user, int lobbyType, int groupIndex ); 51 52 void SetActiveLobby( int lobbyType ); 53 void SetActiveChatGroup( int groupIndex ); 54 int FindTalkerByUserId( lobbyUserID_t lobbyUserID, int lobbyType ); 55 bool GetLocalChatData( int talkerIndex, byte * data, int & dataSize ); 56 void SubmitIncomingChatData( const byte * data, int dataSize ); 57 voiceState_t GetVoiceState( const lobbyUser_t * user ); 58 bool CanSendVoiceTo( int talkerFromIndex, int talkerToIndex ); 59 bool IsRestrictedByPrivleges(); 60 61 void SetHeadsetState( int talkerIndex, bool state ); 62 bool GetHeadsetState( int talkerIndex ) const { return talkers[ talkerIndex ].hasHeadset; } 63 bool HasHeadsetStateChanged( int talkerIndex ); 64 65 enum disableVoiceReason_t { 66 REASON_GENERIC = BIT( 0 ), 67 REASON_PRIVILEGES = BIT( 1 ), 68 }; 69 70 void SetDisableVoiceReason( disableVoiceReason_t reason ); 71 void ClearDisableVoiceReason( disableVoiceReason_t reason ); 72 73 virtual bool GetLocalChatDataInternal( int talkerIndex, byte * data, int & dataSize ) = 0; 74 virtual void SubmitIncomingChatDataInternal( int talkerIndex, const byte * data, int dataSize ) = 0; 75 virtual bool TalkerHasData( int talkerIndex ) = 0; 76 virtual void Pump() {} 77 virtual void FlushBuffers() {} 78 virtual void ToggleMuteLocal( const lobbyUser_t * src, const lobbyUser_t * target ); 79 80 protected: 81 82 struct remoteMachine_t { 83 int lobbyType; 84 lobbyAddress_t address; 85 int refCount; 86 int sendFrame; 87 }; 88 89 struct talker_t { 90 talker_t() : 91 user( NULL ), 92 isLocal( false ), 93 lobbyType( -1 ), 94 groupIndex( -1 ), 95 registered( false ), 96 registeredSuccess( false ), 97 machineIndex( -1 ), 98 isMuted( false ), 99 hasHeadset( true ), 100 hasHeadsetChanged( false ), 101 talking( false ), 102 talkingGlobal( false ), 103 talkingTime( 0 ) 104 {} 105 106 lobbyUser_t * user; 107 bool isLocal; 108 int lobbyType; 109 int groupIndex; 110 bool registered; // True if this user is currently registered with the XHV engine 111 bool registeredSuccess; // True if this user is currently successfully registered with the XHV engine 112 int machineIndex; // Index into remote machines array (-1 if this is a local talker) 113 bool isMuted; // This machine is not allowed to hear or talk to this player 114 bool hasHeadset; // This user has a headset connected 115 bool hasHeadsetChanged; // This user's headset state has changed 116 bool talking; 117 bool talkingGlobal; 118 int talkingTime; 119 120 bool IsLocal() const { return isLocal; } 121 }; 122 123 virtual bool RegisterTalkerInternal( int index ) = 0; 124 virtual void UnregisterTalkerInternal( int index ) = 0; 125 126 int FindTalkerIndex( const lobbyUser_t * user, int lobbyType ); 127 int FindMachine( const lobbyAddress_t & address, int lobbyType ); 128 int AddMachine( const lobbyAddress_t & address, int lobbyType ); 129 void RemoveMachine( int machineIndex, int lobbyType ); 130 void UpdateRegisteredTalkers(); 131 132 idStaticList< talker_t, MAX_PLAYERS * 2 > talkers; // * 2 to account for handling both session types 133 idStaticList< remoteMachine_t, MAX_PLAYERS * 2 > remoteMachines; // * 2 to account for handling both session types 134 135 int activeLobbyType; 136 int activeGroupIndex; 137 int sendFrame; 138 uint32 disableVoiceReasons; 139 bool sendGlobal; 140 }; 141 142 143 #endif // __SYS_VOICECHATMGR_H__