コード例 #1
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
        /// <summary>
        /// Sets a timer to call the given native function at a set interval. If a timer is already set
        /// for this delegate, it will update the current timer to the new parameters and reset its
        /// elapsed time to 0.
        /// </summary>
        /// <param name="obj">Object to call the timer function on.</param>
        /// <param name="function">Method to call when timer fires (must be a UFunction method).</param>
        /// <param name="time">The amount of time between set and firing. If &lt;= 0.f, clears existing timers.</param>
        /// <param name="looping">true to keep firing at Rate intervals, false to fire only once.</param>
        /// <param name="firstDelay">The time for the first iteration of a looping timer. If &lt; 0.f inRate will be used.</param>
        /// <returns>The handle for the timer.</returns>
        public FTimerHandle SetTimer(UObject obj, FSimpleDelegate function, float time, bool looping = false, float firstDelay = -1.0f)
        {
            FTimerHandle handle = default(FTimerHandle);

            SetTimer(ref handle, obj, GetFunctionName(obj, function), time, looping, firstDelay);
            return(handle);
        }
コード例 #2
0
ファイル: EntryPoint.Shared.cs プロジェクト: iainmckay/USharp
        public static void Init(IntPtr addTickerAddr, IntPtr isInGameThreadAddr, FSimpleDelegate onRuntimeChanged)
        {
            isInGameThread = (Del_IsInGameThread)Marshal.GetDelegateForFunctionPointer(isInGameThreadAddr, typeof(Del_IsInGameThread));

            Debug.Assert(IsInGameThread(), "USharp should only be loaded from the game thread");
            addStaticTicker = (Del_AddStaticTicker)Marshal.GetDelegateForFunctionPointer(addTickerAddr, typeof(Del_AddStaticTicker));
            ticker          = Tick;
            addStaticTicker(ticker, 0.0f);

            OnRuntimeChanged = onRuntimeChanged;
        }
コード例 #3
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
        private static void Run(FSimpleDelegate func, EAsyncThreadType threadType, bool waitForComplete)
        {
            switch (threadType)
            {
            case EAsyncThreadType.GameThreadUnloadIgnore:
            case EAsyncThreadType.GameThread:
                if (IsInGameThread())
                {
                    func();
                    return;
                }
                break;

            case EAsyncThreadType.RHIThread:
                if (IsInRHIThread())
                {
                    func();
                    return;
                }
                break;

            case EAsyncThreadType.RenderingThread:
                if (IsInRenderingThread())
                {
                    func();
                    return;
                }
                break;
            }

            if (HotReload.IsUnloading)
            {
                return;
            }

            AsyncCallback callback = new AsyncCallback(func, threadType);

            lock (callbacks)
            {
                callbacks.Add(callback);
            }
            Native_FAsync.AsyncTask(callback.Run, threadType);
            if (waitForComplete)
            {
                callback.WaitForComplete();
            }
            else
            {
                callback.Dispose();
            }
        }
コード例 #4
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
        private static FName GetFunctionName(UObject obj, FSimpleDelegate function)
        {
            Delegate del = function as Delegate;

            if (del != null)
            {
                UObject target = del.Target as UObject;
                if (target != null)// Also check against obj?
                {
                    IntPtr functionAddress = NativeReflection.LookupTable.FindFunction(target, del.Method);
                    FName  name;
                    Native_UObjectBase.GetFName(functionAddress, out name);
                    return(name);
                }
            }
            return(FName.None);
        }
コード例 #5
0
 public static void Run(FSimpleDelegate callback)
 {
     if (IsInGameThread())
     {
         callback();
     }
     else
     {
         using (AutoResetEvent waitHandle = new AutoResetEvent(false))
         {
             asyncTask(delegate
             {
                 callback();
                 waitHandle.Set();
             }, 0);
             waitHandle.WaitOne(Timeout.Infinite);
         }
     }
 }
コード例 #6
0
ファイル: EntryPoint.Shared.cs プロジェクト: iainmckay/USharp
 public static void Run(FSimpleDelegate callback)
 {
     if (IsInGameThread())
     {
         callback();
     }
     else
     {
         CallbackInfo callbackInfo = new CallbackInfo()
         {
             Callback   = callback,
             WaitHandle = new AutoResetEvent(false)
         };
         lock (callbacks)
         {
             callbacks.Enqueue(callbackInfo);
         }
         callbackInfo.WaitHandle.WaitOne(Timeout.Infinite);
         callbackInfo.WaitHandle.Close();
     }
 }
コード例 #7
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
 /// <summary>
 /// Runs a function on the game thread synchronously
 /// </summary>
 public static void RunOnGameThread(FSimpleDelegate func)
 {
     Run(func, EAsyncThreadType.GameThread, true);
 }
コード例 #8
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
 public AsyncCallback(FSimpleDelegate callback, EAsyncThreadType threadType)
 {
     this.callback = callback;
     ThreadType    = threadType;
 }
コード例 #9
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
 internal static void RunUnloader(FSimpleDelegate func)
 {
     Run(func, EAsyncThreadType.GameThreadUnloadIgnore, true);
 }
コード例 #10
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
 /// <summary>
 /// Runs a function on any thread asynchronously (no real reason to use this - just use regular C# threading)
 /// </summary>
 internal static void RunOnAnyThreadAsync(FSimpleDelegate func)
 {
     Run(func, EAsyncThreadType.AnyThread, false);
 }
コード例 #11
0
ファイル: FThreading.cs プロジェクト: zwywilliam/USharp
 /// <summary>
 /// Runs a function on the rendering thread asynchronously
 /// </summary>
 public static void RunOnRenderingThreadAsync(FSimpleDelegate func)
 {
     Run(func, EAsyncThreadType.RenderingThread, false);
 }
コード例 #12
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
 public FTimerHandle FindTimerHandle(UObject obj, FSimpleDelegate function)
 {
     return(FindTimerHandle(obj, GetFunctionName(obj, function)));
 }
コード例 #13
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
 /// <summary>
 /// Sets a timer to call the given native function on the next tick
 /// (this could be called RunFunctionOnNextTick as it isn't really timer related (aside from being done by FTimerManager)).
 /// </summary>
 /// <param name="obj">Object to call the timer function on.</param>
 /// <param name="function">Method to call when timer fires.</param>
 public void SetTimerForNextTick(UObject obj, FSimpleDelegate function)
 {
     SetTimerForNextTick(obj, GetFunctionName(obj, function));
 }
コード例 #14
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
 /// <summary>
 /// Sets a timer to call the given native function at a set interval. If a timer is already set
 /// for this delegate, it will update the current timer to the new parameters and reset its
 /// elapsed time to 0.
 /// </summary>
 /// <param name="inOutHandle">Handle to identify this timer. If it is invalid when passed in it will be made into a valid handle.</param>
 /// <param name="obj">Object to call the timer function on.</param>
 /// <param name="function">Method to call when timer fires (must be a UFunction method).</param>
 /// <param name="time">The amount of time between set and firing. If &lt;= 0.f, clears existing timers.</param>
 /// <param name="looping">true to keep firing at Rate intervals, false to fire only once.</param>
 /// <param name="firstDelay">The time for the first iteration of a looping timer. If &lt; 0.f inRate will be used.</param>
 public void SetTimer(ref FTimerHandle inOutHandle, UObject obj, FSimpleDelegate function, float time, bool looping = false, float firstDelay = -1.0f)
 {
     SetTimer(ref inOutHandle, obj, GetFunctionName(obj, function), time, looping, firstDelay);
 }