mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-06-17 21:48:32 -04:00
rework: SDL detection
Now uses SDL_Init call to detect if SDL is being used.
This commit is contained in:
@@ -227,7 +227,6 @@ class SDLJoystickHandler {
|
||||
*/
|
||||
synchronized void pollInputDevices() {
|
||||
if (!firstPollDone) {
|
||||
MinecraftGLSurface.sdlEnabled = true;
|
||||
if (sDirectGamepadEnableHandler != null){
|
||||
sDirectGamepadEnableHandler.onDirectGamepadEnabled();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.annotation.Keep;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.libsdl.app.SDLActivity;
|
||||
import org.libsdl.app.SDLSurface;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -60,7 +61,7 @@ public class CallbackBridge {
|
||||
mouseY = y;
|
||||
nativeSendCursorPos(mouseX, mouseY);
|
||||
// HOVER_MOVE and MOVE are equivalent in SDL
|
||||
SDLActivity.onNativeMouse(0, MotionEvent.ACTION_MOVE, x, y, true);
|
||||
SDLActivity.onNativeMouse(0, MotionEvent.ACTION_MOVE, x, y, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +123,7 @@ public class CallbackBridge {
|
||||
public static void sendMouseKeycode(int button, int modifiers, boolean isDown) {
|
||||
// if (isGrabbing()) DEBUG_STRING.append("MouseGrabStrace: " + android.util.Log.getStackTraceString(new Throwable()) + "\n");
|
||||
nativeSendMouseButton(button, isDown ? 1 : 0, modifiers);
|
||||
SDLActivity.onNativeMouse(button, isDown ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP, mouseX, mouseY, true);
|
||||
SDLActivity.onNativeMouse(button, isDown ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP, mouseX, mouseY, false);
|
||||
}
|
||||
|
||||
public static void sendMouseKeycode(int keycode) {
|
||||
@@ -167,6 +168,31 @@ public class CallbackBridge {
|
||||
}
|
||||
}
|
||||
|
||||
// Notification types
|
||||
private static final int SDL = 0;
|
||||
|
||||
// Notification actions
|
||||
private static final int INIT = 0;
|
||||
/**
|
||||
* Used for any sort of notification that needs to be given from the JRE side
|
||||
* @return if notification successful
|
||||
*/
|
||||
// Called from JRE side via jni
|
||||
@SuppressWarnings("unused")
|
||||
@Keep
|
||||
public static boolean notifyLauncher(int type, int... action) {
|
||||
switch (type) {
|
||||
case SDL:
|
||||
if (action[0] == INIT) {
|
||||
MinecraftGLSurface.sdlEnabled = true;
|
||||
// Notifies SDL of native surface res which is needed for proper input handling
|
||||
SDLActivity.getSDLSurface().surfaceChanged();
|
||||
Logger.appendToLog("Amethyst-Android: SDL support enabled!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getCurrentMods() {
|
||||
int currMods = 0;
|
||||
|
||||
@@ -52,6 +52,7 @@ struct pojav_environ_s {
|
||||
jmethodID method_internalWindowSizeChanged;
|
||||
jmethodID method_internalChangeMonitorSize;
|
||||
jmethodID method_getAndroidDPI;
|
||||
jmethodID method_notifyLauncher;
|
||||
jclass bridgeClazz;
|
||||
jclass vmGlfwClass;
|
||||
jboolean isGrabbing;
|
||||
|
||||
@@ -59,6 +59,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
pojav_environ->method_onGrabStateChanged = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
|
||||
pojav_environ->method_onDirectInputEnable = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onDirectInputEnable", "()V");
|
||||
pojav_environ->method_getAndroidDPI = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "getAndroidDPI", "()F");
|
||||
pojav_environ->method_notifyLauncher = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "notifyLauncher", "(I[I)Z");
|
||||
pojav_environ->isUseStackQueueCall = JNI_FALSE;
|
||||
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
|
||||
LOGI("Saving JVM environ...");
|
||||
@@ -332,6 +333,13 @@ JNIEXPORT jfloat JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeGetAndroidDPI(
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeNotifyLauncher(JNIEnv* env, __attribute__((unused)) jclass clazz, jint type, jintArray action) {
|
||||
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeNotifyLauncher failed!\n",);
|
||||
jboolean result = (*dvm_env)->CallStaticBooleanMethod(dvm_env, pojav_environ->bridgeClazz,
|
||||
pojav_environ->method_notifyLauncher, type, convertIntArrayJVM(env, dvm_env, action));
|
||||
return result;
|
||||
}
|
||||
|
||||
jboolean critical_send_char(jchar codepoint) {
|
||||
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
|
||||
@@ -59,6 +59,22 @@ jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr) {
|
||||
return dstStr;
|
||||
}
|
||||
|
||||
jintArray convertIntArrayJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jintArray srcIntArray) {
|
||||
if (srcIntArray == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jsize len = (*srcEnv)->GetArrayLength(srcEnv, srcIntArray);
|
||||
jint* srcPtr = (*srcEnv)->GetIntArrayElements(srcEnv, srcIntArray, NULL);
|
||||
|
||||
jintArray dstIntArray = (*dstEnv)->NewIntArray(dstEnv, len);
|
||||
(*dstEnv)->SetIntArrayRegion(dstEnv, dstIntArray, 0, len, srcPtr);
|
||||
|
||||
(*srcEnv)->ReleaseIntArrayElements(srcEnv, srcIntArray, srcPtr, JNI_ABORT);
|
||||
|
||||
return dstIntArray;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeSurfaceAWT(JNIEnv *env, jclass clazz, jlong surface) {
|
||||
shared_awt_surface = surface;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
|
||||
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
|
||||
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
|
||||
jintArray convertIntArrayJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jintArray srcIntArray);
|
||||
|
||||
JNIEnv* get_attached_env(JavaVM* jvm);
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);
|
||||
|
||||
@@ -19,6 +19,11 @@ public class CallbackBridge {
|
||||
|
||||
public static final boolean INPUT_DEBUG_ENABLED;
|
||||
|
||||
// Notification types
|
||||
public static final int SDL = 0;
|
||||
// Notification actions
|
||||
public static final int INIT = 0;
|
||||
|
||||
public static boolean sGamepadDirectEnabled;
|
||||
|
||||
// TODO send grab state event to Android
|
||||
@@ -58,5 +63,6 @@ public class CallbackBridge {
|
||||
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
||||
private static native boolean nativeEnableGamepadDirectInput();
|
||||
public static native float nativeGetAndroidDPI();
|
||||
public static native boolean nativeNotifyLauncher(int type, int... action);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright LWJGL. All rights reserved.
|
||||
* License terms: https://www.lwjgl.org/license
|
||||
* MACHINE GENERATED FILE, DO NOT EDIT
|
||||
*/
|
||||
package org.lwjgl.sdl;
|
||||
|
||||
import static org.lwjgl.system.APIUtil.apiGetFunctionAddress;
|
||||
import static org.lwjgl.system.Checks.CHECKS;
|
||||
import static org.lwjgl.system.Checks.checkNT1;
|
||||
import static org.lwjgl.system.Checks.checkNT1Safe;
|
||||
import static org.lwjgl.system.JNI.invokeI;
|
||||
import static org.lwjgl.system.JNI.invokePP;
|
||||
import static org.lwjgl.system.JNI.invokePPPZ;
|
||||
import static org.lwjgl.system.JNI.invokePPZ;
|
||||
import static org.lwjgl.system.JNI.invokeV;
|
||||
import static org.lwjgl.system.JNI.invokeZ;
|
||||
import static org.lwjgl.system.MemoryStack.stackGet;
|
||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||
import static org.lwjgl.system.MemoryUtil.memAddress;
|
||||
import static org.lwjgl.system.MemoryUtil.memAddressSafe;
|
||||
import static org.lwjgl.system.MemoryUtil.memUTF8Safe;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.NativeType;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SDLInit {
|
||||
|
||||
/** Contains the function pointers loaded from {@code SDL.getLibrary()}. */
|
||||
public static final class Functions {
|
||||
|
||||
private Functions() {}
|
||||
|
||||
/** Function address. */
|
||||
public static final long
|
||||
Init = apiGetFunctionAddress(SDL.getLibrary(), "SDL_Init"),
|
||||
InitSubSystem = apiGetFunctionAddress(SDL.getLibrary(), "SDL_InitSubSystem"),
|
||||
QuitSubSystem = apiGetFunctionAddress(SDL.getLibrary(), "SDL_QuitSubSystem"),
|
||||
WasInit = apiGetFunctionAddress(SDL.getLibrary(), "SDL_WasInit"),
|
||||
Quit = apiGetFunctionAddress(SDL.getLibrary(), "SDL_Quit"),
|
||||
IsMainThread = apiGetFunctionAddress(SDL.getLibrary(), "SDL_IsMainThread"),
|
||||
RunOnMainThread = apiGetFunctionAddress(SDL.getLibrary(), "SDL_RunOnMainThread"),
|
||||
SetAppMetadata = apiGetFunctionAddress(SDL.getLibrary(), "SDL_SetAppMetadata"),
|
||||
SetAppMetadataProperty = apiGetFunctionAddress(SDL.getLibrary(), "SDL_SetAppMetadataProperty"),
|
||||
GetAppMetadataProperty = apiGetFunctionAddress(SDL.getLibrary(), "SDL_GetAppMetadataProperty");
|
||||
|
||||
}
|
||||
|
||||
public static final int
|
||||
SDL_INIT_AUDIO = 0x00000010,
|
||||
SDL_INIT_VIDEO = 0x00000020,
|
||||
SDL_INIT_JOYSTICK = 0x00000200,
|
||||
SDL_INIT_HAPTIC = 0x00001000,
|
||||
SDL_INIT_GAMEPAD = 0x00002000,
|
||||
SDL_INIT_EVENTS = 0x00004000,
|
||||
SDL_INIT_SENSOR = 0x00008000,
|
||||
SDL_INIT_CAMERA = 0x00010000;
|
||||
|
||||
public static final int
|
||||
SDL_APP_CONTINUE = 0,
|
||||
SDL_APP_SUCCESS = 1,
|
||||
SDL_APP_FAILURE = 2;
|
||||
|
||||
public static final String
|
||||
SDL_PROP_APP_METADATA_NAME_STRING = "SDL.app.metadata.name",
|
||||
SDL_PROP_APP_METADATA_VERSION_STRING = "SDL.app.metadata.version",
|
||||
SDL_PROP_APP_METADATA_IDENTIFIER_STRING = "SDL.app.metadata.identifier",
|
||||
SDL_PROP_APP_METADATA_CREATOR_STRING = "SDL.app.metadata.creator",
|
||||
SDL_PROP_APP_METADATA_COPYRIGHT_STRING = "SDL.app.metadata.copyright",
|
||||
SDL_PROP_APP_METADATA_URL_STRING = "SDL.app.metadata.url",
|
||||
SDL_PROP_APP_METADATA_TYPE_STRING = "SDL.app.metadata.type";
|
||||
|
||||
protected SDLInit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// --- [ SDL_Init ] ---
|
||||
/** {@code bool SDL_Init(SDL_InitFlags flags)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_Init(@NativeType("SDL_InitFlags") int flags) {
|
||||
CallbackBridge.nativeNotifyLauncher(CallbackBridge.SDL, CallbackBridge.INIT);
|
||||
long __functionAddress = Functions.Init;
|
||||
return invokeZ(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_InitSubSystem ] ---
|
||||
|
||||
/** {@code bool SDL_InitSubSystem(SDL_InitFlags flags)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_InitSubSystem(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.InitSubSystem;
|
||||
return invokeZ(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_QuitSubSystem ] ---
|
||||
|
||||
/** {@code void SDL_QuitSubSystem(SDL_InitFlags flags)} */
|
||||
public static void SDL_QuitSubSystem(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.QuitSubSystem;
|
||||
invokeV(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_WasInit ] ---
|
||||
|
||||
/** {@code SDL_InitFlags SDL_WasInit(SDL_InitFlags flags)} */
|
||||
@NativeType("SDL_InitFlags")
|
||||
public static int SDL_WasInit(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.WasInit;
|
||||
return invokeI(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_Quit ] ---
|
||||
|
||||
/** {@code void SDL_Quit(void)} */
|
||||
public static void SDL_Quit() {
|
||||
long __functionAddress = Functions.Quit;
|
||||
invokeV(__functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_IsMainThread ] ---
|
||||
|
||||
/** {@code bool SDL_IsMainThread(void)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_IsMainThread() {
|
||||
long __functionAddress = Functions.IsMainThread;
|
||||
return invokeZ(__functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_RunOnMainThread ] ---
|
||||
|
||||
/** {@code bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void * userdata, bool wait_complete)} */
|
||||
public static boolean nSDL_RunOnMainThread(long callback, long userdata, boolean wait_complete) {
|
||||
long __functionAddress = Functions.RunOnMainThread;
|
||||
return invokePPZ(callback, userdata, wait_complete, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void * userdata, bool wait_complete)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_RunOnMainThread(@NativeType("SDL_MainThreadCallback") SDL_MainThreadCallbackI callback, @NativeType("void *") long userdata, @NativeType("bool") boolean wait_complete) {
|
||||
return nSDL_RunOnMainThread(callback.address(), userdata, wait_complete);
|
||||
}
|
||||
|
||||
// --- [ SDL_SetAppMetadata ] ---
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
public static boolean nSDL_SetAppMetadata(long appname, long appversion, long appidentifier) {
|
||||
long __functionAddress = Functions.SetAppMetadata;
|
||||
return invokePPPZ(appname, appversion, appidentifier, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadata(@NativeType("char const *") @Nullable ByteBuffer appname, @NativeType("char const *") @Nullable ByteBuffer appversion, @NativeType("char const *") @Nullable ByteBuffer appidentifier) {
|
||||
if (CHECKS) {
|
||||
checkNT1Safe(appname);
|
||||
checkNT1Safe(appversion);
|
||||
checkNT1Safe(appidentifier);
|
||||
}
|
||||
return nSDL_SetAppMetadata(memAddressSafe(appname), memAddressSafe(appversion), memAddressSafe(appidentifier));
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadata(@NativeType("char const *") @Nullable CharSequence appname, @NativeType("char const *") @Nullable CharSequence appversion, @NativeType("char const *") @Nullable CharSequence appidentifier) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nUTF8Safe(appname, true);
|
||||
long appnameEncoded = appname == null ? NULL : stack.getPointerAddress();
|
||||
stack.nUTF8Safe(appversion, true);
|
||||
long appversionEncoded = appversion == null ? NULL : stack.getPointerAddress();
|
||||
stack.nUTF8Safe(appidentifier, true);
|
||||
long appidentifierEncoded = appidentifier == null ? NULL : stack.getPointerAddress();
|
||||
return nSDL_SetAppMetadata(appnameEncoded, appversionEncoded, appidentifierEncoded);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
// --- [ SDL_SetAppMetadataProperty ] ---
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
public static boolean nSDL_SetAppMetadataProperty(long name, long value) {
|
||||
long __functionAddress = Functions.SetAppMetadataProperty;
|
||||
return invokePPZ(name, value, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadataProperty(@NativeType("char const *") ByteBuffer name, @NativeType("char const *") ByteBuffer value) {
|
||||
if (CHECKS) {
|
||||
checkNT1(name);
|
||||
checkNT1(value);
|
||||
}
|
||||
return nSDL_SetAppMetadataProperty(memAddress(name), memAddress(value));
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadataProperty(@NativeType("char const *") CharSequence name, @NativeType("char const *") CharSequence value) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nASCII(name, true);
|
||||
long nameEncoded = stack.getPointerAddress();
|
||||
stack.nUTF8(value, true);
|
||||
long valueEncoded = stack.getPointerAddress();
|
||||
return nSDL_SetAppMetadataProperty(nameEncoded, valueEncoded);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
// --- [ SDL_GetAppMetadataProperty ] ---
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
public static long nSDL_GetAppMetadataProperty(long name) {
|
||||
long __functionAddress = Functions.GetAppMetadataProperty;
|
||||
return invokePP(name, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
@NativeType("char const *")
|
||||
public static @Nullable String SDL_GetAppMetadataProperty(@NativeType("char const *") ByteBuffer name) {
|
||||
if (CHECKS) {
|
||||
checkNT1(name);
|
||||
}
|
||||
long __result = nSDL_GetAppMetadataProperty(memAddress(name));
|
||||
return memUTF8Safe(__result);
|
||||
}
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
@NativeType("char const *")
|
||||
public static @Nullable String SDL_GetAppMetadataProperty(@NativeType("char const *") CharSequence name) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nASCII(name, true);
|
||||
long nameEncoded = stack.getPointerAddress();
|
||||
long __result = nSDL_GetAppMetadataProperty(nameEncoded);
|
||||
return memUTF8Safe(__result);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,11 @@ public class CallbackBridge {
|
||||
|
||||
public static final boolean INPUT_DEBUG_ENABLED;
|
||||
|
||||
// Notification types
|
||||
public static final int SDL = 0;
|
||||
// Notification actions
|
||||
public static final int INIT = 0;
|
||||
|
||||
public static boolean sGamepadDirectEnabled;
|
||||
|
||||
// TODO send grab state event to Android
|
||||
@@ -58,5 +63,6 @@ public class CallbackBridge {
|
||||
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
||||
private static native boolean nativeEnableGamepadDirectInput();
|
||||
public static native float nativeGetAndroidDPI();
|
||||
public static native boolean nativeNotifyLauncher(int type, int... action);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright LWJGL. All rights reserved.
|
||||
* License terms: https://www.lwjgl.org/license
|
||||
* MACHINE GENERATED FILE, DO NOT EDIT
|
||||
*/
|
||||
package org.lwjgl.sdl;
|
||||
|
||||
import org.jspecify.annotations.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
import org.lwjgl.system.*;
|
||||
|
||||
import static org.lwjgl.system.APIUtil.*;
|
||||
import static org.lwjgl.system.Checks.*;
|
||||
import static org.lwjgl.system.JNI.*;
|
||||
import static org.lwjgl.system.MemoryStack.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
public class SDLInit {
|
||||
|
||||
/** Contains the function pointers loaded from {@code SDL.getLibrary()}. */
|
||||
public static final class Functions {
|
||||
|
||||
private Functions() {}
|
||||
|
||||
/** Function address. */
|
||||
public static final long
|
||||
Init = apiGetFunctionAddress(SDL.getLibrary(), "SDL_Init"),
|
||||
InitSubSystem = apiGetFunctionAddress(SDL.getLibrary(), "SDL_InitSubSystem"),
|
||||
QuitSubSystem = apiGetFunctionAddress(SDL.getLibrary(), "SDL_QuitSubSystem"),
|
||||
WasInit = apiGetFunctionAddress(SDL.getLibrary(), "SDL_WasInit"),
|
||||
Quit = apiGetFunctionAddress(SDL.getLibrary(), "SDL_Quit"),
|
||||
IsMainThread = apiGetFunctionAddress(SDL.getLibrary(), "SDL_IsMainThread"),
|
||||
RunOnMainThread = apiGetFunctionAddress(SDL.getLibrary(), "SDL_RunOnMainThread"),
|
||||
SetAppMetadata = apiGetFunctionAddress(SDL.getLibrary(), "SDL_SetAppMetadata"),
|
||||
SetAppMetadataProperty = apiGetFunctionAddress(SDL.getLibrary(), "SDL_SetAppMetadataProperty"),
|
||||
GetAppMetadataProperty = apiGetFunctionAddress(SDL.getLibrary(), "SDL_GetAppMetadataProperty");
|
||||
|
||||
}
|
||||
|
||||
public static final int
|
||||
SDL_INIT_AUDIO = 0x00000010,
|
||||
SDL_INIT_VIDEO = 0x00000020,
|
||||
SDL_INIT_JOYSTICK = 0x00000200,
|
||||
SDL_INIT_HAPTIC = 0x00001000,
|
||||
SDL_INIT_GAMEPAD = 0x00002000,
|
||||
SDL_INIT_EVENTS = 0x00004000,
|
||||
SDL_INIT_SENSOR = 0x00008000,
|
||||
SDL_INIT_CAMERA = 0x00010000;
|
||||
|
||||
public static final int
|
||||
SDL_APP_CONTINUE = 0,
|
||||
SDL_APP_SUCCESS = 1,
|
||||
SDL_APP_FAILURE = 2;
|
||||
|
||||
public static final String
|
||||
SDL_PROP_APP_METADATA_NAME_STRING = "SDL.app.metadata.name",
|
||||
SDL_PROP_APP_METADATA_VERSION_STRING = "SDL.app.metadata.version",
|
||||
SDL_PROP_APP_METADATA_IDENTIFIER_STRING = "SDL.app.metadata.identifier",
|
||||
SDL_PROP_APP_METADATA_CREATOR_STRING = "SDL.app.metadata.creator",
|
||||
SDL_PROP_APP_METADATA_COPYRIGHT_STRING = "SDL.app.metadata.copyright",
|
||||
SDL_PROP_APP_METADATA_URL_STRING = "SDL.app.metadata.url",
|
||||
SDL_PROP_APP_METADATA_TYPE_STRING = "SDL.app.metadata.type";
|
||||
|
||||
protected SDLInit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// --- [ SDL_Init ] ---
|
||||
/** {@code bool SDL_Init(SDL_InitFlags flags)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_Init(@NativeType("SDL_InitFlags") int flags) {
|
||||
CallbackBridge.nativeNotifyLauncher(CallbackBridge.SDL, CallbackBridge.INIT);
|
||||
long __functionAddress = Functions.Init;
|
||||
return invokeZ(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_InitSubSystem ] ---
|
||||
|
||||
/** {@code bool SDL_InitSubSystem(SDL_InitFlags flags)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_InitSubSystem(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.InitSubSystem;
|
||||
return invokeZ(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_QuitSubSystem ] ---
|
||||
|
||||
/** {@code void SDL_QuitSubSystem(SDL_InitFlags flags)} */
|
||||
public static void SDL_QuitSubSystem(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.QuitSubSystem;
|
||||
invokeV(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_WasInit ] ---
|
||||
|
||||
/** {@code SDL_InitFlags SDL_WasInit(SDL_InitFlags flags)} */
|
||||
@NativeType("SDL_InitFlags")
|
||||
public static int SDL_WasInit(@NativeType("SDL_InitFlags") int flags) {
|
||||
long __functionAddress = Functions.WasInit;
|
||||
return invokeI(flags, __functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_Quit ] ---
|
||||
|
||||
/** {@code void SDL_Quit(void)} */
|
||||
public static void SDL_Quit() {
|
||||
long __functionAddress = Functions.Quit;
|
||||
invokeV(__functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_IsMainThread ] ---
|
||||
|
||||
/** {@code bool SDL_IsMainThread(void)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_IsMainThread() {
|
||||
long __functionAddress = Functions.IsMainThread;
|
||||
return invokeZ(__functionAddress);
|
||||
}
|
||||
|
||||
// --- [ SDL_RunOnMainThread ] ---
|
||||
|
||||
/** {@code bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void * userdata, bool wait_complete)} */
|
||||
public static boolean nSDL_RunOnMainThread(long callback, long userdata, boolean wait_complete) {
|
||||
long __functionAddress = Functions.RunOnMainThread;
|
||||
return invokePPZ(callback, userdata, wait_complete, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_RunOnMainThread(SDL_MainThreadCallback callback, void * userdata, bool wait_complete)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_RunOnMainThread(@NativeType("SDL_MainThreadCallback") SDL_MainThreadCallbackI callback, @NativeType("void *") long userdata, @NativeType("bool") boolean wait_complete) {
|
||||
return nSDL_RunOnMainThread(callback.address(), userdata, wait_complete);
|
||||
}
|
||||
|
||||
// --- [ SDL_SetAppMetadata ] ---
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
public static boolean nSDL_SetAppMetadata(long appname, long appversion, long appidentifier) {
|
||||
long __functionAddress = Functions.SetAppMetadata;
|
||||
return invokePPPZ(appname, appversion, appidentifier, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadata(@NativeType("char const *") @Nullable ByteBuffer appname, @NativeType("char const *") @Nullable ByteBuffer appversion, @NativeType("char const *") @Nullable ByteBuffer appidentifier) {
|
||||
if (CHECKS) {
|
||||
checkNT1Safe(appname);
|
||||
checkNT1Safe(appversion);
|
||||
checkNT1Safe(appidentifier);
|
||||
}
|
||||
return nSDL_SetAppMetadata(memAddressSafe(appname), memAddressSafe(appversion), memAddressSafe(appidentifier));
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadata(char const * appname, char const * appversion, char const * appidentifier)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadata(@NativeType("char const *") @Nullable CharSequence appname, @NativeType("char const *") @Nullable CharSequence appversion, @NativeType("char const *") @Nullable CharSequence appidentifier) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nUTF8Safe(appname, true);
|
||||
long appnameEncoded = appname == null ? NULL : stack.getPointerAddress();
|
||||
stack.nUTF8Safe(appversion, true);
|
||||
long appversionEncoded = appversion == null ? NULL : stack.getPointerAddress();
|
||||
stack.nUTF8Safe(appidentifier, true);
|
||||
long appidentifierEncoded = appidentifier == null ? NULL : stack.getPointerAddress();
|
||||
return nSDL_SetAppMetadata(appnameEncoded, appversionEncoded, appidentifierEncoded);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
// --- [ SDL_SetAppMetadataProperty ] ---
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
public static boolean nSDL_SetAppMetadataProperty(long name, long value) {
|
||||
long __functionAddress = Functions.SetAppMetadataProperty;
|
||||
return invokePPZ(name, value, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadataProperty(@NativeType("char const *") ByteBuffer name, @NativeType("char const *") ByteBuffer value) {
|
||||
if (CHECKS) {
|
||||
checkNT1(name);
|
||||
checkNT1(value);
|
||||
}
|
||||
return nSDL_SetAppMetadataProperty(memAddress(name), memAddress(value));
|
||||
}
|
||||
|
||||
/** {@code bool SDL_SetAppMetadataProperty(char const * name, char const * value)} */
|
||||
@NativeType("bool")
|
||||
public static boolean SDL_SetAppMetadataProperty(@NativeType("char const *") CharSequence name, @NativeType("char const *") CharSequence value) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nASCII(name, true);
|
||||
long nameEncoded = stack.getPointerAddress();
|
||||
stack.nUTF8(value, true);
|
||||
long valueEncoded = stack.getPointerAddress();
|
||||
return nSDL_SetAppMetadataProperty(nameEncoded, valueEncoded);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
// --- [ SDL_GetAppMetadataProperty ] ---
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
public static long nSDL_GetAppMetadataProperty(long name) {
|
||||
long __functionAddress = Functions.GetAppMetadataProperty;
|
||||
return invokePP(name, __functionAddress);
|
||||
}
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
@NativeType("char const *")
|
||||
public static @Nullable String SDL_GetAppMetadataProperty(@NativeType("char const *") ByteBuffer name) {
|
||||
if (CHECKS) {
|
||||
checkNT1(name);
|
||||
}
|
||||
long __result = nSDL_GetAppMetadataProperty(memAddress(name));
|
||||
return memUTF8Safe(__result);
|
||||
}
|
||||
|
||||
/** {@code char const * SDL_GetAppMetadataProperty(char const * name)} */
|
||||
@NativeType("char const *")
|
||||
public static @Nullable String SDL_GetAppMetadataProperty(@NativeType("char const *") CharSequence name) {
|
||||
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
|
||||
try {
|
||||
stack.nASCII(name, true);
|
||||
long nameEncoded = stack.getPointerAddress();
|
||||
long __result = nSDL_GetAppMetadataProperty(nameEncoded);
|
||||
return memUTF8Safe(__result);
|
||||
} finally {
|
||||
stack.setPointer(stackPointer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user