Fix VSync, Fix Mouse Input (Yay!), Add MAXFPS env

This commit is contained in:
2021-01-13 19:40:11 +01:00
parent 0370a2e871
commit 37542ab831
6 changed files with 31 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ Size=894,195
Collapsed=0
[Window][Debug Utils]
Pos=18,8
Pos=3,6
Size=791,379
Collapsed=0

View File

@@ -251,6 +251,12 @@ ShaderProgram* Controller::getShaderProgramByName(std::vector<ShaderProgram*> sh
return nullptr;
}
void Controller::setMaxFps(uint16_t fps)
{
MAX_FPS = fps;
}
#ifdef _DEBUG
void Controller::renderImGui(World &world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows)
{

View File

@@ -24,6 +24,8 @@ public:
static ShaderProgram* getShaderProgramByName(std::vector<ShaderProgram*> shaderPrograms, const char *name);
static void error_callback(int error, const char *description);
void setMaxFps(uint16_t fps);
private:
void limit_framerate();
@@ -46,7 +48,7 @@ private:
Menu *menu;
const uint16_t MAX_FPS = 60;
uint16_t MAX_FPS = 60;
double deltaTime;
float exposure = 1.0f;

View File

@@ -7,7 +7,7 @@ double EventHandler::cameraMouseActionRegister[CAMERA_MOUSE_ACTION_NUM_ITEMS] =
bool EventHandler::windowActionRegister[WINDOW_ACTION_NUM_ITEMS] = {0};
bool EventHandler::firstMouseInput = 1;
float EventHandler::mouseSensitivity = 0.5f;
float EventHandler::mouseSensitivity = 0.15f;
EventHandler::EventHandler(GLFWwindow *p_window) :
@@ -113,8 +113,8 @@ void EventHandler::mouse_callback(GLFWwindow *window, double xpos, double ypos)
deltaCursorPosX *= mouseSensitivity;
deltaCursorPosY *= mouseSensitivity;
cameraMouseActionRegister[cameraMouseDeltaX] = deltaCursorPosX;
cameraMouseActionRegister[cameraMouseDeltaY] = deltaCursorPosY;
cameraMouseActionRegister[cameraMouseDeltaX] += deltaCursorPosX;
cameraMouseActionRegister[cameraMouseDeltaY] += deltaCursorPosY;
}
bool * EventHandler::getCameraActionRegister()

View File

@@ -37,27 +37,24 @@ Window::Window()
// Enable multisampling (a bit redundant because most graphics drivers do this automatically)
glEnable(GL_MULTISAMPLE);
// Disable VSync since my sleep function handles this
glfwSwapInterval(0);
#ifdef _DEBUG
// Disable mouse cursor
#ifdef _DEBUG
mouseCatched = false;
#endif
setCatchedCursor(mouseCatched);
// Enable primitive gamma correction
// glEnable(GL_FRAMEBUFFER_SRGB);
// Maximize in release build
#ifndef _DEBUG
glfwMaximizeWindow(window);
#endif
#ifdef _DEBUG
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(openGLDebugCallback, NULL);
#else
// Maximize in release build
glfwMaximizeWindow(window);
#endif
setCatchedCursor(mouseCatched);
glViewport(0, 0, width, height);

View File

@@ -14,9 +14,16 @@ int main(int argc, char **argv)
std::cout << "[Debug Mode]" << std::endl;
#endif
// Create window
// Create controller
Controller *mainController = new Controller();
const char* fps_env = std::getenv("MAXFPS");
if(fps_env) {
uint16_t maxfps = std::stoul(fps_env);
mainController->setMaxFps(maxfps);
std::cout << "[Warning] Default max FPS overridden with " << maxfps << " by environment." << std::endl;
}
mainController->run();
delete mainController;