当前位置: 首页>>代码示例>>C#>>正文


C# OnVoidDelegate类代码示例

本文整理汇总了C#中OnVoidDelegate的典型用法代码示例。如果您正苦于以下问题:C# OnVoidDelegate类的具体用法?C# OnVoidDelegate怎么用?C# OnVoidDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OnVoidDelegate类属于命名空间,在下文中一共展示了OnVoidDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForceCallThreadSafeCallbacks

	/** Forces thread safe callbacks to be called.
	 * This method should only be called from inside another thread safe callback to for example instantly run some graph updates.
	 * \throws System.InvalidOperationException if any threads are detected to be active and running
	 */
	public static void ForceCallThreadSafeCallbacks () {
		if (!threadSafeUpdateState) {
			throw new System.InvalidOperationException ("You should only call this function from a thread safe callback. That does not seem to be the case for this call.");
		}
		
		if (OnThreadSafeCallback != null) {
			OnVoidDelegate tmp = OnThreadSafeCallback;
			OnThreadSafeCallback = null;
			tmp ();
		}
	}
开发者ID:GJL91,项目名称:Epidemic,代码行数:15,代码来源:AstarPath.cs

示例2: DoUpdateGraphs

	/** Updates the graphs based on the #graphUpdateQueue
	 * \see UpdateGraphs
	 */
	private void DoUpdateGraphs () {
		isRegisteredForUpdate = false;
		isUpdatingGraphs = true;
		lastGraphUpdate = Time.time;
		
		if (OnGraphsWillBeUpdated2 != null) {
			OnVoidDelegate callbacks = OnGraphsWillBeUpdated2;
			OnGraphsWillBeUpdated2 = null;
			callbacks ();
		}
		
		if (OnGraphsWillBeUpdated != null) {
			OnVoidDelegate callbacks = OnGraphsWillBeUpdated;
			OnGraphsWillBeUpdated = null;
			callbacks ();
		}
		GraphModifier.TriggerEvent (GraphModifier.EventType.PreUpdate);
		
		//If any GUOs requires a flood fill, then issue it, otherwise we can skip it to save processing power
		bool anyRequiresFloodFill = false;
		
		if (graphUpdateQueue != null) {
			while (graphUpdateQueue.Count > 0) {
				GraphUpdateObject ob = graphUpdateQueue.Dequeue ();
				
				if (ob.requiresFloodFill) anyRequiresFloodFill = true;
				
				foreach (IUpdatableGraph g in astarData.GetUpdateableGraphs ()) {
					NavGraph gr = g as NavGraph;
					if (ob.nnConstraint == null || ob.nnConstraint.SuitableGraph (active.astarData.GetGraphIndex (gr),gr)) {
						
						g.UpdateArea (ob);
					}
				}
				
			}
		}
		
		isUpdatingGraphs = false;
		
		//If any GUOs required flood filling and if we are not scanning graphs at the moment (in that case a FloodFill will be done later)
		if (anyRequiresFloodFill && !isScanning) {
			FloodFill ();
		}
		
		//this callback should not be called if scanning
		//Notify scripts that the graph has been updated
		if (OnGraphsUpdated != null && !isScanning) {
			OnGraphsUpdated (this);
		}
		GraphModifier.TriggerEvent (GraphModifier.EventType.PostUpdate);
	}
开发者ID:GJL91,项目名称:Epidemic,代码行数:55,代码来源:AstarPath.cs

