コード例 #1
0
ファイル: DateTimeSystem.cs プロジェクト: Orden4/WCSharp
        public DateTimeSystem(DateTimeSyncMethod method, Action <WcDateTime> action = null)
        {
            this.method = method;
            this.action = action;

            this.timestamps = new Dictionary <int, WcDateTime>();
        }
コード例 #2
0
ファイル: WcDateTime.cs プロジェクト: Orden4/WCSharp
 /// <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();
     }
 }
コード例 #3
0
ファイル: WcDateTime.cs プロジェクト: Orden4/WCSharp
 /// <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);
     }
 }
コード例 #4
0
ファイル: WcDateTime.cs プロジェクト: Orden4/WCSharp
        internal static void StoreSynchronisedTime(int seconds, DateTimeSyncMethod method)
        {
            if (!offsetByMethod.ContainsKey(method))
            {
                if (baseTime < 0)
                {
                    baseTime = seconds;
                    PeriodicEvents.AddPeriodicEvent(() =>
                    {
                        baseTime++;
                        return(true);
                    }, 1f);
                }

                offsetByMethod.Add(method, seconds - baseTime);
            }
        }