From 27a0a6e0263fa42d97bcb41a9d49b98c3674fea6 Mon Sep 17 00:00:00 2001 From: SnpM Date: Mon, 22 Aug 2016 12:37:04 -0600 Subject: [PATCH 1/2] Expose dictionaries --- Core/Game/Agents/AgentController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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>(); From cd8cbbcddd5c188c8b9a6d4cbcaa391b5c2bf257 Mon Sep 17 00:00:00 2001 From: SnpM Date: Wed, 24 Aug 2016 14:58:26 -0600 Subject: [PATCH 2/2] Optimize scan node bucket iteration for garbage collection --- Core/Simulation/Grid/Core/ScanNode.cs | 15 ++++++++++++++- .../Simulation/Grid/Influence/InfluenceManager.cs | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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++) {