mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-16 06:12:28 +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 Inventory Inventory { get; internal set; }
|
||||||
public Workshop Workshop { get; internal set; }
|
public Workshop Workshop { get; internal set; }
|
||||||
|
|
||||||
internal Action OnUpdate;
|
internal event Action OnUpdate;
|
||||||
|
|
||||||
internal Interop.NativeInterface native;
|
internal Interop.NativeInterface native;
|
||||||
|
|
||||||
@ -86,6 +86,7 @@ namespace Facepunch.Steamworks
|
|||||||
public virtual void Update()
|
public virtual void Update()
|
||||||
{
|
{
|
||||||
Inventory.Update();
|
Inventory.Update();
|
||||||
|
|
||||||
Networking.Update();
|
Networking.Update();
|
||||||
|
|
||||||
if ( OnUpdate != null )
|
if ( OnUpdate != null )
|
||||||
|
@ -74,6 +74,7 @@ namespace Facepunch.Steamworks
|
|||||||
native.api.SteamAPI_RunCallbacks();
|
native.api.SteamAPI_RunCallbacks();
|
||||||
|
|
||||||
Voice.Update();
|
Voice.Update();
|
||||||
|
|
||||||
base.Update();
|
base.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ namespace Facepunch.Steamworks
|
|||||||
public Action<IntPtr, int> OnCompressedData;
|
public Action<IntPtr, int> OnCompressedData;
|
||||||
public Action<IntPtr, int> OnUncompressedData;
|
public Action<IntPtr, int> OnUncompressedData;
|
||||||
|
|
||||||
|
private System.Diagnostics.Stopwatch UpdateTimer = System.Diagnostics.Stopwatch.StartNew();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the optimal sample rate for voice - according to Steam
|
/// Returns the optimal sample rate for voice - according to Steam
|
||||||
@ -92,6 +93,11 @@ namespace Facepunch.Steamworks
|
|||||||
if ( OnCompressedData == null && OnUncompressedData == null )
|
if ( OnCompressedData == null && OnUncompressedData == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ( UpdateTimer.Elapsed.TotalSeconds < 1.0f / 10.0f )
|
||||||
|
return;
|
||||||
|
|
||||||
|
UpdateTimer.Reset();
|
||||||
|
UpdateTimer.Start();
|
||||||
|
|
||||||
uint bufferRegularLastWrite = 0;
|
uint bufferRegularLastWrite = 0;
|
||||||
uint bufferCompressedLastWrite = 0;
|
uint bufferCompressedLastWrite = 0;
|
||||||
|
@ -15,6 +15,7 @@ namespace Facepunch.Steamworks
|
|||||||
private List<int> ListenChannels = new List<int>();
|
private List<int> ListenChannels = new List<int>();
|
||||||
|
|
||||||
private MemoryStream ReceiveBuffer = new MemoryStream();
|
private MemoryStream ReceiveBuffer = new MemoryStream();
|
||||||
|
private System.Diagnostics.Stopwatch UpdateTimer = System.Diagnostics.Stopwatch.StartNew();
|
||||||
|
|
||||||
internal SteamNative.SteamNetworking networking;
|
internal SteamNative.SteamNetworking networking;
|
||||||
|
|
||||||
@ -42,6 +43,13 @@ namespace Facepunch.Steamworks
|
|||||||
if ( OnP2PData == null )
|
if ( OnP2PData == null )
|
||||||
return;
|
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 )
|
foreach ( var channel in ListenChannels )
|
||||||
{
|
{
|
||||||
while ( ReadP2PPacket( channel ) )
|
while ( ReadP2PPacket( channel ) )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user