Пример #1
0
    void AttachToHand(ref HandData hand, GameObject gameObject)
    {
        NetworkInfo networkInfo = gameObject.GetComponent <NetworkInfo>();

        networkInfo.AttachCubeToLocalPlayer(this, hand);

#if DEBUG_AUTHORITY
        Debug.Log("client " + context.GetClientIndex() + " grabbed cube " + networkInfo.GetCubeId() + " and set ownership sequence to " + networkInfo.GetOwnershipSequence());
#endif // #if DEBUG_AUTHORITY

        if (!context.IsServer())
        {
            networkInfo.ClearConfirmed();
        }
        else
        {
            networkInfo.SetConfirmed();
        }

        for (int i = 0; i < ThrowRingBufferSize; ++i)
        {
            hand.throwRingBufferEntries[i].valid = false;
            hand.throwRingBufferEntries[i].speed = 0.0f;
        }
    }
    public void RecurseSupportObjects(GameObject gameObject, ref HashSet <GameObject> support)
    {
        if (support.Contains(gameObject))
        {
            return;
        }

        support.Add(gameObject);

        NetworkInfo networkInfo = gameObject.GetComponent <NetworkInfo>();

        int cubeId = networkInfo.GetCubeId();

        Interactions.Entry entry = interactions.GetInteractions(cubeId);

        for (int i = 0; i < Constants.NumCubes; ++i)
        {
            if (entry.interactions[i] == 0)
            {
                continue;
            }

            if (cubes[i].layer != layer)
            {
                continue;
            }

            if (cubes[i].transform.position.y < gameObject.transform.position.y + Constants.SupportHeightThreshold)
            {
                continue;
            }

            RecurseSupportObjects(cubes[i], ref support);
        }
    }
    void UpdatePendingCommit(NetworkInfo networkInfo, int authorityIndex, int fromClientIndex, int toClientIndex)
    {
        if (networkInfo.IsPendingCommit() && authorityIndex != toClientIndex + 1)
        {
#if DEBUG_AUTHORITY
            Debug.Log("client " + toClientIndex + " sees update for cube " + networkInfo.GetCubeId() + " from client " + fromClientIndex + " with authority index (" + authorityIndex + ") and clears pending commit flag");
#endif // #if DEBUG_AUTHORITY
            networkInfo.ClearPendingCommit();
        }
    }
Пример #4
0
    void DetachFromHand(ref HandData hand)
    {
        // IMPORTANT: This happens when passing a cube from hand-to-hand
        if (hand.gripObject == null)
        {
            return;
        }

        NetworkInfo networkInfo = hand.gripObject.GetComponent <NetworkInfo>();

        networkInfo.DetachCubeFromPlayer();

#if DEBUG_AUTHORITY
        Debug.Log("client " + context.GetClientIndex() + " released cube " + networkInfo.GetCubeId() + ". ownership sequence is " + networkInfo.GetOwnershipSequence() + ", authority sequence is " + networkInfo.GetAuthoritySequence());
#endif // #if DEBUG_AUTHORITY
    }
Пример #5
0
    /*
     * Collision Callback.
     * This is used to call into the collision callback on the context that owns these cubes,
     * which is used to track authority transfer (poorly), and to increase network priority
     * for cubes that were recently in high energy collisions with other cubes, or the floor.
     */

    void OnCollisionEnter(Collision collision)
    {
        GameObject gameObject2 = collision.gameObject;

        NetworkInfo networkInfo2 = gameObject2.GetComponent <NetworkInfo>();

        int cubeId1 = m_cubeId;
        int cubeId2 = -1;                   // IMPORTANT: cube id of -1 represents a collision with the floor

        if (networkInfo2 != null)
        {
            cubeId2 = networkInfo2.GetCubeId();
        }

        m_context.CollisionCallback(cubeId1, cubeId2, collision);
    }
    public void TakeAuthorityOverObject(NetworkInfo networkInfo)
    {
        Assert.IsTrue(networkInfo.GetAuthorityIndex() == 0);
#if DEBUG_AUTHORITY
        Debug.Log("client " + clientIndex + " took authority over cube " + networkInfo.GetCubeId());
#endif // #if DEBUG_AUTHORITY
        networkInfo.SetAuthorityIndex(authorityIndex);
        networkInfo.IncreaseAuthoritySequence();
        if (!IsServer())
        {
            networkInfo.ClearConfirmed();
        }
        else
        {
            networkInfo.SetConfirmed();
        }
    }
Пример #7
0
    public static void Initialize(out AvatarState state, int clientIndex, OvrAvatarDriver.PoseFrame frame, GameObject leftHandHeldObject, GameObject rightHandHeldObject)
    {
        state.client_index = clientIndex;

        state.head_position = frame.headPosition;
        state.head_rotation = frame.headRotation;

        state.left_hand_position   = frame.handLeftPosition;
        state.left_hand_rotation   = frame.handLeftRotation;
        state.left_hand_grip_flex  = frame.handLeftPose.gripFlex;
        state.left_hand_index_flex = frame.handLeftPose.indexFlex;
        state.left_hand_pointing   = frame.handLeftPose.isPointing;
        state.left_hand_thumbs_up  = frame.handLeftPose.isThumbUp;

        if (leftHandHeldObject)
        {
            state.left_hand_holding_cube = true;

            NetworkInfo networkInfo = leftHandHeldObject.GetComponent <NetworkInfo>();

            state.left_hand_cube_id             = networkInfo.GetCubeId();
            state.left_hand_authority_sequence  = networkInfo.GetAuthoritySequence();
            state.left_hand_ownership_sequence  = networkInfo.GetOwnershipSequence();
            state.left_hand_cube_local_position = leftHandHeldObject.transform.localPosition;
            state.left_hand_cube_local_rotation = leftHandHeldObject.transform.localRotation;
        }
        else
        {
            state.left_hand_holding_cube        = false;
            state.left_hand_cube_id             = -1;
            state.left_hand_authority_sequence  = 0;
            state.left_hand_ownership_sequence  = 0;
            state.left_hand_cube_local_position = Vector3.zero;
            state.left_hand_cube_local_rotation = Quaternion.identity;
        }

        state.right_hand_position   = frame.handRightPosition;
        state.right_hand_rotation   = frame.handRightRotation;
        state.right_hand_grip_flex  = frame.handRightPose.gripFlex;
        state.right_hand_index_flex = frame.handRightPose.indexFlex;
        state.right_hand_pointing   = frame.handRightPose.isPointing;
        state.right_hand_thumbs_up  = frame.handRightPose.isThumbUp;

        if (rightHandHeldObject)
        {
            state.right_hand_holding_cube = true;

            NetworkInfo networkInfo = rightHandHeldObject.GetComponent <NetworkInfo>();

            state.right_hand_cube_id             = networkInfo.GetCubeId();
            state.right_hand_authority_sequence  = networkInfo.GetAuthoritySequence();
            state.right_hand_ownership_sequence  = networkInfo.GetOwnershipSequence();
            state.right_hand_cube_local_position = rightHandHeldObject.transform.localPosition;
            state.right_hand_cube_local_rotation = rightHandHeldObject.transform.localRotation;
        }
        else
        {
            state.right_hand_holding_cube        = false;
            state.right_hand_cube_id             = -1;
            state.right_hand_authority_sequence  = 0;
            state.right_hand_ownership_sequence  = 0;
            state.right_hand_cube_local_position = Vector3.zero;
            state.right_hand_cube_local_rotation = Quaternion.identity;
        }

        state.voice_amplitude = frame.voiceAmplitude;
    }