示例#1
0
        /// <summary>
        /// 周期调用触发任务
        /// </summary>
        public static void Tick()
        {
            m_unTick = (uint)(1000 * Time.time);

            while (m_queue.Count != 0)
            {
                AbsTimerData p;
                lock (m_queueLock)
                    p = m_queue.Peek();
                if (m_unTick < p.UnNextTick)
                {
                    break;
                }
                lock (m_queueLock)
                    m_queue.Dequeue();
                if (p.NInterval > 0)
                {
                    p.UnNextTick += (ulong)p.NInterval;
                    lock (m_queueLock)
                        m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
                    p.DoAction();
                }
                else
                {
                    p.DoAction();
                }
            }
        }
示例#2
0
 public static void Tick()
 {
     mCurrentTick += (uint)mStopWatch.ElapsedMilliseconds;
     mStopWatch.Reset();
     mStopWatch.Start();
     while (mPriorityQueue.Count != 0)
     {
         TimerTask p;
         lock (mQueueLock)
         {
             p = mPriorityQueue.Peek();
         }
         if (mCurrentTick < p.NextTick)
         {
             break;
         }
         lock (mQueueLock)
         {
             mPriorityQueue.Dequeue();
         }
         if (p.Interval > 0)
         {
             p.NextTick += (ulong)p.Interval;
             lock (mQueueLock)
             {
                 mPriorityQueue.Enqueue(p.TimerId, p, p.NextTick);
             }
             p.DoAction();
         }
         else
         {
             p.DoAction();
         }
     }
 }
        /// <summary>
        /// 周期调用触发任务
        /// </summary>
        public static void Tick()
        {
            m_unTick += (uint)m_stopWatch.ElapsedMilliseconds;
            m_stopWatch.Reset();
            m_stopWatch.Start();

            while (m_queue.Count != 0)
            {
                AbsTimerData p;
                lock (m_queueLock)
                    p = m_queue.Peek();
                if (m_unTick < p.UnNextTick)
                {
                    break;
                }
                lock (m_queueLock)
                    m_queue.Dequeue();
                if (p.NInterval > 0)
                {
                    p.UnNextTick += (ulong)p.NInterval;
                    lock (m_queueLock)
                        m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
                    p.DoAction();
                }
                else
                {
                    p.DoAction();
                }
            }
        }
示例#4
0
        /// <summary>
        /// 周期调用触发任务
        /// </summary>
        public static void Tick()
        {
            m_unTick += (uint)(1000 * Time.deltaTime);
            //LoggerHelper.Error("m_unTick: " + (uint)(1000 * Time.deltaTime) + " Time.timeScale: " + Time.timeScale + " Time.deltaTime: " + Time.deltaTime);

            while (m_queue.Count != 0)
            {
                AbsTimerData p;
                lock (m_queueLock)
                    p = m_queue.Peek();
                if (m_unTick < p.UnNextTick)
                {
                    break;
                }
                lock (m_queueLock)
                    m_queue.Dequeue();
                if (p.NInterval > 0)
                {
                    p.UnNextTick += (ulong)p.NInterval;
                    lock (m_queueLock)
                        m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
                    p.DoAction();
                }
                else
                {
                    p.DoAction();
                }
            }
        }
示例#5
0
 public static void Tick()
 {
     mCurrentTick += (uint)(1000 * Time.deltaTime);
     while (mPriorityQueue.Count != 0)
     {
         AbstractTimerData p;
         lock (mQueueLock)
             p = mPriorityQueue.Peek();
         if (mCurrentTick < p.mNextTick)
         {
             break;
         }
         lock (mQueueLock)
             mPriorityQueue.Dequeue();
         if (p.mInterval > 0)
         {
             p.mNextTick += (ulong)p.mInterval;
             lock (mQueueLock)
                 mPriorityQueue.Enqueue(p.mTimerId, p, p.mNextTick);
             p.DoAction();
         }
         else
         {
             p.DoAction();
         }
     }
 }
