示例#1
0
        public void SynchronizeSwapBuffersAcrossAllNodes()
        {
            // 1. send a swap_buffers_request message to the server
            VRNet.SendSwapBuffersRequest(ref client);

            // 2. wait for and receive a swap_buffers_now message from the server
            VRNet.ReceiveSwapBuffersNow(ref client);
        }
示例#2
0
        public void SynchronizeInputEventsAcrossAllNodes(ref List <VREvent> inputEvents)
        {
            // 1. send inputEvents to server
            VRNet.SendEventData(ref client, /*in*/ inputEvents);

            // 2. receive and parse serverInputEvents
            List <VREvent> serverInputEvents = new List <VREvent>();

            VRNet.ReceiveEventData(ref client, ref serverInputEvents);

            // 3. inputEvents = serverInputEvents
            inputEvents = serverInputEvents;
        }
示例#3
0
        public void SynchronizeInputEventsAcrossAllNodes(ref List <VREvent> inputEvents)
        {
            // 1. FOR EACH CLIENT, RECEIVE A LIST OF INPUT EVENTS GENERATED ON THE CLIENT
            // AND ADD THEM TO THE SERVER'S INPUTEVENTS LIST

            // the following section implements something similar to a socket select statement.
            // we need to receive data from all clients, but socket 4 may be ready to send data
            // before socket 1, so we loop through the sockets reading from the first we find
            // that is ready to send data, then continue looping until we have read from all.

            // initialize list to include all streams in the list to read from
            List <int> toRead = new List <int>(clients.Count);

            for (int i = 0; i < clients.Count; i++)
            {
                toRead.Add(i);
            }

            // loop until the list of streams to read from is empty
            while (toRead.Count > 0)
            {
                int i = 0;
                while (i < toRead.Count)
                {
                    if (clients[toRead[i]].GetStream().DataAvailable)
                    {
                        // if ready to read, read data and remove from the list of streams to read from
                        TcpClient c = clients[toRead[i]];
                        VRNet.ReceiveEventData(ref c, ref inputEvents);
                        toRead.RemoveAt(i);
                    }
                    else
                    {
                        // this stream not ready to read, move on to the next
                        i++;
                    }
                }
            }


            // 2. SEND THE COMBINED INPUT EVENTS LIST OUT TO ALL CLIENTS
            for (int i = 0; i < clients.Count; i++)
            {
                TcpClient c = clients[i];
                VRNet.SendEventData(ref c, /*in*/ inputEvents);
            }
        }
示例#4
0
        public void SynchronizeSwapBuffersAcrossAllNodes()
        {
            // 1. WAIT FOR A SWAP BUFFERS REQUEST MESSAGE FROM ALL CLIENTS

            // the following section implements something similar to a socket select statement.
            // we need to receive data from all clients, but socket 4 may be ready to send data
            // before socket 1, so we loop through the sockets reading from the first we find
            // that is ready to send data, then continue looping until we have read from all.

            // initialize list to include all streams in the list to read from
            List <int> toRead = new List <int>(clients.Count);

            for (int i = 0; i < clients.Count; i++)
            {
                toRead.Add(i);
            }

            // loop until the list of streams to read from is empty
            while (toRead.Count > 0)
            {
                int i = 0;
                while (i < toRead.Count)
                {
                    if (clients[toRead[i]].GetStream().DataAvailable)
                    {
                        // if ready to read, read data and remove from the list of streams to read from
                        TcpClient c = clients[toRead[i]];
                        VRNet.ReceiveSwapBuffersRequest(ref c);
                        toRead.RemoveAt(i);
                    }
                    else
                    {
                        // this stream not ready to read, move on to the next
                        i++;
                    }
                }
            }


            // 2. SEND A SWAP BUFFERS NOW MESSAGE TO ALL CLIENTS
            for (int i = 0; i < clients.Count; i++)
            {
                TcpClient c = clients[i];
                VRNet.SendSwapBuffersNow(ref c);
            }
        }