diff --git a/.gitignore b/.gitignore index 65d3a72..e678b90 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ __UTILS__ snapshots OUTPUT-Linux OUTPUT-w64 -OUTPUT-w32 \ No newline at end of file +OUTPUT-w32 +makeheaders/makeheaders.exe +makeheaders/makeheaders \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..05021ce --- /dev/null +++ b/README @@ -0,0 +1,29 @@ +# Compiling +! NOTICE: Compile with `-recursive`, e.g `git clone ... -recursive` +## Compiling on Linux +1) Install tools. +**Debian-based distros:** +Essential: +```sh +sudo apt install build-essential cmake zip unzip make libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev +``` +If you also want to compile for Windows: +```sh +sudo apt install g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 g++-mingw-w64-i686 gcc-mingw-w64-i686 +``` + +**Arch-based distros:** +Essential: +`TODO` +If you also want to compile for Windows: +`TODO` + +2) Run `compile.sh` to compile for Linux, 64-bit Windows & 32-bit Windows. +Run `compile_linux.sh` to compile for Linux only. + +## Compiling on Windows +1) Install [CMake](https://cmake.org/download/), [Ninja](https://ninja-build.org/) and [MinGW](https://www.mingw-w64.org/). +Try them out in the terminal: `cmake -version`, `ninja --version`, `gcc -version`, `g++ -version`. +If some are missing, add them to PATH. + +2) From the terminal, run `compile.ps1`. \ No newline at end of file diff --git a/compile.ps1 b/compile.ps1 new file mode 100644 index 0000000..f147796 --- /dev/null +++ b/compile.ps1 @@ -0,0 +1,15 @@ +cd makeheaders +make +cd .. + +./makeheaders/makeheaders.exe -h src/helpers/vars.hpp src/helpers/chunks.cpp src/helpers/debug.cpp src/helpers/entities.cpp src/helpers/input.cpp src/helpers/menu.cpp src/helpers/mesher.cpp src/helpers/networking.cpp src/helpers/utils.cpp src/helpers/inlines.hpp src/helpers/inventory.cpp src/helpers/locale.cpp src/helpers/recipes.cpp src/helpers/particles.cpp src/helpers/player.cpp src/helpers/multisound.cpp -v > tmp.hpp +Get-Content .\additions.hpp, .\tmp.hpp | Out-File .\src\helpers\common.hpp -Encoding UTF8 +rm tmp.hpp + +echo Building x86-64 Windows... +rm build +cmake -DCMAKE_TOOLCHAIN_FILE='toolchains/mingw-w64-native.cmake' . -DWIN32=ON -DWIN32=true -B build -G "Ninja" +cmake --build build +mkdir OUTPUT-w64 +cp build/src/RCRAFT.exe OUTPUT-w64/CubeGame.exe +cp -r data/resources OUTPUT-w64 \ No newline at end of file diff --git a/compile.sh b/compile.sh index c89989f..82f276e 100644 --- a/compile.sh +++ b/compile.sh @@ -1,5 +1,9 @@ #/usr/bin/bash +cd makeheaders +make +cd .. + sh compile_linux.sh sh compile_windows_64.sh sh compile_windows.sh \ No newline at end of file diff --git a/compile_linux.sh b/compile_linux.sh index 21231e4..eaabb36 100644 --- a/compile_linux.sh +++ b/compile_linux.sh @@ -7,9 +7,7 @@ rm tmp.hpp echo Building x86-64 Linux... rm -rf build cmake -B build -DUNIX=ON -DUNIX=true -DCMAKE_BUILD_TYPE=Debug -cd build -make -j12 -cd .. +cmake --build build mkdir OUTPUT-Linux cp build/src/RCRAFT OUTPUT-Linux/CubeGame cp -r data/resources OUTPUT-Linux \ No newline at end of file diff --git a/compile_windows.sh b/compile_windows.sh index 3d058ac..36f600d 100644 --- a/compile_windows.sh +++ b/compile_windows.sh @@ -7,9 +7,7 @@ rm tmp.hpp echo Building i686 Windows... rm -rf build cmake -DCMAKE_TOOLCHAIN_FILE=toolchains/mingw-w32.cmake -DWIN32=ON -DWIN32=true -B build -cd build -make -j12 -cd .. +cmake --build build mkdir OUTPUT-w32 cp build/src/RCRAFT.exe OUTPUT-w32/CubeGame.exe cp -r data/resources OUTPUT-w32 \ No newline at end of file diff --git a/compile_windows_64.sh b/compile_windows_64.sh index a38b01f..ac589b9 100644 --- a/compile_windows_64.sh +++ b/compile_windows_64.sh @@ -7,9 +7,7 @@ rm tmp.hpp echo Building x86-64 Windows... rm -rf build cmake -DCMAKE_TOOLCHAIN_FILE=toolchains/mingw-w64.cmake -DWIN32=ON -DWIN32=true -B build -cd build -make -j12 -cd .. +cmake --build build mkdir OUTPUT-w64 cp build/src/RCRAFT.exe OUTPUT-w64/CubeGame.exe cp -r data/resources OUTPUT-w64 \ No newline at end of file diff --git a/makeheaders/makeheaders b/makeheaders/makeheaders deleted file mode 100755 index 8ae85bb..0000000 Binary files a/makeheaders/makeheaders and /dev/null differ diff --git a/src/helpers/common.hpp b/src/helpers/common.hpp index 49d4fd2..ef652f5 100644 --- a/src/helpers/common.hpp +++ b/src/helpers/common.hpp @@ -1,4 +1,4 @@ -#ifdef WIN32 // FUCK WINDOWS +#ifdef WIN32 // FUCK WINDOWS #include "external/fix_win32_compatibility.h" #undef PlaySound #endif diff --git a/src/helpers/menu.cpp b/src/helpers/menu.cpp index 0e875eb..c99aa63 100644 --- a/src/helpers/menu.cpp +++ b/src/helpers/menu.cpp @@ -488,10 +488,10 @@ void DrawWorldSelect() { DrawBackground(); int i = 0; for(std::filesystem::path path : worldList) { - if(Button(reinterpret_cast(path.filename().u8string().c_str()), GetScreenWidth()/2-64, i*48+8, 128, 0)) { + if(Button(reinterpret_cast(path.filename().string().c_str()), GetScreenWidth()/2-64, i*48+8, 128, 0)) { online = false; SetTargetFPS(-1); - _LoadWorld(reinterpret_cast(path.u8string().c_str())); + _LoadWorld(reinterpret_cast(path.string().c_str())); return; } i++; diff --git a/src/helpers/networking.cpp b/src/helpers/networking.cpp index d09f06a..1dc646e 100644 --- a/src/helpers/networking.cpp +++ b/src/helpers/networking.cpp @@ -25,7 +25,7 @@ ENetHost* StartServer() { /* Bind the server to port 1234. */ address.port = PORT; - server = enet_host_create(&address, 32, 1, 0); + server = enet_host_create(&address, 32, 1, 0, 0); if (server == NULL) { fprintf (stderr, @@ -41,7 +41,8 @@ ENetHost* StartClient() { client = enet_host_create (NULL /* create a client host */, 1 /* 1 channel*/, 1 /* only allow 1 outgoing connection */, - 0 /* assume any amount of incoming bandwidth */); + 0 /* assume any amount of incoming bandwidth */, + 0); if (client == NULL) { diff --git a/src/helpers/recipes.cpp b/src/helpers/recipes.cpp index b9ca033..d88a0f9 100644 --- a/src/helpers/recipes.cpp +++ b/src/helpers/recipes.cpp @@ -49,7 +49,7 @@ void LoadRecipes() { try { Recipe _recipe; - const std::string path = dir_entry.path().u8string(); + const std::string path = dir_entry.path().string(); std::cout << "loading " << path << std::endl; YAML::Node recipe = YAML::LoadFile(path); _recipe.requiredStation = recipe["station"].as(); diff --git a/toolchains/mingw-w64-native.cmake b/toolchains/mingw-w64-native.cmake new file mode 100644 index 0000000..a2c68b7 --- /dev/null +++ b/toolchains/mingw-w64-native.cmake @@ -0,0 +1,14 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_VERSION 1) + +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) +set(CMAKE_RC_COMPILER windres) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(CMAKE_C_FLAGS "-static-libgcc -static-libstdc++ ${CMAKE_C_FLAGS}") +set(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++ ${CMAKE_CXX_FLAGS}")