From ac4b671ef382da8fd1f877cefae65297da7ddb3c Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Sun, 11 Aug 2024 01:16:32 +0100 Subject: [PATCH] Add README and make dice setup script universal to Unix systems --- README.md | 66 +++++++++++++++++++++++++++++++--- dice_setup.sh => unix_setup.sh | 14 ++++---- win_setup.bat | 28 +++++++-------- 3 files changed, 82 insertions(+), 26 deletions(-) rename dice_setup.sh => unix_setup.sh (84%) diff --git a/README.md b/README.md index c0d29a5..e67a2aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,62 @@ -On Linux/OSX, SDL2 is found in the system package manager. -On Linux, run: apt-get install libsdl2-dev -On OSX, run: brew install sdl2 +# Haskell Game Jam Template -For Windows, SDL2 development libraries are provided within the repository. -Run `win_setup.bat` to create a file that specifies where to find these libraries. +This is a template repository for a game written in Haskell! + +Comments are sprinkled wherever possible to make it easier to understand. + +The "core" (where the update/draw loop is) is in `Game.hs`, check out the `updateState` and `drawState` functions! + +## Using this template + +This project has been tested on GHC 8.8.4, 8.10.7, and 9.4.8, on Windows 11, macOS Sonoma (Arm), and DICE Ubuntu. + +This project uses SDL2 as the cross-platform window/graphics abstraction library. +So to build this project correctly, we'll need to install SDL2 so Haskell can find it. +You can do this either system-wide or local to this project. + +- System-wide SDL2 installation + - On DICE: + - This is unsupported. + - On Windows: + - This is unsupported. + - On Linux (Ubuntu): + - Run `apt-get install libsdl2-dev` + - On Linux (other): + - Find the SDL2 development package from your system package manager. + - On MacOS: + - Run `brew install sdl2` assuming you have Homebrew. If you do not, follow the local installation. +- Local SDL2 installation + - On DICE/MacOS/Ubuntu/other: + - Run `./unix_setup.sh`, which relies only on `tar`, `curl`, `make` and standard C compilation tools. + - On Windows: + - Run `.\win_setup.sh`. + +After SDL2 is setup, run the following to build the project and run it: + +``` +cabal run +``` + +### Understanding + +The project template starts a fixed-FPS game loop (at 60FPS), which handles the movement of a 2D sprite. + +Feel free to expand this in any direction you want! (Even 3D is possible if you wrangle with it enough) + +### Adding dependencies + +To add dependencies to the project, edit the `.cabal` file's `build-depends` clause. + +### Packaging + +Packaging the game can be a little complex if you're on Linux or Mac, since the game binary might contain an absolute path reference to the SDL libraries, which will be broken if you move it to another machine. Please investigate "SDL game distribution" on your own :( + +For Windows: +- Run `cabal list-bin Game` to find where the built binary is +- Copy the SDL2.dll file, your game binary, and whatever other assets/resources you need, into a new folder +- Test by double-clicking the game binary to see that it runs. +- ZIP that folder up for distribution. + +### Stack + +This project does not support using Stack. You can try, but if you already have Cabal installed, it's much quicker to use that. diff --git a/dice_setup.sh b/unix_setup.sh similarity index 84% rename from dice_setup.sh rename to unix_setup.sh index cbb3310..ee77abf 100644 --- a/dice_setup.sh +++ b/unix_setup.sh @@ -1,8 +1,8 @@ #!/bin/sh -# Don't run if the sdl2_dice folder or cabal.project.local already exists -if [ -d "sdl2_dice" ] || [ -f "cabal.project.local" ]; then - echo "sdl2_dice folder or cabal.project.local already exists." +# Don't run if the sdl2_local folder or cabal.project.local already exists +if [ -d "sdl2_local" ] || [ -f "cabal.project.local" ]; then + echo "sdl2_local folder or cabal.project.local already exists." echo "Please remove them before running this script." exit 1 fi @@ -26,7 +26,7 @@ mkdir build cd build || (printf "\033[31mError: SDL2-2.30.6/build folder not found.\033[0m\n" && exit 1) printf "\033[32minfo \033[0m Configuring SDL2 to prepare build...\n" -if ! output=$(../configure --prefix="$(pwd)/../../sdl2_dice" 2>&1); then +if ! output=$(../configure --prefix="$(pwd)/../../sdl2_local" 2>&1); then printf "\033[31mError configuring SDL2. Check sdl_build_log.txt for more information.\033[0m\n" echo "$output" >> sdl_build_log.txt exit 1 @@ -37,7 +37,7 @@ if ! output=$(make 2>&1); then echo "$output" >> sdl_build_log.txt exit 1 fi -printf "\033[32minfo \033[0m Copying built libraries to new sdl2_dice folder...\n" +printf "\033[32minfo \033[0m Copying built libraries to new sdl2_local folder...\n" if ! output=$(make install 2>&1); then printf "\033[31mError copying SDL2. Check sdl_build_log.txt for more information.\033[0m\n" echo "$output" >> sdl_build_log.txt @@ -55,8 +55,8 @@ printf "\033[32minfo \033[0m Creating cabal.project.local file...\n" cat <> cabal.project.local package sdl2 flags: -pkgconfig - extra-lib-dirs: $(pwd)/sdl2_dice/lib - extra-include-dirs: $(pwd)/sdl2_dice/include/SDL2 + extra-lib-dirs: $(pwd)/sdl2_local/lib + extra-include-dirs: $(pwd)/sdl2_local/include/SDL2 EOF printf "\033[32mSetup complete! Try running '\033[107m\033[30mcabal run\033[0m\033[32m' to build the project.\033[0m\n" diff --git a/win_setup.bat b/win_setup.bat index 8d4c556..193cfc9 100644 --- a/win_setup.bat +++ b/win_setup.bat @@ -1,14 +1,14 @@ @echo off -rem Don't run if the sdl2_win_mingw folder or cabal.project.local already exists -if exist sdl2_win_mingw ( - echo Error: The 'sdl2_win_mingw' folder already exists. - echo If you want to re-run the setup, delete the 'sdl2_win_mingw' folder and 'cabal.project.local' file and try again. +rem Don't run if the sdl2_local_win folder or cabal.project.local already exists +if exist sdl2_local_win ( + echo Error: The 'sdl2_local_win' folder already exists. + echo If you want to re-run the setup, delete the 'sdl2_local_win' folder and 'cabal.project.local' file and try again. exit /b ) if exist cabal.project.local ( echo Error: The 'cabal.project.local' file already exists. - echo If you want to re-run the setup, delete the 'sdl2_win_mingw' folder and 'cabal.project.local' file and try again. + echo If you want to re-run the setup, delete the 'sdl2_local_win' folder and 'cabal.project.local' file and try again. exit /b ) @@ -26,13 +26,13 @@ rem Remove the zip file echo.info  Removing downloaded SDL2-devel-2.30.6-mingw.zip file... del SDL2-devel-2.30.6-mingw.zip -rem Copy the bin, include and lib folders to the sdl2_win_mingw folder -echo.info  Making new sdl2_win_mingw folder... -mkdir sdl2_win_mingw -echo.info  Copying SDL2 libraries to new sdl2_win_mingw folder... -xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\bin sdl2_win_mingw\bin\ > nul -xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\include sdl2_win_mingw\include\ > nul -xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\lib sdl2_win_mingw\lib\ > nul +rem Copy the bin, include and lib folders to the sdl2_local_win folder +echo.info  Making new sdl2_local_win folder... +mkdir sdl2_local_win +echo.info  Copying SDL2 libraries to new sdl2_local_win folder... +xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\bin sdl2_local_win\bin\ > nul +xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\include sdl2_local_win\include\ > nul +xcopy /E /Y SDL2-devel-2.30.6-mingw\SDL2-2.30.6\x86_64-w64-mingw32\lib sdl2_local_win\lib\ > nul rem Remove the extracted SDL2 folder echo.info  Removing extracted SDL2-devel-2.30.6-mingw folder... @@ -45,8 +45,8 @@ echo.package sdl2 echo. -- Disable pkg-config, as we instead supply the path to the SDL2 libraries manually echo. flags: -pkgconfig echo. -- Supply the path to the local SDL2 libraries (must be absolute path^) -echo. extra-lib-dirs: "%cd:\=\\%\\sdl2_win_mingw\\lib" -echo. extra-include-dirs: "%cd:\=\\%\\sdl2_win_mingw\\include\\SDL2" +echo. extra-lib-dirs: "%cd:\=\\%\\sdl2_local_win\\lib" +echo. extra-include-dirs: "%cd:\=\\%\\sdl2_local_win\\include\\SDL2" echo.package text echo. -- Disable use of SIMD, which makes text fails to build on Win + GHC 8.8.4 echo. flags: -simdutf