Beispiel #1
0
    public void run()
    {
        bool               result;
        AgentConnection    agentConnection;
        InstantiateRequest request;

        //simulationState.stdout.Send("CH: entering main loop\n");

        tcpListener.Start();

        while (!quit)
        {
            Thread.Sleep(0);
            tcpClient       = tcpListener.AcceptTcpClient();
            agentConnection = new AgentConnection(simulationState, tcpClient);

            //simulationState.stdout.Send(String.Format("CH: accepted client.\n"));

            if (agentConnection.init())
            {
                agentConnections.Add(agentConnection);

                request = new InstantiateRequest(agentConnection);
                simulationState.instantiateRequests.Send(request);
                // Block until we get the signal that the agent has been instantiated in the simulation.
                // Then, we can start running it's thread and it's perceive-act loop.
                if (instantiationResults.Recv(out result))
                {
                    if (result)
                    {
                        agentConnection.start();
                    }
                    else
                    {
                        Debug.Log("CH Error: instantiation unsuccesful.");
                    }
                }
                else
                {
                    Debug.LogError("CH Error: instantiation empty.");
                }
            }
        }
        //simulationState.stdout.Send("CH: exit main loop.\n");
    }
    public void run()
    {
        bool result;
        AgentConnection    agentConnection;
        InstantiateRequest request;

        //simulationState.stdout.Send("CH: entering main loop\n");

        tcpListener.Start();

        while (!quit) {
            Thread.Sleep(0);
            tcpClient       = tcpListener.AcceptTcpClient();
            agentConnection = new AgentConnection(simulationState, tcpClient);

            //simulationState.stdout.Send(String.Format("CH: accepted client.\n"));

            if (agentConnection.init()) {
                agentConnections.Add(agentConnection);

                request = new InstantiateRequest(agentConnection);
                simulationState.instantiateRequests.Send(request);
                // Block until we get the signal that the agent has been instantiated in the simulation.
                // Then, we can start running it's thread and it's perceive-act loop.
                if (instantiationResults.Recv(out result)) {
                    if (result) {
                        agentConnection.start();
                    }
                    else {
                        Debug.Log("CH Error: instantiation unsuccesful.");
                    }
                }
                else {
                    Debug.LogError("CH Error: instantiation empty.");
                }
            }
        }
        //simulationState.stdout.Send("CH: exit main loop.\n");
    }