Exemplo n.º 1
0
        void UpdateFramerate()
        {
            timeleft -= Time.deltaTime;
            accum    += Time.timeScale / Time.deltaTime;
            ++frames;

            // Interval ended - update GUI text and start new interval
            if (timeleft <= 0.0)
            {
                lastFps  = accum / frames;
                timeleft = updateInterval;
                accum    = 0.0F;
                frames   = 0;

                if (lastFps < CognitiveVR.CognitiveVR_Preferences.Instance.LowFramerateThreshold && !lowFramerate)
                {
                    lowFramerate     = true;
                    fpsTransactionID = System.Guid.NewGuid().ToString();
                    Instrumentation.Transaction("performance", fpsTransactionID).setProperty("fps", lastFps).begin();
                    Util.logDebug("low framerate");
                }
                else if (lastFps > CognitiveVR.CognitiveVR_Preferences.Instance.LowFramerateThreshold && lowFramerate)
                {
                    lowFramerate = false;
                    Instrumentation.Transaction("performance", fpsTransactionID).end();
                }
            }
        }
Exemplo n.º 2
0
        void UpdateHMDRotation()
        {
            rotTimeLeft   -= Time.deltaTime;
            accumRotation += Quaternion.Angle(CognitiveVR_Manager.HMD.rotation, lastRotation) / Time.deltaTime;
            lastRotation   = CognitiveVR_Manager.HMD.rotation;
            ++rotFrames;

            // Interval ended - update GUI text and start new interval
            if (rotTimeLeft <= 0.0)
            {
                lastRps       = accumRotation / rotFrames;
                rotTimeLeft   = updateInterval;
                accumRotation = 0.0F;
                rotFrames     = 0;

                Instrumentation.Transaction("comfort", fpsTransactionID)
                .setProperty("fps", lastFps)
                .setProperty("rps", lastRps)
#if CVR_OCULUS
                .setProperty("cpulevel", OVRPlugin.cpuLevel)
                .setProperty("gpulevel", OVRPlugin.gpuLevel)
                .setProperty("powersaving", OVRPlugin.powerSaving)
#endif
                .beginAndEnd();
                Util.logDebug("comfort fps " + lastFps + " rps " + lastRps);
            }
        }
Exemplo n.º 3
0
        private void OnUngripped(object sender, ClickedEventArgs e)
        {
            string transactionID;
            string transactionDescription = "input";

            if (pendingTransactions.TryGetValue(transactionDescription, out transactionID))
            {
                Instrumentation.Transaction(transactionDescription, transactionID).end();
                pendingTransactions.Remove(transactionID);
            }
        }
