3 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
15 const float RangeNear = 0.4f;
18 private readonly ClientPeer netClient;
19 private DateTime lastSendTime;
20 private readonly List<VoipQueue> queues;
22 private UInt16 storedBufferID = 0;
24 private static Rectangle[] voiceIconSheetRects;
31 queues =
new List<VoipQueue>();
33 lastSendTime = DateTime.Now;
39 if (!queues.Contains(queue)) { queues.Add(queue); }
44 if (queues.Contains(queue)) { queues.Remove(queue); }
49 if (GameSettings.CurrentConfig.Audio.VoiceSetting ==
VoiceMode.Disabled)
66 DebugConsole.ThrowError($
"VoipCature.Create failed: {e.Message} {e.StackTrace.CleanupStackTrace()}");
67 var config = GameSettings.CurrentConfig;
68 config.Audio.VoiceSetting =
VoiceMode.Disabled;
69 GameSettings.SetCurrentConfig(config);
74 if (DateTime.Now >= lastSendTime + VoipConfig.SEND_INTERVAL)
82 netClient.Send(msg, DeliveryMethod.Unreliable);
84 lastSendTime = DateTime.Now;
92 VoipQueue queue = queues.Find(q => q.QueueID == queueId);
97 DebugConsole.NewMessage(
"Couldn't find VoipQueue with id " + queueId.ToString() +
"!", GUIStyle.Red);
102 Client client = gameClient.ConnectedClients.Find(c => c.VoipQueue == queue);
108 DebugConsole.Log(
"Recreating voipsound " + queueId);
117 float rangeMultiplier = spectating ? 2.0f : 1.0f;
132 client.
VoipSound.
SetRange(senderRadio.
Range * RangeNear * speechImpedimentMultiplier * rangeMultiplier, senderRadio.
Range * speechImpedimentMultiplier * rangeMultiplier);
133 if (distanceFactor > RangeNear && !spectating)
136 client.
RadioNoise = MathF.Pow(MathUtils.InverseLerp(RangeNear, 1.0f, distanceFactor), 2);
159 if (Vector3.DistanceSquared(clientPos, listenerPos) < attenuationDist * attenuationDist)
174 if (voiceIconSheetRects ==
null)
176 var soundIconStyle = GUIStyle.GetComponentStyle(
"GUISoundIcon");
177 Rectangle sourceRect = soundIconStyle.Sprites.First().Value.First().Sprite.SourceRect;
178 var indexPieces = soundIconStyle.Element.GetAttribute(
"sheetindices").Value.Split(
';');
179 voiceIconSheetRects =
new Rectangle[indexPieces.Length];
180 for (
int i = 0; i < indexPieces.Length; i++)
182 Point location = sourceRect.Location + XMLExtensions.ParsePoint(indexPieces[i].Trim()) * sourceRect.Size;
183 voiceIconSheetRects[i] =
new Rectangle(location, sourceRect.Size);
188 userdata.
Second = Math.Max(voipAmplitude, userdata.
Second - deltaTime);
190 if (userdata.
Second <= 0.0f)
197 int sheetIndex = (int)Math.Floor(userdata.
Second * voiceIconSheetRects.Length);
198 sheetIndex = MathHelper.Clamp(sheetIndex, 0, voiceIconSheetRects.Length - 1);
199 soundIcon.
SourceRect = voiceIconSheetRects[sheetIndex];
void ShowTextlessSpeechBubble(float duration, Color color)
static Character? Controlled
void SetClientSpeaking(Client client)
virtual Vector2 WorldPosition
ComponentState? OverrideState
static GameSession?? GameSession
static NetLobbyScreen NetLobbyScreen
static Sounds.SoundManager SoundManager
bool CanReceive(WifiComponent sender)
const float SpeakRangeVOIP
This is shorter than the text chat speak range, because the voice chat is still intelligible (just qu...
static Color[] MessageColor
static bool CanUseRadio(Character sender, bool ignoreJamming=false)
static void Create(string deviceName, UInt16? storedBufferID=null)
static VoipCapture Instance
void RegisterQueue(VoipQueue queue)
void Read(IReadMessage msg)
static void UpdateVoiceIndicator(GUIImage soundIcon, float voipAmplitude, float deltaTime)
VoipClient(GameClient gClient, ClientPeer nClient)
void UnregisterQueue(VoipQueue queue)
virtual bool Read(IReadMessage msg, bool discardData=false)
virtual void Write(IWriteMessage msg)
float GetCategoryGainMultiplier(string category, int index=-1)
void SetRange(float near, float far)
float??? CurrentAmplitude
Single ReadRangedSingle(Single min, Single max, int bitCount)
void SetPlayerSpeaking(Client client)