Ejemplo n.º 1
0
        public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
        {
            var properties = layerModel?.Properties as AmbientLightPropertiesModel;

            if (properties == null)
            {
                return;
            }

            var width  = (int)Math.Round(properties.Width);
            var height = (int)Math.Round(properties.Height);

            var data    = ScreenCaptureManager.GetLastScreenCapture();
            var newData = GetAmbienceCreator(properties)
                          .GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width,
                                       height, properties);

            _lastData = _lastData?.Blend(newData, properties.SmoothMode) ?? newData;
            var stride = (width * ScreenCaptureManager.LastCapturePixelFormat.BitsPerPixel + 7) / 8;

            properties.AmbientLightBrush = new DrawingBrush(new ImageDrawing
                                                                (BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData,
                                                                                     stride), new Rect(0, 0, width, height)));

            layerModel.ApplyProperties(true);
        }
Ejemplo n.º 2
0
 public SourcesModel(ILocalVideoSourceManager localVideoSourceManager, ILocalAudioSourceManager localAudioSourceManager, CoreData coreData, LocalSettingsService localSettingsService,
                     IWindowStateManager windowStateManager)
 {
     _localVideoSourceManager = localVideoSourceManager;
     _localAudioSourceManager = localAudioSourceManager;
     _coreData             = coreData;
     _localSettingsService = localSettingsService;
     _windowStateManager   = windowStateManager;
     _screenCaptureManager = ScreenCaptureManager.Instance;
 }
        public async Task Multiple_Capture_should_throw()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var capture1 = await manager.Capture(screen);

            Func <Task> act = () => manager.Capture(screen);

            act.Should().Throw <ScreenCaptureException>();
        }
        public async Task Capture_Bitmap()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            using var capture = await manager.Capture(screen);

            using var bitmap = await capture.ToBitmap();

            Run(bitmap, "capture");
        }
        public void GetScreens()
        {
            var manager = new ScreenCaptureManager();
            var screens = manager.GetScreens();

            screens.Should().NotBeEmpty();
            foreach (var screen in screens)
            {
                screen.AdapterId.Should().NotBe(0);
                screen.OutputName.Should().NotBeNullOrEmpty();

                Console.WriteLine($"{screen.AdapterId} {screen.OutputName}");
            }
        }
        public async Task CreateImage_CopyHostPtr(bool reuseImage)
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var api = CL.GetApi();

            var(platformId, deviceId) = FindFirstGpuPlatform(api);
            if (platformId == default)
            {
                throw new Exception("No GPU device found.");
            }

            var platformName = GetPlatformName(api, platformId);

            Console.WriteLine($"Platform: {platformName}");

            var contextId = CreateContext(api, platformId, deviceId);

            var queueId = api.CreateCommandQueue(contextId, deviceId, default, out var err);
        public async Task CaptureStream_benchmark()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(10));

            var sw = Stopwatch.StartNew();

            var count = 0;

            await foreach (var capture in manager.CaptureStream(screen, cancellationToken: tcs.Token))
            {
                capture.Dispose();
                count++;
            }

            sw.Stop();

            Console.WriteLine($"Average: {(int)(sw.Elapsed.TotalMicroseconds() / count)} us");
            Console.WriteLine($"FPS: {count/sw.Elapsed.TotalSeconds}");
        }
Ejemplo n.º 8
0
        internal void Start()
        {
            _coreData.Subscriptions.SubscribeForProperties <IDevice>(s => s.PreviewAudioSources, (d, c, p) => RefreshDeviceBasedState());
            _coreData.Subscriptions.SubscribeForProperties <IDevice>(s => s.PreviewSources, (d, c, p) => RefreshDeviceBasedState());
            _coreData.Subscriptions.SubscribeForProperties <IDevice>(s => s.State, (d, c, p) => RefreshDeviceBasedState());

            try
            {
                _coreData.ThisDevice.ApiContract = ScreenCaptureManager.GetApiContract();
            }
            catch
            {
                _coreData.ThisDevice.ApiContract = -1;
            }

            UpdateModelWithLocalDevice(_videoSources, _coreData.ThisDevice.VideoInputs);
            UpdateModelWithLocalDevice(_audioSources, _coreData.ThisDevice.AudioInputs);
            UpdateCaptureModel();
            UpdatePluginModel();

            RefreshDeviceBasedState();
        }
        public async Task Capture_benchmark()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(10));

            var sw = Stopwatch.StartNew();

            var count = 0;

            while (!tcs.IsCancellationRequested)
            {
                using var capture = await manager.Capture(screen, cancellationToken : tcs.Token);

                count++;
            }

            sw.Stop();

            Console.WriteLine($"Average: {(int)(sw.Elapsed.TotalMilliseconds / count)} ms");
            Console.WriteLine($"FPS: {count / sw.Elapsed.TotalSeconds}");
        }
        public async Task Multiple_CaptureStream_should_throw()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var stream1 = manager.CaptureStream(screen);

            var enumerator = stream1.GetAsyncEnumerator();

            Exception ex = null;

            try
            {
                var capture1 = await enumerator.MoveNextAsync();

                var capture2 = await enumerator.MoveNextAsync();
            }
            catch (ScreenCaptureException sce)
            {
                ex = sce;
            }

            ex.Should().BeOfType <ScreenCaptureException>();
        }
