Пример #1
0
        public void UpdateGoal()
        {
            //List3D<OCChunk> chunks = _map.GetChunks ();

            // Since this is probably bogging down the gameplay, switch it to block creation only.
            //FindGoalBlockPositionInChunks(chunks);

            Vector3 sourcePos   = gameObject.transform.position;
            Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos;

            float integrityChange = _goalNameToChangeRatePerSecond["Integrity"] / (distanceVec.magnitude * _distanceAttenuation);

            integrityChange = integrityChange / 10;

            UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI");

            if (integrityChange > 0.04)
            {
                for (int iAGI = 0; iAGI < agiArray.Length; iAGI++)
                {
                    UnityEngine.GameObject agiObject = agiArray[iAGI];

                    OpenCog.Embodiment.OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OpenCog.Embodiment.OCPhysiologicalModel>();

                    OpenCog.Embodiment.OCPhysiologicalEffect nearHomeEffect = OCPhysiologicalEffect.CreateInstance <OCPhysiologicalEffect>();
                    nearHomeEffect.CostLevelProp = OpenCog.Embodiment.OCPhysiologicalEffect.CostLevel.NONE;

                    nearHomeEffect.FitnessChange = integrityChange;

                    //UnityEngine.Debug.Log ("Increasing Integrity by '" + integrityChange.ToString() + "'");

                    agiPhysModel.ProcessPhysiologicalEffect(nearHomeEffect);
                }
            }

            if (GoalBlockPos != Vector3i.zero && _map.GetBlock(GoalBlockPos).IsEmpty())
            {
                OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
                console.AddConsoleEntry("I perceive no more " + _goalBlockType.GetName() + " blocks in my world.", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
                System.Console.WriteLine(OCLogSymbol.RUNNING + "No more " + _goalBlockType.GetName() + " are reported");

                GoalBlockPos = Vector3i.zero;

                OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>();

                foreach (OCAction action in actions)
                {
                    if (action.EndTarget != null)
                    {
                        action.EndTarget.transform.position = Vector3.zero;
                    }
                    if (action.StartTarget != null)
                    {
                        action.StartTarget.transform.position = Vector3.zero;
                    }
                }
            }
        }
Пример #2
0
        public IEnumerator Listen()
        {
            UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "OCServerListener.Listen() has a networkelement with GUID " + _networkElement.VerificationGuid);

            try
            {
                if (_listener == null)
                {
                    _listener = new TcpListener(_networkElement.IP, _networkElement.Port);

                    _listener.Start();

                    UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "Now listening on " + _networkElement.IP + ":" + _networkElement.Port + "...");

                    OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
                    console.AddConsoleEntry("Listening for connection callback...", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                }
            }
            catch (SocketException se)
            {
                UnityEngine.Debug.LogError(OCLogSymbol.IMPOSSIBLE_ERROR + "Whoops, something went wrong making a TCPListener: " + se.Message);
                //Debug.LogError(se.Message);
                yield break;
            }

            while (!_shouldStop)
            {
                if (!_listener.Pending())
                {
                    //UnityEngine.Debug.Log (System.DateTime.Now.ToString ("HH:mm:ss.fff") + ": Nope, not pending...");
                    if (_shouldStop)
                    {
                        UnityEngine.Debug.LogError(OCLogSymbol.IMPOSSIBLE_ERROR + "OCServerListener.Listener() has TCPListener.Pending() reporting false. Which is funny, because IT SHOULDN'T BE HERE BECAUSE _shouldStop IS TRUE!!");
                    }
                    // If listener is not pending, sleep for a while to relax the CPU.
                    yield return(new UnityEngine.WaitForSeconds(0.5f));
                }
                else
                {
                    UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "Listener is Pending");

                    //try{
                    _sockets.Add(_listener.AcceptSocket());

                    UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "Listener Socket accepted...");

                    OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;

                    // Two sockets must be accepted, for data and
                    // control, we don't know which one is which
                    // though
                    if (_sockets.Count == 1)
                    {
                        console.AddConsoleEntry("First callback received, initializing MessageHandler...",
                                                "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                        new OldMessageHandler(OCNetworkElement.Instance, _sockets.Last()).start();
                    }
                    else if (_sockets.Count == 2)
                    {
                        console.AddConsoleEntry("Second and last callback received, initializing MessageHandler...",
                                                "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                        new OldMessageHandler(OCNetworkElement.Instance, _sockets.Last()).start();

                        _isReady    = true;
                        _shouldStop = true;

                        UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "The Count of scokets is at two, and the MessageHandler is online.");

                        console.AddConsoleEntry("MessageHandler online, ready to receive messages!", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);

                        yield return(new UnityEngine.WaitForSeconds(0.1f));
                    }

                    //	UnityEngine.Debug.Log ("Ok, I'm going to make a new MessageHandler and call StartProcessing now...");
                    //
                    //	if (_messageHandler == null)
                    //		_messageHandler = OCMessageHandler.Instance;
                    //
                    //	if (_messageHandler == null)
                    //		UnityEngine.Debug.Log ("No handler?? I just made it!!");
                    //
                    //	_messageHandler.UpdateMessagesSync(workSocket);
                    //	_messageHandler.UpdateMessages(workSocket);

                    //	UnityEngine.Debug.Log ("Well...did anything happen?");
                    //	}
                    //	catch( SocketException se )
                    //	{
                    //		//Debug.LogError(se.Message);
                    //			UnityEngine.Debug.Log (se.Message);
                    //	}
                }
            }
        }
