Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/Game/Agents/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public sealed class AgentController
public static ushort PeakGlobalID { get; private set; }

public const int MaxAgents = 16384;
private static readonly Dictionary<string,IAgentData> CodeInterfacerMap = new Dictionary<string, IAgentData>();
private static readonly Dictionary<string, LSAgent> CodeTemplateMap = new Dictionary<string, LSAgent>();
public static readonly Dictionary<string,IAgentData> CodeInterfacerMap = new Dictionary<string, IAgentData>();
public static readonly Dictionary<string, LSAgent> CodeTemplateMap = new Dictionary<string, LSAgent>();
public static IAgentData[] AgentData;

public static Dictionary<ushort, FastList<bool>> TypeAgentsActive = new Dictionary<ushort, FastList<bool>>();
Expand Down
15 changes: 14 additions & 1 deletion Core/Simulation/Grid/Core/ScanNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte,FastBucket<LSInfluencer>> LocatedAgents = new Dictionary<byte,FastBucket<LSInfluencer>> ();

public int X;
public int Y;
public int AgentCount;
Expand All @@ -25,6 +26,7 @@ public void Add (LSInfluencer influencer) {
if (!LocatedAgents.TryGetValue(teamID, out bucket)) {
bucket = new FastBucket<LSInfluencer>();
LocatedAgents.Add(teamID, bucket);
FastIterationBuckets.Add(new KeyValuePair<byte, FastBucket<LSInfluencer>>(teamID,bucket));
}
influencer.NodeTicket = bucket.Add(influencer);
AgentCount++;
Expand All @@ -35,13 +37,24 @@ public void Remove (LSInfluencer influencer) {
AgentCount--;
}

//Using this for no garbage collection from enumeration
private FastList<KeyValuePair<byte,FastBucket<LSInfluencer>>> FastIterationBuckets = new FastList<KeyValuePair<byte,FastBucket<LSInfluencer>>>();

public void GetBucketsWithAllegiance (Func<byte,bool> bucketConditional, FastList<FastBucket<LSInfluencer>> output) {
for (int i = 0; i < FastIterationBuckets.Count; i++) {
var pair = FastIterationBuckets[i];
if (bucketConditional(pair.Key))
output.Add(pair.Value);
}
}
/*
public IEnumerable<FastBucket<LSInfluencer>> BucketsWithAllegiance (Func<byte,bool> bucketConditional) {
foreach (KeyValuePair<byte,FastBucket<LSInfluencer>> pair in LocatedAgents) {
if (bucketConditional (pair.Key))
{
yield return pair.Value;
}
}
}
}*/
}
}
5 changes: 4 additions & 1 deletion Core/Simulation/Grid/Influence/InfluenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static LSAgent Scan(Vector2d position, long radius, Func<LSAgent, bool> a
return FindClosestAgent(position, bufferAgents);
}

static FastList<FastBucket<LSInfluencer>> bufferBuckets = new FastList<FastBucket<LSInfluencer>>();
public static FastList<LSAgent> bufferAgents = new FastList<LSAgent>();
public static void ScanAll(Vector2d position, long radius, Func<LSAgent, bool> agentConditional, Func<byte, bool> bucketConditional, FastList<LSAgent> output)
{
Expand All @@ -90,8 +91,10 @@ public static void ScanAll(Vector2d position, long radius, Func<LSAgent, bool> a
{
if (tempNode.AgentCount > 0)
{
foreach (FastBucket<LSInfluencer> tempBucket in tempNode.BucketsWithAllegiance(bucketConditional))
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++)
{
Expand Down