Beispiel #1
0
    void Update()
    {
        if (text != null)
        {
            if (Input.GetKeyDown(KeyCode.I))
            {
                text.enabled = !text.enabled;
            }

            if (text.enabled)
            {
                var compositor = OpenVR.Compositor;
                if (compositor != null)
                {
                    var timing = new Compositor_FrameTiming();
                    timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
                    compositor.GetFrameTiming(ref timing, 0);

                    var update = timing.m_flSystemTimeInSeconds;
                    if (update > lastUpdate)
                    {
                        var framerate = (lastUpdate > 0.0f) ? 1.0f / (update - lastUpdate) : 0.0f;
                        lastUpdate = update;
                        text.text  = string.Format("framerate: {0:N0}\ndropped frames: {1}", framerate, (int)timing.m_nNumDroppedFrames);
                    }
                    else
                    {
                        lastUpdate = update;
                    }
                }
            }
        }
    }
Beispiel #2
0
 // Token: 0x06005F92 RID: 24466 RVA: 0x00219C10 File Offset: 0x00218010
 private void Update()
 {
     if (this.text != null)
     {
         if (Input.GetKeyDown(KeyCode.I))
         {
             this.text.enabled = !this.text.enabled;
         }
         if (this.text.enabled)
         {
             CVRCompositor compositor = OpenVR.Compositor;
             if (compositor != null)
             {
                 Compositor_FrameTiming compositor_FrameTiming = default(Compositor_FrameTiming);
                 compositor_FrameTiming.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                 compositor.GetFrameTiming(ref compositor_FrameTiming, 0u);
                 double flSystemTimeInSeconds = compositor_FrameTiming.m_flSystemTimeInSeconds;
                 if (flSystemTimeInSeconds > this.lastUpdate)
                 {
                     double num = (this.lastUpdate <= 0.0) ? 0.0 : (1.0 / (flSystemTimeInSeconds - this.lastUpdate));
                     this.lastUpdate = flSystemTimeInSeconds;
                     this.text.text  = string.Format("framerate: {0:N0}\ndropped frames: {1}", num, (int)compositor_FrameTiming.m_nNumDroppedFrames);
                 }
                 else
                 {
                     this.lastUpdate = flSystemTimeInSeconds;
                 }
             }
         }
     }
 }
Beispiel #3
0
    public static Compositor_FrameTiming GetFrameTiming(this CVRCompositor compositor, uint unFramesAgo)
    {
        Compositor_FrameTiming pTiming = default(Compositor_FrameTiming);

        pTiming.m_nSize = FRAMETIMING_SIZE;
        OpenVR.Compositor.GetFrameTiming(ref pTiming, unFramesAgo);
        return(pTiming);
    }
Beispiel #4
0
 public static bool GetFrameTiming(ref Compositor_FrameTiming pTiming, uint unFramesAgo)
 {
     pTiming.m_nSize = (uint)Marshal.SizeOf(pTiming);
     if (m_vrCompositor != null)
     {
         return(m_vrCompositor.GetFrameTiming(ref pTiming, unFramesAgo));
     }
     return(false);
 }
Beispiel #5
0
        private async void StartPacemaker()
        {
            Compositor_FrameTiming cft = new Compositor_FrameTiming();

            cft.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));

            await Task.Run(() =>
            {
                while (true)
                {
                    Thread.Sleep(100); // This sucks but will do for now
                    OpenVR.Compositor.GetFrameTiming(ref cft, 0);
                    //Console.WriteLine(cft.m_flTotalRenderGpuMs);
                }
            });
        }
    void SetTiming()
    {
        var timing = new Compositor_FrameTiming();

        timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
        compositor.GetFrameTiming(ref timing, 0);

        var update = timing.m_flSystemTimeInSeconds;

        if (update > lastUpdate)
        {
            var framerate        = (lastUpdate > 0.0f) ? 1.0f / (update - lastUpdate) : 0.0f;
            int numFramesDropped = (int)timing.m_nNumDroppedFrames;
            lastUpdate = update;
            text.text  = string.Format("FPS: {0:N0}\nDropped: {1}", framerate, numFramesDropped);
            ColorizeText(framerate);
        }
        else
        {
            lastUpdate = update;
        }
    }
        //----------------------コンポジターfps取得-------------------
        public double GetCompositorFrameTime()
        {
            CVRCompositor cVRCompositor = OpenVR.Compositor;

            if (cVRCompositor == null)
            {
                return(float.NaN);
            }

            //現在
            Compositor_FrameTiming pTiming0 = new Compositor_FrameTiming();

            pTiming0.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
            if (!cVRCompositor.GetFrameTiming(ref pTiming0, 0))
            {
                return(float.NaN);
            }

            double frameTime0 = pTiming0.m_flTotalRenderGpuMs;
            double fps        = 1f / frameTime0;

            return(frameTime0);
        }
