Beispiel #1
0
        public void WaitForEvents()
        {
            //Receives a move done event from the simcore
            string objID     = null;
            string eventType = null;
            List <SimulationEvent> incomingEvents = new List <SimulationEvent>();

            while (true)
            {
                incomingEvents = server.GetEvents();

                if (incomingEvents.Count == 0)
                {//do nothing
                }
                else
                {
                    foreach (SimulationEvent e in incomingEvents)
                    {
                        eventType = e.eventType;
                        switch (eventType)
                        {
                        case "MoveDone":
                            objID = ((StringValue)e["ObjectID"]).value;     //see line 222 of MotionSim.cs for reference
                            MoveComplete_Event returnEvent = new MoveComplete_Event(objID.ToString());

                            IncomingList.Add(returnEvent);

                            break;

                        case "MoveObjectRequest":
                            //Figure out from Dennis how to let him know this happened

                            break;

                        case "AttackObjectRequest":
                            //Figure out from Dennis how to let him know this happened

                            break;

                        default:
                            //Should throw an error?  Will getEvents receive events I'm not subscribed to?
                            break;
                        }
                    }
                    incomingEvents = null;
                }
                Thread.Sleep(100);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string scenarioFile = args[0];

            new ScenarioToQueues(scenarioFile);
            //           string hostname = "dgeller";
            string hostname = args[1];
//            int port = 9999;
            int port = int.Parse(args[2]);
            //           string simModelName = "SimulationModel.xml";
            string        simModelName = args[3];
            NetworkClient c            = new NetworkClient();

            c.Connect(hostname, port);
            EventCommunicator eventCommunicator = new EventCommunicator(c);

            SimulationModelReader smr          = new SimulationModelReader();
            SimulationModelInfo   simModelInfo = smr.readModel(simModelName);

            SimulationEventDistributor       dist = new SimulationEventDistributor(ref simModelInfo);
            SimulationEventDistributorClient cc   = new SimulationEventDistributorClient();

            dist.RegisterClient(ref cc);



            sink = new Watcher(400);
            ThreadStart stub       = new ThreadStart(sink.WatcherThread);
            Thread      stubThread = new Thread(stub);

            stubThread.Start();


            for (int i = 0; i < 5; i++) // in test the move happens at time 2
            {
                TimerTicker.NextTick();
            }
            IncomingList.Add(new MoveComplete_Event("UNIT0"));
            for (int i = 0; i < 2; i++)
            {
                TimerTicker.NextTick();
            }

            Console.WriteLine("The end");
        }