Refactor includes

This commit is contained in:
2021-07-04 23:44:30 +02:00
parent 498de84943
commit 979ae4686f
34 changed files with 175 additions and 95 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include "ShaderProgram.h"
#include "EventHandler.h"
#include "definitions/eventActions.h"
#include <glm/glm.hpp>
class Camera

View File

@@ -6,6 +6,8 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <GLFW/glfw3.h>
#ifdef _DEBUG
#include <imgui.h>
#include <imgui_impl_glfw.h>
@@ -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()
{

View File

@@ -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 <memory>
#include <vector>
#include <glm/glm.hpp>
class ShaderProgram;
class Window;
class EventHandler;
class World;
class Camera;
class Menu;
class FrameBuffer;
class Controller
{

View File

@@ -1,4 +1,8 @@
#include "Entity.h"
#include "VertexArray.h"
#include "Mesh.h"
#include "ShaderProgram.h"
#include "Model.h"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
@@ -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;

View File

@@ -1,12 +1,14 @@
#pragma once
#include "Model.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
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;

View File

@@ -1,5 +1,6 @@
#include "EventHandler.h"
#include "GLFW/glfw3.h"
#include <iostream>
CameraActionMap EventHandler::s_cameraActionMap = {{CameraAction::Forward, false}, {CameraAction::Backward, false},

View File

@@ -1,15 +1,9 @@
#pragma once
#include <GLFW/glfw3.h>
#include <unordered_map>
#include "definitions/enumHash.h"
#include "definitions/eventActions.h"
typedef std::unordered_map<CameraAction, bool, EnumClassHash> CameraActionMap;
typedef std::unordered_map<CameraMouseAction, double, EnumClassHash> CameraMouseActionMap;
typedef std::unordered_map<WindowAction, bool, EnumClassHash> WindowActionMap;
typedef std::unordered_map<MouseButtonAction, bool, EnumClassHash> MouseButtonActionMap;
class GLFWwindow;
class EventHandler
{

View File

@@ -1,5 +1,8 @@
#include "FrameBuffer.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include <cstddef>
#include <iostream>

View File

@@ -1,9 +1,10 @@
#pragma once
#include "ShaderProgram.h"
#include "Texture.h"
#include <glad/glad.h>
class ShaderProgram;
class CubeMap;
class FrameBuffer
{
public:

View File

@@ -1,6 +1,6 @@
#pragma once
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <chrono>
#include <stdint.h>
#include <string>

View File

@@ -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 <fstream>
#include <future>

View File

@@ -1,15 +1,18 @@
#pragma once
#include "Entity.h"
#include "Light.h"
#include "Model.h"
#include "Screen.h"
#include "ShaderProgram.h"
#include <jsoncpp/json/json.h>
#include <string>
#include <vector>
class Model;
class Entity;
class Light;
class Screen;
class Skybox;
class ShaderProgram;
class FrameBuffer;
class Widget;
class JsonParser
{
public:

View File

@@ -1,4 +1,5 @@
#include "Light.h"
#include "ShaderProgram.h"
#include <string>

View File

@@ -1,11 +1,12 @@
#pragma once
#include <glm/glm.hpp>
#include "ShaderProgram.h"
#include <string>
#define NUM_POINT_LIGHTS 1
class ShaderProgram;
class Light
{
public:

View File

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

View File

@@ -1,12 +1,15 @@
#pragma once
#include "definitions/eventActions.h"
#include <string>
#include <unordered_map>
#include <vector>
#include "FrameBuffer.h"
#include "JsonParser.h"
#include "Screen.h"
#include "EventHandler.h"
class ShaderProgram;
class FrameBuffer;
class Screen;
class Window;
class Menu
{

View File

@@ -1,4 +1,6 @@
#include "Mesh.h"
#include "Texture.h"
#include "ShaderProgram.h"
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures)
: m_numElements(indices.size()), m_textures(textures),

View File

@@ -1,11 +1,12 @@
#pragma once
#include "definitions/models.h"
#include "VertexArray.h"
#include <vector>
#include "ShaderProgram.h"
#include "Texture.h"
#include "VertexArray.h"
#include "definitions/models.h"
class ShaderProgram;
class Texture;
class Mesh
{

View File

@@ -1,4 +1,7 @@
#include "Model.h"
#include "Mesh.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include <fstream>
#include <iostream>

View File

@@ -1,9 +1,13 @@
#pragma once
#include "definitions/models.h"
#include <string>
#include <vector>
#include "Mesh.h"
class ShaderProgram;
class Mesh;
class Texture;
struct TexturePrototype
{

View File

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

View File

@@ -1,12 +1,14 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include "FrameBuffer.h"
#include "ShaderProgram.h"
#include "Widget.h"
class Menu;
class Widget;
class FrameBuffer;
class ShaderProgram;
class Texture;
class Screen
{

View File

@@ -1,11 +1,11 @@
#include "ShaderProgram.h"
#include <fstream>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <string>
#include "ShaderProgram.h"
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
const std::string &fragmentShaderPath)
: m_uniqueName(name)

View File

@@ -1,4 +1,5 @@
#include "Texture.h"
#include "ShaderProgram.h"
#include <iostream>
#include <stb/stb_image.h>

View File

@@ -1,7 +1,5 @@
#pragma once
#include "ShaderProgram.h"
#include "definitions/models.h"
#include <cstdint>
@@ -9,6 +7,8 @@
#include <string>
#include <vector>
class ShaderProgram;
// Order is important!
enum cubeMapFaces
{

View File

@@ -1,9 +1,9 @@
#include <cstddef>
#include <vector>
#include "VertexArray.h"
#include "definitions/models.h"
#include <cstddef>
#include <vector>
VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices)
{
glGenVertexArrays(1, &m_VAO);

View File

@@ -1,9 +1,10 @@
#pragma once
#include <glad/glad.h>
#include "definitions/models.h"
#include <glad/glad.h>
#include <vector>
class VertexArray
{
public:

View File

@@ -1,7 +1,12 @@
#include "Widget.h"
#include "Menu.h"
#include "Mesh.h"
#include "ShaderProgram.h"
#include "Window.h"
#include "VertexArray.h"
#include <GLFW/glfw3.h>
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)
{

View File

@@ -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 <string>
#include <vector>
class Menu;
class ShaderProgram;
class Texture;
class Window;
class Mesh;
class Widget
{

View File

@@ -1,11 +1,12 @@
#include <glad/glad.h>
#include <iostream>
#include "Helper.h"
#include "Window.h"
#include "definitions/eventActions.h"
#include "Helper.h"
#include "ShaderProgram.h"
#include "definitions/window.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
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()

View File

@@ -1,8 +1,8 @@
#pragma once
#include "EventHandler.h"
#include "definitions/eventActions.h"
#include <GLFW/glfw3.h>
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;

View File

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

View File

@@ -1,12 +1,21 @@
#pragma once
#include <vector>
#include "Camera.h"
#include "Entity.h"
#include "FrameBuffer.h"
#include "Light.h"
#include "ShaderProgram.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
#include <string>
class Camera;
class Entity;
class Light;
class PointLight;
class DirectionalLight;
class ShaderProgram;
class Skybox;
class Model;
class World
{

View File

@@ -1,5 +1,8 @@
#pragma once
#include "enumHash.h"
#include <unordered_map>
enum class CameraAction
{
Up,
@@ -33,3 +36,8 @@ enum class MouseButtonAction
MiddleClicked,
MOUSE_BUTTON_ACTION_NUM_ITEMS
};
typedef std::unordered_map<CameraAction, bool, EnumClassHash> CameraActionMap;
typedef std::unordered_map<CameraMouseAction, double, EnumClassHash> CameraMouseActionMap;
typedef std::unordered_map<WindowAction, bool, EnumClassHash> WindowActionMap;
typedef std::unordered_map<MouseButtonAction, bool, EnumClassHash> MouseButtonActionMap;