From 979ae4686f23ba68a0484bf5ea011df4aebb6f40 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sun, 4 Jul 2021 23:44:30 +0200 Subject: [PATCH] Refactor includes --- src/Camera.h | 4 ++-- src/Controller.cpp | 9 ++++++++ src/Controller.h | 20 +++++++++-------- src/Entity.cpp | 12 +++++------ src/Entity.h | 9 ++++---- src/EventHandler.cpp | 1 + src/EventHandler.h | 8 +------ src/FrameBuffer.cpp | 3 +++ src/FrameBuffer.h | 5 +++-- src/Helper.h | 2 +- src/JsonParser.cpp | 7 ++++++ src/JsonParser.h | 15 +++++++------ src/Light.cpp | 1 + src/Light.h | 5 +++-- src/Menu.cpp | 5 +++++ src/Menu.h | 11 ++++++---- src/Mesh.cpp | 2 ++ src/Mesh.h | 9 ++++---- src/Model.cpp | 3 +++ src/Model.h | 6 +++++- src/Screen.cpp | 5 +++++ src/Screen.h | 10 +++++---- src/ShaderProgram.cpp | 4 ++-- src/Texture.cpp | 1 + src/Texture.h | 4 ++-- src/VertexArray.cpp | 6 +++--- src/VertexArray.h | 5 +++-- src/Widget.cpp | 5 +++++ src/Widget.h | 13 +++++++----- src/Window.cpp | 39 +++++++++++++++++----------------- src/Window.h | 6 +++--- src/World.cpp | 6 ++++++ src/World.h | 21 ++++++++++++------ src/definitions/eventActions.h | 8 +++++++ 34 files changed, 175 insertions(+), 95 deletions(-) diff --git a/src/Camera.h b/src/Camera.h index 29c556f..cb38399 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -1,7 +1,7 @@ #pragma once -#include "ShaderProgram.h" -#include "EventHandler.h" +#include "definitions/eventActions.h" + #include class Camera diff --git a/src/Controller.cpp b/src/Controller.cpp index ccc250e..f777d2f 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -6,6 +6,8 @@ #include #include +#include + #ifdef _DEBUG #include #include @@ -22,6 +24,13 @@ #include "VertexArray.h" #include "Widget.h" #include "World.h" +#include "Menu.h" +#include "Camera.h" +#include "Light.h" +#include "Window.h" +#include "Texture.h" +#include "ShaderProgram.h" +#include "EventHandler.h" Controller::Controller() { diff --git a/src/Controller.h b/src/Controller.h index ade7586..431437f 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -1,14 +1,16 @@ #pragma once -#include "Camera.h" -#include "Entity.h" -#include "EventHandler.h" -#include "FrameBuffer.h" -#include "Light.h" -#include "Menu.h" -#include "ShaderProgram.h" -#include "Window.h" -#include "World.h" +#include +#include +#include + +class ShaderProgram; +class Window; +class EventHandler; +class World; +class Camera; +class Menu; +class FrameBuffer; class Controller { diff --git a/src/Entity.cpp b/src/Entity.cpp index c8844bb..3202958 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -1,4 +1,8 @@ #include "Entity.h" +#include "VertexArray.h" +#include "Mesh.h" +#include "ShaderProgram.h" +#include "Model.h" #include #include @@ -6,9 +10,8 @@ uint32_t Entity::s_idCounter = 0; Entity::Entity(const std::string &name, Model *model, ShaderProgram *shaderProgram) - : m_uniqueName(name), m_model(model), m_shaderProgram(shaderProgram) + : m_uniqueName(name), m_model(model), m_shaderProgram(shaderProgram), m_id(s_idCounter++) { - m_id = s_idCounter++; } void Entity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) @@ -115,11 +118,6 @@ void Entity::setIsLightSource(bool temp) m_isLightSource = temp; } -void Entity::setId(uint32_t id) -{ - this->m_id = id; -} - uint32_t Entity::getId() { return m_id; diff --git a/src/Entity.h b/src/Entity.h index 4d83edf..bf38b7b 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -1,12 +1,14 @@ #pragma once -#include "Model.h" -#include "ShaderProgram.h" #include "Texture.h" #include #include +class VertexArray; +class ShaderProgram; +class Model; + class Entity { public: @@ -25,7 +27,6 @@ public: void setRotation(glm::vec3 axis, float radians); void setScale(float scaleFactor); void setIsLightSource(bool temp); - void setId(uint32_t id); uint32_t getId(); std::string getUniqueName(); @@ -36,7 +37,7 @@ public: private: void updateModelMatrix(); - uint32_t m_id; + const uint32_t m_id; static uint32_t s_idCounter; std::string m_uniqueName; diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 0408e14..eb56bae 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -1,5 +1,6 @@ #include "EventHandler.h" +#include "GLFW/glfw3.h" #include CameraActionMap EventHandler::s_cameraActionMap = {{CameraAction::Forward, false}, {CameraAction::Backward, false}, diff --git a/src/EventHandler.h b/src/EventHandler.h index 0782e7b..49af75e 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -1,15 +1,9 @@ #pragma once -#include -#include - #include "definitions/enumHash.h" #include "definitions/eventActions.h" -typedef std::unordered_map CameraActionMap; -typedef std::unordered_map CameraMouseActionMap; -typedef std::unordered_map WindowActionMap; -typedef std::unordered_map MouseButtonActionMap; +class GLFWwindow; class EventHandler { diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 462ee5a..773f25a 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -1,5 +1,8 @@ #include "FrameBuffer.h" +#include "ShaderProgram.h" +#include "Texture.h" + #include #include diff --git a/src/FrameBuffer.h b/src/FrameBuffer.h index c2e6db9..9e891b6 100644 --- a/src/FrameBuffer.h +++ b/src/FrameBuffer.h @@ -1,9 +1,10 @@ #pragma once -#include "ShaderProgram.h" -#include "Texture.h" #include +class ShaderProgram; +class CubeMap; + class FrameBuffer { public: diff --git a/src/Helper.h b/src/Helper.h index c24ba49..72ea70b 100644 --- a/src/Helper.h +++ b/src/Helper.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/src/JsonParser.cpp b/src/JsonParser.cpp index c344d9c..6e6689e 100644 --- a/src/JsonParser.cpp +++ b/src/JsonParser.cpp @@ -1,4 +1,11 @@ #include "JsonParser.h" +#include "Entity.h" +#include "Light.h" +#include "Model.h" +#include "Screen.h" +#include "ShaderProgram.h" +#include "Texture.h" +#include "Widget.h" #include #include diff --git a/src/JsonParser.h b/src/JsonParser.h index 60b0897..8696a97 100644 --- a/src/JsonParser.h +++ b/src/JsonParser.h @@ -1,15 +1,18 @@ #pragma once -#include "Entity.h" -#include "Light.h" -#include "Model.h" -#include "Screen.h" -#include "ShaderProgram.h" - #include #include #include +class Model; +class Entity; +class Light; +class Screen; +class Skybox; +class ShaderProgram; +class FrameBuffer; +class Widget; + class JsonParser { public: diff --git a/src/Light.cpp b/src/Light.cpp index 01d9a02..ac544e5 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -1,4 +1,5 @@ #include "Light.h" +#include "ShaderProgram.h" #include diff --git a/src/Light.h b/src/Light.h index 25bed6f..a10ad66 100644 --- a/src/Light.h +++ b/src/Light.h @@ -1,11 +1,12 @@ #pragma once #include - -#include "ShaderProgram.h" +#include #define NUM_POINT_LIGHTS 1 +class ShaderProgram; + class Light { public: diff --git a/src/Menu.cpp b/src/Menu.cpp index 6480d97..76b4868 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1,6 +1,11 @@ #include "Menu.h" #include "Helper.h" #include "JsonParser.h" +#include "ShaderProgram.h" +#include "FrameBuffer.h" +#include "Screen.h" +#include "Window.h" +#include "Widget.h" #include "definitions/eventActions.h" #include diff --git a/src/Menu.h b/src/Menu.h index cfcf746..518212d 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -1,12 +1,15 @@ #pragma once +#include "definitions/eventActions.h" + #include #include +#include -#include "FrameBuffer.h" -#include "JsonParser.h" -#include "Screen.h" -#include "EventHandler.h" +class ShaderProgram; +class FrameBuffer; +class Screen; +class Window; class Menu { diff --git a/src/Mesh.cpp b/src/Mesh.cpp index ce7130e..f992847 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -1,4 +1,6 @@ #include "Mesh.h" +#include "Texture.h" +#include "ShaderProgram.h" Mesh::Mesh(std::vector vertices, std::vector indices, std::vector textures) : m_numElements(indices.size()), m_textures(textures), diff --git a/src/Mesh.h b/src/Mesh.h index d147eb8..43e8348 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -1,11 +1,12 @@ #pragma once +#include "definitions/models.h" +#include "VertexArray.h" + #include -#include "ShaderProgram.h" -#include "Texture.h" -#include "VertexArray.h" -#include "definitions/models.h" +class ShaderProgram; +class Texture; class Mesh { diff --git a/src/Model.cpp b/src/Model.cpp index c47ed32..255ce6f 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -1,4 +1,7 @@ #include "Model.h" +#include "Mesh.h" +#include "ShaderProgram.h" +#include "Texture.h" #include #include diff --git a/src/Model.h b/src/Model.h index 201b01e..25b3914 100644 --- a/src/Model.h +++ b/src/Model.h @@ -1,9 +1,13 @@ #pragma once +#include "definitions/models.h" + #include #include -#include "Mesh.h" +class ShaderProgram; +class Mesh; +class Texture; struct TexturePrototype { diff --git a/src/Screen.cpp b/src/Screen.cpp index 9f3887c..d9e0bc1 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1,4 +1,9 @@ #include "Screen.h" +#include "Menu.h" +#include "Widget.h" +#include "FrameBuffer.h" +#include "ShaderProgram.h" +#include "Texture.h" #include "Helper.h" uint32_t Screen::s_idCounter = 0; diff --git a/src/Screen.h b/src/Screen.h index 46b0539..1701208 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -1,12 +1,14 @@ #pragma once +#include +#include #include -#include "FrameBuffer.h" -#include "ShaderProgram.h" -#include "Widget.h" - class Menu; +class Widget; +class FrameBuffer; +class ShaderProgram; +class Texture; class Screen { diff --git a/src/ShaderProgram.cpp b/src/ShaderProgram.cpp index 93dfa40..407e749 100644 --- a/src/ShaderProgram.cpp +++ b/src/ShaderProgram.cpp @@ -1,11 +1,11 @@ +#include "ShaderProgram.h" + #include #include #include #include #include -#include "ShaderProgram.h" - ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &fragmentShaderPath) : m_uniqueName(name) diff --git a/src/Texture.cpp b/src/Texture.cpp index 3236209..ef3561f 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -1,4 +1,5 @@ #include "Texture.h" +#include "ShaderProgram.h" #include #include diff --git a/src/Texture.h b/src/Texture.h index 78e8a4e..ab8e514 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -1,7 +1,5 @@ #pragma once -#include "ShaderProgram.h" - #include "definitions/models.h" #include @@ -9,6 +7,8 @@ #include #include +class ShaderProgram; + // Order is important! enum cubeMapFaces { diff --git a/src/VertexArray.cpp b/src/VertexArray.cpp index 015c6b6..049e018 100644 --- a/src/VertexArray.cpp +++ b/src/VertexArray.cpp @@ -1,9 +1,9 @@ -#include -#include - #include "VertexArray.h" #include "definitions/models.h" +#include +#include + VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices) { glGenVertexArrays(1, &m_VAO); diff --git a/src/VertexArray.h b/src/VertexArray.h index 0fa628b..2e80571 100644 --- a/src/VertexArray.h +++ b/src/VertexArray.h @@ -1,9 +1,10 @@ #pragma once -#include - #include "definitions/models.h" +#include +#include + class VertexArray { public: diff --git a/src/Widget.cpp b/src/Widget.cpp index d1c9dad..feae8e7 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -1,7 +1,12 @@ #include "Widget.h" #include "Menu.h" +#include "Mesh.h" +#include "ShaderProgram.h" +#include "Window.h" #include "VertexArray.h" +#include + Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId) : m_posX(p_x), m_posY(p_y), m_width(p_w), m_height(p_h), m_uniqueName(name), m_callbackId(callbackId) { diff --git a/src/Widget.h b/src/Widget.h index b59d121..7b0076c 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -1,12 +1,15 @@ #pragma once -#include "FrameBuffer.h" -#include "Mesh.h" -#include "Texture.h" -#include "Window.h" -#include "definitions/eventActions.h" +#include "definitions/models.h" + +#include +#include class Menu; +class ShaderProgram; +class Texture; +class Window; +class Mesh; class Widget { diff --git a/src/Window.cpp b/src/Window.cpp index 6abcab7..03ba40f 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1,11 +1,12 @@ -#include -#include - -#include "Helper.h" #include "Window.h" -#include "definitions/eventActions.h" +#include "Helper.h" +#include "ShaderProgram.h" #include "definitions/window.h" +#include +#include +#include + Window::Window() { // Initialize GLFW @@ -28,19 +29,19 @@ Window::Window() glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); #endif - window = glfwCreateWindow(m_width, m_height, "OpenGL", NULL, NULL); - if (!window) { + m_window = glfwCreateWindow(m_width, m_height, "OpenGL", NULL, NULL); + if (!m_window) { std::cout << "Failed to create window" << std::endl; } // Wait for window to maximize (in case) Helper::sleep(1000); - glfwGetWindowPos(window, &m_posX, &m_posY); - glfwGetWindowSize(window, &m_width, &m_height); + glfwGetWindowPos(m_window, &m_posX, &m_posY); + glfwGetWindowSize(m_window, &m_width, &m_height); // Create OpenGL context - glfwMakeContextCurrent(window); + glfwMakeContextCurrent(m_window); // Initialize GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { @@ -81,23 +82,23 @@ Window::Window() Window::~Window() { - glfwDestroyWindow(window); + glfwDestroyWindow(m_window); glfwTerminate(); } bool Window::isWindowResized() { int new_width, new_height, new_posx, new_posy; - glfwGetFramebufferSize(window, &new_width, &new_height); - glfwGetWindowPos(window, &new_posx, &new_posy); + glfwGetFramebufferSize(m_window, &new_width, &new_height); + glfwGetWindowPos(m_window, &new_posx, &new_posy); return !(new_width == m_width && new_height == m_height && new_posx == m_posX && new_posy == m_posY); } void Window::updateWindowDimensions() { - glfwGetFramebufferSize(window, &m_width, &m_height); - glfwGetWindowPos(window, &m_posX, &m_posY); + glfwGetFramebufferSize(m_window, &m_width, &m_height); + glfwGetWindowPos(m_window, &m_posX, &m_posY); glViewport(0, 0, m_width, m_height); } @@ -105,9 +106,9 @@ void Window::updateWindowDimensions() void Window::setCatchedCursor(bool value) { if (value) { - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); } else { - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } } @@ -130,7 +131,7 @@ void Window::handleWindowActionMap(WindowActionMap &windowActionMap) } if (windowActionMap.at(WindowAction::WindowShouldClose)) { - glfwSetWindowShouldClose(window, true); + glfwSetWindowShouldClose(m_window, true); } } @@ -149,7 +150,7 @@ void Window::framebuffer_size_callback(GLFWwindow *window, int width, int height GLFWwindow *Window::getGLFWwindow() { - return window; + return m_window; } int Window::getWindowWidth() diff --git a/src/Window.h b/src/Window.h index b417ca1..4d13aa4 100644 --- a/src/Window.h +++ b/src/Window.h @@ -1,8 +1,8 @@ #pragma once -#include "EventHandler.h" +#include "definitions/eventActions.h" -#include +class GLFWwindow; class Window { @@ -27,7 +27,7 @@ private: static void framebuffer_size_callback(GLFWwindow *window, int width, int height); void setCatchedCursor(bool value); - GLFWwindow *window; + GLFWwindow *m_window; int m_posX, m_posY; int m_width, m_height; diff --git a/src/World.cpp b/src/World.cpp index d08f878..762295a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,6 +1,12 @@ #include "World.h" +#include "Entity.h" #include "Controller.h" +#include "Model.h" +#include "Light.h" #include "JsonParser.h" +#include "Camera.h" +#include "Texture.h" +#include "ShaderProgram.h" #include diff --git a/src/World.h b/src/World.h index c111947..8c700a2 100644 --- a/src/World.h +++ b/src/World.h @@ -1,12 +1,21 @@ #pragma once -#include - -#include "Camera.h" -#include "Entity.h" #include "FrameBuffer.h" -#include "Light.h" -#include "ShaderProgram.h" + +#include +#include + +#include +#include + +class Camera; +class Entity; +class Light; +class PointLight; +class DirectionalLight; +class ShaderProgram; +class Skybox; +class Model; class World { diff --git a/src/definitions/eventActions.h b/src/definitions/eventActions.h index 02bd497..7ee1786 100644 --- a/src/definitions/eventActions.h +++ b/src/definitions/eventActions.h @@ -1,5 +1,8 @@ #pragma once +#include "enumHash.h" +#include + enum class CameraAction { Up, @@ -33,3 +36,8 @@ enum class MouseButtonAction MiddleClicked, MOUSE_BUTTON_ACTION_NUM_ITEMS }; + +typedef std::unordered_map CameraActionMap; +typedef std::unordered_map CameraMouseActionMap; +typedef std::unordered_map WindowActionMap; +typedef std::unordered_map MouseButtonActionMap;