Move helper functions into cpp file

This commit is contained in:
2021-04-17 13:54:48 +02:00
parent 781625f525
commit b48624c245
8 changed files with 50 additions and 37 deletions

View File

@@ -17,6 +17,7 @@ add_executable(Fall-Fever
Screen.cpp
Menu.cpp
JsonParser.cpp
Helper.cpp
)
target_link_libraries(

View File

@@ -12,7 +12,7 @@
#include <imgui_impl_opengl3.h>
#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();

View File

@@ -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;

View File

@@ -1,11 +1,7 @@
#pragma once
#include "Helper.h"
#include <stdint.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <chrono>
#include <GLFW/glfw3.h>
#ifdef __linux__
#include <unistd.h>
@@ -14,20 +10,18 @@
#include <windows.h>
#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<float> 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;
}

25
src/Helper.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <stdint.h>
#include <string>
#include <chrono>
#include <GLFW/glfw3.h>
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<float> duration;
};
}

View File

@@ -1,7 +1,7 @@
#include "Menu.h"
#include "JsonParser.h"
#include "eventActions.h"
#include "helper.h"
#include "Helper.h"
#include <iostream>

View File

@@ -1,5 +1,5 @@
#include "Screen.h"
#include "helper.h"
#include "Helper.h"
uint32_t Screen::id_counter = 0;

View File

@@ -4,7 +4,7 @@
#include "Window.h"
#include "eventActions.h"
#include "defines.h"
#include "helper.h"
#include "Helper.h"
Window::Window()
{