Beispiel #8
0
        private void Update()
        {
            if (Input.anyKeyDown)
            {
                print("Got Key Down, Count: " + ++_count + ", Player " + (!_hasPaused ? "Paused" : "Playing"));
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    print("Got Key Down, Code: Escape");
                    _hasPaused                = true;
                    _toAnotherScene           = true;
                    enabled                   = false;
                    ConfigurationManager.Test = (int)_count;
                    SceneManager.LoadScene(ConfigurationManager.MenuSceneName, LoadSceneMode.Single);
                    return;
                }

                _hasPaused = !_hasPaused;
            }

            if (UseVrDevice && _compositor == null)
            {
                _compositor = SteamVR.instance.compositor;
            }
            var frameTiming = new Compositor_FrameTiming
            {
                m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming))
            };

            if (!UseVrDevice || _compositor != null && _compositor.GetFrameTiming(ref frameTiming, 0))
            {
                if (frameTiming.m_nFrameIndex == _lastVrFrameIndex)
                {
                    return;
                }
                _lastVrFrameIndex = frameTiming.m_nFrameIndex;
            }
        }
Beispiel #9
0
        void Start()
        {
            if (App.Config.m_SdkMode == SdkMode.SteamVR)
            {
                if (SteamVR.instance != null)
                {
                    SteamVR_Events.InputFocus.Listen(OnInputFocusSteam);
                    SteamVR_Events.NewPosesApplied.Listen(OnNewPoses);
                }
                m_FrameTiming = new Compositor_FrameTiming
                {
                    m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(
                        typeof(Compositor_FrameTiming))
                };
            }
            else if (App.Config.m_SdkMode == SdkMode.Oculus)
            {
#if OCULUS_SUPPORTED
                OculusHandTrackingManager.NewPosesApplied += OnNewPoses;
                // We shouldn't call this frequently, hence the local cache and callbacks.
                OVRManager.VrFocusAcquired += () => { OnInputFocus(true); };
                OVRManager.VrFocusLost     += () => { OnInputFocus(false); };
#endif // OCULUS_SUPPORTED
            }
            else if (App.Config.m_SdkMode == SdkMode.Gvr)
            {
                var brushGeom = InputManager.Brush.Geometry;
                GvrControllerInput.OnPostControllerInputUpdated += OnNewPoses;
            }

            if (m_NeedsToAttachConsoleScript && m_VrControls != null)
            {
                ControllerConsoleScript.m_Instance.AttachToController(
                    m_VrControls.Brush);
                m_NeedsToAttachConsoleScript = false;
            }
        }
Beispiel #10
0
    private void FrameCounter()
    {
        var compositor = OpenVR.Compositor;

        if (compositor != null)
        {
            var timing = new Compositor_FrameTiming();
            timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
            compositor.GetFrameTiming(ref timing, 0);

            var update = timing.m_flSystemTimeInSeconds;
            if (update > lastUpdate)
            {
                var framerate = (lastUpdate > 0.0f) ? 1.0f / (update - lastUpdate) : 0.0f;
                lastUpdate         = update;
                FPS                = framerate;
                droppedFramesCount = (int)timing.m_nNumDroppedFrames;
            }
            else
            {
                lastUpdate = update;
            }
        }
    }
Beispiel #11
0
 public abstract bool GetFrameTiming(ref Compositor_FrameTiming pTiming,uint unFramesAgo);
Beispiel #12
0
 public override bool GetFrameTiming(ref Compositor_FrameTiming pTiming,uint unFramesAgo)
 {
     CheckIfUsable();
     bool result = VRNativeEntrypoints.VR_IVRCompositor_GetFrameTiming(m_pVRCompositor,ref pTiming,unFramesAgo);
     return result;
 }
