From b48624c24594b41137b9664be4fb1b38ae93cf3b Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sat, 17 Apr 2021 13:54:48 +0200 Subject: [PATCH] Move helper functions into cpp file --- src/CMakeLists.txt | 1 + src/Controller.cpp | 6 ++--- src/Controller.h | 2 +- src/{helper.h => Helper.cpp} | 47 +++++++++++++----------------------- src/Helper.h | 25 +++++++++++++++++++ src/Menu.cpp | 2 +- src/Screen.cpp | 2 +- src/Window.cpp | 2 +- 8 files changed, 50 insertions(+), 37 deletions(-) rename src/{helper.h => Helper.cpp} (75%) create mode 100644 src/Helper.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26350aa..cc6cc48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,7 @@ add_executable(Fall-Fever Screen.cpp Menu.cpp JsonParser.cpp + Helper.cpp ) target_link_libraries( diff --git a/src/Controller.cpp b/src/Controller.cpp index e3e3926..094b059 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -12,7 +12,7 @@ #include #endif -#include "helper.h" +#include "Helper.h" #include "Controller.h" #include "VertexArray.h" #include "Texture.h" @@ -150,7 +150,7 @@ void Controller::run() pp_framebuffer->render(); #ifdef _DEBUG - renderImGui(world, world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); + renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); #endif } glfwSwapBuffers(gameWindow->getGLFWwindow()); @@ -238,7 +238,7 @@ void Controller::setMaxFps(uint16_t fps) } #ifdef _DEBUG -void Controller::renderImGui(World *world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows) +void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); diff --git a/src/Controller.h b/src/Controller.h index d3c0f6f..fb11ca3 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -34,7 +34,7 @@ private: ShaderProgram* getShaderProgramByName(const std::string& name); - void renderImGui(World *world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows); + void renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows); private: Window *gameWindow; diff --git a/src/helper.h b/src/Helper.cpp similarity index 75% rename from src/helper.h rename to src/Helper.cpp index 3623cd8..ee550c3 100644 --- a/src/helper.h +++ b/src/Helper.cpp @@ -1,11 +1,7 @@ -#pragma once +#include "Helper.h" -#include #include -#include #include -#include -#include #ifdef __linux__ #include @@ -14,20 +10,18 @@ #include #endif -namespace Helper -{ -static void sleep(uint32_t us) +void Helper::sleep(uint32_t us) { #ifdef __linux__ usleep(us); #endif #ifdef _WIN32 - // I really don't know why I have to divide by 2000 and not 1000 but this way it works even on Windows + // I don't know why I have to divide by 2000 and not 1000 but this way it works even on Windows Sleep(us / 2000); #endif } -static void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { (void)length; (void)userParam; @@ -136,24 +130,17 @@ static void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum seve << std::endl; } -class Timer { -public: - Timer(const std::string& name) : name(name) { - start = std::chrono::high_resolution_clock::now(); - } - - ~Timer() { - end = std::chrono::high_resolution_clock::now(); - - duration = end - start; - float ms = duration.count() * 1000.0f; - - std::cout << "Timer " << name << " took " << ms << "ms!" << std::endl; - } -private: - std::string name; - std::chrono::high_resolution_clock::time_point start, end; - std::chrono::duration duration; -}; - +Helper::Timer::Timer(const std::string& name) : name(name) +{ + start = std::chrono::high_resolution_clock::now(); +} + +Helper::Timer::~Timer() +{ + end = std::chrono::high_resolution_clock::now(); + + duration = end - start; + float ms = duration.count() * 1000.0f; + + std::cout << "Timer " << name << " took " << ms << "ms!" << std::endl; } diff --git a/src/Helper.h b/src/Helper.h new file mode 100644 index 0000000..8e1ebf4 --- /dev/null +++ b/src/Helper.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include + +namespace Helper +{ +void sleep(uint32_t us); + +void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); + +class Timer { +public: + Timer(const std::string& name); + ~Timer(); + +private: + std::string name; + std::chrono::high_resolution_clock::time_point start, end; + std::chrono::duration duration; +}; + +} diff --git a/src/Menu.cpp b/src/Menu.cpp index d016950..9b3a8fb 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1,7 +1,7 @@ #include "Menu.h" #include "JsonParser.h" #include "eventActions.h" -#include "helper.h" +#include "Helper.h" #include diff --git a/src/Screen.cpp b/src/Screen.cpp index 2f97879..fe7fbb2 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1,5 +1,5 @@ #include "Screen.h" -#include "helper.h" +#include "Helper.h" uint32_t Screen::id_counter = 0; diff --git a/src/Window.cpp b/src/Window.cpp index 45d7617..fd39225 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -4,7 +4,7 @@ #include "Window.h" #include "eventActions.h" #include "defines.h" -#include "helper.h" +#include "Helper.h" Window::Window() {