mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 06:38:01 +03:00
Throttle Network + Voice updates
This commit is contained in:
parent
8bf391a300
commit
f838cf6b98
@ -20,7 +20,7 @@ namespace Facepunch.Steamworks
|
||||
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 @@ namespace Facepunch.Steamworks
|
||||
public virtual void Update()
|
||||
{
|
||||
Inventory.Update();
|
||||
|
||||
Networking.Update();
|
||||
|
||||
if ( OnUpdate != null )
|
||||
|
@ -74,7 +74,8 @@ namespace Facepunch.Steamworks
|
||||
native.api.SteamAPI_RunCallbacks();
|
||||
|
||||
Voice.Update();
|
||||
base.Update();
|
||||
|
||||
base.Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -22,6 +22,7 @@ namespace Facepunch.Steamworks
|
||||
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 @@ namespace Facepunch.Steamworks
|
||||
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;
|
||||
|
@ -15,6 +15,7 @@ namespace Facepunch.Steamworks
|
||||
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 @@ namespace Facepunch.Steamworks
|
||||
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 ) )
|
||||
|
Loading…
x
Reference in New Issue
Block a user