|
@@ -1,51 +1,53 @@
|
|
|
+#include "GLFW/glfw3.h"
|
|
|
+
|
|
|
#include "client/input/Controller.h"
|
|
|
#include "client/rendering/Engine.h"
|
|
|
|
|
|
-Controller::Controller()
|
|
|
- : left(GLFW_KEY_A, "Left"), right(GLFW_KEY_D, "Right"), up(GLFW_KEY_W, "X"),
|
|
|
- down(GLFW_KEY_S, "Y"), jump(GLFW_KEY_SPACE, "L"),
|
|
|
- sneak(GLFW_KEY_LEFT_SHIFT, "R"), camLeft(GLFW_KEY_LEFT, "Start"),
|
|
|
- camRight(GLFW_KEY_RIGHT, "Select"), camUp(GLFW_KEY_UP, "Left"),
|
|
|
- camDown(GLFW_KEY_DOWN, "Right"),
|
|
|
- leftClick(GLFW_MOUSE_BUTTON_LEFT, "Left Click"),
|
|
|
- rightClick(GLFW_MOUSE_BUTTON_RIGHT, "Right Click") {
|
|
|
-}
|
|
|
+Window::Controls::ButtonId Controller::left = 0;
|
|
|
+Window::Controls::ButtonId Controller::right = 0;
|
|
|
+Window::Controls::ButtonId Controller::up = 0;
|
|
|
+Window::Controls::ButtonId Controller::down = 0;
|
|
|
+Window::Controls::ButtonId Controller::jump = 0;
|
|
|
+Window::Controls::ButtonId Controller::sneak = 0;
|
|
|
+Window::Controls::ButtonId Controller::camLeft = 0;
|
|
|
+Window::Controls::ButtonId Controller::camRight = 0;
|
|
|
+Window::Controls::ButtonId Controller::camUp = 0;
|
|
|
+Window::Controls::ButtonId Controller::camDown = 0;
|
|
|
+Window::Controls::ButtonId Controller::leftClick = 0;
|
|
|
+Window::Controls::ButtonId Controller::rightClick = 0;
|
|
|
|
|
|
void Controller::init() {
|
|
|
- Buttons& b = Engine::getButtons();
|
|
|
- b.add(left);
|
|
|
- b.add(right);
|
|
|
- b.add(up);
|
|
|
- b.add(down);
|
|
|
- b.add(jump);
|
|
|
- b.add(sneak);
|
|
|
- b.add(camLeft);
|
|
|
- b.add(camRight);
|
|
|
- b.add(camUp);
|
|
|
- b.add(camDown);
|
|
|
-
|
|
|
- b.addMouse(leftClick);
|
|
|
- b.addMouse(rightClick);
|
|
|
-
|
|
|
- b.mapGamepadAxis(left, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
|
|
|
- b.mapGamepadAxis(right, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
|
|
|
- b.mapGamepadAxis(up, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
|
|
|
- b.mapGamepadAxis(down, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
|
|
|
+ left = Window::Controls::add("Left");
|
|
|
+ Window::Controls::bindKey(left, GLFW_KEY_A);
|
|
|
+ right = Window::Controls::add("Right");
|
|
|
+ Window::Controls::bindKey(right, GLFW_KEY_D);
|
|
|
+ up = Window::Controls::add("Up");
|
|
|
+ Window::Controls::bindKey(up, GLFW_KEY_W);
|
|
|
+ down = Window::Controls::add("Down");
|
|
|
+ Window::Controls::bindKey(down, GLFW_KEY_S);
|
|
|
+ jump = Window::Controls::add("Jump");
|
|
|
+ Window::Controls::bindKey(jump, GLFW_KEY_SPACE);
|
|
|
+ sneak = Window::Controls::add("Sneak");
|
|
|
+ Window::Controls::bindKey(sneak, GLFW_KEY_LEFT_SHIFT);
|
|
|
+ camLeft = Window::Controls::add("Camera Left");
|
|
|
+ Window::Controls::bindKey(camLeft, GLFW_KEY_LEFT);
|
|
|
+ camRight = Window::Controls::add("Camera Right");
|
|
|
+ Window::Controls::bindKey(camRight, GLFW_KEY_RIGHT);
|
|
|
+ camUp = Window::Controls::add("Camera Up");
|
|
|
+ Window::Controls::bindKey(camUp, GLFW_KEY_UP);
|
|
|
+ camDown = Window::Controls::add("Camera Down");
|
|
|
+ Window::Controls::bindKey(camDown, GLFW_KEY_DOWN);
|
|
|
|
|
|
- b.mapGamepadAxis(camUp, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
|
|
|
- b.mapGamepadAxis(camDown, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
|
|
|
- b.mapGamepadAxis(camLeft, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
|
|
|
- b.mapGamepadAxis(camRight, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
|
|
|
+ leftClick = Window::Controls::add("Left Click");
|
|
|
+ Window::Controls::bindMouse(leftClick, GLFW_MOUSE_BUTTON_LEFT);
|
|
|
+ rightClick = Window::Controls::add("Right Click");
|
|
|
+ Window::Controls::bindMouse(leftClick, GLFW_MOUSE_BUTTON_RIGHT);
|
|
|
}
|
|
|
|
|
|
-Vector2 Controller::getMouse() const {
|
|
|
- Buttons& b = Engine::getButtons();
|
|
|
- return Vector2(static_cast<float>(b.getMouseX()),
|
|
|
- static_cast<float>(b.getMouseY()));
|
|
|
+bool Controller::wasReleased(Window::Controls::ButtonId id) {
|
|
|
+ return Window::Controls::wasReleased(id);
|
|
|
}
|
|
|
|
|
|
-Vector2 Controller::getMouseChange() const {
|
|
|
- Buttons& b = Engine::getButtons();
|
|
|
- return Vector2(static_cast<float>(b.getMouseX() - b.getLastMouseX()),
|
|
|
- static_cast<float>(b.getMouseY() - b.getLastMouseY()));
|
|
|
+bool Controller::isDown(Window::Controls::ButtonId id) {
|
|
|
+ return Window::Controls::isDown(id);
|
|
|
}
|