mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-10 05:01:29 -04:00
Feat[launcher]: changes related to game obtaining and updating screen dimensions.
- Changed the way the initial screen dimensions are sent to the game - Changed how the dimension updates are sent to the game - Changed how the dimensions are determined and calculated
This commit is contained in:
parent
ce2d81eaae
commit
192cd746a3
Binary file not shown.
@ -1 +1 @@
|
|||||||
1720909595576
|
1731408235037
|
@ -240,8 +240,12 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
|
// Post to get the correct display dimensions after layout.
|
||||||
|
mControlLayout.post(()->{
|
||||||
LauncherPreferences.computeNotchSize(this);
|
LauncherPreferences.computeNotchSize(this);
|
||||||
|
Tools.getDisplayMetrics(this);
|
||||||
loadControls();
|
loadControls();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Boilerplate binding */
|
/** Boilerplate binding */
|
||||||
@ -299,9 +303,16 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
|||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
if(mGyroControl != null) mGyroControl.updateOrientation();
|
if(mGyroControl != null) mGyroControl.updateOrientation();
|
||||||
Tools.updateWindowSize(this);
|
// Layout resize is practically guaranteed on a configuration change, and `onConfigurationChanged`
|
||||||
|
// does not implicitly start a layout. So, request a layout and expect the screen dimensions to be valid after the]
|
||||||
|
// post.
|
||||||
|
mControlLayout.requestLayout();
|
||||||
|
mControlLayout.post(()->{
|
||||||
|
// Child of mControlLayout, so refreshing size here is correct
|
||||||
minecraftGLView.refreshSize();
|
minecraftGLView.refreshSize();
|
||||||
runOnUiThread(() -> mControlLayout.refreshControlButtonPositions());
|
Tools.updateWindowSize(this);
|
||||||
|
mControlLayout.refreshControlButtonPositions();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -326,14 +326,22 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Called when the size need to be set at any point during the surface lifecycle **/
|
/** Called when the size need to be set at any point during the surface lifecycle **/
|
||||||
public void refreshSize(){
|
public void refreshSize(){
|
||||||
windowWidth = Tools.getDisplayFriendlyRes(Tools.currentDisplayMetrics.widthPixels, mScaleFactor);
|
refreshSize(false);
|
||||||
windowHeight = Tools.getDisplayFriendlyRes(Tools.currentDisplayMetrics.heightPixels, mScaleFactor);
|
}
|
||||||
|
|
||||||
|
/** Same as refreshSize, but allows you to force an immediate size update **/
|
||||||
|
public void refreshSize(boolean immediate) {
|
||||||
|
if(isInLayout() && !immediate) {
|
||||||
|
post(this::refreshSize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Use the width and height of the View instead of display dimensions to avoid
|
||||||
|
// getting squiched/stretched due to inconsistencies between the layout and
|
||||||
|
// screen dimensions.
|
||||||
|
windowWidth = Tools.getDisplayFriendlyRes(getWidth(), mScaleFactor);
|
||||||
|
windowHeight = Tools.getDisplayFriendlyRes(getHeight(), mScaleFactor);
|
||||||
if(mSurface == null){
|
if(mSurface == null){
|
||||||
Log.w("MGLSurface", "Attempt to refresh size on null surface");
|
Log.w("MGLSurface", "Attempt to refresh size on null surface");
|
||||||
return;
|
return;
|
||||||
@ -355,8 +363,9 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void realStart(Surface surface){
|
private void realStart(Surface surface){
|
||||||
// Initial size set
|
// Initial size set. Request immedate refresh, otherwise the initial width and height for the game
|
||||||
refreshSize();
|
// may be broken/unknown.
|
||||||
|
refreshSize(true);
|
||||||
|
|
||||||
//Load Minecraft options:
|
//Load Minecraft options:
|
||||||
MCOptionUtils.set("fullscreen", "off");
|
MCOptionUtils.set("fullscreen", "off");
|
||||||
|
@ -31,6 +31,9 @@ import android.util.ArrayMap;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
import android.view.WindowInsetsController;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -38,6 +41,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
@ -504,10 +508,14 @@ public final class Tools {
|
|||||||
return displayMetrics;
|
return displayMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFullscreen(Activity activity, boolean fullscreen) {
|
@SuppressWarnings("deprecation")
|
||||||
|
private static void setFullscreenLegacy(Activity activity, boolean fullscreen) {
|
||||||
final View decorView = activity.getWindow().getDecorView();
|
final View decorView = activity.getWindow().getDecorView();
|
||||||
View.OnSystemUiVisibilityChangeListener visibilityChangeListener = visibility -> {
|
View.OnSystemUiVisibilityChangeListener visibilityChangeListener = visibility -> {
|
||||||
if(fullscreen){
|
boolean multiWindowMode = SDK_INT >= 24 && activity.isInMultiWindowMode();
|
||||||
|
// When in multi-window mode, asking for fullscreen makes no sense (cause the launcher runs in a window)
|
||||||
|
// So, ignore the fullscreen setting when activity is in multi window mode
|
||||||
|
if(fullscreen && !multiWindowMode){
|
||||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
@ -525,11 +533,67 @@ public final class Tools {
|
|||||||
visibilityChangeListener.onSystemUiVisibilityChange(decorView.getSystemUiVisibility()); //call it once since the UI state may not change after the call, so the activity wont become fullscreen
|
visibilityChangeListener.onSystemUiVisibilityChange(decorView.getSystemUiVisibility()); //call it once since the UI state may not change after the call, so the activity wont become fullscreen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
|
private static void setFullscreenSdk30(Activity activity, boolean fullscreen) {
|
||||||
|
final Window window = activity.getWindow();
|
||||||
|
final View decorView = window.getDecorView();
|
||||||
|
final int insetControllerFlags = WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars();
|
||||||
|
final View.OnApplyWindowInsetsListener windowInsetsListener = (view, windowInsets) ->{
|
||||||
|
WindowInsetsController windowInsetsController = decorView.getWindowInsetsController();
|
||||||
|
if(windowInsetsController == null) return windowInsets;
|
||||||
|
boolean multiWindowMode = activity.isInMultiWindowMode();
|
||||||
|
// Emulate the behaviour of the legacy function using the new flags
|
||||||
|
if(fullscreen && !multiWindowMode) {
|
||||||
|
windowInsetsController.hide(insetControllerFlags);
|
||||||
|
windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
|
||||||
|
window.setDecorFitsSystemWindows(false);
|
||||||
|
}else {
|
||||||
|
windowInsetsController.show(insetControllerFlags);
|
||||||
|
// Both of the constants below have the exact same numerical value, but
|
||||||
|
// for some reason the one that works below Android S was removed
|
||||||
|
// from the acceptable constants for setSystemBarsBehaviour
|
||||||
|
if (SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
|
||||||
|
}else {
|
||||||
|
// noinspection WrongConstant
|
||||||
|
windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE);
|
||||||
|
}
|
||||||
|
window.setDecorFitsSystemWindows(true);
|
||||||
|
}
|
||||||
|
return windowInsets;
|
||||||
|
};
|
||||||
|
decorView.setOnApplyWindowInsetsListener(windowInsetsListener);
|
||||||
|
windowInsetsListener.onApplyWindowInsets(decorView, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFullscreen(Activity activity, boolean fullscreen) {
|
||||||
|
if (SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
setFullscreenSdk30(activity, fullscreen);
|
||||||
|
}else {
|
||||||
|
setFullscreenLegacy(activity, fullscreen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static DisplayMetrics currentDisplayMetrics;
|
public static DisplayMetrics currentDisplayMetrics;
|
||||||
|
|
||||||
public static void updateWindowSize(Activity activity) {
|
public static void updateWindowSize(Activity activity) {
|
||||||
currentDisplayMetrics = getDisplayMetrics(activity);
|
currentDisplayMetrics = getDisplayMetrics(activity);
|
||||||
|
|
||||||
|
View dimensionView = activity.findViewById(R.id.dimension_tracker);
|
||||||
|
|
||||||
|
if(dimensionView != null) {
|
||||||
|
int width = dimensionView.getWidth();
|
||||||
|
int height = dimensionView.getHeight();
|
||||||
|
if(width != 0 && height != 0) {
|
||||||
|
Log.i("Tools", "Using dimension_tracker for display dimensions; W="+width+" H="+height);
|
||||||
|
CallbackBridge.physicalWidth = width;
|
||||||
|
CallbackBridge.physicalHeight = height;
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
Log.e("Tools","Dimension tracker detected but dimensions out of date. Please check usage.", new Exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CallbackBridge.physicalWidth = currentDisplayMetrics.widthPixels;
|
CallbackBridge.physicalWidth = currentDisplayMetrics.widthPixels;
|
||||||
CallbackBridge.physicalHeight = currentDisplayMetrics.heightPixels;
|
CallbackBridge.physicalHeight = currentDisplayMetrics.heightPixels;
|
||||||
}
|
}
|
||||||
|
@ -212,11 +212,14 @@ int pojavInitOpenGL() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void updateMonitorSize(int width, int height);
|
||||||
|
|
||||||
EXTERNAL_API int pojavInit() {
|
EXTERNAL_API int pojavInit() {
|
||||||
ANativeWindow_acquire(pojav_environ->pojavWindow);
|
ANativeWindow_acquire(pojav_environ->pojavWindow);
|
||||||
pojav_environ->savedWidth = ANativeWindow_getWidth(pojav_environ->pojavWindow);
|
pojav_environ->savedWidth = ANativeWindow_getWidth(pojav_environ->pojavWindow);
|
||||||
pojav_environ->savedHeight = ANativeWindow_getHeight(pojav_environ->pojavWindow);
|
pojav_environ->savedHeight = ANativeWindow_getHeight(pojav_environ->pojavWindow);
|
||||||
ANativeWindow_setBuffersGeometry(pojav_environ->pojavWindow,pojav_environ->savedWidth,pojav_environ->savedHeight,AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM);
|
ANativeWindow_setBuffersGeometry(pojav_environ->pojavWindow,pojav_environ->savedWidth,pojav_environ->savedHeight,AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM);
|
||||||
|
updateMonitorSize(pojav_environ->savedWidth, pojav_environ->savedHeight);
|
||||||
pojavInitOpenGL();
|
pojavInitOpenGL();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,9 @@ typedef void GLFW_invoke_Char_func(void* window, unsigned int codepoint);
|
|||||||
typedef void GLFW_invoke_CharMods_func(void* window, unsigned int codepoint, int mods);
|
typedef void GLFW_invoke_CharMods_func(void* window, unsigned int codepoint, int mods);
|
||||||
typedef void GLFW_invoke_CursorEnter_func(void* window, int entered);
|
typedef void GLFW_invoke_CursorEnter_func(void* window, int entered);
|
||||||
typedef void GLFW_invoke_CursorPos_func(void* window, double xpos, double ypos);
|
typedef void GLFW_invoke_CursorPos_func(void* window, double xpos, double ypos);
|
||||||
typedef void GLFW_invoke_FramebufferSize_func(void* window, int width, int height);
|
|
||||||
typedef void GLFW_invoke_Key_func(void* window, int key, int scancode, int action, int mods);
|
typedef void GLFW_invoke_Key_func(void* window, int key, int scancode, int action, int mods);
|
||||||
typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, int mods);
|
typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, int mods);
|
||||||
typedef void GLFW_invoke_Scroll_func(void* window, double xoffset, double yoffset);
|
typedef void GLFW_invoke_Scroll_func(void* window, double xoffset, double yoffset);
|
||||||
typedef void GLFW_invoke_WindowSize_func(void* window, int width, int height);
|
|
||||||
|
|
||||||
struct pojav_environ_s {
|
struct pojav_environ_s {
|
||||||
struct ANativeWindow* pojavWindow;
|
struct ANativeWindow* pojavWindow;
|
||||||
@ -46,6 +44,7 @@ struct pojav_environ_s {
|
|||||||
jmethodID method_onGrabStateChanged;
|
jmethodID method_onGrabStateChanged;
|
||||||
jmethodID method_glftSetWindowAttrib;
|
jmethodID method_glftSetWindowAttrib;
|
||||||
jmethodID method_internalWindowSizeChanged;
|
jmethodID method_internalWindowSizeChanged;
|
||||||
|
jmethodID method_internalChangeMonitorSize;
|
||||||
jclass bridgeClazz;
|
jclass bridgeClazz;
|
||||||
jclass vmGlfwClass;
|
jclass vmGlfwClass;
|
||||||
jboolean isGrabbing;
|
jboolean isGrabbing;
|
||||||
@ -56,7 +55,7 @@ struct pojav_environ_s {
|
|||||||
JavaVM* dalvikJavaVMPtr;
|
JavaVM* dalvikJavaVMPtr;
|
||||||
JNIEnv* dalvikJNIEnvPtr_ANDROID;
|
JNIEnv* dalvikJNIEnvPtr_ANDROID;
|
||||||
long showingWindow;
|
long showingWindow;
|
||||||
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse;
|
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse, shouldUpdateMonitorSize;
|
||||||
int savedWidth, savedHeight;
|
int savedWidth, savedHeight;
|
||||||
#define ADD_CALLBACK_WWIN(NAME) \
|
#define ADD_CALLBACK_WWIN(NAME) \
|
||||||
GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME;
|
GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME;
|
||||||
@ -64,11 +63,9 @@ struct pojav_environ_s {
|
|||||||
ADD_CALLBACK_WWIN(CharMods);
|
ADD_CALLBACK_WWIN(CharMods);
|
||||||
ADD_CALLBACK_WWIN(CursorEnter);
|
ADD_CALLBACK_WWIN(CursorEnter);
|
||||||
ADD_CALLBACK_WWIN(CursorPos);
|
ADD_CALLBACK_WWIN(CursorPos);
|
||||||
ADD_CALLBACK_WWIN(FramebufferSize);
|
|
||||||
ADD_CALLBACK_WWIN(Key);
|
ADD_CALLBACK_WWIN(Key);
|
||||||
ADD_CALLBACK_WWIN(MouseButton);
|
ADD_CALLBACK_WWIN(MouseButton);
|
||||||
ADD_CALLBACK_WWIN(Scroll);
|
ADD_CALLBACK_WWIN(Scroll);
|
||||||
ADD_CALLBACK_WWIN(WindowSize);
|
|
||||||
|
|
||||||
#undef ADD_CALLBACK_WWIN
|
#undef ADD_CALLBACK_WWIN
|
||||||
};
|
};
|
||||||
|
@ -26,11 +26,9 @@
|
|||||||
#define EVENT_TYPE_CHAR 1000
|
#define EVENT_TYPE_CHAR 1000
|
||||||
#define EVENT_TYPE_CHAR_MODS 1001
|
#define EVENT_TYPE_CHAR_MODS 1001
|
||||||
#define EVENT_TYPE_CURSOR_ENTER 1002
|
#define EVENT_TYPE_CURSOR_ENTER 1002
|
||||||
#define EVENT_TYPE_FRAMEBUFFER_SIZE 1004
|
|
||||||
#define EVENT_TYPE_KEY 1005
|
#define EVENT_TYPE_KEY 1005
|
||||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||||
#define EVENT_TYPE_SCROLL 1007
|
#define EVENT_TYPE_SCROLL 1007
|
||||||
#define EVENT_TYPE_WINDOW_SIZE 1008
|
|
||||||
|
|
||||||
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||||
|
|
||||||
@ -52,7 +50,8 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
|||||||
(*vm)->GetEnv(vm, (void**) &pojav_environ->runtimeJNIEnvPtr_JRE, JNI_VERSION_1_4);
|
(*vm)->GetEnv(vm, (void**) &pojav_environ->runtimeJNIEnvPtr_JRE, JNI_VERSION_1_4);
|
||||||
pojav_environ->vmGlfwClass = (*pojav_environ->runtimeJNIEnvPtr_JRE)->NewGlobalRef(pojav_environ->runtimeJNIEnvPtr_JRE, (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW"));
|
pojav_environ->vmGlfwClass = (*pojav_environ->runtimeJNIEnvPtr_JRE)->NewGlobalRef(pojav_environ->runtimeJNIEnvPtr_JRE, (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW"));
|
||||||
pojav_environ->method_glftSetWindowAttrib = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "glfwSetWindowAttrib", "(JII)V");
|
pojav_environ->method_glftSetWindowAttrib = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "glfwSetWindowAttrib", "(JII)V");
|
||||||
pojav_environ->method_internalWindowSizeChanged = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "internalWindowSizeChanged", "(JII)V");
|
pojav_environ->method_internalWindowSizeChanged = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "internalWindowSizeChanged", "(J)V");
|
||||||
|
pojav_environ->method_internalChangeMonitorSize = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "internalChangeMonitorSize", "(II)V");
|
||||||
jfieldID field_keyDownBuffer = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticFieldID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "keyDownBuffer", "Ljava/nio/ByteBuffer;");
|
jfieldID field_keyDownBuffer = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticFieldID(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, "keyDownBuffer", "Ljava/nio/ByteBuffer;");
|
||||||
jobject keyDownBufferJ = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticObjectField(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, field_keyDownBuffer);
|
jobject keyDownBufferJ = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticObjectField(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, field_keyDownBuffer);
|
||||||
pojav_environ->keyDownBuffer = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetDirectBufferAddress(pojav_environ->runtimeJNIEnvPtr_JRE, keyDownBufferJ);
|
pojav_environ->keyDownBuffer = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetDirectBufferAddress(pojav_environ->runtimeJNIEnvPtr_JRE, keyDownBufferJ);
|
||||||
@ -86,16 +85,17 @@ ADD_CALLBACK_WWIN(Char)
|
|||||||
ADD_CALLBACK_WWIN(CharMods)
|
ADD_CALLBACK_WWIN(CharMods)
|
||||||
ADD_CALLBACK_WWIN(CursorEnter)
|
ADD_CALLBACK_WWIN(CursorEnter)
|
||||||
ADD_CALLBACK_WWIN(CursorPos)
|
ADD_CALLBACK_WWIN(CursorPos)
|
||||||
ADD_CALLBACK_WWIN(FramebufferSize)
|
|
||||||
ADD_CALLBACK_WWIN(Key)
|
ADD_CALLBACK_WWIN(Key)
|
||||||
ADD_CALLBACK_WWIN(MouseButton)
|
ADD_CALLBACK_WWIN(MouseButton)
|
||||||
ADD_CALLBACK_WWIN(Scroll)
|
ADD_CALLBACK_WWIN(Scroll)
|
||||||
ADD_CALLBACK_WWIN(WindowSize)
|
|
||||||
|
|
||||||
#undef ADD_CALLBACK_WWIN
|
#undef ADD_CALLBACK_WWIN
|
||||||
|
|
||||||
void handleFramebufferSizeJava(long window, int w, int h) {
|
void updateMonitorSize(int width, int height) {
|
||||||
(*pojav_environ->runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, pojav_environ->method_internalWindowSizeChanged, (long)window, w, h);
|
(*pojav_environ->runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, pojav_environ->method_internalChangeMonitorSize, width, height);
|
||||||
|
}
|
||||||
|
void updateWindowSize(void* window) {
|
||||||
|
(*pojav_environ->runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, pojav_environ->method_internalWindowSizeChanged, (long)window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pojavPumpEvents(void* window) {
|
void pojavPumpEvents(void* window) {
|
||||||
@ -103,6 +103,9 @@ void pojavPumpEvents(void* window) {
|
|||||||
pojav_environ->GLFW_invoke_CursorPos(window, floor(pojav_environ->cursorX),
|
pojav_environ->GLFW_invoke_CursorPos(window, floor(pojav_environ->cursorX),
|
||||||
floor(pojav_environ->cursorY));
|
floor(pojav_environ->cursorY));
|
||||||
}
|
}
|
||||||
|
if(pojav_environ->shouldUpdateMonitorSize) {
|
||||||
|
updateWindowSize(window);
|
||||||
|
}
|
||||||
|
|
||||||
size_t index = pojav_environ->outEventIndex;
|
size_t index = pojav_environ->outEventIndex;
|
||||||
size_t targetIndex = pojav_environ->outTargetIndex;
|
size_t targetIndex = pojav_environ->outTargetIndex;
|
||||||
@ -125,14 +128,6 @@ void pojavPumpEvents(void* window) {
|
|||||||
case EVENT_TYPE_SCROLL:
|
case EVENT_TYPE_SCROLL:
|
||||||
if(pojav_environ->GLFW_invoke_Scroll) pojav_environ->GLFW_invoke_Scroll(window, event.i1, event.i2);
|
if(pojav_environ->GLFW_invoke_Scroll) pojav_environ->GLFW_invoke_Scroll(window, event.i1, event.i2);
|
||||||
break;
|
break;
|
||||||
case EVENT_TYPE_FRAMEBUFFER_SIZE:
|
|
||||||
handleFramebufferSizeJava(pojav_environ->showingWindow, event.i1, event.i2);
|
|
||||||
if(pojav_environ->GLFW_invoke_FramebufferSize) pojav_environ->GLFW_invoke_FramebufferSize(window, event.i1, event.i2);
|
|
||||||
break;
|
|
||||||
case EVENT_TYPE_WINDOW_SIZE:
|
|
||||||
handleFramebufferSizeJava(pojav_environ->showingWindow, event.i1, event.i2);
|
|
||||||
if(pojav_environ->GLFW_invoke_WindowSize) pojav_environ->GLFW_invoke_WindowSize(window, event.i1, event.i2);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
@ -162,6 +157,10 @@ void pojavStartPumping() {
|
|||||||
pojav_environ->cLastY = pojav_environ->cursorY;
|
pojav_environ->cLastY = pojav_environ->cursorY;
|
||||||
pojav_environ->shouldUpdateMouse = true;
|
pojav_environ->shouldUpdateMouse = true;
|
||||||
}
|
}
|
||||||
|
if(pojav_environ->shouldUpdateMonitorSize) {
|
||||||
|
// Perform a monitor size update here to avoid doing it on every single window
|
||||||
|
updateMonitorSize(pojav_environ->savedWidth, pojav_environ->savedHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prepare the library for the next round of new events */
|
/** Prepare the library for the next round of new events */
|
||||||
@ -170,8 +169,9 @@ void pojavStopPumping() {
|
|||||||
|
|
||||||
// New events may have arrived while pumping, so remove only the difference before the start and end of execution
|
// New events may have arrived while pumping, so remove only the difference before the start and end of execution
|
||||||
atomic_fetch_sub_explicit(&pojav_environ->eventCounter, pojav_environ->inEventCount, memory_order_acquire);
|
atomic_fetch_sub_explicit(&pojav_environ->eventCounter, pojav_environ->inEventCount, memory_order_acquire);
|
||||||
// Make sure the next frame won't send mouse updates if it's unnecessary
|
// Make sure the next frame won't send mouse or monitor updates if it's unnecessary
|
||||||
pojav_environ->shouldUpdateMouse = false;
|
pojav_environ->shouldUpdateMouse = false;
|
||||||
|
pojav_environ->shouldUpdateMonitorSize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
@ -502,23 +502,11 @@ void noncritical_send_mouse_button(__attribute__((unused)) JNIEnv* env, __attrib
|
|||||||
void critical_send_screen_size(jint width, jint height) {
|
void critical_send_screen_size(jint width, jint height) {
|
||||||
pojav_environ->savedWidth = width;
|
pojav_environ->savedWidth = width;
|
||||||
pojav_environ->savedHeight = height;
|
pojav_environ->savedHeight = height;
|
||||||
if (pojav_environ->isInputReady) {
|
pojav_environ->shouldUpdateMonitorSize = true;
|
||||||
if (pojav_environ->GLFW_invoke_FramebufferSize) {
|
// Don't use the direct updates for screen dimensions.
|
||||||
if (pojav_environ->isUseStackQueueCall) {
|
// This is done to ensure that we have predictable conditions to correctly call
|
||||||
sendData(EVENT_TYPE_FRAMEBUFFER_SIZE, width, height, 0, 0);
|
// updateMonitorSize() and updateWindowSize() while on the render thread with an attached
|
||||||
} else {
|
// JNIEnv.
|
||||||
pojav_environ->GLFW_invoke_FramebufferSize((void*) pojav_environ->showingWindow, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pojav_environ->GLFW_invoke_WindowSize) {
|
|
||||||
if (pojav_environ->isUseStackQueueCall) {
|
|
||||||
sendData(EVENT_TYPE_WINDOW_SIZE, width, height, 0, 0);
|
|
||||||
} else {
|
|
||||||
pojav_environ->GLFW_invoke_WindowSize((void*) pojav_environ->showingWindow, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void noncritical_send_screen_size(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint width, jint height) {
|
void noncritical_send_screen_size(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint width, jint height) {
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<View style="@style/DimensionTracker"/>
|
||||||
|
|
||||||
<net.kdt.pojavlaunch.MinecraftGLSurface
|
<net.kdt.pojavlaunch.MinecraftGLSurface
|
||||||
android:id="@+id/main_game_render_view"
|
android:id="@+id/main_game_render_view"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
@ -20,4 +20,10 @@
|
|||||||
<item name="android:background">?android:attr/listDivider</item>
|
<item name="android:background">?android:attr/listDivider</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<item name="dimension_tracker" type="id" />
|
||||||
|
<style name="DimensionTracker">
|
||||||
|
<item name="android:id">@id/dimension_tracker</item>
|
||||||
|
<item name="android:layout_width">match_parent</item>
|
||||||
|
<item name="android:layout_height">match_parent</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -478,7 +478,6 @@ public class GLFW
|
|||||||
/* volatile */ public static GLFWCursorPosCallback mGLFWCursorPosCallback;
|
/* volatile */ public static GLFWCursorPosCallback mGLFWCursorPosCallback;
|
||||||
/* volatile */ public static GLFWDropCallback mGLFWDropCallback;
|
/* volatile */ public static GLFWDropCallback mGLFWDropCallback;
|
||||||
/* volatile */ public static GLFWErrorCallback mGLFWErrorCallback;
|
/* volatile */ public static GLFWErrorCallback mGLFWErrorCallback;
|
||||||
/* volatile */ public static GLFWFramebufferSizeCallback mGLFWFramebufferSizeCallback;
|
|
||||||
/* volatile */ public static GLFWJoystickCallback mGLFWJoystickCallback;
|
/* volatile */ public static GLFWJoystickCallback mGLFWJoystickCallback;
|
||||||
/* volatile */ public static GLFWKeyCallback mGLFWKeyCallback;
|
/* volatile */ public static GLFWKeyCallback mGLFWKeyCallback;
|
||||||
/* volatile */ public static GLFWMonitorCallback mGLFWMonitorCallback;
|
/* volatile */ public static GLFWMonitorCallback mGLFWMonitorCallback;
|
||||||
@ -491,7 +490,11 @@ public class GLFW
|
|||||||
/* volatile */ public static GLFWWindowMaximizeCallback mGLFWWindowMaximizeCallback;
|
/* volatile */ public static GLFWWindowMaximizeCallback mGLFWWindowMaximizeCallback;
|
||||||
/* volatile */ public static GLFWWindowPosCallback mGLFWWindowPosCallback;
|
/* volatile */ public static GLFWWindowPosCallback mGLFWWindowPosCallback;
|
||||||
/* volatile */ public static GLFWWindowRefreshCallback mGLFWWindowRefreshCallback;
|
/* volatile */ public static GLFWWindowRefreshCallback mGLFWWindowRefreshCallback;
|
||||||
/* volatile */ public static GLFWWindowSizeCallback mGLFWWindowSizeCallback;
|
|
||||||
|
// Store callback method references directly to avoid a roundtrip through
|
||||||
|
// JNI when calling the default LWJGL callbacks.
|
||||||
|
@Nullable public static GLFWFramebufferSizeCallbackI mGLFWFramebufferSizeCallbackI;
|
||||||
|
@Nullable public static GLFWWindowSizeCallbackI mGLFWWindowSizeCallbackI;
|
||||||
|
|
||||||
volatile public static int mGLFWWindowWidth, mGLFWWindowHeight;
|
volatile public static int mGLFWWindowWidth, mGLFWWindowHeight;
|
||||||
|
|
||||||
@ -513,22 +516,6 @@ public class GLFW
|
|||||||
public static long mainContext = 0;
|
public static long mainContext = 0;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String windowWidth = System.getProperty(PROP_WINDOW_WIDTH);
|
|
||||||
String windowHeight = System.getProperty(PROP_WINDOW_HEIGHT);
|
|
||||||
if (windowWidth == null || windowHeight == null) {
|
|
||||||
System.err.println("Warning: Property " + PROP_WINDOW_WIDTH + " or " + PROP_WINDOW_HEIGHT + " not set, defaulting to 1280 and 720");
|
|
||||||
|
|
||||||
mGLFWWindowWidth = 1280;
|
|
||||||
mGLFWWindowHeight = 720;
|
|
||||||
} else {
|
|
||||||
mGLFWWindowWidth = Integer.parseInt(windowWidth);
|
|
||||||
mGLFWWindowHeight = Integer.parseInt(windowHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Minecraft triggers a glfwPollEvents() on splash screen, so update window size there.
|
|
||||||
// CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE, mGLFWWindowWidth, mGLFWWindowHeight, 0, 0);
|
|
||||||
// CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_WINDOW_SIZE, mGLFWWindowWidth, mGLFWWindowHeight, 0, 0);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.loadLibrary("pojavexec");
|
System.loadLibrary("pojavexec");
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
@ -582,11 +569,9 @@ public class GLFW
|
|||||||
private static native long nglfwSetCharModsCallback(long window, long ptr);
|
private static native long nglfwSetCharModsCallback(long window, long ptr);
|
||||||
private static native long nglfwSetCursorEnterCallback(long window, long ptr);
|
private static native long nglfwSetCursorEnterCallback(long window, long ptr);
|
||||||
private static native long nglfwSetCursorPosCallback(long window, long ptr);
|
private static native long nglfwSetCursorPosCallback(long window, long ptr);
|
||||||
private static native long nglfwSetFramebufferSizeCallback(long window, long ptr);
|
|
||||||
private static native long nglfwSetKeyCallback(long window, long ptr);
|
private static native long nglfwSetKeyCallback(long window, long ptr);
|
||||||
private static native long nglfwSetMouseButtonCallback(long window, long ptr);
|
private static native long nglfwSetMouseButtonCallback(long window, long ptr);
|
||||||
private static native long nglfwSetScrollCallback(long window, long ptr);
|
private static native long nglfwSetScrollCallback(long window, long ptr);
|
||||||
private static native long nglfwSetWindowSizeCallback(long window, long ptr);
|
|
||||||
// private static native void nglfwSetInputReady();
|
// private static native void nglfwSetInputReady();
|
||||||
private static native void nglfwSetShowingWindow(long window);
|
private static native void nglfwSetShowingWindow(long window);
|
||||||
|
|
||||||
@ -633,6 +618,7 @@ public class GLFW
|
|||||||
return GLFW;
|
return GLFW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") // Used by pojavexec
|
||||||
public static void internalChangeMonitorSize(int width, int height) {
|
public static void internalChangeMonitorSize(int width, int height) {
|
||||||
mGLFWWindowWidth = width;
|
mGLFWWindowWidth = width;
|
||||||
mGLFWWindowHeight = height;
|
mGLFWWindowHeight = height;
|
||||||
@ -699,11 +685,12 @@ public class GLFW
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GLFWFramebufferSizeCallback glfwSetFramebufferSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWframebuffersizefun") GLFWFramebufferSizeCallbackI cbfun) {
|
public static GLFWFramebufferSizeCallback glfwSetFramebufferSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWframebuffersizefun") GLFWFramebufferSizeCallbackI cbfun) {
|
||||||
GLFWFramebufferSizeCallback lastCallback = mGLFWFramebufferSizeCallback;
|
GLFWFramebufferSizeCallback previousCallback = null;
|
||||||
if (cbfun == null) mGLFWFramebufferSizeCallback = null;
|
if(mGLFWFramebufferSizeCallbackI != null) {
|
||||||
else mGLFWFramebufferSizeCallback = GLFWFramebufferSizeCallback.createSafe(nglfwSetFramebufferSizeCallback(window, memAddressSafe(cbfun)));
|
previousCallback = GLFWFramebufferSizeCallback.create(mGLFWFramebufferSizeCallbackI);
|
||||||
|
}
|
||||||
return lastCallback;
|
mGLFWFramebufferSizeCallbackI = cbfun;
|
||||||
|
return previousCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GLFWJoystickCallback glfwSetJoystickCallback(/* @NativeType("GLFWwindow *") long window, */ @Nullable @NativeType("GLFWjoystickfun") GLFWJoystickCallbackI cbfun) {
|
public static GLFWJoystickCallback glfwSetJoystickCallback(/* @NativeType("GLFWwindow *") long window, */ @Nullable @NativeType("GLFWjoystickfun") GLFWJoystickCallbackI cbfun) {
|
||||||
@ -802,11 +789,12 @@ public class GLFW
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GLFWWindowSizeCallback glfwSetWindowSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowsizefun") GLFWWindowSizeCallbackI cbfun) {
|
public static GLFWWindowSizeCallback glfwSetWindowSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowsizefun") GLFWWindowSizeCallbackI cbfun) {
|
||||||
GLFWWindowSizeCallback lastCallback = mGLFWWindowSizeCallback;
|
GLFWWindowSizeCallback previousCallback = null;
|
||||||
if (cbfun == null) mGLFWWindowSizeCallback = null;
|
if(mGLFWWindowSizeCallbackI != null) {
|
||||||
else mGLFWWindowSizeCallback = GLFWWindowSizeCallback.createSafe(nglfwSetWindowSizeCallback(window, memAddressSafe(cbfun)));
|
previousCallback = GLFWWindowSizeCallback.create(mGLFWWindowSizeCallbackI);
|
||||||
|
}
|
||||||
return lastCallback;
|
mGLFWWindowSizeCallbackI = cbfun;
|
||||||
|
return previousCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isGLFWReady;
|
static boolean isGLFWReady;
|
||||||
@ -1088,11 +1076,12 @@ public class GLFW
|
|||||||
callV(Functions.StopPumping);
|
callV(Functions.StopPumping);
|
||||||
mGLFWInputPumping = false;
|
mGLFWInputPumping = false;
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("unused") // Used by pojavexec
|
||||||
public static void internalWindowSizeChanged(long window, int w, int h) {
|
public static void internalWindowSizeChanged(long window) {
|
||||||
try {
|
try {
|
||||||
internalChangeMonitorSize(w, h);
|
|
||||||
glfwSetWindowSize(window, mGLFWWindowWidth, mGLFWWindowHeight);
|
glfwSetWindowSize(window, mGLFWWindowWidth, mGLFWWindowHeight);
|
||||||
|
if(mGLFWFramebufferSizeCallbackI != null) mGLFWFramebufferSizeCallbackI.invoke(window, mGLFWWindowWidth, mGLFWWindowHeight);
|
||||||
|
if(mGLFWWindowSizeCallbackI != null) mGLFWWindowSizeCallbackI.invoke(window, mGLFWWindowWidth, mGLFWWindowHeight);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user