Example #1
0
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="connectionID">The id of the device that connected</param>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(int connectionID, byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        RPCSerializer   rpcData   = (RPCSerializer)formatter.Deserialize(stream);

        int        playerID = -1;
        NaviDevice dev      = null;

        for (int i = 0; i < playerConnectionIds.Count; i++)
        {
            if (playerConnectionIds[i].connectionID == connectionID)
            {
                playerID = i;
                dev      = playerConnectionIds[i];
                break;
            }
        }

        if (rpcData.methodName.Equals(TOUCH_METHOD_ID))
        {
            TouchSerializer ts = (TouchSerializer)rpcData.args [0];
            TouchManager.ProcessTouch(playerID, ts);
        }
        else if (rpcData.methodName.Equals(SET_SIZE_METHOD_ID))
        {
            dev.SetServerScreenSize((int)rpcData.args[0], (int)rpcData.args[1]);
        }
    }
    /// <summary>
    /// A static method that takes the network data and dispatches events based on what was inputted on the smart device
    /// </summary>
    /// <param name="ts">The data from the smart device, which has been parsed into a TouchSerializer already</param>
    public static void ProcessTouch(TouchSerializer ts)
    {
        TouchEvent touchType = TouchPhaseLookup(ts.phase);
        if (touchType != null) {
            touchType(ts.fingerID, ts.position);
        }

        if (OnDoubleTap != null && ts.tapCount == 2 && touchType == OnTouchUp) {
            OnDoubleTap (ts.fingerID, ts.position);
        }

        if (OnTripleTap != null && ts.tapCount == 3 && touchType == OnTouchUp) {
            OnTripleTap (ts.fingerID, ts.position);
        }
    }
Example #3
0
    /// <summary>
    /// Method to parse and send an RPC event from smart device such as recieving touch input
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandleRPC(byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        RPCSerializer   rpcData   = (RPCSerializer)formatter.Deserialize(stream);

        if (rpcData.methodName.Equals(TOUCH_METHOD_ID))
        {
            TouchSerializer ts = (TouchSerializer)rpcData.args [0];
            TouchManager.ProcessTouch(ts);
        }
        else if (rpcData.methodName.Equals(SET_SIZE_METHOD_ID))
        {
            TouchManager.Instance.SetServerScreenSize((int)rpcData.args[0], (int)rpcData.args[1]);
        }
    }
Example #4
0
    /// <summary>
    /// A static method that takes the network data and dispatches events based on what was inputted on the smart device
    /// </summary>
    /// <param name="playerID">The device the touch input is coming from</param>
    /// <param name="ts">The data from the smart device, which has been parsed into a TouchSerializer already</param>
    public static void ProcessTouch(int playerID, TouchSerializer ts)
    {
        TouchEvent touchType = TouchPhaseLookup(ts.phase);

        if (touchType != null)
        {
            touchType(playerID, ts.fingerID, ts.position);
        }

        if (OnDoubleTap != null && ts.tapCount == 2 && touchType == OnTouchUp)
        {
            OnDoubleTap(playerID, ts.fingerID, ts.position);
        }

        if (OnTripleTap != null && ts.tapCount == 3 && touchType == OnTouchUp)
        {
            OnTripleTap(playerID, ts.fingerID, ts.position);
        }
    }
Example #5
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;

        byte[]           recBuffer  = new byte[MAX_RECIEVE_SIZE];
        int              bufferSize = MAX_RECIEVE_SIZE;
        int              dataSize;
        byte             error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);

        Array.Resize <byte> (ref recBuffer, dataSize);        //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;

        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId)
            {
                HandleRPC(recBuffer);
            }
            else if (channelId == myReliableFramentedChannelId)
            {
                HandleBigRPC(recBuffer);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;

        default:         //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0)           //we are connected to a device
        {
            byte[]          buffer              = new byte[BUFFER_SIZE];
            Stream          stream              = new MemoryStream(buffer);
            BinaryFormatter formatter           = new BinaryFormatter();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error);              //send full buffer

            foreach (Touch t in Input.touches)
            {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args       = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args [0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText();

            if (Screen.orientation != prevOrientation)
            {
                SendCurrentSize();
                prevOrientation = Screen.orientation;
            }
        }
    }
Example #6
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;
        byte[] recBuffer = new byte[MAX_RECIEVE_SIZE];
        int bufferSize = MAX_RECIEVE_SIZE;
        int dataSize;
        byte error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
        Array.Resize<byte> (ref recBuffer, dataSize); //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;
        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId) {
                HandleRPC (recBuffer);
            } else if (channelId == myReliableFramentedChannelId) {
                HandleBigRPC (recBuffer);
            }

            break;
        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;
        default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0) { //we are connected to a device
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream (buffer);
            BinaryFormatter formatter = new BinaryFormatter ();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration ();
            pose.Fill (TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize (stream, pose);
            NetworkTransport.Send (socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer

            foreach (Touch t in Input.touches) {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream (buffer);

                RPCSerializer rpc = new RPCSerializer ();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args = new object[1];
                TouchSerializer ts = new TouchSerializer ();
                ts.Fill (t);
                rpc.args [0] = ts;
                formatter.Serialize (stream, rpc);
                NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText ();

            if (Screen.orientation != prevOrientation) {
                SendCurrentSize ();
                prevOrientation = Screen.orientation;
            }
        }
    }
Example #7
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;
        byte[] recBuffer = new byte[1024];
        int bufferSize = 1024;
        int dataSize;
        byte error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
        switch (recData)
        {
        case NetworkEventType.DataEvent:
            if (!naviPoseAssigned || !touchConnectionAssigned) {
                Stream stream = new MemoryStream(recBuffer);
                BinaryFormatter formatter = new BinaryFormatter();
                string message = formatter.Deserialize(stream) as string;
                AssignID(connectionId, message);
            }

            break;
        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;
        default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviPoseConnectionID > 0) {
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();
            PoseSerializer pose = new PoseSerializer();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer
        }

        if (touchConnectionID > 0) {
            BinaryFormatter formatter = new BinaryFormatter();
            foreach (Touch t in Input.touches){
                byte[] buffer = new byte[BUFFER_SIZE];
                Stream stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args[0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }
        }
    }
Example #8
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;

        byte[]           recBuffer  = new byte[1024];
        int              bufferSize = 1024;
        int              dataSize;
        byte             error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);

        switch (recData)
        {
        case NetworkEventType.DataEvent:
            if (!naviPoseAssigned || !touchConnectionAssigned)
            {
                Stream          stream    = new MemoryStream(recBuffer);
                BinaryFormatter formatter = new BinaryFormatter();
                string          message   = formatter.Deserialize(stream) as string;
                AssignID(connectionId, message);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;

        default:         //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviPoseConnectionID > 0)
        {
            byte[]          buffer    = new byte[BUFFER_SIZE];
            Stream          stream    = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();
            PoseSerializer  pose      = new PoseSerializer();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviPoseConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error);             //send full buffer
        }


        if (touchConnectionID > 0)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            foreach (Touch t in Input.touches)
            {
                byte[] buffer = new byte[BUFFER_SIZE];
                Stream stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args       = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args[0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, touchConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }
        }
    }