From 3b886e055d1114f32481cd246d23f410a1f8f8c3 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 16 Oct 2020 15:39:04 -0400 Subject: [PATCH] Add Native GL Option --- .gitignore | 1 + debian/client/DEBIAN/postinst | 5 ----- debian/client/common/DEBIAN/postinst | 5 +++++ .../client/{ => common}/usr/bin/minecraft-pi | 16 ++++----------- .../share/applications/minecraft-pi.desktop | 0 .../minecraft-pi/client/docker-compose.yml | 1 + .../usr/share/pixmaps/minecraft-pi.png | Bin debian/client/native/DEBIAN/control | 8 ++++++++ .../client/native/usr/lib/minecraft-pi/run.sh | 9 +++++++++ debian/client/{ => virgl}/DEBIAN/control | 3 ++- .../client/virgl/usr/lib/minecraft-pi/run.sh | 19 ++++++++++++++++++ mods/src/compat.c | 13 +++++++----- mods/src/extra.c | 16 ++++++++++++--- mods/src/extra.h | 2 +- scripts/build.sh | 2 +- scripts/package.sh | 14 +++++++++++-- 16 files changed, 84 insertions(+), 30 deletions(-) delete mode 100755 debian/client/DEBIAN/postinst create mode 100755 debian/client/common/DEBIAN/postinst rename debian/client/{ => common}/usr/bin/minecraft-pi (80%) rename debian/client/{ => common}/usr/share/applications/minecraft-pi.desktop (100%) rename debian/client/{ => common}/usr/share/minecraft-pi/client/docker-compose.yml (91%) rename debian/client/{ => common}/usr/share/pixmaps/minecraft-pi.png (100%) create mode 100644 debian/client/native/DEBIAN/control create mode 100644 debian/client/native/usr/lib/minecraft-pi/run.sh rename debian/client/{ => virgl}/DEBIAN/control (82%) create mode 100644 debian/client/virgl/usr/lib/minecraft-pi/run.sh diff --git a/.gitignore b/.gitignore index 8895e24be..e94549fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /core/build /mods/build /out +/debian/tmp diff --git a/debian/client/DEBIAN/postinst b/debian/client/DEBIAN/postinst deleted file mode 100755 index 7d4c2c683..000000000 --- a/debian/client/DEBIAN/postinst +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -MCPI_FEATURES='' MCPI_USERNAME='' docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml pull diff --git a/debian/client/common/DEBIAN/postinst b/debian/client/common/DEBIAN/postinst new file mode 100755 index 000000000..9e615293f --- /dev/null +++ b/debian/client/common/DEBIAN/postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +MCPI_MODE='' MCPI_FEATURES='' MCPI_USERNAME='' docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml pull diff --git a/debian/client/usr/bin/minecraft-pi b/debian/client/common/usr/bin/minecraft-pi similarity index 80% rename from debian/client/usr/bin/minecraft-pi rename to debian/client/common/usr/bin/minecraft-pi index 47c33a9d4..faa768c24 100755 --- a/debian/client/usr/bin/minecraft-pi +++ b/debian/client/common/usr/bin/minecraft-pi @@ -10,10 +10,6 @@ fi export MCPI_FEATURES export MCPI_USERNAME -# Start VirGL -virgl_test_server & -VIRGL_PID="$!" - # Ensure Groups Are Correct if [ -z "${MCPI_SUBSHELL}" ]; then if ! id -Gn "$(whoami)" | grep '\bdocker\b' > /dev/null; then @@ -25,13 +21,9 @@ fi # Allow X11 Connections From Root xhost local:root -# Launch Minecraft -DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml" +# Update Docker Container +export DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml" (${DOCKER_COMPOSE} pull || :) | zenity --class 'Minecraft - Pi edition' --progress --pulsate --no-cancel --auto-close --text 'Updating Minecraft...' -${DOCKER_COMPOSE} run --rm minecraft-pi || : -RET="$?" -# Kill VirGL -kill "${VIRGL_PID}" - -exit "${RET}" +# Run +/usr/lib/minecraft-pi/run.sh diff --git a/debian/client/usr/share/applications/minecraft-pi.desktop b/debian/client/common/usr/share/applications/minecraft-pi.desktop similarity index 100% rename from debian/client/usr/share/applications/minecraft-pi.desktop rename to debian/client/common/usr/share/applications/minecraft-pi.desktop diff --git a/debian/client/usr/share/minecraft-pi/client/docker-compose.yml b/debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml similarity index 91% rename from debian/client/usr/share/minecraft-pi/client/docker-compose.yml rename to debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml index a4fb39085..dea4c8be9 100644 --- a/debian/client/usr/share/minecraft-pi/client/docker-compose.yml +++ b/debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml @@ -11,3 +11,4 @@ services: - 'DISPLAY=unix${DISPLAY}' - 'MCPI_FEATURES=${MCPI_FEATURES}' - 'MCPI_USERNAME=${MCPI_USERNAME}' + - 'MCPI_MODE=${MCPI_MODE}' diff --git a/debian/client/usr/share/pixmaps/minecraft-pi.png b/debian/client/common/usr/share/pixmaps/minecraft-pi.png similarity index 100% rename from debian/client/usr/share/pixmaps/minecraft-pi.png rename to debian/client/common/usr/share/pixmaps/minecraft-pi.png diff --git a/debian/client/native/DEBIAN/control b/debian/client/native/DEBIAN/control new file mode 100644 index 000000000..d5e877412 --- /dev/null +++ b/debian/client/native/DEBIAN/control @@ -0,0 +1,8 @@ +Package: minecraft-pi-native +Version: 1.0.0 +Maintainer: TheBrokenRail +Description: Fun with Blocks +Homepage: https://www.minecraft.net/en-us/edition/pi +Architecture: all +Depends: docker.io, docker-compose, zenity, policykit-1, passwd, login, qemu-user-static, binfmt-support +Conflicts: minecraft-pi-virgl diff --git a/debian/client/native/usr/lib/minecraft-pi/run.sh b/debian/client/native/usr/lib/minecraft-pi/run.sh new file mode 100644 index 000000000..84375ea36 --- /dev/null +++ b/debian/client/native/usr/lib/minecraft-pi/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +# Enable VirGL +export MCPI_MODE=native + +# Launch Minecraft +${DOCKER_COMPOSE} run --rm minecraft-pi \ No newline at end of file diff --git a/debian/client/DEBIAN/control b/debian/client/virgl/DEBIAN/control similarity index 82% rename from debian/client/DEBIAN/control rename to debian/client/virgl/DEBIAN/control index 56331a770..7db2872b7 100644 --- a/debian/client/DEBIAN/control +++ b/debian/client/virgl/DEBIAN/control @@ -1,7 +1,8 @@ -Package: minecraft-pi +Package: minecraft-pi-virgl Version: 1.0.0 Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: all Depends: docker.io, docker-compose, virgl-server, zenity, policykit-1, passwd, login, qemu-user-static, binfmt-support +Conflicts: minecraft-pi-native diff --git a/debian/client/virgl/usr/lib/minecraft-pi/run.sh b/debian/client/virgl/usr/lib/minecraft-pi/run.sh new file mode 100644 index 000000000..e800768b4 --- /dev/null +++ b/debian/client/virgl/usr/lib/minecraft-pi/run.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +# Enable VirGL +export MCPI_MODE=virgl + +# Start VirGL +virgl_test_server & +VIRGL_PID="$!" + +# Launch Minecraft +${DOCKER_COMPOSE} run --rm minecraft-pi || : +RET="$?" + +# Kill VirGL +kill "${VIRGL_PID}" + +exit "${RET}" \ No newline at end of file diff --git a/mods/src/compat.c b/mods/src/compat.c index 0b5ad6fc1..fd8b0d3bc 100644 --- a/mods/src/compat.c +++ b/mods/src/compat.c @@ -41,7 +41,7 @@ static void store_x11_window() { // Handle GLFW Error static void glfw_error(__attribute__((unused)) int error, const char *description) { - fprintf(stderr, "GLFW Error: %s\n", description); + fprintf(stderr, "[ERR] GLFW Error: %s\n", description); exit(1); } @@ -465,9 +465,12 @@ HOOK(eglTerminate, EGLBoolean, (__attribute__((unused)) EGLDisplay display)) { // Use VirGL __attribute__((constructor)) static void init() { - is_server = extra_get_is_server(); - setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); - if (!is_server) { - setenv("GALLIUM_DRIVER", "virpipe", 1); + int mode = extra_get_mode(); + if (mode == 0) { + setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); + if (!is_server) { + setenv("GALLIUM_DRIVER", "virpipe", 1); + } } + is_server = mode == 2; } diff --git a/mods/src/extra.c b/mods/src/extra.c index 3f37a8a71..64436e46b 100644 --- a/mods/src/extra.c +++ b/mods/src/extra.c @@ -154,12 +154,22 @@ int extra_has_feature(const char *name) { } } -int extra_get_is_server() { - return getenv("MCPI_SERVER") != NULL; +int extra_get_mode() { + char *mode = getenv("MCPI_MODE"); + if (strcmp("virgl", mode) == 0) { + return 0; + } else if (strcmp("native", mode) == 0) { + return 1; + } else if (strcmp("server", mode) == 0) { + return 2; + } else { + fprintf(stderr, "[ERR] Inavlid MCPI_MODE: %s\n", mode); + exit(1); + } } __attribute__((constructor)) static void init() { - is_server = extra_get_is_server(); + is_server = extra_get_mode() == 2; if (is_server) { server_init(); } diff --git a/mods/src/extra.h b/mods/src/extra.h index 21fc2cb04..146e0e8ad 100644 --- a/mods/src/extra.h +++ b/mods/src/extra.h @@ -7,7 +7,7 @@ extern "C" { #endif int extra_has_feature(const char *name); -int extra_get_is_server(); +int extra_get_mode(); void extra_key_press(char key); void extra_clear_input(); diff --git a/scripts/build.sh b/scripts/build.sh index ea8b76c13..8de51a720 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,4 +3,4 @@ set -e docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:client -f Dockerfile.client . -docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:server -f Dockerfile.server . +#docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:server -f Dockerfile.server . diff --git a/scripts/package.sh b/scripts/package.sh index 653c6421d..8f0503da9 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -9,8 +9,18 @@ chmod -R g-s debian rm -rf out mkdir -p out/deb -# Generate DEB -dpkg -b debian/client out/deb +# Package Client DEBs +package_client() { + rm -rf debian/tmp + rsync -r debian/client/common/ debian/tmp + rsync -r "debian/client/$1/" debian/tmp + dpkg -b debian/tmp out/deb + rm -rf debian/tmp +} +package_client virgl +package_client native + +# Package Server DEB dpkg -b debian/server out/deb # Export Libraries