Example #1
0
 public static void Clear()
 {
     for (int i = 0; i < PlayerManager.AgentControllers.PeakCount; i++)
     {
         if (PlayerManager.AgentControllers.arrayAllocation [i])
         {
             FastBucket <LSAgent> selectedAgents = PlayerManager.AgentControllers[i].SelectedAgents;
             for (int j = 0; j < selectedAgents.PeakCount; j++)
             {
                 if (selectedAgents.arrayAllocation [j])
                 {
                     selectedAgents [j].IsSelected = false;
                     onRemove(selectedAgents [j]);
                 }
             }
             selectedAgents.FastClear();
         }
     }
     //if (MainSelectedAgent && MainSelectedAgent.IsSelected)
     //{
     //    MainSelectedAgent.IsSelected = false;
     //}
     MainSelectedAgent = null;
     onClear();
 }
Example #2
0
        //Adds the agent and returns a ticket number
        public void Add(LSInfluencer influencer)
        {
            byte controllerID = influencer.Agent.Controller.ControllerID;

            if (AgentBuckets.Count <= controllerID)
            {
                //fill up indices up till the desired bucket's index
                for (int i = controllerID - AgentBuckets.Count; i >= 0; i--)
                {
                    AgentBuckets.Add(null);
                }
            }

            FastBucket <LSInfluencer> bucket = AgentBuckets [controllerID];

            if (bucket == null)
            {
                //A new bucket for the controller must be created
                bucket = new FastBucket <LSInfluencer> ();
                AgentBuckets [controllerID] = bucket;
            }

            influencer.NodeTicket = bucket.Add(influencer);
            AgentCount++;
        }
Example #3
0
 private void AddChild(LSBody child)
 {
     if (Children == null)
     {
         Children = new FastBucket <LSBody> ();
     }
     Children.Add(child);
 }
 private static void VisualizeBucket(FastBucket <LSProjectile> bucket)
 {
     for (int i = bucket.PeakCount - 1; i >= 0; i--)
     {
         if (bucket.arrayAllocation[i])
         {
             bucket[i].Visualize();
         }
     }
 }
        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;
        }
        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);
                            }
                        }
                    }
                }
            }
        }
Example #7
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 (agent.IsNotNull() && 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
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }