Remove SDL Dependency
This commit is contained in:
parent
521d10a9fd
commit
f8836fb2ae
@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN \
|
||||
# Install Runtime Dependencies
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends tini libgles1 libx11-6 libsdl1.2debian zlib1g libfreeimage3 libglfw3 xinput libxfixes3 gosu tk && \
|
||||
apt-get install -y --no-install-recommends tini libgles1 libx11-6 zlib1g libfreeimage3 libglfw3 xinput libxfixes3 gosu tk && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Compile Environment
|
||||
@ -43,9 +43,7 @@ RUN \
|
||||
mkdir -p /home && \
|
||||
chmod -R a+rw /home
|
||||
|
||||
# Include Exported Libraries
|
||||
COPY --from=build /app/export /
|
||||
# Include Mods
|
||||
# Copy Build
|
||||
COPY --from=build /app/minecraft-pi /app/minecraft-pi
|
||||
|
||||
WORKDIR /app/minecraft-pi
|
||||
|
@ -6,10 +6,12 @@ git clone --depth 1 https://git.code.sf.net/p/libpng/code libpng -b libpng12
|
||||
|
||||
cd libpng
|
||||
|
||||
./configure --prefix /usr
|
||||
./configure
|
||||
|
||||
make -j$(nproc)
|
||||
make install DESTDIR=/app/export
|
||||
|
||||
mkdir -p ../minecraft-pi/lib
|
||||
cp -L .libs/libpng12.so.0 ../minecraft-pi/lib
|
||||
|
||||
cd ../
|
||||
|
||||
|
@ -4,8 +4,31 @@ project(launcher)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Werror)
|
||||
|
||||
## Launcher
|
||||
|
||||
add_executable(launcher src/launcher.c)
|
||||
|
||||
# Install
|
||||
install(TARGETS launcher DESTINATION /)
|
||||
install(PROGRAMS src/run.sh DESTINATION /)
|
||||
install(PROGRAMS src/run.sh DESTINATION /)
|
||||
|
||||
## Stubs
|
||||
|
||||
# Stub RPI-Specific Graphics
|
||||
add_library(bcm_host SHARED src/stubs/bcm_host.c)
|
||||
|
||||
# Stub EGL
|
||||
add_library(EGL SHARED src/stubs/EGL.c)
|
||||
|
||||
# Stub SDL
|
||||
add_library(SDL-1.2 SHARED src/stubs/SDL.cpp)
|
||||
target_link_libraries(SDL-1.2 pthread)
|
||||
set_target_properties(SDL-1.2 PROPERTIES SOVERSION "0")
|
||||
|
||||
# MCPI Links Against GLESv2 But Uses GLESv1_CM
|
||||
add_library(GLESv2 SHARED src/stubs/GLESv2.c)
|
||||
target_link_libraries(GLESv2 GLESv1_CM)
|
||||
target_link_options(GLESv2 PRIVATE "-Wl,--no-as-needed")
|
||||
|
||||
# Install Stubs
|
||||
install(TARGETS bcm_host EGL SDL-1.2 GLESv2 DESTINATION /lib)
|
@ -9,10 +9,10 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// Check String Prefix/Suffix
|
||||
static int starts_with(const char *s, const char *t) {
|
||||
return strncmp(s, t, strlen(t)) == 0;
|
||||
}
|
||||
|
||||
static int ends_with(const char *s, const char *t) {
|
||||
size_t slen = strlen(s);
|
||||
size_t tlen = strlen(t);
|
||||
@ -20,6 +20,7 @@ static int ends_with(const char *s, const char *t) {
|
||||
return strcmp(s + slen - tlen, t) == 0;
|
||||
}
|
||||
|
||||
// Set Environmental Variable
|
||||
static void trim(char *value) {
|
||||
// Remove Trailing Colon
|
||||
int length = strlen(value);
|
||||
@ -27,26 +28,30 @@ static void trim(char *value) {
|
||||
value[length - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void set_and_print_env(char *name, char *value) {
|
||||
// Set Variable With Not Trailing Colon
|
||||
// Set Variable With No Trailing Colon
|
||||
trim(value);
|
||||
|
||||
fprintf(stderr, "Set %s = %s\n", name, value);
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
// Get Environmental Variable
|
||||
static char *get_env_safe(const char *name) {
|
||||
// Get Variable Or Blank String If Not Set
|
||||
char *ret = getenv(name);
|
||||
return ret != NULL ? ret : "";
|
||||
}
|
||||
|
||||
static void load(char **ld_path, char **ld_preload, char *folder) {
|
||||
// Get All SO Files In Folder
|
||||
static void load(char **ld_preload, char *folder) {
|
||||
int folder_name_length = strlen(folder);
|
||||
// Retry Until Successful
|
||||
while (1) {
|
||||
// Open Folder
|
||||
DIR *dp = opendir(folder);
|
||||
if (dp != NULL) {
|
||||
// Loop Through Folder
|
||||
struct dirent *entry = NULL;
|
||||
errno = 0;
|
||||
while (1) {
|
||||
@ -75,14 +80,14 @@ static void load(char **ld_path, char **ld_preload, char *folder) {
|
||||
fprintf(stderr, "Error Reading Directory: %s: %s\n", folder, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
// Done!
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Close Folder
|
||||
closedir(dp);
|
||||
|
||||
// Add To LD_LIBRARY_PATH
|
||||
asprintf(ld_path, "%s:%s", *ld_path, folder);
|
||||
|
||||
// Exit Function
|
||||
return;
|
||||
} else if (errno == ENOENT) {
|
||||
// Folder Doesn't Exists, Attempt Creation
|
||||
@ -92,6 +97,7 @@ static void load(char **ld_path, char **ld_preload, char *folder) {
|
||||
fprintf(stderr, "Error Creating Directory: %s: %s\n", folder, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Continue Retrying
|
||||
} else {
|
||||
// Unable To Open Folder
|
||||
fprintf(stderr, "Error Opening Directory: %s: %s\n", folder, strerror(errno));
|
||||
@ -121,31 +127,25 @@ int main(__attribute__((unused)) int argc, char *argv[]) {
|
||||
}
|
||||
free(minecraft_folder);
|
||||
|
||||
char *ld_path = NULL;
|
||||
|
||||
// Start Configuring LD_LIBRARY_PATH
|
||||
asprintf(&ld_path, "/usr/arm-linux-gnueabihf/lib");
|
||||
// Configure LD_LIBRARY_PATH
|
||||
char *ld_path;
|
||||
asprintf(&ld_path, "./lib:/usr/arm-linux-gnueabihf/lib:%s", get_env_safe("LD_LIBRARY_PATH"));
|
||||
set_and_print_env("LD_LIBRARY_PATH", ld_path);
|
||||
free(ld_path);
|
||||
|
||||
// Start Configuring LD_PRELOAD
|
||||
char *ld_preload = NULL;
|
||||
asprintf(&ld_preload, "%s", get_env_safe("LD_PRELOAD"));
|
||||
|
||||
// Load Mods From ./mods
|
||||
load(&ld_path, &ld_preload, "./mods/");
|
||||
load(&ld_preload, "./mods/");
|
||||
|
||||
// Loads Mods From ~/.minecraft-pi/mods
|
||||
char *home_mods = NULL;
|
||||
asprintf(&home_mods, "%s/.minecraft-pi/mods/", getenv("HOME"));
|
||||
load(&ld_path, &ld_preload, home_mods);
|
||||
load(&ld_preload, home_mods);
|
||||
free(home_mods);
|
||||
|
||||
// Add Existing LD_LIBRARY_PATH
|
||||
asprintf(&ld_path, "%s:%s", ld_path, get_env_safe("LD_LIBRARY_PATH"));
|
||||
|
||||
// Set LD_LIBRARY_PATH
|
||||
set_and_print_env("LD_LIBRARY_PATH", ld_path);
|
||||
free(ld_path);
|
||||
|
||||
// Set LD_PRELOAD
|
||||
set_and_print_env("LD_PRELOAD", ld_preload);
|
||||
free(ld_preload);
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include "../compat/compat.h"
|
||||
|
||||
// EGL/SDL Is Replaced With GLFW
|
||||
// EGL Is Replaced With GLFW
|
||||
|
||||
EGLDisplay eglGetDisplay(__attribute__((unused)) NativeDisplayType native_display) {
|
||||
return 0;
|
||||
@ -34,9 +32,6 @@ EGLBoolean eglDestroyContext(__attribute__((unused)) EGLDisplay display, __attri
|
||||
EGLBoolean eglTerminate(__attribute__((unused)) EGLDisplay display) {
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
// Send Buffer Swap Request To GLFW
|
||||
EGLBoolean eglSwapBuffers(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface) {
|
||||
compat_eglSwapBuffers();
|
||||
return EGL_TRUE;
|
||||
}
|
41
launcher/src/stubs/SDL.cpp
Normal file
41
launcher/src/stubs/SDL.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <vector>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
// SDL Is Replaced With GLFW
|
||||
|
||||
int SDL_Init(__attribute__((unused)) uint32_t flags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_Quit() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Event Queue
|
||||
|
||||
static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static std::vector<SDL_Event> queue;
|
||||
|
||||
int SDL_PollEvent(SDL_Event *event) {
|
||||
pthread_mutex_lock(&queue_mutex);
|
||||
int ret;
|
||||
if (queue.size() > 0) {
|
||||
*event = queue[0];
|
||||
queue.erase(queue.begin());
|
||||
ret = 1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&queue_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SDL_PushEvent(SDL_Event *event) {
|
||||
pthread_mutex_lock(&queue_mutex);
|
||||
queue.push_back(*event);
|
||||
pthread_mutex_unlock(&queue_mutex);
|
||||
return 1;
|
||||
}
|
@ -12,9 +12,6 @@ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
|
||||
# Add libreborn
|
||||
add_subdirectory(../libreborn libreborn)
|
||||
|
||||
# Include Libraries Exported To Runtime Environment
|
||||
include_directories(/app/export/include)
|
||||
|
||||
# Find GLFW
|
||||
find_package(glfw3 3.3 REQUIRED)
|
||||
|
||||
@ -64,19 +61,5 @@ target_link_libraries(test reborn)
|
||||
add_library(init SHARED src/init/init.c)
|
||||
target_link_libraries(init compat server game_mode camera input misc options textures chat test)
|
||||
|
||||
## Stubs
|
||||
|
||||
# Stub RPI-Specific Graphics
|
||||
add_library(bcm_host SHARED src/stubs/bcm_host.c)
|
||||
|
||||
# Stub EGL
|
||||
add_library(EGL SHARED src/stubs/EGL.c)
|
||||
target_link_libraries(EGL compat)
|
||||
|
||||
# MCPI Links Against GLESv2 But Uses GLESv1_CM
|
||||
add_library(GLESv2 SHARED src/stubs/GLESv2.c)
|
||||
target_link_libraries(GLESv2 GLESv1_CM)
|
||||
target_link_options(GLESv2 PRIVATE "-Wl,--no-as-needed")
|
||||
|
||||
## Install
|
||||
install(TARGETS init compat readdir feature screenshot override server game_mode camera input misc options textures chat test bcm_host EGL GLESv2 DESTINATION /mods)
|
||||
## Install Mods
|
||||
install(TARGETS init compat readdir feature screenshot override server game_mode camera input misc options textures chat test DESTINATION /mods)
|
@ -13,6 +13,7 @@
|
||||
#include <SDL/SDL_syswm.h>
|
||||
#include <GLES/gl.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
|
||||
@ -22,8 +23,6 @@
|
||||
#include "../chat/chat.h"
|
||||
#include "../init/init.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
static GLFWwindow *glfw_window;
|
||||
|
||||
static int is_server = 0;
|
||||
@ -212,11 +211,12 @@ HOOK(SDL_WM_SetCaption, void, (const char *title, __attribute__((unused)) const
|
||||
}
|
||||
}
|
||||
|
||||
void compat_eglSwapBuffers() {
|
||||
HOOK(eglSwapBuffers, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface)) {
|
||||
if (!is_server) {
|
||||
// Don't Swap Buffers In A Context-Less Window
|
||||
glfwSwapBuffers(glfw_window);
|
||||
}
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
static int is_fullscreen = 0;
|
||||
|
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
void compat_eglSwapBuffers();
|
Loading…
Reference in New Issue
Block a user