separate input handling from main
parent
4c46811a25
commit
950e8c68ab
|
@ -0,0 +1,16 @@
|
|||
#ifndef CONTROLS_H
|
||||
#define CONTROLS_H
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "worldupdatemessage.h"
|
||||
|
||||
namespace controls{
|
||||
void init();
|
||||
void update(GLFWwindow* window);
|
||||
|
||||
WorldUpdateMsgQueue& getWorldUpdateQueue();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,6 +3,5 @@
|
|||
|
||||
void framebuffer_size_callback(GLFWwindow *, int, int);
|
||||
void mouse_callback(GLFWwindow *window, double xpos, double ypos);
|
||||
void processInput(GLFWwindow *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
project(OpenGLTest)
|
||||
|
||||
set(SOURCE_FILES main.cpp chunk.cpp chunkmanager.cpp chunkmesher.cpp chunkgenerator.cpp
|
||||
set(SOURCE_FILES main.cpp controls.cpp chunk.cpp chunkmanager.cpp chunkmesher.cpp chunkgenerator.cpp
|
||||
debugwindow.cpp renderer.cpp spacefilling.cpp stb_image.cpp utils.cpp OpenSimplexNoise.cpp)
|
||||
|
||||
add_executable(OpenGLTest ${SOURCE_FILES})
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include "controls.hpp"
|
||||
#include "renderer.hpp"
|
||||
|
||||
namespace controls{
|
||||
WorldUpdateMsgQueue MsgQueue;
|
||||
float lastBlockPick=0.0;
|
||||
bool blockpick = false;
|
||||
bool cursor = false;
|
||||
|
||||
void init(){
|
||||
}
|
||||
|
||||
void update(GLFWwindow* window){
|
||||
// Reset blockping timeout if 200ms have passed
|
||||
if(glfwGetTime() - lastBlockPick > 0.1) blockpick = false;
|
||||
|
||||
if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS && !blockpick){
|
||||
//chunkmanager::blockpick(false);
|
||||
blockpick=true;
|
||||
lastBlockPick=glfwGetTime();
|
||||
}
|
||||
|
||||
if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS && !blockpick){
|
||||
//chunkmanager::blockpick(true);
|
||||
blockpick=true;
|
||||
lastBlockPick=glfwGetTime();
|
||||
}
|
||||
|
||||
// Reset blockpicking if enough time has passed
|
||||
if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE) blockpick = false;
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_F2) == GLFW_PRESS) renderer::saveScreenshot();
|
||||
if(glfwGetKey(window, GLFW_KEY_F3) == GLFW_PRESS) renderer::saveScreenshot(true);
|
||||
if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
|
||||
cursor = !cursor;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, cursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
WorldUpdateMsgQueue& getWorldUpdateQueue(){ return MsgQueue; }
|
||||
};
|
Loading…
Reference in New Issue