From 7ac5d15737e33514a6f4f973e4aba7e7b3eb7a4b Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 6 Oct 2020 11:08:10 -0400 Subject: [PATCH] Clean Up Compat Code --- mods/src/compat.c | 97 +++++++++++++++++++--------------------------- scripts/package.sh | 4 +- 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/mods/src/compat.c b/mods/src/compat.c index ee70c16a..77dc6237 100644 --- a/mods/src/compat.c +++ b/mods/src/compat.c @@ -28,11 +28,6 @@ static Window x11_window; static Window x11_root_window; static int window_loaded = 0; -HOOK(eglGetDisplay, EGLDisplay, (__attribute__((unused)) NativeDisplayType native_display)) { - // Handled In ensure_x11_window() - return 0; -} - // Get Reference To X Window static void store_x11_window() { x11_display = glfwGetX11Display(); @@ -42,57 +37,6 @@ static void store_x11_window() { window_loaded = 1; } -// Handled In SDL_WM_SetCaption -HOOK(eglInitialize, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLint *major, __attribute__((unused)) EGLint *minor)) { - return EGL_TRUE; -} - -// Handled In SDL_WM_SetCaption -HOOK(eglChooseConfig, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLint const *attrib_list, __attribute__((unused)) EGLConfig *configs, __attribute__((unused)) EGLint config_size, __attribute__((unused)) EGLint *num_config)) { - return EGL_TRUE; -} - -// Handled In SDL_WM_SetCaption -HOOK(eglBindAPI, EGLBoolean, (__attribute__((unused)) EGLenum api)) { - return EGL_TRUE; -} - -// Handled In SDL_WM_SetCaption -HOOK(eglCreateContext, EGLContext, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) EGLContext share_context, __attribute__((unused)) EGLint const *attrib_list)) { - return 0; -} - -// Handled In SDL_WM_SetCaption -HOOK(eglCreateWindowSurface, EGLSurface, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) NativeWindowType native_window, __attribute__((unused)) EGLint const *attrib_list)) { - return 0; -} - -// Handled In SDL_WM_SetCaption -HOOK(eglMakeCurrent, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface draw, __attribute__((unused)) EGLSurface read, __attribute__((unused)) EGLContext context)) { - return EGL_TRUE; -} - -// Handled In SDL_Quit -HOOK(eglDestroySurface, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface)) { - return EGL_TRUE; -} - -// Handled In SDL_Quit -HOOK(eglDestroyContext, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLContext context)) { - return EGL_TRUE; -} - -// Handled In SDL_Quit -HOOK(eglTerminate, EGLBoolean, (__attribute__((unused)) EGLDisplay display)) { - return EGL_TRUE; -} - -// Handled In SDL_WM_SetCaption -HOOK(SDL_SetVideoMode, SDL_Surface *, (__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags)) { - // Return Value Is Only Used For A NULL-Check - return (SDL_Surface *) 1; -} - // Handle GLFW Error static void glfw_error(__attribute__((unused)) int error, const char *description) { fprintf(stderr, "GLFW Error: %s\n", description); @@ -392,7 +336,7 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) { return ret; } -// Terminate EGL +// Terminate GLFW HOOK(SDL_Quit, void, ()) { ensure_SDL_Quit(); (*real_SDL_Quit)(); @@ -425,6 +369,12 @@ HOOK(SDL_ShowCursor, int, (int toggle)) { return toggle == SDL_QUERY ? (glfwGetInputMode(glfw_window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL ? SDL_ENABLE : SDL_DISABLE) : toggle; } +// SDL Stub +HOOK(SDL_SetVideoMode, SDL_Surface *, (__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags)) { + // Return Value Is Only Used For A NULL-Check + return (SDL_Surface *) 1; +} + HOOK(XTranslateCoordinates, int, (Display *display, Window src_w, Window dest_w, int src_x, int src_y, int *dest_x_return, int *dest_y_return, Window *child_return)) { ensure_XTranslateCoordinates(); if (window_loaded) { @@ -443,6 +393,39 @@ HOOK(XGetWindowAttributes, int, (Display *display, Window w, XWindowAttributes * } } +// EGL Stubs + +HOOK(eglGetDisplay, EGLDisplay, (__attribute__((unused)) NativeDisplayType native_display)) { + return 0; +} +HOOK(eglInitialize, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLint *major, __attribute__((unused)) EGLint *minor)) { + return EGL_TRUE; +} +HOOK(eglChooseConfig, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLint const *attrib_list, __attribute__((unused)) EGLConfig *configs, __attribute__((unused)) EGLint config_size, __attribute__((unused)) EGLint *num_config)) { + return EGL_TRUE; +} +HOOK(eglBindAPI, EGLBoolean, (__attribute__((unused)) EGLenum api)) { + return EGL_TRUE; +} +HOOK(eglCreateContext, EGLContext, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) EGLContext share_context, __attribute__((unused)) EGLint const *attrib_list)) { + return 0; +} +HOOK(eglCreateWindowSurface, EGLSurface, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) NativeWindowType native_window, __attribute__((unused)) EGLint const *attrib_list)) { + return 0; +} +HOOK(eglMakeCurrent, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface draw, __attribute__((unused)) EGLSurface read, __attribute__((unused)) EGLContext context)) { + return EGL_TRUE; +} +HOOK(eglDestroySurface, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface)) { + return EGL_TRUE; +} +HOOK(eglDestroyContext, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLContext context)) { + return EGL_TRUE; +} +HOOK(eglTerminate, EGLBoolean, (__attribute__((unused)) EGLDisplay display)) { + return EGL_TRUE; +} + #include // Use VirGL diff --git a/scripts/package.sh b/scripts/package.sh index 0090dbaa..256be33d 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -19,4 +19,6 @@ mkdir -p out/lib cp -r mods/include out/lib/include # Copy Shared Library -docker run -v "$(pwd)/out/lib:/out" --entrypoint sh thebrokenrail/minecraft-pi -c 'cp ./mods/lib*.so /out' +IMG_ID="$(docker create thebrokenrail/minecraft-pi)" +docker cp "${IMG_ID}":/app/minecraft-pi/mods/. ./out/lib/. +docker rm -v "${IMG_ID}"