示例#6
0
 private static uint AddTimer(AbsTimerData p)
 {
     lock (m_queueLock)
     {
         m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
     }
     return(p.NTimerId);
 }
        private static void UpdateEdge(HalfEdge edgeToRemove, KeyedPriorityQueue <int, HalfEdge, float> priorityQueue, HashSet <EdgeID> deletedEdgeSet, List <Vector2> pointList)
        {
            HalfEdge left   = GetUndeletedLeft(edgeToRemove, deletedEdgeSet);
            HalfEdge right  = GetUndeletedRight(edgeToRemove, deletedEdgeSet);
            HalfEdge reLeft = RepresentActive(left);

            if (priorityQueue.Contain(reLeft.mKey))
            {
                // Check if this is still removable
                HalfEdge leftOfLeft = GetUndeletedLeft(left.mPartner, deletedEdgeSet);
                if ((leftOfLeft.mPartner != null && (leftOfLeft.mPartner.mKey == right.mKey || leftOfLeft.mPartner.mKey == edgeToRemove.mKey)) ||
                    !GeoPolygonUtils.IsConvex(pointList[edgeToRemove.mIndex], pointList[right.mNext.mIndex], pointList[leftOfLeft.mIndex]))
                {
                    priorityQueue.Remove(reLeft.mKey);
                }
                else
                {
                    // Need to update the priority
                    float pri = GetSmallestAdjacentAngleOnEdge(left, deletedEdgeSet, pointList);
                    priorityQueue.Remove(reLeft.mKey);
                    priorityQueue.Enqueue(reLeft.mKey, reLeft, pri);
                }
            }
            HalfEdge reRight = RepresentActive(right);

            if (priorityQueue.Contain(reRight.mKey))
            {
                HalfEdge rightOfRight = GetUndeletedRight(right, deletedEdgeSet);
                if ((rightOfRight.mPartner != null && (rightOfRight.mPartner.mKey == left.mKey || rightOfRight.mKey == edgeToRemove.mKey)) ||
                    !GeoPolygonUtils.IsConvex(pointList[edgeToRemove.mIndex], pointList[rightOfRight.mNext.mIndex], pointList[left.mIndex]))
                {
                    priorityQueue.Remove(reRight.mKey);
                }
                else
                {
                    priorityQueue.Remove(reRight.mKey);
                    priorityQueue.Enqueue(reRight.mKey, reRight, GetSmallestAdjacentAngleOnEdge(right, deletedEdgeSet, pointList));
                }
            }
        }
示例#8
0
        /// <summary>
        /// 周期调用触发任务
        /// </summary>
        public static void Tick()
        {
            //累计获取逝去的时间
            m_unTick += (uint)m_stopWatch.ElapsedMilliseconds;
            //重置StopWatch
            m_stopWatch.Reset();
            m_stopWatch.Start();

            while (m_queue.Count != 0)
            {
                //队列出列
                AbsTimerData p;
                lock (m_queueLock)
                    p = m_queue.Peek();
                //判断出列Timer是否到时间
                if (m_unTick < p.UnNextTick)
                {
                    break;
                }
                //出列
                lock (m_queueLock)
                    m_queue.Dequeue();
                //间隔时间不等于0,重复执行Timer
                if (p.NInterval > 0)
                {
                    //更新下一次Tick时间
                    p.UnNextTick += (ulong)p.NInterval;
                    //重新入列
                    lock (m_queueLock)
                        m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
                    p.DoAction();
                }
                else
                {
                    p.DoAction();
                }
            }
        }
示例#9
0
            private void AddInternal(UpdateDelegate update, bool ignoreBehaviour, int priority, bool unscaled)
            {
                if (update == null)
                {
                    return;
                }
                int key = update.GetHashCode();

                if (mUpdaters.ContainsKey(key) || mNewUpdaters.Contains(key))
                {
                    return;
                }
                MonoBehaviour behaviour = ignoreBehaviour ? null : update.Target as MonoBehaviour;
                UpdateItem    updater   = UpdateItem.Get(key, priority, unscaled, behaviour, update);

                if (mUpdating)
                {
                    mToAddUpdaters.Add(updater);
                }
                else
                {
                    mNewUpdaters.Enqueue(key, updater, priority);
                }
            }
        private static void GetRemovableEdgeQueue(List <Vector2> vertes, List <HalfEdge> edges, ref KeyedPriorityQueue <int, HalfEdge, float> remoableEdge)
        {
            HashSet <EdgeID> deleteSet = new HashSet <EdgeID>();

            foreach (HalfEdge edge in edges)
            {
                if (edge.mIndex > edge.mNext.mIndex)
                {
                    continue;
                }
                if (IsEdgeRemovable(vertes, edge))
                {
                    remoableEdge.Enqueue(edge.mKey, edge, GetSmallestAdjacentAngleOnEdge(edge, deleteSet, vertes));
                }
            }
        }
        internal protected override void Schedule(WaitCallback callback, Guid workflowInstanceId, DateTime whenUtc, Guid timerId)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (workflowInstanceId.Equals(Guid.Empty))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CantBeEmptyGuid, "workflowInstanceId"));
            }
            if (timerId.Equals(Guid.Empty))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CantBeEmptyGuid, "timerId"));
            }

            lock (locker)
            {
                WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "ManualWorkflowSchedulerService: Schedule timer {0} for workflow {1} at {2}", timerId, workflowInstanceId, whenUtc);
                pendingScheduleRequests.Enqueue(timerId, new CallbackInfo(callback, workflowInstanceId, timerId, whenUtc), whenUtc);
            }
        }