Пример #3
0
        public IEnumerator Listen()
        {
            UnityEngine.Debug.Log("OCServerListener::Listen has a networkelement with GUID " + _networkElement.VerificationGuid);

            try
            {
                if (_listener == null)
                {
                    _listener = new TcpListener(_networkElement.IP, _networkElement.Port);

                    _listener.Start();

                    UnityEngine.Debug.Log("Now listening on " + _networkElement.IP + ":" + _networkElement.Port + "...");

                    OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
                    console.AddConsoleEntry("Listening for connection callback...", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                }
            }
            catch (SocketException se)
            {
                UnityEngine.Debug.Log("Whoops, something went wrong making a TCPListener: " + se.Message);
                //OCLogger.Error(se.Message);
                yield break;
            }

            while (!_shouldStop)
            {
                if (!_listener.Pending())
                {
                    UnityEngine.Debug.Log(System.DateTime.Now.ToString("HH:mm:ss.fff") + ": Nope, not pending...");
                    if (_shouldStop)
                    {
                        UnityEngine.Debug.Log("Which is funny, because IT SHOULDN'T BE HERE BECAUSE _shouldStop IS TRUE!!");
                    }
                    // If listener is not pending, sleep for a while to relax the CPU.
                    yield return(new UnityEngine.WaitForSeconds(0.5f));
                }
                else
                {
                    UnityEngine.Debug.Log("Yep, pending!");

//				try
//				{
                    UnityEngine.Debug.Log("Accepting socket from listener...");

                    _workSocket = _listener.AcceptSocket();

                    UnityEngine.Debug.Log("Socket accepted...");

                    OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
                    console.AddConsoleEntry("Callback received, initializing MessageHandler...", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);

                    _isReady = true;

                    _shouldStop = true;

                    UnityEngine.Debug.Log("_shouldStop is now TRUE!");

                    new OldMessageHandler(OCNetworkElement.Instance, _workSocket).start();

                    console.AddConsoleEntry("MessageHandler online, ready to receive messages!", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);

                    yield return(new UnityEngine.WaitForSeconds(0.1f));

//					UnityEngine.Debug.Log ("Ok, I'm going to make a new MessageHandler and call StartProcessing now...");
//
//					if (_messageHandler == null)
//						_messageHandler = OCMessageHandler.Instance;
//
//					if (_messageHandler == null)
//						UnityEngine.Debug.Log ("No handler?? I just made it!!");
//
//					_messageHandler.UpdateMessagesSync(workSocket);
                    //_messageHandler.UpdateMessages(workSocket);

//					UnityEngine.Debug.Log ("Well...did anything happen?");
//				}
//				catch( SocketException se )
//				{
//					//OCLogger.Error(se.Message);
//						UnityEngine.Debug.Log (se.Message);
//				}
                }
            }
        }
Пример #4
0
        protected System.Collections.IEnumerator Connect()
        {
            if (_connectionState == ConnectionState.Disconnected)
            {
                _connectionState = ConnectionState.Connecting;

                UnityEngine.Debug.Log("_connectionState == Disconnected, connecting...");

                UnityEngine.Debug.Log("NetworkElement.Connect called at " + System.DateTime.Now.ToString("HH:mm:ss.fff"));

                Socket asyncSocket = new
                                     Socket
                                         (AddressFamily.InterNetwork
                                         , SocketType.Stream
                                         , ProtocolType.Tcp
                                         );

                IPEndPoint ipe = new IPEndPoint(_routerIP, _routerPort);

                UnityEngine.Debug.Log("Start Connecting to router on IP " + _routerIP + ":" + _routerPort + "...");

                // I'd kinda like to display this in the console...so people can see how it's connecting.

                OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;

                if (console == null)
                {
                    UnityEngine.Debug.Log("Nope, grabbing the console didn't work...");
                }
                else
                {
                    //UnityEngine.Debug.Log ("Awesome grabbing the console worked...");

                    console.AddConsoleEntry("Start Connecting to router on IP " + _routerIP + ":" + _routerPort + "...", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                }

                // Start the async connection request.
                System.IAsyncResult ar = asyncSocket
                                         .BeginConnect
                                             (ipe
                                             , new System.AsyncCallback(ConnectCallback)
                                             , asyncSocket
                                             );

                //UnityEngine.Debug.Log ("Error occurs after this...");

                yield return(new UnityEngine.WaitForSeconds(3f));

                //UnityEngine.Debug.Log ("...but before this.");

                int retryTimes = CONNECTION_TIMEOUT;
                while (!ar.IsCompleted)
                {
                    retryTimes--;
                    if (retryTimes == 0)
                    {
                        UnityEngine.Debug.LogWarning("Connection timed out.");
                        yield break;
                    }

                    yield return(new UnityEngine.WaitForSeconds(1.5f));
                }
            }
            else if (_connectionState == ConnectionState.Connecting)
            {
                UnityEngine.Debug.Log("_connectionState == Connecting, not doing anything...");
            }
            else if (_connectionState == ConnectionState.Connected)
            {
                UnityEngine.Debug.Log("_connectionState == Connected, are you a mental?");
            }
        }
Пример #5
0
        protected System.Collections.IEnumerator Connect()
        {
            if (_connectionState == ConnectionState.Disconnected)
            {
                _connectionState = ConnectionState.Connecting;

                //UnityEngine.Debug.Log ("_connectionState == Disconnected, connecting...");

                UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "Trying to Connect, current time is " + System.DateTime.Now.ToString("HH:mm:ss.fff"));


                //NOTE: This InterNetwork flag is probably why our game and embodiment machines must be
                //on the same network in order to detect one another.
                //TODO [Task]: if we checked out our IP address ahead of time we could see if it was on
                //the same network as us and throw a message about it.
                Socket asyncSocket = new
                                     Socket
                                         (AddressFamily.InterNetwork
                                         , SocketType.Stream
                                         , ProtocolType.Tcp
                                         );

                IPEndPoint ipe = new IPEndPoint(_routerIP, _routerPort);

                UnityEngine.Debug.Log(OCLogSymbol.CONNECTION + "Start Connecting to router on IP " + _routerIP + ":" + _routerPort + "...");

                // I'd kinda like to display this in the console...so people can see how it's connecting.

                OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;

                if (console == null)
                {
                    UnityEngine.Debug.LogWarning(OCLogSymbol.WARN + "Nope, grabbing the console didn't work...");
                }
                else
                {
                    //UnityEngine.Debug.Log ("Awesome grabbing the console worked...");

                    console.AddConsoleEntry("Start Connecting to router on IP " + _routerIP + ":" + _routerPort + "...", "Unity World", OpenCog.Utility.Console.Console.ConsoleEntry.Type.RESULT);
                }

                // Start the async connection request.
                System.IAsyncResult ar = asyncSocket
                                         .BeginConnect
                                             (ipe
                                             , new System.AsyncCallback(ConnectCallback)
                                             , asyncSocket
                                             );

                //UnityEngine.Debug.Log ("Error occurs after this...");

                yield return(new UnityEngine.WaitForSeconds(3f));

                //UnityEngine.Debug.Log ("...but before this.");

                int retryTimes = CONNECTION_TIMEOUT;
                while (!ar.IsCompleted)
                {
                    retryTimes--;
                    if (retryTimes == 0)
                    {
                        UnityEngine.Debug.LogError(OCLogSymbol.ERROR + "Connection timed out.");

                        _isEstablished = false;
                        _clientSocket  = null;
                        yield return(false);

                        yield break;
                    }

                    yield return(new UnityEngine.WaitForSeconds(1.5f));
                }
            }
            else if (_connectionState == ConnectionState.Connecting)
            {
                System.Console.WriteLine(OCLogSymbol.CONNECTION + "_connectionState == Connecting, not doing anything...");
            }
            else if (_connectionState == ConnectionState.Connected)
            {
                System.Console.WriteLine(OCLogSymbol.CONNECTION + "_connectionState == Connected, are you a mental?");
            }
        }