private static void UpdatePoses()
 {
     if (_compositor == null)
     {
         return;
     }
     _compositor.GetLastPoses(_poses, _gamePoses);
     SteamVR_Event.Send("new_poses", _poses);
     SteamVR_Event.Send("new_poses_applied");
 }
        private static void OnNewPoses(params object[] args)
        {
            var poses = (TrackedDevicePose_t[])args[0];

            for (int i = 0; i < poses.Length; i++)
            {
                var connected = poses[i].bDeviceIsConnected;
                if (connected != ControllerManager.connected[i])
                {
                    SteamVR_Event.Send("device_connected", i, connected);
                }
            }

            if (poses.Length > OpenVR.k_unTrackedDeviceIndex_Hmd)
            {
                var result = poses[OpenVR.k_unTrackedDeviceIndex_Hmd].eTrackingResult;

                var initializing = result == ETrackingResult.Uninitialized;
                if (initializing != SteamVR.initializing)
                {
                    SteamVR_Event.Send("initializing", initializing);
                }

                var calibrating =
                    result == ETrackingResult.Calibrating_InProgress ||
                    result == ETrackingResult.Calibrating_OutOfRange;
                if (calibrating != SteamVR.calibrating)
                {
                    SteamVR_Event.Send("calibrating", calibrating);
                }

                var outOfRange =
                    result == ETrackingResult.Running_OutOfRange ||
                    result == ETrackingResult.Calibrating_OutOfRange;
                if (outOfRange != SteamVR.outOfRange)
                {
                    SteamVR_Event.Send("out_of_range", outOfRange);
                }
            }
        }
        public static void RunOverlays()
        {
            Stopwatch fpsWatch    = new Stopwatch();
            VREvent_t eventData   = new VREvent_t();
            uint      vrEventSize = (uint)Marshal.SizeOf <VREvent_t>();

            while (!_doStop)
            {
                fpsWatch.Restart();

                UpdatePoses();

                PreUpdateCallback?.Invoke(null, null);

                foreach (WebKitOverlay overlay in Overlays)
                {
                    overlay.Update();
                }
                while (OpenVR.System.PollNextEvent(ref eventData, vrEventSize))
                {
                    SteamVR_Event.Send(((EVREventType)eventData.eventType).ToString().Replace("VREvent_", ""), eventData);
                }

                PostUpdateCallback?.Invoke(null, null);

                PreDrawCallback?.Invoke(null, null);

                foreach (WebKitOverlay overlay in Overlays)
                {
                    overlay.Draw();
                }

                PostDrawCallback?.Invoke(null, null);

                fpsWatch.Stop();
                Thread.Sleep(fpsWatch.ElapsedMilliseconds >= _frameSleep ? 0 : (int)(_frameSleep - fpsWatch.ElapsedMilliseconds));
            }

            CefShutdown();
        }