示例#12
0
        public List <Vector2i> PathFind(Vector2i start, Vector2i end)
        {
            bool found = false;

            mOpenTable.Clear();
            mResultPath.Clear();
            mOpenStatusValue  += 2;
            mCloseStatusValue += 2;
            int    closeNodeCounter = 0;
            ushort location         = (ushort)((start[1] << mGridXLog2) + start[0]);
            ushort endLocation      = (ushort)((end[1] << mGridXLog2) + end[0]);

            mGridNode[location].G      = 0;
            mGridNode[location].F      = _hEstimate;
            mGridNode[location].PX     = (ushort)start[0];
            mGridNode[location].PY     = (ushort)start[1];
            mGridNode[location].Status = mOpenStatusValue;

            mOpenTable.Enqueue(location, location, mGridNode[location].F);

            ushort locationX;
            ushort locationY;
            ushort mHoriz = 0;

            sbyte[,] direction = _useDiagonal ? AStarDirection.DiagonalDirection : AStarDirection.NormalDirection;
            int directionCount = _useDiagonal ? 8 : 4;

            while (mOpenTable.Count > 0)
            {
                location = mOpenTable.Dequeue();
                if (mGridNode[location].Status == mCloseStatusValue)
                {
                    continue;
                }
                if (location == endLocation)
                {
                    mGridNode[location].Status = mCloseStatusValue;
                    found = true;
                    break;
                }
                if (closeNodeCounter > _searchLimit)
                {
                    break;
                }
                locationX = (ushort)(location & mGridXMod);
                locationY = (ushort)(location >> mGridXLog2);
                if (_usePunish)
                {
                    mHoriz = (ushort)(locationX - mGridNode[location].PX);
                }
                int newG;
                for (int i = 0; i < directionCount; i++)
                {
                    ushort newLocationX = (ushort)(locationX + direction[i, 0]);
                    ushort newLocationY = (ushort)(locationY + direction[i, 1]);
                    ushort newLocation  = (ushort)((newLocationY << mGridXLog2) + newLocationX);
                    if (newLocationX >= mGridX || newLocationY >= mGridY)
                    {
                        continue;
                    }
                    if (mGridNode[newLocation].Status == mCloseStatusValue && !ReuseClose)
                    {
                        continue;
                    }
                    if (mGrid[newLocationX, newLocationY] == 0)
                    {
                        continue;
                    }
                    if (_useDiagonal && i > 3)
                    {
                        newG = mGridNode[location].G + (int)(mGrid[newLocationX, newLocationY] * 2.41);
                    }
                    else
                    {
                        newG = mGridNode[location].G + mGrid[newLocationX, newLocationY];
                    }
                    if (Punish)
                    {
                        if ((newLocationX - locationX) != 0)
                        {
                            if (mHoriz == 0)
                            {
                                newG += Math.Abs(newLocationX - end[0]) + Math.Abs(newLocationY - end[1]);
                            }
                        }
                        if ((newLocationY - locationY) != 0)
                        {
                            if (mHoriz != 0)
                            {
                                newG += Math.Abs(newLocationX - end[0]) + Math.Abs(newLocationY - end[1]);
                            }
                        }
                    }
                    if (mGridNode[newLocation].Status == mOpenStatusValue || mGridNode[newLocation].Status == mCloseStatusValue)
                    {
                        if (mGridNode[newLocation].G <= newG)
                        {
                            continue;
                        }
                    }
                    mGridNode[newLocation].PX = locationX;
                    mGridNode[newLocation].PY = locationY;
                    mGridNode[newLocation].G  = newG;

                    int newH = 0;
                    switch (_useFormula)
                    {
                    case AStarFormula.Manhattan:
                        newH = _hEstimate * (Math.Abs(newLocationX - end[0]) + Math.Abs(newLocationY - end[1]));
                        break;

                    case AStarFormula.MaxDXDY:
                        newH = _hEstimate * (Math.Max(Math.Abs(newLocationX - end[0]), Math.Abs(newLocationY - end[1])));
                        break;

                    case AStarFormula.DiagonalShortCut:
                        int h_diagonal = Math.Min(Math.Abs(newLocationX - end[0]), Math.Abs(newLocationY - end[1]));
                        int h_straight = (Math.Abs(newLocationX - end[0]) + Math.Abs(newLocationY - end[1]));
                        newH = (_hEstimate * 2) * h_diagonal + _hEstimate * (h_straight - 2 * h_diagonal);
                        break;

                    case AStarFormula.Euclidean:
                        newH = (int)(_hEstimate * Math.Sqrt(Math.Pow((newLocationY - end[0]), 2) + Math.Pow((newLocationY - end[1]), 2)));
                        break;

                    case AStarFormula.EuclideanNoSQR:
                        newH = (int)(_hEstimate * (Math.Pow((newLocationX - end[0]), 2) + Math.Pow((newLocationY - end[1]), 2)));
                        break;

                    case AStarFormula.Custom:
                        Vector2i dxy        = new Vector2i(Math.Abs(end[0] - newLocationX), Math.Abs(end[1] - newLocationY));
                        int      Orthogonal = Math.Abs(dxy[0] - dxy[1]);
                        int      Diagonal   = Math.Abs(((dxy[0] + dxy[1]) - Orthogonal) / 2);
                        newH = _hEstimate * (Diagonal + Orthogonal + dxy[0] + dxy[1]);
                        break;
                    }
                    if (_useTieBreaker)
                    {
                        int dx1   = locationX - end[0];
                        int dy1   = locationY - end[1];
                        int dx2   = start[0] - end[0];
                        int dy2   = start[1] - end[1];
                        int cross = Math.Abs(dx1 * dy2 - dx2 * dy1);
                        newH = (int)(newH + cross * _multiple);
                    }
                    mGridNode[newLocation].F = newG + newH;
                    mOpenTable.Enqueue(newLocation, newLocation, mGridNode[newLocation].F);
                    mGridNode[newLocation].Status = mOpenStatusValue;
                }
                closeNodeCounter++;
                mGridNode[location].Status = mCloseStatusValue;
            }
            if (found)
            {
                mResultPath.Clear();
                PathNode       tmp  = mGridNode[(end[1] << mGridXLog2) + end[0]];
                PathNodeResult node = new PathNodeResult();
                node.F  = tmp.F;
                node.G  = tmp.G;
                node.H  = 0;
                node.PX = tmp.PX;
                node.PY = tmp.PY;
                node.X  = end[0];
                node.Y  = end[1];
                while (node.X != node.PX || node.Y != node.PY)
                {
                    mResultPath.Add(node);
                    ushort posX = node.PX;
                    ushort posY = node.PY;
                    tmp     = mGridNode[(posY << mGridXLog2) + posX];
                    node    = new PathNodeResult();
                    node.F  = tmp.F;
                    node.G  = tmp.G;
                    node.H  = 0;
                    node.PX = tmp.PX;
                    node.PY = tmp.PY;
                    node.X  = posX;
                    node.Y  = posY;
                }
                mResultPath.Add(node);
                mResultPath.Reverse(0, mResultPath.Count);
                List <Vector2i> res = new List <Vector2i>();
                foreach (PathNodeResult n in mResultPath)
                {
                    res.Add(new Vector2i(n.X, n.Y));
                }
                return(res);
            }
            return(null);
        }