Beispiel #13
0
    // Token: 0x06005F65 RID: 24421 RVA: 0x00218144 File Offset: 0x00216544
    private void Update()
    {
        SteamVR_Controller.Update();
        CVRSystem system = OpenVR.System;

        if (system != null)
        {
            VREvent_t arg         = default(VREvent_t);
            uint      uncbVREvent = (uint)Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref arg, uncbVREvent))
                {
                    break;
                }
                EVREventType eventType = (EVREventType)arg.eventType;
                if (eventType != EVREventType.VREvent_InputFocusCaptured)
                {
                    if (eventType != EVREventType.VREvent_InputFocusReleased)
                    {
                        if (eventType != EVREventType.VREvent_HideRenderModels)
                        {
                            if (eventType != EVREventType.VREvent_ShowRenderModels)
                            {
                                SteamVR_Events.System((EVREventType)arg.eventType).Send(arg);
                            }
                            else
                            {
                                SteamVR_Events.HideRenderModels.Send(false);
                            }
                        }
                        else
                        {
                            SteamVR_Events.HideRenderModels.Send(true);
                        }
                    }
                    else if (arg.data.process.pid == 0u)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                }
                else if (arg.data.process.oldPid == 0u)
                {
                    SteamVR_Events.InputFocus.Send(false);
                }
            }
        }
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true;
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;
        if (this.lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0f)
        {
            SteamVR instance = SteamVR.instance;
            if (instance != null)
            {
                Compositor_FrameTiming compositor_FrameTiming = default(Compositor_FrameTiming);
                compositor_FrameTiming.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                instance.compositor.GetFrameTiming(ref compositor_FrameTiming, 0u);
                Time.fixedDeltaTime = Time.timeScale / instance.hmd_DisplayFrequency;
            }
        }
    }
    protected override void OnUpdate()
    {
#if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_5)
        if (poseUpdater == null)
        {
            var go = new GameObject("poseUpdater");
            go.transform.parent = transform;
            poseUpdater         = go.AddComponent <SteamVR_UpdatePoses>();
        }
#else
        if (cameras.Length == 0)
        {
            enabled = false;
            return;
        }

        // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
        SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_PostPresentHandoff);
#endif
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Dispatch any OpenVR events.
        var system = OpenVR.System;
        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:                         // another app has taken focus (likely dashboard)
                    SteamVR_Utils.Event.Send("input_focus", false);
                    break;

                case EVREventType.VREvent_InputFocusReleased:                         // that app has released input focus
                    SteamVR_Utils.Event.Send("input_focus", true);
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Utils.Event.Send("hide_render_models", false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Utils.Event.Send("hide_render_models", true);
                    break;

                default:
                    var name = System.Enum.GetName(typeof(EVREventType), vrEvent.eventType);
                    if (name != null)
                    {
                        SteamVR_Utils.Event.Send(name.Substring(8) /*strip VREvent_*/, vrEvent);
                    }
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale * timing.m_nNumFramePresents / SteamVR.instance.hmd_DisplayFrequency;
            }
        }
    }
        private void Update()
        {
            SteamVR_Controller.Update();



            CVRSystem system = OpenVR.System;

            if (system != null)
            {
                VREvent_t pEvent      = default(VREvent_t);
                uint      uncbVREvent = (uint)Marshal.SizeOf(typeof(VREvent_t));
                for (int i = 0; i < 64; i++)
                {
                    if (!system.PollNextEvent(ref pEvent, uncbVREvent))
                    {
                        break;
                    }

                    switch (pEvent.eventType)
                    {
                    case 400u:
                        if (pEvent.data.process.oldPid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(arg0: false);
                        }
                        break;

                    case 401u:
                        if (pEvent.data.process.pid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(arg0: true);
                        }
                        break;

                    case 411u:
                        SteamVR_Events.HideRenderModels.Send(arg0: false);
                        break;

                    case 410u:
                        SteamVR_Events.HideRenderModels.Send(arg0: true);
                        break;

                    default:
                        SteamVR_Events.System((EVREventType)pEvent.eventType).Send(pEvent);
                        break;
                    }
                }
            }



            Application.targetFrameRate     = -1;
            Application.runInBackground     = true;
            QualitySettings.maxQueuedFrames = -1;
            QualitySettings.vSyncCount      = 0;
            if (lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0f)
            {
                SteamVR instance = SteamVR.instance;
                if (instance != null)
                {
                    Compositor_FrameTiming pTiming = default(Compositor_FrameTiming);
                    pTiming.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                    instance.compositor.GetFrameTiming(ref pTiming, 0u);
                    Time.fixedDeltaTime = Time.timeScale / instance.hmd_DisplayFrequency;
                }
            }
        }
Beispiel #16
0
 internal static extern uint StoreVrFrameTiming(ref Compositor_FrameTiming vrTiming);
