From 5cf173cd9180242738a729eb311ebfefdfbb5f6c Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Wed, 8 Mar 2023 00:17:19 +0000 Subject: [PATCH] switching workstation --- libhart/inferno_hart.hpp | 8 +-- libhart/thirdparty/yolo/yolo.hpp | 14 ++-- src/window.cpp | 111 ++++++++++++------------------- 3 files changed, 55 insertions(+), 78 deletions(-) diff --git a/libhart/inferno_hart.hpp b/libhart/inferno_hart.hpp index fa66380..6528936 100644 --- a/libhart/inferno_hart.hpp +++ b/libhart/inferno_hart.hpp @@ -12,7 +12,7 @@ /** * infero HART modules - * Modules are registered at load time - instantiated when selected + * Modules are registered at load time - instantiated when selected * _GET, _DESTROY & _CREDIT must be defined and return valid context's * * Inferno will first initialise the module and then wait for the Ready state. @@ -22,11 +22,11 @@ * - Idle (Ready for rays) * - Build (Scene is submitted and being processed) * - Trace (Tracing!) - * + * * Once the HHM dispatches a new scene to the module, it will wait until * the state is Done to dispatch work during scene building the modules * state must be Build. - * + * * Once the scene is ready and so is the trace, the HHM will start the tracing * state by calling the start function of the module, the module must go * through the rays added to it before start was called and then @@ -129,5 +129,5 @@ struct ModuleCredit const int VersionMinor; const int VersionBuild; }; - + } diff --git a/libhart/thirdparty/yolo/yolo.hpp b/libhart/thirdparty/yolo/yolo.hpp index f41130d..8c9a728 100644 --- a/libhart/thirdparty/yolo/yolo.hpp +++ b/libhart/thirdparty/yolo/yolo.hpp @@ -23,7 +23,7 @@ namespace detail { return oss.str(); } - inline std::string formatTime() + inline std::string formatTime() { auto now = std::chrono::system_clock::now(); std::time_t time = std::chrono::system_clock::to_time_t(now); @@ -38,9 +38,9 @@ namespace detail { template inline void __log(const std::string& level, const std::string& col, const std::string& message, Args... args) { - std::cout + std::cout << '[' << detail::formatTime() << "] " - << '[' << col << level << "\033[0m" << "] " + << '[' << col << level << "\033[0m" << "] " << detail::format(message, args...) << std::endl; } @@ -48,7 +48,7 @@ template inline void __log(uint8_t module, const std::string& level, const std::string& col, const std::string& message, Args... args) { auto mod = detail::modules[module]; - std::cout + std::cout << '[' << detail::formatTime() << "] " << '[' << col << level << "\033[0m" << "] " << '[' << mod.second << mod.first << "\033[0m" << "] " @@ -58,7 +58,7 @@ inline void __log(uint8_t module, const std::string& level, const std::string& c template inline void info(const std::string& format, Args&&... args) -{ +{ __log("INFO", "\u001b[32;1m", format, args...); } @@ -83,7 +83,7 @@ inline void debug(const std::string& format, Args&&... args) template inline void info(uint8_t module, const std::string& format, Args&&... args) -{ +{ __log(module, "INFO", "\u001b[32;1m", format, args...); } @@ -112,7 +112,7 @@ inline void debug(uint8_t module, const std::string& format, Args&&... args) inline uint8_t registerModule(std::string name, std::string ANSI) { detail::modules.push_back(std::make_pair(name, ANSI)); - return detail::modules.size() - 1; + return detail::modules.size() - 1; } } diff --git a/src/window.cpp b/src/window.cpp index 1c859bc..121a470 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -6,80 +6,56 @@ using namespace inferno; -Window::Window() -{ +Window::Window() {} -} - -Window::~Window() -{ +Window::~Window() { shutdownImGui(); - shutdownGLFW(); + shutdownGLFW(); } -void Window::init(std::string title, int width, int height) -{ +void Window::init(std::string title, int width, int height) { this->width = width; this->height = height; setupGLFW(title); - glfwSetKeyCallback(getGLFWWindow(), glfwKeyCallback); setupImGui(); } -void Window::setTitle(std::string title) -{ +void Window::setTitle(std::string title) { glfwSetWindowTitle(window, title.c_str()); } -void Window::setSize(int w, int h) -{ +void Window::setSize(int w, int h) { width = w; height = h; glfwSetWindowSize(window, width, height); } -void Window::setPos(int x, int y) -{ - glfwSetWindowPos(window, x, y); -} +void Window::setPos(int x, int y) { glfwSetWindowPos(window, x, y); } -glm::vec2 Window::getSize() -{ - return {width, height}; -} +glm::vec2 Window::getSize() { return {width, height}; } -void Window::getPos(int& x, int& y) -{ - glfwGetWindowPos(window, &x, &y); -} +void Window::getPos(int &x, int &y) { glfwGetWindowPos(window, &x, &y); } -void Window::setFPSMode() -{ +void Window::setFPSMode() { mWinMode = WIN_MODE_FPS; glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } -void Window::setKeyCallback(KeyCallback callback) -{ - mKeyCallback = callback; -} +void Window::setKeyCallback(KeyCallback callback) { mKeyCallback = callback; } -KeyCallback Window::getKeyCallback() -{ - return mKeyCallback; -} +KeyCallback Window::getKeyCallback() { return mKeyCallback; } -bool Window::newFrame() -{ +bool Window::newFrame() { glfwPollEvents(); - if (mWinMode == WIN_MODE_FPS) - { + if (mWinMode == WIN_MODE_FPS) { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetCursorPos(window, (double)width / 2, (double)height / 2); } - if (glfwWindowShouldClose(window)) { return false; } + if (glfwWindowShouldClose(window)) { + return false; + } glfwGetWindowSize(window, &width, &height); @@ -97,8 +73,7 @@ bool Window::newFrame() return true; } -void Window::render() -{ +void Window::render() { ImGui::End(); ImGui::Render(); auto io = ImGui::GetIO(); @@ -108,10 +83,10 @@ void Window::render() ImGui::UpdatePlatformWindows(); } -void Window::setupGLFW(std::string title) -{ +void Window::setupGLFW(std::string title) { glfwSetErrorCallback(glfwErrorCallback); - if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW"); + if (!glfwInit()) + throw std::runtime_error("Failed to initialize GLFW"); // Decide GL+GLSL versions #if defined(IMGUI_IMPL_OPENGL_ES2) @@ -125,27 +100,27 @@ void Window::setupGLFW(std::string title) glslVersion = "#version 150"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac #else // GL 4.5 + GLSL 450 glslVersion = "#version 450"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only #endif // Create window with graphics context window = glfwCreateWindow(1280, 720, title.c_str(), NULL, NULL); - if (window == NULL) throw std::runtime_error("Could not create window"); + if (window == NULL) + throw std::runtime_error("Could not create window"); glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); glfwSwapInterval(1); // Enable vsync } -void Window::setupImGui() -{ +void Window::setupImGui() { // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -153,40 +128,42 @@ void Window::setupImGui() // Setup Dear ImGui style ImGui::StyleColorsDark(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking - io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP! + ImGuiIO &io = ImGui::GetIO(); + (void)io; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking + io.ConfigFlags |= + ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T + // WORK AS EXPECTED. DON'T USE IN + // USER APP! io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI - // io.ConfigDockingWithShift = true; + // io.ConfigDockingWithShift + // = true; - // Setup Platform/Renderer backends + // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(glslVersion); SetupImGuiStyle2(); } -void Window::shutdownImGui() -{ +void Window::shutdownImGui() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); } -void Window::shutdownGLFW() -{ +void Window::shutdownGLFW() { glfwDestroyWindow(window); glfwTerminate(); } -void Window::glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - if (Window::GetInstance().getKeyCallback() != nullptr) - { +void Window::glfwKeyCallback(GLFWwindow *window, int key, int scancode, + int action, int mods) { + if (Window::GetInstance().getKeyCallback() != nullptr) { Window::GetInstance().getKeyCallback()(key, scancode, action, mods); } } -void Window::glfwErrorCallback(int error, const char* description) { +void Window::glfwErrorCallback(int error, const char *description) { yolo::error("[GLFW {}] {}", error, description); }