示例3: CalculatePaths

	/** Main pathfinding function. This function will calculate the paths in the pathfinding queue
	 * \see CalculatePaths
	 */
	private static IEnumerator CalculatePaths (System.Object _threadInfo) {
		
		
		//Increment the counter for how many threads are calculating
		System.Threading.Interlocked.Increment (ref numActiveThreads);
		
		PathThreadInfo threadInfo;
		try {
			threadInfo = (PathThreadInfo)_threadInfo;
		} catch (System.Exception e) {
			Debug.LogError ("Arguments to pathfinding threads must be of type ThreadStartInfo\n"+e);
			throw new System.ArgumentException ("Argument must be of type ThreadStartInfo",e);
		}
		
		int numPaths = 0;
		
		//Initialize memory for this thread
		NodeRunData runData = threadInfo.runData;
		
		
		//Max number of ticks before yielding/sleeping
		long maxTicks = (long)(active.maxFrameTime*10000);
		long targetTick = System.DateTime.UtcNow.Ticks + maxTicks;
		
		threadSafeUpdateState = true;
		
		while (true) {
			
			//The path we are currently calculating
			Path p = null;
			
			AstarProfiler.StartProfile ("Path Queue");
			
			//Try to get the next path to be calculated
			while (true) {
				//Cancel function (and thus the thread) if no more paths should be accepted.
				//This is done when the A* object is about to be destroyed
				if (!active.acceptNewPaths) {
					System.Threading.Interlocked.Decrement (ref numActiveThreads);
					yield break;
				}
				
				if (pathQueue.Count > 0) {
					p = pathQueue.Dequeue ();
				}
				
				//System.Threading.Interlocked.Increment(ref threadsIdle);
				
				//Last thread alive
				//Call callbacks if any are requested
				OnVoidDelegate tmp = OnSafeCallback;
				OnSafeCallback = null;
				if (tmp != null) tmp();
				
				TryCallThreadSafeCallbacks ();
				//The threadSafeUpdateState is still enabled since this is coroutine mode
				//It would be reset in TryCallThreadSafeCallbacks
				threadSafeUpdateState = true;
				
				if (p == null) {
					AstarProfiler.EndProfile ();
					yield return 0;
					AstarProfiler.StartProfile ("Path Queue");
				}
				
				//If we have a path, start calculating it
				if (p != null) break;
			}
			
			AstarProfiler.EndProfile ();
			
			AstarProfiler.StartProfile ("Path Calc");
			
			//Max number of ticks we are allowed to continue working in one run
			//One tick is 1/10000 of a millisecond
			maxTicks = (long)(active.maxFrameTime*10000);
			
			threadSafeUpdateState = false;
			
			p.PrepareBase (runData);
			
			//Now processing the path
			//Will advance to Processing
			p.AdvanceState (PathState.Processing);
			
			//Call some callbacks
			if (OnPathPreSearch != null) {
				OnPathPreSearch (p);
			}
			
			numPaths++;
			
			//Tick for when the path started, used for calculating how long time the calculation took
			long startTicks = System.DateTime.UtcNow.Ticks;
			long totalTicks = 0;
			
			AstarProfiler.StartFastProfile(8);
//.........这里部分代码省略.........
开发者ID:GJL91,项目名称:Epidemic,代码行数:101,代码来源:AstarPath.cs

示例4: TryCallThreadSafeCallbacks

	/* Checks if the OnThreadSafeCallback callback needs to be (and can) be called and if so, does it.
	 * Unpauses pathfinding threads after that.
	 * Thread safe callbacks can only be called when no pathfinding threads are running at the momment.
	 * Should only be called from the main unity thread.
	 * \see FlushThreadSafeCallbacks
	 * \see Update
	 */
	private static void TryCallThreadSafeCallbacks () {
		if (threadSafeUpdateState) {
			if (OnThreadSafeCallback != null) {
				OnVoidDelegate tmp = OnThreadSafeCallback;
				OnThreadSafeCallback = null;
				tmp ();
			}
			threadSafeUpdateFlag.Set();
			threadSafeUpdateState = false;
		}
	}
开发者ID:GJL91,项目名称:Epidemic,代码行数:18,代码来源:AstarPath.cs

示例5: AstarWorkItem

		public AstarWorkItem (OnVoidDelegate init, System.Func<bool, bool> update) {
			this.init = init;
			this.update = update;
		}
开发者ID:JackHR,项目名称:WaveIncoming,代码行数:4,代码来源:AstarPath.cs

示例6: RegisterSafeNodeUpdate

	/** Will send a callback when it is safe to update nodes. This is defined as between the path searches.
	  * This callback will only be sent once and is nulled directly after the callback has been sent
	  * \warning Note that these callbacks are not thread safe when using multithreading, DO NOT call any part of the Unity API from these callbacks except for Debug.Log
	  * \see RegisterThreadSafeNodeUpdate
	  */
	public static void RegisterSafeNodeUpdate (OnVoidDelegate callback) {
		if (callback == null) {
			return;
		}
		
		if (isCalculatingPaths) {
			OnSafeNodeUpdate += callback;
		} else {
			callback ();
		}
	}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:16,代码来源:AstarPath.cs

示例7: RegisterSafeUpdate

	public static void RegisterSafeUpdate (OnVoidDelegate callback, bool threadSafe) {
		RegisterSafeUpdate ( callback );
	}
开发者ID:vekkna,项目名称:Wolf-Pack-Alpha-2,代码行数:3,代码来源:AstarPath.cs

示例8: GetNextPathID

	/** Returns the next free path ID. If the next free path ID overflows 65535, a cleanup operation is queued
	  * \see Pathfinding.CleanupPath65K */
	public ushort GetNextPathID ()
	{
		if (nextFreePathID == 0) {
			nextFreePathID++;
			
			//Queue a cleanup operation to zero all path IDs
			//StartPath (new CleanupPath65K ());
			Debug.Log ("65K cleanup");
			
			//ushort toBeReturned = nextFreePathID;
			
			if (On65KOverflow != null) {
				OnVoidDelegate tmp = On65KOverflow;
				On65KOverflow = null;
				tmp ();
			}
			
			//return nextFreePathID++;
		}
		return nextFreePathID++;
	}
开发者ID:JackHR,项目名称:WaveIncoming,代码行数:23,代码来源:AstarPath.cs

示例9: DoUpdateGraphs

	/** Updates the graphs based on the #graphUpdateQueue
	 * \see UpdateGraphs
	 */
	private void DoUpdateGraphs () {
		
		isUpdatingGraphs = true;
		lastGraphUpdate = Time.realtimeSinceStartup;
		
		if (OnGraphsWillBeUpdated2 != null) {
			OnVoidDelegate callbacks = OnGraphsWillBeUpdated2;
			OnGraphsWillBeUpdated2 = null;
			callbacks ();
		}
		
		if (OnGraphsWillBeUpdated != null) {
			OnVoidDelegate callbacks = OnGraphsWillBeUpdated;
			OnGraphsWillBeUpdated = null;
			callbacks ();
		}
		
		//If any GUOs requires a flood fill, then issue it, otherwise we can skip it to save processing power
		bool anyRequiresFloodFill = false;
		
		if (graphUpdateQueue != null) {
			while (graphUpdateQueue.Count > 0) {
				GraphUpdateObject ob = graphUpdateQueue.Dequeue ();
				
				if (ob.requiresFloodFill) anyRequiresFloodFill = true;
				
				foreach (IUpdatableGraph g in astarData.GetUpdateableGraphs ()) {
						
						g.UpdateArea (ob);
				}
				
			}
		}
		isUpdatingGraphs = false;
		
		if (anyRequiresFloodFill) {
			FloodFill ();
		}
		
		if (OnGraphsUpdated != null) {
			OnGraphsUpdated (this);
		}
		
		//Debug.Log ("Updating Graphs... "+((Time.realtimeSinceStartup-startUpdate)*1000).ToString ("0.00"));
		//resetEvent.Set ();
		//resetFlag = true;
	}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:50,代码来源:AstarPath.cs

示例10: RegisterCanUpdateGraphs

	public void RegisterCanUpdateGraphs (OnVoidDelegate callback, OnVoidDelegate callback2 = null) {
		
		OnGraphsWillBeUpdated += callback;
		
		if (callback2 != null) {
			OnGraphsWillBeUpdated2 += callback2;
		}
		
		if (limitGraphUpdates && Time.realtimeSinceStartup-lastGraphUpdate < maxGraphUpdateFreq) {
			if (!graphUpdateRoutineRunning) {
				StartCoroutine (DelayedGraphUpdate ());
			}
		} else {
			if (useMultithreading) {
				lock (lockObject) {
					DoUpdateGraphs ();
				}
			} else if (!isRegisteredForUpdate) {
				//Only add a callback for the first item
				isRegisteredForUpdate = true;
				OnGraphUpdate += DoUpdateGraphs;
			}
		}
	}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:24,代码来源:AstarPath.cs

示例11: GetNextPathID

	/** Returns the next free path ID. If the next free path ID overflows 65535, a cleanup operation is queued
	  * \see Pathfinding::CleanupPath65K */
	public int GetNextPathID () {
		if (nextFreePathID > 65535) {
			nextFreePathID = 1;
			
			//Queue a cleanup operation to zero all path IDs
			StartPath (new CleanupPath65K ());
			
			int toBeReturned = nextFreePathID++;
			
			if (On65KOverflow != null) {
				OnVoidDelegate tmp = On65KOverflow;
				On65KOverflow = null;
				tmp ();
			}
			
			return toBeReturned;
		}
		return nextFreePathID++;
	}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:21,代码来源:AstarPath.cs

示例12: RegisterThreadSafeNodeUpdate

	/** Will send a callback when it is safe to update nodes. This is defined as between the path searches.
	  * This callback will only be sent once and is nulled directly after the callback has been sent. This callback is also threadsafe, and because of that, using it often might affect performance when called often and multithreading is enabled due to locking and synchronisation.
	  * \see RegisterSafeNodeUpdate
	  */
	public static void RegisterThreadSafeNodeUpdate (OnVoidDelegate callback) {
		if (callback == null) {
			return;
		}
		
		if (isCalculatingPaths) {
			if (active.useMultithreading) {
				lock (lockObject) {
					callback ();
				}
			} else {
				OnSafeNodeUpdate += callback;
			}
		} else {
			callback ();
		}
	}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:21,代码来源:AstarPath.cs

示例13: RegisterSafeUpdate

	/** Will send a callback when it is safe to update nodes. This is defined as between the path searches.
	  * This callback will only be sent once and is nulled directly after the callback has been sent.
	  * When using more threads than one, calling this often might decrease pathfinding performance due to a lot of idling in the threads.
	  * Not performance as in it will use much CPU power,
	  * but performance as in the number of paths per second will probably go down (though your framerate might actually increase a tiny bit)
	  * 
	  * You should only call this function from the main unity thread (i.e normal game code).
	  * 
	  * \warning Note that if you do not set \a threadSafe to true, the callback might not be called from the Unity thread,
	  * DO NOT call any part of the Unity API from those callbacks except for Debug.Log
	  * 
	  * \code
Node node = AstarPath.active.GetNearest (transform.position).node;
AstarPath.RegisterSafeUpdate (delegate () {
	node.walkable = false;
}, false);
\endcode

\code
Node node = AstarPath.active.GetNearest (transform.position).node;
AstarPath.RegisterSafeUpdate (delegate () {
	node.position = (Int3)transform.position;
}, true);
\endcode
	  * Note that the second example uses transform in the callback, and must thus be threadSafe.
	  */
	public static void RegisterSafeUpdate (OnVoidDelegate callback, bool threadSafe) {
		if (callback == null || !Application.isPlaying) {
			return;
		}
		
		if (active.pathQueue.AllReceiversBlocked) {
			// We need to lock here since we cannot be sure that this is the Unity Thread
			// and therefore we cannot be sure that some other thread will not unblock the queue while we are processing the callback
			active.pathQueue.Lock();
			try {
				//Check again
				if (active.pathQueue.AllReceiversBlocked) {
					callback ();
					return;
				}
			} finally {
				active.pathQueue.Unlock();
			}
		}
		
		lock (safeUpdateLock) {			
			if (threadSafe)
				OnThreadSafeCallback += callback;
			else
				OnSafeCallback += callback;
		}
		//Block path queue so that the above callbacks may be called
		active.pathQueue.Block();
		
	}
开发者ID:JackHR,项目名称:WaveIncoming,代码行数:56,代码来源:AstarPath.cs

示例14: RegisterSafeUpdate

	/** Will send a callback when it is safe to update nodes. This is defined as between the path searches.
	  * This callback will only be sent once and is nulled directly after the callback has been sent.
	  * When using more threads than one, calling this often might decrease pathfinding performance due to a lot of idling in the threads.
	  * Not performance as in it will use much CPU power,
	  * but performance as in the number of paths per second will probably go down (though your framerate might actually increase a tiny bit)
	  * 
	  * You should only call this function from the main unity thread (i.e normal game code).
	  * 
	  * \warning Note that if you do not set \a threadSafe to true, the callback might not be called from the Unity thread,
	  * DO NOT call any part of the Unity API from those callbacks except for Debug.Log
	  * 
	  * \code
Node node = AstarPath.active.GetNearest (transform.position).node;
AstarPath.RegisterSafeUpdate (delegate () {
	node.walkable = false;
}, false);
\endcode

\code
Node node = AstarPath.active.GetNearest (transform.position).node;
AstarPath.RegisterSafeUpdate (delegate () {
	node.position = (Int3)transform.position;
}, true);
\endcode
	  * Note that the second example uses transform in the callback, and must thus be threadSafe.
	  */
	public static void RegisterSafeUpdate (OnVoidDelegate callback, bool threadSafe) {
		if (callback == null || !Application.isPlaying) {
			return;
		}
		
		//If it already is safe to call any callbacks. call them.
		if (threadSafeUpdateState) {
			callback ();
			return;
		}
		
		if (IsUsingMultithreading) {
			int max = 0;
			//Try to aquire all locks, this will not block
			for (int i=0;i<threadInfos.Length;i++) {
				if (Monitor.TryEnter (threadInfos[i].Lock))
					max = i;
				else
					break;
			}
			
			//We could aquire all locks
			if (max == threadInfos.Length-1) {
				//Temporarily set threadSafeUpdateState to true to tell error checking code that it is safe to update graphs
				threadSafeUpdateState = true;
				callback ();
				threadSafeUpdateState = false;
			}
			
			//Release all locks we managed to aquire
			for (int i=0;i<=max;i++)
				Monitor.Exit (threadInfos[i].Lock);
			
			//If we could not aquire all locks, put it in a queue to be called as soon as possible
			if (max != threadInfos.Length-1) {
				//To speed up things, the path queue flag is reset and it is flagged that it should not be set until callbacks have been updated
				//This will trick the threads to think there is nothing to process and go to sleep (thereby allowing us to update graphs)
				doSetQueueState = false;
				pathQueueFlag.Reset();
				
				lock (safeUpdateLock) {
					
					if (threadSafe)
						OnThreadSafeCallback += callback;
					else
						OnSafeCallback += callback;
					
					//SetSafeUpdateState (true);
					safeUpdateFlag.Set();
				}
			}
		} else {
			
			if (threadSafeUpdateState) {
				callback();
			} else {
				lock (safeUpdateLock) {
					if (threadSafe)
						OnThreadSafeCallback += callback;
					else
						OnSafeCallback += callback;
				}
			}
		}
	}
开发者ID:GJL91,项目名称:Epidemic,代码行数:91,代码来源:AstarPath.cs

示例15: LockThread

	private static void LockThread (System.Object _astar) {
		AstarPath astar = (AstarPath)_astar;
		
		while (astar.acceptNewPaths) {
			safeUpdateFlag.WaitOne ();
			
			PathThreadInfo[] infos = threadInfos;
			if (infos == null) { Debug.LogError ("Path Thread Infos are null"); return; }
			
			//Claim all locks
			for (int i=0;i<infos.Length;i++)
				Monitor.Enter (infos[i].Lock);
			
			lock (safeUpdateLock) {
				safeUpdateFlag.Reset ();
				OnVoidDelegate tmp = OnSafeCallback;
				OnSafeCallback = null;
				if (tmp != null) tmp();
				
				if (OnThreadSafeCallback != null) {
					threadSafeUpdateFlag.Reset ();
				} else {
					threadSafeUpdateFlag.Set();
				}
			}
			threadSafeUpdateState = true;
			
			//Wait until threadsafe updates have been called
			threadSafeUpdateFlag.WaitOne();
			
			//We can set the pathQueueFlag now since we have updated all graphs
			doSetQueueState = true;
			pathQueueFlag.Set();
			
			//Release all locks
			for (int i=0;i<infos.Length;i++)
				Monitor.Exit (infos[i].Lock);
			
		}
	}
开发者ID:GJL91,项目名称:Epidemic,代码行数:40,代码来源:AstarPath.cs


注:本文中的OnVoidDelegate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。