From 04907abda70a17ad22bcf4ffd3d9bec5be6021bb Mon Sep 17 00:00:00 2001 From: noffie Date: Thu, 12 Dec 2024 18:35:36 +0100 Subject: [PATCH] removing tests --- CMakeLists.txt | 83 +--------------------------------- include/logger.hpp | 56 +++++++++++++++++++++++ src/gui/raygui.cpp | 2 - src/libimpl.cpp | 5 +++ src/main.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++-- tests/lua.cpp | 0 tests/tests.cpp | 6 --- 7 files changed, 167 insertions(+), 93 deletions(-) create mode 100644 include/logger.hpp delete mode 100644 src/gui/raygui.cpp create mode 100644 src/libimpl.cpp delete mode 100644 tests/lua.cpp delete mode 100644 tests/tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c70cef..887e4db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,12 +73,6 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED ON) # Prevent automatic updates set(FETCHCONTENT_QUIET OFF) # Display download progress set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json -# ======================================================== -# Options -# ======================================================== - -option(SVA_BUILD_TEST ON) # Option for test to be build as well - # ======================================================== # External Dependencies # ======================================================== @@ -101,6 +95,7 @@ FetchContent_Declare( FetchContent_MakeAvailable(lua) set(LUA_BUILD_INTERPRETER ON CACHE BOOL "Build the Lua interpreter" FORCE) +set(SOL2_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) # ======================================================== # Helper Function: Set Common Target Properties @@ -159,85 +154,9 @@ if (APPLE) target_link_libraries(${PROJECT_NAME} "-framework Cocoa") target_link_libraries(${PROJECT_NAME} "-framework OpenGL") endif() - -# ------------------------------- -# SFML (Not used anymore) -# ------------------------------- -# -# --- Add SFML (Simple and Fast Multimedia Library) -# FetchContent_Declare(SFML -# GIT_REPOSITORY https://github.com/SFML/SFML.git -# GIT_TAG 2.6.x -# GIT_SHALLOW ON -# EXCLUDE_FROM_ALL -# SYSTEM -# ) -# FetchContent_MakeAvailable(SFML) -# -# target_link_libraries(${GUI_TARGET_NAME} PRIVATE sfml-graphics) # Link SFML graphics library -# -# --- Special handling for Windows: Copy OpenAL DLL (for sound support) -# if(WIN32) -# add_custom_command( -# TARGET ${GUI_TARGET_NAME} -# COMMENT "Copy OpenAL DLL" -# PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$,x64,x86>/openal32.dll $ -# VERBATIM -# ) -# endif() -# // SFML is not used anymore set_common_properties(${GUI_TARGET_NAME}) - -# ======================================================== -# Test Setup (Only if SVA_BUILD_TEST is ON) -# ======================================================== - -if(${SVA_BUILD_TEST}) - # --- Add Google Test - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.12.1 - ) - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Prevent shared CRT issues on Windows - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) # Prevents installation of gtest on the system - FetchContent_MakeAvailable(googletest) - - # Enable testing support - enable_testing() - - # --- Create Test Executable - set(TEST_TARGET_NAME "${GUI_TARGET_NAME}_test") - - file(GLOB TEST_SOURCES "tests/*.cpp") - add_executable( - ${TEST_TARGET_NAME} - ${TEST_SOURCES} - ) - - target_link_libraries( - ${TEST_TARGET_NAME} - PRIVATE GTest::gtest_main # Link Google Test framework - ) - set_common_properties(${TEST_TARGET_NAME}) - - # --- Enable Google Test's test discovery feature - include(GoogleTest) - gtest_discover_tests(${TEST_TARGET_NAME}) - - # put google test targets into a folder - put_targets_into_folder( - FOLDER "gtest" - TARGETS - GTest::gtest_main - GTest::gmock_main - GTest::gmock - GTest::gtest - ) -endif() - # Option to create an includes target set(SVA_CREATE_INCLUDES_TARGET ON CACHE BOOL "Create an includes target") diff --git a/include/logger.hpp b/include/logger.hpp new file mode 100644 index 0000000..7f56393 --- /dev/null +++ b/include/logger.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include + +namespace sva +{ + class Logging + { + std::unordered_map m_Level_Names; + size_t m_Active_Level; + std::ostream& m_Stream; + public: + Logging(std::ostream& stream); + + template requires std::is_enum_v + std::string& levelName(const T lvl) + { + return m_Level_Names[static_cast(lvl)]; + } + + template + Logging& logln(Args&& ...args) + { + m_Stream << " [" << m_Level_Names[m_Active_Level] << "] " << (std::forward(args) << ...) << std::endl; + return *this; + } + + template requires std::is_enum_v + Logging& operator()(const T lvl) + { + try + { + std::string& lvn = m_Level_Names.at(static_cast(lvl)); + } + catch (...) + { + return *this; + } + m_Active_Level = static_cast(lvl); + return *this; + } + }; +} + + + +#ifdef SVA_LOGGING_IMPLEMENTATION +#undef SVA_LOGGING_IMPLEMENTATION + +sva::Logging::Logging(std::ostream& stream) : m_Active_Level(0), m_Stream(stream) +{ + m_Level_Names[0] = "General"; +} +#endif \ No newline at end of file diff --git a/src/gui/raygui.cpp b/src/gui/raygui.cpp deleted file mode 100644 index 3052e1a..0000000 --- a/src/gui/raygui.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define RAYGUI_IMPLEMENTATION -#include \ No newline at end of file diff --git a/src/libimpl.cpp b/src/libimpl.cpp new file mode 100644 index 0000000..c0767ff --- /dev/null +++ b/src/libimpl.cpp @@ -0,0 +1,5 @@ +#define RAYGUI_IMPLEMENTATION +#include + +#define SVA_LOGGING_IMPLEMENTATION +#include \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 675c642..92400de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,13 +13,115 @@ * Signature: "Darling, I'm Home!" - Jann Hoffmann **************************************************************/ - - - #include +// sva logger +#include + +/* raylib includes */ +#include +#include + +constexpr int window_width = 800; +constexpr int window_height = 650; +constexpr char window_title[] = "Sortiva"; + + +enum class logerr_level +{ + Debug = 0, + Window, + SVA, +}; + +void fitWindowToMonitor(int monitor = 0) +{ + if (GetMonitorCount() < monitor) return; + int width = GetMonitorHeight(monitor); + int height = GetMonitorHeight(monitor); + SetWindowMonitor(monitor); + SetWindowSize(width, height); + + int refresh_rate = GetMonitorRefreshRate(monitor); + SetTargetFPS(refresh_rate); +} + + int main(void) { std::cout << "Darling, I'm Home!\n"; + + sva::Logging logerr = sva::Logging(std::cerr); + logerr.levelName(logerr_level::Debug) = "Debug"; + logerr.levelName(logerr_level::Window) = "Window"; + logerr.levelName(logerr_level::SVA) = "SVA"; + + logerr(logerr_level::Debug); + + /* Window and rendering */ + + InitWindow(window_width, window_height, window_title); + + fitWindowToMonitor(); + + if (!IsWindowReady()) + { + logerr(logerr_level::Window).logln("Window could not be created..."); + return 0; + } + + ClearWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE | ConfigFlags::FLAG_WINDOW_TRANSPARENT); + SetWindowState(ConfigFlags::FLAG_WINDOW_ALWAYS_RUN | ConfigFlags::FLAG_BORDERLESS_WINDOWED_MODE); + + SetWindowFocused(); + + + bool m_Running = true; + + int wnd_width = GetRenderWidth(); + int wnd_height = GetRenderHeight(); + + Vector2 anchor03 = { static_cast(wnd_width) / 2 , static_cast(wnd_height) / 2 }; + + bool CloseQuestionBoxActive = false; + bool CQB_YesButton = false; + bool CQB_NoButton = false; + + while (m_Running) { + if (IsWindowResized()) + { + wnd_width = GetRenderWidth(); + wnd_height = GetRenderHeight(); + anchor03 = { static_cast(wnd_width) / 2 , static_cast(wnd_height) / 2 }; + } + + if (WindowShouldClose()) CloseQuestionBoxActive = !CloseQuestionBoxActive; + + BeginDrawing(); + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + if (CloseQuestionBoxActive) + { + CloseQuestionBoxActive = !GuiWindowBox({ anchor03.x + -168, anchor03.y + -88, 328, 160 }, "#191# Are you sure you want to close this program?"); + CQB_YesButton = GuiButton({ anchor03.x + -152, anchor03.y + 32, 120, 24 }, "Yes"); + CQB_NoButton = GuiButton({ anchor03.x + 24, anchor03.y + 32, 120, 24 }, "No"); + GuiLabel({ anchor03.x + -104, anchor03.y + -40, 208, 24 }, "Are you sure you want to close this?"); + GuiLabel({ anchor03.x + -56, anchor03.y + -8, 120, 24 }, "Press \"Yes\" to close"); + if (CQB_YesButton) + { + m_Running = false; + break; + } + if (CQB_NoButton) CloseQuestionBoxActive = false; + } + + EndDrawing(); + + } + + CloseWindow(); + return 0; } \ No newline at end of file diff --git a/tests/lua.cpp b/tests/lua.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/tests/tests.cpp b/tests/tests.cpp deleted file mode 100644 index 093e784..0000000 --- a/tests/tests.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} \ No newline at end of file