Throttle Network + Voice updates

This commit is contained in:
Garry Newman 2016-11-03 15:26:56 +00:00
parent 8bf391a300
commit f838cf6b98
4 changed files with 18 additions and 2 deletions

View File

@ -20,7 +20,7 @@ public class BaseSteamworks : IDisposable
public Inventory Inventory { get; internal set; }
public Workshop Workshop { get; internal set; }
internal Action OnUpdate;
internal event Action OnUpdate;
internal Interop.NativeInterface native;
@ -86,6 +86,7 @@ internal void RegisterCallbackHandle( SteamNative.CallbackHandle handle )
public virtual void Update()
{
Inventory.Update();
Networking.Update();
if ( OnUpdate != null )

View File

@ -74,7 +74,8 @@ public override void Update()
native.api.SteamAPI_RunCallbacks();
Voice.Update();
base.Update();
base.Update();
}
/// <summary>

View File

@ -22,6 +22,7 @@ public class Voice : IDisposable
public Action<IntPtr, int> OnCompressedData;
public Action<IntPtr, int> OnUncompressedData;
private System.Diagnostics.Stopwatch UpdateTimer = System.Diagnostics.Stopwatch.StartNew();
/// <summary>
/// Returns the optimal sample rate for voice - according to Steam
@ -92,6 +93,11 @@ internal void Update()
if ( OnCompressedData == null && OnUncompressedData == null )
return;
if ( UpdateTimer.Elapsed.TotalSeconds < 1.0f / 10.0f )
return;
UpdateTimer.Reset();
UpdateTimer.Start();
uint bufferRegularLastWrite = 0;
uint bufferCompressedLastWrite = 0;

View File

@ -15,6 +15,7 @@ public class Networking : IDisposable
private List<int> ListenChannels = new List<int>();
private MemoryStream ReceiveBuffer = new MemoryStream();
private System.Diagnostics.Stopwatch UpdateTimer = System.Diagnostics.Stopwatch.StartNew();
internal SteamNative.SteamNetworking networking;
@ -42,6 +43,13 @@ internal void Update()
if ( OnP2PData == null )
return;
// Update every 60th of a second
if ( UpdateTimer.Elapsed.TotalSeconds < 1.0 / 60.0 )
return;
UpdateTimer.Reset();
UpdateTimer.Start();
foreach ( var channel in ListenChannels )
{
while ( ReadP2PPacket( channel ) )