Ejemplo n.º 1
0
    /*
     * Update is called once per frame
     * Take the most recent ZMQ message and use it to position the cameras.
     * If there has not been a recent message, the renderer should probably pause rendering until a new request is received.
     */

    void Update()
    {
        if (pull_socket.HasIn || socket_initialized)
        {
            // Receive most recent message
            var msg     = new NetMQMessage();
            var new_msg = new NetMQMessage();
            // Blocking receive for a message
            msg = pull_socket.ReceiveMultipartMessage();
            // Make sure that splashscreen is disabled
            splashScreen.SetActive(false);

            // Check if this is the latest message
            while (pull_socket.TryReceiveMultipartMessage(ref new_msg))
            {
                ;
            }

            // Check that we got the whole message
            if (new_msg.FrameCount >= msg.FrameCount)
            {
                msg = new_msg;
            }

            if (msg.FrameCount == 0)
            {
                return;
            }

            // Get scene state from LCM
            state = JsonConvert.DeserializeObject <StateMessage_t>(msg[1].ConvertToString());

            // Make sure that all objects are initialized properly
            initializeObjects();
            // Ensure that dynamic object settings such as depth-scaling and color are set correctly.
            updateDynamicObjectSettings();
            // Update position of game objects.
            updateObjectPositions();

            // Mark socket as initialized
            socket_initialized = true;
        }
        else
        {
            // Throttle to 10hz when idle
            Thread.Sleep(100); // [ms]
        }
    }