Example #1
0
        public void SimulationLoop()
        {
            long startTime = DateTime.Now.Ticks;

            SimulationTime = new LongValuedLogicalTime(startTime);
            ILogicalTime finalTime = new LongValuedLogicalTime(startTime + NumberOfSeconds * TimeSpan.TicksPerSecond);
            ILogicalTime lastTime  = new LongValuedLogicalTime(startTime);

            while (SimulationTime.CompareTo(finalTime) < 0 && !shouldStop)
            {
                SimulationTime = new LongValuedLogicalTime(DateTime.Now.Ticks);
                boidsManager.DoSimulation(((LongValuedLogicalTimeInterval)time.Distance(lastTime)).Value);
                AdvanceTime();
                lastTime = SimulationTime;
            }

            // clean up for the next test
            ResignAndDestroy();
        }
Example #2
0
        public void SimulationLoop()
        {
            ((XrtiExecutiveAmbassador)rtiAmbassador).interactionManager.AddInteractionListener(this);

            List <ExternalCountry> countriesList = new List <ExternalCountry>();
            Random ran = new Random();

            for (int i = 0; i < 1; i++)
            {
                ExternalCountry aCountry = ExternalCountry.NewExternalCountry();
                aCountry.Name       = "Country[" + i + "]";
                aCountry.Population = ran.Next(1000, 2000);
                countriesList.Add(aCountry);
            }

            SimulationTime = new LongValuedLogicalTime(0);
            ILogicalTime finalTime = new LongValuedLogicalTime(1000);

            while (SimulationTime.CompareTo(finalTime) < 0)
            {
                federateAmbassador.DumpObjects();

                foreach (ExternalCountry country in countriesList)
                {
                    country.Population *= 1.0 + ran.NextDouble() * 0.1; // some random increase in range (1.00 and 1.10)
                }
                CommunicationMessage msg = new CommunicationMessage();
                msg.Message = "Hi, I finished my time " + SimulationTime.ToString();
                Thread.Sleep(4 * 1000);
                ((XrtiExecutiveAmbassador)rtiAmbassador).SendInteraction(msg);
                AdvanceTime();
            }

            if (log.IsInfoEnabled)
            {
                log.Info("Finaliza el bucle de simulaciĆ³n");
            }

            // clean up for the next test
            ResignAndDestroy();
        }