Browse Source

Rename inputcodes to keycodes

master
Riyyi 4 years ago
parent
commit
e0510a3f6f
  1. 4
      inferno/src/inferno/application.cpp
  2. 4
      inferno/src/inferno/keycodes.cpp
  3. 2
      inferno/src/inferno/keycodes.h
  4. 30
      inferno/src/inferno/script/cameracontroller.cpp
  5. 4
      inferno/src/inferno/script/registration.cpp
  6. 1
      inferno/src/inferno/systems/camera.cpp
  7. 4
      inferno/src/inferno/window.cpp

4
inferno/src/inferno/application.cpp

@ -5,7 +5,7 @@
#include "inferno/event/event.h"
#include "inferno/event/keyevent.h"
#include "inferno/event/mouseevent.h"
#include "inferno/inputcodes.h"
#include "inferno/keycodes.h"
#include "inferno/io/input.h"
#include "inferno/io/log.h"
#include "inferno/render/buffer.h"
@ -202,7 +202,7 @@ namespace Inferno {
e.getKey());
// Stop the main loop on 'Escape' keypress
if (e.getKey() == KeyCode("GLFW_KEY_ESCAPE")) {
if (e.getKey() == keyCode("GLFW_KEY_ESCAPE")) {
m_window->setShouldClose(true);
}

4
inferno/src/inferno/inputcodes.cpp → inferno/src/inferno/keycodes.cpp

@ -4,7 +4,7 @@
#include "GLFW/glfw3.h"
#include "inferno/assert.h"
#include "inferno/inputcodes.h"
#include "inferno/keycodes.h"
namespace Inferno {
@ -134,7 +134,7 @@ namespace Inferno {
// -----------------------------------------
int KeyCode(const char* name)
int keyCode(const char* name)
{
ASSERT(keys.find(name) != keys.end(), "keyCode could not find '{}'", name);
return keys.at(name);

2
inferno/src/inferno/inputcodes.h → inferno/src/inferno/keycodes.h

@ -5,7 +5,7 @@
namespace Inferno {
int KeyCode(const char* name);
int keyCode(const char* name);
}

30
inferno/src/inferno/script/cameracontroller.cpp

@ -1,6 +1,6 @@
#include "glm/ext/matrix_transform.hpp" // glm::radians
#include "inferno/inputcodes.h"
#include "inferno/keycodes.h"
#include "inferno/io/input.h"
#include "inferno/script/cameracontroller.h"
@ -12,10 +12,10 @@ namespace Inferno {
float cameraRotateSpeed = ROTATE_SPEED * deltaTime;
if (Input::isKeyPressed(KeyCode("GLFW_KEY_Q"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_Q"))) {
transform->rotate.z -= cameraRotateSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_E"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_E"))) {
transform->rotate.z += cameraRotateSpeed;
}
@ -31,19 +31,19 @@ namespace Inferno {
float cameraTranslateSpeed = TRANSLATE_SPEED * deltaTime;
// WASD movement
if (Input::isKeyPressed(KeyCode("GLFW_KEY_W"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_W"))) {
transform->translate.x += -sin(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
transform->translate.y += cos(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_S"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_S"))) {
transform->translate.x -= -sin(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
transform->translate.y -= cos(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_A"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_A"))) {
transform->translate.x -= cos(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
transform->translate.y -= sin(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_D"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_D"))) {
transform->translate.x += cos(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
transform->translate.y += sin(glm::radians(transform->rotate.z)) * cameraTranslateSpeed;
}
@ -52,10 +52,10 @@ namespace Inferno {
float zoomSpeed = ZOOM_SENSITIVITY * deltaTime;
if (Input::isKeyPressed(KeyCode("GLFW_KEY_EQUAL"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_EQUAL"))) {
m_camera->zoomLevel -= zoomSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_MINUS"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_MINUS"))) {
m_camera->zoomLevel += zoomSpeed;
}
m_camera->zoomLevel = std::max(m_camera->zoomLevel, 0.25f);
@ -97,23 +97,23 @@ namespace Inferno {
float cameraSpeed = TRANSLATE_SPEED * deltaTime;
// WASD movement
if (Input::isKeyPressed(KeyCode("GLFW_KEY_W"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_W"))) {
transform->translate += transform->rotate * cameraSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_S"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_S"))) {
transform->translate -= transform->rotate * cameraSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_A"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_A"))) {
transform->translate -= glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_D"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_D"))) {
transform->translate += glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed;
}
// Up / down movement
if (Input::isKeyPressed(KeyCode("GLFW_KEY_SPACE"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_SPACE"))) {
transform->translate.y += cameraSpeed;
}
if (Input::isKeyPressed(KeyCode("GLFW_KEY_LEFT_SHIFT"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_LEFT_SHIFT"))) {
transform->translate.y -= cameraSpeed;
}
}

4
inferno/src/inferno/script/registration.cpp

@ -3,7 +3,7 @@
#include "glm/ext/vector_float4.hpp" // glm::vec4
#include "glm/ext/matrix_transform.hpp" // glm::radians
#include "inferno/inputcodes.h"
#include "inferno/keycodes.h"
#include "inferno/io/input.h"
#include "inferno/scene/components.h"
#include "inferno/script/registration.h"
@ -106,7 +106,7 @@ namespace Inferno {
void Registration::input(sol::state_view& state)
{
state.set_function("keyCode", &KeyCode);
state.set_function("keyCode", &keyCode);
// state["keyCode"] = &KeyCode;
auto input = state.new_usertype<Input>("Input", sol::no_constructor);

1
inferno/src/inferno/systems/camera.cpp

@ -3,7 +3,6 @@
#include "inferno/application.h"
#include "inferno/assert.h"
#include "inferno/inputcodes.h"
#include "inferno/io/input.h"
#include "inferno/io/log.h"
#include "inferno/systems/camera.h"

4
inferno/src/inferno/window.cpp

@ -5,7 +5,7 @@
#include "inferno/event/applicationevent.h"
#include "inferno/event/keyevent.h"
#include "inferno/event/mouseevent.h"
#include "inferno/inputcodes.h"
#include "inferno/keycodes.h"
#include "inferno/io/input.h"
#include "inferno/io/log.h"
#include "inferno/render/context.h"
@ -165,7 +165,7 @@ namespace Inferno {
glfwPollEvents();
// Lock mouse in window
if (Input::isKeyPressed(KeyCode("GLFW_KEY_LEFT_SUPER"))) {
if (Input::isKeyPressed(keyCode("GLFW_KEY_LEFT_SUPER"))) {
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
else {

Loading…
Cancel
Save