Skip to content

Commit 07fdf71

Browse files
committed
Migrate the Android port to SDL2
1 parent fca60e2 commit 07fdf71

30 files changed

+217
-1538
lines changed

android/SDL_Java_RMB_fix.patch

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
diff --git a/android/app/src/main/java/org/libsdl/app/SDLActivity.java b/android/app/src/main/java/org/libsdl/app/SDLActivity.java
2+
index fd5a056e3..83e3cf657 100644
3+
--- a/android/app/src/main/java/org/libsdl/app/SDLActivity.java
4+
+++ b/android/app/src/main/java/org/libsdl/app/SDLActivity.java
5+
@@ -1345,7 +1345,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
6+
}
7+
}
8+
9+
- if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
10+
+ if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE ||
11+
+ /*
12+
+ * CUSTOM ADDITION FOR MINETEST
13+
+ * should be upstreamed
14+
+ */
15+
+ (source & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE) {
16+
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
17+
// they are ignored here because sending them as mouse input to SDL is messy
18+
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {

android/app/src/main/java/net/minetest/minetest/GameActivity.java

+28-36
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
package net.minetest.minetest;
2222

23-
import android.app.NativeActivity;
23+
import org.libsdl.app.SDLActivity;
24+
2425
import android.content.Intent;
2526
import android.net.Uri;
2627
import android.os.Bundle;
@@ -32,6 +33,7 @@
3233
import android.view.inputmethod.InputMethodManager;
3334
import android.widget.Button;
3435
import android.widget.LinearLayout;
36+
import android.content.res.Configuration;
3537

3638
import androidx.annotation.Keep;
3739
import androidx.appcompat.app.AlertDialog;
@@ -45,45 +47,36 @@
4547
// This annotation prevents the minifier/Proguard from mangling them.
4648
@Keep
4749
@SuppressWarnings("unused")
48-
public class GameActivity extends NativeActivity {
49-
static {
50-
System.loadLibrary("c++_shared");
51-
System.loadLibrary("minetest");
52-
}
53-
54-
enum DialogType { TEXT_INPUT, SELECTION_INPUT }
55-
enum DialogState { DIALOG_SHOWN, DIALOG_INPUTTED, DIALOG_CANCELED }
56-
57-
private DialogType lastDialogType = DialogType.TEXT_INPUT;
58-
private DialogState inputDialogState = DialogState.DIALOG_CANCELED;
59-
private String messageReturnValue = "";
60-
private int selectionReturnValue = 0;
61-
50+
public class GameActivity extends SDLActivity {
6251
@Override
63-
public void onCreate(Bundle savedInstanceState) {
64-
super.onCreate(savedInstanceState);
65-
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
52+
protected String getMainSharedObject() {
53+
return getContext().getApplicationInfo().nativeLibraryDir + "/libminetest.so";
6654
}
6755

68-
private void makeFullScreen() {
69-
this.getWindow().getDecorView().setSystemUiVisibility(
70-
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
71-
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
72-
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
56+
@Override
57+
protected String getMainFunction() {
58+
return "SDL_Main";
7359
}
7460

7561
@Override
76-
public void onWindowFocusChanged(boolean hasFocus) {
77-
super.onWindowFocusChanged(hasFocus);
78-
if (hasFocus)
79-
makeFullScreen();
62+
protected String[] getLibraries() {
63+
return new String[] {
64+
"minetest"
65+
};
8066
}
8167

68+
// Prevent SDL from changing orientation settings since we already set the
69+
// correct orientation in our AndroidManifest.xml
8270
@Override
83-
protected void onResume() {
84-
super.onResume();
85-
makeFullScreen();
86-
}
71+
public void setOrientationBis(int w, int h, boolean resizable, String hint) {}
72+
73+
enum DialogType { TEXT_INPUT, SELECTION_INPUT }
74+
enum DialogState { DIALOG_SHOWN, DIALOG_INPUTTED, DIALOG_CANCELED }
75+
76+
private DialogType lastDialogType = DialogType.TEXT_INPUT;
77+
private DialogState inputDialogState = DialogState.DIALOG_CANCELED;
78+
private String messageReturnValue = "";
79+
private int selectionReturnValue = 0;
8780

8881
private native void saveSettings();
8982

@@ -96,11 +89,6 @@ protected void onStop() {
9689
saveSettings();
9790
}
9891

99-
@Override
100-
public void onBackPressed() {
101-
// Ignore the back press so Minetest can handle it
102-
}
103-
10492
public void showTextInputDialog(String hint, String current, int editType) {
10593
runOnUiThread(() -> showTextInputDialogUI(hint, current, editType));
10694
}
@@ -265,4 +253,8 @@ public String getLanguage() {
265253

266254
return langCode;
267255
}
256+
257+
public boolean hasPhysicalKeyboard() {
258+
return getContext().getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
259+
}
268260
}

android/app/src/main/java/org/libsdl/app/SDLActivity.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,12 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
13451345
}
13461346
}
13471347

1348-
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
1348+
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE ||
1349+
/*
1350+
* CUSTOM ADDITION FOR MINETEST
1351+
* should be upstreamed
1352+
*/
1353+
(source & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE) {
13491354
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
13501355
// they are ignored here because sending them as mouse input to SDL is messy
13511356
if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {

builtin/settingtypes.txt

-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ invert_hotbar_mouse_wheel (Hotbar: Invert mouse wheel direction) bool false
153153
[*Touchscreen]
154154

155155
# Enables touchscreen mode, allowing you to play the game with a touchscreen.
156-
#
157-
# Requires: !android
158156
enable_touch (Enable touchscreen) bool true
159157

160158
# Touchscreen sensitivity multiplier.

cmake/Modules/MinetestAndroidLibs.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ set(VORBIS_LIBRARY ${DEPS}/Vorbis/libvorbis.a)
2525
set(VORBISFILE_LIBRARY ${DEPS}/Vorbis/libvorbisfile.a)
2626
set(ZSTD_INCLUDE_DIR ${DEPS}/Zstd/include)
2727
set(ZSTD_LIBRARY ${DEPS}/Zstd/libzstd.a)
28+
set(SDL2_INCLUDE_DIRS ${DEPS}/SDL2/include/SDL2)
29+
set(SDL2_LIBRARIES ${DEPS}/SDL2/libSDL2.a)

irr/include/IEventReceiver.h

-34
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ enum EEVENT_TYPE
7979
*/
8080
EET_USER_EVENT,
8181

82-
//! Pass on raw events from the OS
83-
EET_SYSTEM_EVENT,
84-
8582
//! Application state events like a resume, pause etc.
8683
EET_APPLICATION_EVENT,
8784

@@ -187,17 +184,6 @@ enum ETOUCH_INPUT_EVENT
187184
ETIE_COUNT
188185
};
189186

190-
enum ESYSTEM_EVENT_TYPE
191-
{
192-
//! From Android command handler for native activity messages
193-
ESET_ANDROID_CMD = 0,
194-
195-
// TODO: for example ESET_WINDOWS_MESSAGE for win32 message loop events
196-
197-
//! No real event, but to get number of event types
198-
ESET_COUNT
199-
};
200-
201187
//! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
202188
enum EAPPLICATION_EVENT_TYPE
203189
{
@@ -528,25 +514,6 @@ struct SEvent
528514
size_t UserData2;
529515
};
530516

531-
// Raw events from the OS
532-
struct SSystemEvent
533-
{
534-
//! Android command handler native activity messages.
535-
struct SAndroidCmd
536-
{
537-
//! APP_CMD_ enums defined in android_native_app_glue.h from the Android NDK
538-
s32 Cmd;
539-
};
540-
541-
// TOOD: more structs for iphone, Windows, X11, etc.
542-
543-
ESYSTEM_EVENT_TYPE EventType;
544-
union
545-
{
546-
struct SAndroidCmd AndroidCmd;
547-
};
548-
};
549-
550517
// Application state event
551518
struct SApplicationEvent
552519
{
@@ -567,7 +534,6 @@ struct SEvent
567534
struct SJoystickEvent JoystickEvent;
568535
struct SLogEvent LogEvent;
569536
struct SUserEvent UserEvent;
570-
struct SSystemEvent SystemEvent;
571537
struct SApplicationEvent ApplicationEvent;
572538
};
573539
};

irr/include/IrrlichtDevice.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ class IrrlichtDevice : public virtual IReferenceCounted
180180
virtual bool isFullscreen() const = 0;
181181

182182
//! Checks if the window could possibly be visible.
183-
//! Currently, this only returns false when the activity is stopped on
184-
//! Android. Note that for Android activities, "stopped" means something
185-
//! different than you might expect (and also something different than
186-
//! "paused"). Read the Android lifecycle documentation.
183+
/** If this returns false, you should not do any rendering. */
187184
virtual bool isWindowVisible() const { return true; };
188185

189186
//! Get the current color format of the window

irr/src/Android/CAndroidAssetFileArchive.cpp

-100
This file was deleted.

irr/src/Android/CAndroidAssetFileArchive.h

-58
This file was deleted.

0 commit comments

Comments
 (0)