public void UnsubscribeAIAgent(AIAgent aiAgent) { lock (runLock) { int aiAgentIndex = aiAgents.IndexOf(aiAgent); if (aiAgentIndex >= 0) { aiAgents.RemoveAt(aiAgentIndex); if (isSubscribed) { AddTotalAIAgents(-1); if (useSingleThread) { AddTotalAIAgentsSinglethreaded(-1); } } // if removed agent is part of a range of agents that still has to be simulated, // then correct the respective range-entry for the next run-tick of the manager int rangeIndex = -1; for (int i = 0; i < remainingRanges.Count; i++) { if ((remainingRanges[i].X <= aiAgentIndex) && (remainingRanges[i].Y >= aiAgentIndex)) { rangeIndex = i; } } if ((aiAgentIndex == 0) && (aiAgents.Count < 1)) { // if this AIAgent was the very last one, reset the remainingRanges remainingRanges.Clear(); remainingRanges.Add(new Types.Vec2i(-1, -1)); } else if (rangeIndex >= 0) { remainingRanges[rangeIndex] = new Types.Vec2i( remainingRanges[rangeIndex].X, remainingRanges[rangeIndex].Y - 1); } } } }
public void SubscribeAIAgent(AIAgent aiAgent) { lock (runLock) { if (!aiAgents.Contains(aiAgent)) { aiAgents.Add(aiAgent); if (isSubscribed) { AddTotalAIAgents(1); if (useSingleThread) { AddTotalAIAgentsSinglethreaded(1); } } // extend the remaining simulation range by 1 new agent added too the bunch int lastIndex = remainingRanges.Count - 1; if (lastIndex >= 0) { if (remainingRanges[lastIndex].X < 0) { remainingRanges[lastIndex] = new Types.Vec2i(0, remainingRanges[lastIndex].Y + 1); } else { remainingRanges[lastIndex] = new Types.Vec2i( remainingRanges[lastIndex].X, remainingRanges[lastIndex].Y + 1); } } else { remainingRanges[lastIndex] = new Types.Vec2i(0, 0); } } } }
// run method for singlethreaded AIManager-instances public void RunSinglethreaded(int maxAgents, out int simulatedAgents, out bool allSimulated) { simulatedAgents = 0; allSimulated = false; int loopLimit = maxAgents; if (aiAgents.Count < maxAgents) { loopLimit = aiAgents.Count; } int currRangeNext, currRangeEnd; try { lock (runLock) { if (remainingRanges[0].X < -1) { // return early because no agents have to be simulated allSimulated = true; return; } while (simulatedAgents < loopLimit) { currRangeNext = remainingRanges[0].X; currRangeEnd = remainingRanges[0].Y; while (currRangeNext <= currRangeEnd) { if (simulatedAgents >= loopLimit) { // return early if the maximum number of agents to simulate // this tick / turn is reached remainingRanges[0] = new Types.Vec2i(currRangeNext, currRangeEnd); return; } aiAgents[currRangeNext].Act(); totalSimulated++; simulatedAgents++; currRangeNext++; } if (remainingRanges.Count > 1) { remainingRanges.RemoveAt(0); } else { // reset the remainingRanges if no agents remain to be simulated remainingRanges[0] = new Types.Vec2i(-1, -1); allSimulated = true; return; } } //for (int i = 0; i < loopLimit; i++) //{ // aiAgents[i].Act(); // totalSimulated++; // tempSimulated++; //} } } catch (Exception ex) { MakeLogError(ex); } }
public override void setPosition(Types.Vec2i position) { throw new NotImplementedException(); }
public override void setPosition(Types.Vec2i position) { throw new NotSupportedException("Text 3D uses 3 coordinates, use setPosition(Types.Vec3f) instead!"); }
public override void setPosition(Types.Vec2i pos) { throw new NotImplementedException("This function does not work for list elements"); }