Beispiel #17
0
    void Update()
    {
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
        //SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_PostPresentHandoff);

        // Dispatch any OpenVR events.
        var system = OpenVR.System;

        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:                         // another app has taken focus (likely dashboard)
                    if (vrEvent.data.process.oldPid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(false);
                    }
                    break;

                case EVREventType.VREvent_InputFocusReleased:                         // that app has released input focus
                    if (vrEvent.data.process.pid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Events.HideRenderModels.Send(false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Events.HideRenderModels.Send(true);
                    break;

                default:
                    SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0.0f)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale / vr.hmd_DisplayFrequency;
            }
        }
    }
Beispiel #18
0
    private void Update()
    {
#if !(UNITY_5_6)
        if (poseUpdater == null)
        {
            var go = new GameObject("poseUpdater");
            go.transform.parent = transform;
            poseUpdater         = go.AddComponent <SteamVR_UpdatePoses>();
        }
#endif
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Dispatch any OpenVR events.
        var system = OpenVR.System;
        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:
                    // another app has taken focus (likely dashboard)
                    if (vrEvent.data.process.oldPid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(false);
                    }
                    break;

                case EVREventType.VREvent_InputFocusReleased: // that app has released input focus
                    if (vrEvent.data.process.pid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Events.HideRenderModels.Send(false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Events.HideRenderModels.Send(true);
                    break;

                default:
                    SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0.0f)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale / vr.hmd_DisplayFrequency;
            }
        }
    }
        private IEnumerator UpdateBarGraph()
        {
            //while (!SteamVRManager.isConnected) yield return null;


            int framesToUpdate = 20;

            /*//Yield for
             * for (int i = 0; i < framesToUpdate; i++){
             *      yield return null;
             * }*/


            while (true)
            {
                while (!SteamVRManager.isConnected)
                {
                    yield return(null);
                }

                while (!SteamVRManager.isWearingHeadset)
                {
                    yield return(null);
                }

                while (!wristboardDP.overlay.shouldRender)
                {
                    yield return(null);
                }

                int targetFPS = SteamVRManager.hmdRefreshRate;


                //If frametimes go beyond this, they're bad frames
                float goodFrameTime = (1f / targetFPS) * 1000f;



                var timing = new Compositor_FrameTiming[framesToUpdate];
                timing[0].m_nSize = sizeOfCompFrameTime;
                OpenVR.Compositor.GetFrameTimings(timing);

                float avgFPS = 0f;

                //Loop through backwards so frames are always displayed framesToUpdate frames behind when they actually were
                for (int i = timing.Length - 1; i >= 0; i -= 2)
                {
                    Compositor_FrameTiming otherFrame = timing[i];
                    if (i > 1)
                    {
                        otherFrame = timing[i - 1];
                    }

                    Compositor_FrameTiming frame = timing[i];

                    //if (frame.m_flTotalRenderGpuMs > otherFrame.m_flTotalRenderGpuMs) frame = otherFrame;

                    float value = 0f;

                    List <float> frameTimes = new List <float>()
                    {
                        frame.m_flTotalRenderGpuMs,
                        otherFrame.m_flTotalRenderGpuMs,
                        frame.m_flCompositorRenderCpuMs,
                        otherFrame.m_flCompositorRenderCpuMs
                    };


                    value = frameTimes.Max();


                    Image last = bars.Last();


                    float frameImageHeight = Maths.LinearUnclamped(value, 0f, goodFrameTime, 0f, 45f);

                    last.rectTransform.sizeDelta = new Vector2(3f, frameImageHeight);

                    if (value > goodFrameTime)
                    {
                        last.color = frameBadColor;

                        int fps = Mathf.RoundToInt(1f / (value / 1000f));
                        fpsText.SetText(fps.ToString());

                        avgFPS += fps;
                        avgFPS += fps;
                    }
                    else
                    {
                        last.color = frameGoodColor;

                        //fpsText.SetText(targetFPS.ToString());

                        avgFPS += targetFPS;
                        avgFPS += targetFPS;
                    }


                    //Move it to the start
                    bars.Remove(last);
                    bars.Insert(0, last);

                    last.rectTransform.SetSiblingIndex(bars.Count - 1);

                    //Return twice since we're displaying two frames in one
                    yield return(null);

                    yield return(null);
                }

                //Update the text:
                string avgFPSText = Mathf.RoundToInt((avgFPS / framesToUpdate)).ToString();
                fpsText.SetText(avgFPSText);



                if (timing.Length <= 0)
                {
                    yield return(null);
                }
            }
        }