Ejemplo n.º 1
0
        private void PaintSimulationWorld(SimulationWorld simulationWorld)
        {
            /* TODO: If window is smaller then symulation world, we should probably scale every coordinates and dimensions,
             * so that we can paint whole world in smaller window */

            worldCanvas.Children.Clear();
            WorldDim.Text = String.Format("{0} x {1}", simulationWorld.WorldWidth, simulationWorld.WorldHeight);
            SimTime.Text  = String.Format("{0:0.00} s", simulationWorld.Time);
            int robots = simulationWorld.Entities.Where(x => x.Value.ShapeID == SimEnt.KHEPERA_ROBOT_ID).Count();

            NumOfRob.Text = robots.ToString();
            if (robots != 0)
            {
                RobotsGrid.Visibility  = System.Windows.Visibility.Visible;
                RobotsGrid.ItemsSource = simulationWorld.Entities
                                         .Select(x => x.Value)
                                         .Where(x => x.ShapeID == SimEnt.KHEPERA_ROBOT_ID)
                                         .Select(x => new
                {
                    ID = x.ID,
                    IP = x.ControllerAddr ?? "Not connected"
                })
                                         .OrderBy(x => x.ID);
            }
            else
            {
                RobotsGrid.Visibility = System.Windows.Visibility.Hidden;
            }

            foreach (SimEnt entity in simulationWorld.Entities.Values)
            {
                entity.AddToCanvas(worldCanvas);
            }
        }
Ejemplo n.º 2
0
 private void WorldReceiverThread()
 {
     while (_connected)
     {
         SimulationWorld simulationWorld = _connMan.ReciveWorldDesc();
         worldCanvas.Dispatcher.Invoke(new UpdateWorldCallback(PaintSimulationWorld), simulationWorld);
     }
     _connMan.Disconnect();
 }
Ejemplo n.º 3
0
        public SimulationWorld ReciveWorldDesc()
        {
            SimulationWorld result = new SimulationWorld();

            BinaryReader reader = new BinaryReader(_tcpClient.GetStream());

            result.WorldWidth  = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());
            result.WorldHeight = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32());
            result.Time        = reader.ReadDouble();
            bool hasBounds       = reader.ReadBoolean(); // information not used in visualisation
            int  numberOfEntites = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());

            for (int i = 0; i < numberOfEntites; i++)
            {
                SimEnt entity = EntityReceiver.ReadNext(reader);
                entity.VertFunc = x => result.WorldHeight - x;
                result.Entities.Add(entity.ID, entity);
            }

            byte numberOfControllers = reader.ReadByte();

            for (int i = 0; i < numberOfControllers; i++)
            {
                UInt16 robotId = (UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                String port    = ((UInt16)IPAddress.NetworkToHostOrder(reader.ReadInt16())).ToString();
                String ip      = reader.ReadByte().ToString() + '.';
                ip += reader.ReadByte().ToString() + '.';
                ip += reader.ReadByte().ToString() + '.';
                ip += reader.ReadByte().ToString();
                SimEnt entity = null;
                if (result.Entities.TryGetValue(robotId, out entity))
                {
                    entity.ControllerAddr = String.Concat(ip, ':', port);
                }
            }

            return(result);
        }