public KeyboardManager()
 {
     _frame = 0;
     _bindings = new BidirectionalDict<string, KeyBinding>();
     _previous = InputSnapshot.With(Keyboard.GetState());
     _current = InputSnapshot.With(Keyboard.GetState());
     _repeatingBindingHistory = new Dictionary<string, int>();
 }
        public void Run()
        {
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                debug: false,
                swapchainDepthFormat: PixelFormat.R16_UNorm,
                syncToVerticalBlank: true,
                resourceBindingModel: ResourceBindingModel.Improved,
                preferDepthRangeZeroToOne: true,
                preferStandardClipSpaceYDirection: true);

#if DEBUG
            options.Debug = true;
#endif
            GD      = VeldridStartup.CreateGraphicsDevice(Window, options, GraphicsBackend.Direct3D11);
            Factory = new DisposeCollectorResourceFactory(GD.ResourceFactory);
            GraphicsDeviceCreated?.Invoke(GD, Factory, GD.MainSwapchain);

            Stopwatch sw = Stopwatch.StartNew();
            double    previousElapsed = sw.Elapsed.TotalSeconds;
            long      ticks           = 0;

            while (Window.Exists)
            {
                double newElapsed   = sw.Elapsed.TotalSeconds;
                float  deltaSeconds = (float)(newElapsed - previousElapsed);

                InputSnapshot inputSnapshot = Window.PumpEvents();
                InputTracker.UpdateFrameInput(inputSnapshot);

                if (Window.Exists)
                {
                    previousElapsed = newElapsed;
                    if (WindowResized)
                    {
                        WindowResized = false;
                        GD.ResizeMainWindow((uint)Window.Width, (uint)Window.Height);
                        Resized?.Invoke();
                    }

                    Rendering?.Invoke(deltaSeconds, ticks++);
                }
            }

            GD.WaitForIdle();
            Factory.DisposeCollector.DisposeAll();
            GD.Dispose();
            GraphicsDeviceDestroyed?.Invoke();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            /*
             * if (!ColliderCon.connect())
             * {
             *  Console.WriteLine("Cannot connect to ColliderconVR service.\nMake Sure VRChat is running and that ColliderCon is loaded");
             *  Console.ReadLine();
             *  Environment.Exit(-1);
             * }*/

            BTManager.rescanDevices();

            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1024, 768, WindowState.Normal, "Lovetap"),
                new GraphicsDeviceOptions(true, null, true),
                out _window,
                out _gd);
            _window.Resized += () =>
            {
                _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
                _controller.WindowResized(_window.Width, _window.Height);
            };

            _cl         = _gd.ResourceFactory.CreateCommandList();
            _controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);
            CollideSystem.updateColliders();
            StartUI();
            // CollideSystem.colliders.Add(new WatchedCollider(CollideSystem.getColliderByName("celhandleft"), CollideSystem.getColliderByName("celhandright")));
            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (!_window.Exists)
                {
                    break;
                }
                _controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                SubmitUI();

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
                _controller.Render(_gd, _cl);
                _cl.End();
                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Create window, GraphicsDevice, and all resources necessary for the demo.
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "_imgui.NET Sample Program"),
                new GraphicsDeviceOptions(true, null, true, ResourceBindingModel.Improved, true, true),
                out _window,
                out _gd);
            _window.Resized += () =>
            {
                _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
                _controller.WindowResized(_window.Width, _window.Height);
            };
            _cl           = _gd.ResourceFactory.CreateCommandList();
            _controller   = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);
            _memoryEditor = new MemoryEditor();
            Random random = new Random();

            _memoryEditorData = Enumerable.Range(0, 1024).Select(i => (byte)random.Next(255)).ToArray();

            // Main application loop
            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (!_window.Exists)
                {
                    break;
                }
                _controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to _imgui.

                SubmitUI();

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
                _controller.Render(_gd, _cl);
                _cl.End();
                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }

            // Clean up Veldrid resources
            _gd.WaitForIdle();
            _controller.Dispose();
            _cl.Dispose();
            _gd.Dispose();
            _imgui = new ImGui();
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            window = CreateWindow();

            Initialize();

            while (window.Exists)
            {
                inputSnapshot = window.PumpEvents();

                Update();
                Draw();
            }

            Dispose();
        }
        public void Update()
        {
            long currentTime = Utils.Timestamp;

            if (currentTime > lastSend + ticksPerSend)              //perform rate limit
            {
                lastSend = currentTime;
                InputSnapshot snapshot = TakeInputSnapshot();
                previousInputs.Enqueue(snapshot);
                InputConsumer.inst.ConsumeInput(-1, snapshot, true);
                MUGAClient.inst.client.SendByChannel(
                    MsgTypeExt.USER_INPUT,
                    new ByteMsgBase(snapshot.ToBytes()),
                    Channels.DefaultUnreliable);
            }
        }
        public void AcceptState(InterpolateStep step)
        {
            if (lastTruth != null && step.timestamp < lastTruth.timestamp)
            {
                //throwaway out-of-order messages
                return;
            }
            long now = Utils.Timestamp;

            lastTruth = step;
            //new step is the truth
            lastTruth.profile.RestoreSelfToGameObject(gameObject);
            long lastKnownTime = lastTruth.timestamp;

            knownLag = (now - lastKnownTime) / Utils.TICKS_PER_SEC;
            if (previousInputs.Count < 1)
            {
                //Debug.Log("no saved inputs");
                return;
            }
            //deque all the ones older than this step
            InputSnapshot snap = previousInputs.Peek();

            while (snap != null && snap.timeSent < lastKnownTime)
            {
                previousInputs.Dequeue();
                if (previousInputs.Count < 1)
                {
                    break;
                }
                snap = previousInputs.Peek();
            }

            //for the rest use physics magikery to simulate everything
            Physics.autoSimulation = false;

            //for each step simulate the futures
            foreach (InputSnapshot futureSnap in previousInputs)
            {
                //simulate teh future
                InputConsumer.inst.ConsumeInput(-1, futureSnap, false);
                Physics.Simulate((float)(futureSnap.timeSent - lastKnownTime) / Utils.TICKS_PER_SEC);
                lastKnownTime = futureSnap.timeSent;
            }

            Physics.autoSimulation = true;
        }
