Exemple #1
0
        public void Add(AbstractEmitterType emitter)
        {
            Vector3d initialVelocity;
            Point3d  emittionPt = emitter.Emit(out initialVelocity);
            IQuelea  quelea     = MakeParticle(queleaSettings[nextIndex], emittionPt, initialVelocity);

            Quelea.Add(quelea);
            nextIndex = (nextIndex + 1) % queleaSettings.Count;
        }
Exemple #2
0
 private ISpatialCollection <IQuelea> GetNeighborsWrapped()
 {
     foreach (IQuelea potentialNeighbor in queleaNetwork.Quelea)
     {
         if (agent == potentialNeighbor)
         {
             continue;
         }
         Point3d wrappedPosition = agent.Environment.WrapPoint(agent.Position, potentialNeighbor.Position);
         if (agent.Position.DistanceTo(wrappedPosition) <= agent.VisionRadius * visionRadiusMultiplier)
         {
             neighbors.Add(potentialNeighbor);
             wrappedPositions.Add(wrappedPosition);
         }
     }
     return(neighbors);
 }
Exemple #3
0
        public static void testSpatialCollection(ISpatialCollection <AgentType> testingAgents)
        {
            Console.WriteLine("Running test for " + testingAgents.GetType().Name);
            ISpatialCollection <AgentType> baseAgents = new SpatialCollectionAsList <AgentType>();
            List <AgentType> agents = new List <AgentType>();

            Console.WriteLine("Creating Agents.");
            for (int i = 0; i < NUM_AGENTS; i++)
            {
                agents.Add(new AgentType(Random.RandomPoint(min, max)));
            }
            // DK: For testing/debugging, was using just these 2 points:
            // agents.Add(new AgentType(new Point3d(1, 1, 1)));
            // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

            Stopwatch stopwatchBase    = new Stopwatch();
            Stopwatch stopwatchTesting = new Stopwatch();

            Console.WriteLine("Getting add time data.");

            stopwatchBase.Start();
            foreach (AgentType agent in agents)
            {
                baseAgents.Add(agent);
            }
            //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchBase.Stop();

            stopwatchTesting.Start();
            foreach (AgentType agent in agents)
            {
                testingAgents.Add(agent);
            }
            //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchTesting.Stop();

            TimeSpan baseAddTime = stopwatchBase.Elapsed;
            TimeSpan testAddTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseAddTime);
            Console.WriteLine("Testing time elapsed: {0}", testAddTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

            if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
            {
                Console.WriteLine("Checking neighbors match.");
                foreach (AgentType agent in agents)
                {
                    ISpatialCollection <AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
                    ISpatialCollection <AgentType> baseNeighbors    = baseAgents.getNeighborsInSphere(agent, visionRadius);
                    foreach (AgentType neighbor in testingNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                        {
                            Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                    foreach (AgentType neighbor in baseNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                        {
                            Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                }
            }
            Console.WriteLine("Getting getNeighbors timing data.");
            stopwatchBase.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchBase.Stop();
            TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);


            stopwatchTesting.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchTesting.Stop();
            TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

            TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);

            Console.WriteLine("Total base time: {0}", totalBaseTime);
            TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);

            Console.WriteLine("Total test time: {0}", totalTestTime);
            Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
        }
Exemple #4
0
    public static void testSpatialCollection(ISpatialCollection<AgentType> testingAgents)
    {
      Console.WriteLine("Running test for " + testingAgents.GetType().Name);
      ISpatialCollection<AgentType> baseAgents = new SpatialCollectionAsList<AgentType>();
      List<AgentType> agents = new List<AgentType>();
      Console.WriteLine("Creating Agents.");
      for (int i = 0; i < NUM_AGENTS; i++) agents.Add(new AgentType(Random.RandomPoint(min, max)));
      // DK: For testing/debugging, was using just these 2 points:
      // agents.Add(new AgentType(new Point3d(1, 1, 1)));
      // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

      Stopwatch stopwatchBase = new Stopwatch();
      Stopwatch stopwatchTesting = new Stopwatch();
      Console.WriteLine("Getting add time data.");

      stopwatchBase.Start();
      foreach (AgentType agent in agents)
      {
          baseAgents.Add(agent);
      }
      //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchBase.Stop();

      stopwatchTesting.Start();
      foreach (AgentType agent in agents)
      {
        testingAgents.Add(agent);
      }
      //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchTesting.Stop();

      TimeSpan baseAddTime = stopwatchBase.Elapsed;
      TimeSpan testAddTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseAddTime);
      Console.WriteLine("Testing time elapsed: {0}", testAddTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

      if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
      {
          Console.WriteLine("Checking neighbors match.");
          foreach (AgentType agent in agents)
          {
              ISpatialCollection<AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
              ISpatialCollection<AgentType> baseNeighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
              foreach (AgentType neighbor in testingNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                  {
                    Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
              foreach (AgentType neighbor in baseNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                  {
                    Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
          }
      }
      Console.WriteLine("Getting getNeighbors timing data.");
      stopwatchBase.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchBase.Stop();
      TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);

      
      stopwatchTesting.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchTesting.Stop();
      TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

      TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);
      Console.WriteLine("Total base time: {0}", totalBaseTime);
      TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);
      Console.WriteLine("Total test time: {0}", totalTestTime);
      Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
    }
Exemple #5
0
 public void AddCollider(Collider collider)
 {
     _colliders.Add(collider, collider.bounds);
 }