Refactor some code
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../Base/IInitable.hpp"
|
||||
#include "../../Base/ITickable.hpp"
|
||||
#include "../../Base/ICloseable.hpp"
|
||||
#include "../../Base/IPlatform.hpp"
|
||||
#include "InputDeviceGLFW.hpp"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <array>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
@@ -18,7 +24,7 @@ namespace openVulkanoCpp
|
||||
friend WindowGLFW;
|
||||
static InputProviderGLFW* INSTANCE;
|
||||
|
||||
std::array<ControllerGLFW, GLFW_JOYSTICK_LAST> controllers = {};
|
||||
std::array<ControllerGLFW, 16> controllers = {};
|
||||
MouseGLFW mouse;
|
||||
KeyboardGLFW keyboard;
|
||||
uint8_t mouseButtons = 0;
|
||||
@@ -27,73 +33,23 @@ namespace openVulkanoCpp
|
||||
public:
|
||||
void Init() override;
|
||||
|
||||
void Close() override
|
||||
{
|
||||
glfwSetJoystickCallback(NULL);
|
||||
INSTANCE = nullptr;
|
||||
}
|
||||
void Close() override;
|
||||
|
||||
void PreTick()
|
||||
{
|
||||
mouse.ClearAxes();
|
||||
keyboard.PreTick();
|
||||
}
|
||||
void PreTick();
|
||||
|
||||
void Tick() override
|
||||
{
|
||||
for(ControllerGLFW& controller : controllers)
|
||||
{
|
||||
controller.Tick();
|
||||
}
|
||||
mouse.UpdateButtons(mouseButtons);
|
||||
if (activeWindowChanged)
|
||||
{
|
||||
mouse.ClearAxes();
|
||||
activeWindowChanged = false;
|
||||
}
|
||||
}
|
||||
void Tick() override;
|
||||
|
||||
void SetMouseButton(int button, bool state)
|
||||
{
|
||||
const uint8_t bit = 1 << button;
|
||||
if (state)
|
||||
{
|
||||
mouseButtons |= bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseButtons ^= bit;
|
||||
}
|
||||
}
|
||||
void SetMouseButton(int button, bool state);
|
||||
|
||||
void SetKeyboardKey(IWindow* window, int key, int scanCode, int action, int mods);
|
||||
|
||||
void MouseEnterExitWindow(IWindow* window)
|
||||
{
|
||||
activeWindowChanged = true;
|
||||
mouse.UpdateActiveWindow(window);
|
||||
keyboard.UpdateActiveWindow(window);
|
||||
}
|
||||
void MouseEnterExitWindow(IWindow* window);
|
||||
|
||||
void OnJoystickConnect(int joystickId);
|
||||
|
||||
void OnJoystickDisconnect(int joystickId);
|
||||
|
||||
static void JoystickCallback(int joystickId, int joystickEvent)
|
||||
{
|
||||
if (joystickEvent == GLFW_CONNECTED)
|
||||
{
|
||||
INSTANCE->OnJoystickConnect(joystickId);
|
||||
}
|
||||
else if (joystickEvent == GLFW_DISCONNECTED)
|
||||
{
|
||||
INSTANCE->OnJoystickDisconnect(joystickId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::INPUT->warn("Unknown GLFW joystick event {0} for joystick {1}", joystickEvent, joystickId);
|
||||
}
|
||||
}
|
||||
static void JoystickCallback(int joystickId, int joystickEvent);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user