Beispiel #8
0
        public void Update(double deltaSeconds)
        {
            // Poll input
            InputSnapshot snapshot = _window.PumpEvents();

            InputTracker.UpdateFrameInput(snapshot);
            float   circleWidth = 4f;
            float   timeFactor  = (float)DateTime.UtcNow.TimeOfDay.TotalMilliseconds / 1000;
            Vector3 position    = new Vector3(
                (float)(Math.Cos(timeFactor) * circleWidth),
                3 + (float)Math.Sin(timeFactor) * 2,
                (float)(Math.Sin(timeFactor) * circleWidth));
            Vector3 lookDirection = -position;

            _viewMatrix = Matrix4x4.CreateLookAt(position, position + lookDirection, Vector3.UnitY);
            _viewBuffer.SetData(_viewMatrix);
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            window          = CreateWindow();
            window.Resized += () => graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);

            Initialize();

            while (window.Exists)
            {
                inputSnapshot = window.PumpEvents();

                Update();
                Draw();
            }

            Dispose();
        }
Beispiel #10
0
        public void Run()
        {
            while (isRendering)
            {
                //防止界面假死
                // Application.DoEvents();
                double newElapsed   = sw.Elapsed.TotalSeconds;
                float  deltaSeconds = (float)(newElapsed - previousElapsed);

                //这里不再使用通用的事件处理程序
                InputSnapshot inputSnapshot = _window.PumpEvents();
                InputTracker.UpdateFrameInput(inputSnapshot);
                //
                previousElapsed = newElapsed;
                Rendering?.Invoke(deltaSeconds);
            }
        }
Beispiel #11
0
        private void Update()
        {
            InputSnapshot snapshot = _window !.PumpEvents();

            if (!_window.Exists)
            {
                return;
            }


            HeldResponsiveKeys.ForEach(key => AlertResponsiveKeyEvent(key));


            _controller !.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

            if (!DrawUI())
            {
                _window.Close();
            }

            if (_controller.ShowDemoWindow)
            {
                ImGui.ShowDemoWindow(ref _controller.ShowDemoWindow);
            }

            _gd !.WaitForIdle();
            _cl !.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
            _controller.Render(_gd, _cl);

            _cl.End();

            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
            _gd.WaitForIdle();

            RecordFramebuffer(_gd.MainSwapchain.Framebuffer);

            if (_housekeepingTimerFired)
            {
                _controller.ClearCachedImageResources();
                _housekeepingTimerFired = false;
                _longTimer !.Start();
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCi = new WindowCreateInfo()
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 800,
                WindowHeight       = 600,
                WindowTitle        = "Pentagonal Hexecontahedron",
                WindowInitialState = WindowState.Normal
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                true,
                PixelFormat.R16_UNorm,
                true,
                ResourceBindingModel.Improved,
                true,
                true);

            _window          = VeldridStartup.CreateWindow(ref windowCi);
            _window.Resized += () => { _isResized = true; };

            _window.KeyUp += keyArg =>
            {
                if (keyArg.Key == Key.Escape)
                {
                    _window.Close();
                }
            };
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window, options, GraphicsBackend.Vulkan);

            CreateResources();

            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (snapshot.IsMouseDown(MouseButton.Left))
                {
                    _rotate += 0.01f;
                    ViewProjectionUpdate();
                }
                Draw();
            }

            DisposeResources();
        }
Beispiel #13
0
    // Update is called once per frame
    new protected void FixedUpdate()
    {
        if (InputToken == null)
        {
            base.FixedUpdate();
            return;
        }

        InputSnapshot input = InputToken.GetSnapshot();
        var           data  = SimulateFrame(input, cyoteTime);

        cyoteTime = data.cyoteTime;
        if (data.jumpConsumed)
        {
            InputToken.ConsumeJump();
        }
    }
Beispiel #14
0
        static void Main(string[] args)
        {
            _uiManager = new UiManager();

            // Create window, GraphicsDevice, and all resources necessary for the demo.
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1000, 720, WindowState.Normal, "FileDialog Demo"),
                new GraphicsDeviceOptions(true, null, true),
                out _window,
                out _gd);

            _window.Resized += _window_Resized;

            _cl = _gd.ResourceFactory.CreateCommandList();

            _controller = new ImGuiRenderer(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);

            ImGui.StyleColorsLight();

            // Main application loop
            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (!_window.Exists)
                {
                    break;
                }
                _controller.Update(1f / 60f, snapshot);

                SubmitUI();

                _cl.Begin();
                _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
                _cl.ClearColorTarget(0, new RgbaFloat(0.5f, 0.5f, 0.5f, 1f));
                _controller.Render(_gd, _cl);
                _cl.End();
                _gd.SubmitCommands(_cl);
                _gd.SwapBuffers(_gd.MainSwapchain);
            }

            // Clean up Veldrid resources
            _gd.WaitForIdle();
            _controller.Dispose();
            _cl.Dispose();
            _gd.Dispose();
        }
Beispiel #15
0
        internal override void UpdateSnapshot(InputSnapshot snapshot)
        {
            foreach (KeyEvent key in snapshot.KeyEvents)
            {
                if (key.Down)
                {
                    this.pressedKeys.Add(key.Key);
                }
                else
                {
                    this.pressedKeys.Remove(key.Key);
                }
            }

            Keys[] newKeys = this.pressedKeys.Select(key => key.ConvertKey()).ToArray();
            this.currentState = new KeyboardState(newKeys);
        }
Beispiel #16
0
        public static void UpdateFrameInput(Sdl2Window window, InputSnapshot snapshot)
        {
            FrameSnapshot = snapshot;
            _newKeysThisFrame.Clear();
            _newMouseButtonsThisFrame.Clear();

            window.CursorVisible = !LockMouse;

            if (LockMouse)
            {
                window.SetMousePosition(window.Width / 2, window.Height / 2);
                MousePosition = new Vector2(window.Width / 2, window.Height / 2);
                MouseDelta    = snapshot.MousePosition - MousePosition;
            }
            else
            {
                var newPosition = snapshot.MousePosition;
                MouseDelta    = newPosition - MousePosition;
                MousePosition = newPosition;
            }
            for (int i = 0; i < snapshot.KeyEvents.Count; i++)
            {
                KeyEvent ke = snapshot.KeyEvents[i];
                if (ke.Down)
                {
                    KeyDown(ke.Key);
                }
                else
                {
                    KeyUp(ke.Key);
                }
            }
            for (int i = 0; i < snapshot.MouseEvents.Count; i++)
            {
                MouseEvent me = snapshot.MouseEvents[i];
                if (me.Down)
                {
                    MouseDown(me.MouseButton);
                }
                else
                {
                    MouseUp(me.MouseButton);
                }
            }
        }
Beispiel #17
0
        public void Run()
        {
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                debug: false,
                swapchainDepthFormat: PixelFormat.R16_UNorm,
                syncToVerticalBlank: true,
                resourceBindingModel: ResourceBindingModel.Improved);

#if DEBUG
            options.Debug = true;
#endif
            _gd      = VeldridStartup.CreateGraphicsDevice(_window, options);
            _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory);
            GraphicsDeviceCreated?.Invoke(_gd, _factory, _gd.MainSwapchain);

            Stopwatch sw = Stopwatch.StartNew();
            double    previousElapsed = sw.Elapsed.TotalSeconds;

            while (_window.Exists)
            {
                double newElapsed   = sw.Elapsed.TotalSeconds;
                float  deltaSeconds = (float)(newElapsed - previousElapsed);

                InputSnapshot inputSnapshot = _window.PumpEvents();
                InputTracker.UpdateFrameInput(inputSnapshot);

                if (_window.Exists)
                {
                    previousElapsed = newElapsed;
                    if (_windowResized)
                    {
                        _windowResized = false;
                        _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
                        Resized?.Invoke();
                    }

                    Rendering?.Invoke(deltaSeconds);
                }
            }

            _gd.WaitForIdle();
            _factory.DisposeCollector.DisposeAll();
            _gd.Dispose();
            GraphicsDeviceDestroyed?.Invoke();
        }
Beispiel #18
0
        public void UpdateImGui(float deltaSeconds, InputSnapshot inputSnapshot)
        {
            var io = ImGui.GetIO();

            io.DeltaTime               = deltaSeconds;
            io.DisplaySize             = new System.Numerics.Vector2(Resolution.Horizontal, Resolution.Vertical);
            io.DisplayFramebufferScale = new System.Numerics.Vector2(Resolution.Horizontal / Resolution.Vertical);

            ImGui.NewFrame();
            UpdateImGuiInput(inputSnapshot);
            SubmitImGUILayout(deltaSeconds);
            ImGui.Render();

            if (backendCallback)
            {
                changeBackendAction?.Invoke(newGraphicsBackend);
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "ImGui.NET"),
                new GraphicsDeviceOptions(true, null, true),
                out m_window,
                out m_device);

            m_window.Resized += () =>
            {
                m_device.MainSwapchain.Resize((uint)m_window.Width, (uint)m_window.Height);
                m_controller.WindowResized(m_window.Width, m_window.Height);
            };

            m_commandList = m_device.ResourceFactory.CreateCommandList();
            m_controller  = new ImGuiController(m_device, m_device.MainSwapchain.Framebuffer.OutputDescription, m_window.Width, m_window.Height);

            // Main application loop
            while (m_window.Exists)
            {
                InputSnapshot snapshot = m_window.PumpEvents();
                if (!m_window.Exists)
                {
                    break;
                }
                m_controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                SubmitUI();

                m_commandList.Begin();
                m_commandList.SetFramebuffer(m_device.MainSwapchain.Framebuffer);
                m_commandList.ClearColorTarget(0, new RgbaFloat(m_clearColor.X, m_clearColor.Y, m_clearColor.Z, 1f));
                m_controller.Render(m_device, m_commandList);
                m_commandList.End();
                m_device.SubmitCommands(m_commandList);
                m_device.SwapBuffers(m_device.MainSwapchain);
            }

            // Clean up Veldrid resources
            m_device.WaitForIdle();
            m_controller.Dispose();
            m_commandList.Dispose();
            m_device.Dispose();
        }
Beispiel #20
0
        /// <summary>
        /// Updates ImGui input and IO configuration state.
        /// </summary>
        public void Update(float deltaSeconds, InputSnapshot snapshot)
        {
            if (_frameBegun)
            {
                ImGui.Render();
                ImGui.UpdatePlatformWindows();
            }

            SetPerFrameImGuiData(deltaSeconds);
            UpdateImGuiInput(snapshot);
            UpdateMonitors();

            _frameBegun = true;
            ImGui.NewFrame();

            ImGui.Text($"Main viewport Position: {ImGui.GetPlatformIO().MainViewport.Pos}");
            ImGui.Text($"Main viewport Size: {ImGui.GetPlatformIO().MainViewport.Size}");
            ImGui.Text($"MoouseHoveredViewport: {ImGui.GetIO().MouseHoveredViewport}");
        }
Beispiel #21
0
        internal override void UpdateSnapshot(InputSnapshot snapshot)
        {
            foreach (MouseEvent key in snapshot.MouseEvents)
            {
                if (key.Down)
                {
                    this.buttons |= key.MouseButton.ConvertMouseButtons();
                }
                else
                {
                    this.buttons ^= key.MouseButton.ConvertMouseButtons();
                }
            }

            this.currentState = new MouseState(
                (int)snapshot.MousePosition.X,
                (int)snapshot.MousePosition.Y,
                (int)snapshot.WheelDelta,
                this.buttons);
        }
Beispiel #22
0
        public void Run()
        {
            InputSnapshot snapshot = _window.PumpEvents();

            if (!_window.Exists)
            {
                return;
            }
            _controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

            SubmitUI();

            _cl.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
            _controller.Render(_gd, _cl);
            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
        }
Beispiel #23
0
        private void ProcessMouse(InputSnapshot snapshot, float timeSinceLastUpdateSeconds)
        {
            _mousePositionLastFrame = MousePosition;
            MousePosition           = snapshot.MousePosition;

            if (_isFirstFrame)
            {
                MousePositionDeltaSinceLastFrame = Vector2.Zero;
                MouseVelocity = Vector2.Zero;
            }
            else
            {
                MousePositionDeltaSinceLastFrame = MousePosition - _mousePositionLastFrame;
                MouseVelocity = MousePositionDeltaSinceLastFrame / timeSinceLastUpdateSeconds;
            }

            _mouseButtonsDownThisFrame.Clear();
            _mouseButtonsUpThisFrame.Clear();

            for (var n = 0; n < snapshot.MouseEvents.Count; n++)
            {
                var me          = snapshot.MouseEvents[n];
                var button      = me.MouseButton;
                var mouseButton = ToMouseButton(button);

                if (me.Down)
                {
                    MouseDown(mouseButton);
                }
                else
                {
                    MouseUp(mouseButton);
                }
            }

            foreach (var button in _mouseButtonsDown.Keys.ToList())
            {
                _mouseButtonsDown[button] += timeSinceLastUpdateSeconds;
            }
        }
Beispiel #24
0
        public static void Update(JORManager manager)
        {
            if (!_window.Exists)
            {
                Environment.Exit(0); return;
            }
            InputSnapshot snapshot = _window.PumpEvents();

            if (!_window.Exists)
            {
                return;
            }
            _controller.Update(1f / 60f, snapshot);
            SubmitUI(manager);
            _cl.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
            _controller.Render(_gd, _cl);
            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
        }
Beispiel #25
0
        internal static void UpdateInput(InputSnapshot snapshot)
        {
            keyDownDict.Clear();
            keyUpDict.Clear();
            mouseDownDict.Clear();
            mouseUpDict.Clear();

            lastMousePosition = mousePosition;
            mousePosition     = new vec2(snapshot.MousePosition.X, snapshot.MousePosition.Y);
            wheelDelta        = snapshot.WheelDelta;

            foreach (KeyEvent keyEvent in snapshot.KeyEvents)
            {
                keyStateDict[keyEvent.Key] = keyEvent.Down;

                if (keyEvent.Down)
                {
                    keyDownDict[keyEvent.Key] = true;
                }
                else
                {
                    keyUpDict[keyEvent.Key] = true;
                }
            }

            foreach (MouseEvent mouseEvent in snapshot.MouseEvents)
            {
                mouseStateDict[mouseEvent.MouseButton] = mouseEvent.Down;

                if (mouseEvent.Down)
                {
                    mouseDownDict[mouseEvent.MouseButton] = true;
                }
                else
                {
                    mouseUpDict[mouseEvent.MouseButton] = true;
                }
            }
        }
Beispiel #26
0
    void SyncInput()
    {
        List <StoredInput> testList = new List <StoredInput> ();

        for (int i = 0; i < syncInputHistory.Count; i++)
        {
            InputSnapshot snapshot = new InputSnapshot();
            snapshot.Copy(syncInputHistory[i].snapshot);

            testList.Add(new StoredInput(
                             syncInputHistory[i].tick,
                             syncInputHistory[i].playerID,
                             snapshot));
        }

        _inputContext.ReplaceInputHistory(testList);

        if (_timeContext.tick.value < lockstepTick)
        {
            _timeContext.ReplaceJumpInTime(lockstepTick);
        }
    }
Beispiel #27
0
        public void UpdateFrameInput(InputSnapshot snapshot)
        {
            CurrentSnapshot = snapshot;
            _newKeysThisFrame.Clear();
            _newMouseButtonsThisFrame.Clear();

            MouseDelta = CurrentSnapshot.MousePosition - _previousSnapshotMousePosition;
            _previousSnapshotMousePosition = CurrentSnapshot.MousePosition;

            IReadOnlyList <KeyEvent> keyEvents = snapshot.KeyEvents;

            for (int i = 0; i < keyEvents.Count; i++)
            {
                KeyEvent ke = keyEvents[i];
                if (ke.Down)
                {
                    KeyDown(ke.Key);
                }
                else
                {
                    KeyUp(ke.Key);
                }
            }
            IReadOnlyList <MouseEvent> mouseEvents = snapshot.MouseEvents;

            for (int i = 0; i < mouseEvents.Count; i++)
            {
                MouseEvent me = mouseEvents[i];
                if (me.Down)
                {
                    MouseDown(me.MouseButton);
                }
                else
                {
                    MouseUp(me.MouseButton);
                }
            }
        }
Beispiel #28
0
        public void Update()
        {
            UpdatePosition();
            InputSnapshot snapshot = _window.PumpEvents();

            if (!_window.Exists)
            {
                return;
            }

            _controller.Update(1f / 60f, snapshot);

            SubmitUi(snapshot);

            _cl.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(0, 0, 0, 255));
            _controller.Render(_gd, _cl);
            _cl.End();

            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
        }
Beispiel #29
0
        protected override void Update(InputSnapshot snapshot, float elapsedSeconds)
        {
            base.Update(snapshot, elapsedSeconds);

            if (targetFps >= 1)
            {
                TargetTicksPerFrame = System.Diagnostics.Stopwatch.Frequency / targetFps;
            }

            if (targetTps >= 10 && targetTps > targetFps)
            {
                TargetTicksPerUpdate = System.Diagnostics.Stopwatch.Frequency / targetTps;
            }

            if (ImGui.Begin("Settings"))
            {
                if (ImGui.BeginMenu("Application Settings"))
                {
                    ImGui.InputInt("Target FPS", ref targetFps);
                    ImGui.InputInt("Target TPS", ref targetTps);
                }
            }
        }