示例#13
0
 public void AddTask(T task, int priority)
 {
     m_WaitingTasks.Enqueue(task.SerialId, task, priority);
 }
示例#14
0
        public void GenerateDisjktraMatrix(NodeType startNode, float infinite)
        {
            if (mAdjacencyLists.Count == 0)
            {
                return;
            }
            mCostMatrix     = new float[mAdjacencyLists.Count * mAdjacencyLists.Count];
            mLeastNodeArray = new NodeType[mAdjacencyLists.Count];
            //mCostMatrixIndices.Clear();
            //foreach (var key in mAdjacencyLists.Keys)
            //{
            //    mCostMatrixIndices.Add(key);
            //}
            //mCostMatrixIndices.Sort((NodeType node1, NodeType node2) => { return mCompareFunc(node1, node2); }); // 由小到大排序
            for (int i = 0; i < mAdjacencyLists.Count * mAdjacencyLists.Count; ++i)
            {
                mCostMatrix[i] = infinite;
            }
            int adjacentIndex = GetIndexByKey(startNode);

            if (adjacentIndex == -1)
            {
                throw new Exception("-1 null");
            }
            for (int r = 0; r < mAdjacencyLists.Count; ++r)
            {
                mCostMatrix[r * mAdjacencyLists.Count + adjacentIndex] = 0.0f;
            }
            mRootNode = startNode;
            int      row         = 0;
            NodeType currentNode = startNode;
            Dictionary <NodeType, float> adjacencyList;
            float    edgeWeight, adjacentNodeWeight, currentNodeWeight = 0.0f;
            NodeType adjacentKey;
            Dictionary <NodeType, float> openSet = new Dictionary <NodeType, float>();

            while (row < mAdjacencyLists.Count - 1)
            {
                adjacencyList = mAdjacencyLists[currentNode];
                foreach (var v in adjacencyList)
                {
                    edgeWeight         = v.Value;
                    adjacentKey        = v.Key;
                    adjacentIndex      = GetIndexByKey(adjacentKey);
                    adjacentNodeWeight = mCostMatrix[row * mAdjacencyLists.Count + adjacentIndex];
                    if (currentNodeWeight + edgeWeight < adjacentNodeWeight)
                    {
                        // Update the weight for the adjacent node
                        for (int r = row; r < mAdjacencyLists.Count; r++)
                        {
                            mCostMatrix[r * mAdjacencyLists.Count + adjacentIndex] = currentNodeWeight + edgeWeight;
                        }
                        if (!openSet.ContainsKey(adjacentKey))
                        {
                            openSet.Add(adjacentKey, currentNodeWeight + edgeWeight);
                        }
                        else
                        {
                            openSet[adjacentKey] = currentNodeWeight + edgeWeight;
                        }
                    }
                }
                KeyedPriorityQueue <NodeType, NodeType, float> minHeap = new KeyedPriorityQueue <NodeType, NodeType, float>();
                foreach (var open in openSet)
                {
                    minHeap.Enqueue(open.Key, open.Key, open.Value);
                }
                if (minHeap.Count == 0)
                {
                    isValidPath = true;
                    break;
                }
                currentNodeWeight    = minHeap.PeekPriority();
                mLeastNodeArray[row] = minHeap.Dequeue();
                currentNode          = mLeastNodeArray[row];
                openSet.Remove(currentNode);
                row++;
            }
            isValidPath = true;
        }
