New Repository
Had my private email in a old commit of the first repository
This commit is contained in:
commit
f25d3cc8da
20 changed files with 6534 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
build
|
||||
test/local
|
||||
bin
|
||||
.idea
|
||||
.vs
|
||||
.vscode
|
229
CMakeLists.txt
Normal file
229
CMakeLists.txt
Normal file
|
@ -0,0 +1,229 @@
|
|||
# ========================================================
|
||||
# CMake Configuration for the Sortiva Project
|
||||
# ========================================================
|
||||
|
||||
# Specify the minimum CMake version required
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
# Project name, languages, and version
|
||||
project(sortiva
|
||||
LANGUAGES CXX
|
||||
VERSION 1.0.0
|
||||
)
|
||||
|
||||
# ========================================================
|
||||
# C++ Standard and General Settings
|
||||
# ========================================================
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20) # Use C++20
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enforce C++20 standard
|
||||
set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile commands (useful for IDEs)
|
||||
set(USE_FOLDERS ON) # Organize targets into folders (for IDEs)
|
||||
set(BUILD_SHARED_LIBS OFF) # Build static libraries by default
|
||||
|
||||
# =======================================================
|
||||
# Helper Functions:
|
||||
# Puts Targets into a Folder
|
||||
# Finds all files in a dir wich are defined file-types
|
||||
# =======================================================
|
||||
# This function puts targets into a specified folder.
|
||||
# It checks if the target exists and gets the actual target (if it is aliased).
|
||||
# It then sets the folder property for the target.
|
||||
|
||||
function(put_targets_into_folder)
|
||||
set(oneValueArgs FOLDER)
|
||||
set(multiValueArgs TARGETS)
|
||||
cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
foreach(target ${ARGS_TARGETS})
|
||||
# Check if target exists
|
||||
if (NOT TARGET ${target})
|
||||
message(FATAL_ERROR "${target} target not found")
|
||||
endif()
|
||||
|
||||
# Get the actual target (if it is aliased)
|
||||
get_target_property(actual_target ${target} ALIASED_TARGET)
|
||||
if (NOT actual_target)
|
||||
set(actual_target ${target})
|
||||
endif()
|
||||
|
||||
# Set the folder property for the target
|
||||
set_target_properties(${actual_target} PROPERTIES FOLDER ${ARGS_FOLDER})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(find_files var_name path)
|
||||
set(sources)
|
||||
foreach(ext ${ARGN})
|
||||
file(GLOB_RECURSE files "${path}/*.${ext}")
|
||||
list(APPEND sources ${files})
|
||||
endforeach()
|
||||
set(${var_name} ${${var_name}} ${sources} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# ========================================================
|
||||
# FetchContent Setup
|
||||
# ========================================================
|
||||
# FetchContent allows us to retrieve external libraries (e.g., Sol2, Google Test) dynamically.
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# Set FetchContent to work offline if needed
|
||||
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
|
||||
# ========================================================
|
||||
|
||||
# --- Add Sol2 (Lua C++ Binding Library)
|
||||
FetchContent_Declare(
|
||||
sol2
|
||||
GIT_REPOSITORY https://github.com/ThePhD/sol2.git
|
||||
GIT_TAG v3.3.0
|
||||
)
|
||||
FetchContent_MakeAvailable(sol2)
|
||||
|
||||
# ========================================================
|
||||
# Helper Function: Set Common Target Properties
|
||||
# ========================================================
|
||||
# This function defines common properties (such as libraries and include directories)
|
||||
# that are shared among all targets.
|
||||
|
||||
function(set_common_properties target)
|
||||
target_link_libraries(${target} PRIVATE sol2::sol2) # Link with Sol2
|
||||
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) # Include project headers
|
||||
target_sources(${target} PRIVATE ${SVA_COMMON_FILES}) # Include common files
|
||||
endfunction()
|
||||
|
||||
# ========================================================
|
||||
# GUI Setup
|
||||
# ========================================================
|
||||
|
||||
set(GUI_TARGET_NAME "${PROJECT_NAME}")
|
||||
# --- Create GUI Executable
|
||||
|
||||
find_files(SVA_GUI_FILES "./src/gui/" hpp cpp h c hxx cxx)
|
||||
add_executable(${GUI_TARGET_NAME}
|
||||
src/main.cpp # Entry point for the GUI application
|
||||
src/sva.hpp # Header file for the console
|
||||
${SVA_GUI_FILES}
|
||||
)
|
||||
|
||||
# ---------------
|
||||
# RAYLIB
|
||||
# ---------------
|
||||
# Dependencies
|
||||
set(RAYLIB_VERSION 5.0)
|
||||
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
|
||||
|
||||
if (NOT raylib_FOUND) # If there's none, fetch and build raylib
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
||||
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz
|
||||
)
|
||||
FetchContent_GetProperties(raylib)
|
||||
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
||||
set(FETCHCONTENT_QUIET NO)
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
|
||||
endif()
|
||||
endif()
|
||||
|
||||
put_targets_into_folder(FOLDER "raylib" TARGETS raylib uninstall)
|
||||
|
||||
target_link_libraries(${GUI_TARGET_NAME} PRIVATE raylib)
|
||||
|
||||
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
||||
if (APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
|
||||
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/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:${GUI_TARGET_NAME}>
|
||||
# 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
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
# Enable testing support
|
||||
enable_testing()
|
||||
|
||||
# --- Create Test Executable
|
||||
add_executable(
|
||||
sortiva_test
|
||||
tests/test_main.cpp # Test entry point
|
||||
tests/test_sorting_functions.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
sortiva_test
|
||||
PRIVATE GTest::gtest_main # Link Google Test framework
|
||||
)
|
||||
set_common_properties(sortiva_test)
|
||||
|
||||
# --- Enable Google Test's test discovery feature
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(sortiva_test)
|
||||
|
||||
# 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()
|
||||
|
201
LICENSE
Normal file
201
LICENSE
Normal file
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
sortiva
|
||||
-------------
|
34
include/flagman.hpp
Normal file
34
include/flagman.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
#include "types.hpp"
|
||||
|
||||
template <typename EnumType>
|
||||
class FlagManager
|
||||
{
|
||||
EnumType flags;
|
||||
public:
|
||||
static constexpr size_t size = sizeof(EnumType) * 8;
|
||||
FlagManager(EnumType flags) : flags(flags) {}
|
||||
|
||||
[[nodiscard]]
|
||||
bool get(EnumType flag) const { return (flags & flag) == flag; }
|
||||
void set(EnumType flag) { flags |= flag; }
|
||||
void clear(EnumType flag) { flags &= ~flag; }
|
||||
void toggle(EnumType flag) { flags ^= flag; }
|
||||
|
||||
[[nodiscard]]
|
||||
bool any() const { return flags; }
|
||||
|
||||
void set_all() { flags = EnumType(-1); }
|
||||
void clear_all() { flags = 0; }
|
||||
|
||||
bool operator==(const FlagManager& other) const { return flags == other.flags; }
|
||||
bool operator!=(const FlagManager& other) const { return flags != other.flags; }
|
||||
|
||||
// return true if every bit in *this is set in other
|
||||
bool of(FlagManager& other) const { return (flags & other.flags) == flags; }
|
||||
// return true if every bit in *this is set in other
|
||||
bool of(EnumType other) const { return (flags & other) == flags; }
|
||||
};
|
||||
|
||||
template <typename EnumType>
|
||||
using Flagman = FlagManager<EnumType>;
|
5521
include/raylibs/raygui.h
Normal file
5521
include/raylibs/raygui.h
Normal file
File diff suppressed because it is too large
Load diff
86
include/types.hpp
Normal file
86
include/types.hpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
template<typename T>
|
||||
struct TVector2
|
||||
{
|
||||
using type = T;
|
||||
T x, y;
|
||||
template<typename G>
|
||||
constexpr TVector2(G _x, G _y) {
|
||||
x = static_cast<T>(_x);
|
||||
y = static_cast<T>(_y);
|
||||
}
|
||||
constexpr TVector2(T _x, T _y) {
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
constexpr TVector2() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef TVector2<float> vec2f;
|
||||
typedef TVector2<double> vec2d;
|
||||
typedef TVector2<uintmax_t> vec2u;
|
||||
typedef TVector2<intmax_t> vec2i;
|
||||
|
||||
template<typename T>
|
||||
constexpr T min(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T max(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct TRect
|
||||
{
|
||||
using type = T;
|
||||
T x, y, width, height;
|
||||
|
||||
template<typename G>
|
||||
constexpr TRect(
|
||||
G _x, G _y,
|
||||
G _width, G _height )
|
||||
: x(static_cast<T>(_x)), y(static_cast<T>(_y)),
|
||||
width(static_cast<T>(_width)), height(static_cast<T>(_height))
|
||||
{}
|
||||
|
||||
constexpr TRect(
|
||||
T _x, T _y,
|
||||
T _width, T _height)
|
||||
: x(_x), y(_y),
|
||||
width(_width), height(_height)
|
||||
{}
|
||||
|
||||
constexpr TRect()
|
||||
: x(0), y(0),
|
||||
width(0), height(0)
|
||||
{}
|
||||
};
|
||||
|
||||
typedef TRect<float> rectf;
|
||||
typedef TRect<double> rectd;
|
||||
typedef TRect<uintmax_t> rectu;
|
||||
typedef TRect<intmax_t> recti;
|
||||
|
BIN
res/images/sva-logo.png
Normal file
BIN
res/images/sva-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
13
src/gui/Views/View.cpp
Normal file
13
src/gui/Views/View.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "View.h"
|
||||
#include <raylibs/raygui.h>
|
||||
|
||||
void View::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void View::update()
|
||||
{
|
||||
}
|
43
src/gui/Views/View.h
Normal file
43
src/gui/Views/View.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
#include "raylib.h"
|
||||
#include <types.hpp>
|
||||
|
||||
class View
|
||||
{
|
||||
friend class ViewManager;
|
||||
public:
|
||||
View(rectu rect) : m_rect(rect) {}
|
||||
virtual ~View() = default;
|
||||
virtual void draw();
|
||||
virtual void update();
|
||||
virtual void onMouseDown(vec2d mousePos) {}
|
||||
virtual void onMouseUp(vec2d mousePos) {}
|
||||
virtual void onMouseMove(vec2d mousePos) {}
|
||||
virtual void onKeyDown(int key) {}
|
||||
virtual void onKeyUp(int key) {}
|
||||
virtual void onKeyPress(int key) {}
|
||||
virtual void onFocus() {}
|
||||
virtual void onBlur() {}
|
||||
|
||||
virtual void onResize(vec2d factor)
|
||||
{
|
||||
m_rect.width = static_cast<rectu::type>(static_cast<float>(m_rect.width) * factor.x);
|
||||
m_rect.height = static_cast<rectu::type>(static_cast<float>(m_rect.height) * factor.y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec2u getPosition() const { return {m_rect.x, m_rect.y}; }
|
||||
vec2u getSize() const { return {m_rect.width, m_rect.height}; }
|
||||
const rectu& getRect() const { return m_rect; }
|
||||
void setPosition(vec2u pos) { m_rect.x = pos.x; m_rect.y = pos.y; }
|
||||
void setSize(vec2u size) { m_rect.width = size.x; m_rect.height = size.y; }
|
||||
void setRect(rectu &rect) { m_rect = rect; }
|
||||
virtual void Resize(float multiplier)
|
||||
{
|
||||
m_rect.width = static_cast<rectu::type>(static_cast<float>(m_rect.width) * multiplier);
|
||||
m_rect.height = static_cast<rectu::type>(static_cast<float>(m_rect.height) * multiplier);
|
||||
}
|
||||
private:
|
||||
rectu m_rect;
|
||||
};
|
21
src/gui/Views/ViewManager.cpp
Normal file
21
src/gui/Views/ViewManager.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "ViewManager.h"
|
||||
|
||||
ViewManager::ViewManager()
|
||||
{
|
||||
m_viewportSize = { GetScreenWidth(), GetScreenHeight() };
|
||||
m_mainView = new View({ 0, 0, m_viewportSize.x, m_viewportSize.y });
|
||||
}
|
||||
|
||||
void ViewManager::update()
|
||||
{
|
||||
if (IsWindowResized())
|
||||
{
|
||||
m_viewportSize = { GetScreenWidth(), GetScreenHeight() };
|
||||
m_mainView->onResize({ static_cast<float>(m_viewportSize.x), static_cast<float>(m_viewportSize.y) });
|
||||
}
|
||||
m_mainView->update();
|
||||
}
|
||||
|
||||
void ViewManager::draw()
|
||||
{
|
||||
}
|
16
src/gui/Views/ViewManager.h
Normal file
16
src/gui/Views/ViewManager.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
#include "View.h"
|
||||
#include <vector>
|
||||
#include <types.hpp>
|
||||
|
||||
class ViewManager
|
||||
{
|
||||
vec2u m_viewportSize;
|
||||
public:
|
||||
ViewManager();
|
||||
~ViewManager();
|
||||
void update();
|
||||
void draw();
|
||||
private:
|
||||
View* m_mainView;
|
||||
};
|
60
src/gui/drawing_helper.cpp
Normal file
60
src/gui/drawing_helper.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "drawing_helper.hpp"
|
||||
|
||||
namespace sva
|
||||
{
|
||||
std::vector<std::string> split(const std::string& str, char delim)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
std::istringstream tokenStream(str);
|
||||
while (std::getline(tokenStream, token, delim))
|
||||
{
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Color sva::GetThemeColor(GuiControlProperty property)
|
||||
{
|
||||
return GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL));
|
||||
}
|
||||
|
||||
void sva::DrawText(const std::string& text, vec2i pos, int size, Color color, TEXT_ALIGNMENT alignment)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TEXT_ALIGN_LEFT:
|
||||
return DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
if (text.find('\n') != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> lines = split(text, '\n');
|
||||
for (auto& line : lines)
|
||||
{
|
||||
pos.x -= MeasureText(line.c_str(), size);
|
||||
DrawText(line.c_str(), pos.x, pos.y, size, color);
|
||||
pos.y += size;
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos.x -= MeasureText(text.c_str(), size);
|
||||
return DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
|
||||
case TEXT_ALIGN_CENTER:
|
||||
if (text.find('\n') != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> lines = sva::split(text, '\n');
|
||||
for (auto& line : lines)
|
||||
{
|
||||
pos.x -= MeasureText(line.c_str(), size) / 2;
|
||||
DrawText(line.c_str(), pos.x, pos.y, size, color);
|
||||
pos.y += size;
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos.x -= MeasureText(text.c_str(), size) / 2;
|
||||
DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
}
|
||||
}
|
29
src/gui/drawing_helper.hpp
Normal file
29
src/gui/drawing_helper.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <raylib.h>
|
||||
#include <raylibs/raygui.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace sva
|
||||
{
|
||||
template<typename T>
|
||||
struct TVector2
|
||||
{
|
||||
T x, y;
|
||||
};
|
||||
typedef TVector2<int> vec2i;
|
||||
typedef TVector2<float> vec2f;
|
||||
|
||||
enum TEXT_ALIGNMENT
|
||||
{
|
||||
TEXT_ALIGN_LEFT,
|
||||
TEXT_ALIGN_CENTER,
|
||||
TEXT_ALIGN_RIGHT
|
||||
};
|
||||
|
||||
|
||||
Color GetThemeColor(GuiControlProperty property);
|
||||
|
||||
void DrawText(const std::string& text, vec2i pos, int size, Color color = GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), TEXT_ALIGNMENT alignment = TEXT_ALIGN_LEFT);
|
||||
}
|
2
src/gui/raygui.cpp
Normal file
2
src/gui/raygui.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define RAYGUI_IMPLEMENTATION
|
||||
#include <raylibs/raygui.h>
|
42
src/gui/themes/dark.h
Normal file
42
src/gui/themes/dark.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// StyleAsCode exporter v2.0 - Style data exported as a values array //
|
||||
// //
|
||||
// USAGE: On init call: GuiLoadStyleDark(); //
|
||||
// //
|
||||
// more info and bugs-report: github.com/raysan5/raygui //
|
||||
// feedback and support: ray[at]raylibtech.com //
|
||||
// //
|
||||
// Copyright (c) 2020-2023 raylib technologies (@raylibtech) //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DARK_STYLE_PROPS_COUNT 8
|
||||
|
||||
// Custom style name: dark
|
||||
static const GuiStyleProp darkStyleProps[DARK_STYLE_PROPS_COUNT] = {
|
||||
{ 0, 0, 0x7b7b7bff }, // DEFAULT_BORDER_COLOR_NORMAL
|
||||
{ 0, 1, 0x595959ff }, // DEFAULT_BASE_COLOR_NORMAL
|
||||
{ 0, 2, 0xdededeff }, // DEFAULT_TEXT_COLOR_NORMAL
|
||||
{ 0, 9, 0x232323ff }, // DEFAULT_BORDER_COLOR_DISABLED
|
||||
{ 0, 10, 0x606060ff }, // DEFAULT_BASE_COLOR_DISABLED
|
||||
{ 0, 11, 0x9f9f9fff }, // DEFAULT_TEXT_COLOR_DISABLED
|
||||
{ 0, 18, 0x68cbd0ff }, // DEFAULT_LINE_COLOR
|
||||
{ 0, 19, 0x262626ff }, // DEFAULT_BACKGROUND_COLOR
|
||||
};
|
||||
|
||||
// Style loading function: dark
|
||||
static void GuiLoadStyleDark(void)
|
||||
{
|
||||
// Load style properties provided
|
||||
// NOTE: Default properties are propagated
|
||||
for (int i = 0; i < DARK_STYLE_PROPS_COUNT; i++)
|
||||
{
|
||||
GuiSetStyle(darkStyleProps[i].controlId, darkStyleProps[i].propertyId, darkStyleProps[i].propertyValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
// TODO: Custom user style setup: Set specific properties here (if required)
|
||||
// i.e. Controls specific BORDER_WIDTH, TEXT_PADDING, TEXT_ALIGNMENT
|
||||
}
|
152
src/main.cpp
Normal file
152
src/main.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
#include <raylibs/raygui.h>
|
||||
#include "sva.hpp"
|
||||
|
||||
|
||||
#include "gui/drawing_helper.hpp"
|
||||
|
||||
#define RESOURCES_PATH "G:\\School\\Belegarbeit\\sortiva\\res\\"
|
||||
|
||||
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 720;
|
||||
|
||||
enum GAME_STATES
|
||||
{
|
||||
SVA_STATE_TITLE,
|
||||
SVA_STATE_GAMEPLAY,
|
||||
};
|
||||
|
||||
GAME_STATES gameState = SVA_STATE_TITLE;
|
||||
|
||||
void UpdateDrawFrame(); // Update and Draw one frame
|
||||
|
||||
#include "gui/themes/dark.h"
|
||||
#include <filesystem>
|
||||
#include "gui/Views/ViewManager.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
sva_console_init();
|
||||
|
||||
if(!DirectoryExists(RESOURCES_PATH))
|
||||
{
|
||||
std::cerr << "Resources folder not found!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "Sortiva - Sorting Algorithm Visualizer");
|
||||
|
||||
SetWindowIcon(LoadImage(RESOURCES_PATH "/images/sva-logo.png"));
|
||||
|
||||
SetWindowMinSize(screenWidth, screenHeight);
|
||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||
SetExitKey(0);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
GuiLoadStyleDark();
|
||||
GuiSetStyle(DEFAULT, TEXT_SIZE, 20);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
if (IsWindowResized())
|
||||
{
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
}
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Render Functions
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
void RenderGameplayState();
|
||||
|
||||
|
||||
Rectangle ButtonRects[] = {
|
||||
{50, 150, 150, 40},
|
||||
{50, 200, 150, 40},
|
||||
{50, 300, 150, 40},
|
||||
};
|
||||
|
||||
void UpdateDrawFrame()
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
|
||||
|
||||
switch (gameState)
|
||||
{
|
||||
case SVA_STATE_TITLE:
|
||||
sva::DrawText("Sortiva", {screenWidth/2, 20}, 100, sva::GetThemeColor(TEXT_COLOR_NORMAL), sva::TEXT_ALIGN_CENTER);
|
||||
|
||||
if(GuiButton(ButtonRects[0], "Öffnen"))
|
||||
{
|
||||
gameState = SVA_STATE_GAMEPLAY;
|
||||
}
|
||||
if(GuiButton(ButtonRects[1], "Speichern"))
|
||||
{
|
||||
gameState = SVA_STATE_GAMEPLAY;
|
||||
}
|
||||
if(GuiButton(ButtonRects[2], "Schließen"))
|
||||
{
|
||||
CloseWindow();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
break;
|
||||
case SVA_STATE_GAMEPLAY:
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
{
|
||||
gameState = SVA_STATE_TITLE;
|
||||
}
|
||||
RenderGameplayState();
|
||||
break;
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
#include <numbers>
|
||||
|
||||
#define PI_2 std::numbers::pi_v<float> / 2
|
||||
|
||||
#define sin3(x) pow((-cos(PI_2+ ##x)),3)
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Vector2 heart_position = Vector2{static_cast<float>(screenWidth)/2, static_cast<float>(screenHeight)/2.5f};
|
||||
Vector2 heart_function(float t, float scale)
|
||||
{
|
||||
return Vector2{
|
||||
((16 * static_cast<float>(sin3(t))) * scale) + heart_position.x,
|
||||
((13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t)) * -scale) + heart_position.y
|
||||
};
|
||||
}
|
||||
|
||||
#define STEPS 1000
|
||||
#define STEP_SIZE 0.01f
|
||||
|
||||
void RenderGameplayState()
|
||||
{
|
||||
for (int i = 0; i < STEPS; i++)
|
||||
{
|
||||
Vector2 pos = heart_function(static_cast<float>(i) * STEP_SIZE, 20);
|
||||
Vector2 pos2 = heart_function(static_cast<float>(i) * STEP_SIZE + STEP_SIZE, 20);
|
||||
DrawLine(
|
||||
pos.x,
|
||||
pos.y,
|
||||
pos2.x,
|
||||
pos2.y,
|
||||
GetColor(GuiGetStyle(DEFAULT, LINE_COLOR))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
17
src/sva.hpp
Normal file
17
src/sva.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
inline const char* ASCII_TITLE = R"(
|
||||
__
|
||||
(_ _ ___|_ o _
|
||||
__)(_) | |_ | \_/(_|
|
||||
|
||||
|
||||
|
||||
)";
|
||||
|
||||
inline void sva_console_init()
|
||||
{
|
||||
std::cout << ASCII_TITLE;
|
||||
}
|
6
tests/test_main.cpp
Normal file
6
tests/test_main.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
54
tests/test_sorting_functions.cpp
Normal file
54
tests/test_sorting_functions.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
// tests/sorting_tests.cpp
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
|
||||
template<typename T>
|
||||
void swap(T& a, T& b) noexcept
|
||||
{
|
||||
T temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void bubble_sort(std::vector<T>& in)
|
||||
{
|
||||
for (size_t i = 0; i < in.size(); ++i)
|
||||
{
|
||||
for (size_t j = 0; j < in.size() - 1; ++j)
|
||||
{
|
||||
if (in[j] > in[j + 1])
|
||||
{
|
||||
swap(in[j], in[j + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(BubbleSortTest, CorrectlySortsVector) {
|
||||
std::vector input = {5, 2, 8, 1, 9};
|
||||
std::vector expected = {1, 2, 5, 8, 9};
|
||||
|
||||
bubble_sort(input);
|
||||
|
||||
EXPECT_EQ(input, expected);
|
||||
}
|
||||
|
||||
TEST(BubbleSortTest, HandlesEmptyVector) {
|
||||
std::vector<int> input = {};
|
||||
std::vector<int> expected = {};
|
||||
|
||||
bubble_sort(input);
|
||||
|
||||
EXPECT_EQ(input, expected);
|
||||
}
|
||||
|
||||
TEST(BubbleSortTest, HandlesSingleElement) {
|
||||
std::vector input = {1};
|
||||
std::vector expected = {1};
|
||||
|
||||
bubble_sort(input);
|
||||
|
||||
EXPECT_EQ(input, expected);
|
||||
}
|
Loading…
Reference in a new issue