Beispiel #30
0
        public void Run()
        {
            long      previousFrameTicks = 0;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (_window.Exists)
            {
                long   currentFrameTicks = sw.ElapsedTicks;
                double deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;

                while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds)
                {
                    currentFrameTicks = sw.ElapsedTicks;
                    deltaSeconds      = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency;
                }

                previousFrameTicks = currentFrameTicks;

                InputSnapshot snapshot = null;
                Sdl2Events.ProcessEvents();
                Sdl2Events.ProcessEvents();
                Sdl2Events.ProcessEvents();
                snapshot = _window.PumpEvents();
                InputTracker.UpdateFrameInput(snapshot, _window);
                Update((float)deltaSeconds);
                if (!_window.Exists)
                {
                    break;
                }

                Draw();
            }

            DestroyAllObjects();
            _gd.Dispose();
        }
    public virtual void OnControllerInput(InputEntity e, InputSnapshot s)
    {
        if (!this.gameObject.activeInHierarchy)
        {
            return;
        }
        if (e.controllerID.id != playerId && playerId >= 0)
        {
            return;
        }

        //handle axis movement from the player
        Move(
            s.GetAxis(Axes.MoveHorizontal).ToFloat(),
            s.GetAxis(Axes.MoveVertical).ToFloat());

        //handle a button
        AButton(s.GetButton(Buttons.A));

        //handle b button
        BButton(s.GetButton(Buttons.B));

        //handle a button
        RButton(s.GetButton(Buttons.R));

        //handle b button
        LButton(s.GetButton(Buttons.L));

        //handle a button
        XButton(s.GetButton(Buttons.X));

        //handle b button
        YButton(s.GetButton(Buttons.Y));

        //handle a button
        StartButton(s.GetButton(Buttons.START));
    }
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     return inputSnapshot.KeyboardState.HasValue && IsActive(inputSnapshot.KeyboardState.Value);
 }
 /// <summary>
 ///     See <see cref="InputBinding.IsActive" />
 /// </summary>
 public abstract bool IsActive(InputSnapshot inputSnapshot);
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     if (!inputSnapshot.MouseState.HasValue)
         return false;
     var mouseState = inputSnapshot.MouseState.Value;
     ButtonState buttonState;
     switch (Button)
     {
         case MouseButton.Left:
             buttonState = mouseState.LeftButton;
             break;
         case MouseButton.Right:
             buttonState = mouseState.RightButton;
             break;
         case MouseButton.Middle:
             buttonState = mouseState.MiddleButton;
             break;
         default:
             buttonState = ButtonState.Released;
             break;
     }
     return buttonState == ButtonState.Pressed;
 }
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     if (!inputSnapshot.GamePadState.HasValue)
         return false;
     return inputSnapshot.GamePadState.Value.IsButtonDown(Button);
 }
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     if (!inputSnapshot.GamePadState.HasValue)
         return false;
     var gamePadState = inputSnapshot.GamePadState.Value;
     var triggerMag = Trigger == Trigger.Left ? gamePadState.Triggers.Left : gamePadState.Triggers.Right;
     return triggerMag >= inputSnapshot.InputSettings.TriggerThreshold;
 }
        public override bool IsActive(InputSnapshot inputSnapshot)
        {
            if (!inputSnapshot.GamePadState.HasValue)
                return false;

            var gamePadState = inputSnapshot.GamePadState.Value;
            var settings = inputSnapshot.InputSettings;

            Vector2 gamepadThumbstick = Thumbstick == Thumbstick.Left
                                            ? gamePadState.ThumbSticks.Left
                                            : gamePadState.ThumbSticks.Right;
            bool isActive = false;
            switch (Direction)
            {
                case ThumbstickDirection.Up:
                    isActive = (gamepadThumbstick.Y >= settings.ThumbstickThreshold);
                    break;
                case ThumbstickDirection.Down:
                    isActive = (gamepadThumbstick.Y <= -settings.ThumbstickThreshold);
                    break;
                case ThumbstickDirection.Left:
                    isActive = (gamepadThumbstick.X <= -settings.ThumbstickThreshold);
                    break;
                case ThumbstickDirection.Right:
                    isActive = (gamepadThumbstick.X >= settings.ThumbstickThreshold);
                    break;
                default:
                    break;
            }
            return isActive;
        }
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     return inputSnapshot.KeyboardState.HasValue && inputSnapshot.KeyboardState.Value.IsKeyDown(Key);
 }
 public void Update()
 {
     _previous = InputSnapshot.With(_current.KeyboardState);
     _current = InputSnapshot.With(Keyboard.GetState());
     _frame++;
 }
 public override bool IsActive(InputSnapshot inputSnapshot)
 {
     if (!inputSnapshot.GamePadState.HasValue)
         return false;
     var gamePadState = inputSnapshot.GamePadState.Value;
     Vector2 gamepadThumbstickMag = Thumbstick == Thumbstick.Left
                                        ? gamePadState.ThumbSticks.Left
                                        : gamePadState.ThumbSticks.Right;
     return gamepadThumbstickMag.Length() >= inputSnapshot.InputSettings.ThumbstickThreshold;
 }