From 24affc78d85338233cf99c2f00576e74c9bbe53d Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 17 Jan 2017 16:23:48 +0000 Subject: [PATCH] Exposed update functions, so they can be called manually by the host (profiling etc) --- Facepunch.Steamworks/BaseSteamworks.cs | 8 +++++++ Facepunch.Steamworks/Client.cs | 11 ++++++++-- Facepunch.Steamworks/Client/Voice.cs | 5 ++++- Facepunch.Steamworks/Interfaces/Inventory.cs | 21 +++++++++++++++++-- Facepunch.Steamworks/Interfaces/Networking.cs | 5 ++++- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Facepunch.Steamworks/BaseSteamworks.cs b/Facepunch.Steamworks/BaseSteamworks.cs index 04160fa..435890c 100644 --- a/Facepunch.Steamworks/BaseSteamworks.cs +++ b/Facepunch.Steamworks/BaseSteamworks.cs @@ -89,6 +89,14 @@ namespace Facepunch.Steamworks Networking.Update(); + RunUpdateCallbacks(); + } + + /// + /// This gets called automatically in Update. Only call it manually if you know why you're doing it. + /// + public void RunUpdateCallbacks() + { if ( OnUpdate != null ) OnUpdate(); } diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 4b462a1..4f8531d 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -73,13 +73,20 @@ namespace Facepunch.Steamworks if ( !IsValid ) return; - native.api.SteamAPI_RunCallbacks(); - + RunCallbacks(); Voice.Update(); base.Update(); } + /// + /// This is called in Update() - there's no need to call it manually unless you're running your own Update + /// + public void RunCallbacks() + { + native.api.SteamAPI_RunCallbacks(); + } + /// /// Call when finished to shut down the Steam client. /// diff --git a/Facepunch.Steamworks/Client/Voice.cs b/Facepunch.Steamworks/Client/Voice.cs index 1c46850..c0ea64d 100644 --- a/Facepunch.Steamworks/Client/Voice.cs +++ b/Facepunch.Steamworks/Client/Voice.cs @@ -88,7 +88,10 @@ namespace Facepunch.Steamworks Marshal.FreeHGlobal( UncompressBuffer ); } - internal void Update() + /// + /// This gets called inside Update - so there's no need to call this manually if you're calling update + /// + public void Update() { if ( OnCompressedData == null && OnUncompressedData == null ) return; diff --git a/Facepunch.Steamworks/Interfaces/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs index ef643c3..d08fd30 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -36,6 +37,8 @@ namespace Facepunch.Steamworks internal SteamNative.SteamInventory inventory; + private Stopwatch fetchRetryTimer; + private bool IsServer { get; set; } internal Inventory( BaseSteamworks steamworks, SteamNative.SteamInventory c, bool server ) @@ -214,12 +217,26 @@ namespace Facepunch.Steamworks } /// - /// Called every frame + /// No need to call this manually if you're calling Update /// - internal void Update() + public void Update() { if ( Definitions == null ) { + // + // Don't try every frame, just try every 10 seconds. + // + { + if ( fetchRetryTimer != null && fetchRetryTimer.Elapsed.TotalSeconds < 10.0f ) + return; + + if ( fetchRetryTimer == null ) + fetchRetryTimer = Stopwatch.StartNew(); + + fetchRetryTimer.Reset(); + fetchRetryTimer.Start(); + } + FetchItemDefinitions(); inventory.LoadItemDefinitions(); } diff --git a/Facepunch.Steamworks/Interfaces/Networking.cs b/Facepunch.Steamworks/Interfaces/Networking.cs index 15c29fd..f29b40b 100644 --- a/Facepunch.Steamworks/Interfaces/Networking.cs +++ b/Facepunch.Steamworks/Interfaces/Networking.cs @@ -38,7 +38,10 @@ namespace Facepunch.Steamworks } - internal void Update() + /// + /// No need to call this manually if you're calling Update() + /// + public void Update() { if ( OnP2PData == null ) return;