Ejemplo n.º 11
0
        public async Task Capture_benchmark()
        {
            var manager = new ScreenCaptureManager();
            var screen  = manager.GetScreens().FirstOrDefault();

            var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(10));

            using var capture = await manager.Capture(screen, cancellationToken : tcs.Token);

            var sw = Stopwatch.StartNew();

            sw.Start();
            var n = 1000;

            for (var i = 0; i < n; i++)
            {
                var bitmap = await capture.ToBitmap();

                bitmap.Dispose();
            }
            sw.Stop();

            Console.WriteLine($"Average: {(int)(sw.Elapsed.TotalMicroseconds()/n)} us");
        }
Ejemplo n.º 12
0
        public new void HandleInput()
        {
            WidgetInput    input          = m_componentPlayer.View.Input;
            PlayerInput    playerInput    = m_componentPlayer.ComponentInput.PlayerInput;
            ComponentRider componentRider = m_componentPlayer.ComponentRider;

            if (m_componentPlayer.View.ActiveCamera.IsEntityControlEnabled)
            {
                if (!m_keyboardHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_keyboardHelpMessageShown = true;
                    DisplaySmallMessage("按 H 键查看键盘控制帮助\n(或看帮助)", blinking: true, playNotificationSound: true);
                }
                else if (!m_gamepadHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_gamepadHelpMessageShown = true;
                    DisplaySmallMessage("按 START/PAUSE 键查看手柄控制帮助\n(或看帮助)", blinking: true, playNotificationSound: true);
                }
            }
            if (playerInput.KeyboardHelp)
            {
                if (m_keyboardHelpDialog == null)
                {
                    m_keyboardHelpDialog = new KeyboardHelpDialog();
                }
                if (m_keyboardHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_keyboardHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, m_keyboardHelpDialog);
                }
            }
            if (playerInput.GamepadHelp)
            {
                if (m_gamepadHelpDialog == null)
                {
                    m_gamepadHelpDialog = new GamepadHelpDialog();
                }
                if (m_gamepadHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_gamepadHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, m_gamepadHelpDialog);
                }
            }
            if (m_helpButtonWidget.IsClicked)
            {
                ScreensManager.SwitchScreen("Help");
            }
            if (playerInput.ToggleInventory || m_inventoryButtonWidget.IsClicked)
            {
                if (IsInventoryVisible())
                {
                    ModalPanelWidget = null;
                }
                else if (m_componentPlayer.ComponentMiner.Inventory is ComponentCreativeInventory)
                {
                    ModalPanelWidget = new CreativeInventoryWidget(m_componentPlayer.Entity);
                }
                else
                {
                    ModalPanelWidget = new FullInventoryWidget(m_componentPlayer.ComponentMiner.Inventory, m_componentPlayer.Entity.FindComponent <ComponentCraftingTable>(throwOnError: true));
                }
            }
            if (playerInput.ToggleClothing || m_clothingButtonWidget.IsClicked)
            {
                if (IsClothingVisible())
                {
                    ModalPanelWidget = null;
                }
                else
                {
                    ModalPanelWidget = new ClothingWidget(m_componentPlayer);
                }
            }
            if (m_sneakButtonWidget.IsClicked || playerInput.ToggleSneak)
            {
                bool isSneaking = m_componentPlayer.ComponentBody.IsSneaking;
                m_componentPlayer.ComponentBody.IsSneaking = !isSneaking;
                if (m_componentPlayer.ComponentBody.IsSneaking != isSneaking)
                {
                    if (m_componentPlayer.ComponentBody.IsSneaking)
                    {
                        DisplaySmallMessage("Sneak mode on", blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage("Sneak mode off", blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (componentRider != null && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount))
            {
                bool flag = componentRider.Mount != null;
                if (flag)
                {
                    componentRider.StartDismounting();
                }
                else
                {
                    ComponentMount componentMount = componentRider.FindNearestMount();
                    if (componentMount != null)
                    {
                        componentRider.StartMounting(componentMount);
                    }
                }
                if (componentRider.Mount != null != flag)
                {
                    if (componentRider.Mount != null)
                    {
                        DisplaySmallMessage("Mounted", blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage("Dismounted", blinking: false, playNotificationSound: false);
                    }
                }
            }
            if ((m_editItemButton.IsClicked || playerInput.EditItem) && m_nearbyEditableCell.HasValue)
            {
                int cellValue = m_subsystemTerrain.Terrain.GetCellValue(m_nearbyEditableCell.Value.X, m_nearbyEditableCell.Value.Y, m_nearbyEditableCell.Value.Z);
                int contents  = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(m_nearbyEditableCell.Value.X, m_nearbyEditableCell.Value.Y, m_nearbyEditableCell.Value.Z, cellValue, m_componentPlayer); i++)
                {
                }
            }
            else if ((m_editItemButton.IsClicked || playerInput.EditItem) && IsActiveSlotEditable())
            {
                IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
                if (inventory != null)
                {
                    int activeSlotIndex = inventory.ActiveSlotIndex;
                    int num             = Terrain.ExtractContents(inventory.GetSlotValue(activeSlotIndex));
                    if (BlocksManager.Blocks[num].IsEditable)
                    {
                        SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                        for (int j = 0; j < blockBehaviors2.Length && !blockBehaviors2[j].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer); j++)
                        {
                        }
                    }
                }
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly) && componentRider.Mount == null)
            {
                bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
                m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
                if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled)
                {
                    if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled)
                    {
                        m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                        DisplaySmallMessage("Fly mode on", blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage("Fly mode off", blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (m_cameraButtonWidget.IsClicked || playerInput.SwitchCameraMode)
            {
                View view = m_componentPlayer.View;
                if (view.ActiveCamera.GetType() == typeof(FppCamera))
                {
                    view.ActiveCamera = view.FindCamera <TppCamera>();
                    DisplaySmallMessage("第三人称视角", blinking: false, playNotificationSound: false);
                }
                else if (view.ActiveCamera.GetType() == typeof(TppCamera))
                {
                    view.ActiveCamera = view.FindCamera <OrbitCamera>();
                    DisplaySmallMessage("滑轨视角", blinking: false, playNotificationSound: false);
                }
                else if (view.ActiveCamera.GetType() == typeof(OrbitCamera))
                {
                    view.ActiveCamera = view.FindCamera <FixedCamera>();
                    DisplaySmallMessage("固定视角", blinking: false, playNotificationSound: false);
                }
                else if (view.ActiveCamera.GetType() == typeof(FixedCamera))
                {
                    view.ActiveCamera = new DebugCamera(view);
                    DisplaySmallMessage("调试视角", blinking: false, playNotificationSound: false);
                }
                else
                {
                    view.ActiveCamera = view.FindCamera <FppCamera>();
                    DisplaySmallMessage("第一人称视角", blinking: false, playNotificationSound: false);
                }
            }
            if (m_photoButtonWidget.IsClicked || playerInput.TakeScreenshot)
            {
                ScreenCaptureManager.CapturePhoto();
                Time.QueueFrameCountDelayedExecution(Time.FrameIndex + 1, HandleInput_b__108_0);
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_lightningButtonWidget.IsClicked || playerInput.Lighting))
            {
                Matrix matrix = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
                base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true).ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, matrix.Forward);
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay))
            {
                float num2  = MathUtils.Remainder(0.25f, 1f);
                float num3  = MathUtils.Remainder(0.5f, 1f);
                float num4  = MathUtils.Remainder(0.75f, 1f);
                float num5  = MathUtils.Remainder(1f, 1f);
                float num6  = MathUtils.Remainder(num2 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num7  = MathUtils.Remainder(num3 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num8  = MathUtils.Remainder(num4 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num9  = MathUtils.Remainder(num5 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num10 = MathUtils.Min(num6, num7, num8, num9);
                if (num6 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num6;
                    DisplaySmallMessage("Dawn", blinking: false, playNotificationSound: false);
                }
                else if (num7 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num7;
                    DisplaySmallMessage("Noon", blinking: false, playNotificationSound: false);
                }
                else if (num8 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num8;
                    DisplaySmallMessage("Dusk", blinking: false, playNotificationSound: false);
                }
                else if (num9 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num9;
                    DisplaySmallMessage("Midnight", blinking: false, playNotificationSound: false);
                }
            }
            if (ModalPanelWidget != null)
            {
                if (input.Cancel || input.Back || m_backButtonWidget.IsClicked)
                {
                    ModalPanelWidget = null;
                }
            }
            else if (input.Back || m_backButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, new GameMenuDialog(m_componentPlayer));
            }
        }