diff --git a/.gitignore b/.gitignore index c9ce571..b95a92c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ build .idea cmake-**/ .kdev4 -*.kdev4 \ No newline at end of file +*.kdev4 +assets/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a69366..021655c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(colysis - LANGUAGES C CXX + LANGUAGES CXX VERSION 0.0.1 ) @@ -10,7 +10,7 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -22,24 +22,20 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Build static libraries by include(cmake/CPM.cmake) +# sfml CPMAddPackage( - NAME raylib - GITHUB_REPOSITORY raysan5/raylib - GIT_TAG 5.5 + NAME sfml + GITHUB_REPOSITORY SFML/SFML + GIT_TAG 3.0.0 ) -CPMAddPackage( - NAME flecs - GITHUB_REPOSITORY SanderMertens/flecs - GIT_TAG v4.0.4 -) +# # flecs +# CPMAddPackage( +# NAME flecs +# GITHUB_REPOSITORY SanderMertens/flecs +# GIT_TAG v4.0.4 +# ) -## alyson engine (needs flecs and raylib) -set(ASSETS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/assets/") -add_subdirectory(alyson) - - -## Colysis .game include(cmake/utils.cmake) @@ -51,22 +47,17 @@ add_executable(colysis ) target_link_libraries(colysis - raylib - flecs::flecs_static - alyson + SFML::Audio + SFML::Graphics + SFML::Window + SFML::System ) -target_include_directories(colysis PUBLIC include - #${ALYSON_INCLUDE_DIR} -) # put the assets folder path as a C preprocessor define +set(ASSETS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/assets/") target_compile_definitions(colysis PRIVATE ASSETS_PATH="${ASSETS_PATH}") +message(STATUS "Assets path : ${ASSETS_PATH}") -# if the os is windows, add the uninstall target to the vendor/raylib folder -if(WIN32) - put_targets_into_folder(FOLDER "vendor/raylib" TARGETS uninstall) -endif() -put_targets_into_folder(FOLDER "vendor/raylib" TARGETS raylib) -put_targets_into_folder(FOLDER "vendor/flecs" TARGETS flecs::flecs flecs::flecs_static) +# put_targets_into_folder(FOLDER "vendor/flecs" TARGETS flecs::flecs flecs::flecs_static) diff --git a/README.md b/README.md index 1c87905..1708637 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Colysis -A little video game with a custom engine written in C/C++. -It uses [Flecs](https://github.com/SanderMertens/flecs) as an ECS framework and [Raylib](https://www.raylib.com/) as a 2D graphics library. +A simple game engine written in C++ and using SFML. ## Building To build the project, you need to have [CMake](https://cmake.org/) installed. diff --git a/alyson/CMakeLists.txt b/alyson/CMakeLists.txt deleted file mode 100644 index 757d975..0000000 --- a/alyson/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -project(alyson - VERSION 0.0.1 - LANGUAGES C CXX -) - -cmake_minimum_required(VERSION 3.20) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -include(cmake/utils.cmake) - -add_library(alyson) -target_include_directories(alyson PUBLIC includes) - -CPMAddPackage( - NAME raylib - GITHUB_REPOSITORY raysan5/raylib - GIT_TAG 5.5 -) - -CPMAddPackage( - NAME flecs - GITHUB_REPOSITORY SanderMertens/flecs - GIT_TAG v4.0.4 -) - -target_link_libraries(alyson PUBLIC raylib) -target_link_libraries(alyson PUBLIC flecs::flecs_static) - -target_compile_definitions(alyson PRIVATE ASSETS_PATH="${ASSETS_PATH}") - -# Add alyson files -find_files(alyson_src src cpp hpp cxx hxx c h) - -target_sources(alyson PRIVATE ${alyson_src}) - -# set(ALYSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/alyson/include) - -# google tests - -find_package(GTest QUIET) -if(NOT GTest_FOUND) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.12.1 - ) - - FetchContent_MakeAvailable(googletest) -endif() - -find_files(alyson_test_src tests cpp hpp cxx hxx c h) -add_executable(alyson_test ${alyson_test_src}) -target_link_libraries(alyson_test PRIVATE alyson) -target_link_libraries(alyson_test PRIVATE GTest::gtest) -target_link_libraries(alyson_test PRIVATE GTest::gtest_main) - -target_include_directories(alyson_test PRIVATE ${GTEST_INCLUDE_DIRS}) - diff --git a/alyson/LICENSE b/alyson/LICENSE deleted file mode 100644 index 2ac80e8..0000000 --- a/alyson/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2025 n0ffie (noffie.github@icloud.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/alyson/cmake/CPM.cmake b/alyson/cmake/CPM.cmake deleted file mode 100644 index 6130666..0000000 --- a/alyson/cmake/CPM.cmake +++ /dev/null @@ -1,1289 +0,0 @@ -# CPM.cmake - CMake's missing package manager -# =========================================== -# See https://github.com/cpm-cmake/CPM.cmake for usage and update instructions. -# -# MIT License -# ----------- -#[[ - Copyright (c) 2019-2023 Lars Melchior and contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -]] - -cmake_minimum_required(VERSION 3.14 FATAL_ERROR) - -# Initialize logging prefix -if(NOT CPM_INDENT) - set(CPM_INDENT - "CPM:" - CACHE INTERNAL "" - ) -endif() - -if(NOT COMMAND cpm_message) - function(cpm_message) - message(${ARGV}) - endfunction() -endif() - -if(DEFINED EXTRACTED_CPM_VERSION) - set(CURRENT_CPM_VERSION "${EXTRACTED_CPM_VERSION}${CPM_DEVELOPMENT}") -else() - set(CURRENT_CPM_VERSION 0.40.7) -endif() - -get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH) -if(CPM_DIRECTORY) - if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY) - if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION) - message( - AUTHOR_WARNING - "${CPM_INDENT} \ -A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \ -It is recommended to upgrade CPM to the most recent version. \ -See https://github.com/cpm-cmake/CPM.cmake for more information." - ) - endif() - if(${CMAKE_VERSION} VERSION_LESS "3.17.0") - include(FetchContent) - endif() - return() - endif() - - get_property( - CPM_INITIALIZED GLOBAL "" - PROPERTY CPM_INITIALIZED - SET - ) - if(CPM_INITIALIZED) - return() - endif() -endif() - -if(CURRENT_CPM_VERSION MATCHES "development-version") - message( - WARNING "${CPM_INDENT} Your project is using an unstable development version of CPM.cmake. \ -Please update to a recent release if possible. \ -See https://github.com/cpm-cmake/CPM.cmake for details." - ) -endif() - -set_property(GLOBAL PROPERTY CPM_INITIALIZED true) - -macro(cpm_set_policies) - # the policy allows us to change options without caching - cmake_policy(SET CMP0077 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) - - # the policy allows us to change set(CACHE) without caching - if(POLICY CMP0126) - cmake_policy(SET CMP0126 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0126 NEW) - endif() - - # The policy uses the download time for timestamp, instead of the timestamp in the archive. This - # allows for proper rebuilds when a projects url changes - if(POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) - endif() - - # treat relative git repository paths as being relative to the parent project's remote - if(POLICY CMP0150) - cmake_policy(SET CMP0150 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0150 NEW) - endif() -endmacro() -cpm_set_policies() - -option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" - $ENV{CPM_USE_LOCAL_PACKAGES} -) -option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" - $ENV{CPM_LOCAL_PACKAGES_ONLY} -) -option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL}) -option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package" - $ENV{CPM_DONT_UPDATE_MODULE_PATH} -) -option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path" - $ENV{CPM_DONT_CREATE_PACKAGE_LOCK} -) -option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK - "Add all packages added through CPM.cmake to the package lock" - $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK} -) -option(CPM_USE_NAMED_CACHE_DIRECTORIES - "Use additional directory of package name in cache on the most nested level." - $ENV{CPM_USE_NAMED_CACHE_DIRECTORIES} -) - -set(CPM_VERSION - ${CURRENT_CPM_VERSION} - CACHE INTERNAL "" -) -set(CPM_DIRECTORY - ${CPM_CURRENT_DIRECTORY} - CACHE INTERNAL "" -) -set(CPM_FILE - ${CMAKE_CURRENT_LIST_FILE} - CACHE INTERNAL "" -) -set(CPM_PACKAGES - "" - CACHE INTERNAL "" -) -set(CPM_DRY_RUN - OFF - CACHE INTERNAL "Don't download or configure dependencies (for testing)" -) - -if(DEFINED ENV{CPM_SOURCE_CACHE}) - set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE}) -else() - set(CPM_SOURCE_CACHE_DEFAULT OFF) -endif() - -set(CPM_SOURCE_CACHE - ${CPM_SOURCE_CACHE_DEFAULT} - CACHE PATH "Directory to download CPM dependencies" -) - -if(NOT CPM_DONT_UPDATE_MODULE_PATH AND NOT DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR) - set(CPM_MODULE_PATH - "${CMAKE_BINARY_DIR}/CPM_modules" - CACHE INTERNAL "" - ) - # remove old modules - file(REMOVE_RECURSE ${CPM_MODULE_PATH}) - file(MAKE_DIRECTORY ${CPM_MODULE_PATH}) - # locally added CPM modules should override global packages - set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}") -endif() - -if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) - set(CPM_PACKAGE_LOCK_FILE - "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake" - CACHE INTERNAL "" - ) - file(WRITE ${CPM_PACKAGE_LOCK_FILE} - "# CPM Package Lock\n# This file should be committed to version control\n\n" - ) -endif() - -include(FetchContent) - -# Try to infer package name from git repository uri (path or url) -function(cpm_package_name_from_git_uri URI RESULT) - if("${URI}" MATCHES "([^/:]+)/?.git/?$") - set(${RESULT} - ${CMAKE_MATCH_1} - PARENT_SCOPE - ) - else() - unset(${RESULT} PARENT_SCOPE) - endif() -endfunction() - -# Try to infer package name and version from a url -function(cpm_package_name_and_ver_from_url url outName outVer) - if(url MATCHES "[/\\?]([a-zA-Z0-9_\\.-]+)\\.(tar|tar\\.gz|tar\\.bz2|zip|ZIP)(\\?|/|$)") - # We matched an archive - set(filename "${CMAKE_MATCH_1}") - - if(filename MATCHES "([a-zA-Z0-9_\\.-]+)[_-]v?(([0-9]+\\.)*[0-9]+[a-zA-Z0-9]*)") - # We matched - (ie foo-1.2.3) - set(${outName} - "${CMAKE_MATCH_1}" - PARENT_SCOPE - ) - set(${outVer} - "${CMAKE_MATCH_2}" - PARENT_SCOPE - ) - elseif(filename MATCHES "(([0-9]+\\.)+[0-9]+[a-zA-Z0-9]*)") - # We couldn't find a name, but we found a version - # - # In many cases (which we don't handle here) the url would look something like - # `irrelevant/ACTUAL_PACKAGE_NAME/irrelevant/1.2.3.zip`. In such a case we can't possibly - # distinguish the package name from the irrelevant bits. Moreover if we try to match the - # package name from the filename, we'd get bogus at best. - unset(${outName} PARENT_SCOPE) - set(${outVer} - "${CMAKE_MATCH_1}" - PARENT_SCOPE - ) - else() - # Boldly assume that the file name is the package name. - # - # Yes, something like `irrelevant/ACTUAL_NAME/irrelevant/download.zip` will ruin our day, but - # such cases should be quite rare. No popular service does this... we think. - set(${outName} - "${filename}" - PARENT_SCOPE - ) - unset(${outVer} PARENT_SCOPE) - endif() - else() - # No ideas yet what to do with non-archives - unset(${outName} PARENT_SCOPE) - unset(${outVer} PARENT_SCOPE) - endif() -endfunction() - -function(cpm_find_package NAME VERSION) - string(REPLACE " " ";" EXTRA_ARGS "${ARGN}") - find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET) - if(${CPM_ARGS_NAME}_FOUND) - if(DEFINED ${CPM_ARGS_NAME}_VERSION) - set(VERSION ${${CPM_ARGS_NAME}_VERSION}) - endif() - cpm_message(STATUS "${CPM_INDENT} Using local package ${CPM_ARGS_NAME}@${VERSION}") - CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}") - set(CPM_PACKAGE_FOUND - YES - PARENT_SCOPE - ) - else() - set(CPM_PACKAGE_FOUND - NO - PARENT_SCOPE - ) - endif() -endfunction() - -# Create a custom FindXXX.cmake module for a CPM package This prevents `find_package(NAME)` from -# finding the system library -function(cpm_create_module_file Name) - if(NOT CPM_DONT_UPDATE_MODULE_PATH) - if(DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR) - # Redirect find_package calls to the CPM package. This is what FetchContent does when you set - # OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for find_package in CONFIG - # mode, unlike the Find${Name}.cmake fallback. CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined - # in script mode, or in CMake < 3.24. - # https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples - string(TOLOWER ${Name} NameLower) - file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake - "include(\"\${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n" - "include(\"\${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n" - ) - file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config-version.cmake - "set(PACKAGE_VERSION_COMPATIBLE TRUE)\n" "set(PACKAGE_VERSION_EXACT TRUE)\n" - ) - else() - file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake - "include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)" - ) - endif() - endif() -endfunction() - -# Find a package locally or fallback to CPMAddPackage -function(CPMFindPackage) - set(oneValueArgs NAME VERSION GIT_TAG FIND_PACKAGE_ARGUMENTS) - - cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN}) - - if(NOT DEFINED CPM_ARGS_VERSION) - if(DEFINED CPM_ARGS_GIT_TAG) - cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION) - endif() - endif() - - set(downloadPackage ${CPM_DOWNLOAD_ALL}) - if(DEFINED CPM_DOWNLOAD_${CPM_ARGS_NAME}) - set(downloadPackage ${CPM_DOWNLOAD_${CPM_ARGS_NAME}}) - elseif(DEFINED ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) - set(downloadPackage $ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) - endif() - if(downloadPackage) - CPMAddPackage(${ARGN}) - cpm_export_variables(${CPM_ARGS_NAME}) - return() - endif() - - cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}) - - if(NOT CPM_PACKAGE_FOUND) - CPMAddPackage(${ARGN}) - cpm_export_variables(${CPM_ARGS_NAME}) - endif() - -endfunction() - -# checks if a package has been added before -function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION) - if("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES) - CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION) - if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}") - message( - WARNING - "${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})." - ) - endif() - cpm_get_fetch_properties(${CPM_ARGS_NAME}) - set(${CPM_ARGS_NAME}_ADDED NO) - set(CPM_PACKAGE_ALREADY_ADDED - YES - PARENT_SCOPE - ) - cpm_export_variables(${CPM_ARGS_NAME}) - else() - set(CPM_PACKAGE_ALREADY_ADDED - NO - PARENT_SCOPE - ) - endif() -endfunction() - -# Parse the argument of CPMAddPackage in case a single one was provided and convert it to a list of -# arguments which can then be parsed idiomatically. For example gh:foo/bar@1.2.3 will be converted -# to: GITHUB_REPOSITORY;foo/bar;VERSION;1.2.3 -function(cpm_parse_add_package_single_arg arg outArgs) - # Look for a scheme - if("${arg}" MATCHES "^([a-zA-Z]+):(.+)$") - string(TOLOWER "${CMAKE_MATCH_1}" scheme) - set(uri "${CMAKE_MATCH_2}") - - # Check for CPM-specific schemes - if(scheme STREQUAL "gh") - set(out "GITHUB_REPOSITORY;${uri}") - set(packageType "git") - elseif(scheme STREQUAL "gl") - set(out "GITLAB_REPOSITORY;${uri}") - set(packageType "git") - elseif(scheme STREQUAL "bb") - set(out "BITBUCKET_REPOSITORY;${uri}") - set(packageType "git") - # A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine - # type - elseif(arg MATCHES ".git/?(@|#|$)") - set(out "GIT_REPOSITORY;${arg}") - set(packageType "git") - else() - # Fall back to a URL - set(out "URL;${arg}") - set(packageType "archive") - - # We could also check for SVN since FetchContent supports it, but SVN is so rare these days. - # We just won't bother with the additional complexity it will induce in this function. SVN is - # done by multi-arg - endif() - else() - if(arg MATCHES ".git/?(@|#|$)") - set(out "GIT_REPOSITORY;${arg}") - set(packageType "git") - else() - # Give up - message(FATAL_ERROR "${CPM_INDENT} Can't determine package type of '${arg}'") - endif() - endif() - - # For all packages we interpret @... as version. Only replace the last occurrence. Thus URIs - # containing '@' can be used - string(REGEX REPLACE "@([^@]+)$" ";VERSION;\\1" out "${out}") - - # Parse the rest according to package type - if(packageType STREQUAL "git") - # For git repos we interpret #... as a tag or branch or commit hash - string(REGEX REPLACE "#([^#]+)$" ";GIT_TAG;\\1" out "${out}") - elseif(packageType STREQUAL "archive") - # For archives we interpret #... as a URL hash. - string(REGEX REPLACE "#([^#]+)$" ";URL_HASH;\\1" out "${out}") - # We don't try to parse the version if it's not provided explicitly. cpm_get_version_from_url - # should do this at a later point - else() - # We should never get here. This is an assertion and hitting it means there's a problem with the - # code above. A packageType was set, but not handled by this if-else. - message(FATAL_ERROR "${CPM_INDENT} Unsupported package type '${packageType}' of '${arg}'") - endif() - - set(${outArgs} - ${out} - PARENT_SCOPE - ) -endfunction() - -# Check that the working directory for a git repo is clean -function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean) - - find_package(Git REQUIRED) - - if(NOT GIT_EXECUTABLE) - # No git executable, assume directory is clean - set(${isClean} - TRUE - PARENT_SCOPE - ) - return() - endif() - - # check for uncommitted changes - execute_process( - COMMAND ${GIT_EXECUTABLE} status --porcelain - RESULT_VARIABLE resultGitStatus - OUTPUT_VARIABLE repoStatus - OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET - WORKING_DIRECTORY ${repoPath} - ) - if(resultGitStatus) - # not supposed to happen, assume clean anyway - message(WARNING "${CPM_INDENT} Calling git status on folder ${repoPath} failed") - set(${isClean} - TRUE - PARENT_SCOPE - ) - return() - endif() - - if(NOT "${repoStatus}" STREQUAL "") - set(${isClean} - FALSE - PARENT_SCOPE - ) - return() - endif() - - # check for committed changes - execute_process( - COMMAND ${GIT_EXECUTABLE} diff -s --exit-code ${gitTag} - RESULT_VARIABLE resultGitDiff - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_QUIET - WORKING_DIRECTORY ${repoPath} - ) - - if(${resultGitDiff} EQUAL 0) - set(${isClean} - TRUE - PARENT_SCOPE - ) - else() - set(${isClean} - FALSE - PARENT_SCOPE - ) - endif() - -endfunction() - -# Add PATCH_COMMAND to CPM_ARGS_UNPARSED_ARGUMENTS. This method consumes a list of files in ARGN -# then generates a `PATCH_COMMAND` appropriate for `ExternalProject_Add()`. This command is appended -# to the parent scope's `CPM_ARGS_UNPARSED_ARGUMENTS`. -function(cpm_add_patches) - # Return if no patch files are supplied. - if(NOT ARGN) - return() - endif() - - # Find the patch program. - find_program(PATCH_EXECUTABLE patch) - if(CMAKE_HOST_WIN32 AND NOT PATCH_EXECUTABLE) - # The Windows git executable is distributed with patch.exe. Find the path to the executable, if - # it exists, then search `../usr/bin` and `../../usr/bin` for patch.exe. - find_package(Git QUIET) - if(GIT_EXECUTABLE) - get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY) - get_filename_component(extra_search_path_1up ${extra_search_path} DIRECTORY) - get_filename_component(extra_search_path_2up ${extra_search_path_1up} DIRECTORY) - find_program( - PATCH_EXECUTABLE patch HINTS "${extra_search_path_1up}/usr/bin" - "${extra_search_path_2up}/usr/bin" - ) - endif() - endif() - if(NOT PATCH_EXECUTABLE) - message(FATAL_ERROR "Couldn't find `patch` executable to use with PATCHES keyword.") - endif() - - # Create a temporary - set(temp_list ${CPM_ARGS_UNPARSED_ARGUMENTS}) - - # Ensure each file exists (or error out) and add it to the list. - set(first_item True) - foreach(PATCH_FILE ${ARGN}) - # Make sure the patch file exists, if we can't find it, try again in the current directory. - if(NOT EXISTS "${PATCH_FILE}") - if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}") - message(FATAL_ERROR "Couldn't find patch file: '${PATCH_FILE}'") - endif() - set(PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}") - endif() - - # Convert to absolute path for use with patch file command. - get_filename_component(PATCH_FILE "${PATCH_FILE}" ABSOLUTE) - - # The first patch entry must be preceded by "PATCH_COMMAND" while the following items are - # preceded by "&&". - if(first_item) - set(first_item False) - list(APPEND temp_list "PATCH_COMMAND") - else() - list(APPEND temp_list "&&") - endif() - # Add the patch command to the list - list(APPEND temp_list "${PATCH_EXECUTABLE}" "-p1" "<" "${PATCH_FILE}") - endforeach() - - # Move temp out into parent scope. - set(CPM_ARGS_UNPARSED_ARGUMENTS - ${temp_list} - PARENT_SCOPE - ) - -endfunction() - -# method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload -# FetchContent calls. As these are internal cmake properties, this method should be used carefully -# and may need modification in future CMake versions. Source: -# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152 -function(cpm_override_fetchcontent contentName) - cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "") - if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "") - message(FATAL_ERROR "${CPM_INDENT} Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}") - endif() - - string(TOLOWER ${contentName} contentNameLower) - set(prefix "_FetchContent_${contentNameLower}") - - set(propertyName "${prefix}_sourceDir") - define_property( - GLOBAL - PROPERTY ${propertyName} - BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" - FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" - ) - set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}") - - set(propertyName "${prefix}_binaryDir") - define_property( - GLOBAL - PROPERTY ${propertyName} - BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" - FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" - ) - set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}") - - set(propertyName "${prefix}_populated") - define_property( - GLOBAL - PROPERTY ${propertyName} - BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" - FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" - ) - set_property(GLOBAL PROPERTY ${propertyName} TRUE) -endfunction() - -# Download and add a package from source -function(CPMAddPackage) - cpm_set_policies() - - list(LENGTH ARGN argnLength) - if(argnLength EQUAL 1) - cpm_parse_add_package_single_arg("${ARGN}" ARGN) - - # The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM - set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;") - endif() - - set(oneValueArgs - NAME - FORCE - VERSION - GIT_TAG - DOWNLOAD_ONLY - GITHUB_REPOSITORY - GITLAB_REPOSITORY - BITBUCKET_REPOSITORY - GIT_REPOSITORY - SOURCE_DIR - FIND_PACKAGE_ARGUMENTS - NO_CACHE - SYSTEM - GIT_SHALLOW - EXCLUDE_FROM_ALL - SOURCE_SUBDIR - CUSTOM_CACHE_KEY - ) - - set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES) - - cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") - - # Set default values for arguments - - if(NOT DEFINED CPM_ARGS_VERSION) - if(DEFINED CPM_ARGS_GIT_TAG) - cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION) - endif() - endif() - - if(CPM_ARGS_DOWNLOAD_ONLY) - set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY}) - else() - set(DOWNLOAD_ONLY NO) - endif() - - if(DEFINED CPM_ARGS_GITHUB_REPOSITORY) - set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git") - elseif(DEFINED CPM_ARGS_GITLAB_REPOSITORY) - set(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git") - elseif(DEFINED CPM_ARGS_BITBUCKET_REPOSITORY) - set(CPM_ARGS_GIT_REPOSITORY "https://bitbucket.org/${CPM_ARGS_BITBUCKET_REPOSITORY}.git") - endif() - - if(DEFINED CPM_ARGS_GIT_REPOSITORY) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY}) - if(NOT DEFINED CPM_ARGS_GIT_TAG) - set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION}) - endif() - - # If a name wasn't provided, try to infer it from the git repo - if(NOT DEFINED CPM_ARGS_NAME) - cpm_package_name_from_git_uri(${CPM_ARGS_GIT_REPOSITORY} CPM_ARGS_NAME) - endif() - endif() - - set(CPM_SKIP_FETCH FALSE) - - if(DEFINED CPM_ARGS_GIT_TAG) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG}) - # If GIT_SHALLOW is explicitly specified, honor the value. - if(DEFINED CPM_ARGS_GIT_SHALLOW) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW ${CPM_ARGS_GIT_SHALLOW}) - endif() - endif() - - if(DEFINED CPM_ARGS_URL) - # If a name or version aren't provided, try to infer them from the URL - list(GET CPM_ARGS_URL 0 firstUrl) - cpm_package_name_and_ver_from_url(${firstUrl} nameFromUrl verFromUrl) - # If we fail to obtain name and version from the first URL, we could try other URLs if any. - # However multiple URLs are expected to be quite rare, so for now we won't bother. - - # If the caller provided their own name and version, they trump the inferred ones. - if(NOT DEFINED CPM_ARGS_NAME) - set(CPM_ARGS_NAME ${nameFromUrl}) - endif() - if(NOT DEFINED CPM_ARGS_VERSION) - set(CPM_ARGS_VERSION ${verFromUrl}) - endif() - - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS URL "${CPM_ARGS_URL}") - endif() - - # Check for required arguments - - if(NOT DEFINED CPM_ARGS_NAME) - message( - FATAL_ERROR - "${CPM_INDENT} 'NAME' was not provided and couldn't be automatically inferred for package added with arguments: '${ARGN}'" - ) - endif() - - # Check if package has been added before - cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}") - if(CPM_PACKAGE_ALREADY_ADDED) - cpm_export_variables(${CPM_ARGS_NAME}) - return() - endif() - - # Check for manual overrides - if(NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "") - set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE}) - set(CPM_${CPM_ARGS_NAME}_SOURCE "") - CPMAddPackage( - NAME "${CPM_ARGS_NAME}" - SOURCE_DIR "${PACKAGE_SOURCE}" - EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}" - SYSTEM "${CPM_ARGS_SYSTEM}" - PATCHES "${CPM_ARGS_PATCHES}" - OPTIONS "${CPM_ARGS_OPTIONS}" - SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}" - DOWNLOAD_ONLY "${DOWNLOAD_ONLY}" - FORCE True - ) - cpm_export_variables(${CPM_ARGS_NAME}) - return() - endif() - - # Check for available declaration - if(NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "") - set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}}) - set(CPM_DECLARATION_${CPM_ARGS_NAME} "") - CPMAddPackage(${declaration}) - cpm_export_variables(${CPM_ARGS_NAME}) - # checking again to ensure version and option compatibility - cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}") - return() - endif() - - if(NOT CPM_ARGS_FORCE) - if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY) - cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}) - - if(CPM_PACKAGE_FOUND) - cpm_export_variables(${CPM_ARGS_NAME}) - return() - endif() - - if(CPM_LOCAL_PACKAGES_ONLY) - message( - SEND_ERROR - "${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})" - ) - endif() - endif() - endif() - - CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}") - - if(DEFINED CPM_ARGS_GIT_TAG) - set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}") - elseif(DEFINED CPM_ARGS_SOURCE_DIR) - set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}") - else() - set(PACKAGE_INFO "${CPM_ARGS_VERSION}") - endif() - - if(DEFINED FETCHCONTENT_BASE_DIR) - # respect user's FETCHCONTENT_BASE_DIR if set - set(CPM_FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR}) - else() - set(CPM_FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_deps) - endif() - - cpm_add_patches(${CPM_ARGS_PATCHES}) - - if(DEFINED CPM_ARGS_DOWNLOAD_COMMAND) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND}) - elseif(DEFINED CPM_ARGS_SOURCE_DIR) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR}) - if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR}) - # Expand `CPM_ARGS_SOURCE_DIR` relative path. This is important because EXISTS doesn't work - # for relative paths. - get_filename_component( - source_directory ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR} - ) - else() - set(source_directory ${CPM_ARGS_SOURCE_DIR}) - endif() - if(NOT EXISTS ${source_directory}) - string(TOLOWER ${CPM_ARGS_NAME} lower_case_name) - # remove timestamps so CMake will re-download the dependency - file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild") - endif() - elseif(CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE) - string(TOLOWER ${CPM_ARGS_NAME} lower_case_name) - set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS}) - list(SORT origin_parameters) - if(CPM_ARGS_CUSTOM_CACHE_KEY) - # Application set a custom unique directory name - set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${CPM_ARGS_CUSTOM_CACHE_KEY}) - elseif(CPM_USE_NAMED_CACHE_DIRECTORIES) - string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG") - set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME}) - else() - string(SHA1 origin_hash "${origin_parameters}") - set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}) - endif() - # Expand `download_directory` relative path. This is important because EXISTS doesn't work for - # relative paths. - get_filename_component(download_directory ${download_directory} ABSOLUTE) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory}) - - if(CPM_SOURCE_CACHE) - file(LOCK ${download_directory}/../cmake.lock) - endif() - - if(EXISTS ${download_directory}) - if(CPM_SOURCE_CACHE) - file(LOCK ${download_directory}/../cmake.lock RELEASE) - endif() - - cpm_store_fetch_properties( - ${CPM_ARGS_NAME} "${download_directory}" - "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build" - ) - cpm_get_fetch_properties("${CPM_ARGS_NAME}") - - if(DEFINED CPM_ARGS_GIT_TAG AND NOT (PATCH_COMMAND IN_LIST CPM_ARGS_UNPARSED_ARGUMENTS)) - # warn if cache has been changed since checkout - cpm_check_git_working_dir_is_clean(${download_directory} ${CPM_ARGS_GIT_TAG} IS_CLEAN) - if(NOT ${IS_CLEAN}) - message( - WARNING "${CPM_INDENT} Cache for ${CPM_ARGS_NAME} (${download_directory}) is dirty" - ) - endif() - endif() - - cpm_add_subdirectory( - "${CPM_ARGS_NAME}" - "${DOWNLOAD_ONLY}" - "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" - "${${CPM_ARGS_NAME}_BINARY_DIR}" - "${CPM_ARGS_EXCLUDE_FROM_ALL}" - "${CPM_ARGS_SYSTEM}" - "${CPM_ARGS_OPTIONS}" - ) - set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}") - - # As the source dir is already cached/populated, we override the call to FetchContent. - set(CPM_SKIP_FETCH TRUE) - cpm_override_fetchcontent( - "${lower_case_name}" SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" - BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" - ) - - else() - # Enable shallow clone when GIT_TAG is not a commit hash. Our guess may not be accurate, but - # it should guarantee no commit hash get mis-detected. - if(NOT DEFINED CPM_ARGS_GIT_SHALLOW) - cpm_is_git_tag_commit_hash("${CPM_ARGS_GIT_TAG}" IS_HASH) - if(NOT ${IS_HASH}) - list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW TRUE) - endif() - endif() - - # remove timestamps so CMake will re-download the dependency - file(REMOVE_RECURSE ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild) - set(PACKAGE_INFO "${PACKAGE_INFO} to ${download_directory}") - endif() - endif() - - cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(\"${ARGN}\")") - - if(CPM_PACKAGE_LOCK_ENABLED) - if((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK) - cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}") - elseif(CPM_ARGS_SOURCE_DIR) - cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory") - else() - cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}") - endif() - endif() - - cpm_message( - STATUS "${CPM_INDENT} Adding package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION} (${PACKAGE_INFO})" - ) - - if(NOT CPM_SKIP_FETCH) - # CMake 3.28 added EXCLUDE, SYSTEM (3.25), and SOURCE_SUBDIR (3.18) to FetchContent_Declare. - # Calling FetchContent_MakeAvailable will then internally forward these options to - # add_subdirectory. Up until these changes, we had to call FetchContent_Populate and - # add_subdirectory separately, which is no longer necessary and has been deprecated as of 3.30. - # A Bug in CMake prevents us to use the non-deprecated functions until 3.30.3. - set(fetchContentDeclareExtraArgs "") - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3") - if(${CPM_ARGS_EXCLUDE_FROM_ALL}) - list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL) - endif() - if(${CPM_ARGS_SYSTEM}) - list(APPEND fetchContentDeclareExtraArgs SYSTEM) - endif() - if(DEFINED CPM_ARGS_SOURCE_SUBDIR) - list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR}) - endif() - # For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory - if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY) - foreach(OPTION ${CPM_ARGS_OPTIONS}) - cpm_parse_option("${OPTION}") - set(${OPTION_KEY} "${OPTION_VALUE}") - endforeach() - endif() - endif() - cpm_declare_fetch( - "${CPM_ARGS_NAME}" ${fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS}" - ) - - cpm_fetch_package("${CPM_ARGS_NAME}" ${DOWNLOAD_ONLY} populated ${CPM_ARGS_UNPARSED_ARGUMENTS}) - if(CPM_SOURCE_CACHE AND download_directory) - file(LOCK ${download_directory}/../cmake.lock RELEASE) - endif() - if(${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.30.3") - cpm_add_subdirectory( - "${CPM_ARGS_NAME}" - "${DOWNLOAD_ONLY}" - "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" - "${${CPM_ARGS_NAME}_BINARY_DIR}" - "${CPM_ARGS_EXCLUDE_FROM_ALL}" - "${CPM_ARGS_SYSTEM}" - "${CPM_ARGS_OPTIONS}" - ) - endif() - cpm_get_fetch_properties("${CPM_ARGS_NAME}") - endif() - - set(${CPM_ARGS_NAME}_ADDED YES) - cpm_export_variables("${CPM_ARGS_NAME}") -endfunction() - -# Fetch a previously declared package -macro(CPMGetPackage Name) - if(DEFINED "CPM_DECLARATION_${Name}") - CPMAddPackage(NAME ${Name}) - else() - message(SEND_ERROR "${CPM_INDENT} Cannot retrieve package ${Name}: no declaration available") - endif() -endmacro() - -# export variables available to the caller to the parent scope expects ${CPM_ARGS_NAME} to be set -macro(cpm_export_variables name) - set(${name}_SOURCE_DIR - "${${name}_SOURCE_DIR}" - PARENT_SCOPE - ) - set(${name}_BINARY_DIR - "${${name}_BINARY_DIR}" - PARENT_SCOPE - ) - set(${name}_ADDED - "${${name}_ADDED}" - PARENT_SCOPE - ) - set(CPM_LAST_PACKAGE_NAME - "${name}" - PARENT_SCOPE - ) -endmacro() - -# declares a package, so that any call to CPMAddPackage for the package name will use these -# arguments instead. Previous declarations will not be overridden. -macro(CPMDeclarePackage Name) - if(NOT DEFINED "CPM_DECLARATION_${Name}") - set("CPM_DECLARATION_${Name}" "${ARGN}") - endif() -endmacro() - -function(cpm_add_to_package_lock Name) - if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) - cpm_prettify_package_arguments(PRETTY_ARGN false ${ARGN}) - file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name}\n${PRETTY_ARGN})\n") - endif() -endfunction() - -function(cpm_add_comment_to_package_lock Name) - if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) - cpm_prettify_package_arguments(PRETTY_ARGN true ${ARGN}) - file(APPEND ${CPM_PACKAGE_LOCK_FILE} - "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name}\n${PRETTY_ARGN}#)\n" - ) - endif() -endfunction() - -# includes the package lock file if it exists and creates a target `cpm-update-package-lock` to -# update it -macro(CPMUsePackageLock file) - if(NOT CPM_DONT_CREATE_PACKAGE_LOCK) - get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE) - if(EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH}) - include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH}) - endif() - if(NOT TARGET cpm-update-package-lock) - add_custom_target( - cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE} - ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH} - ) - endif() - set(CPM_PACKAGE_LOCK_ENABLED true) - endif() -endmacro() - -# registers a package that has been added to CPM -function(CPMRegisterPackage PACKAGE VERSION) - list(APPEND CPM_PACKAGES ${PACKAGE}) - set(CPM_PACKAGES - ${CPM_PACKAGES} - CACHE INTERNAL "" - ) - set("CPM_PACKAGE_${PACKAGE}_VERSION" - ${VERSION} - CACHE INTERNAL "" - ) -endfunction() - -# retrieve the current version of the package to ${OUTPUT} -function(CPMGetPackageVersion PACKAGE OUTPUT) - set(${OUTPUT} - "${CPM_PACKAGE_${PACKAGE}_VERSION}" - PARENT_SCOPE - ) -endfunction() - -# declares a package in FetchContent_Declare -function(cpm_declare_fetch PACKAGE) - if(${CPM_DRY_RUN}) - cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)") - return() - endif() - - FetchContent_Declare(${PACKAGE} ${ARGN}) -endfunction() - -# returns properties for a package previously defined by cpm_declare_fetch -function(cpm_get_fetch_properties PACKAGE) - if(${CPM_DRY_RUN}) - return() - endif() - - set(${PACKAGE}_SOURCE_DIR - "${CPM_PACKAGE_${PACKAGE}_SOURCE_DIR}" - PARENT_SCOPE - ) - set(${PACKAGE}_BINARY_DIR - "${CPM_PACKAGE_${PACKAGE}_BINARY_DIR}" - PARENT_SCOPE - ) -endfunction() - -function(cpm_store_fetch_properties PACKAGE source_dir binary_dir) - if(${CPM_DRY_RUN}) - return() - endif() - - set(CPM_PACKAGE_${PACKAGE}_SOURCE_DIR - "${source_dir}" - CACHE INTERNAL "" - ) - set(CPM_PACKAGE_${PACKAGE}_BINARY_DIR - "${binary_dir}" - CACHE INTERNAL "" - ) -endfunction() - -# adds a package as a subdirectory if viable, according to provided options -function( - cpm_add_subdirectory - PACKAGE - DOWNLOAD_ONLY - SOURCE_DIR - BINARY_DIR - EXCLUDE - SYSTEM - OPTIONS -) - - if(NOT DOWNLOAD_ONLY AND EXISTS ${SOURCE_DIR}/CMakeLists.txt) - set(addSubdirectoryExtraArgs "") - if(EXCLUDE) - list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL) - endif() - if("${SYSTEM}" AND "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.25") - # https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html#prop_dir:SYSTEM - list(APPEND addSubdirectoryExtraArgs SYSTEM) - endif() - if(OPTIONS) - foreach(OPTION ${OPTIONS}) - cpm_parse_option("${OPTION}") - set(${OPTION_KEY} "${OPTION_VALUE}") - endforeach() - endif() - set(CPM_OLD_INDENT "${CPM_INDENT}") - set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:") - add_subdirectory(${SOURCE_DIR} ${BINARY_DIR} ${addSubdirectoryExtraArgs}) - set(CPM_INDENT "${CPM_OLD_INDENT}") - endif() -endfunction() - -# downloads a previously declared package via FetchContent and exports the variables -# `${PACKAGE}_SOURCE_DIR` and `${PACKAGE}_BINARY_DIR` to the parent scope -function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated) - set(${populated} - FALSE - PARENT_SCOPE - ) - if(${CPM_DRY_RUN}) - cpm_message(STATUS "${CPM_INDENT} Package ${PACKAGE} not fetched (dry run)") - return() - endif() - - FetchContent_GetProperties(${PACKAGE}) - - string(TOLOWER "${PACKAGE}" lower_case_name) - - if(NOT ${lower_case_name}_POPULATED) - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3") - if(DOWNLOAD_ONLY) - # MakeAvailable will call add_subdirectory internally which is not what we want when - # DOWNLOAD_ONLY is set. Populate will only download the dependency without adding it to the - # build - FetchContent_Populate( - ${PACKAGE} - SOURCE_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-src" - BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build" - SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild" - ${ARGN} - ) - else() - FetchContent_MakeAvailable(${PACKAGE}) - endif() - else() - FetchContent_Populate(${PACKAGE}) - endif() - set(${populated} - TRUE - PARENT_SCOPE - ) - endif() - - cpm_store_fetch_properties( - ${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR} - ) - - set(${PACKAGE}_SOURCE_DIR - ${${lower_case_name}_SOURCE_DIR} - PARENT_SCOPE - ) - set(${PACKAGE}_BINARY_DIR - ${${lower_case_name}_BINARY_DIR} - PARENT_SCOPE - ) -endfunction() - -# splits a package option -function(cpm_parse_option OPTION) - string(REGEX MATCH "^[^ ]+" OPTION_KEY "${OPTION}") - string(LENGTH "${OPTION}" OPTION_LENGTH) - string(LENGTH "${OPTION_KEY}" OPTION_KEY_LENGTH) - if(OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH) - # no value for key provided, assume user wants to set option to "ON" - set(OPTION_VALUE "ON") - else() - math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1") - string(SUBSTRING "${OPTION}" "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE) - endif() - set(OPTION_KEY - "${OPTION_KEY}" - PARENT_SCOPE - ) - set(OPTION_VALUE - "${OPTION_VALUE}" - PARENT_SCOPE - ) -endfunction() - -# guesses the package version from a git tag -function(cpm_get_version_from_git_tag GIT_TAG RESULT) - string(LENGTH ${GIT_TAG} length) - if(length EQUAL 40) - # GIT_TAG is probably a git hash - set(${RESULT} - 0 - PARENT_SCOPE - ) - else() - string(REGEX MATCH "v?([0123456789.]*).*" _ ${GIT_TAG}) - set(${RESULT} - ${CMAKE_MATCH_1} - PARENT_SCOPE - ) - endif() -endfunction() - -# guesses if the git tag is a commit hash or an actual tag or a branch name. -function(cpm_is_git_tag_commit_hash GIT_TAG RESULT) - string(LENGTH "${GIT_TAG}" length) - # full hash has 40 characters, and short hash has at least 7 characters. - if(length LESS 7 OR length GREATER 40) - set(${RESULT} - 0 - PARENT_SCOPE - ) - else() - if(${GIT_TAG} MATCHES "^[a-fA-F0-9]+$") - set(${RESULT} - 1 - PARENT_SCOPE - ) - else() - set(${RESULT} - 0 - PARENT_SCOPE - ) - endif() - endif() -endfunction() - -function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT) - set(oneValueArgs - NAME - FORCE - VERSION - GIT_TAG - DOWNLOAD_ONLY - GITHUB_REPOSITORY - GITLAB_REPOSITORY - BITBUCKET_REPOSITORY - GIT_REPOSITORY - SOURCE_DIR - FIND_PACKAGE_ARGUMENTS - NO_CACHE - SYSTEM - GIT_SHALLOW - EXCLUDE_FROM_ALL - SOURCE_SUBDIR - ) - set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND) - cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - foreach(oneArgName ${oneValueArgs}) - if(DEFINED CPM_ARGS_${oneArgName}) - if(${IS_IN_COMMENT}) - string(APPEND PRETTY_OUT_VAR "#") - endif() - if(${oneArgName} STREQUAL "SOURCE_DIR") - string(REPLACE ${CMAKE_SOURCE_DIR} "\${CMAKE_SOURCE_DIR}" CPM_ARGS_${oneArgName} - ${CPM_ARGS_${oneArgName}} - ) - endif() - string(APPEND PRETTY_OUT_VAR " ${oneArgName} ${CPM_ARGS_${oneArgName}}\n") - endif() - endforeach() - foreach(multiArgName ${multiValueArgs}) - if(DEFINED CPM_ARGS_${multiArgName}) - if(${IS_IN_COMMENT}) - string(APPEND PRETTY_OUT_VAR "#") - endif() - string(APPEND PRETTY_OUT_VAR " ${multiArgName}\n") - foreach(singleOption ${CPM_ARGS_${multiArgName}}) - if(${IS_IN_COMMENT}) - string(APPEND PRETTY_OUT_VAR "#") - endif() - string(APPEND PRETTY_OUT_VAR " \"${singleOption}\"\n") - endforeach() - endif() - endforeach() - - if(NOT "${CPM_ARGS_UNPARSED_ARGUMENTS}" STREQUAL "") - if(${IS_IN_COMMENT}) - string(APPEND PRETTY_OUT_VAR "#") - endif() - string(APPEND PRETTY_OUT_VAR " ") - foreach(CPM_ARGS_UNPARSED_ARGUMENT ${CPM_ARGS_UNPARSED_ARGUMENTS}) - string(APPEND PRETTY_OUT_VAR " ${CPM_ARGS_UNPARSED_ARGUMENT}") - endforeach() - string(APPEND PRETTY_OUT_VAR "\n") - endif() - - set(${OUT_VAR} - ${PRETTY_OUT_VAR} - PARENT_SCOPE - ) - -endfunction() diff --git a/alyson/cmake/utils.cmake b/alyson/cmake/utils.cmake deleted file mode 100644 index 60b3175..0000000 --- a/alyson/cmake/utils.cmake +++ /dev/null @@ -1,33 +0,0 @@ - -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() - diff --git a/alyson/includes/alargs.h b/alyson/includes/alargs.h deleted file mode 100644 index 97f08c4..0000000 --- a/alyson/includes/alargs.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ALARGS_H_INCLUDED -#define ALARGS_H_INCLUDED - - - -#ifdef __cplusplus -extern "C" { -#endif - - typedef struct { - int argc; - char** argv; - } alyson_args_t, *ALArgs; - - ALArgs al_args_create(int argc, char** argv); - void al_args_destroy(ALArgs args); - -#ifdef __cplusplus -} -#endif - -#endif // ALARGS_H_INCLUDED diff --git a/alyson/includes/altilemap.h b/alyson/includes/altilemap.h deleted file mode 100644 index 1e0dd73..0000000 --- a/alyson/includes/altilemap.h +++ /dev/null @@ -1,29 +0,0 @@ - - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "types.h" - - typedef struct { - Texture2D texture; - uveci2 texture_dimentions; - uveci2 rows_and_collumns; - - uveci2 tile_dimentions; - } al_tilemap_t, *ALTilemap; - - typedef struct { - ALTilemap map; - umat2 source; - - } al_tile_t, *ALTile; - - - -#ifdef __cplusplus -} -#endif diff --git a/alyson/includes/alyson.h b/alyson/includes/alyson.h deleted file mode 100644 index f759531..0000000 --- a/alyson/includes/alyson.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once -#ifndef ALYSON_HPP -#define ALYSON_HPP - -#ifndef ASSETS_PATH -#define ASSETS_PATH "./assets/" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "types.h" - -#define ALYSIS_ENGINE_WINDOW_TITLE "Alyson Engine" - -#include "alargs.h" - -#include "resources/alpath.h" - -#include "resources/alresource.h" - - #if defined(RAYLIB_BACKEND) - #include - #include - - #include - #endif - - - /* TODO : implement - typedef struct { - ALResource* resources; - usx count; - usx capacity; - } alyson_resource_manager_t, *ALResourceManager; - - ALResourceManager al_resource_manager_create(); - void al_resource_manager_destroy(ALResourceManager manager); - - void al_resource_manager_add(ALResourceManager manager, ALResource resource); - void al_resource_manager_remove(ALResourceManager manager, usx id); - void al_resource_manager_clear(ALResourceManager manager); - - - - typedef struct { - ALResourceManager resources_manager; - usx id; - char* name; - usx width; - usx height; - } alyson_window_t, *ALWindow; - - ALWindow al_window_create(char* name, int width, int height); - void al_window_destroy(ALWindow window); - - -#include - - typedef struct { - ALWindow wnd; - ecs_world_t* engine; - ecs_world_t* ui; - } alyson_engine_t, *ALEngine; - - ALEngine al_engine_create(ALArgs args, ALWindow wnd = NULL); - void al_engine_destroy(ALEngine engine); - - void al_engine_run(ALEngine engine); - void al_engine_stop(ALEngine engine); - bool al_engine_is_running(ALEngine engine); - bool al_engine_is_stopped(ALEngine engine); - - void al_engine_update(ALEngine engine); - void al_engine_draw(ALEngine engine); - void al_engine_draw_ui(ALEngine engine); - - void al_engine_set_window(ALEngine engine, ALWindow wnd); - ALWindow al_engine_get_window(ALEngine engine); - -*/ - -#ifdef __cplusplus -} -#endif - -#endif // ALYSON_HPP diff --git a/alyson/includes/animation/sprite.h b/alyson/includes/animation/sprite.h deleted file mode 100644 index 2573a5e..0000000 --- a/alyson/includes/animation/sprite.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef ANIMATION_SPRITE_H -#define ANIMATION_SPRITE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - Texture2D texture; - Vector2 dimentions; - - Rectangle sourceRect; - Vector2 size; - float rotation; - float scale; - - int frameCount; - int currentFrame; - - float speed; - float time; -} sprite_animation_t, *SpriteAnimation; - -SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed); - -void UpdateSpriteAnimation(SpriteAnimation spriteAnimation, float dt); - -void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position); - -void DestroySpriteAnimation(SpriteAnimation spriteAnimation); - -#ifdef __cplusplus -} -#endif - -#endif // ANIMATION_SPRITE_H diff --git a/alyson/includes/resources/alpath.h b/alyson/includes/resources/alpath.h deleted file mode 100644 index f070819..0000000 --- a/alyson/includes/resources/alpath.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef ALPATH_H_INCLUDED -#define ALPATH_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif -#include "../types.h" - -typedef struct { - char type[4 + 1]; - char group[26 + 1]; - char* name; - char* path; -} alyson_path_t, *ALPath; - -/* - * @function: demangle_path - * @description: Demangles a path - * @param path: path to resource - * @return: ALPath - */ -ALPath al_demangle_path(const char* path); -char* al_mangle_path(const ALPath path); -ALPath al_create_path( - const char* type, - const char* path, - const char* name, - const char* group -); -void al_destroy_path(ALPath path); - -#ifdef __cplusplus -} -#endif - -#endif // ALPATH_H_INCLUDED diff --git a/alyson/includes/resources/alresource.h b/alyson/includes/resources/alresource.h deleted file mode 100644 index 056435e..0000000 --- a/alyson/includes/resources/alresource.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ALRESOURCE_H_INCLUDED -#define ALRESOURCE_H_INCLUDED - - -#ifdef __cplusplus -extern "C" { -#endif - -#include "../types.h" -#include "alpath.h" - -typedef struct { - usx id; - alyson_path_t path; -} alyson_resource_t, *ALResource; - -ALResource al_resource_create(ALPath path); -ALResource al_resource_create_from_file(char* name, char* path); -void al_resource_destroy(ALResource resource); - - -#ifdef __cplusplus -} -#endif - -#endif // ALRESOURCE_H_INCLUDED diff --git a/alyson/includes/resources/alresource_manager.h b/alyson/includes/resources/alresource_manager.h deleted file mode 100644 index e69de29..0000000 diff --git a/alyson/includes/rlyson.h b/alyson/includes/rlyson.h deleted file mode 100644 index 8056210..0000000 --- a/alyson/includes/rlyson.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef RLYSON_HPP -#define RLYSON_HPP - -#ifdef __cplusplus -extern "C" { -#endif - - -#include - - -/* - the following functions are not part of the raylib API, - but are used by alyson and can be used by other projects using alyson -*/ - -typedef enum { - TEXT_ORIENTATION_LEFT, - TEXT_ORIENTATION_RIGHT, - TEXT_ORIENTATION_CENTER -} text_orientation_t; - -void DrawTextFull( - Font font, - const char* text, - Vector2 origin, - text_orientation_t orientation, - float rotation, - float fontSize, - float spacing, - float lineSpacing, - Color tint -); - -#ifndef RLAYSON_NO_ANIMATION -#include -// other animation types -#endif - - - -#ifdef __cplusplus -} -#endif - - -#endif // RLYSON_HPP \ No newline at end of file diff --git a/alyson/includes/types.h b/alyson/includes/types.h deleted file mode 100644 index b15893f..0000000 --- a/alyson/includes/types.h +++ /dev/null @@ -1,100 +0,0 @@ -// -// Created by n0ffie on 07/02/25. -// - -#ifndef TYPES_H -#define TYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#include -#include -#include - /* - * Basic types - * - * u8 - unsigned 8-bit integer - * u16 - unsigned 16-bit integer - * u32 - unsigned 32-bit integer - * u64 - unsigned 64-bit integer - * - * i8 - signed 8-bit integer - * i16 - signed 16-bit integer - * i32 - signed 32-bit integer - * i64 - signed 64-bit integer - * - * f32 - 32-bit floating point number - * f64 - 64-bit floating point number - * - * usx - unsigned size_t - * isx - signed size_t - */ - typedef uint64_t u64; - typedef uint32_t u32; - typedef uint16_t u16; - typedef uint8_t u8; - - typedef int64_t i64; - typedef int32_t i32; - typedef int16_t i16; - typedef int8_t i8; - - typedef float f32; - typedef double f64; - - typedef size_t usx; - typedef ptrdiff_t isx; - - typedef bool boolean; - - /* - * Vectors and Matrices - */ - #define ALYSON_DEFINE_VECTOR2_TYPE(type, ...) typedef struct { type x; type y; } __VA_ARGS__ - #define ALYSON_DEFINE_VECTOR3_TYPE(type, ...) typedef struct { type x; type y; type z; } __VA_ARGS__ - #define ALYSON_DEFINE_VECTOR4_TYPE(type, ...) typedef struct { type x; type y; type z; type w; } __VA_ARGS__ - - ALYSON_DEFINE_VECTOR2_TYPE(f32, vec2, vec2f); - ALYSON_DEFINE_VECTOR3_TYPE(f32, vec3, vec3f); - ALYSON_DEFINE_VECTOR4_TYPE(f32, vec4, vec4f); - - ALYSON_DEFINE_VECTOR2_TYPE(f64, vecd2); - ALYSON_DEFINE_VECTOR3_TYPE(f64, vecd3); - ALYSON_DEFINE_VECTOR4_TYPE(f64, vecd4); - - ALYSON_DEFINE_VECTOR2_TYPE(i32, veci2); - ALYSON_DEFINE_VECTOR3_TYPE(i32, veci3); - ALYSON_DEFINE_VECTOR4_TYPE(i32, veci4); - - ALYSON_DEFINE_VECTOR2_TYPE(u32, uveci2); - ALYSON_DEFINE_VECTOR3_TYPE(u32, uveci3); - ALYSON_DEFINE_VECTOR4_TYPE(u32, uveci4); - - #define ALYSON_DEFINE_MATRIX_2x2_TYPE(type, ...) typedef struct { type m00; type m01; type m10; type m11; } __VA_ARGS__ - #define ALYSON_DEFINE_MATRIX_3x3_TYPE(type, ...) typedef struct { type m00; type m01; type m02; type m10; type m11; type m12; type m20; type m21; type m22; } __VA_ARGS__ - #define ALYSON_DEFINE_MATRIX_4x4_TYPE(type, ...) typedef struct { type m00; type m01; type m02; type m03; type m10; type m11; type m12; type m13; type m20; type m21; type m22; type m23; type m30; type m31; type m32; type m33; } __VA_ARGS__ - - ALYSON_DEFINE_MATRIX_2x2_TYPE(f32, mat2, fmat2); - ALYSON_DEFINE_MATRIX_3x3_TYPE(f32, mat3, fmat3); - ALYSON_DEFINE_MATRIX_4x4_TYPE(f32, mat4, fmat4); - - ALYSON_DEFINE_MATRIX_2x2_TYPE(f64, dmat2); - ALYSON_DEFINE_MATRIX_3x3_TYPE(f64, dmat3); - ALYSON_DEFINE_MATRIX_4x4_TYPE(f64, dmat4); - - ALYSON_DEFINE_MATRIX_2x2_TYPE(i32, imat2); - ALYSON_DEFINE_MATRIX_3x3_TYPE(i32, imat3); - ALYSON_DEFINE_MATRIX_4x4_TYPE(i32, imat4); - - ALYSON_DEFINE_MATRIX_2x2_TYPE(u32, umat2); - ALYSON_DEFINE_MATRIX_3x3_TYPE(u32, umat3); - ALYSON_DEFINE_MATRIX_4x4_TYPE(u32, umat4); - -#ifdef __cplusplus -} -#endif - -#endif //TYPES_H diff --git a/alyson/src/alargs.c b/alyson/src/alargs.c deleted file mode 100644 index c5e9ee3..0000000 --- a/alyson/src/alargs.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include - -/* - * ALArgs - */ -ALArgs al_args_create(int argc, char** argv) -{ - ALArgs args = malloc(sizeof(alyson_args_t)); - args->argc = argc; - args->argv = argv; - - return args; -} - -void al_args_destroy(ALArgs args) -{ - free(args); -} diff --git a/alyson/src/alyson.c b/alyson/src/alyson.c deleted file mode 100644 index 9658144..0000000 --- a/alyson/src/alyson.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include -#include -#include -#include - - diff --git a/alyson/src/animation/sprite.c b/alyson/src/animation/sprite.c deleted file mode 100644 index 6f305e9..0000000 --- a/alyson/src/animation/sprite.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include - -#include "raylib.h" -#include "raymath.h" - -#ifdef _DEBUG -#include -#endif - - -SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed) -{ - SpriteAnimation spriteAnimation = malloc(sizeof(sprite_animation_t)); - spriteAnimation->texture = texture; - spriteAnimation->dimentions = sprite_texture_dimentions; - spriteAnimation->sourceRect = (Rectangle){0, 0, sprite_size.x, sprite_size.y}; - spriteAnimation->size = sprite_size; - spriteAnimation->rotation = rotation; - spriteAnimation->scale = scale; - spriteAnimation->frameCount = frameCount; - spriteAnimation->currentFrame = 0; - spriteAnimation->time = 0.f; - spriteAnimation->speed = speed; - - return spriteAnimation; -} - -void UpdateSpriteAnimation(SpriteAnimation self, float dt) { - self->time += dt; - if (self->time >= self->speed) { - self->time = 0.f; - self->currentFrame++; - } - - if(self->currentFrame >= self->frameCount) { - self->currentFrame = 0; - } - - self->sourceRect.x = (self->currentFrame * (int)self->size.x) % (int)self->dimentions.x; - self->sourceRect.y = (self->currentFrame * (int)self->size.y) % (int)self->dimentions.y; -} - -void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) { - position = Vector2Scale(position, .5f); - float yscale = (spriteAnimation->size.y * spriteAnimation->scale) / 2; - float xscale = (spriteAnimation->size.x * spriteAnimation->scale) / 2; - - Rectangle destination = (Rectangle) { - xscale - position.x, - yscale - position.y, - xscale + position.x, - yscale + position.y - }; - - - DrawTexturePro( - spriteAnimation->texture, - spriteAnimation->sourceRect, - destination, - (Vector2){0,0}, - spriteAnimation->rotation, - WHITE - ); -#ifdef _DEBUG - DrawCircleV(position, 5, DARKGREEN); - - DrawRectangleLinesEx(destination, 2, BLACK); -#endif -} - -void DestroySpriteAnimation(SpriteAnimation spriteAnimation) -{ - free(spriteAnimation); -} - diff --git a/alyson/src/resources/alpath.c b/alyson/src/resources/alpath.c deleted file mode 100644 index bf4259b..0000000 --- a/alyson/src/resources/alpath.c +++ /dev/null @@ -1,210 +0,0 @@ -#include - -#include -#include -#include - - -/* - * mangled path format: - * ://(/): - * - * e.g. res://test:/tests/test.png - * type: "res" - * group: "" - * name: "test" - * path: "/tests/test.png" - * - * - * demangled path format: - * .// - * - * e.g. - * type_path: res -> ./assets/ - * demangled_path: tests/test.png - * -> ./assets/tests/test.png - * - * type max length: 4 - * - * smallest possible path: ://:a (5 chars) - * - * groups max length: 26 - * groups: - * e.g. res://image/test:/tests/test.png - * type: "res" - * group: "image" - * name: "test" - * path: "/tests/test.png" - * -> ./assets/tests/test.png - */ - - -// Path - -ALPath al_demangle_path(const char* path) -{ - - const ALPath res = malloc(sizeof(alyson_path_t)); - res->type[0] = '\0'; - res->group[0] = '\0'; - res->name = NULL; - res->path = NULL; - - const usx len = strlen(path); - usx back_ptr = 0; - - if (len < 5) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; too short\n", path); - al_destroy_path(res); - return NULL; - } - - // type - for (usx i = 0; i < sizeof(res->type); i++) - { - if (path[i] == ':') - { - res->type[i] = '\0'; - back_ptr = i + 1; - break; - } - res->type[i] = path[i]; - } - if (back_ptr == 0) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not found\n", path); - al_destroy_path(res); - return NULL; - } - - if (path[back_ptr] != '/' || path[back_ptr+1] != '/') { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; type not followed by '://'\n", path); - al_destroy_path(res); - return NULL; - } - back_ptr += 2; - - // group + name - for (usx i = back_ptr; i < len; i++) - { - if (path[i] == '/') - { - if (res->group[0] != '\0') - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; group already set\n", path); - al_destroy_path(res); - return NULL; - } - if (back_ptr == i) break; - strncpy(res->group, (char*)path + back_ptr, i - back_ptr); - res->group[i-back_ptr] = '\0'; - back_ptr = i + 1; - } - - if (path[i] == ':') - { - res->name = malloc(sizeof(char) * (i - back_ptr + 1)); - strncpy(res->name, (char*)path + back_ptr, i - back_ptr); - res->name[i - back_ptr] = '\0'; - back_ptr = i + 1; - break; - } - } - - // path - if (back_ptr == len) - { - fprintf(stderr, "[ALResource] Invalid path: \"%s\"; path not found\n", path); - al_destroy_path(res); - return NULL; - } - res->path = malloc(sizeof(char) * (len - back_ptr + 1)); - strncpy(res->path, (char*)path + back_ptr, len - back_ptr); - res->path[len - back_ptr] = '\0'; - - return res; -} - -char* al_mangle_path(const ALPath path) -{ - char* str = malloc(sizeof(char) * ( - strlen(path->type) + - strlen(path->group) + - strlen(path->name) + - strlen(path->path) + - 5 )); - if (path->group[0] != '\0') - { - sprintf(str, "%s://%s/%s:%s", path->type, path->group, path->name, path->path); - } - else - { - sprintf(str, "%s://%s:%s", path->type, path->name, path->path); - } - return str; -} - -ALPath al_create_path(const char* type, const char* path, const char* name, const char* group) -{ - const ALPath res = malloc(sizeof(alyson_path_t)); - res->type[0] = '\0'; - res->name = NULL; - res->path = NULL; - - if (type != NULL) - { - if (strlen(type) > 4) - { - fprintf(stderr, "[ALResource] Type name too long: %s\n", type); - return NULL; - } - strncpy(res->type, type, strlen(type)); - res->type[4] = '\0'; - } - - if (path != NULL) - { - usx len = strlen(path); - res->path = malloc(sizeof(char) * (len + 1)); - strncpy(res->path, path, len); - res->path[len] = '\0'; - } - - if (name != NULL) - { - res->name = malloc(sizeof(char) * (strlen(name) + 1)); - strncpy(res->name, name, strlen(name)); - res->name[strlen(name)] = '\0'; - } - - if (group != NULL) - { - if (strlen(group) > 26) - { - fprintf(stderr, "[ALResource] Group name too long: %s\n", group); - al_destroy_path(res); - return NULL; - } - strncpy(res->group, group, strlen(group)); - res->group[strlen(group)] = '\0'; - } - - return res; -} - -void al_destroy_path(ALPath path) -{ - if (path->name != NULL) - { - free(path->name); - path->name = NULL; - } - if (path->path != NULL) - { - free(path->path); - path->path = NULL; - } - free(path); - path = NULL; -} diff --git a/alyson/src/resources/alresource.c b/alyson/src/resources/alresource.c deleted file mode 100644 index 21e305d..0000000 --- a/alyson/src/resources/alresource.c +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include -#include - -ALResource al_resource_create(ALPath path) -{ - ALResource resource = malloc(sizeof(alyson_resource_t)); - resource->id = 0; - memcpy(&resource->path, path, sizeof(alyson_path_t)); - - return resource; -} - -ALResource al_resource_create_from_file(char* name, char* path) -{ - ALResource resource = malloc(sizeof(alyson_resource_t)); - resource->id = 0; - - usx len = strlen(path); - resource->path.path = malloc(sizeof(char) * (len + 1)); - memcpy(resource->path.path, path, sizeof(char) * len); - resource->path.path[len] = '\0'; - - memcpy(&resource->path.type, "res", 4); - resource->path.type[4] = '\0'; - - len = strlen(name); - resource->path.name = malloc(sizeof(char) * len + 1); - memcpy(resource->path.name, name, sizeof(char) * len); - resource->path.name[len] = '\0'; - - memcpy(&resource->path.group, "runtime", 7); - resource->path.group[7] = '\0'; - - return resource; -} - -void al_destroy_resource(ALResource resource) -{ - if (resource->path.name != NULL) - { - free(resource->path.name); - resource->path.name = NULL; - } - if (resource->path.path != NULL) - { - free(resource->path.path); - resource->path.path = NULL; - } - - free(resource); - resource = NULL; -} diff --git a/alyson/src/resources/alresource_manager.c b/alyson/src/resources/alresource_manager.c deleted file mode 100644 index e69de29..0000000 diff --git a/alyson/src/rlyson.c b/alyson/src/rlyson.c deleted file mode 100644 index f72647e..0000000 --- a/alyson/src/rlyson.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#include "raylib.h" - -#include "raymath.h" - -void DrawTextFull( - const Font font, - const char* text, - Vector2 origin, - const text_orientation_t orientation, - const float rotation, - const float fontSize, - const float spacing, - const float lineSpacing, - const Color tint - ) -{ - const Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing); - - const Vector2 pos = origin; - origin = (Vector2){0,0}; - - switch (orientation) { - case TEXT_ORIENTATION_LEFT: - origin.x += textSize.x; - break; - case TEXT_ORIENTATION_RIGHT: - break; - case TEXT_ORIENTATION_CENTER: - origin.x += (textSize.x / 2); - break; - default: - break; - } - - origin.y += textSize.y / 2; - SetTextLineSpacing((int)lineSpacing); - - DrawTextPro(font, text, pos, origin, rotation, fontSize, spacing, tint); -} diff --git a/alyson/src/tilemap.c b/alyson/src/tilemap.c deleted file mode 100644 index e69de29..0000000 diff --git a/alyson/tests/ALPath.cpp b/alyson/tests/ALPath.cpp deleted file mode 100644 index 9be2ca4..0000000 --- a/alyson/tests/ALPath.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Created by n0ffie on 10/02/2025. -// - - -#include -#include -#include -#include - -// gtests -#include - - -bool test_path(const char* path) -{ - if (path == NULL) - return false; - - ALPath al_path = al_demangle_path(path); - if (al_path == NULL) - return false; - - if (al_path->path == NULL) - return false; - - printf("Path: %s\n", al_path->path); - - char* string = al_mangle_path(al_path); - if (strcmp(string, path) != 0) { - printf("%s : %s\n", path, string); - return false; - } - printf("\t%s\n", string); - free(string); - - al_destroy_path(al_path); - return true; -} - -void pathEQ_test(const char* string) { - ALPath al_path = al_demangle_path(string); - char* s2 = al_mangle_path(al_path); - EXPECT_STREQ(string, s2); - free(s2); - al_destroy_path(al_path); -} - - -TEST(PathEqual, normal) { - pathEQ_test("res://normal:path/this.is"); -} - -TEST(PathEqual, group_long_type) { - pathEQ_test("gays://i/love:gays/iam.one/kind.of"); -} - -TEST(PathEqual, group_type) { - pathEQ_test("g/es://this/is:shit"); -} - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} \ No newline at end of file diff --git a/assets/Raylib_logo.png b/assets/Raylib_logo.png deleted file mode 100644 index 6654562..0000000 Binary files a/assets/Raylib_logo.png and /dev/null differ diff --git a/assets/gery.png b/assets/gery.png deleted file mode 100644 index 8cd747d..0000000 Binary files a/assets/gery.png and /dev/null differ diff --git a/assets/gery_hand.png b/assets/gery_hand.png deleted file mode 100644 index 7b5cafd..0000000 Binary files a/assets/gery_hand.png and /dev/null differ diff --git a/assets/karl-heinz_head.png b/assets/karl-heinz_head.png deleted file mode 100644 index 5e1a26c..0000000 Binary files a/assets/karl-heinz_head.png and /dev/null differ diff --git a/include/colysis.h b/include/colysis.h deleted file mode 100644 index 1843995..0000000 --- a/include/colysis.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef COLYSIS_H -#define COLYSIS_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/src/Enemy/Enemy.cpp b/src/Enemy/Enemy.cpp new file mode 100644 index 0000000..65fb124 --- /dev/null +++ b/src/Enemy/Enemy.cpp @@ -0,0 +1,21 @@ +#include "Enemy.hpp" + +Enemy::Enemy(sf::Vector2f position) : rectangle(sf::Vector2f{100, 100}) +{ + rectangle.move(position); + rectangle.setFillColor(sf::Color::Red); +} + +void Enemy::look_at(sf::Vector2f target) +{ + float dx = target.x - rectangle.getPosition().x; + float dy = target.y - rectangle.getPosition().y; + + float angle = atan2(dy, dx); + rectangle.setRotation(sf::degrees(angle)); +} + +void Enemy::draw(sf::RenderTarget& target, const sf::RenderStates states) const +{ + target.draw(rectangle, states); +} \ No newline at end of file diff --git a/src/Enemy/Enemy.hpp b/src/Enemy/Enemy.hpp new file mode 100644 index 0000000..47a8e6d --- /dev/null +++ b/src/Enemy/Enemy.hpp @@ -0,0 +1,13 @@ +#pragma once +#include + +class Enemy : public sf::Drawable +{ + sf::RectangleShape rectangle; +public: + explicit Enemy(sf::Vector2f position); + + void look_at(sf::Vector2f target); + + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; +}; \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp new file mode 100644 index 0000000..aeb7e9c --- /dev/null +++ b/src/Game.cpp @@ -0,0 +1,46 @@ +#include "Game.hpp" + +Game::Game(sf::RenderWindow& window) : window(window) +{ + enemies.emplace_back(sf::Vector2f{100, 100}); + enemies.emplace_back(sf::Vector2f{200, 200}); +} + +#include +void Game::run() +{ + std::cout << "Loading map... Version: " MAP_VERSION_STRING << std::endl; + auto start = std::chrono::system_clock::now(); + auto err = map.load(ASSETS_PATH "/test.cymf"); + auto end = std::chrono::system_clock::now(); + auto milliseconds = std::chrono::duration_cast(end - start); + std::cout << "Loading took: " << milliseconds << std::endl; + if (err.code != 0) + { + std::cout << err.message << std::endl; + return; + } + map.debug(); + while (window.isOpen()) + { + while (const auto event = window.pollEvent()) + { + if (event->is()) + { + window.close(); + } + } + + + // Render game + window.clear({0x20, 0x20, 0x20,0xff}); + + for (auto& enemy : enemies) + { + window.draw(enemy); + } + window.draw(map); + + window.display(); + } +} diff --git a/src/Game.hpp b/src/Game.hpp new file mode 100644 index 0000000..1ae6d20 --- /dev/null +++ b/src/Game.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "Enemy/Enemy.hpp" +#include "Map/Map.hpp" + +#include +class Game +{ + std::vector enemies; + Map map; +public: + explicit Game(sf::RenderWindow& window); + + void run(); +private: + sf::RenderWindow& window; +}; + diff --git a/src/Map/Map.cpp b/src/Map/Map.cpp new file mode 100644 index 0000000..af8470b --- /dev/null +++ b/src/Map/Map.cpp @@ -0,0 +1,162 @@ +#include "Map.hpp" + +#include + +Map::Map() {} + +bool operator&(uint8_t lhs, MapFlags rhs) +{ + return lhs & static_cast(rhs); +} + +bool operator==(int lhs, TileType rhs) +{ + return lhs == static_cast(rhs); +} + +auto operator<=>(int lhs, TileType rhs) +{ + return lhs <=> static_cast(rhs); +} + +#include + +MapError Map::load(const std::filesystem::path& path) +{ + // opening the file and checking the magic number + std::ifstream file(path, std::ios::binary | std::ios::in); + char magic[4]; + file.read(magic, 4); + + if (std::memcmp(magic, "CYMF", 4) != 0) { + return {"Map: [Loading] Invalid magic number", 1}; + } + + // reading the version + uint8_t version[3]; + file.read(reinterpret_cast(version), 3); + if (version[0] != MAP_VERSION_MAJOR || version[1] > MAP_VERSION_MINOR) + { + return {"Map: [Loading] Invalid version; Current: " MAP_VERSION_STRING, 1}; + } + + // reading the flags + uint8_t flags; + file.read(reinterpret_cast(&flags), 1); + + // flag CustomTilemap -> load the tilemap + if (flags & MapFlags::CustomTilemap) + { + uint32_t filepath_buffer_size; + file.read(reinterpret_cast(&filepath_buffer_size), 4); + + char* filepath_buffer = new char[filepath_buffer_size]; + file.read(filepath_buffer, filepath_buffer_size); + + tileAtlas.load(std::filesystem::path(filepath_buffer)); + delete[] filepath_buffer; + } + + + // load the map info + uint32_t map_info[3]; + file.read(reinterpret_cast(map_info), 12); + map_size = sf::Vector3(static_cast(map_info[0])*map_info[1], map_info[0], map_info[1]); + + // load the tiles + tiles = new int[map_info[0] * map_info[1] + map_info[2] * (sizeof(MapSpecial)/4)]; + for (int i = 0; i < map_info[0] * map_info[1] + map_info[2] * (sizeof(MapSpecial)/4); i++) + { + // read the special if needed + file.read(reinterpret_cast(&tiles[i]), 4); + if (tiles[i] == TileType::Special) + { + MapSpecial special{}; + file.read(reinterpret_cast(&special), sizeof(MapSpecial)); + // get position + uint32_t tile_x = i % map_info[0]; + uint32_t tile_y = i / map_info[0]; + specials.emplace_back(std::pair({tile_x, tile_y}, special)); + } + } + + // load the player spawn + uint32_t t_player_spawn[2]; + file.read(reinterpret_cast(t_player_spawn), 8); + player_spawn = sf::Vector2u{t_player_spawn[0], t_player_spawn[1]}; + if (player_spawn.x >= map_size.y || player_spawn.y >= map_size.z) + { + return {"Map: [Loading] Player: Spawn out of bounds", 2}; + } + int player_tile = tiles[player_spawn.x + player_spawn.y * map_size.x]; + if (player_tile <= TileType::Special) + { + return {"Map: [Loading] Player: Spawn is not a valid tile (invalid: wall, special; valid: Floor)", 2}; + } + + // load all the enemy spawns + uint32_t number_enemy_spawns; + file.read(reinterpret_cast(&number_enemy_spawns), 4); + if (number_enemy_spawns > map_size.x) + { + return {"Map: [Loading] Enemies: Too many enemy spawns (More than tile in the map)", 3}; + } + for (int i = 0; i < number_enemy_spawns; i++) + { + uint32_t t_enemy_spawn[2]; + file.read(reinterpret_cast(t_enemy_spawn), 8); + if (t_enemy_spawn[0] >= map_size.x || t_enemy_spawn[1] >= map_size.y) + { + return {"Map: [Loading] Enemy: Spawn out of bounds", 4}; + } + if (tiles[t_enemy_spawn[0] + t_enemy_spawn[1] * map_size.y] <= TileType::Special) + { + return {"Map: [Loading] Enemy: Spawn is not a valid tile (invalid: wall, special; valid: Floor)", 4}; + } + if (t_enemy_spawn[0] == player_spawn.x && t_enemy_spawn[1] == player_spawn.y) + { + return {"Map: [Loading] Enemy: Spawn is the same as the player spawn", 4}; + } + enemy_spawns.emplace_back(t_enemy_spawn[0], t_enemy_spawn[1]); + } + + // Everything went well + return {"Map: [Loading] Success", 0}; +} + +sf::Vector2u Map::getSize() const +{ + return {static_cast(map_size.y), static_cast(map_size.z)}; +} + +void Map::draw(sf::RenderTarget& target, const sf::RenderStates states) const +{ + if (!tiles) return; + for (uint32_t x = 0; x < map_size.y; x++) { + for (uint32_t y = 0; y < map_size.z; ++y) + { + target.draw(tileAtlas, states); + } + } +} + +#include + +void Map::debug() +{ + std::cout << "Map Debug" << std::endl; + std::cout << "\tSize : " << map_size.x << ", " << map_size.y << ", " << map_size.z << std::endl; + std::cout << "\tTiles : 0x" << tiles << std::endl; + for (auto& special : specials) + { + std::cout << "\t\tSpecial : " << special.first.x << ", " << special.first.y << std::endl; + std::cout << "\t\t\tType : " << special.second.type << std::endl; + std::cout << "\t\t\tPortal : " << special.second.portal_end[0] << ", " << special.second.portal_end[1] << std::endl; + } + std::cout << "\t\tEnemy Spawns : " << enemy_spawns.size() << std::endl; + for (auto& spawn : enemy_spawns) + { + std::cout << "\t\t\tSpawn : " << spawn.x << ", " << spawn.y << std::endl; + } + std::cout << "\t\tPlayer Spawn : " << player_spawn.x << ", " << player_spawn.y << std::endl; +} \ No newline at end of file diff --git a/src/Map/Map.hpp b/src/Map/Map.hpp new file mode 100644 index 0000000..f28e631 --- /dev/null +++ b/src/Map/Map.hpp @@ -0,0 +1,101 @@ + +/****************************************************************** + * ============================================================== + * Map File Format + * ============================================================== + * + * int8_t magic[4] = 'CYMF' (Colysis Map File) : 4 bytes + * uint8_t version[3] : major, minor, patch + * + * uint8_t flags + * if (flags): + * case MapFlags::CustomTilemap: + * uint32_t filepath_buffer_size + * char filepath_buffer[filepath_buffer_size] + * uint32_t tile_size[2] : width, height + * uint32_t tile_count[2] : width, height + * + * uint32_t map_size[3] : x, y, specials + * int32_t tiles[x * y + specials * (sizeof(MapSpecial)/4)] : tilemap data + * // a special tile has a type and its tilemap data + * if tiles[i] == Special: + * uint8_t type + * MapSpecial data + * else: + * uint8_t tile + * + * uint32_t player_spawn[2] : x, y + * uint32_t number_enemy_spawns + * uint32_t enemy_spawns[number_enemy_spawns][2] : x, y + * +*******************************************************************/ + +#pragma once +#include + +#define STR(name) #name +#define STR_VALUE(name) STR(name) + +#define MAP_VERSION_MAJOR 0 +#define MAP_VERSION_MINOR 1 +#define MAP_VERSION_PATCH 0 +#define MAP_VERSION (MAP_VERSION_MAJOR << 16 | MAP_VERSION_MINOR << 8 | MAP_VERSION_PATCH) +#define MAP_VERSION_STRING STR_VALUE(MAP_VERSION_MAJOR) "." STR_VALUE(MAP_VERSION_MINOR) "." STR_VALUE(MAP_VERSION_PATCH) + + +struct MapSpecial +{ + int type; + uint32_t portal_end[2]; +}; + +enum class MapFlags : uint8_t +{ + None = 0, + CustomTilemap = 1 << 0, + UNDEFINED = 1 << 1, +}; + +enum class TileType : int +{ + Wall = -1, + Special = 0, + Other = 1, +}; + + +struct MapError +{ + const char* message; + int code; +}; + + +#include "TileAtlas.hpp" + +class Map : public sf::Drawable +{ + static_assert(sizeof(MapSpecial)%4 == 0); + + TileAtlas tileAtlas = TileAtlas::defaultAtlas(); + + sf::Vector3 map_size; // width * height, width, height + int *tiles = nullptr; + + std::vector> specials; + + std::vector enemy_spawns; + sf::Vector2u player_spawn; +public: + Map(); + + MapError load(const std::filesystem::path& path); + + sf::Vector2u getSize() const; + + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; + + void debug(); +}; + + diff --git a/src/Map/TileAtlas.cpp b/src/Map/TileAtlas.cpp new file mode 100644 index 0000000..5bd7d9e --- /dev/null +++ b/src/Map/TileAtlas.cpp @@ -0,0 +1,41 @@ +#include "TileAtlas.hpp" + +TileAtlas TileAtlas::defaultAtlas() +{ + TileAtlas atlas(sf::Vector2u{16, 16}, sf::Vector2u{16, 16}, ASSETS_PATH "/default_tilemap.png"); + atlas.sprite.setTexture(atlas.texture); + atlas.sprite.setTextureRect(sf::IntRect({0, 0}, {static_cast(atlas.tile_size.x), static_cast(atlas.tile_size.y)})); + return atlas; +} + +void TileAtlas::set(uint32_t x, uint32_t y) +{ + if (x >= tile_count.x || y >= tile_count.y) return; + sprite.setTextureRect(sf::IntRect({static_cast(x * tile_size.x), static_cast(y * tile_size.y)}, sf::Vector2(tile_size))); +} + +TileAtlas::TileAtlas(const sf::Vector2u tile_size, const sf::Vector2u tile_count, const std::filesystem::path& path) : + tile_size(tile_size), tile_count(tile_count), sprite(texture) { load(path); } + +TileAtlas::TileAtlas(sf::Vector2u tile_size, sf::Vector2u tile_count) : tile_size(tile_size), tile_count(tile_count), sprite(texture) +{ +} + +void TileAtlas::load(const std::filesystem::path& path) +{ + if (!texture.loadFromFile(path)) + { + throw std::runtime_error("TileAtlas: [Loading] Could not load tilemap -> Fatal"); + } + sprite.setTexture(texture); + sprite.setTextureRect(sf::IntRect({0, 0}, {static_cast(tile_size.x), static_cast(tile_size.y)})); +} + +void TileAtlas::draw(sf::RenderTarget& target, const sf::RenderStates states) const +{ + if (texture.getSize().x == 0 || texture.getSize().y == 0) + { + return; + } + target.draw(sprite, states); +} \ No newline at end of file diff --git a/src/Map/TileAtlas.hpp b/src/Map/TileAtlas.hpp new file mode 100644 index 0000000..ee4663a --- /dev/null +++ b/src/Map/TileAtlas.hpp @@ -0,0 +1,21 @@ +#pragma once +#include + +class TileAtlas : public sf::Drawable +{ + sf::Vector2u tile_size; + sf::Vector2u tile_count; + sf::Texture texture; + sf::Sprite sprite; +public: + explicit TileAtlas(sf::Vector2u tile_size, sf::Vector2u tile_count, const std::filesystem::path& path); + TileAtlas(sf::Vector2u tile_size, sf::Vector2u tile_count); + + void load(const std::filesystem::path& path); + + static TileAtlas defaultAtlas(); + + void set(uint32_t, uint32_t); + + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; +}; \ No newline at end of file diff --git a/src/main.c b/src/main.c deleted file mode 100644 index cb0ce90..0000000 --- a/src/main.c +++ /dev/null @@ -1,71 +0,0 @@ -#include - -#define RAYLIB_BACKEND - -#include -#include -#include -#include - - -#include - -#include -#include - -#include - - -int main(int argc, char** argv) -{ - InitWindow(900, 600, "Colysis"); - SetWindowState(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_MAXIMIZED); - - - Texture2D gery = LoadTexture(ASSETS_PATH "/karl-heinz_head.png"); - - SpriteAnimation geryanim = CreateSpriteAnimation(gery, - (Vector2){64*14,64}, (Vector2){64,64}, - 0.f, 4.f, 5, 0.15f); - - - Camera2D camera = { 0 }; - camera.target = (Vector2){0,0}; - camera.offset = (Vector2){GetScreenWidth()/2.f,GetScreenHeight()/2.f}; - camera.rotation = 0.f; - camera.zoom = 1.f; - - while (!WindowShouldClose()) { - ClearBackground((Color){ 0x00, 0x6d, 0xfb }); - float dt = GetFrameTime(); - camera.offset = (Vector2){GetScreenWidth()/2.f,GetScreenHeight()/2.f}; - - - UpdateSpriteAnimation(geryanim, dt); - - - BeginDrawing(); - { - BeginMode2D(camera); - { - DrawSpriteAnimation(geryanim, (Vector2){0,0}); - } - EndMode2D(); - - { - DrawTextFull(GetFontDefault(), "Darling, I'm Home!", - (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, - 0, 24, 5, 5, RAYWHITE); - } - } - - EndDrawing(); - } - - DestroySpriteAnimation(geryanim); - UnloadTexture(gery); - - CloseWindow(); - - return 0; -} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c351104 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,15 @@ +#include +#include + +#include "Game.hpp" + +int main() +{ + sf::RenderWindow window(sf::VideoMode({800, 450}), "Colysis", sf::Style::Close | sf::Style::Titlebar); + window.setMinimumSize(sf::Vector2u{800, 450}); + + Game game(window); + game.run(); + + return 0; +}