From cb07c61b7f5f527799e92ad8d8e4e3b778b9fbb9 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Fri, 28 Oct 2022 21:16:03 +0500 Subject: [PATCH] window system, glfw, imgui --- CMakeLists.txt | 6 +- cmake/imgui.cmake | 86 ++++++++++++++++ source/creator/CMakeLists.txt | 3 +- source/creator/creator.cpp | 68 +++++++++--- source/hyporo/gpu/CMakeLists.txt | 62 ++++++----- source/hyporo/gpu/glfw/monitor.cpp | 17 ++- source/hyporo/gpu/glfw/monitor.hpp | 14 +++ source/hyporo/gpu/glfw/window.cpp | 103 ++++++++++++++++++- source/hyporo/gpu/glfw/window.hpp | 49 +++++++-- source/hyporo/gpu/glfw/window_system.cpp | 41 +++++++- source/hyporo/gpu/glfw/window_system.hpp | 12 +-- source/hyporo/gpu/monitor.cpp | 11 ++ source/hyporo/gpu/monitor.hpp | 4 +- source/hyporo/gpu/opengl/shader_program.cpp | 2 +- source/hyporo/gpu/window.cpp | 15 +++ source/hyporo/gpu/window.hpp | 4 +- source/hyporo/gpu/window_context.hpp | 5 + source/hyporo/gpu/window_system.cpp | 18 ++-- source/hyporo/gpu/window_system.hpp | 18 ++-- source/hyporo/hyplib/array/dynamic_array.hpp | 8 +- source/hyporo/hyplib/array/static_array.hpp | 1 + 21 files changed, 453 insertions(+), 94 deletions(-) create mode 100644 cmake/imgui.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a42f4d1..4715d90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,6 @@ project( LANGUAGES CXX ) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") option(WITH_GTESTS "Enable GTest unit testing" ON) @@ -21,6 +19,10 @@ endif() include(${CMAKE_SOURCE_DIR}/cmake/glad.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/imgui.cmake) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") add_definitions(-DPRECISION_FLOAT) add_subdirectory(source) diff --git a/cmake/imgui.cmake b/cmake/imgui.cmake new file mode 100644 index 0000000..68c8302 --- /dev/null +++ b/cmake/imgui.cmake @@ -0,0 +1,86 @@ +include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) + +# branch: docking +CPMAddPackage( + NAME imgui_external + GIT_REPOSITORY https://github.com/ocornut/imgui.git + GIT_TAG 24dfebf455ac1f7685e1a72272d37b72601fe70c + DOWNLOAD_ONLY YES +) + +if(imgui_external_ADDED) + project(imgui) + + set(CMAKE_CXX_STANDARD 17) + + find_package(PkgConfig REQUIRED) + find_package(Freetype REQUIRED) + find_package(OpenGL REQUIRED) + pkg_search_module(GLFW REQUIRED glfw3) + + add_library(${PROJECT_NAME} STATIC + ${imgui_external_SOURCE_DIR}/imgui.cpp + ${imgui_external_SOURCE_DIR}/imgui_demo.cpp + ${imgui_external_SOURCE_DIR}/imgui_draw.cpp + ${imgui_external_SOURCE_DIR}/imgui_tables.cpp + ${imgui_external_SOURCE_DIR}/imgui_widgets.cpp + + ${imgui_external_SOURCE_DIR}/backends/imgui_impl_glfw.cpp + ${imgui_external_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp + + ${imgui_external_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp + ${imgui_external_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp + ) + add_library(imgui::imgui ALIAS ${PROJECT_NAME}) + + add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD) + + target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + $ + $ + + ${FREETYPE_INCLUDE_DIRS} + ${GLFW_INCLUDE_DIRS} + ) + + target_link_libraries(${PROJECT_NAME} + PUBLIC + Freetype::Freetype + glfw + OpenGL::GL + ) + + set_target_properties(${PROJECT_NAME} + PROPERTIES + POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME imgui + EXCLUDE_FROM_ALL ON + ) + + include(GNUInstallDirs) + + install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + ) + + install( + EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ) + + install( + DIRECTORY ${imgui_external_SOURCE_DIR} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + COMPONENT devel + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp" + ) +endif() diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 01b4e70..6e46b49 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -14,4 +14,5 @@ add_executable(hyporo target_link_libraries(hyporo PUBLIC - hyporo-hyplib) + hyporo-gpu + imgui) diff --git a/source/creator/creator.cpp b/source/creator/creator.cpp index 98f731b..42255ea 100644 --- a/source/creator/creator.cpp +++ b/source/creator/creator.cpp @@ -1,22 +1,56 @@ -#include "scalar.hpp" -#include "vector.hpp" -#include -#include -#include "matrix.hpp" +#include "../hyporo/gpu/window_system.hpp" +#include "../hyporo/gpu/glfw/window.hpp" +#include +#include +#include int main(void) { - hyporo::vec3 v1 {1, 3, 2}; - hyporo::vec3 v2 {7, 4, 5}; - std::cout << -v1 << std::endl; - std::cout << ((v1 + v2) == hyporo::vec3(8, 7, 7)) << std::endl; - std::cout << v1 - v2 << std::endl; - std::cout << v1 * 2 << std::endl; - std::cout << v1 / 2 << std::endl; - std::cout << (v1 == v2) << std::endl; - std::cout << (v1 == v1) << std::endl; - hyporo::mat3 m1 {1, 3, 2, 5, 3, 6, 7, 2, 0}; - hyporo::mat3 m2 {7, 4, 5, 5, 7, 3, 1, 4, 6}; - std::cout << m1 + m2 << std::endl; + hpr::gpu::WindowSystem* ws = hpr::gpu::WindowSystem::create(hpr::gpu::WindowContext::Provider::GLFW); + hpr::gpu::Window* w = ws->newWindow(); + w->init("test", hpr::gpu::Window::Style::Windowed, 0, 0, 600, 400, nullptr, nullptr); + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + + ImGui::StyleColorsDark(); + + ImGui_ImplGlfw_InitForOpenGL(dynamic_cast(w)->instance(), true); + ImGui_ImplOpenGL3_Init("#version 330"); + + while (w->isOpen()) + { + dynamic_cast(w)->pollEvents(); + + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + bool yes = true; + ImGui::ShowDemoWindow(&yes); + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + { + if (ImGui::Button("Exit")) // Buttons return true when clicked (most widgets return true when edited/activated) + w->state(hpr::gpu::Window::State::Closed); + ImGui::End(); + } + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + dynamic_cast(w)->swapBuffers(); + } + + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + ws->destroyWindow(w); + hpr::gpu::WindowSystem::destroy(ws); + return 0; } diff --git a/source/hyporo/gpu/CMakeLists.txt b/source/hyporo/gpu/CMakeLists.txt index ba8d406..4147601 100644 --- a/source/hyporo/gpu/CMakeLists.txt +++ b/source/hyporo/gpu/CMakeLists.txt @@ -5,35 +5,49 @@ include_directories( add_library(hyporo-gpu STATIC # Source files - buffer.cpp - context.cpp - shader.cpp - opengl/buffer.cpp - opengl/context.cpp - opengl/shader.cpp - opengl/texture.cpp - opengl/device.cpp - opengl/shader_program.cpp - texture.cpp - device.cpp - shader_program.cpp + window_system.cpp + monitor.cpp + buffer.cpp + context.cpp + shader.cpp + window.cpp + opengl/buffer.cpp + opengl/context.cpp + opengl/shader.cpp + opengl/texture.cpp + #opengl/device.cpp + opengl/shader_program.cpp + texture.cpp + #device.cpp + glfw/window_system.cpp + glfw/monitor.cpp + glfw/window.cpp + shader_program.cpp # Header files - context.hpp - shader.hpp - shader_program.hpp - buffer.hpp - device.hpp - texture.hpp - opengl/context.hpp - opengl/shader.hpp - opengl/shader_program.hpp - opengl/buffer.hpp - opengl/device.hpp - opengl/texture.hpp + monitor.hpp + context.hpp + shader.hpp + window_context.hpp + shader_program.hpp + buffer.hpp + #device.hpp + window.hpp + texture.hpp + opengl/context.hpp + opengl/shader.hpp + opengl/shader_program.hpp + opengl/buffer.hpp + #opengl/device.hpp + opengl/texture.hpp + window_system.hpp + glfw/monitor.hpp + glfw/window.hpp + glfw/window_system.hpp ) target_link_libraries(hyporo-gpu glad + glfw hyporo-hyplib ) \ No newline at end of file diff --git a/source/hyporo/gpu/glfw/monitor.cpp b/source/hyporo/gpu/glfw/monitor.cpp index 63a4070..e87002b 100644 --- a/source/hyporo/gpu/glfw/monitor.cpp +++ b/source/hyporo/gpu/glfw/monitor.cpp @@ -1,5 +1,14 @@ -// -// Created by L-Nafaryus on 10/27/2022. -// - #include "monitor.hpp" + + +namespace hpr::gpu::glfw +{ + +Monitor::Monitor() : + gpu::Monitor {Provider::GLFW}, + p_instance {nullptr} +{} + +Monitor::~Monitor() = default; + +} \ No newline at end of file diff --git a/source/hyporo/gpu/glfw/monitor.hpp b/source/hyporo/gpu/glfw/monitor.hpp index 068371f..6cc6d1e 100644 --- a/source/hyporo/gpu/glfw/monitor.hpp +++ b/source/hyporo/gpu/glfw/monitor.hpp @@ -2,12 +2,26 @@ #include "../monitor.hpp" +#include "GLFW/glfw3.h" + namespace hpr::gpu::glfw { class Monitor : public gpu::Monitor { + friend class WindowSystem; + friend class Window; + +protected: + + GLFWmonitor* p_instance; + +public: + + Monitor(); + + ~Monitor(); }; diff --git a/source/hyporo/gpu/glfw/window.cpp b/source/hyporo/gpu/glfw/window.cpp index 71ec96e..156c770 100644 --- a/source/hyporo/gpu/glfw/window.cpp +++ b/source/hyporo/gpu/glfw/window.cpp @@ -1,5 +1,100 @@ -// -// Created by L-Nafaryus on 10/27/2022. -// - #include "window.hpp" +#include "monitor.hpp" + +#include + + +namespace hpr::gpu::glfw +{ + +Window::Window() : + gpu::Window {Provider::GLFW}, + p_instance {nullptr} +{} + +Window::~Window() = default; + +void Window::init(const std::string& title, Style style, int x, int y, int width, int height, gpu::Window* parent, gpu::Monitor* monitor) +{ + if (!checkCompability(parent)) + throw std::invalid_argument("Incompatible window provider passed"); + + gpu::Window::init(title, style, x, y, width, height, parent, monitor); + + glfw::Window* parent_ = dynamic_cast(parent); + glfw::Monitor* monitor_ = dynamic_cast(monitor); + + p_instance = glfwCreateWindow(width, height, title.c_str(), + monitor_ != nullptr ? monitor_->p_instance : nullptr, parent_ != nullptr ? parent_->p_instance : nullptr); + if (p_instance == nullptr) + throw std::runtime_error("Cannot create GLFW window"); + glfwMakeContextCurrent(p_instance); + glfwSetWindowPos(p_instance, x, y); + this->style(style); +} + +void Window::init(const std::string& title, Style style, gpu::Window* parent, gpu::Monitor* monitor) +{ + init(title, style, monitor->originX(), monitor->originY(), monitor->width(), monitor->height(), parent, monitor); +} + +void Window::state(State state) +{ + gpu::Window::state(state); + switch (state) + { + case State::Visible: + glfwShowWindow(p_instance); + break; + case State::Hidden: + glfwHideWindow(p_instance); + break; + case State::Maximized: + glfwMaximizeWindow(p_instance); + break; + case State::Minimized: + glfwIconifyWindow(p_instance); + break; + case State::Closed: + glfwSetWindowShouldClose(p_instance, GLFW_TRUE); + break; + default: + break; + } +} + +void Window::close() +{ + gpu::Window::close(); + glfwDestroyWindow(p_instance); + p_instance = nullptr; +} + +void Window::style(Style style) +{ + gpu::Window::style(style); + if (style == Style::Windowed) + { + glfwSetWindowMonitor(p_instance, nullptr, p_posX, p_posY, p_width, p_height, GLFW_DONT_CARE); + } + else if (style == Style::Fullscreen) + { + glfwSetWindowMonitor(p_instance, glfwGetPrimaryMonitor(), p_posX, p_posY, p_width, p_height, GLFW_DONT_CARE); + } + else if (style == Style::Popup) + { + //throw std::runtime_error("Popup style is not supported"); + } +} + +void Window::swapBuffers() +{ + glfwSwapBuffers(p_instance); +} + +void Window::pollEvents() +{ + glfwPollEvents(); +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/glfw/window.hpp b/source/hyporo/gpu/glfw/window.hpp index 2695d9f..0edc571 100644 --- a/source/hyporo/gpu/glfw/window.hpp +++ b/source/hyporo/gpu/glfw/window.hpp @@ -1,8 +1,45 @@ -// -// Created by L-Nafaryus on 10/27/2022. -// +#pragma once -#ifndef HYPORO_WINDOW_HPP -#define HYPORO_WINDOW_HPP +#include "../window.hpp" -#endif //HYPORO_WINDOW_HPP +#include + + +namespace hpr::gpu::glfw +{ + +class Window : public gpu::Window +{ + friend class WindowSystem; + +protected: + + GLFWwindow* p_instance; + +public: + + Window(); + + virtual + ~Window(); + + GLFWwindow* instance() const + { + return p_instance; + } + void init(const std::string& title, Style style, int x, int y, int width, int height, gpu::Window* parent, gpu::Monitor* monitor) override; + + void init(const std::string& title, Style style, gpu::Window* parent, gpu::Monitor* monitor) override; + + void state(State state) override; + + void close() override; + + void style(Style style) override; + + void swapBuffers(); + + void pollEvents(); +}; + +} \ No newline at end of file diff --git a/source/hyporo/gpu/glfw/window_system.cpp b/source/hyporo/gpu/glfw/window_system.cpp index 06171e1..b30b08e 100644 --- a/source/hyporo/gpu/glfw/window_system.cpp +++ b/source/hyporo/gpu/glfw/window_system.cpp @@ -1,5 +1,38 @@ -// -// Created by L-Nafaryus on 10/27/2022. -// - +#include "monitor.hpp" +#include "window.hpp" #include "window_system.hpp" + + +namespace hpr::gpu::glfw +{ + +WindowSystem::WindowSystem() : + gpu::WindowSystem {Provider::GLFW} +{ + if (!glfwInit()) + throw std::runtime_error("Cannot initialize GLFW"); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +} + +WindowSystem::~WindowSystem() +{ + for (auto& window : p_windows) + window->close(); + glfwTerminate(); +} + +gpu::Window* WindowSystem::newWindow() +{ + p_windows.push(new glfw::Window); + + return static_cast(p_windows.back()); +} + +std::function WindowSystem::deviceProcAddress() const +{ + return std::function(glfwGetProcAddress); +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/glfw/window_system.hpp b/source/hyporo/gpu/glfw/window_system.hpp index 16cac12..636e4ec 100644 --- a/source/hyporo/gpu/glfw/window_system.hpp +++ b/source/hyporo/gpu/glfw/window_system.hpp @@ -3,6 +3,7 @@ #include "../window_system.hpp" #include +#include namespace hpr::gpu::glfw @@ -11,18 +12,15 @@ namespace hpr::gpu::glfw class WindowSystem : public gpu::WindowSystem { -protected: - - GLFWwindow p_instance; - public: WindowSystem(); - ~WindowSystem(); + ~WindowSystem() override; - virtual - void newWindow(Window** window); + gpu::Window* newWindow() override; + + std::function deviceProcAddress() const; }; } \ No newline at end of file diff --git a/source/hyporo/gpu/monitor.cpp b/source/hyporo/gpu/monitor.cpp index cb5db9a..5250d30 100644 --- a/source/hyporo/gpu/monitor.cpp +++ b/source/hyporo/gpu/monitor.cpp @@ -15,6 +15,17 @@ Monitor::Monitor() : p_logicalHeight {0} {} +Monitor::Monitor(Provider provider) : + WindowContext(provider), + p_deviceName {}, + p_originX {0}, + p_originY {0}, + p_width {0}, + p_height {0}, + p_logicalWidth {0}, + p_logicalHeight {0} +{} + Monitor::~Monitor() = default; void Monitor::origin(int x, int y) diff --git a/source/hyporo/gpu/monitor.hpp b/source/hyporo/gpu/monitor.hpp index c466ea7..ce79cca 100644 --- a/source/hyporo/gpu/monitor.hpp +++ b/source/hyporo/gpu/monitor.hpp @@ -8,7 +8,7 @@ namespace hpr::gpu { -class Monitor : WindowContext +class Monitor : public WindowContext { protected: @@ -25,6 +25,8 @@ public: Monitor(); + Monitor(Provider provider); + virtual ~Monitor(); diff --git a/source/hyporo/gpu/opengl/shader_program.cpp b/source/hyporo/gpu/opengl/shader_program.cpp index 455d0aa..05d4735 100644 --- a/source/hyporo/gpu/opengl/shader_program.cpp +++ b/source/hyporo/gpu/opengl/shader_program.cpp @@ -14,7 +14,7 @@ ShaderProgram::ShaderProgram() : ShaderProgram::~ShaderProgram() {} -Shader *ShaderProgram::shader(gpu::Shader::ShaderType type) +Shader* ShaderProgram::shader(gpu::Shader::ShaderType type) { return static_cast(p_slots[(size_t)type]); } diff --git a/source/hyporo/gpu/window.cpp b/source/hyporo/gpu/window.cpp index 5daf32e..afe21d6 100644 --- a/source/hyporo/gpu/window.cpp +++ b/source/hyporo/gpu/window.cpp @@ -19,6 +19,21 @@ Window::Window() : p_isResizing {false} {} +Window::Window(Provider provider) : + WindowContext(provider), + p_width {0}, + p_height {0}, + p_posX {0}, + p_posY {0}, + p_title {}, + p_state {State::Hidden}, + p_style {Style::Unknown}, + p_parent {nullptr}, + p_monitor {nullptr}, + p_isActive {true}, + p_isResizing {false} +{} + Window::~Window() = default; void Window::init(const std::string& title, Style style, int x, int y, int width, int height, Window* parent, Monitor* monitor) diff --git a/source/hyporo/gpu/window.hpp b/source/hyporo/gpu/window.hpp index 87a17a3..8c7e7b1 100644 --- a/source/hyporo/gpu/window.hpp +++ b/source/hyporo/gpu/window.hpp @@ -50,6 +50,8 @@ public: Window(); + Window(Provider provider); + virtual ~Window(); @@ -62,7 +64,7 @@ public: void init(const std::string& title, Style style, Window* parent, Monitor* monitor); virtual - void state(State state = State::Visible); + void state(State state); virtual void close(); diff --git a/source/hyporo/gpu/window_context.hpp b/source/hyporo/gpu/window_context.hpp index 3f84d53..08f1a0a 100644 --- a/source/hyporo/gpu/window_context.hpp +++ b/source/hyporo/gpu/window_context.hpp @@ -34,6 +34,11 @@ public: virtual ~WindowContext() = default; + bool checkCompability(const WindowContext* ctx) const + { + return (ctx != nullptr) ? ctx->p_provider == p_provider : true; + } + }; } diff --git a/source/hyporo/gpu/window_system.cpp b/source/hyporo/gpu/window_system.cpp index 4b8d6c7..00730ff 100644 --- a/source/hyporo/gpu/window_system.cpp +++ b/source/hyporo/gpu/window_system.cpp @@ -15,17 +15,13 @@ WindowSystem::WindowSystem(Provider provider) : WindowSystem::~WindowSystem() = default; -void WindowSystem::create(WindowSystem** ws, Provider provider) +WindowSystem* WindowSystem::create(Provider provider) { - if (ws == nullptr) - throw std::invalid_argument("Invalid parameter 'nullptr'"); if (provider == Provider::Unknown) throw std::invalid_argument("Cannot create window system from 'Unknown' provider"); - *ws = nullptr; - if (provider == Provider::GLFW) - *ws = new glfw::WindowSystem; + return new glfw::WindowSystem; else throw std::invalid_argument("Unsupported window system"); } @@ -36,7 +32,7 @@ void WindowSystem::destroy(WindowSystem*& ws) ws = nullptr; } -Window& WindowSystem::window(int index) +Window* WindowSystem::window(int index) { return p_windows[index]; } @@ -48,16 +44,18 @@ void WindowSystem::closeWindow(Window* window) void WindowSystem::destroyWindow(Window* window) { - p_windows.remove(*window); + p_windows.remove(window); + window->close(); + window = nullptr; } -Monitor& WindowSystem::monitor(int index) +Monitor* WindowSystem::monitor(int index) { return p_monitors[index]; } void WindowSystem::destroyMonitor(Monitor* monitor) { - p_monitors.remove(*monitor); + p_monitors.remove(monitor); } } diff --git a/source/hyporo/gpu/window_system.hpp b/source/hyporo/gpu/window_system.hpp index f9f84d4..52b626d 100644 --- a/source/hyporo/gpu/window_system.hpp +++ b/source/hyporo/gpu/window_system.hpp @@ -10,13 +10,13 @@ namespace hpr::gpu { -class WindowSystem : WindowContext +class WindowSystem : public WindowContext { protected: - darray p_windows; - darray p_monitors; + darray p_windows; + darray p_monitors; protected: @@ -32,7 +32,7 @@ public: // Global functions static - void create(WindowSystem** ws, Provider provider); + WindowSystem* create(Provider provider); static void destroy(WindowSystem*& ws); @@ -40,9 +40,9 @@ public: // Window interface virtual - void newWindow(Window** window) = 0; + Window* newWindow() = 0; - Window& window(int index); + Window* window(int index); void closeWindow(Window* window); @@ -50,10 +50,10 @@ public: // Monitor interface - virtual - void newMonitor(Monitor** monitor) = 0; + //virtual + //void newMonitor(Monitor** monitor) = 0; - Monitor& monitor(int index); + Monitor* monitor(int index); void destroyMonitor(Monitor* monitor); diff --git a/source/hyporo/hyplib/array/dynamic_array.hpp b/source/hyporo/hyplib/array/dynamic_array.hpp index 22e6ddf..2733492 100644 --- a/source/hyporo/hyplib/array/dynamic_array.hpp +++ b/source/hyporo/hyplib/array/dynamic_array.hpp @@ -258,9 +258,11 @@ public: virtual int findByAddress(const value_type& value) { - for (int n = 0; n < p_size; ++n) - if (std::addressof(*(p_start + n)) == std::addressof(value)) + // TODO: make better approach + for (int n = 0; n < p_size; ++n) { + if (*std::addressof(*(p_start + n)) == *std::addressof(value)) return n; + } return -1; } @@ -277,7 +279,7 @@ public: virtual void remove(const value_type& value) { - size_type index = findByAddress(value); + int index = findByAddress(value); if (index != -1) remove(index); else diff --git a/source/hyporo/hyplib/array/static_array.hpp b/source/hyporo/hyplib/array/static_array.hpp index 8ddd0a7..7cecdff 100644 --- a/source/hyporo/hyplib/array/static_array.hpp +++ b/source/hyporo/hyplib/array/static_array.hpp @@ -1,6 +1,7 @@ #pragma once #include "iterator.hpp" + #include #include