コード例 #1
0
        public static IEnumerable <LSAgent> ScanAll(int gridX, int gridY, int deltaCount,
                                                    LSAgent sourceAgent,
                                                    AllegianceType targetAllegiance)
        {
            long sourceX = sourceAgent.Body._position.x;
            long sourceY = sourceAgent.Body._position.y;

            for (int i = 0; i < deltaCount; i++)
            {
                ScanNode tempNode = GridManager.GetScanNode(
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode.IsNotNull())
                {
                    foreach (FastBucket <LSInfluencer> tempBucket in tempNode.BucketsWithAllegiance(sourceAgent, targetAllegiance))
                    {
                        BitArray arrayAllocation = tempBucket.arrayAllocation;
                        for (int j = 0; j < tempBucket.PeakCount; j++)
                        {
                            if (arrayAllocation.Get(j))
                            {
                                LSAgent tempAgent = tempBucket [j].Agent;
                                if (true)//conditional(tempAgent))
                                {
                                    yield return(tempAgent);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static void ScanAll(int gridX, int gridY, int deltaCount, FastList <LSAgent> outputAgents,
                                   Func <LSAgent, bool> conditional)
        {
            outputAgents.FastClear();
            for (int i = 0; i < deltaCount; i++)
            {
                tempNode = GridManager.GetScanNode(
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode.IsNotNull() && tempNode.LocatedAgents.IsNotNull())
                {
                    tempBucket      = tempNode.LocatedAgents;
                    arrayAllocation = tempBucket.arrayAllocation;
                    for (int j = 0; j < tempBucket.PeakCount; j++)
                    {
                        if (arrayAllocation.Get(j))
                        {
                            tempAgent = tempBucket [j];
                            if (conditional(tempAgent))
                            {
                                outputAgents.Add(tempAgent);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static IEnumerable <LSAgent> ScanAll(int gridX, int gridY, int deltaCount, Func <LSAgent, bool> agentConditional, Func <byte, bool> bucketConditional)
        {
            for (int i = 0; i < deltaCount; i++)
            {
                ScanNode tempNode = GridManager.GetScanNode(
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode.IsNotNull())
                {
                    foreach (FastBucket <LSInfluencer> tempBucket in tempNode.BucketsWithAllegiance(bucketConditional))
                    {
                        BitArray arrayAllocation = tempBucket.arrayAllocation;
                        for (int j = 0; j < tempBucket.PeakCount; j++)
                        {
                            if (arrayAllocation.Get(j))
                            {
                                LSAgent tempAgent = tempBucket [j].Agent;
                                if (agentConditional(tempAgent))
                                {
                                    yield return(tempAgent);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
 public static void GetScanCoordinates(long xPos, long yPos, out int xGrid, out int yGrid)
 {
     //xGrid = (int)((((xPos + FixedMath.Half - 1 - OffsetX) >> FixedMath.SHIFT_AMOUNT) + ScanResolution / 2) / ScanResolution);
     //yGrid = (int)((((yPos + FixedMath.Half - 1 - OffsetY) >> FixedMath.SHIFT_AMOUNT) + ScanResolution / 2) / ScanResolution);
     ScanNode scanNode =  GetNode (xPos, yPos).LinkedScanNode;
     xGrid = scanNode.X;
     yGrid = scanNode.Y;
 }
コード例 #5
0
        private static void Generate()
        {
            #region Pooling; no need to create all those nodes again

            if (Grid != null)
            {
                int min = Grid.Length;
                CachedGridNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedGridNodes.Add(Grid[i]);
                    }
                }
            }


            if (ScanGrid != null)
            {
                int min = ScanGrid.Length;
                CachedScanNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedScanNodes.Add(ScanGrid[i]);
                    }
                }
            }
            #endregion

            long startMem = System.GC.GetTotalMemory(true);
            ScanGrid = new ScanNode[ScanGridSize];
            for (int i = ScanWidth - 1; i >= 0; i--)
            {
                for (int j = ScanHeight - 1; j >= 0; j--)
                {
                    ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode();
                    node.Setup(i, j);
                    ScanGrid[GetScanIndex(i, j)] = node;
                }
            }
            Grid = new GridNode[GridSize];
            for (int i = Width - 1; i >= 0; i--)
            {
                for (int j = Height - 1; j >= 0; j--)
                {
                    GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode();
                    node.Setup(i, j);
                    Grid[GetGridIndex(i, j)] = node;
                }
            }
            long usedMem = System.GC.GetTotalMemory(true) - startMem;
            //Debug.Log ("Grid generated using " + usedMem + " Bytes!");
        }
コード例 #6
0
        private static void Generate()
        {
            #region Pooling; no need to create all those nodes again

            if (Grid != null)
            {
                int min = Grid.Length;
                CachedGridNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        CachedGridNodes.Add(Grid[i]);
                    }
                }
            }


            if (ScanGrid != null)
            {
                int min = ScanGrid.Length;
                CachedScanNodes.EnsureCapacity(min);
                for (int i = min - 1; i >= 0; i--)
                {
                    if (LockstepManager.PoolingEnabled)
                    {
                        ;
                    }
                    CachedScanNodes.Add(ScanGrid[i]);
                }
            }
            #endregion


            ScanGrid = new ScanNode[ScanGridSize];
            for (int i = ScanWidth - 1; i >= 0; i--)
            {
                for (int j = ScanHeight - 1; j >= 0; j--)
                {
                    ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode();
                    node.Setup(i, j);
                    ScanGrid [GetScanIndex(i, j)] = node;
                }
            }
            Grid = new GridNode[GridSize];
            for (int i = Width - 1; i >= 0; i--)
            {
                for (int j = Height - 1; j >= 0; j--)
                {
                    GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode();
                    node.Setup(i, j);
                    Grid [GetGridIndex(i, j)] = node;
                }
            }
        }
コード例 #7
0
        public static void ScanAll(Vector2d position, long radius, Func <LSAgent, bool> agentConditional, Func <byte, bool> bucketConditional, FastList <LSAgent> output)
        {
            output.FastClear();
            int xMin = ((position.x - radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).ToInt();
            int xMax = ((position.x + radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).CeilToInt();
            int yMin = ((position.y - radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).ToInt();
            int yMax = ((position.y + radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).CeilToInt();

            long fastRadius = radius * radius;

            for (int x = xMin; x <= xMax; x++)
            {
                for (int y = yMin; y <= yMax; y++)
                {
                    ScanNode tempNode = GridManager.GetScanNode(
                        x,
                        y);

                    if (tempNode.IsNotNull())
                    {
                        if (tempNode.AgentCount > 0)
                        {
                            bufferBuckets.FastClear();
                            tempNode.GetBucketsWithAllegiance(bucketConditional, bufferBuckets);
                            for (int i = 0; i < bufferBuckets.Count; i++)
                            {
                                FastBucket <LSInfluencer> tempBucket = bufferBuckets[i];
                                BitArray arrayAllocation             = tempBucket.arrayAllocation;
                                for (int j = 0; j < tempBucket.PeakCount; j++)
                                {
                                    if (arrayAllocation.Get(j))
                                    {
                                        LSAgent tempAgent = tempBucket[j].Agent;

                                        long distance = (tempAgent.Body.Position - position).FastMagnitude();
                                        if (distance < fastRadius)
                                        {
                                            if (agentConditional(tempAgent))
                                            {
                                                output.Add(tempAgent);
                                            }
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
 public static void Generate()
 {
     ScanGrid = new ScanNode[ScanNodeCount * ScanNodeCount];
     for (int i = 0; i < NodeCount / ScanResolution; i++) {
         for (int j = 0; j < NodeCount / ScanResolution; j++) {
             ScanGrid [GetScanIndex (i, j)] = new ScanNode (i, j);
         }
     }
     Grid = new GridNode[NodeCount * NodeCount];
     for (int i = 0; i < NodeCount; i++) {
         for (int j = 0; j < NodeCount; j++) {
             Grid [i * NodeCount + j] = new GridNode (i, j);
         }
     }
 }
コード例 #9
0
 public static void Generate()
 {
     ScanGrid = new ScanNode[ScanNodeCount * ScanNodeCount];
     for (int i = 0; i < NodeCount / ScanResolution; i++) {
         for (int j = 0; j < NodeCount / ScanResolution; j++) {
             ScanGrid [GetScanIndex (i, j)] = new ScanNode (i, j);
         }
     }
     Grid = new GridNode[NodeCount * NodeCount];
     for (int i = 0; i < NodeCount; i++) {
         for (int j = 0; j < NodeCount; j++) {
             Grid [i * NodeCount + j] = new GridNode (i, j);
         }
     }
 }
コード例 #10
0
        public static LSAgent Scan(int gridX, int gridY, int deltaCount,
                                   Func <LSAgent, bool> conditional, long sourceX, long sourceY)
        {
            agentFound = false;
            for (int i = 0; i < deltaCount; i++)
            {
                tempNode = GridManager.GetScanNode(
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode.IsNotNull() && tempNode.LocatedAgents.IsNotNull())
                {
                    tempBucket      = tempNode.LocatedAgents;
                    arrayAllocation = tempBucket.arrayAllocation;
                    for (int j = 0; j < tempBucket.PeakCount; j++)
                    {
                        if (arrayAllocation.Get(j))
                        {
                            tempAgent = tempBucket [j];
                            if (conditional(tempAgent))
                            {
                                if (agentFound)
                                {
                                    if ((tempDistance = tempAgent.Body.Position.FastDistance(sourceX, sourceY)) < closestDistance)
                                    {
                                        secondClosest   = closestAgent;
                                        closestAgent    = tempAgent;
                                        closestDistance = tempDistance;
                                    }
                                }
                                else
                                {
                                    closestAgent    = tempAgent;
                                    agentFound      = true;
                                    closestDistance = tempAgent.Body.Position.FastDistance(sourceX, sourceY);
                                }
                            }
                        }
                    }
                    if (agentFound)
                    {
                        return(closestAgent);
                    }
                }
            }
            return(null);
        }
コード例 #11
0
ファイル: InfluenceManager.cs プロジェクト: fqkw6/AStartTest
        public static IEnumerable <LSAgent> ScanAll(Vector2d position, long radius, Func <LSAgent, bool> agentConditional, Func <byte, bool> bucketConditional)
        {
            int xMin = ((position.x - radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).ToInt();
            int xMax = ((position.x + radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).CeilToInt();
            int yMin = ((position.y - radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).ToInt();
            int yMax = ((position.y + radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).CeilToInt();

            long fastRadius = radius * radius;

            for (int x = xMin; x <= xMax; x++)
            {
                for (int y = yMin; y <= yMax; y++)
                {
                    ScanNode tempNode = GridManager.GetScanNode(
                        x,
                        y);

                    if (tempNode.IsNotNull())
                    {
                        foreach (FastBucket <LSInfluencer> tempBucket in tempNode.BucketsWithAllegiance(bucketConditional))
                        {
                            BitArray arrayAllocation = tempBucket.arrayAllocation;
                            for (int j = 0; j < tempBucket.PeakCount; j++)
                            {
                                if (arrayAllocation.Get(j))
                                {
                                    LSAgent tempAgent = tempBucket [j].Agent;

                                    long distance = (tempAgent.Body.Position - position).FastMagnitude();
                                    if (distance < fastRadius)
                                    {
                                        if (agentConditional(tempAgent))
                                        {
                                            yield return(tempAgent);
                                        }
                                    }
                                    else
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        public static bool GetScanCoordinates(long xPos, long yPos, out int xGrid, out int yGrid)
        {
            //xGrid = (int)((((xPos + FixedMath.Half - 1 - OffsetX) >> FixedMath.SHIFT_AMOUNT) + ScanResolution / 2) / ScanResolution);
            //yGrid = (int)((((yPos + FixedMath.Half - 1 - OffsetY) >> FixedMath.SHIFT_AMOUNT) + ScanResolution / 2) / ScanResolution);

            GridNode gridNode = GetNode(xPos, yPos);

            if (gridNode.IsNull())
            {
                xGrid = 0;
                yGrid = 0;
                return(false);
            }

            ScanNode scanNode = gridNode.LinkedScanNode;

            xGrid = scanNode.X;
            yGrid = scanNode.Y;

            return(true);
        }
コード例 #13
0
        public static LSAgent Scan(int gridX, int gridY, int deltaCount,
		                     Func<LSAgent,bool> conditional, long sourceX, long sourceY)
        {
            agentFound = false;
            for (int i = 0; i < deltaCount; i++) {
                tempNode = GridManager.GetScanNode (
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode .IsNotNull () && tempNode.LocatedAgents .IsNotNull ()) {
                    tempBucket = tempNode.LocatedAgents;
                    arrayAllocation = tempBucket.arrayAllocation;
                    for (int j = 0; j < tempBucket.PeakCount; j++) {
                        if (arrayAllocation.Get (j)) {
                            tempAgent = tempBucket [j];
                            if (conditional (tempAgent)) {
                                if (agentFound) {
                                    if ((tempDistance = tempAgent.Body.Position.FastDistance (sourceX, sourceY)) < closestDistance) {
                                        secondClosest = closestAgent;
                                        closestAgent = tempAgent;
                                        closestDistance = tempDistance;
                                    }
                                } else {
                                    closestAgent = tempAgent;
                                    agentFound = true;
                                    closestDistance = tempAgent.Body.Position.FastDistance (sourceX, sourceY);
                                }
                            }
                        }
                    }
                    if (agentFound) {
                        return closestAgent;
                    }
                }
            }
            return null;
        }
コード例 #14
0
 public void Initialize()
 {
     GenerateNeighbors ();
     LinkedScanNode = GridManager.GetScanNode (gridX / GridManager.ScanResolution, gridY / GridManager.ScanResolution);
 }
コード例 #15
0
        public static void ScanAll(int gridX, int gridY, int deltaCount, FastList<LSAgent> outputAgents,
		                           	Func<LSAgent,bool> conditional)
        {
            outputAgents.FastClear ();
            for (int i = 0; i < deltaCount; i++) {
                tempNode = GridManager.GetScanNode (
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode .IsNotNull () && tempNode.LocatedAgents .IsNotNull ()) {
                    tempBucket = tempNode.LocatedAgents;
                    arrayAllocation = tempBucket.arrayAllocation;
                    for (int j = 0; j < tempBucket.PeakCount; j++) {
                        if (arrayAllocation.Get (j)) {
                            tempAgent = tempBucket [j];
                            if (conditional (tempAgent)) {
                                outputAgents.Add (tempAgent);
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
        public static void ScanAll(Vector2d position, long radius, Func <LSAgent, bool> agentConditional, Func <byte, bool> bucketConditional, FastList <LSAgent> output)
        {
            //If radius is too big and we scan too many tiles, performance will be bad
            const long circleCastRadius = FixedMath.One * 16;

            output.FastClear();

            if (radius >= circleCastRadius)
            {
                bufferBodies.FastClear();
                PhysicsTool.CircleCast(position, radius, bufferBodies);
                for (int i = 0; i < bufferBodies.Count; i++)
                {
                    var body  = bufferBodies [i];
                    var agent = body.Agent;
                    //we have to check agent's controller since we did not filter it through buckets
                    if (bucketConditional(agent.Controller.ControllerID))
                    {
                        if (agentConditional(agent))
                        {
                            output.Add(agent);
                        }
                    }
                }
                return;
            }

            int xMin = ((position.x - radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).ToInt();
            int xMax = ((position.x + radius - GridManager.OffsetX) / (long)GridManager.ScanResolution).CeilToInt();
            int yMin = ((position.y - radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).ToInt();
            int yMax = ((position.y + radius - GridManager.OffsetY) / (long)GridManager.ScanResolution).CeilToInt();

            long fastRadius = radius * radius;

            for (int x = xMin; x <= xMax; x++)
            {
                for (int y = yMin; y <= yMax; y++)
                {
                    ScanNode tempNode = GridManager.GetScanNode(
                        x,
                        y);

                    if (tempNode.IsNotNull())
                    {
                        if (tempNode.AgentCount > 0)
                        {
                            bufferBuckets.FastClear();
                            tempNode.GetBucketsWithAllegiance(bucketConditional, bufferBuckets);
                            for (int i = 0; i < bufferBuckets.Count; i++)
                            {
                                FastBucket <LSInfluencer> tempBucket = bufferBuckets[i];
                                BitArray arrayAllocation             = tempBucket.arrayAllocation;
                                for (int j = 0; j < tempBucket.PeakCount; j++)
                                {
                                    if (arrayAllocation.Get(j))
                                    {
                                        LSAgent tempAgent = tempBucket[j].Agent;

                                        long distance = (tempAgent.Body.Position - position).FastMagnitude();
                                        if (distance < fastRadius)
                                        {
                                            if (agentConditional(tempAgent))
                                            {
                                                output.Add(tempAgent);
                                            }
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }