InputManager finish
This commit is contained in:
@ -17,4 +17,5 @@ target_include_directories(${DAWN_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(host)
|
||||
add_subdirectory(host)
|
||||
add_subdirectory(input)
|
@ -54,6 +54,7 @@ int32_t DawnHost::init(DawnGame &game) {
|
||||
auto result = game.init();
|
||||
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
||||
|
||||
// Override the defaults
|
||||
game.renderManager.backBuffer.setSize(
|
||||
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT
|
||||
@ -61,6 +62,7 @@ int32_t DawnHost::init(DawnGame &game) {
|
||||
|
||||
// Set up event listeners
|
||||
glfwSetWindowSizeCallback(this->data->window, &glfwOnResize);
|
||||
glfwSetKeyCallback(this->data->window, &glfwOnKey);
|
||||
|
||||
return DAWN_HOST_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
@ -139,4 +141,27 @@ void glfwOnResize(
|
||||
(float_t)width,
|
||||
(float_t)height
|
||||
);
|
||||
}
|
||||
|
||||
void glfwOnKey(
|
||||
GLFWwindow *window,
|
||||
int32_t key,
|
||||
int32_t scancode,
|
||||
int32_t action,
|
||||
int32_t mods
|
||||
) {
|
||||
if(DAWN_HOST == nullptr) return;
|
||||
|
||||
// Determine Value
|
||||
float_t value;
|
||||
if(action == GLFW_PRESS) {
|
||||
value = 1.0f;
|
||||
} else if(action == GLFW_RELEASE) {
|
||||
value = 0.0f;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine the input axis
|
||||
DAWN_HOST->game->inputManager.rawInputValues[key] = value;
|
||||
}
|
@ -26,4 +26,8 @@ namespace Dawn {
|
||||
|
||||
// GLFW Callbacks
|
||||
void glfwOnError(int error, const char* description);
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
||||
void glfwOnKey(
|
||||
GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
);
|
10
src/dawnglfw/input/CMakeLists.txt
Normal file
10
src/dawnglfw/input/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
InputManager.cpp
|
||||
)
|
20
src/dawnglfw/input/InputManager.cpp
Normal file
20
src/dawnglfw/input/InputManager.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "InputManager.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
InputManager::InputManager(DawnGame &game) : IInputManager<int32_t>(game) {
|
||||
|
||||
}
|
||||
|
||||
float_t InputManager::getInputValue(int32_t axis) {
|
||||
auto exist = this->rawInputValues.find(axis);
|
||||
if(exist == this->rawInputValues.end()) return 0.0f;
|
||||
|
||||
return exist->second;
|
||||
}
|
19
src/dawnglfw/input/InputManager.hpp
Normal file
19
src/dawnglfw/input/InputManager.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "input/_InputManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class InputManager : public IInputManager<int32_t> {
|
||||
protected:
|
||||
float_t getInputValue(int32_t axis) override;
|
||||
|
||||
public:
|
||||
std::map<int32_t, float_t> rawInputValues;
|
||||
|
||||
InputManager(DawnGame &game);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user