diff --git a/Core/Game/Agents/AgentController.cs b/Core/Game/Agents/AgentController.cs index f5b0ff16..c47010f2 100755 --- a/Core/Game/Agents/AgentController.cs +++ b/Core/Game/Agents/AgentController.cs @@ -21,8 +21,8 @@ public sealed class AgentController public static ushort PeakGlobalID { get; private set; } public const int MaxAgents = 16384; - private static readonly Dictionary CodeInterfacerMap = new Dictionary(); - private static readonly Dictionary CodeTemplateMap = new Dictionary(); + public static readonly Dictionary CodeInterfacerMap = new Dictionary(); + public static readonly Dictionary CodeTemplateMap = new Dictionary(); public static IAgentData[] AgentData; public static Dictionary> TypeAgentsActive = new Dictionary>(); diff --git a/Core/Simulation/Grid/Core/ScanNode.cs b/Core/Simulation/Grid/Core/ScanNode.cs index 93db7ce4..2822dd44 100755 --- a/Core/Simulation/Grid/Core/ScanNode.cs +++ b/Core/Simulation/Grid/Core/ScanNode.cs @@ -15,6 +15,7 @@ public void Setup (int x, int y) { } //One bucket for each AC of units that lands on this ScanNode private Dictionary> LocatedAgents = new Dictionary> (); + public int X; public int Y; public int AgentCount; @@ -25,6 +26,7 @@ public void Add (LSInfluencer influencer) { if (!LocatedAgents.TryGetValue(teamID, out bucket)) { bucket = new FastBucket(); LocatedAgents.Add(teamID, bucket); + FastIterationBuckets.Add(new KeyValuePair>(teamID,bucket)); } influencer.NodeTicket = bucket.Add(influencer); AgentCount++; @@ -35,6 +37,17 @@ public void Remove (LSInfluencer influencer) { AgentCount--; } + //Using this for no garbage collection from enumeration + private FastList>> FastIterationBuckets = new FastList>>(); + + public void GetBucketsWithAllegiance (Func bucketConditional, FastList> output) { + for (int i = 0; i < FastIterationBuckets.Count; i++) { + var pair = FastIterationBuckets[i]; + if (bucketConditional(pair.Key)) + output.Add(pair.Value); + } + } + /* public IEnumerable> BucketsWithAllegiance (Func bucketConditional) { foreach (KeyValuePair> pair in LocatedAgents) { if (bucketConditional (pair.Key)) @@ -42,6 +55,6 @@ public IEnumerable> BucketsWithAllegiance (Func a return FindClosestAgent(position, bufferAgents); } + static FastList> bufferBuckets = new FastList>(); public static FastList bufferAgents = new FastList(); public static void ScanAll(Vector2d position, long radius, Func agentConditional, Func bucketConditional, FastList output) { @@ -90,8 +91,10 @@ public static void ScanAll(Vector2d position, long radius, Func a { if (tempNode.AgentCount > 0) { - foreach (FastBucket tempBucket in tempNode.BucketsWithAllegiance(bucketConditional)) + tempNode.GetBucketsWithAllegiance(bucketConditional,bufferBuckets); + for (int i = 0; i < bufferBuckets.Count; i++) { + FastBucket tempBucket = bufferBuckets[i]; BitArray arrayAllocation = tempBucket.arrayAllocation; for (int j = 0; j < tempBucket.PeakCount; j++) {