Skip to content

Commit

Permalink
Remove maxDataPerFrame from inspector, because its unnecessary clutter
Browse files Browse the repository at this point in the history
  • Loading branch information
lexonegit committed Jan 23, 2023
1 parent 3b49a59 commit 5518a33
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Unity-Twitch-Chat/Assets/Package/Runtime/IRC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ public partial class IRC : MonoBehaviour
[Tooltip("If true, the thread start and stop will be logged to the console.")]
[SerializeField] public bool showThreadDebug = true;

[Tooltip("Limit how many data messages can be handled per frame.\n0 = unlimited.\n\nNote that setting this value to unlimited may cause lag spikes, particularly when the game is paused and then resumed, as there may be a large number of messages waiting to be processed.")]
[SerializeField] private int maxDataPerFrame = 30;

[Tooltip("If true, chatters who haven't set their name color will be assigned a random color, instead of white.")]
[SerializeField] public bool useBackupRandomNameColor = false;
[Tooltip("If true, chatters who haven't set their name color on Twitch will be assigned a random color, instead of white.")]
[SerializeField] public bool useRandomColorForUndefined = false;

[Header("Chat read settings (read thread)")]

Expand All @@ -59,6 +56,11 @@ public partial class IRC : MonoBehaviour
[Tooltip("The number of milliseconds between each time the write thread checks its queues.")]
public int writeInterval = 50;


// If the game is paused for a significant amount of time and then unpaused,
// there could be a lot of data to handle, which could cause lag spikes.
// To prevent this, we limit the amount of data handled per frame.
private static readonly int maxDataPerFrame = 100;
private int connectionFailCount = 0;
private TwitchConnection connection;
public static IRC Instance { get; private set; }
Expand Down Expand Up @@ -132,7 +134,7 @@ private void HandlePendingInformation()
// Handle pending connection alerts
while (!alertQueue.IsEmpty)
{
if (maxDataPerFrame > 0 && dataHandledThisFrame >= maxDataPerFrame)
if (dataHandledThisFrame >= maxDataPerFrame)
break;

if (alertQueue.TryDequeue(out var alert))
Expand All @@ -145,7 +147,7 @@ private void HandlePendingInformation()
// Handle pending chat messages
while (!chatterQueue.IsEmpty)
{
if (maxDataPerFrame > 0 && dataHandledThisFrame >= maxDataPerFrame)
if (dataHandledThisFrame >= maxDataPerFrame)
break;

if (chatterQueue.TryDequeue(out var chatter))
Expand Down Expand Up @@ -291,6 +293,7 @@ public void SendChatMessage(string message)
Debug.LogWarning("Chat messages cannot be sent with anonymous login");
return;
}

connection.SendChatMessage(message);
}
}
Expand Down

0 comments on commit 5518a33

Please sign in to comment.