Beispiel #1
0
 /// <summary>
 /// This will produce a synchronised time for all players. The given action will be called once a synchronised time has been determined.
 /// <para>This is done by individually querying the time, synchronizing this data across all players, and then deciding an overall time.</para>
 /// </summary>
 /// <param name="action">This action will be called when the synchronised time is determined.</param>
 /// <param name="method">The method it should use for determining the synchronised time.</param>
 public static void GetCurrentTime(Action <WcDateTime> action, DateTimeSyncMethod method = DateTimeSyncMethod.BestFit)
 {
     if (offsetByMethod.TryGetValue(method, out var offset))
     {
         action?.Invoke(new WcDateTime(baseTime + offset));
     }
     else
     {
         var system = new DateTimeSystem(method, action);
         system.Run();
     }
 }
Beispiel #2
0
 /// <summary>
 /// This will attempt to immediately return a synchronised time for all players, if it has already been calculated.
 /// If it has not been calculated, this will return false.
 /// <para>If it has not been calculated, will start a calculation procedure behind the scenes, but this will take some time.</para>
 /// </summary>
 /// <param name="wcDateTime">The synchronised time, if available.</param>
 /// <param name="method">The method it should use for determining the synchronised time.</param>
 /// <returns>Whether the retrieval was successful.</returns>
 public static bool TryGetCurrentTime(out WcDateTime wcDateTime, DateTimeSyncMethod method = DateTimeSyncMethod.BestFit)
 {
     if (offsetByMethod.TryGetValue(method, out var offset))
     {
         wcDateTime = new WcDateTime(baseTime + offset);
         return(true);
     }
     else
     {
         wcDateTime = null;
         var system = new DateTimeSystem(method);
         system.Run();
         return(false);
     }
 }