示例#15
0
文件: CTimeSys.cs 项目: yh821/Zombie
    /// <summary>
    /// 周期调用触发任务
    /// </summary>
    public void Tick()
    {
        if (isPause)
        {
            return;
        }
        if (!m_stopWatch.IsRunning)
        {
            m_stopWatch.Start();
        }

        m_unTick = (uint)(UnityEngine.Time.time * 1000);

        m_checkTimeTmp       += m_invokeReaptingTime;
        m_timeSystemTimerTmp += m_invokeReaptingTime;
        if (m_cheat == false)
        {
            if (m_checkTimeTmp > m_checkPerTime)
            {
                m_checkTimeTmp = 0;
                CheckCheat();
            }
        }

        bool profilerSample = UnityEngine.Debug.isDebugBuild || UnityEngine.Application.isEditor;

        while (m_queue.Count != 0)
        {
            AbsTimerData p;
            lock (m_queueLock)
                p = m_queue.Peek();
            if (m_unTick < p.UnNextTick)
            {
                break;
            }
            lock (m_queueLock)
                m_queue.Dequeue();
            if (p.NInterval > 0)
            {
                p.UnNextTick += (ulong)p.NInterval;
                lock (m_queueLock)
                    m_queue.Enqueue(p.NTimerId, p, p.UnNextTick);
                if (profilerSample)
                {
                    var name = string.IsNullOrEmpty(p.StackTrack) ? p.Action.Method.Name : p.StackTrack;
                    Profiler.BeginSample(name);
                }
                p.DoAction();
                if (profilerSample)
                {
                    Profiler.EndSample();
                }
            }
            else
            {
                if (profilerSample)
                {
                    var name = string.IsNullOrEmpty(p.StackTrack) ? p.Action.Method.Name : p.StackTrack;
                    Profiler.BeginSample(name);
                }
                p.DoAction();
                if (profilerSample)
                {
                    Profiler.EndSample();
                }
            }
        }
    }