From 66761b8e5d860eab58ec5b65759bfa9dff14111a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Tue, 6 Jan 2026 20:07:44 +0100 Subject: [PATCH] feat!: rework header files --- inc/{ => core}/camera.hpp | 5 ++- inc/{ => core}/ebo.hpp | 6 ++-- inc/core/logger.hpp | 53 +++++++++++++++++++++++++++++++ inc/{ => core}/shader.hpp | 0 inc/{ => core}/texture.hpp | 0 inc/core/time.hpp | 30 ++++++++++++++++++ inc/{ => core}/vao.hpp | 0 inc/{ => core}/vbo.hpp | 0 inc/cube.hpp | 3 +- inc/game.hpp | 26 +++++++++++++++ inc/p_cube.hpp | 65 -------------------------------------- inc/shape.hpp | 12 +++---- 12 files changed, 122 insertions(+), 78 deletions(-) rename inc/{ => core}/camera.hpp (94%) rename inc/{ => core}/ebo.hpp (74%) create mode 100644 inc/core/logger.hpp rename inc/{ => core}/shader.hpp (100%) rename inc/{ => core}/texture.hpp (100%) create mode 100644 inc/core/time.hpp rename inc/{ => core}/vao.hpp (100%) rename inc/{ => core}/vbo.hpp (100%) create mode 100644 inc/game.hpp delete mode 100644 inc/p_cube.hpp diff --git a/inc/camera.hpp b/inc/core/camera.hpp similarity index 94% rename from inc/camera.hpp rename to inc/core/camera.hpp index 49229e3..17ca019 100755 --- a/inc/camera.hpp +++ b/inc/core/camera.hpp @@ -1,10 +1,9 @@ #ifndef CAMERA_HPP #define CAMERA_HPP -#include "glm/ext/vector_float3.hpp" +#include "GLFW/glfw3.h" #include "glm/ext/matrix_float4x4.hpp" - -struct GLFWwindow; +#include "glm/ext/vector_float3.hpp" class Camera { diff --git a/inc/ebo.hpp b/inc/core/ebo.hpp similarity index 74% rename from inc/ebo.hpp rename to inc/core/ebo.hpp index 6fd6e3a..8656dbe 100755 --- a/inc/ebo.hpp +++ b/inc/core/ebo.hpp @@ -4,7 +4,8 @@ #include #include "glad/glad.h" - +namespace core +{ class EBO { private: @@ -19,4 +20,5 @@ class EBO void bind(); void unbind(); }; -#endif \ No newline at end of file +}; // namespace core +#endif // EBO_HPP \ No newline at end of file diff --git a/inc/core/logger.hpp b/inc/core/logger.hpp new file mode 100644 index 0000000..73f81a9 --- /dev/null +++ b/inc/core/logger.hpp @@ -0,0 +1,53 @@ +#ifndef LOGGER_HPP +#define LOGGER_HPP + +#include + +// log file +namespace core::log +{ +enum Type +{ + INFO, + ERROR, + WARNING +}; + +static inline const char *getErrorType(Type type) +{ + switch (type) + { + case INFO: + return "INFO"; + case ERROR: + return "ERROR"; + case WARNING: + return "WARNING"; + } + return "UNKNOWN"; +} + +inline void log(Type type, const char *desc, int errortype = 0) +{ + std::cerr << getErrorType(type) << " ERROR" + << ((errortype) ? std::format("({})", errortype) : "") << ": " + << desc << std::endl; +} + +inline void info(const char *desc, int codeerror = 0) +{ + log(Type::INFO, desc, codeerror); +} + +inline void error(const char *desc, int codeerror = 0) +{ + log(Type::ERROR, desc, codeerror); +} + +inline void warning(const char *desc, int codeerror = 0) +{ + log(Type::WARNING, desc, codeerror); +} +}; // namespace core::log + +#endif // LOGGER_HPP \ No newline at end of file diff --git a/inc/shader.hpp b/inc/core/shader.hpp similarity index 100% rename from inc/shader.hpp rename to inc/core/shader.hpp diff --git a/inc/texture.hpp b/inc/core/texture.hpp similarity index 100% rename from inc/texture.hpp rename to inc/core/texture.hpp diff --git a/inc/core/time.hpp b/inc/core/time.hpp new file mode 100644 index 0000000..c069ae0 --- /dev/null +++ b/inc/core/time.hpp @@ -0,0 +1,30 @@ +#ifndef TIME_HPP +#define TIME_HPP + +#include "GLFW/glfw3.h" + +class Time +{ + private: + double deltaTime = 0.; + double lastDTime = 0.; + + public: + double getDeltaTime() const { return deltaTime; } + double getLastDeltaTime() const { return lastDTime; } + + void start() + { + deltaTime = glfwGetTime(); + lastDTime = 0.; + } + + void update() + { + double currentTime = glfwGetTime(); + deltaTime = currentTime - lastDTime; + lastDTime = currentTime; + } +}; + +#endif \ No newline at end of file diff --git a/inc/vao.hpp b/inc/core/vao.hpp similarity index 100% rename from inc/vao.hpp rename to inc/core/vao.hpp diff --git a/inc/vbo.hpp b/inc/core/vbo.hpp similarity index 100% rename from inc/vbo.hpp rename to inc/core/vbo.hpp diff --git a/inc/cube.hpp b/inc/cube.hpp index 0d1b172..2f7bd84 100644 --- a/inc/cube.hpp +++ b/inc/cube.hpp @@ -1,14 +1,13 @@ #ifndef CUBE_HPP #define CUBE_HPP -#include "camera.hpp" #include "glm/ext/vector_float3.hpp" #include "shape.hpp" class Cube : public Shape { public: - Cube(Camera &camera, glm::vec3 pos, std::string texture); + Cube(Camera &camera, glm::vec3 pos, const char *texture); void render(int width, int height) override; }; diff --git a/inc/game.hpp b/inc/game.hpp new file mode 100644 index 0000000..f83583a --- /dev/null +++ b/inc/game.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_HPP +#define GAME_HPP + +#include "GLFW/glfw3.h" +#include "core/time.hpp" + +// class Game +// { +// private: +// Time time; +// GLFWwindow *window = nullptr; +// const char *WINDOW_NAME; +// int width; +// int height; + +// int init(); + +// protected: +// public: +// Game(int width, int height, const char *window_name); +// void run(); + +// static void error(const char *type, int errortype, const char *desc); +// }; + +#endif \ No newline at end of file diff --git a/inc/p_cube.hpp b/inc/p_cube.hpp deleted file mode 100644 index 643ac4d..0000000 --- a/inc/p_cube.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "GLFW/glfw3.h" - -constexpr GLfloat P_CUBE_VERTICE[] = { - // Positions // normales // texture coordinate - // front side - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, - - // back side - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, - - // left side - -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, - - // right side - 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - - // bottom side - -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, - - // up side - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -}; - -constexpr unsigned int P_CUBE_INDICE[] = { - 0, 1, 2, // 1 - 2, 3, 0, // 2 - - 4, 5, 6, // 3 - 6, 7, 4, // 4 - - 8, 9, 10, // 5 - 10, 11, 8, // 6 - - 12, 13, 14, // 7 - 14, 15, 12, // 8 - - 16, 17, 18, // 9 - 18, 19, 16, // 10 - - 20, 21, 22, // 11 - 22, 23, 20 // 12 -}; - -extern "C" const unsigned char P_CUBE_FRAG[]; -extern "C" const unsigned int P_CUBE_FRAG_LEN; -extern "C" const unsigned char P_CUBE_VERT[]; -extern "C" const unsigned int P_CUBE_VERT_LEN; \ No newline at end of file diff --git a/inc/shape.hpp b/inc/shape.hpp index fcb5651..64b4cbe 100644 --- a/inc/shape.hpp +++ b/inc/shape.hpp @@ -1,13 +1,13 @@ #ifndef SHAPE_HPP #define SHAPE_HPP -#include "camera.hpp" -#include "ebo.hpp" +#include "core/camera.hpp" +#include "core/ebo.hpp" +#include "core/shader.hpp" +#include "core/texture.hpp" +#include "core/vao.hpp" +#include "core/vbo.hpp" #include "glm/ext/vector_float3.hpp" -#include "shader.hpp" -#include "texture.hpp" -#include "vao.hpp" -#include "vbo.hpp" class Shape {