Exemplo n.º 4
0
        void CognitiveVR_Manager_OnUpdate()
        {
            if (Vector3.SqrMagnitude(lastRootPosition - root.position) > 0.1f)
            {
                Vector3 newPosition = root.position;

                Instrumentation.Transaction("teleport").setProperty("distance", Vector3.Distance(newPosition, lastRootPosition)).beginAndEnd();
                Util.logDebug("teleport");

                lastRootPosition = root.position;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Send telemetry to report the beginning of a transaction, including any state properties which have been set.
        /// </summary>
        /// <param name="timeout">How long to keep the transaction 'open' without new activity</param>
        /// <param name="mode">The type of activity which will keep the transaction open</param>
        public void Send(Vector3 position)
        {
            float[] pos = new float[3] {
                0, 0, 0
            };

            pos[0] = position.x;
            pos[1] = position.y;
            pos[2] = position.z;

            Instrumentation.SendCustomEvent(_category, _properties, pos);
        }
Exemplo n.º 6
0
 void CognitiveVR_Manager_OnPoseEvent(Valve.VR.EVREventType evrevent)
 {
     if (evrevent == Valve.VR.EVREventType.VREvent_TrackedDeviceUserInteractionStarted)
     {
         hmdpresentGUID = System.Guid.NewGuid().ToString();
         Instrumentation.Transaction("HMDPresent", hmdpresentGUID).setProperty("present", true).setProperty("starttime", Time.time).begin();
     }
     if (evrevent == Valve.VR.EVREventType.VREvent_TrackedDeviceUserInteractionEnded)
     {
         Util.logDebug("hmd removed");
         Instrumentation.Transaction("HMDPresent", hmdpresentGUID).setProperty("present", false).setProperty("endtime", Time.time - 10f).end();
     }
 }
Exemplo n.º 7
0
        private void OnPadClicked(object sender, ClickedEventArgs e)
        {
            Transaction padTransaction = Instrumentation.Transaction("input");

            padTransaction.setProperties(new Dictionary <string, object>
            {
                { "type", "pad" },
                { "controllerindex", e.controllerIndex },
                { "x", e.padX },
                { "y", e.padY }
            });
            padTransaction.beginAndEnd();
        }
Exemplo n.º 8
0
        public override void CognitiveVR_Init(Error initError)
        {
            base.CognitiveVR_Init(initError);

#if CVR_OCULUS
            //TODO add oculus audio changed events
            Instrumentation.updateDeviceState(new Dictionary <string, object>()
            {
                { "cvr.vr.headphonespresent", OVRPlugin.headphonesPresent }
            });
#elif CVR_STEAMVR
            //TODO could check SteamVR_Ears if using speaker?
#endif
        }
Exemplo n.º 9
0
        private void CognitiveVR_Manager_TickEvent()
        {
            if (IsVideo) { return; }
            if (WasPlaying)
            {
                if (!VideoPlayer.isPlaying)
                {
                    if (VideoPlayer.frame == 0)
                    {
                        //stopped event
                        Instrumentation.SendCustomEvent("cvr.media.stop", new List<KeyValuePair<string, object>>() {new KeyValuePair<string, object>( "videoTime", lastFrame ), new KeyValuePair<string, object>("mediaId", MediaSource ) },transform.position);
                    }
                    else
                    {
                        //paused event
                        Instrumentation.SendCustomEvent("cvr.media.pause", new List<KeyValuePair<string, object>>() { new KeyValuePair<string, object>("videoTime", VideoPlayer.frame ), new KeyValuePair<string, object>("mediaId", MediaSource ) }, transform.position);
                    }
                    WasPlaying = false;
                }
                lastFrame = VideoPlayer.frame;
            }
            else
            {
                if (VideoPlayer.isPlaying)
                {
                    //play event
                    Instrumentation.SendCustomEvent("cvr.media.play", new List<KeyValuePair<string, object>>() { new KeyValuePair<string, object>("videoTime", VideoPlayer.frame ), new KeyValuePair<string, object>("mediaId", MediaSource ) }, transform.position);
                    WasPlaying = true;
                }
            }
            //register to prepare_complete to see if video has finished buffering
            //how to tell if video starts buffering again?

            if (wasPrepared)
            {
                if (!VideoPlayer.isPrepared) //started buffering. possibly stopped
                {
                    wasPrepared = false;
                    Instrumentation.SendCustomEvent("cvr.media.videoBuffer", new List<KeyValuePair<string, object>>() { new KeyValuePair<string, object>("videoTime", VideoPlayer.frame ), new KeyValuePair<string, object>("mediaId", MediaSource ) }, transform.position);
                }
            }
            else
            {
                if (VideoPlayer.isPrepared) //finishing buffering
                {
                    wasPrepared = true;
                }
            }
        }
Exemplo n.º 10
0
        void OnTriggerClicked(object sender, ClickedEventArgs e)
        {
            string transactionDescription = "input";

            string      transactionID = System.Guid.NewGuid().ToString();
            Transaction inTransaction = Instrumentation.Transaction(transactionDescription, transactionID);

            inTransaction.setProperty("controllerindex", e.controllerIndex).setProperty("type", "trigger");
            inTransaction.begin();

            if (!pendingTransactions.ContainsKey(transactionDescription))
            {
                pendingTransactions.Add(transactionDescription, transactionID);
            }
        }
Exemplo n.º 11
0
        public override void CognitiveVR_Init(Error initError)
        {
            base.CognitiveVR_Init(initError);

#if CVR_STEAMVR
            CognitiveVR_Manager.OnPoseEvent += CognitiveVR_Manager_PoseEventHandler;


            if (Valve.VR.OpenVR.Chaperone.AreBoundsVisible())
            {
                chaperoneGUID = System.Guid.NewGuid().ToString();
                Instrumentation.Transaction("chaperone", chaperoneGUID).begin();
                Util.logDebug("chaperone visible");
            }
#endif
        }
Exemplo n.º 12
0
 void CognitiveVR_Manager_PoseEventHandler(Valve.VR.EVREventType evrevent)
 {
     if (evrevent == Valve.VR.EVREventType.VREvent_ChaperoneDataHasChanged)
     {
         if (Valve.VR.OpenVR.Chaperone.AreBoundsVisible())
         {
             chaperoneGUID = System.Guid.NewGuid().ToString();
             Instrumentation.Transaction("chaperone", chaperoneGUID).begin();
             Util.logDebug("chaperone visible");
         }
         else
         {
             Instrumentation.Transaction("chaperone", chaperoneGUID).end();
         }
     }
 }
Exemplo n.º 13
0
 private void CognitiveVR_Manager_OnTick()
 {
     if (samples < sampleCount)
     {
         hmdAccumHeight += CognitiveVR_Manager.HMD.position.y;
         samples++;
         if (samples >= sampleCount)
         {
             float averageHeight = hmdAccumHeight / samples;
             Util.logDebug("head height " + averageHeight);
             Instrumentation.updateUserState(new Dictionary <string, object> {
                 { "height", averageHeight }
             });
             CognitiveVR_Manager.OnTick -= CognitiveVR_Manager_OnTick;
         }
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Send telemetry to report the beginning of a transaction, including any state properties which have been set.
        /// </summary>
        /// <param name="timeout">How long to keep the transaction 'open' without new activity</param>
        /// <param name="mode">The type of activity which will keep the transaction open</param>
        public void Send()
        {
            if (HMD == null)
            {
                return;
            }

            float[] pos = new float[3] {
                0, 0, 0
            };

            pos[0] = HMD.position.x;
            pos[1] = HMD.position.y;
            pos[2] = HMD.position.z;

            Instrumentation.SendCustomEvent(_category, _properties, pos);
        }
Exemplo n.º 15
0
 private void CognitiveVR_Manager_OnTick()
 {
     if (CognitiveVR_Manager.HMD != null)
     {
         bool hit = Physics.CheckSphere(CognitiveVR_Manager.HMD.position, 0.25f, CognitiveVR_Preferences.Instance.CollisionLayerMask);
         if (hit && string.IsNullOrEmpty(HMDGuid))
         {
             Util.logDebug("hmd collision");
             HMDGuid = System.Guid.NewGuid().ToString();
             Instrumentation.Transaction("collision", HMDGuid).setProperty("device", "HMD").begin();
         }
         else if (!hit && !string.IsNullOrEmpty(HMDGuid))
         {
             Instrumentation.Transaction("collision", HMDGuid).end();
             HMDGuid = string.Empty;
         }
     }
 }
Exemplo n.º 16
0
        void SendBatteryLevel()
        {
#if CVR_OCULUS
            Util.logDebug("batterylevel " + OVRPlugin.batteryLevel);
            Instrumentation.Transaction("battery")
            .setProperty("batterylevel", OVRPlugin.batteryLevel)
            .setProperty("batterytemperature", OVRPlugin.batteryTemperature)
            .setProperty("batterystatus", OVRPlugin.batteryStatus)
            .beginAndEnd();
#else
            if (GetBatteryLevel())
            {
                Util.logDebug("batterylevel " + batteryLevel);

                Instrumentation.Transaction("battery").setProperty("batterylevel", batteryLevel).beginAndEnd();
            }
#endif
        }
Exemplo n.º 17
0
        /// <summary>
        /// Send telemetry to report the beginning of a transaction, including any state properties which have been set.
        /// </summary>
        /// <param name="timeout">How long to keep the transaction 'open' without new activity</param>
        /// <param name="mode">The type of activity which will keep the transaction open</param>
        public void Send(Vector3 position)
        {
            float[] pos = new float[3] {
                0, 0, 0
            };

            pos[0] = position.x;
            pos[1] = position.y;
            pos[2] = position.z;

            float duration = Time.realtimeSinceStartup - startTime;

            if (duration > 0.011f)
            {
                SetProperty("duration", duration);
            }

            Instrumentation.SendCustomEvent(category, _properties, pos, dynamicObjectId);
        }
Exemplo n.º 18
0
        public void SendIssue(string title, string description = null, string repro = null)
        {
            if (string.IsNullOrEmpty(title))
            {
                return;
            }

            Transaction t = Instrumentation.Transaction("Issue").setProperty("Title", title);

            if (!string.IsNullOrEmpty(description))
            {
                t.setProperty("Description", description);
            }
            if (!string.IsNullOrEmpty(repro))
            {
                t.setProperty("Reproduction", repro);
            }
            t.beginAndEnd();

            //TODO integrate with JIRA rest api
        }
Exemplo n.º 19
0
        private void CognitiveVR_Manager_OnTick()
        {
            if (CognitiveVR_Manager.GetController(0) == null)
            {
                return;
            }

            if (samples < sampleCount)
            {
                maxSqrDistance = Mathf.Max(Vector3.SqrMagnitude(CognitiveVR_Manager.GetController(0).position - CognitiveVR_Manager.HMD.position));

                samples++;
                if (samples >= sampleCount)
                {
                    Util.logDebug("arm length " + maxSqrDistance);
                    Instrumentation.updateUserState(new Dictionary <string, object> {
                        { "armlength", Mathf.Sqrt(maxSqrDistance) }
                    });
                    CognitiveVR_Manager.OnTick -= CognitiveVR_Manager_OnTick;
                }
            }
        }
Exemplo n.º 20
0
        public override void CognitiveVR_Init(Error initError)
        {
            base.CognitiveVR_Init(initError);

#if CVR_STEAMVR
            float roomX = 0;
            float roomY = 0;
            if (Valve.VR.OpenVR.Chaperone == null || !Valve.VR.OpenVR.Chaperone.GetPlayAreaSize(ref roomX, ref roomY))
            {
                Instrumentation.updateDeviceState(new Dictionary <string, object>()
                {
                    { "cvr.vr.roomsize", "0 x 0" }, { "cvr.vr.roomscale", false }
                });
            }
            else
            {
                bool seated = Mathf.Approximately(roomX, 1f) && roomX == roomY;
                Instrumentation.updateDeviceState(new Dictionary <string, object>()
                {
                    { "cvr.vr.roomsize", string.Format("{0:0.0} x {1:0.0}", roomX, roomY) },
                    { "cvr.vr.roomscale", !seated }
                });
            }
#elif CVR_OCULUS
            if (OVRManager.tracker.isPresent)
            {
                Instrumentation.updateDeviceState(new Dictionary <string, object>()
                {
                    { "cvr.vr.frustrumFOV", OVRManager.tracker.GetFrustum().fov },
                    { "cvr.vr.frustrumNear", OVRManager.tracker.GetFrustum().nearZ },
                    { "cvr.vr.frustrumFar", OVRManager.tracker.GetFrustum().farZ }
                });
            }
            else
            {
                Util.logDebug("OVRManager tracker is not present!");
            }
#endif
        }
        private void CognitiveVR_Manager_OnTick()
        {
            bool hit;

            if (CognitiveVR_Manager.GetController(0) != null)
            {
                hit = Physics.CheckSphere(CognitiveVR_Manager.GetController(0).position, 0.25f, CognitiveVR_Preferences.Instance.CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller0GUID))
                {
                    Util.logDebug("controller collision");
                    controller0GUID = System.Guid.NewGuid().ToString();
                    Instrumentation.Transaction("collision", controller0GUID).setProperty("device", "controller 0").begin();
                }
                else if (!hit && !string.IsNullOrEmpty(controller0GUID))
                {
                    Instrumentation.Transaction("collision", controller0GUID).end();
                    controller0GUID = string.Empty;
                }
            }

            if (CognitiveVR_Manager.GetController(1) != null)
            {
                hit = Physics.CheckSphere(CognitiveVR_Manager.GetController(1).position, 0.25f, CognitiveVR_Preferences.Instance.CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller1GUID))
                {
                    Util.logDebug("controller collision");
                    controller1GUID = System.Guid.NewGuid().ToString();
                    Instrumentation.Transaction("collision", controller1GUID).setProperty("device", "controller 1").begin();
                }
                else if (!hit && !string.IsNullOrEmpty(controller1GUID))
                {
                    Instrumentation.Transaction("collision", controller1GUID).end();
                    controller1GUID = string.Empty;
                }
            }
        }
Exemplo n.º 22
0
 public void begin(double timeout = 0, TimeoutMode mode = TimeoutMode.Transaction)
 {
     Instrumentation.SendCustomEvent(_category, _properties, HMD.position);
 }
Exemplo n.º 23
0
 public void beginAndEnd(Vector3 position, string result = TXN_SUCCESS)
 {
     Instrumentation.SendCustomEvent(_category, _properties, position);
 }
Exemplo n.º 24
0
        public void Initialize(string userName = "", Dictionary <string, object> userProperties = null)
        {
            Util.logDebug("CognitiveVR_Manager Initialize");
            if (instance != null && instance != this)
            {
                Util.logDebug("CognitiveVR_Manager Initialize instance is not null and not this! Destroy");
                Destroy(gameObject);
                return;
            } //destroy if there's already another manager
            if (instance == this && Core.Initialized)
            {
                Util.logDebug("CognitiveVR_Manager Initialize instance is this! <color=red>Skip Initialize</color>");
                return;
            } //skip if this manage has already been initialized

            if (!CognitiveVR_Preferences.Instance.IsAPIKeyValid)
            {
                Util.logDebug("CognitiveVR_Manager Initialize does not have valid apikey");
                return;
            }
            if (OutstandingInitRequest)
            {
                Util.logDebug("CognitiveVR_Manager Initialize already called. Waiting for response");
                return;
            }

            OutstandingInitRequest = true;

            //string sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;

            //Core.SetTrackingScene(sceneName);

            Instrumentation.SetMaxTransactions(CognitiveVR_Preferences.S_TransactionSnapshotCount);

            playerSnapshotInverval = new WaitForSeconds(CognitiveVR.CognitiveVR_Preferences.S_SnapshotInterval);
            GPSUpdateInverval      = new WaitForSeconds(CognitiveVR_Preferences.Instance.GPSInterval);
            StartCoroutine(Tick());

#if CVR_STEAMVR
            SteamVR_Events.NewPoses.AddListener(OnPoseUpdate); //steamvr 1.2
            //SteamVR_Utils.Event.Listen("new_poses", OnPoseUpdate); //steamvr 1.1
#endif

            UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_SceneLoaded;
            SceneManager_SceneLoaded(UnityEngine.SceneManagement.SceneManager.GetActiveScene(), UnityEngine.SceneManagement.LoadSceneMode.Single);

            Core.UserId = userName;

            CognitiveVR.Core.init(OnInit); //TODO return errors from init method, not callback since there isn't a delay on startup
            UpdateSessionState(Util.GetDeviceProperties() as Dictionary <string, object>);

#if UNITY_2017_2_OR_NEWER
            UpdateSessionState("cvr.vr.enabled", UnityEngine.XR.XRSettings.enabled);
            UpdateSessionState("cvr.vr.display.model", UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRDevice.isPresent ? UnityEngine.XR.XRDevice.model : "Not Found");               //vive mvt, vive. mv, oculus rift cv1, acer ah100
            UpdateSessionState("cvr.vr.display.family", UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRDevice.isPresent ? UnityEngine.XR.XRSettings.loadedDeviceName : "Not Found"); //openvr, oculus, windowsmr
#else
            UpdateSessionState("cvr.vr.enabled", UnityEngine.VR.VRSettings.enabled);
            UpdateSessionState("cvr.vr.display.model", UnityEngine.VR.VRSettings.enabled && UnityEngine.VR.VRDevice.isPresent ? UnityEngine.VR.VRDevice.model : "Not Found");
            UpdateSessionState("cvr.vr.display.family", UnityEngine.VR.VRSettings.enabled && UnityEngine.VR.VRDevice.isPresent ? UnityEngine.VR.VRSettings.loadedDeviceName : "Not Found");
#endif


            UpdateSessionState("cvr.deviceId", Core.DeviceId);
            UpdateSessionState(userProperties);
            UpdateSessionState("cvr.name", userName);

            CognitiveVR.NetworkManager.InitLocalStorage(System.Environment.NewLine);
        }
Exemplo n.º 25
0
 private void OVRManager_TrackingLost()
 {
     Instrumentation.Transaction("Tracking", hmdGUID).setProperty("Device", "HMD").setProperty("visible", false).end();
     hmdGUID = string.Empty;
 }
Exemplo n.º 26
0
 private void OVRManager_HMDUnmounted()
 {
     Instrumentation.Transaction("HMDPresent", hmdpresentGUID).setProperty("present", false).setProperty("endtime", Time.time).end();
 }
Exemplo n.º 27
0
 private void RecenterEventTracker_RecenteredPose()
 {
     Instrumentation.Transaction("Recenter").beginAndEnd();
 }
Exemplo n.º 28
0
 private void OVRManager_TrackingAcquired()
 {
     hmdGUID = System.Guid.NewGuid().ToString();
     Instrumentation.Transaction("Tracking", hmdGUID).setProperty("Device", "HMD").setProperty("visible", true).begin();
 }
Exemplo n.º 29
0
 private void OVRManager_HMDMounted()
 {
     hmdpresentGUID = System.Guid.NewGuid().ToString();
     Instrumentation.Transaction("HMDPresent", hmdpresentGUID).setProperty("present", true).setProperty("starttime", Time.time).begin();
 }
Exemplo n.º 30
0
        private void CognitiveVR_Manager_PoseUpdateHandler(params object[] args)
        {
            var poses = (Valve.VR.TrackedDevicePose_t[])args[0];

            for (int i = 0; i < 16; i++)
            {
                if (poses.Length <= i)
                {
                    break;
                }

                if (poses[i].bDeviceIsConnected && poses[i].bPoseIsValid)
                {
                    bool foundMatchingDevice = false;
                    for (int j = 0; j < Devices.Count; j++)
                    {
                        if (Devices[j].deviceID == i)
                        {
                            foundMatchingDevice = true; break;
                        }
                    }
                    if (!foundMatchingDevice)
                    {
                        Devices.Add(new TrackedDevice()
                        {
                            deviceID = i
                        });
                    }
                }
            }

            for (int j = 0; j < Devices.Count; j++)
            {
                if (!poses[Devices[j].deviceID].bPoseIsValid)
                {
                    if (Devices[j].ValidTransID == string.Empty)
                    {
                        Devices[j].ValidTransID = System.Guid.NewGuid().ToString();
                        Instrumentation.Transaction("Tracking", Devices[j].ValidTransID).setProperty("deviceID", Devices[j].deviceID).setProperty("visible", false).begin();
                    }
                }
                else if (Devices[j].ValidTransID != string.Empty)
                {
                    Instrumentation.Transaction("Tracking", Devices[j].ValidTransID).setProperty("deviceID", Devices[j].deviceID).setProperty("visible", true).end();
                    Devices[j].ValidTransID = string.Empty;
                }

                if (!poses[Devices[j].deviceID].bDeviceIsConnected)
                {
                    if (Devices[j].ValidTransID == string.Empty)
                    {
                        Devices[j].ConnectedTransID = System.Guid.NewGuid().ToString();
                        Instrumentation.Transaction("Tracking", Devices[j].ConnectedTransID).setProperty("deviceID", Devices[j].deviceID).setProperty("connected", false).begin();
                    }
                }
                else if (Devices[j].ConnectedTransID != string.Empty)
                {
                    Instrumentation.Transaction("Tracking", Devices[j].ConnectedTransID).setProperty("deviceID", Devices[j].deviceID).setProperty("connected", true).end();
                    Devices[j].ConnectedTransID = string.Empty;
                }
            }
        }