From 9b9b1545c50e88881ba1ffd137af6857adc069d6 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:36:14 +0200 Subject: [PATCH 01/52] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8b5602c..d566e02 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Cmake & vcpkg template This is a template repository made to quickly set up a project using cmake & vcpkg. -I usually use Clion as IDE so this repository have a basic .idea configuration You can change the name of the project in the `CMakeLists.txt` and `vcpkg.json` files. From ba2d85f565a77f960fdd9e438d2eaf7782e8c516 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:17:52 +0200 Subject: [PATCH 02/52] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 674cee3..a8f806d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 P0ulpy +Copyright (c) 2024 P0ulpy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 778bf92b8d74527d88d8039248bbd78554ff9d93 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:19:19 +0200 Subject: [PATCH 03/52] Update README.md --- README.md | 236 +++++++++++++++++++----------------------------------- 1 file changed, 81 insertions(+), 155 deletions(-) diff --git a/README.md b/README.md index d566e02..d50b31c 100644 --- a/README.md +++ b/README.md @@ -1,199 +1,125 @@ -# Cmake & vcpkg template +# Raycasting Engine - A Modern C++ Implementation of a DOOM Style Renderer -This is a template repository made to quickly set up a project using cmake & vcpkg. +Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. -You can change the name of the project in the `CMakeLists.txt` and `vcpkg.json` files. +This project is developed in a recreational programming context. It serves as a learning experience to explore new concepts and technologies while creating a project around them. -## Bootstrap workspace +## Goals +The primary goal of this project is to implement a DOOM Style Renderer with a simple Engine around it and a Graphical Editor for prototyping Maps, rendering, gameplay etc... I'm using modern C++ and technologies like raylib and imgui it achieve this goal. At the end the engine should be able to build and ship a standalone executable without prototyping tools. -*Windows* +## Showcase -Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) +![Overall Showcase](.github/videos/overall_showcase.mp4) +![3D View View](.github/images/3D_view.png) +![Map Editor View](.github/images/map_editor_view.png) -Then run the bootstrap script -```bat -.\scripts\bootstrap-workspace.bat -``` +## Features checklist -*GNU/Linux using apt* +For now the project in a prototyping phase, still mainly focused in making an efficient Renderer. -Install necessary build tools and a C/C++ compiler -```sh -sudo apt-get update -sudo apt-get install build-essential tar curl zip unzip autoconf libtool g++ gcc -``` +*Renderer* +- [x] DOOM Style rendering + - [x] Sectors and top/bottom Elevation + - [x] Neighbouring sectors sides + - [ ] Textures for Wall & Borders +- [x] Pitch and Yaw for camera movement +- [ ] Vignette for sprites rendered on over walls +- [ ] Entities sprites within the 3D space +- [ ] Basic Physics including : + - [x] Elevation related to sectors + - [ ] Simple gravity + - [ ] 3D space Raycast +- [x] Simple shading using far plane distance +- [ ] Dynamic lighting for light sources -Then run the bootstrap script -```sh -./scripts/bootstrap-workspace.sh -``` +*Editor* +- [x] 3D View +- [x] Simple inspector for Global world objects (Physics, Camera, etc...) +- [ ] Rendering Debugger + - [ ] Step by step rendering + - [ ] Rendering steps visalizer + - [ ] Map Editor + - [~] Sector Editor + - [ ] Vignet editor + - [ ] Sprite editor + - [ ] -Well done your repo is now ready to work with cmake and vcpkg ! +*System* +- [ ] Project instance cration : being able to create a project witch is using the engine and editor in one click +- [ ] Project shiping + - [ ] Release Build + - [ ] Assets bundle -## Add dependency +## Building the project from sources -You can add any vcpkg dependencies by editing `vcpkg.json` and then add them to you cmake target with `find_package()` and `target_link_libraries()`. You can found more information about cmake integration in the [vcpkg documentation](https://learn.microsoft.com/vcpkg/users/buildsystems/cmake-integration#using-libraries) +This repo toolchain as been created using my (cmake and vcpkg template)[https://github.com/P0ulpy/cmake-vcpkg-template]. -You can found a exemple of adding dependencies in the [Installing dependencies exemple with SFML](#adding-dependencies-exemple-with-sfml-) section. +### Bootstrap workspace -## Generate your project +`Windows :` -Running `generate-cmake-*.sh` will install dependencies if required and then generate your cmake solution. +Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) -Use it every times you add a dependency or modify `CMakeLists.txt` +`GNU/Linux (apt) :` -*Windows* +Install necessary build tools and a C/C++ compiler ```sh -# For debug build -.\scripts\generate-cmake-debug.bat -# For release build -.\scripts\generate-cmake-release.bat +sudo apt-get update +sudo apt-get install build-essential tar curl zip unzip autoconf libtool g++ gcc ``` -*Unix* +Then run the bootstrap script ```sh -# For debug build -./scripts/generate-cmake-debug.sh -# For release build -./scripts/generate-cmake-release.sh +# Unix +./scripts/bootstrap-workspace.sh +# Windows +.\scripts\bootstrap-workspace.bat ``` -## Compile your project +*Generate the project :* -Cmake will atomatically detect your compiler and generator - -*Windows* ```sh # For debug build -.\scripts\build-debug.bat +# Unix +./scripts/generate-cmake-debug.sh +# Windows +.\scripts\generate-cmake-debug.bat + # For release build -.\scripts\build-release.bat +# Unix +./scripts/generate-cmake-release.sh +# Windows +.\scripts\generate-cmake-release.bat ``` -*Unix* +*Compile the project :* + ```bash # For debug build +# Unix ./scripts/build-debug.sh +# Windows +.\scripts\build-debug.bat + # For release build +# Unix ./scripts/build-release.sh +# Windows +.\scripts\build-release.bat ``` -**Run your program** +**Run the program** You can now run the compiled program by looking into `out/Debug` or `out/Release`. The out directory hierarchy will be different depending on your generator. For exemple with Make generator in Debug mode run your program like that ```bash -# The executable name will change acording to the value set in add_executable(, ...) -./out/Debug/cmake-vcpkg-template-app -``` - -## Adding dependencies exemple with SFML : - -In this exemple we will add SFML to our project, make it available in our cmake target and then compile a basic exemple program. - -**Add dependencies to vcpkg :** - -`vcpkg.json` -```json -{ - "name": "cmake-vcpkg-template", - "version": "0.1.0", - "builtin-baseline": "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98", - "dependencies": [ - { - "name" : "sfml", - "version>=" : "2.5.1#14" - } - ] -} -``` - -For further information you can check the [microsoft documentation about vcpkg.json](https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json) and [vcpkg documentation about manifests dependencies](https://learn.microsoft.com/vcpkg/concepts/manifest-mode) - -**Add dependencies to your cmake target :** - -Now that we have added our dependencies to vcpkg we can add them to our cmake target. -First we use `find_package()` to find the package in vcpkg, then we use `target_link_libraries()` to link it to our target, It is important to call it after the target creation (witch is `add_executable` in our case). - -`CMakeLists.txt` -```diff -... -+ find_package(SFML COMPONENTS system window graphics network CONFIG REQUIRED) - -SET(EXECUTABLE_TARGET_NAME cmake-vcpkg-template-app) - -add_executable(${EXECUTABLE_TARGET_NAME} - main.cpp -) - -+ target_link_libraries(${EXECUTABLE_TARGET_NAME} -+ PRIVATE sfml-system sfml-network sfml-graphics sfml-window -+ ) -... -``` - -You must reload your cmake project and reset cache in your IDE or directly with the cmake command to make it work. -```sh -./scripts/generate-cmake-debug.sh -``` - -**In case of issues while running vcpkg install** - -Pay attention at this kind of message of vcpkg : -``` --- SFML currently requires the following libraries from the system package manager: - libudev - libx11 - libxrandr - libxcursor - opengl -You can intall them in your system using apt-get install libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev +# Unix +./out/Debug/raycasting-engine +# Windows +.\out\Debug\raycasting-engine.exe ``` -Most of the time install issues with vcpkg are related to a dynamic library who are not installed in you system. Most of the time vcpkg explain directly how to install them. +## Licence -**Use SFML in our program to make sure our installation is working :** - -For this exemple we will use the [SFML tutorial](https://www.sfml-dev.org/tutorials/2.6/start-linux.php#compiling-a-sfml-program) to make sure our installation is working. -After pasting the exemple code in your `main.cpp` we can now compile our program and run it, you should see a window with a green circle in it and a title "SFML works!". - -Congratulations you have successfully installed SFML in your project ! -You can now add any other dependencies you want. - -**To go deaper into cmake integration using vcpkg you can start by the** [microsoft documentation for cmake integration using libraries](https://learn.microsoft.com/vcpkg/users/buildsystems/cmake-integration#using-libraries) - -## Misc. - -### Vcpkg triplets - -You can found more information about the vcpkg triplets in the [vcpkg documentation about triplets](https://learn.microsoft.com/fr-fr/vcpkg/users/triplets) - -### Updating vcpkg submodule - -If you need to update vcpkg or you encounter issues with it you can update the vcpkg submodule with : -```bash -git submodule update --remote -``` - -After finished it should write in stdout something like : -``` -Submodule path 'vcpkg': checked out '' -``` - -Update the builtin-baseline in `vcpkg.json` -```diff -{ - "name" : "cmake-vcpkg-template", - "version" : "0.1.0", -- "builtin-baseline" : "4874bea8eb8db9e6610672cccdd6ccd5d55c6f1a", -+ "builtin-baseline" : , - "dependencies" : [] -} -``` - -And then commit the modification -```bash -git add . -git commit -m "Update vcpkg to it lastest version" -``` +This repo is ender MIT Licence, see (LICENSE)[LICENSE]. From a40d73faad206b8b921b270fe8d30e747277f4da Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:20:27 +0200 Subject: [PATCH 04/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d50b31c..133fe82 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ For now the project in a prototyping phase, still mainly focused in making an ef - [~] Sector Editor - [ ] Vignet editor - [ ] Sprite editor - - [ ] + - [ ] Texture Browser *System* - [ ] Project instance cration : being able to create a project witch is using the engine and editor in one click From c54d43956f75a84f1edf64dcb398b0f5e5de796e Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:21:22 +0200 Subject: [PATCH 05/52] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 133fe82..99dffb9 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ For now the project in a prototyping phase, still mainly focused in making an ef ## Building the project from sources -This repo toolchain as been created using my (cmake and vcpkg template)[https://github.com/P0ulpy/cmake-vcpkg-template]. +This repo toolchain as been created using my [cmake and vcpkg template](https://github.com/P0ulpy/cmake-vcpkg-template). ### Bootstrap workspace @@ -122,4 +122,4 @@ For exemple with Make generator in Debug mode run your program like that ## Licence -This repo is ender MIT Licence, see (LICENSE)[LICENSE]. +This repo is ender MIT Licence, see [LICENSE](LICENSE). From c122b97a4cbd583e2bf623471e6774239d44215f Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:24:28 +0200 Subject: [PATCH 06/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99dffb9..f345b6e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. -This project is developed in a recreational programming context. It serves as a learning experience to explore new concepts and technologies while creating a project around them. +This project is developed in a **recreational programming** context, it does not aim to be *production ready* at some point. It serves as a learning experience to explore new concepts and technologies while creating a project around them. ## Goals The primary goal of this project is to implement a DOOM Style Renderer with a simple Engine around it and a Graphical Editor for prototyping Maps, rendering, gameplay etc... I'm using modern C++ and technologies like raylib and imgui it achieve this goal. At the end the engine should be able to build and ship a standalone executable without prototyping tools. From 4bbd9b636f92c1d1f37de8ede38bb38b9966a576 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:27:41 +0200 Subject: [PATCH 07/52] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f345b6e..f336e8f 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,14 @@ This repo toolchain as been created using my [cmake and vcpkg template](https:// `Windows :` -Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) +Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with c++ corssplateform extention and [CMake](https://cmake.org/download). `GNU/Linux (apt) :` Install necessary build tools and a C/C++ compiler ```sh sudo apt-get update -sudo apt-get install build-essential tar curl zip unzip autoconf libtool g++ gcc +sudo apt-get install cmake build-essential tar curl zip unzip autoconf libtool g++ gcc ``` Then run the bootstrap script From 3ab2c36535585e490670187d6e78ccd663b84025 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:27:56 +0200 Subject: [PATCH 08/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f336e8f..ff6eb91 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ This repo toolchain as been created using my [cmake and vcpkg template](https:// `Windows :` -Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with c++ corssplateform extention and [CMake](https://cmake.org/download). +Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with c++ crossplateform extention and [CMake](https://cmake.org/download). `GNU/Linux (apt) :` From 4c605570acb50becaffc173856bf63939801efeb Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:29:05 +0200 Subject: [PATCH 09/52] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ff6eb91..6c8ee15 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The primary goal of this project is to implement a DOOM Style Renderer with a si For now the project in a prototyping phase, still mainly focused in making an efficient Renderer. *Renderer* -- [x] DOOM Style rendering +- [x] DOOM Style rendering including : - [x] Sectors and top/bottom Elevation - [x] Neighbouring sectors sides - [ ] Textures for Wall & Borders @@ -35,10 +35,10 @@ For now the project in a prototyping phase, still mainly focused in making an ef *Editor* - [x] 3D View - [x] Simple inspector for Global world objects (Physics, Camera, etc...) -- [ ] Rendering Debugger +- [ ] Rendering Debugger including : - [ ] Step by step rendering - [ ] Rendering steps visalizer - - [ ] Map Editor + - [ ] Map Editor including : - [~] Sector Editor - [ ] Vignet editor - [ ] Sprite editor @@ -46,7 +46,7 @@ For now the project in a prototyping phase, still mainly focused in making an ef *System* - [ ] Project instance cration : being able to create a project witch is using the engine and editor in one click -- [ ] Project shiping +- [ ] Project shiping including : - [ ] Release Build - [ ] Assets bundle From 35c3bb2e0c896460313a0c0d4fd3166dc50a8fde Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:34:23 +0200 Subject: [PATCH 10/52] Create cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 0000000..338470e --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,68 @@ +name: CMake on multiple platforms + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release, Debug] + c_compiler: [gcc, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} From d137f26387c3558df10c531ac0e8e1bde0a65395 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:35:06 +0200 Subject: [PATCH 11/52] Update cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 338470e..f3092e4 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -2,9 +2,9 @@ name: CMake on multiple platforms on: push: - branches: [ "master" ] + branches: [ "main" ] pull_request: - branches: [ "master" ] + branches: [ "main" ] jobs: build: From 3dcdcf5d54b6954b44a04566b5f98f308b5668f1 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:38:09 +0200 Subject: [PATCH 12/52] Update vcpkg.json --- vcpkg.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index 18347fc..c05db07 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name" : "cmake-vcpkg-template", "version" : "0.1.0", - "builtin-baseline" : "c9919121dde6f61c0436adda94624636e041226b", + "builtin-baseline" : "261dd6831673d3b07e5118261f7e161a21d1a759", "dependencies" : [ { "name" : "raylib", @@ -19,4 +19,4 @@ ] } ] -} \ No newline at end of file +} From 61b9754ea9cfa7d83f6fb9e574cb14d91eaeef8e Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:43:05 +0200 Subject: [PATCH 13/52] Update cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index f3092e4..5fb9078 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -48,6 +48,11 @@ jobs: shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Bootstrap vcpkg + shell: bash + run: ./vcpkg/bootstrap-vcpkg.sh -disableMetrics + - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type From 431a2ede245fe1d1dd439a69b44d27f10b05f26f Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:28:52 +0200 Subject: [PATCH 14/52] Update raycasting-engine.code-workspace --- .vscode/raycasting-engine.code-workspace | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/raycasting-engine.code-workspace b/.vscode/raycasting-engine.code-workspace index a0694b3..675ff7c 100644 --- a/.vscode/raycasting-engine.code-workspace +++ b/.vscode/raycasting-engine.code-workspace @@ -239,6 +239,8 @@ "C_Cpp_Runner.excludeSearch": [ "**/build", "**/build/**", + "**/out", + "**/out/**", "**/.*", "**/.*/**", "**/.vscode", @@ -251,4 +253,4 @@ "C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.msvcSecureNoWarnings": false, } -} \ No newline at end of file +} From 26d6fed8f8092e82181efaa9b03362e0cd99e0d4 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:29:18 +0200 Subject: [PATCH 15/52] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c8ee15..5ef13d5 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ This repo toolchain as been created using my [cmake and vcpkg template](https:// `Windows :` -Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with c++ crossplateform extention and [CMake](https://cmake.org/download). +Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with [C and C++ support](https://learn.microsoft.com/cpp/build/vscpp-step-0-installation?view=msvc-170#step-4---choose-workloads) and [C++ linux development with cmake](https://learn.microsoft.com/cpp/linux/download-install-and-setup-the-linux-development-workload?view=msvc-170#visual-studio-setup). +Make sure you installed [CMake](https://cmake.org/download) as well. `GNU/Linux (apt) :` @@ -120,6 +121,11 @@ For exemple with Make generator in Debug mode run your program like that .\out\Debug\raycasting-engine.exe ``` +**Using Visual Studio Code workspace** + +If you are using visual studio code you can directly use the project embeded workspace `.vscode/raycasting-engine.code-workspace`. +You can press `F5` to build and run with debugger gdb or vsdbg (visual studio debugger). + ## Licence This repo is ender MIT Licence, see [LICENSE](LICENSE). From 7d7f7135d1f10557bcce701a664e36477631e5fb Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:31:21 +0200 Subject: [PATCH 16/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ef13d5..d74e9f2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ For now the project in a prototyping phase, still mainly focused in making an ef - [x] Neighbouring sectors sides - [ ] Textures for Wall & Borders - [x] Pitch and Yaw for camera movement -- [ ] Vignette for sprites rendered on over walls +- [ ] Vignette for sprites rendered over walls - [ ] Entities sprites within the 3D space - [ ] Basic Physics including : - [x] Elevation related to sectors From 135f827cdad2ec6386e83f5d3243587782f4f4b2 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:35:54 +0200 Subject: [PATCH 17/52] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d74e9f2..c1b7c05 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![CMake Build on multiple platforms](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-multi-platform.yml) # Raycasting Engine - A Modern C++ Implementation of a DOOM Style Renderer Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. From 93e4dee3efe8715c493775bf47efb4abcf1e206f Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:48:19 +0200 Subject: [PATCH 18/52] Update and rename cmake-multi-platform.yml to cmake-build-multi-platform.yml --- ...{cmake-multi-platform.yml => cmake-build-multi-platform.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{cmake-multi-platform.yml => cmake-build-multi-platform.yml} (98%) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml similarity index 98% rename from .github/workflows/cmake-multi-platform.yml rename to .github/workflows/cmake-build-multi-platform.yml index 5fb9078..1771079 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -1,4 +1,4 @@ -name: CMake on multiple platforms +name: CMake Build on multiple platforms on: push: From d1b228d0bd468b4c30efb467559aa45db8101cb3 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:49:05 +0200 Subject: [PATCH 19/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1b7c05..abf6c00 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CMake Build on multiple platforms](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-multi-platform.yml) +[![CMake Build on multiple platforms](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-multi-platform.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-multi-platform.yml) # Raycasting Engine - A Modern C++ Implementation of a DOOM Style Renderer Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. From d68094e8c47f46c52a33ac0945eaccc3134dfdd9 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Wed, 26 Jun 2024 23:13:46 +0200 Subject: [PATCH 20/52] Update vcpkg submodule --- vcpkg | 2 +- vcpkg.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vcpkg b/vcpkg index 261dd68..2f7e9e1 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit 261dd6831673d3b07e5118261f7e161a21d1a759 +Subproject commit 2f7e9e11f2fc18c93763254dfacd4549eae0212e diff --git a/vcpkg.json b/vcpkg.json index c05db07..1ee619a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name" : "cmake-vcpkg-template", "version" : "0.1.0", - "builtin-baseline" : "261dd6831673d3b07e5118261f7e161a21d1a759", + "builtin-baseline" : "2f7e9e11f2fc18c93763254dfacd4549eae0212e", "dependencies" : [ { "name" : "raylib", From 854564b46add55cd608c6936107d0fcdc914c642 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Wed, 26 Jun 2024 23:18:59 +0200 Subject: [PATCH 21/52] Update vcpkg submodule at tag 2023.10.19 --- vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg b/vcpkg index 2f7e9e1..8eb5735 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit 2f7e9e11f2fc18c93763254dfacd4549eae0212e +Subproject commit 8eb57355a4ffb410a2e94c07b4dca2dffbee8e50 From f700ae0e5604188b9060c2f9b213e91ace6a93b8 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:32:59 +0200 Subject: [PATCH 22/52] Update cmake-build-multi-platform.yml --- .../workflows/cmake-build-multi-platform.yml | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 1771079..209fb2b 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -48,26 +48,23 @@ jobs: shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - uses: lukka/get-cmake@latest - - name: Bootstrap vcpkg - shell: bash - run: ./vcpkg/bootstrap-vcpkg.sh -disableMetrics - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} - - name: Build - # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + - name: Restore from cache and setup vcpkg executable and data files. + uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: 'vcpkg.json' - - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} + # Note: if the preset misses the "configuration", it is possible to explicitly select the + # configuration with the additional `--config` flag, e.g.: + # buildPreset: 'ninja-vcpkg' + # buildPresetAdditionalArgs: "[`--config`, `Release`]" + # testPreset: 'ninja-vcpkg' + # testPresetAdditionalArgs: "[`--config`, `Release`]" + - name: Run CMake+vcpkg+Ninja+CTest to build packages and generate/build/test the code. + uses: lukka/run-cmake@v10 + with: + configurePreset: 'ninja-multi-vcpkg' + buildPreset: 'ninja-vcpkg-release' + testPreset: 'test-release' From 35a8942fe3284585cd6c158e318eb35e1730e224 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:33:59 +0200 Subject: [PATCH 23/52] Create CMakePresets.json --- CMakePresets.json | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 CMakePresets.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..8d14b09 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,65 @@ +{ + "version": 8, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "ninja-multi-vcpkg", + "displayName": "Ninja Multi-Config", + "description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations", + "binaryDir": "${sourceDir}/builds/${presetName}", + "generator": "Ninja Multi-Config", + "toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake" + } + ], + "buildPresets": [ + { + "name": "ninja-vcpkg-debug", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build (Debug)", + "description": "Build with Ninja/vcpkg (Debug)", + "configuration": "Debug" + }, + { + "name": "ninja-vcpkg-release", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build (Release)", + "description": "Build with Ninja/vcpkg (Release)", + "configuration": "Release" + }, + { + "name": "ninja-vcpkg", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build", + "description": "Build with Ninja/vcpkg" + } + ], + "testPresets": [ + { + "name": "test-ninja-vcpkg", + "configurePreset": "ninja-multi-vcpkg", + "hidden": true + }, + { + "name": "test-debug", + "description": "Test (Debug)", + "displayName": "Test (Debug)", + "configuration": "Debug", + "inherits": [ + "test-ninja-vcpkg" + ] + }, + { + "name": "test-release", + "description": "Test (Release)", + "displayName": "Test (Release)", + "configuration": "Release", + "inherits": [ + "test-ninja-vcpkg" + ] + } + ] +} From 611c697b7d9261eed29bcf6816e9e53aeda35c44 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Wed, 26 Jun 2024 23:36:24 +0200 Subject: [PATCH 24/52] Update vcpkg submodule to 2024.06.15 --- vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg b/vcpkg index 8eb5735..f7423ee 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit 8eb57355a4ffb410a2e94c07b4dca2dffbee8e50 +Subproject commit f7423ee180c4b7f40d43402c2feb3859161ef625 From b2db016e29df54de8e26677def51222a311485f4 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:04:58 +0200 Subject: [PATCH 25/52] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abf6c00..e01ff24 100644 --- a/README.md +++ b/README.md @@ -129,4 +129,4 @@ You can press `F5` to build and run with debugger gdb or vsdbg (visual studio de ## Licence -This repo is ender MIT Licence, see [LICENSE](LICENSE). +This project is open-source and available under the [MIT Licence](LICENSE). From 6ccaf0f4e0d923f428c1ccc1ac6e6af00f648a53 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:45:33 +0200 Subject: [PATCH 26/52] Update cmake-build-multi-platform.yml --- .../workflows/cmake-build-multi-platform.yml | 89 +++++++------------ 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 209fb2b..63e08c9 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -7,64 +7,43 @@ on: branches: [ "main" ] jobs: - build: + job: + name: ${{ matrix.os }}-${{ github.workflow }} runs-on: ${{ matrix.os }} - strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. fail-fast: false - - # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest, windows-latest] - build_type: [Release, Debug] - c_compiler: [gcc, cl] - include: - - os: windows-latest - c_compiler: cl - cpp_compiler: cl - - os: ubuntu-latest - c_compiler: gcc - cpp_compiler: g++ - exclude: - - os: windows-latest - c_compiler: gcc - - os: ubuntu-latest - c_compiler: cl + os: [ubuntu-latest, macos-latest, windows-latest] + #env: + # + # [OPTIONAL] Define the vcpkg's triplet + # you want to enforce, otherwise the default one + # for the hosting system will be automatically + # choosen (x64 is the default on all platforms, + # e.g. x64-osx). + # VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }} steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Set reusable strings - # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. - id: strings - shell: bash - run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - - uses: lukka/get-cmake@latest - - - name: Restore from cache and setup vcpkg executable and data files. - uses: lukka/run-vcpkg@v11 - with: - vcpkgJsonGlob: 'vcpkg.json' - - # Note: if the preset misses the "configuration", it is possible to explicitly select the - # configuration with the additional `--config` flag, e.g.: - # buildPreset: 'ninja-vcpkg' - # buildPresetAdditionalArgs: "[`--config`, `Release`]" - # testPreset: 'ninja-vcpkg' - # testPresetAdditionalArgs: "[`--config`, `Release`]" - - name: Run CMake+vcpkg+Ninja+CTest to build packages and generate/build/test the code. - uses: lukka/run-cmake@v10 - with: - configurePreset: 'ninja-multi-vcpkg' - buildPreset: 'ninja-vcpkg-release' - testPreset: 'test-release' + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: lukka/get-cmake@latest + + - name: Restore from cache and setup vcpkg executable and data files. + uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: 'vcpkg.json' + + # Note: if the preset misses the "configuration", it is possible to explicitly select the + # configuration with the additional `--config` flag, e.g.: + # buildPreset: 'ninja-vcpkg' + # buildPresetAdditionalArgs: "[`--config`, `Release`]" + # testPreset: 'ninja-vcpkg' + # testPresetAdditionalArgs: "[`--config`, `Release`]" + - name: Run CMake+vcpkg+Ninja+CTest to build packages and generate/build/test the code. + uses: lukka/run-cmake@v10 + with: + configurePreset: 'ninja-multi-vcpkg' + buildPreset: 'ninja-vcpkg-release' + testPreset: 'test-release' From 09227bd87d23e57af83c14176166b871238fe538 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:48:09 +0200 Subject: [PATCH 27/52] Update vcpkg.json --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 1ee619a..8c2abb5 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name" : "cmake-vcpkg-template", "version" : "0.1.0", - "builtin-baseline" : "2f7e9e11f2fc18c93763254dfacd4549eae0212e", + "builtin-baseline" : "f7423ee180c4b7f40d43402c2feb3859161ef625", "dependencies" : [ { "name" : "raylib", From 95be91f6f5898e0ed25e77dcf6fb15b8b3104e95 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 18:54:06 +0200 Subject: [PATCH 28/52] Update Vcpkg --- vcpkg | 2 +- vcpkg.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vcpkg b/vcpkg index f7423ee..f61a294 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit f7423ee180c4b7f40d43402c2feb3859161ef625 +Subproject commit f61a294e765b257926ae9e9d85f96468a0af74e7 diff --git a/vcpkg.json b/vcpkg.json index 8c2abb5..6671092 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name" : "cmake-vcpkg-template", "version" : "0.1.0", - "builtin-baseline" : "f7423ee180c4b7f40d43402c2feb3859161ef625", + "builtin-baseline" : "f61a294e76", "dependencies" : [ { "name" : "raylib", From d37b3f40fe321230daafad27483a3099f8e3c4b1 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 18:55:19 +0200 Subject: [PATCH 29/52] Update vcpkg.json --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 6671092..8cfbb4a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "name" : "cmake-vcpkg-template", "version" : "0.1.0", - "builtin-baseline" : "f61a294e76", + "builtin-baseline" : "f61a294e765b257926ae9e9d85f96468a0af74e7", "dependencies" : [ { "name" : "raylib", From d9712e0766ef9414a1d357a225dd88b2042eba9f Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:07:35 +0200 Subject: [PATCH 30/52] Update vcpkg.json --- vcpkg.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index 8cfbb4a..c4e4536 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,6 @@ { - "name" : "cmake-vcpkg-template", - "version" : "0.1.0", - "builtin-baseline" : "f61a294e765b257926ae9e9d85f96468a0af74e7", + "name" : "raycasting-engine", + "version-string": "latest", "dependencies" : [ { "name" : "raylib", From d958d90387665725983ea974d8d6cf2368d12a39 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:08:58 +0200 Subject: [PATCH 31/52] Update vcpkg.json --- vcpkg.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index c4e4536..e7eb39d 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,15 +4,15 @@ "dependencies" : [ { "name" : "raylib", - "version>=" : "5.0" + "version=" : "5.0" }, { "name" : "raygui", - "version>=" : "4.0" + "version=" : "4.0" }, { "name" : "imgui", - "version>=" : "1.90", + "version=" : "1.90", "features": [ "docking-experimental" ] From 85151b974272b6d7195219cf1f0bbb1ee6843c2b Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:10:34 +0200 Subject: [PATCH 32/52] Update vcpkg.json --- vcpkg.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index e7eb39d..e9f4bd2 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,16 +3,13 @@ "version-string": "latest", "dependencies" : [ { - "name" : "raylib", - "version=" : "5.0" + "name" : "raylib" }, { - "name" : "raygui", - "version=" : "4.0" + "name" : "raygui" }, { "name" : "imgui", - "version=" : "1.90", "features": [ "docking-experimental" ] From 5e3bfe582a7b9441383f4ee301958ca45fc5f8ad Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:29:51 +0200 Subject: [PATCH 33/52] Update githubaction --- .github/workflows/cmake-build-multi-platform.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 63e08c9..6751a43 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -28,6 +28,14 @@ jobs: with: submodules: true + - name: Install dependencies on Ubuntu for GLFW3 + if: runner.os == 'Linux' + run: sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on Ubuntu for Raylib + if: runner.os == 'Linux' + run: sudo apt install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + - uses: lukka/get-cmake@latest - name: Restore from cache and setup vcpkg executable and data files. From c482860fcac718b7fa4c7f28f34ac169d22ed5a4 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:35:45 +0200 Subject: [PATCH 34/52] Update githubaction --- .github/workflows/cmake-build-multi-platform.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 6751a43..7eb17ef 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -29,12 +29,24 @@ jobs: submodules: true - name: Install dependencies on Ubuntu for GLFW3 - if: runner.os == 'Linux' + if: runner.os == 'ubuntu-latest' run: sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config - name: Install dependencies on Ubuntu for Raylib - if: runner.os == 'Linux' + if: runner.os == 'ubuntu-latest' run: sudo apt install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + - name: Install dependencies on macOS for GLFW3 + if: runner.os == 'macos-latest' + run: brew install install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on macOS for Raylib + if: runner.os == 'macos-latest' + run: brew install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + # - name: Install dependencies on Windows + # if: runner.os == 'windows-latest' + # run: choco install - uses: lukka/get-cmake@latest From 54a316f3ba999cf1fabba92df0c607949f95413d Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:49:03 +0200 Subject: [PATCH 35/52] Update githubaction --- .../workflows/cmake-build-multi-platform.yml | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 7eb17ef..971343a 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -11,17 +11,11 @@ jobs: name: ${{ matrix.os }}-${{ github.workflow }} runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: true matrix: os: [ubuntu-latest, macos-latest, windows-latest] - #env: - # - # [OPTIONAL] Define the vcpkg's triplet - # you want to enforce, otherwise the default one - # for the hosting system will be automatically - # choosen (x64 is the default on all platforms, - # e.g. x64-osx). - # VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }} + build_type: [Release, Debug] + c_compiler: [gcc, cl] steps: - uses: actions/checkout@v4 @@ -61,9 +55,12 @@ jobs: # buildPresetAdditionalArgs: "[`--config`, `Release`]" # testPreset: 'ninja-vcpkg' # testPresetAdditionalArgs: "[`--config`, `Release`]" - - name: Run CMake+vcpkg+Ninja+CTest to build packages and generate/build/test the code. - uses: lukka/run-cmake@v10 - with: - configurePreset: 'ninja-multi-vcpkg' - buildPreset: 'ninja-vcpkg-release' - testPreset: 'test-release' + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} \ No newline at end of file From 90b35f57fdfbe3752ac9c8eae459e37e614b04dc Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:51:04 +0200 Subject: [PATCH 36/52] Update cicd --- .../workflows/cmake-build-multi-platform.yml | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 971343a..f22b707 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -16,6 +16,18 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] build_type: [Release, Debug] c_compiler: [gcc, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: ubuntu-latest + c_compiler: cl steps: - uses: actions/checkout@v4 @@ -49,13 +61,24 @@ jobs: with: vcpkgJsonGlob: 'vcpkg.json' - # Note: if the preset misses the "configuration", it is possible to explicitly select the - # configuration with the additional `--config` flag, e.g.: - # buildPreset: 'ninja-vcpkg' - # buildPresetAdditionalArgs: "[`--config`, `Release`]" - # testPreset: 'ninja-vcpkg' - # testPresetAdditionalArgs: "[`--config`, `Release`]" - - name: Build + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build CMake # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} From c4e7643164bff04feaba7577e5306887b9be85c7 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:54:01 +0200 Subject: [PATCH 37/52] ci --- .github/workflows/cmake-build-multi-platform.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index f22b707..9060109 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -20,12 +20,17 @@ jobs: - os: windows-latest c_compiler: cl cpp_compiler: cl + - os: macos-latest + c_compiler: gcc + cpp_compiler: g++ - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ exclude: - os: windows-latest c_compiler: gcc + - os: macos-latest + c_compiler: cl - os: ubuntu-latest c_compiler: cl From e7cf944b1a63f3c1ff3fcc0c22581d9c2efae4f0 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 19:55:26 +0200 Subject: [PATCH 38/52] CI --- .github/workflows/cmake-build-multi-platform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-multi-platform.yml index 9060109..ca15937 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-multi-platform.yml @@ -8,10 +8,10 @@ on: jobs: job: - name: ${{ matrix.os }}-${{ github.workflow }} + name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-Build runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] build_type: [Release, Debug] From 2fc974794671ed46ec7fce61bc30e50b0119f22f Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 22:03:02 +0200 Subject: [PATCH 39/52] To Compile on MacOs --- src/RaycastingMath.hpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/RaycastingMath.hpp b/src/RaycastingMath.hpp index b2e5a4d..77430fd 100644 --- a/src/RaycastingMath.hpp +++ b/src/RaycastingMath.hpp @@ -11,17 +11,7 @@ #include "ColorHelper.hpp" -struct Vector2i -{ - int x { 0 }; - int y { 0 }; -}; - -struct Vector2ui -{ - unsigned int x { 0 }; - unsigned int y { 0 }; -}; +constexpr Vector2 Vector2Zero = { 0, 0 }; inline Vector2 Vector2DirectionFromAngle(float angleRadian, float length = 1) { @@ -142,7 +132,7 @@ inline constexpr float PointSegmentSide(Vector2 point, Vector2 a, Vector2 b) inline Vector2 FindInsidePoint(const std::vector& walls) { - Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), Vector2(0, 0), + Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), Vector2Zero, [](const Vector2& a, const Wall& b) { return Vector2Add(a, b.segment.a); }); float wallsSize = static_cast(walls.size()); From ded05ed3ca121b0a5866736770f81c3a33ab3d00 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 22:07:00 +0200 Subject: [PATCH 40/52] Vec 2 --- src/RaycastingMath.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/RaycastingMath.hpp b/src/RaycastingMath.hpp index 77430fd..6b216d4 100644 --- a/src/RaycastingMath.hpp +++ b/src/RaycastingMath.hpp @@ -11,6 +11,18 @@ #include "ColorHelper.hpp" +struct Vector2i +{ + int x { 0 }; + int y { 0 }; +}; + +struct Vector2ui +{ + unsigned int x { 0 }; + unsigned int y { 0 }; +}; + constexpr Vector2 Vector2Zero = { 0, 0 }; inline Vector2 Vector2DirectionFromAngle(float angleRadian, float length = 1) From a97ba042a17fbe8a645fc4c929a5247c3d8148aa Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Tue, 2 Jul 2024 22:09:41 +0200 Subject: [PATCH 41/52] vec --- src/RaycastingMath.hpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/RaycastingMath.hpp b/src/RaycastingMath.hpp index 6b216d4..0a6a534 100644 --- a/src/RaycastingMath.hpp +++ b/src/RaycastingMath.hpp @@ -11,20 +11,6 @@ #include "ColorHelper.hpp" -struct Vector2i -{ - int x { 0 }; - int y { 0 }; -}; - -struct Vector2ui -{ - unsigned int x { 0 }; - unsigned int y { 0 }; -}; - -constexpr Vector2 Vector2Zero = { 0, 0 }; - inline Vector2 Vector2DirectionFromAngle(float angleRadian, float length = 1) { return { @@ -144,7 +130,8 @@ inline constexpr float PointSegmentSide(Vector2 point, Vector2 a, Vector2 b) inline Vector2 FindInsidePoint(const std::vector& walls) { - Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), Vector2Zero, + Vector2 startAt = { 0 }; + Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), startAt, [](const Vector2& a, const Wall& b) { return Vector2Add(a, b.segment.a); }); float wallsSize = static_cast(walls.size()); From 9fe6f5d520c3a6585139c389069b6f0b52ea5de4 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:01:38 +0200 Subject: [PATCH 42/52] Update CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed49ae7..66fe99b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cm project(raycasting-engine) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") SET(APP_TARGET_NAME raycasting-engine-app) @@ -35,4 +35,4 @@ target_include_directories(${APP_TARGET_NAME} target_link_libraries(${APP_TARGET_NAME} PRIVATE raylib PRIVATE imgui::imgui -) \ No newline at end of file +) From b64025a19708bd1e7fb37b4eda24265b61b61396 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:04:15 +0200 Subject: [PATCH 43/52] Update WorldEditor.hpp --- src/Editor/WorldEditor.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Editor/WorldEditor.hpp b/src/Editor/WorldEditor.hpp index 4307a42..4596b73 100644 --- a/src/Editor/WorldEditor.hpp +++ b/src/Editor/WorldEditor.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include "../World.hpp" @@ -115,4 +115,4 @@ class WorldEditor private: World& world; RenderTexture2D renderTexture; -}; \ No newline at end of file +}; From 084ed0acca0d4b799a74750efacc155babaf8ea7 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:29:18 +0200 Subject: [PATCH 44/52] cmake-build-debug.yml --- .github/workflows/cmake-single-platform.yml | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .github/workflows/cmake-single-platform.yml diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml new file mode 100644 index 0000000..10318ba --- /dev/null +++ b/.github/workflows/cmake-single-platform.yml @@ -0,0 +1,94 @@ +name: CMake Build Debug + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + job: + name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + build_type: [Debug] + c_compiler: [gcc, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: macos-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: macos-latest + c_compiler: cl + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install dependencies on Ubuntu for GLFW3 + if: runner.os == 'ubuntu-latest' + run: sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on Ubuntu for Raylib + if: runner.os == 'ubuntu-latest' + run: sudo apt install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + - name: Install dependencies on macOS for GLFW3 + if: runner.os == 'macos-latest' + run: brew install install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on macOS for Raylib + if: runner.os == 'macos-latest' + run: brew install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + # - name: Install dependencies on Windows + # if: runner.os == 'windows-latest' + # run: choco install + + - uses: lukka/get-cmake@latest + + - name: Restore from cache and setup vcpkg executable and data files. + uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: 'vcpkg.json' + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build CMake + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} From a5302c7a86833cafc8310c48eaefb4b020020ab2 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:30:54 +0200 Subject: [PATCH 45/52] Rename cmake-single-platform.yml to cmake-build-debug.yml --- .../{cmake-single-platform.yml => cmake-build-debug.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{cmake-single-platform.yml => cmake-build-debug.yml} (100%) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-build-debug.yml similarity index 100% rename from .github/workflows/cmake-single-platform.yml rename to .github/workflows/cmake-build-debug.yml From 65ce55e634218d6fa700c1be840c2fbf365f67be Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:31:33 +0200 Subject: [PATCH 46/52] Update and rename cmake-build-multi-platform.yml to cmake-build-release.yml --- ...ake-build-multi-platform.yml => cmake-build-release.yml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{cmake-build-multi-platform.yml => cmake-build-release.yml} (96%) diff --git a/.github/workflows/cmake-build-multi-platform.yml b/.github/workflows/cmake-build-release.yml similarity index 96% rename from .github/workflows/cmake-build-multi-platform.yml rename to .github/workflows/cmake-build-release.yml index ca15937..d60b1df 100644 --- a/.github/workflows/cmake-build-multi-platform.yml +++ b/.github/workflows/cmake-build-release.yml @@ -1,4 +1,4 @@ -name: CMake Build on multiple platforms +name: CMake Build Release on: push: @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - build_type: [Release, Debug] + build_type: [Release] c_compiler: [gcc, cl] include: - os: windows-latest @@ -91,4 +91,4 @@ jobs: working-directory: ${{ steps.strings.outputs.build-output-dir }} # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} \ No newline at end of file + run: ctest --build-config ${{ matrix.build_type }} From 59b66a2a8b9f05a57eb0279adc7c10292873ba1c Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:32:51 +0200 Subject: [PATCH 47/52] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e01ff24..957f8d9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[![CMake Build on multiple platforms](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-multi-platform.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-multi-platform.yml) +[![CMake Build Debug](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-debug.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-debug.yml) +[![CMake Build Release](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-release.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-release.yml) # Raycasting Engine - A Modern C++ Implementation of a DOOM Style Renderer Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. From 10d897b080fbe981594e30e16aa2e633fc3c9bc8 Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:39:55 +0200 Subject: [PATCH 48/52] Update WorldEditor.hpp --- src/Editor/WorldEditor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Editor/WorldEditor.hpp b/src/Editor/WorldEditor.hpp index 4596b73..e166433 100644 --- a/src/Editor/WorldEditor.hpp +++ b/src/Editor/WorldEditor.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include "../World.hpp" From fc19cdd0c53e5c6a44e46fe6e56ff3428673ff22 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Sun, 9 Jun 2024 14:41:42 +0200 Subject: [PATCH 49/52] Renderer : Add sector elevation Editor : Editor / Player Docker spaces dissociation Update README.md Update LICENSE Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Update README.md Create cmake-multi-platform.yml Update cmake-multi-platform.yml Update vcpkg.json Update cmake-multi-platform.yml Update raycasting-engine.code-workspace Update README.md Update README.md Update README.md Update and rename cmake-multi-platform.yml to cmake-build-multi-platform.yml Update README.md Update vcpkg submodule Update vcpkg submodule at tag 2023.10.19 Update vcpkg submodule to 2024.06.15 Update cmake-build-multi-platform.yml Create CMakePresets.json Update README.md Update cmake-build-multi-platform.yml Update vcpkg.json Update Vcpkg Update vcpkg.json Update vcpkg.json Update githubaction Update vcpkg.json Update vcpkg.json Update githubaction Update githubaction Update cicd ci CI To Compile on MacOs Vec 2 vec Update CMakeLists.txt Update WorldEditor.hpp cmake-build-debug.yml Rename cmake-single-platform.yml to cmake-build-debug.yml Update and rename cmake-build-multi-platform.yml to cmake-build-release.yml Update README.md Update WorldEditor.hpp --- .github/workflows/cmake-build-debug.yml | 94 +++++++++ .github/workflows/cmake-build-release.yml | 94 +++++++++ .vscode/raycasting-engine.code-workspace | 4 +- CMakeLists.txt | 4 +- CMakePresets.json | 65 ++++++ LICENSE | 2 +- README.md | 241 ++++++++-------------- src/DrawingHelper.hpp | 25 +++ src/Editor/WorldEditor.hpp | 118 +++++++++++ src/ImGuiStyle.hpp | 112 ++++++++++ src/MiniMapViewport.hpp | 73 +++---- src/RaycastingCamera.hpp | 143 ++++++------- src/RaycastingCameraViewport.hpp | 11 +- src/RaycastingMath.hpp | 31 +-- src/RenderingOrchestrator.hpp | 61 ++++++ src/World.cpp | 42 ++++ src/World.hpp | 31 +-- src/WorldRasterizer.cpp | 87 +++++--- src/WorldRasterizer.hpp | 16 +- src/main.cpp | 56 +++-- vcpkg | 2 +- vcpkg.json | 14 +- 22 files changed, 948 insertions(+), 378 deletions(-) create mode 100644 .github/workflows/cmake-build-debug.yml create mode 100644 .github/workflows/cmake-build-release.yml create mode 100644 CMakePresets.json create mode 100644 src/DrawingHelper.hpp create mode 100644 src/Editor/WorldEditor.hpp create mode 100644 src/ImGuiStyle.hpp create mode 100644 src/RenderingOrchestrator.hpp create mode 100644 src/World.cpp diff --git a/.github/workflows/cmake-build-debug.yml b/.github/workflows/cmake-build-debug.yml new file mode 100644 index 0000000..10318ba --- /dev/null +++ b/.github/workflows/cmake-build-debug.yml @@ -0,0 +1,94 @@ +name: CMake Build Debug + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + job: + name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + build_type: [Debug] + c_compiler: [gcc, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: macos-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: macos-latest + c_compiler: cl + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install dependencies on Ubuntu for GLFW3 + if: runner.os == 'ubuntu-latest' + run: sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on Ubuntu for Raylib + if: runner.os == 'ubuntu-latest' + run: sudo apt install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + - name: Install dependencies on macOS for GLFW3 + if: runner.os == 'macos-latest' + run: brew install install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on macOS for Raylib + if: runner.os == 'macos-latest' + run: brew install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + # - name: Install dependencies on Windows + # if: runner.os == 'windows-latest' + # run: choco install + + - uses: lukka/get-cmake@latest + + - name: Restore from cache and setup vcpkg executable and data files. + uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: 'vcpkg.json' + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build CMake + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/cmake-build-release.yml b/.github/workflows/cmake-build-release.yml new file mode 100644 index 0000000..d60b1df --- /dev/null +++ b/.github/workflows/cmake-build-release.yml @@ -0,0 +1,94 @@ +name: CMake Build Release + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + job: + name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: macos-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: macos-latest + c_compiler: cl + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Install dependencies on Ubuntu for GLFW3 + if: runner.os == 'ubuntu-latest' + run: sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on Ubuntu for Raylib + if: runner.os == 'ubuntu-latest' + run: sudo apt install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + - name: Install dependencies on macOS for GLFW3 + if: runner.os == 'macos-latest' + run: brew install install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config + + - name: Install dependencies on macOS for Raylib + if: runner.os == 'macos-latest' + run: brew install libgl1-mesa-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev + + # - name: Install dependencies on Windows + # if: runner.os == 'windows-latest' + # run: choco install + + - uses: lukka/get-cmake@latest + + - name: Restore from cache and setup vcpkg executable and data files. + uses: lukka/run-vcpkg@v11 + with: + vcpkgJsonGlob: 'vcpkg.json' + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build CMake + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} diff --git a/.vscode/raycasting-engine.code-workspace b/.vscode/raycasting-engine.code-workspace index a0694b3..675ff7c 100644 --- a/.vscode/raycasting-engine.code-workspace +++ b/.vscode/raycasting-engine.code-workspace @@ -239,6 +239,8 @@ "C_Cpp_Runner.excludeSearch": [ "**/build", "**/build/**", + "**/out", + "**/out/**", "**/.*", "**/.*/**", "**/.vscode", @@ -251,4 +253,4 @@ "C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.msvcSecureNoWarnings": false, } -} \ No newline at end of file +} diff --git a/CMakeLists.txt b/CMakeLists.txt index ed49ae7..66fe99b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cm project(raycasting-engine) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") SET(APP_TARGET_NAME raycasting-engine-app) @@ -35,4 +35,4 @@ target_include_directories(${APP_TARGET_NAME} target_link_libraries(${APP_TARGET_NAME} PRIVATE raylib PRIVATE imgui::imgui -) \ No newline at end of file +) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..8d14b09 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,65 @@ +{ + "version": 8, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "ninja-multi-vcpkg", + "displayName": "Ninja Multi-Config", + "description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations", + "binaryDir": "${sourceDir}/builds/${presetName}", + "generator": "Ninja Multi-Config", + "toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake" + } + ], + "buildPresets": [ + { + "name": "ninja-vcpkg-debug", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build (Debug)", + "description": "Build with Ninja/vcpkg (Debug)", + "configuration": "Debug" + }, + { + "name": "ninja-vcpkg-release", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build (Release)", + "description": "Build with Ninja/vcpkg (Release)", + "configuration": "Release" + }, + { + "name": "ninja-vcpkg", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build", + "description": "Build with Ninja/vcpkg" + } + ], + "testPresets": [ + { + "name": "test-ninja-vcpkg", + "configurePreset": "ninja-multi-vcpkg", + "hidden": true + }, + { + "name": "test-debug", + "description": "Test (Debug)", + "displayName": "Test (Debug)", + "configuration": "Debug", + "inherits": [ + "test-ninja-vcpkg" + ] + }, + { + "name": "test-release", + "description": "Test (Release)", + "displayName": "Test (Release)", + "configuration": "Release", + "inherits": [ + "test-ninja-vcpkg" + ] + } + ] +} diff --git a/LICENSE b/LICENSE index 674cee3..a8f806d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 P0ulpy +Copyright (c) 2024 P0ulpy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8b5602c..957f8d9 100644 --- a/README.md +++ b/README.md @@ -1,200 +1,133 @@ -# Cmake & vcpkg template +[![CMake Build Debug](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-debug.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-debug.yml) +[![CMake Build Release](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-release.yml/badge.svg)](https://github.com/P0ulpy/raycasting-engine/actions/workflows/cmake-build-release.yml) +# Raycasting Engine - A Modern C++ Implementation of a DOOM Style Renderer -This is a template repository made to quickly set up a project using cmake & vcpkg. -I usually use Clion as IDE so this repository have a basic .idea configuration +Welcome to the Raycasting Engine project, an implementation of a DOOM Style renderer using modern C++ and technologies like raylib and imgui. -You can change the name of the project in the `CMakeLists.txt` and `vcpkg.json` files. +This project is developed in a **recreational programming** context, it does not aim to be *production ready* at some point. It serves as a learning experience to explore new concepts and technologies while creating a project around them. -## Bootstrap workspace +## Goals +The primary goal of this project is to implement a DOOM Style Renderer with a simple Engine around it and a Graphical Editor for prototyping Maps, rendering, gameplay etc... I'm using modern C++ and technologies like raylib and imgui it achieve this goal. At the end the engine should be able to build and ship a standalone executable without prototyping tools. -*Windows* +## Showcase -Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) +![Overall Showcase](.github/videos/overall_showcase.mp4) +![3D View View](.github/images/3D_view.png) +![Map Editor View](.github/images/map_editor_view.png) -Then run the bootstrap script -```bat -.\scripts\bootstrap-workspace.bat -``` +## Features checklist -*GNU/Linux using apt* +For now the project in a prototyping phase, still mainly focused in making an efficient Renderer. -Install necessary build tools and a C/C++ compiler -```sh -sudo apt-get update -sudo apt-get install build-essential tar curl zip unzip autoconf libtool g++ gcc -``` +*Renderer* +- [x] DOOM Style rendering including : + - [x] Sectors and top/bottom Elevation + - [x] Neighbouring sectors sides + - [ ] Textures for Wall & Borders +- [x] Pitch and Yaw for camera movement +- [ ] Vignette for sprites rendered over walls +- [ ] Entities sprites within the 3D space +- [ ] Basic Physics including : + - [x] Elevation related to sectors + - [ ] Simple gravity + - [ ] 3D space Raycast +- [x] Simple shading using far plane distance +- [ ] Dynamic lighting for light sources -Then run the bootstrap script -```sh -./scripts/bootstrap-workspace.sh -``` +*Editor* +- [x] 3D View +- [x] Simple inspector for Global world objects (Physics, Camera, etc...) +- [ ] Rendering Debugger including : + - [ ] Step by step rendering + - [ ] Rendering steps visalizer + - [ ] Map Editor including : + - [~] Sector Editor + - [ ] Vignet editor + - [ ] Sprite editor + - [ ] Texture Browser -Well done your repo is now ready to work with cmake and vcpkg ! +*System* +- [ ] Project instance cration : being able to create a project witch is using the engine and editor in one click +- [ ] Project shiping including : + - [ ] Release Build + - [ ] Assets bundle -## Add dependency +## Building the project from sources -You can add any vcpkg dependencies by editing `vcpkg.json` and then add them to you cmake target with `find_package()` and `target_link_libraries()`. You can found more information about cmake integration in the [vcpkg documentation](https://learn.microsoft.com/vcpkg/users/buildsystems/cmake-integration#using-libraries) +This repo toolchain as been created using my [cmake and vcpkg template](https://github.com/P0ulpy/cmake-vcpkg-template). -You can found a exemple of adding dependencies in the [Installing dependencies exemple with SFML](#adding-dependencies-exemple-with-sfml-) section. +### Bootstrap workspace -## Generate your project +`Windows :` -Running `generate-cmake-*.sh` will install dependencies if required and then generate your cmake solution. +Make sure you installed [Visual Studio](https://visualstudio.microsoft.com/) with [C and C++ support](https://learn.microsoft.com/cpp/build/vscpp-step-0-installation?view=msvc-170#step-4---choose-workloads) and [C++ linux development with cmake](https://learn.microsoft.com/cpp/linux/download-install-and-setup-the-linux-development-workload?view=msvc-170#visual-studio-setup). +Make sure you installed [CMake](https://cmake.org/download) as well. -Use it every times you add a dependency or modify `CMakeLists.txt` +`GNU/Linux (apt) :` -*Windows* +Install necessary build tools and a C/C++ compiler ```sh -# For debug build -.\scripts\generate-cmake-debug.bat -# For release build -.\scripts\generate-cmake-release.bat +sudo apt-get update +sudo apt-get install cmake build-essential tar curl zip unzip autoconf libtool g++ gcc ``` -*Unix* +Then run the bootstrap script ```sh -# For debug build -./scripts/generate-cmake-debug.sh -# For release build -./scripts/generate-cmake-release.sh +# Unix +./scripts/bootstrap-workspace.sh +# Windows +.\scripts\bootstrap-workspace.bat ``` -## Compile your project - -Cmake will atomatically detect your compiler and generator +*Generate the project :* -*Windows* ```sh # For debug build -.\scripts\build-debug.bat +# Unix +./scripts/generate-cmake-debug.sh +# Windows +.\scripts\generate-cmake-debug.bat + # For release build -.\scripts\build-release.bat +# Unix +./scripts/generate-cmake-release.sh +# Windows +.\scripts\generate-cmake-release.bat ``` -*Unix* +*Compile the project :* + ```bash # For debug build +# Unix ./scripts/build-debug.sh +# Windows +.\scripts\build-debug.bat + # For release build +# Unix ./scripts/build-release.sh +# Windows +.\scripts\build-release.bat ``` -**Run your program** +**Run the program** You can now run the compiled program by looking into `out/Debug` or `out/Release`. The out directory hierarchy will be different depending on your generator. For exemple with Make generator in Debug mode run your program like that ```bash -# The executable name will change acording to the value set in add_executable(, ...) -./out/Debug/cmake-vcpkg-template-app -``` - -## Adding dependencies exemple with SFML : - -In this exemple we will add SFML to our project, make it available in our cmake target and then compile a basic exemple program. - -**Add dependencies to vcpkg :** - -`vcpkg.json` -```json -{ - "name": "cmake-vcpkg-template", - "version": "0.1.0", - "builtin-baseline": "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98", - "dependencies": [ - { - "name" : "sfml", - "version>=" : "2.5.1#14" - } - ] -} -``` - -For further information you can check the [microsoft documentation about vcpkg.json](https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json) and [vcpkg documentation about manifests dependencies](https://learn.microsoft.com/vcpkg/concepts/manifest-mode) - -**Add dependencies to your cmake target :** - -Now that we have added our dependencies to vcpkg we can add them to our cmake target. -First we use `find_package()` to find the package in vcpkg, then we use `target_link_libraries()` to link it to our target, It is important to call it after the target creation (witch is `add_executable` in our case). - -`CMakeLists.txt` -```diff -... -+ find_package(SFML COMPONENTS system window graphics network CONFIG REQUIRED) - -SET(EXECUTABLE_TARGET_NAME cmake-vcpkg-template-app) - -add_executable(${EXECUTABLE_TARGET_NAME} - main.cpp -) - -+ target_link_libraries(${EXECUTABLE_TARGET_NAME} -+ PRIVATE sfml-system sfml-network sfml-graphics sfml-window -+ ) -... +# Unix +./out/Debug/raycasting-engine +# Windows +.\out\Debug\raycasting-engine.exe ``` -You must reload your cmake project and reset cache in your IDE or directly with the cmake command to make it work. -```sh -./scripts/generate-cmake-debug.sh -``` - -**In case of issues while running vcpkg install** - -Pay attention at this kind of message of vcpkg : -``` --- SFML currently requires the following libraries from the system package manager: - libudev - libx11 - libxrandr - libxcursor - opengl -You can intall them in your system using apt-get install libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev -``` +**Using Visual Studio Code workspace** -Most of the time install issues with vcpkg are related to a dynamic library who are not installed in you system. Most of the time vcpkg explain directly how to install them. +If you are using visual studio code you can directly use the project embeded workspace `.vscode/raycasting-engine.code-workspace`. +You can press `F5` to build and run with debugger gdb or vsdbg (visual studio debugger). -**Use SFML in our program to make sure our installation is working :** +## Licence -For this exemple we will use the [SFML tutorial](https://www.sfml-dev.org/tutorials/2.6/start-linux.php#compiling-a-sfml-program) to make sure our installation is working. -After pasting the exemple code in your `main.cpp` we can now compile our program and run it, you should see a window with a green circle in it and a title "SFML works!". - -Congratulations you have successfully installed SFML in your project ! -You can now add any other dependencies you want. - -**To go deaper into cmake integration using vcpkg you can start by the** [microsoft documentation for cmake integration using libraries](https://learn.microsoft.com/vcpkg/users/buildsystems/cmake-integration#using-libraries) - -## Misc. - -### Vcpkg triplets - -You can found more information about the vcpkg triplets in the [vcpkg documentation about triplets](https://learn.microsoft.com/fr-fr/vcpkg/users/triplets) - -### Updating vcpkg submodule - -If you need to update vcpkg or you encounter issues with it you can update the vcpkg submodule with : -```bash -git submodule update --remote -``` - -After finished it should write in stdout something like : -``` -Submodule path 'vcpkg': checked out '' -``` - -Update the builtin-baseline in `vcpkg.json` -```diff -{ - "name" : "cmake-vcpkg-template", - "version" : "0.1.0", -- "builtin-baseline" : "4874bea8eb8db9e6610672cccdd6ccd5d55c6f1a", -+ "builtin-baseline" : , - "dependencies" : [] -} -``` - -And then commit the modification -```bash -git add . -git commit -m "Update vcpkg to it lastest version" -``` +This project is open-source and available under the [MIT Licence](LICENSE). diff --git a/src/DrawingHelper.hpp b/src/DrawingHelper.hpp new file mode 100644 index 0000000..841cdfb --- /dev/null +++ b/src/DrawingHelper.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +#include "RaycastingMath.hpp" + +void DrawSectorAsPolygon(const Sector& sector, Color color); +// { +// if (sector.walls.size() < 3) +// { +// return; // Not a polygon +// } + +// Vector2 firstPoint = sector.walls[0].segment.a; + +// for (size_t i = 1; i < sector.walls.size() - 1; ++i) +// { +// Vector2 secondPoint = sector.walls[i].segment.a; +// Vector2 thirdPoint = sector.walls[i + 1].segment.a; + +// DrawTriangle(firstPoint, secondPoint, thirdPoint, color); +// } +// } \ No newline at end of file diff --git a/src/Editor/WorldEditor.hpp b/src/Editor/WorldEditor.hpp new file mode 100644 index 0000000..e166433 --- /dev/null +++ b/src/Editor/WorldEditor.hpp @@ -0,0 +1,118 @@ +#pragma once + +#include +#include +#include +#include + +#include "../World.hpp" +#include "../RaycastingCamera.hpp" + +class WorldEditor +{ +public: + WorldEditor(World& world) + : world(world) + , renderTexture(LoadRenderTexture(1920, 1080)) + {} + + ~WorldEditor() + { + UnloadRenderTexture(renderTexture); + } + + void ResizeRenderTextureSize(int width, int height) + { + UnloadRenderTexture(renderTexture); + renderTexture = LoadRenderTexture(width, height); + } + + void DrawGUI() + { + + + + + + + + + + + + { + ImGui::Begin("World Editor"); + ImGuiID worldEditorDockerSpace = ImGui::GetID("worldEditorDockerSpace"); + ImGui::DockSpace(worldEditorDockerSpace); + ImGui::End(); + + ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); + ImGui::Begin("Sectors"); + + ImGui::Text("salut"); + + ImGui::End(); + + ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + // ImGui::SetNextWindowSizeConstraints(ImVec2(renderTexture.texture.width, renderTexture.texture.height), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); + + if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar)) + { + // ImVec2 windowSize = ImGui::GetWindowSize(); + // if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) + // { + // ResizeRenderTextureSize(windowSize.x, windowSize.y); + // } + + // rlImGuiImageRenderTextureFit(&renderTexture, true); + } + ImGui::End(); + + // ImGui::PopStyleVar(); + } + + + + + + // ImGui::Begin("World Editor", nullptr, ImGuiWindowFlags_DockNodeHost); + + // ImGui::Begin("Sectors"); + // ImGui::Text("salut"); + // ImGui::End(); + + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + // ImGui::SetNextWindowSizeConstraints(ImVec2(renderTexture.texture.width, renderTexture.texture.height), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); + + // if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar)) + // { + // ImVec2 windowSize = ImGui::GetWindowSize(); + // if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) + // { + // ResizeRenderTextureSize(windowSize.x, windowSize.y); + // } + + // rlImGuiImageRenderTextureFit(&renderTexture, true); + // } + // ImGui::End(); + + // ImGui::PopStyleVar(); + + // ImGui::End(); + } + + void Render(RaycastingCamera& cam) + { + + } + + void Update(float dt) + { + + } + +private: + World& world; + RenderTexture2D renderTexture; +}; diff --git a/src/ImGuiStyle.hpp b/src/ImGuiStyle.hpp new file mode 100644 index 0000000..48bb982 --- /dev/null +++ b/src/ImGuiStyle.hpp @@ -0,0 +1,112 @@ +#pragma once + +#include + +void SetupImGuiStyle() +{ + // Fork of Unreal style from ImThemes + ImGuiStyle& style = ImGui::GetStyle(); + + style.Alpha = 1.0f; + style.DisabledAlpha = 0.6000000238418579f; + style.WindowPadding = ImVec2(8.0f, 8.0f); + style.WindowRounding = 0.0f; + style.WindowBorderSize = 1.0f; + style.WindowMinSize = ImVec2(32.0f, 32.0f); + style.WindowTitleAlign = ImVec2(0.0f, 0.5f); + style.WindowMenuButtonPosition = ImGuiDir_Left; + style.ChildRounding = 0.0f; + style.ChildBorderSize = 1.0f; + style.PopupRounding = 0.0f; + style.PopupBorderSize = 1.0f; + style.FramePadding = ImVec2(4.0f, 3.0f); + style.FrameRounding = 0.0f; + style.FrameBorderSize = 0.0f; + style.ItemSpacing = ImVec2(8.0f, 4.0f); + style.ItemInnerSpacing = ImVec2(4.0f, 4.0f); + style.CellPadding = ImVec2(4.0f, 2.0f); + style.IndentSpacing = 21.0f; + style.ColumnsMinSpacing = 6.0f; + style.ScrollbarSize = 14.0f; + style.ScrollbarRounding = 9.0f; + style.GrabMinSize = 10.0f; + style.GrabRounding = 0.0f; + style.TabRounding = 4.0f; + style.TabBorderSize = 0.0f; + style.TabMinWidthForCloseButton = 0.0f; + style.ColorButtonPosition = ImGuiDir_Right; + style.ButtonTextAlign = ImVec2(0.5f, 0.5f); + style.SelectableTextAlign = ImVec2(0.0f, 0.0f); + + style.TouchExtraPadding = ImVec2(0.00f, 0.00f); + style.LogSliderDeadzone = 4; + style.FramePadding = ImVec2(5.00f, 2.00f); + style.CellPadding = ImVec2(6.00f, 6.00f); + style.ItemSpacing = ImVec2(6.00f, 6.00f); + style.ItemInnerSpacing = ImVec2(6.00f, 6.00f); + style.IndentSpacing = 25; + style.ScrollbarSize = 15; + style.GrabMinSize = 10; + style.TabBorderSize = 1; + style.WindowRounding = 6; + style.ChildRounding = 3; + style.FrameRounding = 2; + style.PopupRounding = 3; + style.ScrollbarRounding = 7; + style.GrabRounding = 3; + style.TabRounding = 3; + + style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.4980392158031464f, 0.4980392158031464f, 0.4980392158031464f, 1.0f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.05882352963089943f, 0.05882352963089943f, 0.05882352963089943f, 0.9399999976158142f); + style.Colors[ImGuiCol_ChildBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.0f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.0784313753247261f, 0.0784313753247261f, 0.0784313753247261f, 0.9399999976158142f); + style.Colors[ImGuiCol_Border] = ImVec4(0.4274509847164154f, 0.4274509847164154f, 0.4980392158031464f, 0.5f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.2000000029802322f, 0.2078431397676468f, 0.2196078449487686f, 0.5400000214576721f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.4000000059604645f, 0.4000000059604645f, 0.4000000059604645f, 0.4000000059604645f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.1764705926179886f, 0.1764705926179886f, 0.1764705926179886f, 0.6700000166893005f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.03921568766236305f, 0.03921568766236305f, 0.03921568766236305f, 1.0f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.2862745225429535f, 0.2862745225429535f, 0.2862745225429535f, 1.0f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.0f, 0.0f, 0.5099999904632568f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.1372549086809158f, 0.1372549086809158f, 0.1372549086809158f, 1.0f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.01960784383118153f, 0.01960784383118153f, 0.01960784383118153f, 0.5299999713897705f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3098039329051971f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.407843142747879f, 0.407843142747879f, 0.407843142747879f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.5098039507865906f, 0.5098039507865906f, 0.5098039507865906f, 1.0f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.9372549057006836f, 0.9372549057006836f, 0.9372549057006836f, 1.0f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.5098039507865906f, 0.5098039507865906f, 0.5098039507865906f, 1.0f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.8588235378265381f, 0.8588235378265381f, 0.8588235378265381f, 1.0f); + style.Colors[ImGuiCol_Button] = ImVec4(0.4392156898975372f, 0.4392156898975372f, 0.4392156898975372f, 0.4000000059604645f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.4588235318660736f, 0.4666666686534882f, 0.47843137383461f, 1.0f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.4196078479290009f, 0.4196078479290009f, 0.4196078479290009f, 1.0f); + style.Colors[ImGuiCol_Header] = ImVec4(0.6980392336845398f, 0.6980392336845398f, 0.6980392336845398f, 0.3100000023841858f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.6980392336845398f, 0.6980392336845398f, 0.6980392336845398f, 0.800000011920929f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.47843137383461f, 0.4980392158031464f, 0.5176470875740051f, 1.0f); + style.Colors[ImGuiCol_Separator] = ImVec4(0.4274509847164154f, 0.4274509847164154f, 0.4980392158031464f, 0.5f); + style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.7176470756530762f, 0.7176470756530762f, 0.7176470756530762f, 0.7799999713897705f); + style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.5098039507865906f, 0.5098039507865906f, 0.5098039507865906f, 1.0f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.9098039269447327f, 0.9098039269447327f, 0.9098039269447327f, 0.25f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.8078431487083435f, 0.8078431487083435f, 0.8078431487083435f, 0.6700000166893005f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.4588235318660736f, 0.4588235318660736f, 0.4588235318660736f, 0.949999988079071f); + style.Colors[ImGuiCol_Tab] = ImVec4(0.1764705926179886f, 0.3490196168422699f, 0.5764706134796143f, 0.8619999885559082f); + style.Colors[ImGuiCol_TabHovered] = ImVec4(0.2588235437870026f, 0.5882353186607361f, 0.9764705896377563f, 0.800000011920929f); + style.Colors[ImGuiCol_TabActive] = ImVec4(0.196078434586525f, 0.407843142747879f, 0.6784313917160034f, 1.0f); + style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.06666667014360428f, 0.1019607856869698f, 0.1450980454683304f, 0.9724000096321106f); + style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.1333333402872086f, 0.2588235437870026f, 0.4235294163227081f, 1.0f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(0.6078431606292725f, 0.6078431606292725f, 0.6078431606292725f, 1.0f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 0.4274509847164154f, 0.3490196168422699f, 1.0f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.729411780834198f, 0.6000000238418579f, 0.1490196138620377f, 1.0f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 0.6000000238418579f, 0.0f, 1.0f); + style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.2000000029802322f, 1.0f); + style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3490196168422699f, 1.0f); + style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832f, 0.2274509817361832f, 0.2470588237047195f, 1.0f); + style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.8666666746139526f, 0.8666666746139526f, 0.8666666746139526f, 0.3499999940395355f); + style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.0f, 1.0f, 0.0f, 0.8999999761581421f); + style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.6000000238418579f, 0.6000000238418579f, 0.6000000238418579f, 1.0f); + style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.699999988079071f); + style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.2000000029802322f); + style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.3499999940395355f); +} \ No newline at end of file diff --git a/src/MiniMapViewport.hpp b/src/MiniMapViewport.hpp index 499dabc..d3e737f 100644 --- a/src/MiniMapViewport.hpp +++ b/src/MiniMapViewport.hpp @@ -8,6 +8,7 @@ #include "World.hpp" #include "RaycastingCamera.hpp" +#include "DrawingHelper.hpp" class MiniMapViewport { @@ -16,6 +17,39 @@ class MiniMapViewport : renderTexture(LoadRenderTexture(width, height)) {} + void Render(World& world, RaycastingCamera& cam) + { + Camera2D minimapCamera = { 0 }; + minimapCamera.target = cam.position; + minimapCamera.offset = { (float)renderTexture.texture.width / 2, (float)renderTexture.texture.height / 2 }; + minimapCamera.rotation = 0.0f; + minimapCamera.zoom = zoom; + + BeginTextureMode(renderTexture); + + BeginMode2D(minimapCamera); + + ClearBackground(LIGHTGRAY); + + Vector2 camHeadingDirectionPoint = Vector2Add(cam.position, Vector2Scale(cam.Forward(), 50)); + DrawLineV(cam.position, camHeadingDirectionPoint, RED); + DrawCircleV(cam.position, 10, GREEN); + + for(const auto& [ sectorId, sector ] : world.Sectors) + { + // DrawSectorAsPolygon(sector, BLUE); + + for(const auto& wall : sector.walls) + { + DrawLineV(wall.segment.a, wall.segment.b, wall.color); + } + } + + EndMode2D(); + + EndTextureMode(); + } + void DrawGUI() { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 5)); @@ -31,13 +65,13 @@ class MiniMapViewport } rlImGuiImageRenderTextureFit(&renderTexture, true); - - ImGui::End(); } + ImGui::End(); ImGui::PopStyleVar(); } +public: RenderTexture2D& GetRendertexture() { return renderTexture; } float GetZoom() const { return zoom; } @@ -45,36 +79,5 @@ class MiniMapViewport RenderTexture2D renderTexture { 0 }; bool focused = false; - float zoom = 1.f; -}; - -void RenderMinimap(RenderTexture2D& targetTexture, World& world, RaycastingCamera& cam, float zoom) -{ - Camera2D minimapCamera = { 0 }; - minimapCamera.target = cam.position; - minimapCamera.offset = { (float)targetTexture.texture.width / 2, (float)targetTexture.texture.height / 2 }; - minimapCamera.rotation = 0.0f; - minimapCamera.zoom = zoom; - - BeginTextureMode(targetTexture); - - BeginMode2D(minimapCamera); - - ClearBackground(LIGHTGRAY); - - Vector2 camHeadingDirectionPoint = Vector2Add(cam.position, Vector2Scale(cam.Forward(), 50)); - DrawLineV(cam.position, camHeadingDirectionPoint, RED); - DrawCircleV(cam.position, 10, GREEN); - - for(const auto& [ key, sector ] : world.Sectors) - { - for(const auto& wall : sector.walls) - { - DrawLineV(wall.segment.a, wall.segment.b, wall.color); - } - } - - EndMode2D(); - - EndTextureMode(); -} \ No newline at end of file + float zoom = 0.3f; +}; \ No newline at end of file diff --git a/src/RaycastingCamera.hpp b/src/RaycastingCamera.hpp index b2928db..5ed3b43 100644 --- a/src/RaycastingCamera.hpp +++ b/src/RaycastingCamera.hpp @@ -22,7 +22,7 @@ struct RaycastingCamera size_t maxRenderItr { 25 }; - uint32_t currentSector = 1; + uint32_t currentSectorId = 1; RaycastingCamera(Vector2 position = { 0 }) : position(position) @@ -54,10 +54,10 @@ struct RaycastingCamera { ImGui::Begin("Camera"); - ImGui::InputFloat2("position", (float*)(&position)); + ImGui::InputFloat2("position", (float*)&position); ImGui::InputFloat("z", &elevation, 0.5); - ImGui::SliderAngle("yaw", &yaw, -90, 90); - ImGui::SliderAngle("pitch", &pitch, -180, 180); + ImGui::SliderAngle("yaw", &yaw, 0, 360); + ImGui::SliderAngle("pitch", &pitch, -90, 90); ImGui::SliderFloat("FOV", &fov, 20, 180); ImGui::SliderFloat("FOV Vetical", &fovVectical, 20, 180); @@ -67,10 +67,77 @@ struct RaycastingCamera ImGui::InputInt("Max render itr", (int*)&maxRenderItr); - ImGui::InputInt("Current Sector", (int*)¤tSector); + ImGui::InputInt("Current Sector", (int*)¤tSectorId); ImGui::End(); } + + void Update(float deltaTime) + { + Vector2 moveDirection { 0 }; + + if(IsKeyDown(KEY_D)) + { + moveDirection = Vector2Add(moveDirection, Right()); + } + if(IsKeyDown(KEY_A)) + { + Vector2 left = Vector2Negate(Right()); + moveDirection = Vector2Add(moveDirection, left); + } + if(IsKeyDown(KEY_W)) + { + moveDirection = Vector2Add(moveDirection, Forward()); + } + if(IsKeyDown(KEY_S)) + { + Vector2 backward = Vector2Negate(Forward()); + moveDirection = Vector2Add(moveDirection, backward); + } + + float moveSpeed = 100.f; + + moveDirection = Vector2Normalize(moveDirection); + moveDirection = Vector2Scale(moveDirection, moveSpeed); + moveDirection = Vector2Scale(moveDirection, deltaTime); + + position = Vector2Add(position, moveDirection); + + // Up / Down + + constexpr float UpDownSpeed = 500.f; + + if(IsKeyDown(KEY_SPACE)) + { + elevation += UpDownSpeed * deltaTime; + } + if(IsKeyDown(KEY_LEFT_SHIFT)) + { + elevation -= UpDownSpeed * deltaTime; + } + + // Get the mouse delta (how much the mouse moved since the last frame) + Vector2 mouseDelta = GetMouseDelta(); + + // Scale the mouse movement by a sensitivity factor to control the speed of the rotation + constexpr float sensitivity = 0.003f; + float yawChange = mouseDelta.x * sensitivity; + float pitchChange = mouseDelta.y * sensitivity; + + // Update the camera's yaw + yaw += yawChange; + pitch += pitchChange; + + // Clamp yaw in between 0 and 2 * PI + if(yaw > 2 * PI) yaw -= 2 * PI; + if(yaw < 0) yaw += 2 * PI; + + // Clamp pitch between -(PI / 2) and PI / 2 + if(pitch > PI / 2) pitch = PI / 2; + if(pitch < -PI / 2) pitch = -PI / 2; + + SetMousePosition(GetScreenWidth() / 2, GetScreenHeight() / 2); + } }; inline float RayAngleforScreenXCam(int screenX, const RaycastingCamera& cam, uint32_t RenderTargetWidth) @@ -80,69 +147,3 @@ inline float RayAngleforScreenXCam(int screenX, const RaycastingCamera& cam, uin return angle + (fovRate * screenX); } - -inline void UpdateCamera(RaycastingCamera& cam, float deltaTime) -{ - Vector2 moveDirection { 0 }; - - if(IsKeyDown(KEY_D)) - { - moveDirection = Vector2Add(moveDirection, cam.Right()); - } - if(IsKeyDown(KEY_A)) - { - Vector2 left = Vector2Negate(cam.Right()); - moveDirection = Vector2Add(moveDirection, left); - } - if(IsKeyDown(KEY_W)) - { - moveDirection = Vector2Add(moveDirection, cam.Forward()); - } - if(IsKeyDown(KEY_S)) - { - Vector2 backward = Vector2Negate(cam.Forward()); - moveDirection = Vector2Add(moveDirection, backward); - } - - float moveSpeed = 100.f; - - moveDirection = Vector2Normalize(moveDirection); - moveDirection = Vector2Scale(moveDirection, moveSpeed); - moveDirection = Vector2Scale(moveDirection, deltaTime); - - cam.position = Vector2Add(cam.position, moveDirection); - - // Up / Down - - constexpr float UpDownSpeed = 500.f; - - if(IsKeyDown(KEY_SPACE)) - { - cam.elevation += UpDownSpeed * deltaTime; - } - if(IsKeyDown(KEY_LEFT_SHIFT)) - { - cam.elevation -= UpDownSpeed * deltaTime; - } - - // Get the mouse delta (how much the mouse moved since the last frame) - Vector2 mouseDelta = GetMouseDelta(); - - // Scale the mouse movement by a sensitivity factor to control the speed of the rotation - constexpr float sensitivity = 0.003f; - float yawChange = mouseDelta.x * sensitivity; - float pitchChange = mouseDelta.y * sensitivity; - - // Update the camera's yaw - cam.yaw += yawChange; - cam.pitch += pitchChange; - - // Clamp yaw in between 0 and 2 * PI - if(cam.yaw > 2 * PI) cam.yaw -= 2 * PI; - if(cam.yaw < 0) cam.yaw += 2 * PI; - - // Clamp pitch between -(PI / 2) and PI / 2 - if(cam.pitch > PI / 2) cam.pitch = PI / 2; - if(cam.pitch < -PI / 2) cam.pitch = -PI / 2; - -} diff --git a/src/RaycastingCameraViewport.hpp b/src/RaycastingCameraViewport.hpp index 7aa3fb5..1adc16b 100644 --- a/src/RaycastingCameraViewport.hpp +++ b/src/RaycastingCameraViewport.hpp @@ -18,7 +18,7 @@ class RaycastingCameraViewport UnloadRenderTexture(renderTexture); } - void UpdateRenderTextureSize(int width, int height) + void ResizeRenderTextureSize(int width, int height) { UnloadRenderTexture(renderTexture); renderTexture = LoadRenderTexture(width, height); @@ -38,7 +38,7 @@ class RaycastingCameraViewport ImVec2 windowSize = ImGui::GetWindowSize(); if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) { - UpdateRenderTextureSize(windowSize.x, windowSize.y); + ResizeRenderTextureSize(windowSize.x, windowSize.y); } } @@ -47,6 +47,7 @@ class RaycastingCameraViewport rlImGuiImageRenderTextureFit(&renderTexture, true); } ImGui::End(); + ImGui::PopStyleVar(); } @@ -66,12 +67,12 @@ class RaycastingCameraViewport { if(ImGui::MenuItem("1920x1080 (16:9)")) { - UpdateRenderTextureSize(1920, 1080); + ResizeRenderTextureSize(1920, 1080); autoResize = false; } if(ImGui::MenuItem("720x480 (4:3)")) { - UpdateRenderTextureSize(720, 480); + ResizeRenderTextureSize(720, 480); autoResize = false; } if(ImGui::MenuItem("Fit to window size")) @@ -79,7 +80,7 @@ class RaycastingCameraViewport ImVec2 windowSize = ImGui::GetWindowSize(); if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) { - UpdateRenderTextureSize(windowSize.x, windowSize.y); + ResizeRenderTextureSize(windowSize.x, windowSize.y); } autoResize = true; diff --git a/src/RaycastingMath.hpp b/src/RaycastingMath.hpp index 59f0e74..0a6a534 100644 --- a/src/RaycastingMath.hpp +++ b/src/RaycastingMath.hpp @@ -11,18 +11,6 @@ #include "ColorHelper.hpp" -struct Vector2i -{ - int x { 0 }; - int y { 0 }; -}; - -struct Vector2ui -{ - unsigned int x { 0 }; - unsigned int y { 0 }; -}; - inline Vector2 Vector2DirectionFromAngle(float angleRadian, float length = 1) { return { @@ -140,9 +128,10 @@ inline constexpr float PointSegmentSide(Vector2 point, Vector2 a, Vector2 b) return -(((point.x - a.x) * (b.y - a.y)) - ((point.y - a.y) * (b.x - a.x))); } -inline Vector2 InsidePoint(const std::vector& walls) +inline Vector2 FindInsidePoint(const std::vector& walls) { - Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), Vector2(0, 0), + Vector2 startAt = { 0 }; + Vector2 insidePoint = std::accumulate(walls.begin(), walls.end(), startAt, [](const Vector2& a, const Wall& b) { return Vector2Add(a, b.segment.a); }); float wallsSize = static_cast(walls.size()); @@ -154,19 +143,7 @@ inline Vector2 InsidePoint(const std::vector& walls) inline bool IsPointInSector(Vector2 point, const Sector& sector) { - std::vector walls(sector.walls); - - // Find a point inside the sector - Vector2 insidePoint = InsidePoint(walls); - - // Order the wall segments based on the angle they make with the inside point - std::sort(walls.begin(), walls.end(), - [insidePoint](const Wall& a, const Wall& b) - { - float angleA = std::atan2(a.segment.a.y - insidePoint.y, a.segment.a.x - insidePoint.x); - float angleB = std::atan2(b.segment.a.y - insidePoint.y, b.segment.a.x - insidePoint.x); - return angleA < angleB; - }); + const std::vector& walls = sector.walls; // Use the ray casting algorithm bool inside = false; diff --git a/src/RenderingOrchestrator.hpp b/src/RenderingOrchestrator.hpp new file mode 100644 index 0000000..097c4bc --- /dev/null +++ b/src/RenderingOrchestrator.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include + +#include "RaycastingCameraViewport.hpp" + +class RenderingOrchestrator +{ +public: + RenderingOrchestrator(RaycastingCameraViewport& cameraViewport) + : cameraViewport(cameraViewport) + {} + + void Render(World &world, RaycastingCamera &cam) + { + if(play) + { + RasterizeWorldInTexture(cameraViewport.GetRenderTexture(), world, cam); + } + else + { + RenderStepByStep(); + } + } + void RenderStepByStep() + { + /// ... + } + + void DrawGUI() + { + ImGui::Begin("Rendering"); + + if(ImGui::Button("Play")) + { + play = true; + } + ImGui::SameLine(); + if(ImGui::Button("Pause")) + { + play = false; + } + ImGui::SameLine(); + if(ImGui::Button(">> Step") && !play) + { + + } + + // *** + // Display renderStack step by step + // *** + + ImGui::End(); + } + +private: + bool play = true; + + RaycastingCameraViewport& cameraViewport; +}; + diff --git a/src/World.cpp b/src/World.cpp new file mode 100644 index 0000000..0cf007a --- /dev/null +++ b/src/World.cpp @@ -0,0 +1,42 @@ +#include "World.hpp" + +World::World() +{ + InitWorld(); +} + +void World::InitWorld() +{ + for(auto& [ sectorId, sector ] : Sectors) + { + RearrangeWallListToPolygon(sector.walls); + } +} + +void RearrangeWallListToPolygon(std::vector &walls) +{ + // Find a point inside the sector + Vector2 insidePoint = FindInsidePoint(walls); + + // Order the wall segments based on the angle they make with the inside point + std::sort(walls.begin(), walls.end(), + [insidePoint](const Wall& a, const Wall& b) + { + float angleA = std::atan2(a.segment.a.y - insidePoint.y, a.segment.a.x - insidePoint.x); + float angleB = std::atan2(b.segment.a.y - insidePoint.y, b.segment.a.x - insidePoint.x); + return angleA < angleB; + }); +} + +uint32_t FindSectorOfPoint(Vector2 point, const World &world) +{ + for(const auto& [ sectorId, sector ] : world.Sectors) + { + if(IsPointInSector(point, sector)) + { + return sectorId; + } + } + + return NULL_SECTOR; +} \ No newline at end of file diff --git a/src/World.hpp b/src/World.hpp index 8e8df0e..3561866 100644 --- a/src/World.hpp +++ b/src/World.hpp @@ -6,6 +6,8 @@ struct World { + World(); + std::unordered_map Sectors = { { @@ -14,8 +16,7 @@ struct World .walls = { { .segment = { { 500, 600 }, { 500, 700 } }, - .toSector = 1U, - .color = PURPLE, + .toSector = 1U }, { .segment = { { 500, 600 }, { 300, 600 } }, @@ -52,8 +53,7 @@ struct World }, { .segment = { { 500, 500 }, { 700, 700 } }, - .toSector = 2U, - .color = PURPLE, + .toSector = 2U }, } }, @@ -72,28 +72,19 @@ struct World }, { .segment = { { 700, 700 }, { 500, 500 } }, - .toSector = 1U, - .color = PURPLE, + .toSector = 1U }, }, - .floorColor = BLUE, - .ceilingColor = RED, + .floorColor = RED, + .ceilingColor = BLUE, .zCeiling = 0.60f, .zFloor = 0.75f, }, }, }; -}; -inline uint32_t FindSectorOfPoint(Vector2 point, const World& world) -{ - for(const auto& [ sectorId, sector ] : world.Sectors) - { - if(IsPointInSector(point, sector)) - { - return sectorId; - } - } + void InitWorld(); +}; - return NULL_SECTOR; -} \ No newline at end of file +void RearrangeWallListToPolygon(std::vector& walls); +uint32_t FindSectorOfPoint(Vector2 point, const World& world); \ No newline at end of file diff --git a/src/WorldRasterizer.cpp b/src/WorldRasterizer.cpp index b9abae0..f88f145 100644 --- a/src/WorldRasterizer.cpp +++ b/src/WorldRasterizer.cpp @@ -6,17 +6,17 @@ #include #include #include +#include RasterizeWorldContext InitRasterizeWorldContext(uint32_t RenderTargetWidth, uint32_t RenderTargetHeight, const World& world, const RaycastingCamera& cam) { - float FloorVerticalOffset = round(0.5f * RenderTargetHeight * (tanf(cam.pitch)) / tanf(0.5f * cam.fovVectical)); - RasterizeWorldContext context = { .world = world, .cam = cam, .RenderTargetWidth = RenderTargetWidth, .RenderTargetHeight = RenderTargetHeight, - .FloorVerticalOffset = FloorVerticalOffset, + .FloorVerticalOffset = ComputeVerticalOffset(cam, RenderTargetHeight), + .CamCurrentSectorElevationOffset = ComputeElevationOffset(cam, world, RenderTargetHeight), }; context.yBoundaries.resize(RenderTargetWidth); @@ -27,10 +27,10 @@ RasterizeWorldContext InitRasterizeWorldContext(uint32_t RenderTargetWidth, uint bound.min = 0; } - assert(world.Sectors.contains(cam.currentSector), "Try to InitRasterizeWorldContext with an invalid SectorID"); + // assert(world.Sectors.contains(cam.currentSector), "Try to InitRasterizeWorldContext with an invalid SectorID"); context.renderStack.push({ - .sectorId = cam.currentSector, + .sectorId = cam.currentSectorId, .renderArea = { .xBegin = 0, .xEnd = RenderTargetWidth - 1, @@ -58,15 +58,15 @@ void RasterizeWorld(uint32_t RenderTargetWidth, uint32_t RenderTargetHeight, con ++i ) { - RasterizeInRenderArea(rasterizeContext, rasterizeContext.renderStack.top()); + RasterizeInRenderArea(rasterizeContext, rasterizeContext.renderStack.top(), RenderNextAreaBorders); } } -void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderContext renderContext) +void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderContext renderContext, RenderNextAreaBordersCallback renderNextAreaBordersCallback) { std::unordered_map renderAreaToPushInStack; - auto& [ world, cam, RenderTargetWidth, RenderTargetHeight, FloorVerticalOffset, yBoundaries, renderStack ] = worldContext; + auto& [ world, cam, RenderTargetWidth, RenderTargetHeight, FloorVerticalOffset, CamCurrentSectorElevationOffset, yBoundaries, renderStack ] = worldContext; const auto& [ sectorId, renderArea ] = renderContext; const Sector& currentSector = world.Sectors.at(sectorId); @@ -108,19 +108,21 @@ void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderCont if(bestHitData.distance < std::numeric_limits::max()) { + // Floor / ceiling rendering { // Draw floor - float centerY = (RenderTargetHeight / 2) - FloorVerticalOffset; + float centerY = ((RenderTargetHeight / 2) - FloorVerticalOffset) + CamCurrentSectorElevationOffset; DrawLine(x, yMinMax.min, x, centerY, currentSector.ceilingColor); // Draw Ceiling DrawLine(x, centerY, x, yMinMax.max, currentSector.floorColor); } - + // Means this is a slid wall if(bestHitData.wall->toSector == NULL_SECTOR) { CameraYLineData cameraWallYData = - ComputeCameraYAxis(cam, x, bestHitData.distance, FloorVerticalOffset, + ComputeCameraYAxis(cam, x, bestHitData.distance, + FloorVerticalOffset, CamCurrentSectorElevationOffset, RenderTargetWidth, RenderTargetHeight, yMinMax.max, yMinMax.min, @@ -131,16 +133,12 @@ void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderCont } else { - if(!world.Sectors.contains(bestHitData.wall->toSector)) - { - std::cerr << "Try to render a next sector with an invalid SectorID (" << bestHitData.wall->toSector << ")"<< std::endl; - continue; - } + // assert(world.Sectors.contains(bestHitData.wall->toSector), "Try to render a next sector with an invalid SectorID"); const SectorID nextSectorId = bestHitData.wall->toSector; const Sector& nextSector = world.Sectors.at(nextSectorId); - RenderNextRenderAreaBorders(worldContext, yMinMax, currentSector, nextSector, x, bestHitData.distance); + renderNextAreaBordersCallback(worldContext, yMinMax, currentSector, nextSector, x, bestHitData.distance); // Create / update NextRenderArea @@ -160,6 +158,9 @@ void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderCont { renderAreaToPushInStack[nextSectorId].renderArea.xEnd = x; } + + // Draw a Purple placeholder where next sector will be drawn + DrawLineV({(float)x, (float)yMinMax.min}, { (float)x, (float)yMinMax.max }, PURPLE); } } } @@ -173,21 +174,25 @@ void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderCont } } -void RenderNextRenderAreaBorders(RasterizeWorldContext& worldContext, RenderAreaYMinMax& yMinMax, const Sector& currentSector, const Sector& nextSector, uint32_t x, float hitDistance) +void RenderNextAreaBorders(RasterizeWorldContext& worldContext, RenderAreaYMinMax& yMinMax, const Sector& currentSector, const Sector& nextSector, uint32_t x, float hitDistance) { { bool nextSectCelingHigher = nextSector.zCeiling >= currentSector.zCeiling; const Sector& zSizesSector = (nextSectCelingHigher) ? currentSector : nextSector; - const Color upperBorderColor = (nextSectCelingHigher) ? currentSector.ceilingColor : nextSector.topBorderColor; - bool topBorder = !nextSectCelingHigher; - CameraYLineData topBorderLineData = ComputeCameraYAxis(worldContext.cam, x, hitDistance, worldContext.FloorVerticalOffset, + CameraYLineData topBorderLineData = ComputeCameraYAxis(worldContext.cam, x, hitDistance, + worldContext.FloorVerticalOffset, worldContext.CamCurrentSectorElevationOffset, worldContext.RenderTargetWidth, worldContext.RenderTargetHeight, yMinMax.max, yMinMax.min, 0, zSizesSector.zCeiling ); - RenderCameraYLine(topBorderLineData, upperBorderColor, topBorder, true); + + if(!nextSectCelingHigher) + { + bool topBorder = !nextSectCelingHigher; + RenderCameraYLine(topBorderLineData, nextSector.topBorderColor, topBorder, true); + } // Apply Y min yMinMax.min = topBorderLineData.bottom.y; @@ -197,26 +202,41 @@ void RenderNextRenderAreaBorders(RasterizeWorldContext& worldContext, RenderArea bool nextSectFloorHigher = nextSector.zFloor >= currentSector.zFloor; const Sector& zSizesSector = (nextSectFloorHigher) ? currentSector : nextSector; - const Color lowerBorderColor = (nextSectFloorHigher) ? currentSector.floorColor : nextSector.bottomBorderColor; - bool bottomBorder = !nextSectFloorHigher; - CameraYLineData bottomBorderLineData = ComputeCameraYAxis(worldContext.cam, x, hitDistance, worldContext.FloorVerticalOffset, + CameraYLineData bottomBorderLineData = ComputeCameraYAxis(worldContext.cam, x, hitDistance, + worldContext.FloorVerticalOffset, worldContext.CamCurrentSectorElevationOffset, worldContext.RenderTargetWidth, worldContext.RenderTargetHeight, yMinMax.max, yMinMax.min, zSizesSector.zFloor, 0 ); - RenderCameraYLine(bottomBorderLineData, lowerBorderColor, true, bottomBorder); + + if(!nextSectFloorHigher) + { + bool bottomBorder = !nextSectFloorHigher; + RenderCameraYLine(bottomBorderLineData, nextSector.bottomBorderColor, true, bottomBorder); + } // Apply Y max yMinMax.max = bottomBorderLineData.top.y; } +} + +float ComputeVerticalOffset(const RaycastingCamera& cam, uint32_t RenderTargetHeight) +{ + return round(0.5f * RenderTargetHeight * (tanf(cam.pitch)) / tanf(0.5f * cam.fovVectical)); +} - // Draw a Purple placeholder where next sector will be drawn - DrawLineV({(float)x, (float)yMinMax.min}, { (float)x, (float)yMinMax.max }, PURPLE); +float ComputeElevationOffset(const RaycastingCamera& cam, const World& world, uint32_t RenderTargetHeight) +{ + // const float OneSectorHeight = RenderTargetHeight * cam.nearPlaneDistance; + + const Sector& currentSector = world.Sectors.at(cam.currentSectorId); + return Lerp((float)RenderTargetHeight, 0.f, currentSector.zFloor); } CameraYLineData ComputeCameraYAxis( - const RaycastingCamera& cam, uint32_t renderTargetX, float hitDistance, float FloorVerticalOffset, + const RaycastingCamera& cam, uint32_t renderTargetX, float hitDistance, + float FloorVerticalOffset, float CamCurrentSectorElevationOffset, uint32_t RenderTargetWidth, uint32_t RenderTargetHeight, uint32_t YHigh, uint32_t YLow, float topOffsetPercentage, float bottomOffsetPercentage @@ -239,6 +259,9 @@ CameraYLineData ComputeCameraYAxis( float topY = fullSizeTopY + (objectHeight * topOffsetPercentage); float bottomY = (fullSizeTopY + objectHeight) - (objectHeight * bottomOffsetPercentage); + topY += CamCurrentSectorElevationOffset; + bottomY += CamCurrentSectorElevationOffset; + return { .top = { static_cast(renderTargetX), Clamp(topY, YLow, YHigh) }, .bottom = { static_cast(renderTargetX), Clamp(bottomY, YLow, YHigh) }, @@ -250,7 +273,7 @@ CameraYLineData ComputeCameraYAxis( void RenderCameraYLine(CameraYLineData renderData, Color color, bool topBorder, bool bottomBorder) { uint8_t brightness = Lerp(255, 0, renderData.normalizedDepth); - + DrawLineV( renderData.top, renderData.bottom, @@ -259,7 +282,7 @@ void RenderCameraYLine(CameraYLineData renderData, Color color, bool topBorder, ); if(topBorder) - DrawRectangle(renderData.top.x - 1, renderData.top.y - 1, 2, 2, GRAY); + DrawRectangle(renderData.top.x - 1, renderData.top.y - 1, 3, 3, GRAY); if(bottomBorder) - DrawRectangle(renderData.bottom.x - 1, renderData.bottom.y - 1, 2, 2, GRAY); + DrawRectangle(renderData.bottom.x - 1, renderData.bottom.y - 1, 3, 3, GRAY); } \ No newline at end of file diff --git a/src/WorldRasterizer.hpp b/src/WorldRasterizer.hpp index 0f41275..20f2dad 100644 --- a/src/WorldRasterizer.hpp +++ b/src/WorldRasterizer.hpp @@ -2,9 +2,8 @@ #include -#include #include -#include +#include #include "RaycastingCamera.hpp" #include "World.hpp" @@ -35,6 +34,7 @@ struct RasterizeWorldContext const uint32_t RenderTargetWidth; const uint32_t RenderTargetHeight; const float FloorVerticalOffset; + const float CamCurrentSectorElevationOffset; RenderAreaYBoundaries yBoundaries; std::stack renderStack; @@ -53,9 +53,11 @@ struct RaycastHitData const Wall* wall = nullptr; }; -void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderContext renderContext); +using RenderNextAreaBordersCallback = std::function; -void RenderNextRenderAreaBorders(RasterizeWorldContext& worldContext, RenderAreaYMinMax& yMinMax, const Sector& currentSector, const Sector& nextSector, uint32_t x, float hitDistance); +void RasterizeInRenderArea(RasterizeWorldContext& worldContext, SectorRenderContext renderContext, RenderNextAreaBordersCallback renderNextAreaBordersCallback); + +void RenderNextAreaBorders(RasterizeWorldContext& worldContext, RenderAreaYMinMax& yMinMax, const Sector& currentSector, const Sector& nextSector, uint32_t x, float hitDistance); struct CameraYLineData { Vector2 top; @@ -65,10 +67,14 @@ struct CameraYLineData }; CameraYLineData ComputeCameraYAxis( - const RaycastingCamera& cam, uint32_t renderTargetX, float hitDistance, float FloorVerticalOffset, + const RaycastingCamera& cam, uint32_t renderTargetX, float hitDistance, + float FloorVerticalOffset, float CamCurrentSectorElevationOffset, uint32_t RenderTargetWidth, uint32_t RenderTargetHeight, uint32_t YHigh, uint32_t YLow, float topOffsetPercentage = 0, float bottomOffsetPercentage = 0 ); +float ComputeVerticalOffset(const RaycastingCamera& cam, uint32_t RenderTargetHeight); +float ComputeElevationOffset(const RaycastingCamera& cam, const World& world, uint32_t RenderTargetHeight); + void RenderCameraYLine(CameraYLineData renderData, Color color, bool topBorder = true, bool bottomBorder = false); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 984433c..207654e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,14 +6,17 @@ #include #include #include +#include "ImGuiStyle.hpp" +#include "World.hpp" #include "RaycastingMath.hpp" #include "RaycastingCamera.hpp" #include "ColorHelper.hpp" -#include "World.hpp" #include "WorldRasterizer.hpp" #include "RaycastingCameraViewport.hpp" #include "MiniMapViewport.hpp" +#include "RenderingOrchestrator.hpp" +#include "Editor/WorldEditor.hpp" constexpr int DefaultScreenWidth = 1720; constexpr int DefaultScreenHeight = 880; @@ -48,13 +51,14 @@ int main() imguiIO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; imguiIO.ConfigFlags |= ImGuiConfigFlags_DockingEnable; imguiIO.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + SetupImGuiStyle(); SetTargetFPS(144); + /// Global + float deltaTime = 0; float lastFrameTime = GetTime(); - - /// Global World world; @@ -64,6 +68,9 @@ int main() RaycastingCameraViewport cameraViewport(cam, 1920, 1080); MiniMapViewport miniMapViewport(DefaultScreenWidth / 4, DefaultScreenWidth / 4); + WorldEditor worldEditor(world); + + RenderingOrchestrator renderingOrchestrator(cameraViewport); bool lockCursor = false; @@ -91,19 +98,22 @@ int main() SetWindowTitle(windowTitle.c_str()); } - if(cameraViewport.IsFocused() && lockCursor) { - UpdateCamera(cam, deltaTime); - SetMousePosition(GetScreenWidth() / 2, GetScreenHeight() / 2); + // Update current sector + uint32_t currentSectorId = FindSectorOfPoint(cam.position, world); + if(NULL_SECTOR != currentSectorId) + { + cam.currentSectorId = currentSectorId; + } } - // Update current sector - uint32_t currentSectorId = FindSectorOfPoint(cam.position, world); - if(NULL_SECTOR != currentSectorId) + if(cameraViewport.IsFocused() && lockCursor) { - cam.currentSector = currentSectorId; + cam.Update(deltaTime); } + worldEditor.Update(deltaTime); + // Draw BeginDrawing(); @@ -117,8 +127,9 @@ int main() ShowCursor(); } - RasterizeWorldInTexture(cameraViewport.GetRenderTexture(), world, cam); - RenderMinimap(miniMapViewport.GetRendertexture(), world, cam, miniMapViewport.GetZoom()); + miniMapViewport.Render(world, cam); + worldEditor.Render(cam); + renderingOrchestrator.Render(world, cam); // Draw GUI @@ -129,9 +140,24 @@ int main() ImGui::DockSpaceOverViewport(); ApplicationMainMenuBar(); - cam.DrawGUI(); - cameraViewport.DrawGUI(); - miniMapViewport.DrawGUI(); + { + ImGui::Begin("Game Player"); + ImGuiID gamePlayerDockerSpace = ImGui::GetID("gamePlayerDockerSpace"); + ImGui::DockSpace(gamePlayerDockerSpace); + ImGui::End(); + + ImGui::SetNextWindowDockID(gamePlayerDockerSpace, ImGuiCond_FirstUseEver); + cam.DrawGUI(); + ImGui::SetNextWindowDockID(gamePlayerDockerSpace, ImGuiCond_FirstUseEver); + cameraViewport.DrawGUI(); + ImGui::SetNextWindowDockID(gamePlayerDockerSpace, ImGuiCond_FirstUseEver); + miniMapViewport.DrawGUI(); + ImGui::SetNextWindowDockID(gamePlayerDockerSpace, ImGuiCond_FirstUseEver); + renderingOrchestrator.DrawGUI(); + } + { + worldEditor.DrawGUI(); + } rlImGuiEnd(); diff --git a/vcpkg b/vcpkg index 261dd68..f61a294 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit 261dd6831673d3b07e5118261f7e161a21d1a759 +Subproject commit f61a294e765b257926ae9e9d85f96468a0af74e7 diff --git a/vcpkg.json b/vcpkg.json index 18347fc..e9f4bd2 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,22 +1,18 @@ { - "name" : "cmake-vcpkg-template", - "version" : "0.1.0", - "builtin-baseline" : "c9919121dde6f61c0436adda94624636e041226b", + "name" : "raycasting-engine", + "version-string": "latest", "dependencies" : [ { - "name" : "raylib", - "version>=" : "5.0" + "name" : "raylib" }, { - "name" : "raygui", - "version>=" : "4.0" + "name" : "raygui" }, { "name" : "imgui", - "version>=" : "1.90", "features": [ "docking-experimental" ] } ] -} \ No newline at end of file +} From 55d61afc80baa7d2dc2a40df291c142fa73de28c Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Wed, 3 Jul 2024 00:54:24 +0200 Subject: [PATCH 50/52] Update vcpkg version --- vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg b/vcpkg index f61a294..f7423ee 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit f61a294e765b257926ae9e9d85f96468a0af74e7 +Subproject commit f7423ee180c4b7f40d43402c2feb3859161ef625 From da271c4eee10b43c8b26f0861b0cf829d752a4f1 Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Wed, 3 Jul 2024 00:54:58 +0200 Subject: [PATCH 51/52] Add sector zfloor / zceling edition --- src/ColorHelper.hpp | 14 +- src/Editor/WorldEditor.hpp | 215 ++++++++++++++++++++++--------- src/MiniMapViewport.hpp | 2 +- src/RaycastingCamera.hpp | 2 +- src/RaycastingCameraViewport.hpp | 15 ++- src/WorldRasterizer.cpp | 8 +- src/WorldRasterizer.hpp | 4 +- src/main.cpp | 26 ++-- 8 files changed, 195 insertions(+), 91 deletions(-) diff --git a/src/ColorHelper.hpp b/src/ColorHelper.hpp index f500844..49778d8 100644 --- a/src/ColorHelper.hpp +++ b/src/ColorHelper.hpp @@ -9,7 +9,17 @@ constexpr Color MY_DARK_BLUE { 40, 17, 64, 255 }; constexpr Color MY_BEIGE { 242, 211, 172, 255 }; constexpr Color MY_BLACK { 50, 50, 50, 255 }; -constexpr Color ColorAlpha255(Color color, uint8_t alpha) +/// @brief +/// @param color base color to be darken +/// @param darkness 0 to 1 value +/// @return Darken color +inline Color ColorDarken(Color color, float darkness) { - return { color.r, color.g, color.b, alpha }; + float clampedDarkness = Clamp(darkness, 0, 1); + + uint8_t red = roundf(Lerp(color.r, 0, clampedDarkness)); + uint8_t green = roundf(Lerp(color.g, 0, clampedDarkness)); + uint8_t blue = roundf(Lerp(color.b, 0, clampedDarkness)); + + return { red, green, blue, 255 }; } \ No newline at end of file diff --git a/src/Editor/WorldEditor.hpp b/src/Editor/WorldEditor.hpp index e166433..a255fd3 100644 --- a/src/Editor/WorldEditor.hpp +++ b/src/Editor/WorldEditor.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include "../World.hpp" @@ -29,90 +29,181 @@ class WorldEditor void DrawGUI() { + ImGui::Begin("World Editor"); + ImGuiID worldEditorDockerSpace = ImGui::GetID("worldEditorDockerSpace"); + ImGui::DockSpace(worldEditorDockerSpace); + ImGui::End(); + ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); + RenderSectorsGui(); + ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); + RenderViewportGui(); + } + void Update(float dt) + { + } + void Render(RaycastingCamera& cam) + { + Camera2D minimapCamera = { 0 }; + minimapCamera.target = cam.position; + minimapCamera.offset = { (float)renderTexture.texture.width / 2, (float)renderTexture.texture.height / 2 }; + minimapCamera.rotation = 0.0f; + minimapCamera.zoom = 1.f;//zoom; + + BeginTextureMode(renderTexture); + + BeginMode2D(minimapCamera); + + ClearBackground(LIGHTGRAY); + + Vector2 camHeadingDirectionPoint = Vector2Add(cam.position, Vector2Scale(cam.Forward(), 50)); + DrawLineV(cam.position, camHeadingDirectionPoint, RED); + DrawCircleV(cam.position, 10, GREEN); + + for(const auto& [ sectorId, sector ] : world.Sectors) + { + bool sectorSelected = sectorId == currentSelectedSector; + + Vector2 selectionMin = { (float)renderTexture.texture.width, (float)renderTexture.texture.height }; + Vector2 selectionMax = { 0, 0 }; + + for(const auto& wall : sector.walls) + { + Color color = WHITE; + if(sectorSelected) + { + color = RED; + if(wall.toSector != NULL_SECTOR) + { + color = BLUE; + } + } + else if(wall.toSector != NULL_SECTOR) color = PURPLE; + + DrawLineV(wall.segment.a, wall.segment.b, color); + + if(sectorSelected) + { + if(wall.segment.a.x < selectionMin.x) + selectionMin.x = wall.segment.a.x; + if(wall.segment.b.x < selectionMin.x) + selectionMin.x = wall.segment.b.x; + + if(wall.segment.a.y < selectionMin.y) + selectionMin.y = wall.segment.a.y; + if(wall.segment.b.y < selectionMin.y) + selectionMin.y = wall.segment.b.y; + + if(wall.segment.a.x > selectionMax.x) + selectionMax.x = wall.segment.a.x; + if(wall.segment.b.x > selectionMax.x) + selectionMax.x = wall.segment.b.x; + + if(wall.segment.a.y > selectionMax.y) + selectionMax.y = wall.segment.a.y; + if(wall.segment.b.y > selectionMax.y) + selectionMax.y = wall.segment.b.y; + } + } + + if(sectorSelected) + { + static const float padding = 10; + + selectionMin.x -= padding; + selectionMin.y -= padding; + selectionMax.x += padding; + selectionMax.y += padding; + + int width = selectionMax.x - selectionMin.x; + int height = selectionMax.y - selectionMin.y; + + DrawRectangleLines(selectionMin.x, selectionMin.y, width, height, ColorAlpha(RED, .5f)); + } + } + + EndMode2D(); + + EndTextureMode(); + } +private: + void RenderViewportGui() + { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::SetNextWindowSizeConstraints(ImVec2(renderTexture.texture.width, renderTexture.texture.height), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); - - - - + if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar)) { - ImGui::Begin("World Editor"); - ImGuiID worldEditorDockerSpace = ImGui::GetID("worldEditorDockerSpace"); - ImGui::DockSpace(worldEditorDockerSpace); - ImGui::End(); - - ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); - ImGui::Begin("Sectors"); - - ImGui::Text("salut"); - - ImGui::End(); - - ImGui::SetNextWindowDockID(worldEditorDockerSpace, ImGuiCond_FirstUseEver); - // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - // ImGui::SetNextWindowSizeConstraints(ImVec2(renderTexture.texture.width, renderTexture.texture.height), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); - - if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar)) + ImVec2 windowSize = ImGui::GetWindowSize(); + if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) { - // ImVec2 windowSize = ImGui::GetWindowSize(); - // if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) - // { - // ResizeRenderTextureSize(windowSize.x, windowSize.y); - // } - - // rlImGuiImageRenderTextureFit(&renderTexture, true); + ResizeRenderTextureSize(windowSize.x, windowSize.y); } - ImGui::End(); - // ImGui::PopStyleVar(); + rlImGuiImageRenderTextureFit(&renderTexture, true); } + ImGui::End(); - - - - - // ImGui::Begin("World Editor", nullptr, ImGuiWindowFlags_DockNodeHost); - - // ImGui::Begin("Sectors"); - // ImGui::Text("salut"); - // ImGui::End(); - - // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - // ImGui::SetNextWindowSizeConstraints(ImVec2(renderTexture.texture.width, renderTexture.texture.height), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); - - // if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar)) - // { - // ImVec2 windowSize = ImGui::GetWindowSize(); - // if(windowSize.x != renderTexture.texture.width || windowSize.y != renderTexture.texture.height) - // { - // ResizeRenderTextureSize(windowSize.x, windowSize.y); - // } - - // rlImGuiImageRenderTextureFit(&renderTexture, true); - // } - // ImGui::End(); - - // ImGui::PopStyleVar(); - - // ImGui::End(); + ImGui::PopStyleVar(); } - void Render(RaycastingCamera& cam) + void RenderSectorsGui() { + using namespace std::string_literals; + ImGui::Begin("Sectors"); + + for(auto& [ sectorId, sector ] : world.Sectors) + { + static const ImGuiTreeNodeFlags BaseSectorFlags = + ImGuiTreeNodeFlags_OpenOnArrow + | ImGuiTreeNodeFlags_OpenOnDoubleClick + | ImGuiTreeNodeFlags_SpanAvailWidth; + + ImGuiTreeNodeFlags sectorFlags = BaseSectorFlags; + if (currentSelectedSector == sectorId) + { + sectorFlags |= ImGuiTreeNodeFlags_Selected; + } + + std::string label = "Sector - "s + std::to_string(sectorId); + bool sectorOpen = ImGui::TreeNodeEx(label.c_str(), sectorFlags); + + if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) + { + currentSelectedSector = sectorId; + } + + if (sectorOpen) + { + RenderSectorContentGui(sector); + ImGui::TreePop(); + } + } + + ImGui::End(); } - void Update(float dt) + void RenderSectorContentGui(Sector& sector) { + ImGui::SliderFloat("zCeiling", §or.zCeiling, -10, 10); + ImGui::SliderFloat("zFloor", §or.zFloor, -10, 10); + for(size_t i = 0; i < sector.walls.size(); ++i) + { + ImGui::Text("[%d] => %d", i, sector.walls[i].toSector); + } } private: World& world; RenderTexture2D renderTexture; -}; + + // State + SectorID currentSelectedSector = NULL_SECTOR; +}; \ No newline at end of file diff --git a/src/MiniMapViewport.hpp b/src/MiniMapViewport.hpp index d3e737f..d06e9a2 100644 --- a/src/MiniMapViewport.hpp +++ b/src/MiniMapViewport.hpp @@ -79,5 +79,5 @@ class MiniMapViewport RenderTexture2D renderTexture { 0 }; bool focused = false; - float zoom = 0.3f; + float zoom = 1.f; }; \ No newline at end of file diff --git a/src/RaycastingCamera.hpp b/src/RaycastingCamera.hpp index 5ed3b43..0323f69 100644 --- a/src/RaycastingCamera.hpp +++ b/src/RaycastingCamera.hpp @@ -17,7 +17,7 @@ struct RaycastingCamera float fov { 60 }; float fovVectical { 120 }; - float farPlaneDistance = 1000.0f; + float farPlaneDistance = 900.0f; float nearPlaneDistance = 100.f; size_t maxRenderItr { 25 }; diff --git a/src/RaycastingCameraViewport.hpp b/src/RaycastingCameraViewport.hpp index 1adc16b..8c36ed0 100644 --- a/src/RaycastingCameraViewport.hpp +++ b/src/RaycastingCameraViewport.hpp @@ -42,9 +42,22 @@ class RaycastingCameraViewport } } - focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows); + bool isFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows); + if(isFocused && !focused) + { + SetMousePosition(GetScreenWidth() / 2, GetScreenHeight() / 2); + } + + focused = isFocused; + // draw the view rlImGuiImageRenderTextureFit(&renderTexture, true); + + if(IsFocused() && IsKeyPressed(KEY_ESCAPE)) + { + ImGui::SetFocusID(ImGui::GetID("Game Player"), ImGui::GetCurrentWindow()); + focused = false; + } } ImGui::End(); diff --git a/src/WorldRasterizer.cpp b/src/WorldRasterizer.cpp index f88f145..045a606 100644 --- a/src/WorldRasterizer.cpp +++ b/src/WorldRasterizer.cpp @@ -16,7 +16,7 @@ RasterizeWorldContext InitRasterizeWorldContext(uint32_t RenderTargetWidth, uint .RenderTargetWidth = RenderTargetWidth, .RenderTargetHeight = RenderTargetHeight, .FloorVerticalOffset = ComputeVerticalOffset(cam, RenderTargetHeight), - .CamCurrentSectorElevationOffset = ComputeElevationOffset(cam, world, RenderTargetHeight), + .CamCurrentSectorElevationOffset = 0,//ComputeElevationOffset(cam, world, RenderTargetHeight), }; context.yBoundaries.resize(RenderTargetWidth); @@ -272,13 +272,13 @@ CameraYLineData ComputeCameraYAxis( void RenderCameraYLine(CameraYLineData renderData, Color color, bool topBorder, bool bottomBorder) { - uint8_t brightness = Lerp(255, 0, renderData.normalizedDepth); + float darkness = Lerp(1, 0, renderData.normalizedDepth); DrawLineV( renderData.top, renderData.bottom, - // ColorAlpha255(color, brightness) - color + ColorDarken(color, renderData.normalizedDepth) + // color ); if(topBorder) diff --git a/src/WorldRasterizer.hpp b/src/WorldRasterizer.hpp index 20f2dad..79a0c78 100644 --- a/src/WorldRasterizer.hpp +++ b/src/WorldRasterizer.hpp @@ -62,8 +62,8 @@ struct CameraYLineData { Vector2 top; Vector2 bottom; - float depth; - float normalizedDepth; + float depth = 0; + float normalizedDepth = 0; }; CameraYLineData ComputeCameraYAxis( diff --git a/src/main.cpp b/src/main.cpp index 207654e..63c53e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include "ImGuiStyle.hpp" @@ -71,8 +72,6 @@ int main() WorldEditor worldEditor(world); RenderingOrchestrator renderingOrchestrator(cameraViewport); - - bool lockCursor = false; while (!WindowShouldClose()) { @@ -82,12 +81,6 @@ int main() // Inputs - if(IsKeyPressed(KEY_ESCAPE)) - { - lockCursor = !lockCursor; - SetMousePosition(GetScreenWidth() / 2, GetScreenHeight() / 2); - } - // Update { @@ -107,9 +100,15 @@ int main() } } - if(cameraViewport.IsFocused() && lockCursor) + if(cameraViewport.IsFocused()) { cam.Update(deltaTime); + SetMousePosition(GetScreenWidth() / 2, GetScreenHeight() / 2); + HideCursor(); + } + else + { + ShowCursor(); } worldEditor.Update(deltaTime); @@ -117,15 +116,6 @@ int main() // Draw BeginDrawing(); - - if(cameraViewport.IsFocused() && lockCursor) - { - HideCursor(); - } - else - { - ShowCursor(); - } miniMapViewport.Render(world, cam); worldEditor.Render(cam); From f4a52fd5acbfd98798ced6ae78eeab4d67a9e46b Mon Sep 17 00:00:00 2001 From: Florian <47593350+P0ulpy@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:40:32 +0200 Subject: [PATCH 52/52] Update raycasting-engine.code-workspace --- .vscode/raycasting-engine.code-workspace | 48 ++++++++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.vscode/raycasting-engine.code-workspace b/.vscode/raycasting-engine.code-workspace index 675ff7c..60e6ce4 100644 --- a/.vscode/raycasting-engine.code-workspace +++ b/.vscode/raycasting-engine.code-workspace @@ -18,8 +18,16 @@ "type": "cppvsdbg", "request": "launch", "preLaunchTask": "CMake build Debug", - "program": "${workspaceFolder}/out/Debug/Debug/raycasting-engine-app.exe", - "cwd": "${workspaceFolder}/out/Debug/Debug", + "program": "${command:cmake.launchTargetPath}", + "cwd": "${workspaceFolder}", + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + } + ], "requireExactSource": false, "console": "newExternalWindow" }, @@ -28,8 +36,16 @@ "type": "cppvsdbg", "request": "launch", "preLaunchTask": "CMake build Release", - "program": "${workspaceFolder}/out/Release/Release/raycasting-engine-app.exe", - "cwd": "${workspaceFolder}/out/Release/Release", + "program": "${command:cmake.launchTargetPath}", + "cwd": "${workspaceFolder}", + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + } + ], "requireExactSource": false, "console": "newExternalWindow" }, @@ -38,8 +54,16 @@ "type": "cppdbg", "request": "launch", "preLaunchTask": "CMake build Debug", - "program": "${workspaceFolder}/out/Debug/raycasting-engine-app.exe", - "cwd": "${workspaceFolder}/out/Debug", + "program": "${command:cmake.launchTargetPath}", + "cwd": "${workspaceFolder}", + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + } + ], "MIMode": "gdb", "miDebuggerPath": "gdb.exe", "externalConsole": true, @@ -57,8 +81,16 @@ "type": "cppdbg", "request": "launch", "preLaunchTask": "CMake build Release", - "program": "${workspaceFolder}/out/Release/raycasting-engine-app.exe", - "cwd": "${workspaceFolder}/out/Release", + "program": "${command:cmake.launchTargetPath}", + "cwd": "${workspaceFolder}", + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + } + ], "MIMode": "gdb", "miDebuggerPath": "gdb.exe", "externalConsole": true,