diff --git a/.gitignore b/.gitignore index 17506fdb2..032fee893 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ bin/* build/* .gradle/* TerrarumBuild.jar +buildapp/out/Terrarum* +assets/mods/dwarventech/ModuleComputers.jar # Java native errors hs_err_pid* diff --git a/buildapp/appimagetool-x86_64.AppImage b/buildapp/appimagetool-x86_64.AppImage new file mode 100755 index 000000000..25365df3f Binary files /dev/null and b/buildapp/appimagetool-x86_64.AppImage differ diff --git a/buildapp/build_app_linux_arm.sh b/buildapp/build_app_linux_arm.sh new file mode 100755 index 000000000..a758bdda0 --- /dev/null +++ b/buildapp/build_app_linux_arm.sh @@ -0,0 +1,29 @@ +#!/bin/bash +cd "${0%/*}" +APPIMAGETOOL="appimagetool-x86_64.AppImage" +SRCFILES="terrarumlinux_arm" +DESTDIR="TerrarumLinux.arm" +RUNTIME="runtime-linux-arm" + +# Cleanup +rm -rf $DESTDIR || true +mkdir $DESTDIR + +# Prepare an application +cp icns.png $DESTDIR/icns.png +cp $SRCFILES/Terrarum.desktop $DESTDIR/ +cp $SRCFILES/AppRun $DESTDIR/AppRun +chmod +x $DESTDIR/AppRun + +# Copy over a Java runtime +cp -r "../out/$RUNTIME" $DESTDIR/ + +# Copy over all the assets and a jarfile +cp -r "../assets" $DESTDIR/ +cp -r "../out/TerrarumBuild.jar" $DESTDIR/assets/ + +# Pack everything to AppImage +"./$APPIMAGETOOL" $DESTDIR "out/$DESTDIR.AppImage" || { echo 'Building AppImage failed' >&2; exit 1; } +chmod +x "out/$DESTDIR.AppImage" +rm -rf $DESTDIR || true +echo "Build successful: $DESTDIR" \ No newline at end of file diff --git a/buildapp/build_app_linux_x86.sh b/buildapp/build_app_linux_x86.sh new file mode 100755 index 000000000..63f43a65a --- /dev/null +++ b/buildapp/build_app_linux_x86.sh @@ -0,0 +1,29 @@ +#!/bin/bash +cd "${0%/*}" +APPIMAGETOOL="appimagetool-x86_64.AppImage" +SRCFILES="terrarumlinux_x86" +DESTDIR="TerrarumLinux.x86" +RUNTIME="runtime-linux-x86" + +# Cleanup +rm -rf $DESTDIR || true +mkdir $DESTDIR + +# Prepare an application +cp icns.png $DESTDIR/icns.png +cp $SRCFILES/Terrarum.desktop $DESTDIR/ +cp $SRCFILES/AppRun $DESTDIR/AppRun +chmod +x $DESTDIR/AppRun + +# Copy over a Java runtime +cp -r "../out/$RUNTIME" $DESTDIR/ + +# Copy over all the assets and a jarfile +cp -r "../assets" $DESTDIR/ +cp -r "../out/TerrarumBuild.jar" $DESTDIR/assets/ + +# Pack everything to AppImage +"./$APPIMAGETOOL" $DESTDIR "out/$DESTDIR.AppImage" || { echo 'Building AppImage failed' >&2; exit 1; } +chmod +x "out/$DESTDIR.AppImage" +rm -rf $DESTDIR || true +echo "Build successful: $DESTDIR" \ No newline at end of file diff --git a/buildapp/build_app_mac_arm.sh b/buildapp/build_app_mac_arm.sh new file mode 100755 index 000000000..462f305c6 --- /dev/null +++ b/buildapp/build_app_mac_arm.sh @@ -0,0 +1,25 @@ +#!/bin/bash +cd "${0%/*}" +SRCFILES="terrarummac_arm" +DESTDIR="out/TerrarumMac.arm.app" +RUNTIME="runtime-osx-arm" +# Cleanup +rm -rf $DESTDIR || true +mkdir $DESTDIR +mkdir $DESTDIR/Contents +mkdir $DESTDIR/Contents/MacOS + +# Prepare an application +cp icns.png $DESTDIR/.icns +cp $SRCFILES/Info.plist $DESTDIR/Contents/ +cp $SRCFILES/Terrarum.sh $DESTDIR/Contents/MacOS/ +chmod +x $DESTDIR/Contents/MacOS/Terrarum.sh + +# Copy over a Java runtime +cp -r "../out/$RUNTIME" $DESTDIR/Contents/MacOS/ + +# Copy over all the assets and a jarfile +cp -r "../assets" $DESTDIR/Contents/MacOS/ +cp -r "../out/TerrarumBuild.jar" $DESTDIR/Contents/MacOS/assets/ + +echo "Build successful: $DESTDIR" \ No newline at end of file diff --git a/buildapp/build_app_mac_x86.sh b/buildapp/build_app_mac_x86.sh new file mode 100755 index 000000000..f6c431187 --- /dev/null +++ b/buildapp/build_app_mac_x86.sh @@ -0,0 +1,25 @@ +#!/bin/bash +cd "${0%/*}" +SRCFILES="terrarummac_x86" +DESTDIR="out/TerrarumMac.x86.app" +RUNTIME="runtime-osx-x86" +# Cleanup +rm -rf $DESTDIR || true +mkdir $DESTDIR +mkdir $DESTDIR/Contents +mkdir $DESTDIR/Contents/MacOS + +# Prepare an application +cp icns.png $DESTDIR/.icns +cp $SRCFILES/Info.plist $DESTDIR/Contents/ +cp $SRCFILES/Terrarum.sh $DESTDIR/Contents/MacOS/ +chmod +x $DESTDIR/Contents/MacOS/Terrarum.sh + +# Copy over a Java runtime +cp -r "../out/$RUNTIME" $DESTDIR/Contents/MacOS/ + +# Copy over all the assets and a jarfile +cp -r "../assets" $DESTDIR/Contents/MacOS/ +cp -r "../out/TerrarumBuild.jar" $DESTDIR/Contents/MacOS/assets/ + +echo "Build successful: $DESTDIR" \ No newline at end of file diff --git a/buildapp/icns.png b/buildapp/icns.png new file mode 100644 index 000000000..7e14c22a0 --- /dev/null +++ b/buildapp/icns.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6daf9a7822ff9d7c8404b4ab1efb2dbfffa2e0f4a06761045855b45bf51562e4 +size 1176 diff --git a/buildapp/instructions.md b/buildapp/instructions.md new file mode 100644 index 000000000..2227c60fb --- /dev/null +++ b/buildapp/instructions.md @@ -0,0 +1,59 @@ +### Preparation + +Download and unzip the JDK for the appropriate operation systems first! JDKs can be downloaded on https://jdk.java.net/archive/. + +Then, on the terminal, run following commands: + +jlink --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-linux-x86 --no-header-files --no-man-pages --strip-debug --compress=2 + +jlink --module-path ~/Documents/openjdk/jdk-17.0.1-arm/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-linux-arm --no-header-files --no-man-pages --strip-debug --compress=2 +jlink --module-path ~/Documents/openjdk/jdk-17.0.1-windows/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-windows-x86 --no-header-files --no-man-pages --strip-debug --compress=2 +jlink --module-path ~/Documents/openjdk/jdk-17.0.1.jdk-arm/Contents/Home/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-osx-arm --no-header-files --no-man-pages --strip-debug --compress=2 +jlink --module-path ~/Documents/openjdk/jdk-17.0.1.jdk-x86/Contents/Home/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-osx-x86 --no-header-files --no-man-pages --strip-debug --compress=2 + +This process assumes that the game does NOT use the Java 9+ modules and every single required libraries are fat-jar'd (their contents extracted right into the Jar) + +### Packaging + +Create an output directory; its contents shall be: + +``` ++assets +`(regular "assets") +`TerrarumBuild.jar +Terrarum.arm.app /* uses start_game_mac_aarch64.sh and contains runtime-osx-arm */ +Terrarum.x86.app /* uses start_game_mac_x86_64.sh and contains runtime-osx-x86 */ +Terrarum.arm.AppImage /* uses start_game_linux_aarch64.sh and contains runtime-linux-arm */ +Terrarum.x86.AppImage /* uses start_game_linux_x86_64.sh and contains runtime-linux-x86 */ +Terrarum.exe /* uses start_game_windows.bat and contains runtime-windows-x86 */ +``` + +#### Packaging Script + +Before running the packaging script make sure: + +1. All five runtimes must exist on `/out/runtime--` directory +2. The build scripts are on a subdirectory of the project directory + +#### OSX .app Packaging + +``` +Terrarum.*.app ++.icns /* 512x512 PNG */ ++Contents +`Info.plist + +MacOS + `start_game_mac_*.sh * permission: +x */ +``` + + + +`assets/TerrarumBuild.jar` is the artifact built using the TerrarumBuild. + +`start_game_*` files are on the root directory of the project; use them to build executable apps. + +Hide the `.jar` within the subdirectory; users will think this file is the main executable and will try to execute it using whatever JVM they may (or may not) have. + +### Notes to Terrarum Programmers + +By self-containing everything in one file, it is not possible to modify the base game easily. Modloading scheme must be extended to load from mutable directory such as `%APPDATA%/Terrarum/mods`. \ No newline at end of file diff --git a/buildapp/out/Apps built can be found here b/buildapp/out/Apps built can be found here new file mode 100644 index 000000000..f4b62c18c --- /dev/null +++ b/buildapp/out/Apps built can be found here @@ -0,0 +1,9 @@ +You should be able to find following files here: + +TerrarumMac.x86.app (a directory) +TerrarumMac.arm.app (a directory) +TerrarumLinux.x86.AppImage (an ELF executable) +TerrarumLinux.arm.AppImage (an ELF executable) +TerrarumWindows.x86.exe (a Windows executable) + +NOTE: Mac apps won't run unless you disable the Gatekeeper by running `sudo spctl --master-disable` on Terminal (to be honest, doing so also opens a gaping hole called "security hazard"); signing a code requires both Apple Developer Connection (costs 99 USD/year) and a working Mac (cost a fortune) of which I'm not willing to shell out. So, if you're one of those unlucky Mac user try this game on your own risk, or get a Windows machine. diff --git a/buildapp/terrarumlinux_arm/AppRun b/buildapp/terrarumlinux_arm/AppRun new file mode 100755 index 000000000..410dafd05 --- /dev/null +++ b/buildapp/terrarumlinux_arm/AppRun @@ -0,0 +1,3 @@ +#!/bin/bash +cd "${0%/*}" +./runtime-linux-arm/bin/java -Xms1G -Xmx6G -jar ./assets/TerrarumBuild.jar diff --git a/buildapp/terrarumlinux_arm/Terrarum.desktop b/buildapp/terrarumlinux_arm/Terrarum.desktop new file mode 100644 index 000000000..abf3a6cd6 --- /dev/null +++ b/buildapp/terrarumlinux_arm/Terrarum.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=Terrarum +Exec=AppRun +Icon=icns +Type=Application +Categories=Game; \ No newline at end of file diff --git a/buildapp/terrarumlinux_x86/AppRun b/buildapp/terrarumlinux_x86/AppRun new file mode 100755 index 000000000..798aa9835 --- /dev/null +++ b/buildapp/terrarumlinux_x86/AppRun @@ -0,0 +1,3 @@ +#!/bin/bash +cd "${0%/*}" +./runtime-linux-x86/bin/java -Xms1G -Xmx6G -jar ./assets/TerrarumBuild.jar diff --git a/buildapp/terrarumlinux_x86/Terrarum.desktop b/buildapp/terrarumlinux_x86/Terrarum.desktop new file mode 100644 index 000000000..abf3a6cd6 --- /dev/null +++ b/buildapp/terrarumlinux_x86/Terrarum.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name=Terrarum +Exec=AppRun +Icon=icns +Type=Application +Categories=Game; \ No newline at end of file diff --git a/buildapp/terrarummac_arm/Info.plist b/buildapp/terrarummac_arm/Info.plist new file mode 100644 index 000000000..0f220daba --- /dev/null +++ b/buildapp/terrarummac_arm/Info.plist @@ -0,0 +1,8 @@ + + + + + CFBundleExecutable + Terrarum.sh + + \ No newline at end of file diff --git a/buildapp/terrarummac_arm/Terrarum.sh b/buildapp/terrarummac_arm/Terrarum.sh new file mode 100755 index 000000000..f03de8e4f --- /dev/null +++ b/buildapp/terrarummac_arm/Terrarum.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd "${0%/*}" +./runtime-arm-x86/bin/java -Xms1G -Xmx6G -jar ./assets/TerrarumBuild.jar diff --git a/buildapp/terrarummac_x86/Info.plist b/buildapp/terrarummac_x86/Info.plist new file mode 100644 index 000000000..0f220daba --- /dev/null +++ b/buildapp/terrarummac_x86/Info.plist @@ -0,0 +1,8 @@ + + + + + CFBundleExecutable + Terrarum.sh + + \ No newline at end of file diff --git a/buildapp/terrarummac_x86/Terrarum.sh b/buildapp/terrarummac_x86/Terrarum.sh new file mode 100755 index 000000000..6e87bdaa2 --- /dev/null +++ b/buildapp/terrarummac_x86/Terrarum.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd "${0%/*}" +./runtime-osx-x86/bin/java -Xms1G -Xmx6G -jar ./assets/TerrarumBuild.jar diff --git a/buildapp/terrarumwindows_x86/Terrarum.bat b/buildapp/terrarumwindows_x86/Terrarum.bat new file mode 100755 index 000000000..1eadf130b --- /dev/null +++ b/buildapp/terrarumwindows_x86/Terrarum.bat @@ -0,0 +1,2 @@ +cd /D "%~dp0" +.\runtime-windows-x86\bin\java -Xms1G -Xmx6G -jar .\assets\TerrarumBuild.jar diff --git a/how_to_build_jre_with_jlink.md b/how_to_build_jre_with_jlink.md deleted file mode 100644 index d6fd346df..000000000 --- a/how_to_build_jre_with_jlink.md +++ /dev/null @@ -1,42 +0,0 @@ -### Preparation - -Download and unzip the JDK for the appropriate operation systems first! JDKs can be downloaded on https://jdk.java.net/archive/. - -Then, on the terminal, run following commands: - -jlink --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-linux-amd64 --no-header-files --no-man-pages --strip-debug --compress=2 - -jlink --module-path ~/Documents/openjdk/jdk-17.0.1-aarch64/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-linux-aarch64 --no-header-files --no-man-pages --strip-debug --compress=2 -jlink --module-path ~/Documents/openjdk/jdk-17.0.1-windows/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-windows-amd64 --no-header-files --no-man-pages --strip-debug --compress=2 -jlink --module-path ~/Documents/openjdk/jdk-17.0.1.jdk-aarch64/Contents/Home/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-osx-aarch64 --no-header-files --no-man-pages --strip-debug --compress=2 -jlink --module-path ~/Documents/openjdk/jdk-17.0.1.jdk-amd64/Contents/Home/jmods:mods --add-modules java.base,java.desktop,java.logging,jdk.unsupported --output ~/Documents/Terrarum/out/runtime-osx-amd64 --no-header-files --no-man-pages --strip-debug --compress=2 - -This process assumes that the game does NOT use the Java 9+ modules and every single required libraries are fat-jar'd (their contents extracted right into the Jar) - -### Packaging - -Create an output directory; its contents shall be: - -``` -+assets -+runtimes -`+runtime-linux-aarch64 -`+runtime-linux-amd64 -`+runtime-osx-amd64 -`+runtime-osx-aarch64 -`+runtime-windows-amd64 -`TerrarumBuild.jar -start_game_linux_aarch64.sh -start_game_linux_x86_64.sh -start_game_mac_aarch64.sh -start_game_mac_x86_64.sh -start_game_windows.bat -``` - -whereas `runtime-*` are runtime directories generated from the commands above, `TerrarumBuild.jar` is the artifact built using the TerrarumBuild. - -`start_game_*` files are on the root directory of the project; you only need to simply copy them over. - -Hide the `.jar` within the subdirectory; users will think this file is the main executable and will try to execute it using whatever JVM they may (or may not) have. - -And yes, I'm totally aware that `.sh` file says `x86_64` but the runtimes says `amd64`. \ No newline at end of file diff --git a/shit.kts b/shit.kts deleted file mode 100644 index ac59697b4..000000000 --- a/shit.kts +++ /dev/null @@ -1,26 +0,0 @@ -val list = intArrayOf(0,2,4,6,9,13,16,54,88) - -val ID = 555 - -var low = 0 -var high = list.size -var mid = -1 - -while (low < high) { - mid = (low + high).ushr(1) - - if (list[mid] > ID) - high = mid - else - low = mid + 1 - - low -} - -println("$low, $high, $mid") - -val ll = arrayListOf(1,1,1,1,1) -ll.add(5, 8) -println(ll) - -// take mid value? (except for ID < list[0]) \ No newline at end of file diff --git a/start_game_linux_aarch64.sh b/start_game_linux_aarch64.sh deleted file mode 100755 index 0f0767da6..000000000 --- a/start_game_linux_aarch64.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd "${0%/*}" -./runtimes/runtime-linux-aarch64/bin/java -Xms1G -Xmx6G -jar ./runtimes/TerrarumBuild.jar diff --git a/start_game_linux_x86_64.sh b/start_game_linux_x86_64.sh deleted file mode 100755 index 16908294f..000000000 --- a/start_game_linux_x86_64.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd "${0%/*}" -./runtimes/runtime-linux-amd64/bin/java -Xms1G -Xmx6G -jar ./runtimes/TerrarumBuild.jar diff --git a/start_game_mac_aarch64.sh b/start_game_mac_aarch64.sh deleted file mode 100755 index d4caaca9f..000000000 --- a/start_game_mac_aarch64.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd "${0%/*}" -./runtimes/runtime-osx-aarch64/bin/java -Xms1G -Xmx6G -jar ./runtimes/TerrarumBuild.jar diff --git a/start_game_mac_x86_64.sh b/start_game_mac_x86_64.sh deleted file mode 100755 index ddf13e039..000000000 --- a/start_game_mac_x86_64.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd "${0%/*}" -./runtimes/runtime-osx-amd64/bin/java -Xms1G -Xmx6G -jar ./runtimes/TerrarumBuild.jar diff --git a/start_game_windows.bat b/start_game_windows.bat deleted file mode 100755 index 458da61b7..000000000 --- a/start_game_windows.bat +++ /dev/null @@ -1,2 +0,0 @@ -cd /D "%~dp0" -runtimes\runtime-windows-amd64\bin\java -Xms1G -Xmx6G -jar .\runtimes\TerrarumBuild.jar