Ejemplo n.º 1
0
        //发送处理完的所有的robot的信息
        public void send_robots_data()
        {
            List <Robot> robots = RobotSystem.get_singleton().get_robots();

            lock (robots)
            {
                foreach (Robot robot in robots)
                {
                    Queue <NetworkMsg> sendQue = robot.m_clientSocket.load_send_queue();
                    while (sendQue.Count > 0)
                    {
                        NetworkMsg msg = sendQue.Dequeue();
                        m_tcpServer.send_networkMessage(msg, robot.m_clientSocket.m_socket);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //更新robot数组信息
        public void receive_robots_data()
        {
            List <Robot> robots = RobotSystem.get_singleton().get_robots();

            bool start_flag = false;

            foreach (Robot robot in robots)
            {
                if (robot == null)
                {
                    continue;               //断开连接时会使得robot = null
                }
                Queue <NetworkMsg> receiveQue = robot.m_clientSocket.load_receive_queue();
                while (receiveQue.Count > 0)
                {
                    NetworkMsg msg = receiveQue.Dequeue();
                    if (msg.MsgType == Type.StartGame)
                    {
                        Log.INFO("receivesd START msg from client {0}", robot.m_socketId);
                        start_flag = true;
                    }
                    else if (msg.MsgType == Type.RobotsData)
                    {
                        Log.INFO("receivesd ROBOT_DATA msg from client {0}", robot.m_socketId);

                        if (msg.RobotData.Count > 0)
                        {
                            robot.m_mapComponent.m_pos.X = msg.RobotData[0].Position.X;
                            robot.m_mapComponent.m_pos.Y = msg.RobotData[0].Position.Y;
                        }
                    }
                }
            }

            if (start_flag)
            {
                send_robots_data();//返回socketId到clients
                GameServer.s_isGameStart = true;
            }
        }
Ejemplo n.º 3
0
        public void update()
        {
            List <Robot> robots = RobotSystem.get_singleton().get_robots();

            foreach (Robot robot in robots)
            {
                if (robot == null)
                {
                    continue;
                }
                int areaIdOld = robot.m_mapComponent.m_areaId;
                int areaIdNew = calculate_robot_area(robot);
                robot.m_mapComponent.m_areaId = areaIdNew;
                update_map(robot, areaIdOld, areaIdNew);
            }
            foreach (Robot robot in robots)
            {
                if (robot == null)
                {
                    continue;
                }
                load_nearby_area_msg(robot, robots);
            }
        }