From 947fc190d2f3b7c5da7534534325dd68fd4f4ed9 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 3 Nov 2016 10:57:52 +0000 Subject: [PATCH] Added UpdateWhile --- Facepunch.Steamworks.Test/Server/Stats.cs | 7 ++----- .../bin/Debug/Facepunch.Steamworks.xml | 7 +++++++ Facepunch.Steamworks/BaseSteamworks.cs | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Facepunch.Steamworks.Test/Server/Stats.cs b/Facepunch.Steamworks.Test/Server/Stats.cs index df50056..8847a40 100644 --- a/Facepunch.Steamworks.Test/Server/Stats.cs +++ b/Facepunch.Steamworks.Test/Server/Stats.cs @@ -29,11 +29,8 @@ public void StatsGet() Assert.IsTrue( deathsInCallback > 0 ); } ); - while ( !GotStats ) - { - server.Update(); - Thread.Sleep( 10 ); - } + + server.UpdateWhile( () => !GotStats ); var deaths = server.Stats.GetInt( MySteamId, "deaths", -1 ); Console.WriteLine( "deathsInCallback: {0}", deaths ); diff --git a/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml b/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml index 8bb7daa..683812b 100644 --- a/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml +++ b/Facepunch.Steamworks.Test/bin/Debug/Facepunch.Steamworks.xml @@ -14,6 +14,13 @@ Called with a message from Steam + + + Run Update until func returns false. + This will cause your program to lock up until it finishes. + This is useful for things like tests or command line utilities etc. + + An item in your inventory. diff --git a/Facepunch.Steamworks/BaseSteamworks.cs b/Facepunch.Steamworks/BaseSteamworks.cs index 55dd17e..6e5cacf 100644 --- a/Facepunch.Steamworks/BaseSteamworks.cs +++ b/Facepunch.Steamworks/BaseSteamworks.cs @@ -94,5 +94,19 @@ public virtual void Update() if ( OnUpdate != null ) OnUpdate(); } + + /// + /// Run Update until func returns false. + /// This will cause your program to lock up until it finishes. + /// This is useful for things like tests or command line utilities etc. + /// + public void UpdateWhile( Func func ) + { + while ( func() ) + { + Update(); + System.Threading.Thread.Sleep( 1 ); + } + } } } \ No newline at end of file